-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
Describe the bug
Look - I know this code is completely and utterly cooked - it's horrible.
I found it in the codebase at work (and I've fixed it).
However this code does work in TS and produces no errors if the imported Name
is a type - EVEN WITH isolatedModules: true
TS playground.
In either case when TS transpiles the code it elides the import as it assumes it was a type import.
I figured I'd file this to let you know as there does seem to be a gap in the scope analysis tooling because it doesn't recognise that the local let Name
is separate to the imported one.
Input code
import { Name } from 'some_module';
let Name: Name | null = null;
Name = null;
Config
{
"inlineSourcesContent": true,
"jsc": {
"externalHelpers": true,
"parser": {
"syntax": "typescript",
"decorators": true,
"dynamicImport": true,
"tsx": true
},
"target": "es2019",
"transform": {
"react": {
"runtime": "automatic",
"refresh": false,
"useBuiltins": true
},
"optimizer": {
"simplify": true
}
}
},
"sourceMaps": true
}
Playground link
SWC Info output
No response
Expected behavior
Compiles fine and elides the import - i.e. output should be
let FC = null;
FC = null;
Actual behavior
SWC errors:
x cannot reassign to an imported binding
,-[input.tsx:1:1]
1 | import { Name } from 'some_module';
: ^^|^
: `-- imported binding
2 | let Name: Name | null = null;
3 | Name = null;
: ^^^^
`----
Version
1.3.74
Additional context
No response