Skip to content

Commit 4ab7111

Browse files
committed
fix: ban method snippets in the following location: test/*|*/ = () => {}
1 parent b64a4f7 commit 4ab7111

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

typescript/src/completions/isGoodPositionMethodCompletion.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ export const isGoodPositionMethodCompletion = (sourceFile: ts.SourceFile, positi
1111
// type A = typeof obj["|"]
1212
if (ts.isStringLiteralLike(currentNode)) return false
1313
if (ts.isNamedExports(currentNode)) return false
14+
if (
15+
ts.isIdentifier(currentNode) &&
16+
ts.isBinaryExpression(currentNode.parent) &&
17+
currentNode.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
18+
currentNode === currentNode.parent.left
19+
) {
20+
return false
21+
}
1422
if (ts.isIdentifier(currentNode)) currentNode = currentNode.parent
1523
if (ts.isExportSpecifier(currentNode)) return false
1624
if (ts.isJsxSelfClosingElement(currentNode) || ts.isJsxOpeningElement(currentNode)) return false

typescript/test/completions.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ test('Banned positions for all method snippets', () => {
5656
test({
5757
/*|*/
5858
})
59+
test/*|*/ = test
5960
;<Test/*|*/ />
6061
;<Test/*|*/></Test>
6162
;<Test test={/*|*/}></Test>
@@ -83,6 +84,8 @@ test('Not banned positions for method snippets', () => {
8384
method: setTimeout/*|*/
8485
})
8586
test2/*|*/
87+
test = test/*|*/
88+
test/*|*/ >= test/*|*/
8689
`)
8790
for (const [i, pos] of cursorPositions.entries()) {
8891
const result = isGoodPositionMethodCompletion(getSourceFile(), pos - 1, defaultConfigFunc)

0 commit comments

Comments
 (0)