Skip to content

Commit 0662d17

Browse files
committed
fix: should not throw when root property not found
1 parent 622e53b commit 0662d17

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

transformations/__tests__/root-prop-to-use-test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ defineInlineTest(
2020
`Vue.createApp({}).use(router);`,
2121
'Can recognize Vue.createApp'
2222
)
23+
24+
defineInlineTest(
25+
transform,
26+
{
27+
rootPropName: 'router',
28+
},
29+
`createApp({});`,
30+
`createApp({});`
31+
)

transformations/root-prop-to-use.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ export const transformAST: ASTTransformation<Params> = (
4242
// @ts-ignore
4343
(p) => p.key && p.key.name === rootPropName
4444
)
45+
46+
if (propertyIndex === -1) {
47+
return createAppCall
48+
}
49+
4550
// @ts-ignore
4651
const [{ value: pluginInstance }] = rootProps.properties.splice(
4752
propertyIndex,

0 commit comments

Comments
 (0)