Skip to content

Commit 4ae4e52

Browse files
author
Ilya Golovin
committed
fix: handle call expression param case
1 parent 24fb67a commit 4ae4e52

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

typescript/src/codeActions/custom/addDestructure/addSplittedDestructure.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export default (node: ts.Node, sourceFile: ts.SourceFile, formatOptions: ts.Form
2222

2323
if (
2424
ts.isElementAccessExpression(highlightedNode.parent) ||
25-
ts.isCallExpression(highlightedNode.parent.parent) ||
26-
ts.isTypeQueryNode(highlightedNode.parent)
25+
ts.isTypeQueryNode(highlightedNode.parent) ||
26+
(ts.isCallExpression(highlightedNode.parent.parent) && highlightedNode.parent.parent.expression === highlightedNode.parent)
2727
)
2828
return
2929

typescript/test/codeActions/addDestruct.spec.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,34 @@ describe('Add destructure', () => {
253253
})
254254
})
255255
})
256+
describe('Should destruct param call expression param', () => {
257+
test('Should skip if trying to destruct call expression', () => {
258+
const initial = /* ts */ `
259+
const /*t*/newVariable/*t*/ = { test: 1}
260+
261+
const obj = {
262+
tag: foo.map(newVariable.test),
263+
}
264+
`
265+
const expected = /* ts */ `
266+
const { test } = { test: 1}
267+
268+
const obj = {
269+
tag: foo.map(test),
270+
}
271+
`
272+
273+
const { codeAction } = fourslashLikeTester(initial, undefined, { dedent: true })
274+
275+
codeAction(0, {
276+
refactorName: 'Add Destruct',
277+
newContent: expected,
278+
})
279+
})
280+
})
256281

257282
describe('Skip cases', () => {
258-
test('Should skip if trying to destruct call expression', () => {
283+
test('Should skip if trying to destruct expression of call expression', () => {
259284
const initial = /* ts */ `
260285
const /*t*/newVariable/*t*/ = foo
261286

0 commit comments

Comments
 (0)