Skip to content

Commit 61c8c9b

Browse files
authored
Merge branch 'vapor' into edison/feat/vaporTransition
2 parents 2caeecd + 2696f14 commit 61c8c9b

37 files changed

+1458
-1941
lines changed

packages/compiler-sfc/src/compileScript.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ export function compileScript(
175175
const scriptLang = script && script.lang
176176
const scriptSetupLang = scriptSetup && scriptSetup.lang
177177
const vapor = sfc.vapor || options.vapor
178+
const ssr = options.templateOptions?.ssr
178179

179180
if (!scriptSetup) {
180181
if (!script) {
@@ -749,7 +750,7 @@ export function compileScript(
749750
if (
750751
sfc.cssVars.length &&
751752
// no need to do this when targeting SSR
752-
!options.templateOptions?.ssr
753+
!ssr
753754
) {
754755
ctx.helperImports.add(CSS_VARS_HELPER)
755756
ctx.helperImports.add('unref')
@@ -859,7 +860,7 @@ export function compileScript(
859860
} else {
860861
// inline mode
861862
if (sfc.template && !sfc.template.src) {
862-
if (options.templateOptions && options.templateOptions.ssr) {
863+
if (ssr) {
863864
hasInlinedSsrRenderFn = true
864865
}
865866
// inline render function mode - we are going to compile the template and
@@ -933,7 +934,7 @@ export function compileScript(
933934
ctx.s.appendRight(
934935
endOffset,
935936
// vapor mode generates its own return when inlined
936-
`\n${vapor ? `` : `return `}${returned}\n}\n\n`,
937+
`\n${vapor && !ssr ? `` : `return `}${returned}\n}\n\n`,
937938
)
938939
}
939940

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function render(_ctx) {
2626
`;
2727

2828
exports[`compile > custom directive > component 1`] = `
29-
"import { resolveComponent as _resolveComponent, resolveDirective as _resolveDirective, createComponentWithFallback as _createComponentWithFallback, withVaporDirectives as _withVaporDirectives, insert as _insert, createIf as _createIf, template as _template } from 'vue';
29+
"import { resolveComponent as _resolveComponent, resolveDirective as _resolveDirective, setInsertionState as _setInsertionState, createComponentWithFallback as _createComponentWithFallback, withVaporDirectives as _withVaporDirectives, createIf as _createIf, template as _template } from 'vue';
3030
const t0 = _template("<div></div>")
3131
3232
export function render(_ctx) {
@@ -38,9 +38,9 @@ export function render(_ctx) {
3838
"default": () => {
3939
const n0 = _createIf(() => (true), () => {
4040
const n3 = t0()
41+
_setInsertionState(n3)
4142
const n2 = _createComponentWithFallback(_component_Bar)
4243
_withVaporDirectives(n2, [[_directive_hello, void 0, void 0, { world: true }]])
43-
_insert(n2, n3)
4444
return n3
4545
})
4646
return n0
@@ -149,17 +149,17 @@ export function render(_ctx, $props, $emit, $attrs, $slots) {
149149
`;
150150
151151
exports[`compile > directives > v-pre > should not affect siblings after it 1`] = `
152-
"import { resolveComponent as _resolveComponent, child as _child, createComponentWithFallback as _createComponentWithFallback, prepend as _prepend, toDisplayString as _toDisplayString, setText as _setText, setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
152+
"import { resolveComponent as _resolveComponent, setInsertionState as _setInsertionState, createComponentWithFallback as _createComponentWithFallback, child as _child, toDisplayString as _toDisplayString, setText as _setText, setProp as _setProp, renderEffect as _renderEffect, template as _template } from 'vue';
153153
const t0 = _template("<div :id=\\"foo\\"><Comp></Comp>{{ bar }}</div>")
154154
const t1 = _template("<div> </div>")
155155
156156
export function render(_ctx, $props, $emit, $attrs, $slots) {
157157
const _component_Comp = _resolveComponent("Comp")
158158
const n0 = t0()
159159
const n3 = t1()
160-
const n2 = _child(n3)
160+
_setInsertionState(n3, 0)
161161
const n1 = _createComponentWithFallback(_component_Comp)
162-
_prepend(n3, n1)
162+
const n2 = _child(n3)
163163
_renderEffect(() => {
164164
_setText(n2, _toDisplayString(_ctx.bar))
165165
_setProp(n3, "id", _ctx.foo)

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

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

3+
exports[`compiler: children transform > anchor insertion in middle 1`] = `
4+
"import { child as _child, next as _next, setInsertionState as _setInsertionState, createIf as _createIf, template as _template } from 'vue';
5+
const t0 = _template("<div></div>")
6+
const t1 = _template("<div><div></div><!><div></div></div>", true)
7+
8+
export function render(_ctx) {
9+
const n4 = t1()
10+
const n3 = _next(_child(n4))
11+
_setInsertionState(n4, n3)
12+
const n0 = _createIf(() => (1), () => {
13+
const n2 = t0()
14+
return n2
15+
}, null, true)
16+
return n4
17+
}"
18+
`;
19+
320
exports[`compiler: children transform > children & sibling references 1`] = `
421
"import { child as _child, next as _next, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, template as _template } from 'vue';
522
const t0 = _template("<div><p> </p> <p> </p></div>", true)
@@ -40,10 +57,10 @@ const t0 = _template("<div><div>x</div><div><span> </span></div><div><span> </sp
4057
export function render(_ctx) {
4158
const n3 = t0()
4259
const p0 = _next(_child(n3))
43-
const n0 = _child(p0)
4460
const p1 = _next(p0)
45-
const n1 = _child(p1)
4661
const p2 = _next(p1)
62+
const n0 = _child(p0)
63+
const n1 = _child(p1)
4764
const n2 = _child(p2)
4865
const x0 = _child(n0)
4966
const x1 = _child(n1)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ exports[`compiler: element transform > component > generate multi root component
2929
const t0 = _template("123")
3030
3131
export function render(_ctx, $props, $emit, $attrs, $slots) {
32-
const n1 = t0()
3332
const n0 = _createComponent(_ctx.Comp)
33+
const n1 = t0()
3434
return [n0, n1]
3535
}"
3636
`;
@@ -321,8 +321,8 @@ const t2 = _template("<form></form>")
321321
322322
export function render(_ctx) {
323323
const n1 = t1()
324-
const n0 = t0()
325324
const n3 = t2()
325+
const n0 = t0()
326326
const n2 = t2()
327327
_insert(n0, n1)
328328
_insert(n2, n3)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ export function render(_ctx) {
6565
`;
6666

6767
exports[`compiler: v-for > nested v-for 1`] = `
68-
"import { child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, insert as _insert, template as _template } from 'vue';
68+
"import { setInsertionState as _setInsertionState, child as _child, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createFor as _createFor, template as _template } from 'vue';
6969
const t0 = _template("<span> </span>")
7070
const t1 = _template("<div></div>", true)
7171
7272
export function render(_ctx) {
7373
const n0 = _createFor(() => (_ctx.list), (_for_item0) => {
7474
const n5 = t1()
75+
_setInsertionState(n5)
7576
const n2 = _createFor(() => (_for_item0.value), (_for_item1) => {
7677
const n4 = t0()
7778
const x4 = _child(n4)
7879
_renderEffect(() => _setText(x4, _toDisplayString(_for_item1.value+_for_item0.value)))
7980
return n4
8081
}, null, 1)
81-
_insert(n2, n5)
8282
return n5
8383
})
8484
return n0

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const t4 = _template("fine")
2525
const t5 = _template("<div> </div>")
2626
2727
export function render(_ctx) {
28-
const n13 = t5()
2928
const n0 = _createIf(() => (_ctx.ok), () => {
3029
const n2 = t0()
3130
return n2
@@ -38,6 +37,7 @@ export function render(_ctx) {
3837
const n11 = t4()
3938
return [n10, n11]
4039
}))
40+
const n13 = t5()
4141
const x13 = _child(n13)
4242
_renderEffect(() => _setText(x13, _toDisplayString(_ctx.text)))
4343
return [n0, n13]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ export function render(_ctx) {
3636
`;
3737

3838
exports[`compiler: v-once > on component 1`] = `
39-
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback, insert as _insert, template as _template } from 'vue';
39+
"import { resolveComponent as _resolveComponent, setInsertionState as _setInsertionState, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
4040
const t0 = _template("<div></div>", true)
4141
4242
export function render(_ctx) {
4343
const _component_Comp = _resolveComponent("Comp")
4444
const n1 = t0()
45+
_setInsertionState(n1)
4546
const n0 = _createComponentWithFallback(_component_Comp, { id: () => (_ctx.foo) }, null, null, true)
46-
_insert(n0, n1)
4747
return n1
4848
}"
4949
`;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ export function render(_ctx) {
167167
const _component_Comp = _resolveComponent("Comp")
168168
const n5 = _createComponentWithFallback(_component_Comp, null, {
169169
"default": (_slotProps0) => {
170-
const n3 = t0()
171170
const n1 = _createComponentWithFallback(_component_Inner, null, {
172171
"default": (_slotProps1) => {
173172
const n0 = t0()
174173
_renderEffect(() => _setText(n0, _toDisplayString(_slotProps0["foo"] + _slotProps1["bar"] + _ctx.baz)))
175174
return n0
176175
}
177176
})
177+
const n3 = t0()
178178
_renderEffect(() => _setText(n3, " " + _toDisplayString(_slotProps0["foo"] + _ctx.bar + _ctx.baz)))
179179
return [n1, n3]
180180
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,18 @@ describe('compiler: children transform', () => {
5959
expect(code).contains(`const n0 = _nthChild(n1, 2)`)
6060
expect(code).toMatchSnapshot()
6161
})
62+
63+
test('anchor insertion in middle', () => {
64+
const { code } = compileWithElementTransform(
65+
`<div>
66+
<div></div>
67+
<div v-if="1"></div>
68+
<div></div>
69+
</div>`,
70+
)
71+
// ensure the insertion anchor is generated before the insertion statement
72+
expect(code).toMatch(`const n3 = _next(_child(n4))
73+
_setInsertionState(n4, n3)`)
74+
expect(code).toMatchSnapshot()
75+
})
6276
})

0 commit comments

Comments
 (0)