From 782c09d783e006a697b4ba6d1e7ec2f718ce8393 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Mon, 30 Aug 2021 14:18:11 -0700 Subject: [PATCH] Cherry-pick PR #45484 into release-4.4 (#45564) Component commits: 33829fa4a4 Fix and updated tests 2249d6c83e Added test e1a2b9ed19 Revert "Fix and updated tests" This reverts commit 33829fa4a4a4cc0b54d3793ced9a31fa42930e3a. 51881c4ea2 Filter out empty access expression 2253da6ae9 PR feedback Co-authored-by: Armando Aguirre --- src/services/completions.ts | 11 +++++++---- tests/cases/fourslash/getJavaScriptCompletions22.ts | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/getJavaScriptCompletions22.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index 285095e727a0c..ef16b782c2971 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -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; diff --git a/tests/cases/fourslash/getJavaScriptCompletions22.ts b/tests/cases/fourslash/getJavaScriptCompletions22.ts new file mode 100644 index 0000000000000..86f82a346eeb5 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptCompletions22.ts @@ -0,0 +1,12 @@ +/// + +// Regresion test for GH#45436 + +// @allowNonTsExtensions: true +// @Filename: file.js +//// const abc = {}; +//// ({./*1*/}); + +goTo.marker('1'); +edit.insert('.'); +verify.completions({ exact: undefined });