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

Commit 1a7c5b9

Browse files
authored
fix: support optional chaining operator (#69)
1 parent 1788709 commit 1a7c5b9

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/core/identifiers.ts

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ export function getIdentifierUsages(node?: Expression | TSType | SpreadElement |
7070
else if (node.type === 'MemberExpression') {
7171
getIdentifierUsages(node.object, identifiers)
7272
}
73+
else if (node.type === 'OptionalMemberExpression') {
74+
getIdentifierUsages(node.object, identifiers)
75+
}
7376
else if (node.type === 'CallExpression') {
7477
getIdentifierUsages(node.callee as Expression, identifiers)
7578
node.arguments.forEach(arg => getIdentifierUsages(arg as Expression, identifiers))

test/__snapshots__/transform.test.ts.snap

+9-3
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,23 @@ export default __sfc_main;
251251
252252
exports[`transform fixtures test/fixtures/MacrosDefineExpose.vue 1`] = `
253253
"<template>
254-
<div>{{a}}</div>
254+
<div>{{ a }}</div>
255+
<div>{{ text?.length ?? textLengthDefault }}</div>
255256
</template>
256257
257-
<script lang=\\"js\\">
258+
<script lang=\\"ts\\">
259+
import { ref } from '@vue/composition-api';
258260
const __sfc_main = {};
259261
260262
__sfc_main.setup = (__props, __ctx) => {
261263
const a = ref(1);
262264
const b = 1;
265+
const text = 'hello';
266+
const textLengthDefault = 0;
263267
return Object.assign({
264-
a
268+
a,
269+
text,
270+
textLengthDefault
265271
}, {
266272
b
267273
});

test/fixtures/MacrosDefineExpose.vue

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<template>
2-
<div>{{a}}</div>
2+
<div>{{ a }}</div>
3+
<div>{{ text?.length ?? textLengthDefault }}</div>
34
</template>
45

5-
<script setup lang="js">
6-
const a = ref(1);
7-
const b = 1;
8-
defineExpose({b});
6+
<script setup lang="ts">
7+
import { ref } from '@vue/composition-api'
8+
9+
const a = ref(1)
10+
const b = 1
11+
const text = 'hello'
12+
const textLengthDefault = 0
13+
defineExpose({ b })
914
</script>

0 commit comments

Comments
 (0)