From f1f085eda65876cb3d8ae2a57b3ec8a03f86ac7b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 26 Jan 2015 12:06:01 -0800 Subject: [PATCH] Addressed CR feedback. --- src/services/services.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 50b852c241..858a1ac175 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -5620,6 +5620,10 @@ module ts { noRegexTable[SyntaxKind.TrueKeyword] = true; noRegexTable[SyntaxKind.FalseKeyword] = true; + // Just a stack of TemplateHeads and OpenCurlyBraces, used + // to perform rudimentary classification on templates. + var templateStack: SyntaxKind[] = []; + function isAccessibilityModifier(kind: SyntaxKind) { switch (kind) { case SyntaxKind.PublicKeyword: @@ -5658,7 +5662,6 @@ module ts { var offset = 0; var token = SyntaxKind.Unknown; var lastNonTriviaToken = SyntaxKind.Unknown; - var templateStack: SyntaxKind[]; // If we're in a string literal, then prepend: "\ // (and a newline). That way when we lex we'll think we're still in a string literal. @@ -5725,6 +5728,11 @@ module ts { // work well enough in practice. var angleBracketStack = 0; + // Empty out the template stack for reuse. + while (templateStack.length > 0) { + templateStack.pop(); + } + do { token = scanner.scan(); @@ -5767,24 +5775,19 @@ module ts { } } else if (token === SyntaxKind.TemplateHead && syntacticClassifierAbsent) { - if (!templateStack) { - templateStack = [token]; - } - else { - templateStack.push(token); - } + templateStack.push(token); } else if (token === SyntaxKind.OpenBraceToken && syntacticClassifierAbsent) { // If we don't have anything on the template stack, // then we aren't trying to keep track of a previously scanned template head. - if (templateStack && templateStack.length > 0) { + if (templateStack.length > 0) { templateStack.push(token); } } else if (token === SyntaxKind.CloseBraceToken && syntacticClassifierAbsent) { // If we don't have anything on the template stack, // then we aren't trying to keep track of a previously scanned template head. - if (templateStack && templateStack.length > 0) { + if (templateStack.length > 0) { var lastTemplateStackToken = lastOrUndefined(templateStack); if (lastTemplateStackToken === SyntaxKind.TemplateHead) { @@ -5860,7 +5863,7 @@ module ts { } } } - else if (templateStack && templateStack.length > 0 && lastOrUndefined(templateStack) === SyntaxKind.TemplateHead) { + else if (templateStack.length > 0 && lastOrUndefined(templateStack) === SyntaxKind.TemplateHead) { result.finalLexState = EndOfLineState.InTemplateSubstitutionPosition; } }