|
|
@@ -6,7 +6,9 @@ import {
|
|
|
NodeTypes,
|
|
|
CompilerOptions,
|
|
|
InterpolationNode,
|
|
|
- ConstantTypes
|
|
|
+ ConstantTypes,
|
|
|
+ BindingTypes,
|
|
|
+ baseCompile
|
|
|
} from '../../src'
|
|
|
import { transformIf } from '../../src/transforms/vIf'
|
|
|
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()
|
|
|
+ })
|
|
|
+ })
|
|
|
})
|