Skip to content

Commit a8edf2b

Browse files
committed
refactor: remove outdated slot ctx wrapper codegen
1 parent 2a310df commit a8edf2b

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function render(_ctx, _cache) {
2424
const _component_Child = _resolveComponent(\\"Child\\")
2525
2626
return (_openBlock(), _createBlock(_component_Child, null, {
27-
default: _withId(() => [
27+
default: _withCtx(() => [
2828
_createElementVNode(\\"div\\")
2929
]),
3030
_: 1 /* STABLE */
@@ -42,15 +42,15 @@ export function render(_ctx, _cache) {
4242
(_ctx.ok)
4343
? {
4444
name: \\"foo\\",
45-
fn: _withId(() => [
45+
fn: _withCtx(() => [
4646
_createElementVNode(\\"div\\")
4747
])
4848
}
4949
: undefined,
5050
_renderList(_ctx.list, (i) => {
5151
return {
5252
name: i,
53-
fn: _withId(() => [
53+
fn: _withCtx(() => [
5454
_createElementVNode(\\"div\\")
5555
])
5656
}
@@ -66,10 +66,10 @@ export function render(_ctx, _cache) {
6666
const _component_Child = _resolveComponent(\\"Child\\")
6767
6868
return (_openBlock(), _createBlock(_component_Child, null, {
69-
foo: _withId(({ msg }) => [
69+
foo: _withCtx(({ msg }) => [
7070
_createTextVNode(_toDisplayString(msg), 1 /* TEXT */)
7171
]),
72-
bar: _withId(() => [
72+
bar: _withCtx(() => [
7373
_createElementVNode(\\"div\\")
7474
]),
7575
_: 1 /* STABLE */

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('scopeId compiler support', () => {
2020
mode: 'module',
2121
scopeId: 'test'
2222
})
23-
expect(code).toMatch(`default: _withId(() => [`)
23+
expect(code).toMatch(`default: _withCtx(() => [`)
2424
expect(code).toMatchSnapshot()
2525
})
2626

@@ -36,8 +36,8 @@ describe('scopeId compiler support', () => {
3636
scopeId: 'test'
3737
}
3838
)
39-
expect(code).toMatch(`foo: _withId(({ msg }) => [`)
40-
expect(code).toMatch(`bar: _withId(() => [`)
39+
expect(code).toMatch(`foo: _withCtx(({ msg }) => [`)
40+
expect(code).toMatch(`bar: _withCtx(() => [`)
4141
expect(code).toMatchSnapshot()
4242
})
4343

@@ -53,8 +53,8 @@ describe('scopeId compiler support', () => {
5353
scopeId: 'test'
5454
}
5555
)
56-
expect(code).toMatch(/name: "foo",\s+fn: _withId\(/)
57-
expect(code).toMatch(/name: i,\s+fn: _withId\(/)
56+
expect(code).toMatch(/name: "foo",\s+fn: _withCtx\(/)
57+
expect(code).toMatch(/name: i,\s+fn: _withCtx\(/)
5858
expect(code).toMatchSnapshot()
5959
})
6060

packages/compiler-core/src/codegen.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ import {
5858
import { ImportItem } from './transform'
5959

6060
const PURE_ANNOTATION = `/*#__PURE__*/`
61-
const WITH_ID = `_withId`
6261

6362
type CodegenNode = TemplateChildNode | JSChildNode | SSRCodegenNode
6463

@@ -821,15 +820,11 @@ function genFunctionExpression(
821820
node: FunctionExpression,
822821
context: CodegenContext
823822
) {
824-
const { push, indent, deindent, scopeId, mode } = context
823+
const { push, indent, deindent } = context
825824
const { params, returns, body, newline, isSlot } = node
826-
// slot functions also need to push scopeId before rendering its content
827-
const genScopeId =
828-
!__BROWSER__ && isSlot && scopeId != null && mode !== 'function'
829-
830825
if (isSlot) {
831826
// wrap slot functions with owner context
832-
push(genScopeId ? `${WITH_ID}(` : `_${helperNameMap[WITH_CTX]}(`)
827+
push(`_${helperNameMap[WITH_CTX]}(`)
833828
}
834829
push(`(`, node)
835830
if (isArray(params)) {

packages/compiler-ssr/__tests__/ssrScopeId.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('ssr: scopeId', () => {
3434
const _component_foo = _resolveComponent(\\"foo\\")
3535
3636
_push(_ssrRenderComponent(_component_foo, _attrs, {
37-
default: _withId((_, _push, _parent, _scopeId) => {
37+
default: _withCtx((_, _push, _parent, _scopeId) => {
3838
if (_push) {
3939
_push(\`foo\`)
4040
} else {
@@ -63,7 +63,7 @@ describe('ssr: scopeId', () => {
6363
const _component_foo = _resolveComponent(\\"foo\\")
6464
6565
_push(_ssrRenderComponent(_component_foo, _attrs, {
66-
default: _withId((_, _push, _parent, _scopeId) => {
66+
default: _withCtx((_, _push, _parent, _scopeId) => {
6767
if (_push) {
6868
_push(\`<span data-v-xxxxxxx\${_scopeId}>hello</span>\`)
6969
} else {
@@ -93,11 +93,11 @@ describe('ssr: scopeId', () => {
9393
const _component_bar = _resolveComponent(\\"bar\\")
9494
9595
_push(_ssrRenderComponent(_component_foo, _attrs, {
96-
default: _withId((_, _push, _parent, _scopeId) => {
96+
default: _withCtx((_, _push, _parent, _scopeId) => {
9797
if (_push) {
9898
_push(\`<span data-v-xxxxxxx\${_scopeId}>hello</span>\`)
9999
_push(_ssrRenderComponent(_component_bar, null, {
100-
default: _withId((_, _push, _parent, _scopeId) => {
100+
default: _withCtx((_, _push, _parent, _scopeId) => {
101101
if (_push) {
102102
_push(\`<span data-v-xxxxxxx\${_scopeId}></span>\`)
103103
} else {
@@ -112,7 +112,7 @@ describe('ssr: scopeId', () => {
112112
return [
113113
_createVNode(\\"span\\", null, \\"hello\\"),
114114
_createVNode(_component_bar, null, {
115-
default: _withId(() => [
115+
default: _withCtx(() => [
116116
_createVNode(\\"span\\")
117117
]),
118118
_: 1 /* STABLE */

0 commit comments

Comments
 (0)