-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
TypeScript identifier resolver incorrectly handles block scopes #7967
Comments
I think those are same |
I don't understand what you mean by "those are the same", can you elaborate? Type definitions in TypeScript are block-scoped. For example: foo.ts: {
interface Foo {}
}
let foo: Foo; $ tsc --noEmit foo.ts
foo.ts:5:8 - error TS2304: Cannot find name 'Foo'.
5 let foo: Foo;
~~~
Found 1 error in foo.ts:5 I believe this should be treated the same as other definitions so that each interface declaration gets its own The swc/crates/swc_ecma_ast/src/ident.rs Lines 72 to 78 in e749328
Why should interface declarations be treated differently? |
Ping @kdy1, I'm very confused why this was closed. Can you elaborate on my questions above? I'm happy to contribute the change if you agree with my reasoning. |
This also affects { using foo = null }
{ using foo = null } |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Describe the bug
I'm using
swc_ecma_transforms_base::resolver
to determine which declaration a given identifier refers to.I'm defining multiple TypeScript interfaces with the same name, each within its own block (using a top-level BlockStmt). However,
swc_ecma_transforms_base::resolver
maps them to the sameswc_ecma_ast::Id
. See example belowInput code
TypeScript:
Rust:
Config
Using the Rust library.
Playground link
View the AST tab:
https://play.swc.rs/?version=1.3.74&code=H4sIAAAAAAAAA6vmUgCCzLyS1KK0xORUBbf8fIXqWq5aLq5qHDIAgwgOgDIAAAA%3D&config=H4sIAAAAAAAAA1VPOw7DIAzdOQXy3KFi6NA79BCIOhERAYQdqSjK3QsJpM1mv4%2Ff8yqkhIkMPOVaxrJEnQjTuReEsmf9KQhwjkgm2chw6yxTpQbtCHdoOxhgnUbk6kJSd6WaA1wIhN3RsNl6O%2BT%2FTBPmmJDoKqxS7UeH10TRUmEO72Un2y%2B179HgAT9RDzsPg6VXd3JaUGxfBMLf3xcBAAA%3D
Expected behavior
I expect the two
Identifier
AST nodes inside theTsInterfaceDeclaration
nodes to have differentctxt
values inside their spans.Actual behavior
The two
Identifier
nodes have the samectxt
value2
, which means they get mapped to the sameswc_ecma_ast::Id
even though they're different types.Version
1.3.85
The text was updated successfully, but these errors were encountered: