Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed JS completions type spread #45484

Merged
merged 5 commits into from Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/services/completions.ts
Expand Up @@ -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)) {
Comment on lines +1343 to +1346
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually wonder if this whole second condition is even needed now... seems like the examples in the comments would be covered by the new condition you added. It doesn’t hurt to leave it in, so I probably wouldn’t change it this close to a release, but it might be worth running tests with it removed just to see if it can be cleaned up and simplified in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried removing it as well and a couple of tests failed so I decided to leave it in place. Errors were related to writing syntax like

const foo = {
    bar: function (.| ) {}
}

// This is likely dot from incorrectly parsed expression and user is starting to write spread
// eg: Math.min(./**/)
// const x = function (./**/) {}
// ({./**/})
return undefined;
}
break;
Expand Down
12 changes: 12 additions & 0 deletions tests/cases/fourslash/getJavaScriptCompletions22.ts
@@ -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 });