From 782db6d7f5253468160234c2a60e21c4ba3913c3 Mon Sep 17 00:00:00 2001 From: djy0 Date: Mon, 10 Feb 2020 22:33:04 +0800 Subject: [PATCH] chore(compiler-core/codegen): avoid generate indent spaces of empty lines. (#701) --- .../__snapshots__/codegen.spec.ts.snap | 8 ++-- .../__snapshots__/compile.spec.ts.snap | 2 +- .../compiler-core/__tests__/codegen.spec.ts | 15 +++++-- .../__snapshots__/hoistStatic.spec.ts.snap | 42 +++++++++---------- .../__snapshots__/transformText.spec.ts.snap | 12 +++--- .../__snapshots__/vFor.spec.ts.snap | 24 +++++------ .../transforms/__snapshots__/vIf.spec.ts.snap | 16 +++---- .../__snapshots__/vModel.spec.ts.snap | 8 ++-- .../__snapshots__/vOnce.spec.ts.snap | 10 ++--- .../__snapshots__/vSlot.spec.ts.snap | 6 +-- packages/compiler-core/src/codegen.ts | 14 ++++--- .../__snapshots__/index.spec.ts.snap | 2 +- .../__snapshots__/vModel.spec.ts.snap | 24 +++++------ .../__snapshots__/vShow.spec.ts.snap | 2 +- 14 files changed, 99 insertions(+), 86 deletions(-) diff --git a/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap index 5f40c4ef..d38ec84d 100644 --- a/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/codegen.spec.ts.snap @@ -72,14 +72,16 @@ return function render() { }" `; -exports[`compiler: codegen assets 1`] = ` +exports[`compiler: codegen assets + temps 1`] = ` " return function render() { with (this) { const _component_Foo = _resolveComponent(\\"Foo\\") const _component_bar_baz = _resolveComponent(\\"bar-baz\\") const _component_barbaz = _resolveComponent(\\"barbaz\\") -const _directive_my_dir = _resolveDirective(\\"my_dir\\") + const _directive_my_dir_0 = _resolveDirective(\\"my_dir_0\\") + const _directive_my_dir_1 = _resolveDirective(\\"my_dir_1\\") + let _temp0, _temp1, _temp2 return null } @@ -119,7 +121,7 @@ exports[`compiler: codegen function mode preamble 1`] = ` return function render() { with (this) { const { createVNode: _createVNode, resolveDirective: _resolveDirective } = _Vue - + return null } }" diff --git a/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap index 7b0b9c35..5b51457a 100644 --- a/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap @@ -6,7 +6,7 @@ exports[`compiler: integration tests function mode 1`] = ` return function render() { with (this) { const { toDisplayString: _toDisplayString, createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock, createCommentVNode: _createCommentVNode, Fragment: _Fragment, renderList: _renderList, createTextVNode: _createTextVNode } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", { id: \\"foo\\", class: bar.baz diff --git a/packages/compiler-core/__tests__/codegen.spec.ts b/packages/compiler-core/__tests__/codegen.spec.ts index e322658b..04e6b017 100644 --- a/packages/compiler-core/__tests__/codegen.spec.ts +++ b/packages/compiler-core/__tests__/codegen.spec.ts @@ -119,10 +119,11 @@ describe('compiler: codegen', () => { expect(code).toMatchSnapshot() }) - test('assets', () => { + test('assets + temps', () => { const root = createRoot({ components: [`Foo`, `bar-baz`, `barbaz`], - directives: [`my_dir`] + directives: [`my_dir_0`, `my_dir_1`], + temps: 3 }) const { code } = generate(root, { mode: 'function' }) expect(code).toMatch( @@ -139,10 +140,16 @@ describe('compiler: codegen', () => { }("barbaz")\n` ) expect(code).toMatch( - `const _directive_my_dir = _${ + `const _directive_my_dir_0 = _${ helperNameMap[RESOLVE_DIRECTIVE] - }("my_dir")\n` + }("my_dir_0")\n` ) + expect(code).toMatch( + `const _directive_my_dir_1 = _${ + helperNameMap[RESOLVE_DIRECTIVE] + }("my_dir_1")\n` + ) + expect(code).toMatch(`let _temp0, _temp1, _temp2`) expect(code).toMatchSnapshot() }) 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 bda31a1c..5a472c56 100644 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap @@ -9,7 +9,7 @@ const _hoisted_1 = _createVNode(\\"div\\", { key: \\"foo\\" }) return function render() { with (this) { const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1 ])) @@ -29,7 +29,7 @@ const _hoisted_1 = _createVNode(\\"p\\", null, [ return function render() { with (this) { const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1 ])) @@ -48,7 +48,7 @@ const _hoisted_1 = _createVNode(\\"div\\", null, [ return function render() { with (this) { const { createCommentVNode: _createCommentVNode, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1 ])) @@ -66,7 +66,7 @@ const _hoisted_2 = _createVNode(\\"div\\") return function render() { with (this) { const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1, _hoisted_2 @@ -84,7 +84,7 @@ const _hoisted_1 = _createVNode(\\"span\\", { class: \\"inline\\" }, \\"hello\\" return function render() { with (this) { const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1 ])) @@ -101,7 +101,7 @@ const _hoisted_1 = { id: \\"foo\\" } return function render() { with (this) { const { createVNode: _createVNode, withDirectives: _withDirectives, resolveDirective: _resolveDirective, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + const _directive_foo = _resolveDirective(\\"foo\\") return (_openBlock(), _createBlock(\\"div\\", null, [ @@ -122,7 +122,7 @@ const _hoisted_1 = { id: \\"foo\\" } return function render() { with (this) { const { toDisplayString: _toDisplayString, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"div\\", _hoisted_1, _toDisplayString(hello), 1 /* TEXT */) ])) @@ -139,7 +139,7 @@ const _hoisted_1 = { id: \\"foo\\" } return function render() { with (this) { const { resolveComponent: _resolveComponent, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + const _component_Comp = _resolveComponent(\\"Comp\\") return (_openBlock(), _createBlock(\\"div\\", null, [ @@ -160,7 +160,7 @@ const _hoisted_1 = { class: { foo: true } } return function render() { with (this) { const { toDisplayString: _toDisplayString, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"span\\", _hoisted_1, _toDisplayString(_ctx.bar), 1 /* TEXT */) ])) @@ -182,7 +182,7 @@ const _hoisted_1 = _createVNode(\\"span\\", null, [ return function render() { with (this) { const { toDisplayString: _toDisplayString, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1 ])) @@ -199,7 +199,7 @@ const _hoisted_1 = _createVNode(\\"span\\", { foo: 0 }, _toDisplayString(1)) return function render() { with (this) { const { toDisplayString: _toDisplayString, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ _hoisted_1 ])) @@ -229,7 +229,7 @@ exports[`compiler: hoistStatic transform prefixIdentifiers should NOT hoist expr return function render() { with (this) { const { renderList: _renderList, openBlock: _openBlock, createBlock: _createBlock, Fragment: _Fragment, toDisplayString: _toDisplayString, createVNode: _createVNode } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ (_openBlock(false), _createBlock(_Fragment, null, _renderList(_ctx.list, (o) => { return (_openBlock(), _createBlock(\\"p\\", null, [ @@ -247,7 +247,7 @@ exports[`compiler: hoistStatic transform prefixIdentifiers should NOT hoist expr return function render() { with (this) { const { toDisplayString: _toDisplayString, resolveComponent: _resolveComponent, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + const _component_Comp = _resolveComponent(\\"Comp\\") return (_openBlock(), _createBlock(_component_Comp, null, { @@ -264,7 +264,7 @@ exports[`compiler: hoistStatic transform prefixIdentifiers should NOT hoist expr return function render() { with (this) { const { renderList: _renderList, openBlock: _openBlock, createBlock: _createBlock, Fragment: _Fragment, toDisplayString: _toDisplayString, createVNode: _createVNode } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ (_openBlock(false), _createBlock(_Fragment, null, _renderList(_ctx.list, (o) => { return (_openBlock(), _createBlock(\\"p\\", null, [ @@ -282,7 +282,7 @@ exports[`compiler: hoistStatic transform should NOT hoist components 1`] = ` return function render() { with (this) { const { resolveComponent: _resolveComponent, createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + const _component_Comp = _resolveComponent(\\"Comp\\") return (_openBlock(), _createBlock(\\"div\\", null, [ @@ -298,7 +298,7 @@ exports[`compiler: hoistStatic transform should NOT hoist element with dynamic k return function render() { with (this) { const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"div\\", { key: foo }) ])) @@ -312,7 +312,7 @@ exports[`compiler: hoistStatic transform should NOT hoist element with dynamic p return function render() { with (this) { const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"div\\", { id: foo }, null, 8 /* PROPS */, [\\"id\\"]) ])) @@ -326,7 +326,7 @@ exports[`compiler: hoistStatic transform should NOT hoist element with dynamic r return function render() { with (this) { const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"div\\", { ref: foo }, null, 32 /* NEED_PATCH */) ])) @@ -340,7 +340,7 @@ exports[`compiler: hoistStatic transform should NOT hoist root node 1`] = ` return function render() { with (this) { const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue - + return (_openBlock(), _createBlock(\\"div\\")) } }" @@ -356,7 +356,7 @@ const _hoisted_2 = _createVNode(\\"span\\") return function render() { with (this) { const { renderList: _renderList, openBlock: _openBlock, createBlock: _createBlock, Fragment: _Fragment, createVNode: _createVNode } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ (_openBlock(false), _createBlock(_Fragment, null, _renderList(list, (i) => { return (_openBlock(), _createBlock(\\"div\\", _hoisted_1, [ @@ -381,7 +381,7 @@ const _hoisted_2 = _createVNode(\\"span\\") return function render() { with (this) { const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock, createCommentVNode: _createCommentVNode } = _Vue - + return (_openBlock(), _createBlock(\\"div\\", null, [ (_openBlock(), ok ? _createBlock(\\"div\\", _hoisted_1, [ 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 9c56ed92..227ac7df 100644 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/transformText.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/transformText.spec.ts.snap @@ -6,7 +6,7 @@ exports[`compiler: transform text