Fixed JS completions type spread (#45484)

* Fix and updated tests

* Added test

* Revert "Fix and updated tests"

This reverts commit 33829fa4a4.

* Filter out empty access expression

* PR feedback
This commit is contained in:
Armando Aguirre
2021-08-24 14:54:19 -07:00
committed by GitHub
parent b45e129f4a
commit ead9dfbdbd
2 changed files with 19 additions and 4 deletions

View File

@@ -1338,13 +1338,16 @@ namespace ts.Completions {
case SyntaxKind.PropertyAccessExpression:
propertyAccessToConvert = parent as PropertyAccessExpression;
node = propertyAccessToConvert.expression;
if ((isCallExpression(node) || isFunctionLike(node)) &&
node.end === contextToken.pos &&
node.getChildCount(sourceFile) &&
last(node.getChildren(sourceFile)).kind !== SyntaxKind.CloseParenToken) {
const leftmostAccessExpression = getLeftmostAccessExpression(propertyAccessToConvert);
if (nodeIsMissing(leftmostAccessExpression) ||
((isCallExpression(node) || isFunctionLike(node)) &&
node.end === contextToken.pos &&
node.getChildCount(sourceFile) &&
last(node.getChildren(sourceFile)).kind !== SyntaxKind.CloseParenToken)) {
// This is likely dot from incorrectly parsed expression and user is starting to write spread
// eg: Math.min(./**/)
// const x = function (./**/) {}
// ({./**/})
return undefined;
}
break;

View File

@@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />
// Regresion test for GH#45436
// @allowNonTsExtensions: true
// @Filename: file.js
//// const abc = {};
//// ({./*1*/});
goTo.marker('1');
edit.insert('.');
verify.completions({ exact: undefined });