Skip to content

Commit 2ed0be8

Browse files
committed
fix(compiler-vapor): quote slot name
1 parent c849864 commit 2ed0be8

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function render(_ctx) {
3535
const _directive_test = _resolveDirective("test")
3636
const n4 = _createComponent(_component_Comp, null, [
3737
{
38-
default: () => {
38+
"default": () => {
3939
const n0 = _createIf(() => (true), () => {
4040
const n3 = t0()
4141
const n2 = _createComponent(_component_Bar)

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

+23-7
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export function render(_ctx) {
102102
const _component_Comp = _resolveComponent("Comp")
103103
const n1 = _createComponent(_component_Comp, null, [
104104
{
105-
default: () => {
105+
"default": () => {
106106
const n0 = t0()
107107
return n0
108108
}
@@ -122,11 +122,11 @@ export function render(_ctx) {
122122
const _component_Comp = _resolveComponent("Comp")
123123
const n4 = _createComponent(_component_Comp, null, [
124124
{
125-
one: () => {
125+
"one": () => {
126126
const n0 = t0()
127127
return n0
128128
},
129-
default: () => {
129+
"default": () => {
130130
const n2 = t1()
131131
const n3 = t2()
132132
return [n2, n3]
@@ -146,11 +146,11 @@ export function render(_ctx) {
146146
const _component_Comp = _resolveComponent("Comp")
147147
const n5 = _createComponent(_component_Comp, null, [
148148
{
149-
default: _withDestructure(({ foo }) => [foo], (_ctx0) => {
149+
"default": _withDestructure(({ foo }) => [foo], (_ctx0) => {
150150
const n2 = t0()
151151
const n1 = _createComponent(_component_Inner, null, [
152152
{
153-
default: _withDestructure(({ bar }) => [bar], (_ctx1) => {
153+
"default": _withDestructure(({ bar }) => [bar], (_ctx1) => {
154154
const n0 = _createTextNode(() => [_ctx0[0] + _ctx1[0] + _ctx.baz])
155155
return n0
156156
})
@@ -190,7 +190,7 @@ export function render(_ctx) {
190190
const _component_Comp = _resolveComponent("Comp")
191191
const n1 = _createComponent(_component_Comp, null, [
192192
{
193-
named: _withDestructure(({ foo }) => [foo], (_ctx0) => {
193+
"named": _withDestructure(({ foo }) => [foo], (_ctx0) => {
194194
const n0 = _createTextNode(() => [_ctx0[0] + _ctx.bar])
195195
return n0
196196
})
@@ -207,7 +207,7 @@ export function render(_ctx) {
207207
const _component_Comp = _resolveComponent("Comp")
208208
const n1 = _createComponent(_component_Comp, null, [
209209
{
210-
default: _withDestructure(({ foo }) => [foo], (_ctx0) => {
210+
"default": _withDestructure(({ foo }) => [foo], (_ctx0) => {
211211
const n0 = _createTextNode(() => [_ctx0[0] + _ctx.bar])
212212
return n0
213213
})
@@ -216,3 +216,19 @@ export function render(_ctx) {
216216
return n1
217217
}"
218218
`;
219+
220+
exports[`compiler: transform slot > quote slot name 1`] = `
221+
"import { resolveComponent as _resolveComponent, createComponent as _createComponent } from 'vue/vapor';
222+
223+
export function render(_ctx) {
224+
const _component_Comp = _resolveComponent("Comp")
225+
const n1 = _createComponent(_component_Comp, null, [
226+
{
227+
"nav-bar-title-before": () => {
228+
return null
229+
}
230+
}
231+
], true)
232+
return n1
233+
}"
234+
`;

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

+8
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ describe('compiler: transform slot', () => {
398398
])
399399
})
400400

401+
test('quote slot name', () => {
402+
const { code } = compileWithSlots(
403+
`<Comp><template #nav-bar-title-before></template></Comp>`,
404+
)
405+
expect(code).toMatchSnapshot()
406+
expect(code).contains(`"nav-bar-title-before"`)
407+
})
408+
401409
describe('errors', () => {
402410
test('error on extraneous children w/ named default slot', () => {
403411
const onError = vi.fn()

packages/compiler-vapor/src/generators/component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ function genStaticSlots({ slots }: IRSlotsStatic, context: CodegenContext) {
175175
return genMulti(
176176
DELIMITERS_OBJECT_NEWLINE,
177177
...names.map(name => [
178-
`${name}: `,
178+
`${JSON.stringify(name)}: `,
179179
...genSlotBlockWithProps(slots[name], context),
180180
]),
181181
)

0 commit comments

Comments
 (0)