Skip to content

Commit ead9dfb

Browse files
authored
Fixed JS completions type spread (#45484)
* Fix and updated tests * Added test * Revert "Fix and updated tests" This reverts commit 33829fa. * Filter out empty access expression * PR feedback
1 parent b45e129 commit ead9dfb

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/services/completions.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,13 +1338,16 @@ namespace ts.Completions {
13381338
case SyntaxKind.PropertyAccessExpression:
13391339
propertyAccessToConvert = parent as PropertyAccessExpression;
13401340
node = propertyAccessToConvert.expression;
1341-
if ((isCallExpression(node) || isFunctionLike(node)) &&
1342-
node.end === contextToken.pos &&
1343-
node.getChildCount(sourceFile) &&
1344-
last(node.getChildren(sourceFile)).kind !== SyntaxKind.CloseParenToken) {
1341+
const leftmostAccessExpression = getLeftmostAccessExpression(propertyAccessToConvert);
1342+
if (nodeIsMissing(leftmostAccessExpression) ||
1343+
((isCallExpression(node) || isFunctionLike(node)) &&
1344+
node.end === contextToken.pos &&
1345+
node.getChildCount(sourceFile) &&
1346+
last(node.getChildren(sourceFile)).kind !== SyntaxKind.CloseParenToken)) {
13451347
// This is likely dot from incorrectly parsed expression and user is starting to write spread
13461348
// eg: Math.min(./**/)
13471349
// const x = function (./**/) {}
1350+
// ({./**/})
13481351
return undefined;
13491352
}
13501353
break;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// Regresion test for GH#45436
4+
5+
// @allowNonTsExtensions: true
6+
// @Filename: file.js
7+
//// const abc = {};
8+
//// ({./*1*/});
9+
10+
goTo.marker('1');
11+
edit.insert('.');
12+
verify.completions({ exact: undefined });

0 commit comments

Comments
 (0)