Skip to content

Commit b3142a7

Browse files
committed
refactor: conditionally generate withVaporCtx for slots only when they contain components or slot outlets.
1 parent bdba4bd commit b3142a7

File tree

15 files changed

+657
-205
lines changed

15 files changed

+657
-205
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,17 @@ export function render(_ctx) {
316316
`;
317317
318318
exports[`compile > expression parsing > v-slot 1`] = `
319-
"import { resolveComponent as _resolveComponent, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, withVaporCtx as _withVaporCtx, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
319+
"import { resolveComponent as _resolveComponent, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
320320
const t0 = _template(" ")
321321
322322
export function render(_ctx) {
323323
const _component_Comp = _resolveComponent("Comp")
324324
const n1 = _createComponentWithFallback(_component_Comp, null, {
325-
"foo": _withVaporCtx((_slotProps0) => {
325+
"foo": (_slotProps0) => {
326326
const n0 = t0()
327327
_renderEffect(() => _setText(n0, _toDisplayString(_slotProps0.a + _slotProps0.b)))
328328
return n0
329-
})
329+
}
330330
}, true)
331331
return n1
332332
}"

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

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

33
exports[`scopeId compiler support > should wrap default slot 1`] = `
4-
"import { resolveComponent as _resolveComponent, withVaporCtx as _withVaporCtx, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
4+
"import { resolveComponent as _resolveComponent, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
55
const t0 = _template("<div></div>")
66
77
export function render(_ctx) {
88
const _component_Child = _resolveComponent("Child")
99
const n1 = _createComponentWithFallback(_component_Child, null, {
10-
"default": _withVaporCtx(() => {
10+
"default": () => {
1111
const n0 = t0()
1212
return n0
13-
})
13+
}
1414
}, true)
1515
return n1
1616
}"
1717
`;
1818

1919
exports[`scopeId compiler support > should wrap dynamic slots 1`] = `
20-
"import { resolveComponent as _resolveComponent, withVaporCtx as _withVaporCtx, createForSlots as _createForSlots, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
20+
"import { resolveComponent as _resolveComponent, createForSlots as _createForSlots, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
2121
const t0 = _template("<div test></div>")
2222
2323
export function render(_ctx) {
@@ -27,18 +27,18 @@ export function render(_ctx) {
2727
() => (_ctx.ok
2828
? {
2929
name: "foo",
30-
fn: _withVaporCtx(() => {
30+
fn: () => {
3131
const n0 = t0()
3232
return n0
33-
})
33+
}
3434
}
3535
: void 0),
3636
() => (_createForSlots(_ctx.list, (i) => ({
3737
name: i,
38-
fn: _withVaporCtx(() => {
38+
fn: () => {
3939
const n2 = t0()
4040
return n2
41-
})
41+
}
4242
})))
4343
]
4444
}, true)
@@ -47,22 +47,22 @@ export function render(_ctx) {
4747
`;
4848

4949
exports[`scopeId compiler support > should wrap named slots 1`] = `
50-
"import { resolveComponent as _resolveComponent, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, withVaporCtx as _withVaporCtx, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
50+
"import { resolveComponent as _resolveComponent, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue';
5151
const t0 = _template(" ")
5252
const t1 = _template("<div test></div>")
5353
5454
export function render(_ctx) {
5555
const _component_Child = _resolveComponent("Child")
5656
const n4 = _createComponentWithFallback(_component_Child, null, {
57-
"foo": _withVaporCtx((_slotProps0) => {
57+
"foo": (_slotProps0) => {
5858
const n0 = t0()
5959
_renderEffect(() => _setText(n0, _toDisplayString(_slotProps0.msg)))
6060
return n0
61-
}),
62-
"bar": _withVaporCtx(() => {
61+
},
62+
"bar": () => {
6363
const n2 = t1()
6464
return n2
65-
})
65+
}
6666
}, true)
6767
return n4
6868
}"

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function compile(template: string | RootNode, options: CompilerOptions = {}) {
1818
describe('scopeId compiler support', () => {
1919
test('should wrap default slot', () => {
2020
const code = compile(`<Child><div/></Child>`)
21-
expect(code).toMatch(`"default": _withVaporCtx(() => {`)
21+
expect(code).toMatch(`"default": () => {`)
2222
expect(code).toMatchSnapshot()
2323
})
2424

@@ -34,8 +34,8 @@ describe('scopeId compiler support', () => {
3434
scopeId: 'test',
3535
},
3636
)
37-
expect(code).toMatch(`"foo": _withVaporCtx((_slotProps0) => {`)
38-
expect(code).toMatch(`"bar": _withVaporCtx(() => {`)
37+
expect(code).toMatch(`"foo": (_slotProps0) => {`)
38+
expect(code).toMatch(`"bar": () => {`)
3939
expect(code).toMatchSnapshot()
4040
})
4141

@@ -51,8 +51,8 @@ describe('scopeId compiler support', () => {
5151
scopeId: 'test',
5252
},
5353
)
54-
expect(code).toMatch(/name: "foo",\s+fn: _withVaporCtx\(/)
55-
expect(code).toMatch(/name: i,\s+fn: _withVaporCtx\(/)
54+
expect(code).toMatch(/name: "foo",\s+fn: \(/)
55+
expect(code).toMatch(/name: i,\s+fn: \(/)
5656
expect(code).toMatchSnapshot()
5757
})
5858
})

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

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

33
exports[`compiler: transition > basic 1`] = `
4-
"import { VaporTransition as _VaporTransition, applyVShow as _applyVShow, withVaporCtx as _withVaporCtx, createComponent as _createComponent, template as _template } from 'vue';
4+
"import { VaporTransition as _VaporTransition, applyVShow as _applyVShow, createComponent as _createComponent, template as _template } from 'vue';
55
const t0 = _template("<h1>foo</h1>")
66
77
export function render(_ctx) {
88
const n1 = _createComponent(_VaporTransition, { persisted: () => ("") }, {
9-
"default": _withVaporCtx(() => {
9+
"default": () => {
1010
const n0 = t0()
1111
_applyVShow(n0, () => (_ctx.show))
1212
return n0
13-
})
13+
}
1414
}, true)
1515
return n1
1616
}"
1717
`;
1818

1919
exports[`compiler: transition > inject persisted when child has v-show 1`] = `
20-
"import { VaporTransition as _VaporTransition, applyVShow as _applyVShow, withVaporCtx as _withVaporCtx, createComponent as _createComponent, template as _template } from 'vue';
20+
"import { VaporTransition as _VaporTransition, applyVShow as _applyVShow, createComponent as _createComponent, template as _template } from 'vue';
2121
const t0 = _template("<div></div>")
2222
2323
export function render(_ctx) {
2424
const n1 = _createComponent(_VaporTransition, { persisted: () => ("") }, {
25-
"default": _withVaporCtx(() => {
25+
"default": () => {
2626
const n0 = t0()
2727
_applyVShow(n0, () => (_ctx.ok))
2828
return n0
29-
})
29+
}
3030
}, true)
3131
return n1
3232
}"
3333
`;
3434

3535
exports[`compiler: transition > the v-if/else-if/else branches in Transition should ignore comments 1`] = `
36-
"import { VaporTransition as _VaporTransition, setInsertionState as _setInsertionState, createIf as _createIf, withVaporCtx as _withVaporCtx, createComponent as _createComponent, template as _template } from 'vue';
36+
"import { VaporTransition as _VaporTransition, setInsertionState as _setInsertionState, createIf as _createIf, createComponent as _createComponent, template as _template } from 'vue';
3737
const t0 = _template("<div>hey</div>")
3838
const t1 = _template("<p></p>")
3939
const t2 = _template("<div></div>")
4040
4141
export function render(_ctx) {
4242
const n16 = _createComponent(_VaporTransition, null, {
43-
"default": _withVaporCtx(() => {
43+
"default": () => {
4444
const n0 = _createIf(() => (_ctx.a), () => {
4545
const n2 = t0()
4646
n2.$key = 2
@@ -63,14 +63,14 @@ export function render(_ctx) {
6363
return n14
6464
}))
6565
return [n0, n3, n7]
66-
})
66+
}
6767
}, true)
6868
return n16
6969
}"
7070
`;
7171

7272
exports[`compiler: transition > v-show + appear 1`] = `
73-
"import { VaporTransition as _VaporTransition, applyVShow as _applyVShow, withVaporCtx as _withVaporCtx, createComponent as _createComponent, template as _template } from 'vue';
73+
"import { VaporTransition as _VaporTransition, applyVShow as _applyVShow, createComponent as _createComponent, template as _template } from 'vue';
7474
const t0 = _template("<h1>foo</h1>")
7575
7676
export function render(_ctx) {
@@ -79,49 +79,49 @@ export function render(_ctx) {
7979
appear: () => (""),
8080
persisted: () => ("")
8181
}, {
82-
"default": _withVaporCtx(() => {
82+
"default": () => {
8383
const n0 = t0()
8484
deferredApplyVShows.push(() => _applyVShow(n0, () => (_ctx.show)))
8585
return n0
86-
})
86+
}
8787
}, true)
8888
deferredApplyVShows.forEach(fn => fn())
8989
return n1
9090
}"
9191
`;
9292

9393
exports[`compiler: transition > work with dynamic keyed children 1`] = `
94-
"import { VaporTransition as _VaporTransition, createKeyedFragment as _createKeyedFragment, withVaporCtx as _withVaporCtx, createComponent as _createComponent, template as _template } from 'vue';
94+
"import { VaporTransition as _VaporTransition, createKeyedFragment as _createKeyedFragment, createComponent as _createComponent, template as _template } from 'vue';
9595
const t0 = _template("<h1>foo</h1>")
9696
9797
export function render(_ctx) {
9898
const n1 = _createComponent(_VaporTransition, null, {
99-
"default": _withVaporCtx(() => {
99+
"default": () => {
100100
return _createKeyedFragment(() => _ctx.key, () => {
101101
const n0 = t0()
102102
n0.$key = _ctx.key
103103
return n0
104104
})
105-
})
105+
}
106106
}, true)
107107
return n1
108108
}"
109109
`;
110110

111111
exports[`compiler: transition > work with v-if 1`] = `
112-
"import { VaporTransition as _VaporTransition, createIf as _createIf, withVaporCtx as _withVaporCtx, createComponent as _createComponent, template as _template } from 'vue';
112+
"import { VaporTransition as _VaporTransition, createIf as _createIf, createComponent as _createComponent, template as _template } from 'vue';
113113
const t0 = _template("<h1>foo</h1>")
114114
115115
export function render(_ctx) {
116116
const n3 = _createComponent(_VaporTransition, null, {
117-
"default": _withVaporCtx(() => {
117+
"default": () => {
118118
const n0 = _createIf(() => (_ctx.show), () => {
119119
const n2 = t0()
120120
n2.$key = 2
121121
return n2
122122
})
123123
return n0
124-
})
124+
}
125125
}, true)
126126
return n3
127127
}"

0 commit comments

Comments
 (0)