Skip to content

Commit cd0ea0d

Browse files
authored
fix(compiler-core): change node hoisting to caching per instance (#11067)
close #5256 close #9219 close #10959
1 parent f8eba75 commit cd0ea0d

35 files changed

+1167
-1065
lines changed

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

+56-56
Large diffs are not rendered by default.

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

-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`scopeId compiler support > should push scopeId for hoisted nodes 1`] = `
4-
"import { createElementVNode as _createElementVNode, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, openBlock as _openBlock, createElementBlock as _createElementBlock, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue"
5-
6-
const _withScopeId = n => (_pushScopeId("test"),n=n(),_popScopeId(),n)
7-
const _hoisted_1 = /*#__PURE__*/ _withScopeId(() => /*#__PURE__*/_createElementVNode("div", null, "hello", -1 /* HOISTED */))
8-
const _hoisted_2 = /*#__PURE__*/ _withScopeId(() => /*#__PURE__*/_createElementVNode("div", null, "world", -1 /* HOISTED */))
9-
10-
export function render(_ctx, _cache) {
11-
return (_openBlock(), _createElementBlock("div", null, [
12-
_hoisted_1,
13-
_createTextVNode(_toDisplayString(_ctx.foo), 1 /* TEXT */),
14-
_hoisted_2
15-
]))
16-
}"
17-
`;
18-
193
exports[`scopeId compiler support > should wrap default slot 1`] = `
204
"import { createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock } from "vue"
215

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function createRoot(options: Partial<RootNode> = {}): RootNode {
4747
directives: [],
4848
imports: [],
4949
hoists: [],
50-
cached: 0,
50+
cached: [],
5151
temps: 0,
5252
codegenNode: createSimpleExpression(`null`, false),
5353
loc: locStub,
@@ -422,7 +422,7 @@ describe('compiler: codegen', () => {
422422
test('CacheExpression', () => {
423423
const { code } = generate(
424424
createRoot({
425-
cached: 1,
425+
cached: [],
426426
codegenNode: createCacheExpression(
427427
1,
428428
createSimpleExpression(`foo`, false),
@@ -440,7 +440,7 @@ describe('compiler: codegen', () => {
440440
test('CacheExpression w/ isVNode: true', () => {
441441
const { code } = generate(
442442
createRoot({
443-
cached: 1,
443+
cached: [],
444444
codegenNode: createCacheExpression(
445445
1,
446446
createSimpleExpression(`foo`, false),

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

-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import { baseCompile } from '../src/compile'
2-
import { POP_SCOPE_ID, PUSH_SCOPE_ID } from '../src/runtimeHelpers'
3-
import { PatchFlags } from '@vue/shared'
4-
import { genFlagText } from './testUtils'
52

63
/**
74
* Ensure all slot functions are wrapped with _withCtx
@@ -57,28 +54,4 @@ describe('scopeId compiler support', () => {
5754
expect(code).toMatch(/name: i,\s+fn: _withCtx\(/)
5855
expect(code).toMatchSnapshot()
5956
})
60-
61-
test('should push scopeId for hoisted nodes', () => {
62-
const { ast, code } = baseCompile(
63-
`<div><div>hello</div>{{ foo }}<div>world</div></div>`,
64-
{
65-
mode: 'module',
66-
scopeId: 'test',
67-
hoistStatic: true,
68-
},
69-
)
70-
expect(ast.helpers).toContain(PUSH_SCOPE_ID)
71-
expect(ast.helpers).toContain(POP_SCOPE_ID)
72-
expect(ast.hoists.length).toBe(2)
73-
;[
74-
`const _withScopeId = n => (_pushScopeId("test"),n=n(),_popScopeId(),n)`,
75-
`const _hoisted_1 = /*#__PURE__*/ _withScopeId(() => /*#__PURE__*/_createElementVNode("div", null, "hello", ${genFlagText(
76-
PatchFlags.HOISTED,
77-
)}))`,
78-
`const _hoisted_2 = /*#__PURE__*/ _withScopeId(() => /*#__PURE__*/_createElementVNode("div", null, "world", ${genFlagText(
79-
PatchFlags.HOISTED,
80-
)}))`,
81-
].forEach(c => expect(code).toMatch(c))
82-
expect(code).toMatchSnapshot()
83-
})
8457
})

0 commit comments

Comments
 (0)