diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5a56c21ef78..97122529286 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -1406,13 +1406,17 @@ module ts { template.head = parseLiteralNode(); Debug.assert(template.head.kind === SyntaxKind.TemplateHead, "Template head has wrong token kind"); - var templateSpans: TemplateSpan[] = []; + var templateSpans = >[]; + templateSpans.pos = getNodePos(); + do { templateSpans.push(parseTemplateSpan()); } while (templateSpans[templateSpans.length - 1].literal.kind === SyntaxKind.TemplateMiddle) - + + templateSpans.end = getNodeEnd(); template.templateSpans = templateSpans; + return finishNode(template); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0c5fe20b713..44aa2547fc5 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -400,7 +400,7 @@ module ts { export interface TemplateExpression extends Expression { head: LiteralExpression; - templateSpans: TemplateSpan[] + templateSpans: NodeArray; } export interface TemplateSpan extends Node { diff --git a/src/services/services.ts b/src/services/services.ts index 1079381f749..86a0a8c770b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4901,6 +4901,10 @@ module ts { // TODO: we should get another classification type for these literals. return ClassificationTypeNames.stringLiteral; } + else if (isTemplateLiteralKind(tokenKind)) { + // TODO (drosen): we should *also* get another classification type for these literals. + return ClassificationTypeNames.stringLiteral; + } else if (tokenKind === SyntaxKind.Identifier) { switch (token.parent.kind) { case SyntaxKind.ClassDeclaration: diff --git a/tests/cases/fourslash/semanticClassificationInTemplateExpressions.ts b/tests/cases/fourslash/semanticClassificationInTemplateExpressions.ts new file mode 100644 index 00000000000..19f6d1062cb --- /dev/null +++ b/tests/cases/fourslash/semanticClassificationInTemplateExpressions.ts @@ -0,0 +1,21 @@ +/// + +////module /*0*/M { +//// export class /*1*/C { +//// static x; +//// } +//// export enum /*2*/E { +//// E1 = 0 +//// } +////} +////`abcd${ /*3*/M./*4*/C.x + /*5*/M./*6*/E.E1}efg` + +var c = classification; +verify.semanticClassificationsAre( + c.moduleName("M", test.marker("0").position), + c.className("C", test.marker("1").position), + c.enumName("E", test.marker("2").position), + c.moduleName("M", test.marker("3").position), + c.className("C", test.marker("4").position), + c.moduleName("M", test.marker("5").position), + c.enumName("E", test.marker("6").position)); diff --git a/tests/cases/fourslash/syntacticClassificationsTemplates1.ts b/tests/cases/fourslash/syntacticClassificationsTemplates1.ts new file mode 100644 index 00000000000..4c79c047c81 --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsTemplates1.ts @@ -0,0 +1,15 @@ +/// + +////var v = 10e0; +////var x = { +//// p1: `hello world`, +//// p2: `goodbye ${0} cruel ${0} world`, +////}; + +var c = classification; +verify.syntacticClassificationsAre( + c.keyword("var"), c.text("v"), c.operator("="), c.numericLiteral("10e0"), c.punctuation(";"), + c.keyword("var"), c.text("x"), c.operator("="), c.punctuation("{"), + c.text("p1"), c.punctuation(":"), c.stringLiteral("`hello world`"), c.punctuation(","), + c.text("p2"), c.punctuation(":"), c.stringLiteral("`goodbye ${"), c.numericLiteral("0"), c.stringLiteral("} cruel ${"), c.numericLiteral("0"), c.stringLiteral("} world`"), c.punctuation(","), + c.punctuation("}"), c.punctuation(";")); \ No newline at end of file diff --git a/tests/cases/fourslash/syntacticClassificationsTemplates2.ts b/tests/cases/fourslash/syntacticClassificationsTemplates2.ts new file mode 100644 index 00000000000..19bad4b54a8 --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsTemplates2.ts @@ -0,0 +1,11 @@ +/// + +////var tiredOfCanonicalExamples = +////`goodbye "${ `hello world` }" +////and ${ `good${ " " }riddance` }`; + +var c = classification; +verify.syntacticClassificationsAre( + c.keyword("var"), c.text("tiredOfCanonicalExamples"), c.operator("="), + c.stringLiteral("`goodbye \"${"), c.stringLiteral("`hello world`"), + c.stringLiteral("}\" \nand ${"), c.stringLiteral("`good${"), c.stringLiteral("\" \""), c.stringLiteral("}riddance`"), c.stringLiteral("}`"), c.punctuation(";")); \ No newline at end of file