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

Commit c9fbb09

Browse files
committed
fix: v-for parsing, close #22
1 parent d1006d2 commit c9fbb09

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/core/parseSFC.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function parseSFC(code: string, id?: string, options?: ScriptSetupTransfo
5151
if (key.startsWith('v-') || key.startsWith('@') || key.startsWith(':')) {
5252
if (key === 'v-for')
5353
// we strip out delectations for v-for before `in` or `of`
54-
expressions.add(`(${value.replace(/^.*?\w(?:in|of)\w/, '')})`)
54+
expressions.add(`(${value.replace(/^.*\s(?:in|of)\s/, '')})`)
5555
else
5656
expressions.add(`(${value})`)
5757
}

test/__snapshots__/transform.test.ts.snap

+9-1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ exports[`transform fixture VFor.vue 1`] = `
269269
<div v-for=\\"(item, index) in items\\" :key=\\"item\\">
270270
{{ item }}
271271
</div>
272+
<div v-for=\\"{ cargo_key, in_of } in items2\\">
273+
{{ cargo_key }}
274+
</div>
272275
</div>
273276
</template>
274277
@@ -289,9 +292,14 @@ __sfc_main.setup = (__props, __ctx) => {
289292
name: 'Item 4',
290293
value: 4
291294
}];
295+
const items2 = [{
296+
cargo_key: 'cargo_key',
297+
in_of: 'in'
298+
}];
292299
const index = 0;
293300
return {
294-
items
301+
items,
302+
items2
295303
};
296304
};
297305

test/fixtures/VFor.vue

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<div v-for="(item, index) in items" :key="item">
44
{{ item }}
55
</div>
6+
<div v-for="{ cargo_key, in_of } in items2">
7+
{{ cargo_key }}
8+
</div>
69
</div>
710
</template>
811

@@ -14,5 +17,9 @@ const items = [
1417
{ name: 'Item 4', value: 4 },
1518
]
1619
20+
const items2 = [
21+
{ cargo_key: 'cargo_key', in_of: 'in' },
22+
]
23+
1724
const index = 0
1825
</script>

0 commit comments

Comments
 (0)