Skip to content

Commit 273336c

Browse files
committed
test: check IRDynamicPropsKind
1 parent 4cfd4ce commit 273336c

File tree

5 files changed

+51
-18
lines changed

5 files changed

+51
-18
lines changed

packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts

+40-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { makeCompile } from './_utils'
22
import {
3+
IRDynamicPropsKind,
34
IRNodeTypes,
45
transformChildren,
56
transformElement,
@@ -257,7 +258,12 @@ describe('compiler: element transform', () => {
257258
{
258259
type: IRNodeTypes.CREATE_COMPONENT_NODE,
259260
tag: 'Foo',
260-
props: [{ value: { content: 'obj', isStatic: false } }],
261+
props: [
262+
{
263+
kind: IRDynamicPropsKind.EXPRESSION,
264+
value: { content: 'obj', isStatic: false },
265+
},
266+
],
261267
},
262268
])
263269
})
@@ -277,7 +283,10 @@ describe('compiler: element transform', () => {
277283
tag: 'Foo',
278284
props: [
279285
[{ key: { content: 'id' }, values: [{ content: 'foo' }] }],
280-
{ value: { content: 'obj' } },
286+
{
287+
kind: IRDynamicPropsKind.EXPRESSION,
288+
value: { content: 'obj' },
289+
},
281290
],
282291
},
283292
])
@@ -297,7 +306,10 @@ describe('compiler: element transform', () => {
297306
type: IRNodeTypes.CREATE_COMPONENT_NODE,
298307
tag: 'Foo',
299308
props: [
300-
{ value: { content: 'obj' } },
309+
{
310+
kind: IRDynamicPropsKind.EXPRESSION,
311+
value: { content: 'obj' },
312+
},
301313
[{ key: { content: 'id' }, values: [{ content: 'foo' }] }],
302314
],
303315
},
@@ -320,7 +332,10 @@ describe('compiler: element transform', () => {
320332
tag: 'Foo',
321333
props: [
322334
[{ key: { content: 'id' }, values: [{ content: 'foo' }] }],
323-
{ value: { content: 'obj' } },
335+
{
336+
kind: IRDynamicPropsKind.EXPRESSION,
337+
value: { content: 'obj' },
338+
},
324339
[{ key: { content: 'class' }, values: [{ content: 'bar' }] }],
325340
],
326341
},
@@ -373,7 +388,13 @@ describe('compiler: element transform', () => {
373388
{
374389
type: IRNodeTypes.CREATE_COMPONENT_NODE,
375390
tag: 'Foo',
376-
props: [{ value: { content: 'obj' }, handler: true }],
391+
props: [
392+
{
393+
kind: IRDynamicPropsKind.EXPRESSION,
394+
value: { content: 'obj' },
395+
handler: true,
396+
},
397+
],
377398
},
378399
])
379400
})
@@ -444,6 +465,7 @@ describe('compiler: element transform', () => {
444465
element: 0,
445466
props: [
446467
{
468+
kind: IRDynamicPropsKind.EXPRESSION,
447469
value: {
448470
type: NodeTypes.SIMPLE_EXPRESSION,
449471
content: 'obj',
@@ -479,6 +501,7 @@ describe('compiler: element transform', () => {
479501
props: [
480502
[{ key: { content: 'id' }, values: [{ content: 'foo' }] }],
481503
{
504+
kind: IRDynamicPropsKind.EXPRESSION,
482505
value: {
483506
type: NodeTypes.SIMPLE_EXPRESSION,
484507
content: 'obj',
@@ -506,7 +529,10 @@ describe('compiler: element transform', () => {
506529
type: IRNodeTypes.SET_DYNAMIC_PROPS,
507530
element: 0,
508531
props: [
509-
{ value: { content: 'obj' } },
532+
{
533+
kind: IRDynamicPropsKind.EXPRESSION,
534+
value: { content: 'obj' },
535+
},
510536
[{ key: { content: 'id' }, values: [{ content: 'foo' }] }],
511537
],
512538
},
@@ -530,7 +556,10 @@ describe('compiler: element transform', () => {
530556
element: 0,
531557
props: [
532558
[{ key: { content: 'id' }, values: [{ content: 'foo' }] }],
533-
{ value: { content: 'obj' } },
559+
{
560+
kind: IRDynamicPropsKind.EXPRESSION,
561+
value: { content: 'obj' },
562+
},
534563
[{ key: { content: 'class' }, values: [{ content: 'bar' }] }],
535564
],
536565
},
@@ -714,10 +743,12 @@ describe('compiler: element transform', () => {
714743
tag: 'Foo',
715744
props: [
716745
{
746+
kind: IRDynamicPropsKind.ATTRIBUTE,
717747
key: { content: 'foo-bar' },
718748
values: [{ content: 'bar' }],
719749
},
720750
{
751+
kind: IRDynamicPropsKind.ATTRIBUTE,
721752
key: { content: 'baz' },
722753
values: [{ content: 'qux' }],
723754
},
@@ -737,11 +768,13 @@ describe('compiler: element transform', () => {
737768
tag: 'Foo',
738769
props: [
739770
{
771+
kind: IRDynamicPropsKind.ATTRIBUTE,
740772
key: { content: 'foo-bar' },
741773
values: [{ content: 'bar' }],
742774
handler: true,
743775
},
744776
{
777+
kind: IRDynamicPropsKind.ATTRIBUTE,
745778
key: { content: 'baz' },
746779
values: [{ content: 'qux' }],
747780
handler: true,

packages/compiler-vapor/src/generators/component.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { camelize, extend, isArray } from '@vue/shared'
22
import type { CodegenContext } from '../generate'
33
import {
44
type CreateComponentIRNode,
5-
DynamicPropsKind,
5+
IRDynamicPropsKind,
66
type IRProp,
77
type IRProps,
88
type IRPropsStatic,
@@ -66,7 +66,7 @@ export function genRawProps(props: IRProps[], context: CodegenContext) {
6666
return genStaticProps(props, context)
6767
} else {
6868
let expr: CodeFragment[]
69-
if (props.kind === DynamicPropsKind.ATTRIBUTE)
69+
if (props.kind === IRDynamicPropsKind.ATTRIBUTE)
7070
expr = genMulti(SEGMENTS_OBJECT, genProp(props, context))
7171
else {
7272
expr = genExpression(props.value, context)

packages/compiler-vapor/src/generators/prop.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from '@vue/compiler-core'
66
import type { CodegenContext } from '../generate'
77
import {
8-
DynamicPropsKind,
8+
IRDynamicPropsKind,
99
type IRProp,
1010
type SetDynamicPropsIRNode,
1111
type SetPropIRNode,
@@ -74,7 +74,7 @@ export function genDynamicProps(
7474
props =>
7575
Array.isArray(props)
7676
? genLiteralObjectProps(props, context) // static and dynamic arg props
77-
: props.kind === DynamicPropsKind.ATTRIBUTE
77+
: props.kind === IRDynamicPropsKind.ATTRIBUTE
7878
? genLiteralObjectProps([props], context) // dynamic arg props
7979
: genExpression(props.value, context), // v-bind=""
8080
),

packages/compiler-vapor/src/ir.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,19 @@ export interface IRProp extends Omit<DirectiveTransformResult, 'value'> {
8484
values: SimpleExpressionNode[]
8585
}
8686

87-
export enum DynamicPropsKind {
87+
export enum IRDynamicPropsKind {
8888
EXPRESSION, // v-bind="value"
8989
ATTRIBUTE, // v-bind:[foo]="value"
9090
}
9191

9292
export type IRPropsStatic = IRProp[]
9393
export interface IRPropsDynamicExpression {
94-
kind: DynamicPropsKind.EXPRESSION
94+
kind: IRDynamicPropsKind.EXPRESSION
9595
value: SimpleExpressionNode
9696
handler?: boolean
9797
}
9898
export interface IRPropsDynamicAttribute extends IRProp {
99-
kind: DynamicPropsKind.ATTRIBUTE
99+
kind: IRDynamicPropsKind.ATTRIBUTE
100100
}
101101
export type IRProps =
102102
| IRPropsStatic

packages/compiler-vapor/src/transforms/transformElement.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type {
2424
} from '../transform'
2525
import {
2626
DynamicFlag,
27-
DynamicPropsKind,
27+
IRDynamicPropsKind,
2828
IRNodeTypes,
2929
type IRProp,
3030
type IRProps,
@@ -208,7 +208,7 @@ function buildProps(
208208
dynamicExpr.push(prop.exp)
209209
pushMergeArg()
210210
dynamicArgs.push({
211-
kind: DynamicPropsKind.EXPRESSION,
211+
kind: IRDynamicPropsKind.EXPRESSION,
212212
value: prop.exp,
213213
})
214214
} else {
@@ -224,7 +224,7 @@ function buildProps(
224224
dynamicExpr.push(prop.exp)
225225
pushMergeArg()
226226
dynamicArgs.push({
227-
kind: DynamicPropsKind.EXPRESSION,
227+
kind: IRDynamicPropsKind.EXPRESSION,
228228
value: prop.exp,
229229
handler: true,
230230
})
@@ -256,7 +256,7 @@ function buildProps(
256256
pushMergeArg()
257257
dynamicArgs.push(
258258
extend(resolveDirectiveResult(result), {
259-
kind: DynamicPropsKind.ATTRIBUTE,
259+
kind: IRDynamicPropsKind.ATTRIBUTE,
260260
}) as IRPropsDynamicAttribute,
261261
)
262262
} else {

0 commit comments

Comments
 (0)