Skip to content

Commit 581ad93

Browse files
committed
Make object literal properties new identifier locations when not contextually typed
1 parent fd6178b commit 581ad93

5 files changed

+12
-7
lines changed

src/services/completions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,8 @@ namespace ts.Completions {
18821882
return containingNodeKind === SyntaxKind.ModuleDeclaration; // module A.|
18831883

18841884
case SyntaxKind.OpenBraceToken:
1885-
return containingNodeKind === SyntaxKind.ClassDeclaration; // class A{ |
1885+
return containingNodeKind === SyntaxKind.ClassDeclaration // class A { |
1886+
|| containingNodeKind === SyntaxKind.ObjectLiteralExpression; // const obj = { |
18861887

18871888
case SyntaxKind.EqualsToken:
18881889
return containingNodeKind === SyntaxKind.VariableDeclaration // const x = a|

tests/cases/fourslash/completionPropertyShorthandForObjectLiteral.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ const locals = [
5656
];
5757
verify.completions(
5858
// Non-contextual, any, unknown, object, Record<string, ..>, [key: string]: .., Type parameter, etc..
59-
{ marker: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"], exact: completion.globalsPlus(locals)},
59+
{ marker: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"], exact: completion.globalsPlus(locals), isNewIdentifierLocation: true },
6060
// Has named property
61-
{ marker: ["12", "13"], exact: "typed"},
61+
{ marker: ["12", "13"], exact: "typed", isNewIdentifierLocation: false },
6262
// Has both StringIndexType and named property
63-
{ marker: ["14"], exact: "prop", isNewIdentifierLocation: true},
63+
{ marker: ["14"], exact: "prop", isNewIdentifierLocation: true },
6464
// NumberIndexType
65-
{ marker: ["15", "16"], exact: [], isNewIdentifierLocation: true},
65+
{ marker: ["15", "16"], exact: [], isNewIdentifierLocation: true },
6666
);

tests/cases/fourslash/completionPropertyShorthandForObjectLiteral5.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
verify.completions({
1111
marker: "",
1212
exact: completion.globalsPlus(["foo"]),
13+
isNewIdentifierLocation: true,
1314
preferences: { includeCompletionsForModuleExports: true },
1415
});

tests/cases/fourslash/completionsGenericUnconstrained.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
verify.completions({
1212
marker: "",
13+
isNewIdentifierLocation: true,
1314
includes: [{
1415
name: "Object",
1516
sortText: completion.SortText.GlobalsOrKeywords

tests/cases/fourslash/completionsSelfDeclaring2.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
verify.completions({
1111
marker: "1",
12-
exact: completion.globalsPlus(["f1", "f2"])
12+
exact: completion.globalsPlus(["f1", "f2"]),
13+
isNewIdentifierLocation: true
1314
});
1415

1516
verify.completions({
1617
marker: "2",
17-
exact: ["xyz"]
18+
exact: ["xyz"],
19+
isNewIdentifierLocation: false
1820
});

0 commit comments

Comments
 (0)