mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Merge pull request #2658 from Microsoft/fixDecoratorBindingForSuperThis
Fixes #2601, incorrect resolution of this/super
This commit is contained in:
@@ -5600,7 +5600,7 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
if (container.kind === SyntaxKind.ComputedPropertyName) {
|
||||
if (container && container.kind === SyntaxKind.ComputedPropertyName) {
|
||||
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
|
||||
}
|
||||
else if (isCallExpression) {
|
||||
|
||||
@@ -526,6 +526,19 @@ module ts {
|
||||
// the *body* of the container.
|
||||
node = node.parent;
|
||||
break;
|
||||
case SyntaxKind.Decorator:
|
||||
// Decorators are always applied outside of the body of a class or method.
|
||||
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
|
||||
// If the decorator's parent is a Parameter, we resolve the this container from
|
||||
// the grandparent class declaration.
|
||||
node = node.parent.parent;
|
||||
}
|
||||
else if (isClassElement(node.parent)) {
|
||||
// If the decorator's parent is a class element, we resolve the 'this' container
|
||||
// from the parent class declaration.
|
||||
node = node.parent;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.ArrowFunction:
|
||||
if (!includeArrowFunctions) {
|
||||
continue;
|
||||
@@ -568,6 +581,19 @@ module ts {
|
||||
// the *body* of the container.
|
||||
node = node.parent;
|
||||
break;
|
||||
case SyntaxKind.Decorator:
|
||||
// Decorators are always applied outside of the body of a class or method.
|
||||
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
|
||||
// If the decorator's parent is a Parameter, we resolve the this container from
|
||||
// the grandparent class declaration.
|
||||
node = node.parent.parent;
|
||||
}
|
||||
else if (isClassElement(node.parent)) {
|
||||
// If the decorator's parent is a class element, we resolve the 'this' container
|
||||
// from the parent class declaration.
|
||||
node = node.parent;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
@@ -919,6 +945,7 @@ module ts {
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.IndexSignature:
|
||||
return true;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user