From: Evan You Date: Wed, 17 Jul 2024 09:32:31 +0000 (+0800) Subject: chore: Merge branch 'main' into minor X-Git-Tag: v3.5.0-alpha.3~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f15ba2c2e2a107422ae4bfd47f4b260c69218533;p=thirdparty%2Fvuejs%2Fcore.git chore: Merge branch 'main' into minor --- f15ba2c2e2a107422ae4bfd47f4b260c69218533 diff --cc package.json index 7dbd2117a9,e4fa344752..3397c9d939 --- a/package.json +++ b/package.json @@@ -1,7 -1,7 +1,7 @@@ { "private": true, - "version": "3.4.32", + "version": "3.5.0-alpha.2", - "packageManager": "pnpm@9.3.0", + "packageManager": "pnpm@9.5.0", "type": "module", "scripts": { "dev": "node scripts/dev.js", diff --cc packages/compiler-core/__tests__/codegen.spec.ts index 307cbbc8dc,7724d507cb..34386ce693 --- a/packages/compiler-core/__tests__/codegen.spec.ts +++ b/packages/compiler-core/__tests__/codegen.spec.ts @@@ -437,10 -437,10 +437,10 @@@ describe('compiler: codegen', () => expect(code).toMatchSnapshot() }) - test('CacheExpression w/ isVNode: true', () => { + test('CacheExpression w/ isVOnce: true', () => { const { code } = generate( createRoot({ - cached: 1, + cached: [], codegenNode: createCacheExpression( 1, createSimpleExpression(`foo`, false), diff --cc packages/compiler-core/__tests__/transforms/__snapshots__/cacheStatic.spec.ts.snap index fc1446df5e,ef3e2b8f4d..8d0305ee35 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/cacheStatic.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/cacheStatic.spec.ts.snap @@@ -7,9 -13,7 +7,9 @@@ return function render(_ctx, _cache) with (_ctx) { const { createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue - return (_openBlock(), _createElementBlock("div", null, _hoisted_2)) + return (_openBlock(), _createElementBlock("div", null, _cache[0] || (_cache[0] = [ - _createElementVNode("div", { key: "foo" }, null, -1 /* CACHED */) ++ _createElementVNode("div", { key: "foo" }, null, -1 /* HOISTED */) + ]))) } }" `; @@@ -21,16 -34,7 +21,16 @@@ return function render(_ctx, _cache) with (_ctx) { const { createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue - return (_openBlock(), _createElementBlock("div", null, _hoisted_2)) + return (_openBlock(), _createElementBlock("div", null, _cache[0] || (_cache[0] = [ + _createElementVNode("p", null, [ + _createElementVNode("span"), + _createElementVNode("span") - ], -1 /* CACHED */), ++ ], -1 /* HOISTED */), + _createElementVNode("p", null, [ + _createElementVNode("span"), + _createElementVNode("span") - ], -1 /* CACHED */) ++ ], -1 /* HOISTED */) + ]))) } }" `; @@@ -42,11 -54,7 +42,11 @@@ return function render(_ctx, _cache) with (_ctx) { const { createCommentVNode: _createCommentVNode, createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue - return (_openBlock(), _createElementBlock("div", null, _hoisted_2)) + return (_openBlock(), _createElementBlock("div", null, _cache[0] || (_cache[0] = [ + _createElementVNode("div", null, [ + _createCommentVNode("comment") - ], -1 /* CACHED */) ++ ], -1 /* HOISTED */) + ]))) } }" `; @@@ -56,13 -64,17 +56,13 @@@ exports[`compiler: cacheStatic transfor return function render(_ctx, _cache) { with (_ctx) { - const { createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue + const { createElementVNode: _createElementVNode, createTextVNode: _createTextVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue - return (_openBlock(), _createElementBlock("div", null, _hoisted_3)) + return (_openBlock(), _createElementBlock("div", null, _cache[0] || (_cache[0] = [ - _createElementVNode("span", null, null, -1 /* CACHED */), ++ _createElementVNode("span", null, null, -1 /* HOISTED */), + _createTextVNode("foo"), - _createElementVNode("div", null, null, -1 /* CACHED */) ++ _createElementVNode("div", null, null, -1 /* HOISTED */) + ]))) } }" `; @@@ -74,9 -92,7 +74,9 @@@ return function render(_ctx, _cache) with (_ctx) { const { createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue - return (_openBlock(), _createElementBlock("div", null, _hoisted_2)) + return (_openBlock(), _createElementBlock("div", null, _cache[0] || (_cache[0] = [ - _createElementVNode("span", { class: "inline" }, "hello", -1 /* CACHED */) ++ _createElementVNode("span", { class: "inline" }, "hello", -1 /* HOISTED */) + ]))) } }" `; @@@ -145,11 -161,16 +145,11 @@@ exports[`compiler: cacheStatic transfor return function render(_ctx, _cache) { with (_ctx) { - const { toDisplayString: _toDisplayString, normalizeClass: _normalizeClass, createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue + const { toDisplayString: _toDisplayString, createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue - return (_openBlock(), _createElementBlock("div", null, [ - _createElementVNode("span", _hoisted_1, _toDisplayString(_ctx.bar), 1 /* TEXT */) - ])) + return (_openBlock(), _createElementBlock("div", null, _cache[0] || (_cache[0] = [ - _createElementVNode("span", null, "foo " + _toDisplayString(1) + " " + _toDisplayString(true), -1 /* CACHED */) ++ _createElementVNode("span", null, "foo " + _toDisplayString(1) + " " + _toDisplayString(true), -1 /* HOISTED */) + ]))) } }" `; @@@ -161,9 -188,7 +161,9 @@@ return function render(_ctx, _cache) with (_ctx) { const { toDisplayString: _toDisplayString, createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue - return (_openBlock(), _createElementBlock("div", null, _hoisted_2)) + return (_openBlock(), _createElementBlock("div", null, _cache[0] || (_cache[0] = [ - _createElementVNode("span", { foo: 0 }, _toDisplayString(1), -1 /* CACHED */) ++ _createElementVNode("span", { foo: 0 }, _toDisplayString(1), -1 /* HOISTED */) + ]))) } }" `; @@@ -173,15 -198,15 +173,15 @@@ exports[`compiler: cacheStatic transfor return function render(_ctx, _cache) { with (_ctx) { - const { toDisplayString: _toDisplayString, createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue + const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createElementBlock: _createElementBlock, createElementVNode: _createElementVNode } = _Vue - return (_openBlock(), _createElementBlock("div", null, _hoisted_2)) + return (_openBlock(), _createElementBlock("div", null, [ + (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(1, (i) => { + return (_openBlock(), _createElementBlock("div", null, [...(_cache[0] || (_cache[0] = [ - _createElementVNode("span", { class: "hi" }, null, -1 /* CACHED */) ++ _createElementVNode("span", { class: "hi" }, null, -1 /* HOISTED */) + ]))])) + }), 256 /* UNKEYED_FRAGMENT */)) + ])) } }" `; @@@ -215,9 -227,7 +215,9 @@@ return function render(_ctx, _cache) const _directive_foo = _resolveDirective("foo") return (_openBlock(), _createElementBlock("div", null, [ - _withDirectives((_openBlock(), _createElementBlock("svg", null, _hoisted_2)), [ + _withDirectives((_openBlock(), _createElementBlock("svg", null, _cache[0] || (_cache[0] = [ - _createElementVNode("path", { d: "M2,3H5.5L12" }, null, -1 /* CACHED */) ++ _createElementVNode("path", { d: "M2,3H5.5L12" }, null, -1 /* HOISTED */) + ]))), [ [_directive_foo] ]) ])) @@@ -397,15 -401,9 +397,15 @@@ const _hoisted_1 = return function render(_ctx, _cache) { with (_ctx) { - const { openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue + const { createElementVNode: _createElementVNode, openBlock: _openBlock, createElementBlock: _createElementBlock, createCommentVNode: _createCommentVNode } = _Vue - return (_openBlock(), _createElementBlock("div")) + return (_openBlock(), _createElementBlock("div", null, [ + ok + ? (_openBlock(), _createElementBlock("div", _hoisted_1, _cache[0] || (_cache[0] = [ - _createElementVNode("span", null, null, -1 /* CACHED */) ++ _createElementVNode("span", null, null, -1 /* HOISTED */) + ]))) + : _createCommentVNode("v-if", true) + ])) } }" `; @@@ -422,9 -424,7 +422,9 @@@ return function render(_ctx, _cache) return (_openBlock(), _createElementBlock("div", null, [ (_openBlock(true), _createElementBlock(_Fragment, null, _renderList(list, (i) => { - return (_openBlock(), _createElementBlock("div", _hoisted_1, _hoisted_3)) + return (_openBlock(), _createElementBlock("div", _hoisted_1, _cache[0] || (_cache[0] = [ - _createElementVNode("span", null, null, -1 /* CACHED */) ++ _createElementVNode("span", null, null, -1 /* HOISTED */) + ]))) }), 256 /* UNKEYED_FRAGMENT */)) ])) } diff --cc packages/compiler-core/__tests__/transforms/cacheStatic.spec.ts index 8cfe838380,d5a34243bc..ab5ed7baed --- a/packages/compiler-core/__tests__/transforms/cacheStatic.spec.ts +++ b/packages/compiler-core/__tests__/transforms/cacheStatic.spec.ts @@@ -731,37 -594,16 +731,37 @@@ describe('compiler: cacheStatic transfo expect(generate(root).code).toMatchSnapshot() }) - test('clone hoisted array children in HMR mode', () => { - const root = transformWithHoist(`
`, { - hmr: true, - }) - expect(root.hoists.length).toBe(2) - expect(root.codegenNode).toMatchObject({ + test('clone hoisted array children in v-for + HMR mode', () => { + const root = transformWithCache( + `
`, + { + hmr: true, + }, + ) + expect(root.cached.length).toBe(1) + const forBlockCodegen = ( + (root.children[0] as ElementNode).children[0] as ForNode + ).codegenNode + expect(forBlockCodegen).toMatchObject({ + type: NodeTypes.VNODE_CALL, + tag: FRAGMENT, + props: undefined, children: { - content: '[..._hoisted_2]', + type: NodeTypes.JS_CALL_EXPRESSION, + callee: RENDER_LIST, }, - patchFlag: genFlagText(PatchFlags.UNKEYED_FRAGMENT), ++ patchFlag: PatchFlags.UNKEYED_FRAGMENT, }) + const innerBlockCodegen = forBlockCodegen!.children.arguments[1] + expect(innerBlockCodegen.returns).toMatchObject({ + type: NodeTypes.VNODE_CALL, + tag: `"div"`, + children: cachedChildrenArrayMatcher( + ['span'], + true /* needArraySpread */, + ), + }) + expect(generate(root).code).toMatchSnapshot() }) }) }) diff --cc packages/compiler-core/src/ast.ts index 2dec11b029,bbbb7f8a19..3d2ef05dcf --- a/packages/compiler-core/src/ast.ts +++ b/packages/compiler-core/src/ast.ts @@@ -330,9 -330,8 +330,9 @@@ export interface VNodeCall extends Nod | SlotsExpression // component slots | ForRenderListExpression // v-for fragment call | SimpleExpressionNode // hoisted + | CacheExpression // cached | undefined - patchFlag: string | undefined + patchFlag: PatchFlags | undefined dynamicProps: string | SimpleExpressionNode | undefined directives: DirectiveArguments | undefined isBlock: boolean diff --cc packages/compiler-core/src/codegen.ts index 779106d489,b6535c5cef..2798ce989d --- a/packages/compiler-core/src/codegen.ts +++ b/packages/compiler-core/src/codegen.ts @@@ -993,8 -1045,8 +1022,8 @@@ function genCacheExpression(node: Cache } push(`_cache[${node.index}] = `) genNode(node.value, context) - if (node.isVOnce) { + if (needPauseTracking) { - push(`,`) + push(`).cacheIndex = ${node.index},`) newline() push(`${helper(SET_BLOCK_TRACKING)}(1),`) newline() diff --cc packages/compiler-core/src/transforms/cacheStatic.ts index 6b425b6931,5942b73097..6ffd624ff5 --- a/packages/compiler-core/src/transforms/cacheStatic.ts +++ b/packages/compiler-core/src/transforms/cacheStatic.ts @@@ -74,10 -69,10 +74,9 @@@ function walk ? ConstantTypes.NOT_CONSTANT : getConstantType(child, context) if (constantType > ConstantTypes.NOT_CONSTANT) { - if (constantType >= ConstantTypes.CAN_HOIST) { - ;(child.codegenNode as VNodeCall).patchFlag = PatchFlags.HOISTED - child.codegenNode = context.hoist(child.codegenNode!) - hoistedCount++ + if (constantType >= ConstantTypes.CAN_CACHE) { - ;(child.codegenNode as VNodeCall).patchFlag = - PatchFlags.CACHED + (__DEV__ ? ` /* CACHED */` : ``) ++ ;(child.codegenNode as VNodeCall).patchFlag = PatchFlags.CACHED + toCache.push(child) continue } } else { diff --cc packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap index ef0c54d34e,57d880a03f..f55c27a9c6 --- a/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap +++ b/packages/compiler-dom/__tests__/transforms/__snapshots__/stringifyStatic.spec.ts.snap @@@ -20,36 -19,23 +20,36 @@@ return function render(_ctx, _cache) }" `; -exports[`stringify static html > should bail on bindings that are hoisted but not stringifiable 1`] = ` +exports[`stringify static html > should bail for