From: Evan You Date: Mon, 30 Sep 2019 18:58:20 +0000 (-0400) Subject: test: record snapshots for text optimization X-Git-Tag: v3.0.0-alpha.0~662 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=da0d785d84ede0663eeb558b4446b04d3c3d0703;p=thirdparty%2Fvuejs%2Fcore.git test: record snapshots for text optimization --- diff --git a/packages/compiler-core/__tests__/transforms/__snapshots__/optimizeText.spec.ts.snap b/packages/compiler-core/__tests__/transforms/__snapshots__/optimizeText.spec.ts.snap new file mode 100644 index 0000000000..921cbec13f --- /dev/null +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/optimizeText.spec.ts.snap @@ -0,0 +1,60 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`compiler: optimize interpolation consecutive text 1`] = ` +"const _Vue = Vue +return function render() { + with (this) { + const { toString: _toString } = _Vue + return _toString(foo) + \\" bar \\" + _toString(baz) + } +}" +`; + +exports[`compiler: optimize interpolation consecutive text between elements 1`] = ` +"const _Vue = Vue +return function render() { + with (this) { + const { createVNode: _createVNode, toString: _toString } = _Vue + return [ + _createVNode(\\"div\\"), + _toString(foo) + \\" bar \\" + _toString(baz), + _createVNode(\\"div\\") + ] + } +}" +`; + +exports[`compiler: optimize interpolation consecutive text mixed with elements 1`] = ` +"const _Vue = Vue +return function render() { + with (this) { + const { createVNode: _createVNode, toString: _toString } = _Vue + return [ + _createVNode(\\"div\\"), + _toString(foo) + \\" bar \\" + _toString(baz), + _createVNode(\\"div\\"), + _toString(foo) + \\" bar \\" + _toString(baz), + _createVNode(\\"div\\") + ] + } +}" +`; + +exports[`compiler: optimize interpolation no consecutive text 1`] = ` +"const _Vue = Vue +return function render() { + with (this) { + const { toString: _toString } = _Vue + return _toString(foo) + } +}" +`; + +exports[`compiler: optimize interpolation with prefixIdentifiers: true 1`] = ` +"const { toString } = Vue + +return function render() { + const _ctx = this + return toString(_ctx.foo) + \\" bar \\" + toString(_ctx.baz + _ctx.qux) +}" +`; diff --git a/packages/compiler-core/__tests__/transforms/optimizeText.spec.ts b/packages/compiler-core/__tests__/transforms/optimizeText.spec.ts index 64ed2da0d8..3c8c2638b1 100644 --- a/packages/compiler-core/__tests__/transforms/optimizeText.spec.ts +++ b/packages/compiler-core/__tests__/transforms/optimizeText.spec.ts @@ -1,13 +1,21 @@ -import { CompilerOptions, parse, transform, NodeTypes } from '../../src' +import { + CompilerOptions, + parse, + transform, + NodeTypes, + generate +} from '../../src' import { optimizeText } from '../../src/transforms/optimizeText' import { transformExpression } from '../../src/transforms/transformExpression' +import { transformElement } from '../../src/transforms/transformElement' function transformWithTextOpt(template: string, options: CompilerOptions = {}) { const ast = parse(template) transform(ast, { nodeTransforms: [ ...(options.prefixIdentifiers ? [transformExpression] : []), - optimizeText + optimizeText, + transformElement ], ...options }) @@ -23,6 +31,7 @@ describe('compiler: optimize interpolation', () => { content: `foo` } }) + expect(generate(root).code).toMatchSnapshot() }) test('consecutive text', () => { @@ -38,6 +47,7 @@ describe('compiler: optimize interpolation', () => { { type: NodeTypes.INTERPOLATION, content: { content: `baz` } } ] }) + expect(generate(root).code).toMatchSnapshot() }) test('consecutive text between elements', () => { @@ -55,6 +65,7 @@ describe('compiler: optimize interpolation', () => { ] }) expect(root.children[2].type).toBe(NodeTypes.ELEMENT) + expect(generate(root).code).toMatchSnapshot() }) test('consecutive text mixed with elements', () => { @@ -85,6 +96,7 @@ describe('compiler: optimize interpolation', () => { ] }) expect(root.children[4].type).toBe(NodeTypes.ELEMENT) + expect(generate(root).code).toMatchSnapshot() }) test('with prefixIdentifiers: true', () => { @@ -108,5 +120,10 @@ describe('compiler: optimize interpolation', () => { } ] }) + expect( + generate(root, { + prefixIdentifiers: true + }).code + ).toMatchSnapshot() }) })