diff --git a/packages/compiler-vapor/__tests__/__snapshots__/scopeId.spec.ts.snap b/packages/compiler-vapor/__tests__/__snapshots__/scopeId.spec.ts.snap new file mode 100644 index 00000000000..3d0322ce519 --- /dev/null +++ b/packages/compiler-vapor/__tests__/__snapshots__/scopeId.spec.ts.snap @@ -0,0 +1,69 @@ +// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html + +exports[`scopeId compiler support > should wrap default slot 1`] = ` +"import { resolveComponent as _resolveComponent, withVaporCtx as _withVaporCtx, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue'; +const t0 = _template("
") + +export function render(_ctx) { + const _component_Child = _resolveComponent("Child") + const n1 = _createComponentWithFallback(_component_Child, null, { + "default": _withVaporCtx(() => { + const n0 = t0() + return n0 + }) + }, true) + return n1 +}" +`; + +exports[`scopeId compiler support > should wrap dynamic slots 1`] = ` +"import { resolveComponent as _resolveComponent, withVaporCtx as _withVaporCtx, createForSlots as _createForSlots, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue'; +const t0 = _template("") + +export function render(_ctx) { + const _component_Child = _resolveComponent("Child") + const n4 = _createComponentWithFallback(_component_Child, null, { + $: [ + () => (_ctx.ok + ? { + name: "foo", + fn: _withVaporCtx(() => { + const n0 = t0() + return n0 + }) + } + : void 0), + () => (_createForSlots(_ctx.list, (i) => ({ + name: i, + fn: _withVaporCtx(() => { + const n2 = t0() + return n2 + }) + }))) + ] + }, true) + return n4 +}" +`; + +exports[`scopeId compiler support > should wrap named slots 1`] = ` +"import { resolveComponent as _resolveComponent, toDisplayString as _toDisplayString, setText as _setText, renderEffect as _renderEffect, withVaporCtx as _withVaporCtx, createComponentWithFallback as _createComponentWithFallback, template as _template } from 'vue'; +const t0 = _template(" ") +const t1 = _template("") + +export function render(_ctx) { + const _component_Child = _resolveComponent("Child") + const n4 = _createComponentWithFallback(_component_Child, null, { + "foo": _withVaporCtx((_slotProps0) => { + const n0 = t0() + _renderEffect(() => _setText(n0, _toDisplayString(_slotProps0["msg"]))) + return n0 + }), + "bar": _withVaporCtx(() => { + const n2 = t1() + return n2 + }) + }, true) + return n4 +}" +`; diff --git a/packages/compiler-vapor/__tests__/scopeId.spec.ts b/packages/compiler-vapor/__tests__/scopeId.spec.ts index da17ef5552f..8dfcd0c0d3d 100644 --- a/packages/compiler-vapor/__tests__/scopeId.spec.ts +++ b/packages/compiler-vapor/__tests__/scopeId.spec.ts @@ -1,3 +1,58 @@ -// import { compile } from '../src/compile' +import type { RootNode } from '@vue/compiler-dom' +import { type CompilerOptions, compile as _compile } from '../src' -describe.todo('scopeId compiler support', () => {}) +function compile(template: string | RootNode, options: CompilerOptions = {}) { + let { code } = _compile(template, { + ...options, + mode: 'module', + prefixIdentifiers: true, + }) + return code +} + +/** + * Ensure all slot functions are wrapped with `withVaporCtx` + * which sets the `currentInstance` to owner when rendering + * the slot. + */ +describe('scopeId compiler support', () => { + test('should wrap default slot', () => { + const code = compile(`