From 4ff87b71a4018cc48cc418a622faf1ba0f5c0868 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 7 Apr 2015 11:42:08 -0700 Subject: [PATCH] Fixes #2601, incorrect resolution of this/super --- src/compiler/checker.ts | 2 +- src/compiler/utilities.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1b87578a26d..35c3c5fce55 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e3efd12de0a..4df840c3241 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -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: