From dbcb6dc01ee357ff3fb9d2db3f2eb28a529352e0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 7 Nov 2014 13:29:59 -0800 Subject: [PATCH] Corrected isExpression for templates. Fixes #1046. --- src/compiler/parser.ts | 4 +++- tests/cases/fourslash/findAllRefsInsideTemplates1.ts | 12 ++++++++++++ tests/cases/fourslash/findAllRefsInsideTemplates2.ts | 12 ++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/findAllRefsInsideTemplates1.ts create mode 100644 tests/cases/fourslash/findAllRefsInsideTemplates2.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5da1952ab27..20a7f4ca46b 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -490,6 +490,7 @@ module ts { case SyntaxKind.BinaryExpression: case SyntaxKind.ConditionalExpression: case SyntaxKind.TemplateExpression: + case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.OmittedExpression: return true; case SyntaxKind.QualifiedName: @@ -502,7 +503,6 @@ module ts { // fall through case SyntaxKind.NumericLiteral: case SyntaxKind.StringLiteral: - case SyntaxKind.NoSubstitutionTemplateLiteral: var parent = node.parent; switch (parent.kind) { case SyntaxKind.VariableDeclaration: @@ -531,6 +531,8 @@ module ts { (parent).expression === node; case SyntaxKind.TypeAssertion: return node === (parent).operand; + case SyntaxKind.TemplateSpan: + return node === (parent).expression; default: if (isExpression(parent)) { return true; diff --git a/tests/cases/fourslash/findAllRefsInsideTemplates1.ts b/tests/cases/fourslash/findAllRefsInsideTemplates1.ts new file mode 100644 index 00000000000..e4501219265 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsInsideTemplates1.ts @@ -0,0 +1,12 @@ +/// + +////var [|x|] = 10; +////var y = `${ [|x|] } ${ [|x|] }` + +test.ranges().forEach(targetRange => { + goTo.position(targetRange.start); + + test.ranges().forEach(range => { + verify.referencesAtPositionContains(range); + } +} \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsInsideTemplates2.ts b/tests/cases/fourslash/findAllRefsInsideTemplates2.ts new file mode 100644 index 00000000000..cafddd4f45b --- /dev/null +++ b/tests/cases/fourslash/findAllRefsInsideTemplates2.ts @@ -0,0 +1,12 @@ +/// + +////function [|f|](...rest: any[]) { } +////[|f|] `${ [|f|] } ${ [|f|] }` + +test.ranges().forEach(targetRange => { + goTo.position(targetRange.start); + + test.ranges().forEach(range => { + verify.referencesAtPositionContains(range); + } +} \ No newline at end of file