@@ -2497,47 +2497,21 @@ module ts {
2497
2497
}
2498
2498
2499
2499
function isInStringOrRegularExpressionOrTemplateLiteral ( previousToken : Node ) : boolean {
2500
- if ( previousToken . kind === SyntaxKind . StringLiteral || isTemplateLiteralKind ( previousToken . kind ) ) {
2500
+ if ( previousToken . kind === SyntaxKind . StringLiteral
2501
+ || previousToken . kind === SyntaxKind . RegularExpressionLiteral
2502
+ || isTemplateLiteralKind ( previousToken . kind ) ) {
2501
2503
// The position has to be either: 1. entirely within the token text, or
2502
- // 2. at the end position, and the string literal is not terminated
2503
-
2504
+ // 2. at the end position of an unterminated token.
2504
2505
var start = previousToken . getStart ( ) ;
2505
2506
var end = previousToken . getEnd ( ) ;
2506
2507
2507
2508
if ( start < position && position < end ) {
2508
2509
return true ;
2509
2510
}
2510
2511
else if ( position === end ) {
2511
- var width = end - start ;
2512
- var text = previousToken . getSourceFile ( ) . text ;
2513
-
2514
- // If the token is a single character, or its second-to-last charcter indicates an escape code,
2515
- // then we can immediately say that we are in the middle of an unclosed string.
2516
- if ( width <= 1 || text . charCodeAt ( end - 2 ) === CharacterCodes . backslash ) {
2517
- return true ;
2518
- }
2519
-
2520
- // Now check if the last character is a closing character for the token.
2521
- switch ( previousToken . kind ) {
2522
- case SyntaxKind . StringLiteral :
2523
- case SyntaxKind . NoSubstitutionTemplateLiteral :
2524
- return text . charCodeAt ( start ) !== text . charCodeAt ( end - 1 ) ;
2525
-
2526
- case SyntaxKind . TemplateHead :
2527
- case SyntaxKind . TemplateMiddle :
2528
- return text . charCodeAt ( end - 1 ) !== CharacterCodes . openBrace
2529
- || text . charCodeAt ( end - 2 ) !== CharacterCodes . $ ;
2530
-
2531
- case SyntaxKind . TemplateTail :
2532
- return text . charCodeAt ( end - 1 ) !== CharacterCodes . backtick ;
2533
- }
2534
-
2535
- return false ;
2512
+ return ! ! ( < LiteralExpression > previousToken ) . isUnterminated ;
2536
2513
}
2537
2514
}
2538
- else if ( previousToken . kind === SyntaxKind . RegularExpressionLiteral ) {
2539
- return previousToken . getStart ( ) < position && position < previousToken . getEnd ( ) ;
2540
- }
2541
2515
2542
2516
return false ;
2543
2517
}
@@ -5579,7 +5553,7 @@ module ts {
5579
5553
if ( token === SyntaxKind . StringLiteral ) {
5580
5554
// Check to see if we finished up on a multiline string literal.
5581
5555
var tokenText = scanner . getTokenText ( ) ;
5582
- if ( tokenText . length > 0 && tokenText . charCodeAt ( tokenText . length - 1 ) === CharacterCodes . backslash ) {
5556
+ if ( scanner . isUnterminated ( ) ) {
5583
5557
var quoteChar = tokenText . charCodeAt ( 0 ) ;
5584
5558
result . finalLexState = quoteChar === CharacterCodes . doubleQuote
5585
5559
? EndOfLineState . InDoubleQuoteStringLiteral
@@ -5588,10 +5562,7 @@ module ts {
5588
5562
}
5589
5563
else if ( token === SyntaxKind . MultiLineCommentTrivia ) {
5590
5564
// Check to see if the multiline comment was unclosed.
5591
- var tokenText = scanner . getTokenText ( )
5592
- if ( ! ( tokenText . length > 3 && // need to avoid catching '/*/'
5593
- tokenText . charCodeAt ( tokenText . length - 2 ) === CharacterCodes . asterisk &&
5594
- tokenText . charCodeAt ( tokenText . length - 1 ) === CharacterCodes . slash ) ) {
5565
+ if ( scanner . isUnterminated ( ) ) {
5595
5566
result . finalLexState = EndOfLineState . InMultiLineCommentTrivia ;
5596
5567
}
5597
5568
}
0 commit comments