--- /dev/null
+// 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)
+}"
+`;
-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
})
content: `foo`
}
})
+ expect(generate(root).code).toMatchSnapshot()
})
test('consecutive text', () => {
{ type: NodeTypes.INTERPOLATION, content: { content: `baz` } }
]
})
+ expect(generate(root).code).toMatchSnapshot()
})
test('consecutive text between elements', () => {
]
})
expect(root.children[2].type).toBe(NodeTypes.ELEMENT)
+ expect(generate(root).code).toMatchSnapshot()
})
test('consecutive text mixed with elements', () => {
]
})
expect(root.children[4].type).toBe(NodeTypes.ELEMENT)
+ expect(generate(root).code).toMatchSnapshot()
})
test('with prefixIdentifiers: true', () => {
}
]
})
+ expect(
+ generate(root, {
+ prefixIdentifiers: true
+ }).code
+ ).toMatchSnapshot()
})
})