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

Commit cc9ea92

Browse files
committed
fix: v-for parsing
1 parent a81cda4 commit cc9ea92

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/parse.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ export function parseVueSFC(code: string, id?: string): ParseResult {
4444
if (!value)
4545
return
4646
if (key.startsWith('v-') || key.startsWith('@') || key.startsWith(':')) {
47-
if (key === 'v-if')
48-
expressions.add(`for (let ${value}) {}`)
47+
if (key === 'v-for')
48+
// we strip out delectations for v-for before `in` or `of`
49+
expressions.add(`(${value.replace(/^.*?\w(?:in|of)\w/, '')})`)
4950
else
5051
expressions.add(`(${value})`)
5152
}

test/__snapshots__/transform.test.ts.snap

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ exports[`transform fixture VFor.vue 1`] = `
8686
"<template>
8787
<div>
8888
<div v-for=\\"(item, index) in items\\" :key=\\"item\\">
89-
{{ index }}: {{ item }}
89+
{{ item }}
9090
</div>
9191
</div>
9292
</template>
@@ -108,6 +108,7 @@ __sfc_main.setup = (__props, __ctx) => {
108108
name: 'Item 4',
109109
value: 4
110110
}];
111+
const index = 0;
111112
return {
112113
items
113114
};

test/fixtures/VFor.vue

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div>
33
<div v-for="(item, index) in items" :key="item">
4-
{{ index }}: {{ item }}
4+
{{ item }}
55
</div>
66
</div>
77
</template>
@@ -13,4 +13,6 @@ const items = [
1313
{ name: 'Item 3', value: 3 },
1414
{ name: 'Item 4', value: 4 },
1515
]
16+
17+
const index = 0
1618
</script>

0 commit comments

Comments
 (0)