|
6 | 6 | NodeTypes,
|
7 | 7 | CompilerOptions,
|
8 | 8 | InterpolationNode,
|
9 |
| - ConstantTypes |
| 9 | + ConstantTypes, |
| 10 | + BindingTypes, |
| 11 | + baseCompile |
10 | 12 | } from '../../src'
|
11 | 13 | import { transformIf } from '../../src/transforms/vIf'
|
12 | 14 | import { transformExpression } from '../../src/transforms/transformExpression'
|
@@ -457,4 +459,50 @@ describe('compiler: expression transform', () => {
|
457 | 459 | })
|
458 | 460 | })
|
459 | 461 | })
|
| 462 | + |
| 463 | + describe('bindingMetadata', () => { |
| 464 | + const bindingMetadata = { |
| 465 | + props: BindingTypes.PROPS, |
| 466 | + setup: BindingTypes.SETUP_MAYBE_REF, |
| 467 | + setupConst: BindingTypes.SETUP_CONST, |
| 468 | + data: BindingTypes.DATA, |
| 469 | + options: BindingTypes.OPTIONS |
| 470 | + } |
| 471 | + |
| 472 | + function compileWithBindingMetadata( |
| 473 | + template: string, |
| 474 | + options?: CompilerOptions |
| 475 | + ) { |
| 476 | + return baseCompile(template, { |
| 477 | + prefixIdentifiers: true, |
| 478 | + bindingMetadata, |
| 479 | + ...options |
| 480 | + }) |
| 481 | + } |
| 482 | + |
| 483 | + test('non-inline mode', () => { |
| 484 | + const { code } = compileWithBindingMetadata( |
| 485 | + `<div>{{ props }} {{ setup }} {{ data }} {{ options }}</div>` |
| 486 | + ) |
| 487 | + expect(code).toMatch(`$props.props`) |
| 488 | + expect(code).toMatch(`$setup.setup`) |
| 489 | + expect(code).toMatch(`$data.data`) |
| 490 | + expect(code).toMatch(`$options.options`) |
| 491 | + expect(code).toMatch(`_ctx, _cache, $props, $setup, $data, $options`) |
| 492 | + expect(code).toMatchSnapshot() |
| 493 | + }) |
| 494 | + |
| 495 | + test('inline mode', () => { |
| 496 | + const { code } = compileWithBindingMetadata( |
| 497 | + `<div>{{ props }} {{ setup }} {{ setupConst }} {{ data }} {{ options }}</div>`, |
| 498 | + { inline: true } |
| 499 | + ) |
| 500 | + expect(code).toMatch(`__props.props`) |
| 501 | + expect(code).toMatch(`_unref(setup)`) |
| 502 | + expect(code).toMatch(`_toDisplayString(setupConst)`) |
| 503 | + expect(code).toMatch(`_ctx.data`) |
| 504 | + expect(code).toMatch(`_ctx.options`) |
| 505 | + expect(code).toMatchSnapshot() |
| 506 | + }) |
| 507 | + }) |
460 | 508 | })
|
0 commit comments