--- /dev/null
+// 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 */))
+}"
+`;
NodeTypes,
CompilerOptions,
InterpolationNode,
- ConstantTypes
+ ConstantTypes,
+ BindingTypes,
+ baseCompile
} from '../../src'
import { transformIf } from '../../src/transforms/vIf'
import { transformExpression } from '../../src/transforms/transformExpression'
})
})
})
+
+ 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()
+ })
+ })
})