diff --git a/jest.config.js b/jest.config.js index 385de9c49..ebc6e76eb 100644 --- a/jest.config.js +++ b/jest.config.js @@ -19,7 +19,7 @@ module.exports = { '!packages/template-explorer/**', '!packages/size-check/**' ], - watchPathIgnorePatterns: ['/node_modules/'], + watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'], moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], moduleNameMapper: { '^@vue/(.*?)$': '/packages/$1/src', diff --git a/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap index 8adf793ee..d70c5b3bd 100644 --- a/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap @@ -59,15 +59,6 @@ return function render(_ctx, _cache) { }" `; -exports[`compiler: codegen SequenceExpression 1`] = ` -" -return function render(_ctx, _cache) { - with (this) { - return (foo, bar(baz)) - } -}" -`; - exports[`compiler: codegen assets + temps 1`] = ` " return function render(_ctx, _cache) { @@ -106,7 +97,7 @@ exports[`compiler: codegen forNode 1`] = ` " return function render(_ctx, _cache) { with (this) { - return (foo, bar) + return (_openBlock(true), _createBlock(_Fragment, null, _renderList(), 1)) } }" `; @@ -147,7 +138,9 @@ exports[`compiler: codegen ifNode 1`] = ` " return function render(_ctx, _cache) { with (this) { - return (foo, bar) + return foo + ? bar + : baz } }" `; diff --git a/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap index 7afb6ffde..77a37d3a1 100644 --- a/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap @@ -12,9 +12,9 @@ return function render(_ctx, _cache) { class: bar.baz }, [ _createTextVNode(_toDisplayString(world.burn()) + \\" \\", 1 /* TEXT */), - (_openBlock(), ok - ? _createBlock(\\"div\\", { key: 0 }, \\"yes\\") - : _createBlock(_Fragment, { key: 1 }, [\\"no\\"])), + ok + ? (_openBlock(), _createBlock(\\"div\\", { key: 0 }, \\"yes\\")) + : (_openBlock(), _createBlock(_Fragment, { key: 1 }, [\\"no\\"])), (_openBlock(true), _createBlock(_Fragment, null, _renderList(list, (value, index) => { return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */) @@ -34,9 +34,9 @@ return function render(_ctx, _cache) { class: _ctx.bar.baz }, [ _createTextVNode(_toDisplayString(_ctx.world.burn()) + \\" \\", 1 /* TEXT */), - (_openBlock(), (_ctx.ok) - ? _createBlock(\\"div\\", { key: 0 }, \\"yes\\") - : _createBlock(_Fragment, { key: 1 }, [\\"no\\"])), + (_ctx.ok) + ? (_openBlock(), _createBlock(\\"div\\", { key: 0 }, \\"yes\\")) + : (_openBlock(), _createBlock(_Fragment, { key: 1 }, [\\"no\\"])), (_openBlock(true), _createBlock(_Fragment, null, _renderList(_ctx.list, (value, index) => { return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */) @@ -55,9 +55,9 @@ export function render(_ctx, _cache) { class: _ctx.bar.baz }, [ _createTextVNode(_toDisplayString(_ctx.world.burn()) + \\" \\", 1 /* TEXT */), - (_openBlock(), (_ctx.ok) - ? _createBlock(\\"div\\", { key: 0 }, \\"yes\\") - : _createBlock(_Fragment, { key: 1 }, [\\"no\\"])), + (_ctx.ok) + ? (_openBlock(), _createBlock(\\"div\\", { key: 0 }, \\"yes\\")) + : (_openBlock(), _createBlock(_Fragment, { key: 1 }, [\\"no\\"])), (_openBlock(true), _createBlock(_Fragment, null, _renderList(_ctx.list, (value, index) => { return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */) diff --git a/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap index 6193c0acd..c552bfe8d 100644 --- a/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`scopeId compiler support should push scopeId for hoisted nodes 1`] = ` -"import { createVNode as _createVNode, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, createBlock as _createBlock, openBlock as _openBlock, withScopeId as _withScopeId, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from \\"vue\\" +"import { createVNode as _createVNode, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from \\"vue\\" const _withId = _withScopeId(\\"test\\") _pushScopeId(\\"test\\") @@ -19,7 +19,7 @@ export const render = _withId(function render(_ctx, _cache) { `; exports[`scopeId compiler support should wrap default slot 1`] = ` -"import { createVNode as _createVNode, resolveComponent as _resolveComponent, createBlock as _createBlock, openBlock as _openBlock, withScopeId as _withScopeId } from \\"vue\\" +"import { createVNode as _createVNode, resolveComponent as _resolveComponent, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\" const _withId = _withScopeId(\\"test\\") export const render = _withId(function render(_ctx, _cache) { @@ -35,7 +35,7 @@ export const render = _withId(function render(_ctx, _cache) { `; exports[`scopeId compiler support should wrap dynamic slots 1`] = ` -"import { createVNode as _createVNode, resolveComponent as _resolveComponent, renderList as _renderList, createSlots as _createSlots, createBlock as _createBlock, openBlock as _openBlock, withScopeId as _withScopeId } from \\"vue\\" +"import { createVNode as _createVNode, resolveComponent as _resolveComponent, renderList as _renderList, createSlots as _createSlots, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\" const _withId = _withScopeId(\\"test\\") export const render = _withId(function render(_ctx, _cache) { @@ -63,7 +63,7 @@ export const render = _withId(function render(_ctx, _cache) { `; exports[`scopeId compiler support should wrap named slots 1`] = ` -"import { toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, createVNode as _createVNode, resolveComponent as _resolveComponent, createBlock as _createBlock, openBlock as _openBlock, withScopeId as _withScopeId } from \\"vue\\" +"import { toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, createVNode as _createVNode, resolveComponent as _resolveComponent, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\" const _withId = _withScopeId(\\"test\\") export const render = _withId(function render(_ctx, _cache) { @@ -82,7 +82,7 @@ export const render = _withId(function render(_ctx, _cache) { `; exports[`scopeId compiler support should wrap render function 1`] = ` -"import { createVNode as _createVNode, createBlock as _createBlock, openBlock as _openBlock, withScopeId as _withScopeId } from \\"vue\\" +"import { createVNode as _createVNode, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\" const _withId = _withScopeId(\\"test\\") export const render = _withId(function render(_ctx, _cache) { diff --git a/packages/compiler-core/__tests__/codegen.spec.ts b/packages/compiler-core/__tests__/codegen.spec.ts index 02add36a5..929588f4e 100644 --- a/packages/compiler-core/__tests__/codegen.spec.ts +++ b/packages/compiler-core/__tests__/codegen.spec.ts @@ -9,16 +9,18 @@ import { createArrayExpression, createCompoundExpression, createInterpolation, - createSequenceExpression, createCallExpression, createConditionalExpression, - IfCodegenNode, ForCodegenNode, createCacheExpression, createTemplateLiteral, createBlockStatement, createIfStatement, - createAssignmentExpression + createAssignmentExpression, + IfConditionalExpression, + createVNodeCall, + VNodeCall, + DirectiveArguments } from '../src' import { CREATE_VNODE, @@ -26,7 +28,9 @@ import { RESOLVE_DIRECTIVE, helperNameMap, RESOLVE_COMPONENT, - CREATE_COMMENT + CREATE_COMMENT, + FRAGMENT, + RENDER_LIST } from '../src/runtimeHelpers' import { createElementWithCodegen } from './testUtils' import { PatchFlags } from '@vue/shared' @@ -251,14 +255,15 @@ describe('compiler: codegen', () => { type: NodeTypes.IF, loc: locStub, branches: [], - codegenNode: createSequenceExpression([ + codegenNode: createConditionalExpression( createSimpleExpression('foo', false), - createSimpleExpression('bar', false) - ]) as IfCodegenNode + createSimpleExpression('bar', false), + createSimpleExpression('baz', false) + ) as IfConditionalExpression } }) ) - expect(code).toMatch(`return (foo, bar)`) + expect(code).toMatch(/return foo\s+\? bar\s+: baz/) expect(code).toMatchSnapshot() }) @@ -274,21 +279,29 @@ describe('compiler: codegen', () => { objectIndexAlias: undefined, children: [], parseResult: {} as any, - codegenNode: createSequenceExpression([ - createSimpleExpression('foo', false), - createSimpleExpression('bar', false) - ]) as ForCodegenNode + codegenNode: { + type: NodeTypes.VNODE_CALL, + tag: FRAGMENT, + isBlock: true, + isForBlock: true, + props: undefined, + children: createCallExpression(RENDER_LIST), + patchFlag: '1', + dynamicProps: undefined, + directives: undefined, + loc: locStub + } as ForCodegenNode } }) ) - expect(code).toMatch(`return (foo, bar)`) + expect(code).toMatch(`openBlock(true)`) expect(code).toMatchSnapshot() }) test('Element (callExpression + objectExpression + TemplateChildNode[])', () => { const { code } = generate( createRoot({ - codegenNode: createElementWithCodegen([ + codegenNode: createElementWithCodegen( // string `"div"`, // ObjectExpression @@ -319,7 +332,7 @@ describe('compiler: codegen', () => { ), // ChildNode[] [ - createElementWithCodegen([ + createElementWithCodegen( `"p"`, createObjectExpression( [ @@ -331,11 +344,11 @@ describe('compiler: codegen', () => { ], locStub ) - ]) + ) ], // flag PatchFlags.FULL_PROPS + '' - ]) + ) }) ) expect(code).toMatch(` @@ -365,19 +378,6 @@ describe('compiler: codegen', () => { expect(code).toMatchSnapshot() }) - test('SequenceExpression', () => { - const { code } = generate( - createRoot({ - codegenNode: createSequenceExpression([ - createSimpleExpression(`foo`, false), - createCallExpression(`bar`, [`baz`]) - ]) - }) - ) - expect(code).toMatch(`return (foo, bar(baz))`) - expect(code).toMatchSnapshot() - }) - test('ConditionalExpression', () => { const { code } = generate( createRoot({ @@ -595,4 +595,149 @@ describe('compiler: codegen', () => { }" `) }) + + describe('VNodeCall', () => { + function genCode(node: VNodeCall) { + return generate( + createRoot({ + codegenNode: node + }) + ).code.match(/with \(this\) \{\s+([^]+)\s+\}\s+\}$/)![1] + } + + const mockProps = createObjectExpression([ + createObjectProperty(`foo`, createSimpleExpression(`bar`, true)) + ]) + const mockChildren = createCompoundExpression(['children']) + const mockDirs = createArrayExpression([ + createArrayExpression([`foo`, createSimpleExpression(`bar`, false)]) + ]) as DirectiveArguments + + test('tag only', () => { + expect(genCode(createVNodeCall(null, `"div"`))).toMatchInlineSnapshot(` + "return _createVNode(\\"div\\") + " + `) + expect(genCode(createVNodeCall(null, FRAGMENT))).toMatchInlineSnapshot(` + "return _createVNode(_Fragment) + " + `) + }) + + test('with props', () => { + expect(genCode(createVNodeCall(null, `"div"`, mockProps))) + .toMatchInlineSnapshot(` + "return _createVNode(\\"div\\", { foo: \\"bar\\" }) + " + `) + }) + + test('with children, no props', () => { + expect(genCode(createVNodeCall(null, `"div"`, undefined, mockChildren))) + .toMatchInlineSnapshot(` + "return _createVNode(\\"div\\", null, children) + " + `) + }) + + test('with children + props', () => { + expect(genCode(createVNodeCall(null, `"div"`, mockProps, mockChildren))) + .toMatchInlineSnapshot(` + "return _createVNode(\\"div\\", { foo: \\"bar\\" }, children) + " + `) + }) + + test('with patchFlag and no children/props', () => { + expect(genCode(createVNodeCall(null, `"div"`, undefined, undefined, '1'))) + .toMatchInlineSnapshot(` + "return _createVNode(\\"div\\", null, null, 1) + " + `) + }) + + test('as block', () => { + expect( + genCode( + createVNodeCall( + null, + `"div"`, + mockProps, + mockChildren, + undefined, + undefined, + undefined, + true + ) + ) + ).toMatchInlineSnapshot(` + "return (_openBlock(), _createBlock(\\"div\\", { foo: \\"bar\\" }, children)) + " + `) + }) + + test('as for block', () => { + expect( + genCode( + createVNodeCall( + null, + `"div"`, + mockProps, + mockChildren, + undefined, + undefined, + undefined, + true, + true + ) + ) + ).toMatchInlineSnapshot(` + "return (_openBlock(true), _createBlock(\\"div\\", { foo: \\"bar\\" }, children)) + " + `) + }) + + test('with directives', () => { + expect( + genCode( + createVNodeCall( + null, + `"div"`, + mockProps, + mockChildren, + undefined, + undefined, + mockDirs + ) + ) + ).toMatchInlineSnapshot(` + "return _withDirectives(_createVNode(\\"div\\", { foo: \\"bar\\" }, children), [ + [foo, bar] + ]) + " + `) + }) + + test('block + directives', () => { + expect( + genCode( + createVNodeCall( + null, + `"div"`, + mockProps, + mockChildren, + undefined, + undefined, + mockDirs, + true + ) + ) + ).toMatchInlineSnapshot(` + "return _withDirectives((_openBlock(), _createBlock(\\"div\\", { foo: \\"bar\\" }, children)), [ + [foo, bar] + ]) + " + `) + }) + }) }) diff --git a/packages/compiler-core/__tests__/testUtils.ts b/packages/compiler-core/__tests__/testUtils.ts index 8839cd12f..300873fac 100644 --- a/packages/compiler-core/__tests__/testUtils.ts +++ b/packages/compiler-core/__tests__/testUtils.ts @@ -4,9 +4,8 @@ import { locStub, Namespaces, ElementTypes, - PlainElementCodegenNode + VNodeCall } from '../src' -import { CREATE_VNODE } from '../src/runtimeHelpers' import { isString, PatchFlags, PatchFlagNames, isArray } from '@vue/shared' const leadingBracketRE = /^\[/ @@ -39,7 +38,11 @@ export function createObjectMatcher(obj: Record) { } export function createElementWithCodegen( - args: PlainElementCodegenNode['arguments'] + tag: VNodeCall['tag'], + props?: VNodeCall['props'], + children?: VNodeCall['children'], + patchFlag?: VNodeCall['patchFlag'], + dynamicProps?: VNodeCall['dynamicProps'] ): ElementNode { return { type: NodeTypes.ELEMENT, @@ -51,10 +54,16 @@ export function createElementWithCodegen( props: [], children: [], codegenNode: { - type: NodeTypes.JS_CALL_EXPRESSION, - loc: locStub, - callee: CREATE_VNODE, - arguments: args + type: NodeTypes.VNODE_CALL, + tag, + props, + children, + patchFlag, + dynamicProps, + directives: undefined, + isBlock: false, + isForBlock: false, + loc: locStub } } } diff --git a/packages/compiler-core/__tests__/transform.spec.ts b/packages/compiler-core/__tests__/transform.spec.ts index d1b2bbd03..aededa2cc 100644 --- a/packages/compiler-core/__tests__/transform.spec.ts +++ b/packages/compiler-core/__tests__/transform.spec.ts @@ -4,16 +4,14 @@ import { ElementNode, NodeTypes, DirectiveNode, - ExpressionNode + ExpressionNode, + VNodeCall } from '../src/ast' import { ErrorCodes, createCompilerError } from '../src/errors' import { TO_DISPLAY_STRING, - OPEN_BLOCK, - CREATE_BLOCK, FRAGMENT, RENDER_SLOT, - WITH_DIRECTIVES, CREATE_COMMENT } from '../src/runtimeHelpers' import { transformIf } from '../src/transforms/vIf' @@ -251,20 +249,19 @@ describe('compiler: transform', () => { return ast } - function createBlockMatcher(args: any[]) { + function createBlockMatcher( + tag: VNodeCall['tag'], + props?: VNodeCall['props'], + children?: VNodeCall['children'], + patchFlag?: VNodeCall['patchFlag'] + ) { return { - type: NodeTypes.JS_SEQUENCE_EXPRESSION, - expressions: [ - { - type: NodeTypes.JS_CALL_EXPRESSION, - callee: OPEN_BLOCK - }, - { - type: NodeTypes.JS_CALL_EXPRESSION, - callee: CREATE_BLOCK, - arguments: args - } - ] + type: NodeTypes.VNODE_CALL, + isBlock: true, + tag, + props, + children, + patchFlag } } @@ -285,7 +282,7 @@ describe('compiler: transform', () => { test('single element', () => { const ast = transformWithCodegen(`
`) - expect(ast.codegenNode).toMatchObject(createBlockMatcher([`"div"`])) + expect(ast.codegenNode).toMatchObject(createBlockMatcher(`"div"`)) }) test('root v-if', () => { @@ -305,22 +302,8 @@ describe('compiler: transform', () => { test('root element with custom directive', () => { const ast = transformWithCodegen(`
`) expect(ast.codegenNode).toMatchObject({ - type: NodeTypes.JS_SEQUENCE_EXPRESSION, - expressions: [ - { - type: NodeTypes.JS_CALL_EXPRESSION, - callee: OPEN_BLOCK - }, - { - type: NodeTypes.JS_CALL_EXPRESSION, - // should wrap withDirectives() around createBlock() - callee: WITH_DIRECTIVES, - arguments: [ - { callee: CREATE_BLOCK }, - { type: NodeTypes.JS_ARRAY_EXPRESSION } - ] - } - ] + type: NodeTypes.VNODE_CALL, + directives: { type: NodeTypes.JS_ARRAY_EXPRESSION } }) }) @@ -348,15 +331,15 @@ describe('compiler: transform', () => { test('multiple children', () => { const ast = transformWithCodegen(`
`) expect(ast.codegenNode).toMatchObject( - createBlockMatcher([ + createBlockMatcher( FRAGMENT, - `null`, + undefined, [ { type: NodeTypes.ELEMENT, tag: `div` }, { type: NodeTypes.ELEMENT, tag: `div` } - ], + ] as any, genFlagText(PatchFlags.STABLE_FRAGMENT) - ]) + ) ) }) }) diff --git a/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap b/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap index c3678c7ad..f4f1936b5 100644 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap @@ -8,7 +8,7 @@ const _hoisted_1 = _createVNode(\\"div\\", { key: \\"foo\\" }) return function render(_ctx, _cache) { with (this) { - const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1 @@ -28,7 +28,7 @@ const _hoisted_1 = _createVNode(\\"p\\", null, [ return function render(_ctx, _cache) { with (this) { - const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1 @@ -47,7 +47,7 @@ const _hoisted_1 = _createVNode(\\"div\\", null, [ return function render(_ctx, _cache) { with (this) { - const { createCommentVNode: _createCommentVNode, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { createCommentVNode: _createCommentVNode, createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1 @@ -65,7 +65,7 @@ const _hoisted_2 = _createVNode(\\"div\\") return function render(_ctx, _cache) { with (this) { - const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1, @@ -83,7 +83,7 @@ const _hoisted_1 = _createVNode(\\"span\\", { class: \\"inline\\" }, \\"hello\\" return function render(_ctx, _cache) { with (this) { - const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1 @@ -100,7 +100,7 @@ const _hoisted_1 = { id: \\"foo\\" } return function render(_ctx, _cache) { with (this) { - const { createVNode: _createVNode, withDirectives: _withDirectives, resolveDirective: _resolveDirective, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { resolveDirective: _resolveDirective, createVNode: _createVNode, withDirectives: _withDirectives, openBlock: _openBlock, createBlock: _createBlock } = _Vue const _directive_foo = _resolveDirective(\\"foo\\") @@ -121,7 +121,7 @@ const _hoisted_1 = { id: \\"foo\\" } return function render(_ctx, _cache) { with (this) { - const { toDisplayString: _toDisplayString, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { toDisplayString: _toDisplayString, createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"div\\", _hoisted_1, _toDisplayString(hello), 1 /* TEXT */) @@ -138,7 +138,7 @@ const _hoisted_1 = { id: \\"foo\\" } return function render(_ctx, _cache) { with (this) { - const { resolveComponent: _resolveComponent, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { resolveComponent: _resolveComponent, createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue const _component_Comp = _resolveComponent(\\"Comp\\") @@ -159,7 +159,7 @@ const _hoisted_1 = { class: { foo: true } } return function render(_ctx, _cache) { with (this) { - const { toDisplayString: _toDisplayString, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { toDisplayString: _toDisplayString, createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"span\\", _hoisted_1, _toDisplayString(_ctx.bar), 1 /* TEXT */) @@ -176,7 +176,7 @@ const _hoisted_1 = _createVNode(\\"span\\", null, \\"foo \\" + _toDisplayString( return function render(_ctx, _cache) { with (this) { - const { toDisplayString: _toDisplayString, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { toDisplayString: _toDisplayString, createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1 @@ -193,7 +193,7 @@ const _hoisted_1 = _createVNode(\\"span\\", { foo: 0 }, _toDisplayString(1)) return function render(_ctx, _cache) { with (this) { - const { toDisplayString: _toDisplayString, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { toDisplayString: _toDisplayString, createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1 @@ -203,7 +203,7 @@ return function render(_ctx, _cache) { `; exports[`compiler: hoistStatic transform prefixIdentifiers should NOT hoist elements with cached handlers 1`] = ` -"import { createVNode as _createVNode, createBlock as _createBlock, openBlock as _openBlock } from \\"vue\\" +"import { createVNode as _createVNode, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\" export function render(_ctx, _cache) { return (_openBlock(), _createBlock(\\"div\\", null, [ @@ -221,7 +221,7 @@ exports[`compiler: hoistStatic transform prefixIdentifiers should NOT hoist expr return function render(_ctx, _cache) { with (this) { - const { renderList: _renderList, openBlock: _openBlock, createBlock: _createBlock, Fragment: _Fragment, toDisplayString: _toDisplayString, createVNode: _createVNode } = _Vue + const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createBlock: _createBlock, toDisplayString: _toDisplayString, createVNode: _createVNode } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ (_openBlock(true), _createBlock(_Fragment, null, _renderList(_ctx.list, (o) => { @@ -239,7 +239,7 @@ exports[`compiler: hoistStatic transform prefixIdentifiers should NOT hoist expr return function render(_ctx, _cache) { with (this) { - const { toDisplayString: _toDisplayString, createTextVNode: _createTextVNode, resolveComponent: _resolveComponent, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { toDisplayString: _toDisplayString, createTextVNode: _createTextVNode, resolveComponent: _resolveComponent, createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue const _component_Comp = _resolveComponent(\\"Comp\\") @@ -258,7 +258,7 @@ exports[`compiler: hoistStatic transform prefixIdentifiers should NOT hoist expr return function render(_ctx, _cache) { with (this) { - const { renderList: _renderList, openBlock: _openBlock, createBlock: _createBlock, Fragment: _Fragment, toDisplayString: _toDisplayString, createVNode: _createVNode } = _Vue + const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createBlock: _createBlock, toDisplayString: _toDisplayString, createVNode: _createVNode } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ (_openBlock(true), _createBlock(_Fragment, null, _renderList(_ctx.list, (o) => { @@ -276,7 +276,7 @@ exports[`compiler: hoistStatic transform should NOT hoist components 1`] = ` return function render(_ctx, _cache) { with (this) { - const { resolveComponent: _resolveComponent, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { resolveComponent: _resolveComponent, createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue const _component_Comp = _resolveComponent(\\"Comp\\") @@ -292,7 +292,7 @@ exports[`compiler: hoistStatic transform should NOT hoist element with dynamic k return function render(_ctx, _cache) { with (this) { - const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"div\\", { key: foo }) @@ -306,7 +306,7 @@ exports[`compiler: hoistStatic transform should NOT hoist element with dynamic p return function render(_ctx, _cache) { with (this) { - const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"div\\", { id: foo }, null, 8 /* PROPS */, [\\"id\\"]) @@ -320,7 +320,7 @@ exports[`compiler: hoistStatic transform should NOT hoist element with dynamic r return function render(_ctx, _cache) { with (this) { - const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"div\\", { ref: foo }, null, 32 /* NEED_PATCH */) @@ -334,7 +334,7 @@ exports[`compiler: hoistStatic transform should NOT hoist root node 1`] = ` return function render(_ctx, _cache) { with (this) { - const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue return (_openBlock(), _createBlock(\\"div\\")) } @@ -350,7 +350,7 @@ const _hoisted_2 = _createVNode(\\"span\\") return function render(_ctx, _cache) { with (this) { - const { renderList: _renderList, openBlock: _openBlock, createBlock: _createBlock, Fragment: _Fragment, createVNode: _createVNode } = _Vue + const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createBlock: _createBlock, createVNode: _createVNode } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ (_openBlock(true), _createBlock(_Fragment, null, _renderList(list, (i) => { @@ -378,11 +378,11 @@ return function render(_ctx, _cache) { const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock, createCommentVNode: _createCommentVNode } = _Vue return (_openBlock(), _createBlock(\\"div\\", null, [ - (_openBlock(), ok - ? _createBlock(\\"div\\", _hoisted_1, [ + ok + ? (_openBlock(), _createBlock(\\"div\\", _hoisted_1, [ _hoisted_2 - ]) - : _createCommentVNode(\\"v-if\\", true)) + ])) + : _createCommentVNode(\\"v-if\\", true) ])) } }" diff --git a/packages/compiler-core/__tests__/transforms/__snapshots__/transformText.spec.ts.snap b/packages/compiler-core/__tests__/transforms/__snapshots__/transformText.spec.ts.snap index f75897739..ebf472ad3 100644 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/transformText.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/transformText.spec.ts.snap @@ -5,7 +5,7 @@ exports[`compiler: transform text