Skip to content

Commit f8ef17c

Browse files
committed
refactor: sync from test vapor branch
1 parent ac11bd0 commit f8ef17c

40 files changed

+846
-533
lines changed

packages/compiler-vapor/__tests__/__snapshots__/compile.spec.ts.snap

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function render(_ctx) {
3838
"default": () => {
3939
const n0 = _createIf(() => (true), () => {
4040
const n3 = t0()
41-
_setInsertionState(n3, null)
41+
_setInsertionState(n3, null, true)
4242
const n2 = _createComponentWithFallback(_component_Bar)
4343
_withVaporDirectives(n2, [[_directive_hello, void 0, void 0, { world: true }]])
4444
return n3
@@ -157,9 +157,9 @@ export function render(_ctx, $props, $emit, $attrs, $slots) {
157157
const _component_Comp = _resolveComponent("Comp")
158158
const n0 = t0()
159159
const n3 = t1()
160-
_setInsertionState(n3, 0)
160+
const n2 = _child(n3, 1)
161+
_setInsertionState(n3, 0, true)
161162
const n1 = _createComponentWithFallback(_component_Comp)
162-
const n2 = _child(n3)
163163
_renderEffect(() => {
164164
_setProp(n3, "id", _ctx.foo)
165165
_setText(n2, _toDisplayString(_ctx.bar))
@@ -212,17 +212,41 @@ export function render(_ctx) {
212212
}"
213213
`;
214214
215+
exports[`compile > execution order > setInsertionState > next, child and nthChild should be above the setInsertionState 1`] = `
216+
"import { resolveComponent as _resolveComponent, child as _child, next as _next, setInsertionState as _setInsertionState, createComponentWithFallback as _createComponentWithFallback, nthChild as _nthChild, createIf as _createIf, setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
217+
const t0 = _template("<div></div>")
218+
const t1 = _template("<div><div></div><!><div></div><!><div><button></button></div></div>", true)
219+
220+
export function render(_ctx) {
221+
const _component_Comp = _resolveComponent("Comp")
222+
const n6 = t1()
223+
const n5 = _next(_child(n6), 1)
224+
const n7 = _nthChild(n6, 3, 3)
225+
const p0 = _next(n7, 4)
226+
const n4 = _child(p0, 0)
227+
_setInsertionState(n6, n5)
228+
const n0 = _createComponentWithFallback(_component_Comp)
229+
_setInsertionState(n6, n7, true)
230+
const n1 = _createIf(() => (true), () => {
231+
const n3 = t0()
232+
return n3
233+
})
234+
_renderEffect(() => _setProp(n4, "disabled", _ctx.foo))
235+
return n6
236+
}"
237+
`;
238+
215239
exports[`compile > execution order > with insertionState 1`] = `
216240
"import { resolveComponent as _resolveComponent, child as _child, setInsertionState as _setInsertionState, createSlot as _createSlot, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
217241
const t0 = _template("<div><div></div></div>", true)
218242
219243
export function render(_ctx) {
220244
const _component_Comp = _resolveComponent("Comp")
221245
const n3 = t0()
222-
const n1 = _child(n3)
223-
_setInsertionState(n1, null)
246+
const n1 = _child(n3, 0)
247+
_setInsertionState(n1, null, true)
224248
const n0 = _createSlot("default", null)
225-
_setInsertionState(n3, 1)
249+
_setInsertionState(n3, 1, true)
226250
const n2 = _createComponentWithFallback(_component_Comp)
227251
return n3
228252
}"
@@ -234,9 +258,9 @@ const t0 = _template("<div><span> </span> <br> </div>", true)
234258
235259
export function render(_ctx) {
236260
const n3 = t0()
237-
const n0 = _child(n3)
238-
const n1 = _next(n0)
239-
const n2 = _nthChild(n3, 3)
261+
const n0 = _child(n3, 0)
262+
const n1 = _next(n0, 1)
263+
const n2 = _nthChild(n3, 3, 3)
240264
const x0 = _txt(n0)
241265
_setText(x0, _toDisplayString(_ctx.foo))
242266
_renderEffect(() => {

packages/compiler-vapor/__tests__/compile.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,23 @@ describe('compile', () => {
231231
)
232232
})
233233

234+
describe('setInsertionState', () => {
235+
test('next, child and nthChild should be above the setInsertionState', () => {
236+
const code = compile(`
237+
<div>
238+
<div />
239+
<Comp />
240+
<div />
241+
<div v-if="true" />
242+
<div>
243+
<button :disabled="foo" />
244+
</div>
245+
</div>
246+
`)
247+
expect(code).toMatchSnapshot()
248+
})
249+
})
250+
234251
test('with v-once', () => {
235252
const code = compile(
236253
`<div>

packages/compiler-vapor/__tests__/transforms/__snapshots__/expression.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const t0 = _template("<div> </div>", true)
4747
4848
export function render(_ctx) {
4949
const n1 = t0()
50-
const n0 = _child(n1)
50+
const n0 = _child(n1, 0)
5151
const x1 = _txt(n1)
5252
_renderEffect(() => {
5353
const _foo = _ctx.foo
@@ -86,7 +86,7 @@ const t0 = _template("<div> </div>", true)
8686
8787
export function render(_ctx) {
8888
const n1 = t0()
89-
const n0 = _child(n1)
89+
const n0 = _child(n1, 0)
9090
const x1 = _txt(n1)
9191
_renderEffect(() => {
9292
const _String = String

packages/compiler-vapor/__tests__/transforms/__snapshots__/transformChildren.spec.ts.snap

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const t1 = _template("<div><div></div><!><div></div></div>", true)
77
88
export function render(_ctx) {
99
const n4 = t1()
10-
const n3 = _next(_child(n4))
11-
_setInsertionState(n4, n3)
10+
const n3 = _next(_child(n4), 1)
11+
_setInsertionState(n4, n3, true)
1212
const n0 = _createIf(() => (1), () => {
1313
const n2 = t0()
1414
return n2
@@ -23,9 +23,9 @@ const t0 = _template("<div><p> </p> <p> </p></div>", true)
2323
2424
export function render(_ctx) {
2525
const n3 = t0()
26-
const n0 = _child(n3)
27-
const n1 = _next(n0)
28-
const n2 = _next(n1)
26+
const n0 = _child(n3, 0)
27+
const n1 = _next(n0, 1)
28+
const n2 = _next(n1, 2)
2929
const x0 = _txt(n0)
3030
const x2 = _txt(n2)
3131
_renderEffect(() => {
@@ -43,7 +43,7 @@ const t0 = _template("<div><div>x</div><div>x</div><div> </div></div>", true)
4343
4444
export function render(_ctx) {
4545
const n1 = t0()
46-
const n0 = _nthChild(n1, 2)
46+
const n0 = _nthChild(n1, 2, 2)
4747
const x0 = _txt(n0)
4848
_renderEffect(() => _setText(x0, _toDisplayString(_ctx.msg)))
4949
return n1
@@ -56,12 +56,12 @@ const t0 = _template("<div><div>x</div><div><span> </span></div><div><span> </sp
5656
5757
export function render(_ctx) {
5858
const n3 = t0()
59-
const p0 = _next(_child(n3))
60-
const n0 = _child(p0)
61-
const p1 = _next(p0)
62-
const n1 = _child(p1)
63-
const p2 = _next(p1)
64-
const n2 = _child(p2)
59+
const p0 = _next(_child(n3), 1)
60+
const n0 = _child(p0, 0)
61+
const p1 = _next(p0, 2)
62+
const n1 = _child(p1, 0)
63+
const p2 = _next(p1, 3)
64+
const n2 = _child(p2, 0)
6565
const x0 = _txt(n0)
6666
const x1 = _txt(n1)
6767
const x2 = _txt(n2)

packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`compiler: element transform > checkbox with static indeterminate 1`] = `
4+
"import { setProp as _setProp, template as _template } from 'vue';
5+
const t0 = _template("<input type=\\"checkbox\\">", true)
6+
7+
export function render(_ctx) {
8+
const n0 = t0()
9+
_setProp(n0, "indeterminate", "")
10+
return n0
11+
}"
12+
`;
13+
314
exports[`compiler: element transform > component > cache v-on expression with unique handler name 1`] = `
415
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback } from 'vue';
516

packages/compiler-vapor/__tests__/transforms/__snapshots__/vFor.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const t1 = _template("<div></div>", true)
8787
export function render(_ctx) {
8888
const n0 = _createFor(() => (_ctx.list), (_for_item0) => {
8989
const n5 = t1()
90-
_setInsertionState(n5, null)
90+
_setInsertionState(n5, null, true)
9191
const n2 = _createFor(() => (_for_item0.value), (_for_item1) => {
9292
const n4 = t0()
9393
const x4 = _txt(n4)

packages/compiler-vapor/__tests__/transforms/__snapshots__/vIf.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export function render(_ctx) {
149149
const n2 = t0()
150150
return n2
151151
})
152-
_setInsertionState(n8, null)
152+
_setInsertionState(n8, null, true)
153153
const n3 = _createIf(() => (_ctx.bar), () => {
154154
const n5 = t1()
155155
return n5

packages/compiler-vapor/__tests__/transforms/__snapshots__/vOnce.spec.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const t0 = _template("<div> <span></span></div>", true)
1717
1818
export function render(_ctx, $props, $emit, $attrs, $slots) {
1919
const n2 = t0()
20-
const n0 = _child(n2)
21-
const n1 = _next(n0)
20+
const n0 = _child(n2, 0)
21+
const n1 = _next(n0, 1)
2222
_setText(n0, _toDisplayString(_ctx.msg) + " ")
2323
_setClass(n1, _ctx.clz)
2424
return n2
@@ -42,7 +42,7 @@ const t0 = _template("<div></div>", true)
4242
export function render(_ctx) {
4343
const _component_Comp = _resolveComponent("Comp")
4444
const n1 = t0()
45-
_setInsertionState(n1, null)
45+
_setInsertionState(n1, null, true)
4646
const n0 = _createComponentWithFallback(_component_Comp, { id: () => (_ctx.foo) }, null, null, true)
4747
return n1
4848
}"
@@ -54,7 +54,7 @@ const t0 = _template("<div><div></div></div>", true)
5454
5555
export function render(_ctx) {
5656
const n1 = t0()
57-
const n0 = _child(n1)
57+
const n0 = _child(n1, 0)
5858
_setProp(n0, "id", _ctx.foo)
5959
return n1
6060
}"

packages/compiler-vapor/__tests__/transforms/__snapshots__/vSlot.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ export function render(_ctx) {
263263
const n6 = t0()
264264
_setInsertionState(n6, null)
265265
const n0 = _createSlot("foo", null)
266-
_setInsertionState(n6, null)
266+
_setInsertionState(n6, null, true)
267267
const n1 = _createIf(() => (true), () => {
268268
const n3 = _createComponentWithFallback(_component_Foo)
269269
return n3

packages/compiler-vapor/__tests__/transforms/transformChildren.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('compiler: children transform', () => {
5656
<div>{{ msg }}</div>
5757
</div>`,
5858
)
59-
expect(code).contains(`const n0 = _nthChild(n1, 2)`)
59+
expect(code).contains(`const n0 = _nthChild(n1, 2, 2)`)
6060
expect(code).toMatchSnapshot()
6161
})
6262

@@ -69,8 +69,8 @@ describe('compiler: children transform', () => {
6969
</div>`,
7070
)
7171
// ensure the insertion anchor is generated before the insertion statement
72-
expect(code).toMatch(`const n3 = _next(_child(n4))`)
73-
expect(code).toMatch(`_setInsertionState(n4, n3)`)
72+
expect(code).toMatch(`const n3 = _next(_child(n4), 1)`)
73+
expect(code).toMatch(`_setInsertionState(n4, n3, true)`)
7474
expect(code).toMatchSnapshot()
7575
})
7676
})

0 commit comments

Comments
 (0)