Skip to content

Commit d93c28e

Browse files
Process unterminated multiline comments the same way we handle multiline strings.
1 parent 292cfc8 commit d93c28e

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/services/services.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4077,8 +4077,7 @@ module ts {
40774077
var offset = 0;
40784078
var lastTokenOrCommentEnd = 0;
40794079
var lastNonTriviaToken = SyntaxKind.Unknown;
4080-
var inUnterminatedMultiLineComment = false;
4081-
4080+
40824081
// If we're in a string literal, then prepend: "\
40834082
// (and a newline). That way when we lex we'll think we're still in a string literal.
40844083
//
@@ -4104,7 +4103,7 @@ module ts {
41044103
entries: []
41054104
};
41064105

4107-
scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ false, text, onError, /*onComment*/ undefined);
4106+
scanner = createScanner(ScriptTarget.ES5, /*skipTrivia*/ false, text, /*onError*/ undefined, /*onComment*/ undefined);
41084107

41094108
var token = SyntaxKind.Unknown;
41104109
do {
@@ -4130,11 +4129,6 @@ module ts {
41304129

41314130
return result;
41324131

4133-
4134-
function onError(message: DiagnosticMessage): void {
4135-
inUnterminatedMultiLineComment = message.key === Diagnostics.Asterisk_Slash_expected.key;
4136-
}
4137-
41384132
function processToken(): void {
41394133
var start = scanner.getTokenPos();
41404134
var end = scanner.getTextPos();
@@ -4144,10 +4138,8 @@ module ts {
41444138

41454139
if (end >= text.length) {
41464140
// We're at the end.
4147-
if (inUnterminatedMultiLineComment) {
4148-
result.finalLexState = EndOfLineState.InMultiLineCommentTrivia;
4149-
}
4150-
else if (token === SyntaxKind.StringLiteral) {
4141+
if (token === SyntaxKind.StringLiteral) {
4142+
// Check to see if we finished up on a multiline string literal.
41514143
var tokenText = scanner.getTokenText();
41524144
if (tokenText.length > 0 && tokenText.charCodeAt(tokenText.length - 1) === CharacterCodes.backslash) {
41534145
var quoteChar = tokenText.charCodeAt(0);
@@ -4156,6 +4148,15 @@ module ts {
41564148
: EndOfLineState.InSingleQuoteStringLiteral;
41574149
}
41584150
}
4151+
else if (token === SyntaxKind.MultiLineCommentTrivia) {
4152+
// Check to see if the multiline comment was unclosed.
4153+
var tokenText = scanner.getTokenText()
4154+
if (!(tokenText.length > 3 && // need to avoid catching '/*/'
4155+
tokenText.charCodeAt(tokenText.length - 2) === CharacterCodes.asterisk &&
4156+
tokenText.charCodeAt(tokenText.length - 1) === CharacterCodes.slash)) {
4157+
result.finalLexState = EndOfLineState.InMultiLineCommentTrivia;
4158+
}
4159+
}
41594160
}
41604161
}
41614162

0 commit comments

Comments
 (0)