Skip to content

Commit 09d5963

Browse files
authored
fix: use node.forParseResult if present (#18)
1 parent dc9094c commit 09d5963

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/utils/template.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,15 @@ function handleNode(
109109
}
110110
case NodeTypes.DIRECTIVE: {
111111
const nodes = [
112-
node.exp,
112+
...node.forParseResult
113+
? [
114+
node.forParseResult?.source,
115+
node.forParseResult?.value,
116+
node.forParseResult?.key,
117+
node.forParseResult?.index,
118+
]
119+
: [node.exp],
113120
// node.arg,
114-
// node.forParseResult?.source,
115-
// node.forParseResult?.value,
116-
// node.forParseResult?.key,
117-
// node.forParseResult?.index,
118121
...node.modifiers,
119122
].filter(item => !!item)
120123
for (const child of nodes) {

test/template.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ describe('transform typescript template', () => {
1111

1212
expect(await fixture(`<div v-for="(item as string, index) in items as unknown[]" :key="item" :index>{{ item }}</div>`))
1313
.toEqual(`<div v-for="(item, index) in items" :key="item" :index>{{ item }}</div>`)
14+
15+
expect(await fixture(`<div v-for="(item, index) of items" />`))
16+
.toEqual(`<div v-for="(item, index) of items" />`)
1417
})
1518

1619
it('v-if', async () => {

0 commit comments

Comments
 (0)