Skip to content

Commit 4ff87b7

Browse files
committed
Fixes #2601, incorrect resolution of this/super
1 parent 189f07a commit 4ff87b7

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5600,7 +5600,7 @@ module ts {
56005600
}
56015601
}
56025602

5603-
if (container.kind === SyntaxKind.ComputedPropertyName) {
5603+
if (container && container.kind === SyntaxKind.ComputedPropertyName) {
56045604
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
56055605
}
56065606
else if (isCallExpression) {

src/compiler/utilities.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,19 @@ module ts {
526526
// the *body* of the container.
527527
node = node.parent;
528528
break;
529+
case SyntaxKind.Decorator:
530+
// Decorators are always applied outside of the body of a class or method.
531+
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
532+
// If the decorator's parent is a Parameter, we resolve the this container from
533+
// the grandparent class declaration.
534+
node = node.parent.parent;
535+
}
536+
else if (isClassElement(node.parent)) {
537+
// If the decorator's parent is a class element, we resolve the 'this' container
538+
// from the parent class declaration.
539+
node = node.parent;
540+
}
541+
break;
529542
case SyntaxKind.ArrowFunction:
530543
if (!includeArrowFunctions) {
531544
continue;
@@ -568,6 +581,19 @@ module ts {
568581
// the *body* of the container.
569582
node = node.parent;
570583
break;
584+
case SyntaxKind.Decorator:
585+
// Decorators are always applied outside of the body of a class or method.
586+
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
587+
// If the decorator's parent is a Parameter, we resolve the this container from
588+
// the grandparent class declaration.
589+
node = node.parent.parent;
590+
}
591+
else if (isClassElement(node.parent)) {
592+
// If the decorator's parent is a class element, we resolve the 'this' container
593+
// from the parent class declaration.
594+
node = node.parent;
595+
}
596+
break;
571597
case SyntaxKind.FunctionDeclaration:
572598
case SyntaxKind.FunctionExpression:
573599
case SyntaxKind.ArrowFunction:
@@ -919,6 +945,7 @@ module ts {
919945
case SyntaxKind.MethodDeclaration:
920946
case SyntaxKind.GetAccessor:
921947
case SyntaxKind.SetAccessor:
948+
case SyntaxKind.MethodSignature:
922949
case SyntaxKind.IndexSignature:
923950
return true;
924951
default:

0 commit comments

Comments
 (0)