At '.' in object literal, don't close the object (#27850)

* At '.' in object literal, don't close the object

* Include diagnostics test
This commit is contained in:
Andy
2018-10-12 08:49:04 -07:00
committed by GitHub
parent 12cd3ea6ac
commit 54a5be1860
3 changed files with 20 additions and 3 deletions

View File

@@ -1482,7 +1482,15 @@ namespace ts {
// which would be a candidate for improved error reporting.
return token() === SyntaxKind.OpenBracketToken || isLiteralPropertyName();
case ParsingContext.ObjectLiteralMembers:
return token() === SyntaxKind.OpenBracketToken || token() === SyntaxKind.AsteriskToken || token() === SyntaxKind.DotDotDotToken || isLiteralPropertyName();
switch (token()) {
case SyntaxKind.OpenBracketToken:
case SyntaxKind.AsteriskToken:
case SyntaxKind.DotDotDotToken:
case SyntaxKind.DotToken: // Not an object literal member, but don't want to close the object (see `tests/cases/fourslash/completionsDotInObjectLiteral.ts`)
return true;
default:
return isLiteralPropertyName();
}
case ParsingContext.RestProperties:
return isLiteralPropertyName();
case ParsingContext.ObjectBindingElements:

View File

@@ -596,8 +596,7 @@ namespace ts {
{
compilerOptions: {
target: undefined,
module: ModuleKind.ESNext,
types: []
module: ModuleKind.ESNext
},
hasParseErrors: true
}

View File

@@ -0,0 +1,10 @@
/// <reference path="fourslash.ts" />
////const o = {
//// a: 1,
//// [|.|]/**/
////[|}|];
verify.getSyntacticDiagnostics(test.ranges().map((range): FourSlashInterface.Diagnostic =>
({ code: 1003, message: "Identifier expected.", range })));
verify.completions({ marker: "", exact: undefined });