-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript parameter decorators use incorrect scope #2147
Comments
Oh, that's strange. So the scope lookup for parameter decorators is supposed to happen at the top-level, not where the decorator is. I guess that makes sense based on where the generated code for the decorator ends up. I'll have to rework some things to fix this. |
evanw
added a commit
that referenced
this issue
Apr 1, 2022
I believe the relevant code in the TypeScript compiler is this code in case SyntaxKind.Decorator:
// Decorators are resolved at the class declaration. Resolving at the parameter
// or member would result in looking up locals in the method.
//
// function y() {}
// class C {
// method(@y x, y) {} // <-- decorator y should be resolved at the class declaration, not the parameter.
// }
//
if (location.parent && location.parent.kind === SyntaxKind.Parameter) {
location = location.parent;
}
//
// function y() {}
// class C {
// @y method(x, y) {} // <-- decorator y should be resolved at the class declaration, not the method.
// }
//
// class Decorators are resolved outside of the class to avoid referencing type parameters of that class.
//
// type T = number;
// declare function y(x: T): any;
// @param(1 as T) // <-- T should resolve to the type alias outside of class C
// class C<T> {}
if (location.parent && (isClassElement(location.parent) || location.parent.kind === SyntaxKind.ClassDeclaration)) {
location = location.parent;
}
break; |
kanoshin
changed the title
Typescript import name collision with decorated parameter
Typescript parameter decorators use incorrect scope
Apr 4, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example TS code:
Example esbuild output for
esbuild src/index.ts --outfile=dist/bundle.js
command:When running the output code there will be the error:
Abc2 is not defined
. Notice that esbuild thinks that in Root1 case decorator parameter is equal to constructor parameter. Same thing works properly when decorator parameter named differently from constructor parameter.The same code will transpile to JS properly when using TSC.
The text was updated successfully, but these errors were encountered: