Skip to content

Commit 2078aff

Browse files
committed
Minor cleanup of resolveName for decorators
1 parent 0fb624a commit 2078aff

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/compiler/checker.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -417,24 +417,25 @@ module ts {
417417
}
418418
break;
419419
case SyntaxKind.Decorator:
420-
// Decorators are resolved at the class declaration as that point where they are evaluated in the emit:
420+
// Decorators are resolved at the class declaration. Resolving at the parameter
421+
// or member would result in looking up locals in the method.
421422
//
422423
// function y() {}
423424
// class C {
424-
// method(@y x, y) {} // <-- All references to decorators should occur at the class declaration
425+
// method(@y x, y) {} // <-- decorator y should be resolved at the class declaration, not the parameter.
425426
// }
426427
//
427-
let parent = location.parent;
428-
if (parent && parent.kind === SyntaxKind.Parameter) {
429-
parent = parent.parent;
428+
if (location.parent && location.parent.kind === SyntaxKind.Parameter) {
429+
location = location.parent;
430430
}
431-
if (parent && isClassElement(parent)) {
432-
parent = parent.parent;
433-
}
434-
if (parent) {
435-
lastLocation = location;
436-
location = parent;
437-
continue;
431+
//
432+
// function y() {}
433+
// class C {
434+
// @y method(x, y) {} // <-- decorator y should be resolved at the class declaration, not the method.
435+
// }
436+
//
437+
if (location.parent && isClassElement(location.parent)) {
438+
location = location.parent;
438439
}
439440
break;
440441
}

0 commit comments

Comments
 (0)