Skip to content

Commit 378813a

Browse files
authored
fix(volar/jsx-directive): use getStart instead of pos for v-if and v-for (#949)
1 parent 120668f commit 378813a

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

packages/jsx-directive/tests/__snapshots__/v-for.test.ts.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ const set = new Set(['1', '2', '3'])
1111
const object = { id: 1, name: 'admin' }
1212
let selected = 0
1313
14-
const Comp = <>{__MACROS_renderList(4, (i) => <div>{i}</div>)}</>
14+
const Comp = () => {
15+
return <>{__MACROS_renderList(4, (i) => <div>{i}</div>)}</>
16+
}
1517
1618
defineRender(() => (
1719
<>

packages/jsx-directive/tests/fixtures/v-for/index.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const set = new Set(['1', '2', '3'])
77
const object = { id: 1, name: 'admin' }
88
let selected = 0
99
10-
const Comp = <div v-for={i in 4}>{i}</div>
10+
const Comp = () => {
11+
return <div v-for={i in 4}>{i}</div>
12+
}
1113
1214
defineRender(() => (
1315
<>

packages/volar/src/jsx-directive/v-for.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,13 @@ export function transformVFor(
9999
result.unshift('{')
100100
}
101101

102-
replaceSourceRange(codes, source, node.pos, node.pos, ...result)
102+
replaceSourceRange(
103+
codes,
104+
source,
105+
getStart(node, options),
106+
getStart(node, options),
107+
...result,
108+
)
103109

104110
replaceSourceRange(
105111
codes,

packages/volar/src/jsx-directive/v-if.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export function transformVIf(
2323
replaceSourceRange(
2424
codes,
2525
source,
26-
node.pos,
27-
node.pos,
28-
`${hasScope ? '{' : ' '}(`,
26+
getStart(node, options),
27+
getStart(node, options),
28+
`${hasScope ? '{' : ''}(`,
2929
[
3030
getText(attribute.initializer.expression, options),
3131
source,

0 commit comments

Comments
 (0)