test(compiler-core): test expression transform w/ bindingMetadata
This commit is contained in:
parent
d2d27b2e66
commit
338d869c70
@ -0,0 +1,15 @@
|
|||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`compiler: expression transform bindingMetadata inline mode 1`] = `
|
||||||
|
"(_ctx, _cache) => {
|
||||||
|
return (_openBlock(), _createBlock(\\"div\\", null, _toDisplayString(__props.props) + \\" \\" + _toDisplayString(_unref(setup)) + \\" \\" + _toDisplayString(setupConst) + \\" \\" + _toDisplayString(_ctx.data) + \\" \\" + _toDisplayString(_ctx.options), 1 /* TEXT */))
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`compiler: expression transform bindingMetadata non-inline mode 1`] = `
|
||||||
|
"const { toDisplayString: _toDisplayString, createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = Vue
|
||||||
|
|
||||||
|
return function render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||||
|
return (_openBlock(), _createBlock(\\"div\\", null, _toDisplayString($props.props) + \\" \\" + _toDisplayString($setup.setup) + \\" \\" + _toDisplayString($data.data) + \\" \\" + _toDisplayString($options.options), 1 /* TEXT */))
|
||||||
|
}"
|
||||||
|
`;
|
@ -6,7 +6,9 @@ import {
|
|||||||
NodeTypes,
|
NodeTypes,
|
||||||
CompilerOptions,
|
CompilerOptions,
|
||||||
InterpolationNode,
|
InterpolationNode,
|
||||||
ConstantTypes
|
ConstantTypes,
|
||||||
|
BindingTypes,
|
||||||
|
baseCompile
|
||||||
} from '../../src'
|
} from '../../src'
|
||||||
import { transformIf } from '../../src/transforms/vIf'
|
import { transformIf } from '../../src/transforms/vIf'
|
||||||
import { transformExpression } from '../../src/transforms/transformExpression'
|
import { transformExpression } from '../../src/transforms/transformExpression'
|
||||||
@ -457,4 +459,50 @@ describe('compiler: expression transform', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('bindingMetadata', () => {
|
||||||
|
const bindingMetadata = {
|
||||||
|
props: BindingTypes.PROPS,
|
||||||
|
setup: BindingTypes.SETUP_MAYBE_REF,
|
||||||
|
setupConst: BindingTypes.SETUP_CONST,
|
||||||
|
data: BindingTypes.DATA,
|
||||||
|
options: BindingTypes.OPTIONS
|
||||||
|
}
|
||||||
|
|
||||||
|
function compileWithBindingMetadata(
|
||||||
|
template: string,
|
||||||
|
options?: CompilerOptions
|
||||||
|
) {
|
||||||
|
return baseCompile(template, {
|
||||||
|
prefixIdentifiers: true,
|
||||||
|
bindingMetadata,
|
||||||
|
...options
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
test('non-inline mode', () => {
|
||||||
|
const { code } = compileWithBindingMetadata(
|
||||||
|
`<div>{{ props }} {{ setup }} {{ data }} {{ options }}</div>`
|
||||||
|
)
|
||||||
|
expect(code).toMatch(`$props.props`)
|
||||||
|
expect(code).toMatch(`$setup.setup`)
|
||||||
|
expect(code).toMatch(`$data.data`)
|
||||||
|
expect(code).toMatch(`$options.options`)
|
||||||
|
expect(code).toMatch(`_ctx, _cache, $props, $setup, $data, $options`)
|
||||||
|
expect(code).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('inline mode', () => {
|
||||||
|
const { code } = compileWithBindingMetadata(
|
||||||
|
`<div>{{ props }} {{ setup }} {{ setupConst }} {{ data }} {{ options }}</div>`,
|
||||||
|
{ inline: true }
|
||||||
|
)
|
||||||
|
expect(code).toMatch(`__props.props`)
|
||||||
|
expect(code).toMatch(`_unref(setup)`)
|
||||||
|
expect(code).toMatch(`_toDisplayString(setupConst)`)
|
||||||
|
expect(code).toMatch(`_ctx.data`)
|
||||||
|
expect(code).toMatch(`_ctx.options`)
|
||||||
|
expect(code).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user