mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Added syntactic classification for templates; also made 'spans' a NodeArray.
This commit is contained in:
@@ -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 = <NodeArray<TemplateSpan>>[];
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -400,7 +400,7 @@ module ts {
|
||||
|
||||
export interface TemplateExpression extends Expression {
|
||||
head: LiteralExpression;
|
||||
templateSpans: TemplateSpan[]
|
||||
templateSpans: NodeArray<TemplateSpan>;
|
||||
}
|
||||
|
||||
export interface TemplateSpan extends Node {
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////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));
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////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(";"));
|
||||
@@ -0,0 +1,11 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////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(";"));
|
||||
Reference in New Issue
Block a user