Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 397e6df

Browse files
xiaoxiangmoeantfu
authored andcommitted
fix: MemberExpression computed property
1 parent f9a86b9 commit 397e6df

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/core/identifiers.ts

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export function getIdentifierUsages(node?: Expression | TSType | SpreadElement |
6969
}
7070
else if (node.type === 'MemberExpression' || node.type === 'OptionalMemberExpression') {
7171
getIdentifierUsages(node.object, identifiers)
72+
if (node.computed)
73+
getIdentifierUsages(node.property, identifiers)
7274
}
7375
else if (node.type === 'CallExpression' || node.type === 'OptionalCallExpression') {
7476
getIdentifierUsages(node.callee as Expression, identifiers)

test/__snapshots__/transform.test.ts.snap

+15-3
Original file line numberDiff line numberDiff line change
@@ -810,24 +810,36 @@ export default __sfc_main;
810810
exports[`transform fixtures test/fixtures/TemplateOptionalChaining.vue 1`] = `
811811
"<template>
812812
<div @click=\\"callback?.()\\">
813-
{{ text?.length ?? textLengthDefault }}
813+
{{ text?.length ?? textLengthDefault?.[index] }}
814814
{{ classes?.[0] }}
815+
{{ arrayObj.data.value[i] }}
815816
</div>
816817
</template>
817818
818819
<script lang=\\"ts\\">
820+
import { ref } from '@vue/composition-api';
819821
const __sfc_main = {};
820822
821823
__sfc_main.setup = (__props, __ctx) => {
822824
const text = 'hello';
823-
const textLengthDefault = 0;
825+
const textLengthDefault = '';
826+
const index = ref(0);
824827
const callback = (undefined as undefined | (() => void));
825828
const classes = (undefined as undefined | string[]);
829+
const arrayObj = {
830+
data: {
831+
value: [1, 2, 3]
832+
}
833+
};
834+
const i = 0;
826835
return {
827836
text,
828837
textLengthDefault,
838+
index,
829839
callback,
830-
classes
840+
classes,
841+
arrayObj,
842+
i
831843
};
832844
};
833845
+7-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<template>
22
<div @click="callback?.()">
3-
{{ text?.length ?? textLengthDefault }}
3+
{{ text?.length ?? textLengthDefault?.[index] }}
44
{{ classes?.[0] }}
5+
{{ arrayObj.data.value[i] }}
56
</div>
67
</template>
78

89
<script setup lang="ts">
10+
import { ref } from '@vue/composition-api'
911
const text = 'hello'
10-
const textLengthDefault = 0
12+
const textLengthDefault = ''
13+
const index = ref(0)
1114
1215
const callback = undefined as undefined | (() => void)
1316
const classes = undefined as undefined | string[]
17+
const arrayObj = { data: { value: [1, 2, 3] } }
18+
const i = 0
1419
</script>

0 commit comments

Comments
 (0)