Merge pull request #3347 from Microsoft/irregularExpressionCompletion

Block completion when in the flags of a regular expression
This commit is contained in:
Daniel Rosenwasser
2015-06-02 14:15:47 -07:00
7 changed files with 59 additions and 6 deletions

View File

@@ -3130,16 +3130,20 @@ module ts {
if (previousToken.kind === SyntaxKind.StringLiteral
|| previousToken.kind === SyntaxKind.RegularExpressionLiteral
|| isTemplateLiteralKind(previousToken.kind)) {
// The position has to be either: 1. entirely within the token text, or
// 2. at the end position of an unterminated token.
let start = previousToken.getStart();
let end = previousToken.getEnd();
// To be "in" one of these literals, the position has to be:
// 1. entirely within the token text.
// 2. at the end position of an unterminated token.
// 3. at the end of a regular expression (due to trailing flags like '/foo/g').
if (start < position && position < end) {
return true;
}
else if (position === end) {
return !!(<LiteralExpression>previousToken).isUnterminated;
if (position === end) {
return !!(<LiteralExpression>previousToken).isUnterminated ||
previousToken.kind === SyntaxKind.RegularExpressionLiteral;
}
}