Skip to content

Commit

Permalink
test: check IRDynamicPropsKind
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Apr 30, 2024
1 parent 4cfd4ce commit 273336c
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { makeCompile } from './_utils'
import {
IRDynamicPropsKind,
IRNodeTypes,
transformChildren,
transformElement,
Expand Down Expand Up @@ -257,7 +258,12 @@ describe('compiler: element transform', () => {
{
type: IRNodeTypes.CREATE_COMPONENT_NODE,
tag: 'Foo',
props: [{ value: { content: 'obj', isStatic: false } }],
props: [
{
kind: IRDynamicPropsKind.EXPRESSION,
value: { content: 'obj', isStatic: false },
},
],
},
])
})
Expand All @@ -277,7 +283,10 @@ describe('compiler: element transform', () => {
tag: 'Foo',
props: [
[{ key: { content: 'id' }, values: [{ content: 'foo' }] }],
{ value: { content: 'obj' } },
{
kind: IRDynamicPropsKind.EXPRESSION,
value: { content: 'obj' },
},
],
},
])
Expand All @@ -297,7 +306,10 @@ describe('compiler: element transform', () => {
type: IRNodeTypes.CREATE_COMPONENT_NODE,
tag: 'Foo',
props: [
{ value: { content: 'obj' } },
{
kind: IRDynamicPropsKind.EXPRESSION,
value: { content: 'obj' },
},
[{ key: { content: 'id' }, values: [{ content: 'foo' }] }],
],
},
Expand All @@ -320,7 +332,10 @@ describe('compiler: element transform', () => {
tag: 'Foo',
props: [
[{ key: { content: 'id' }, values: [{ content: 'foo' }] }],
{ value: { content: 'obj' } },
{
kind: IRDynamicPropsKind.EXPRESSION,
value: { content: 'obj' },
},
[{ key: { content: 'class' }, values: [{ content: 'bar' }] }],
],
},
Expand Down Expand Up @@ -373,7 +388,13 @@ describe('compiler: element transform', () => {
{
type: IRNodeTypes.CREATE_COMPONENT_NODE,
tag: 'Foo',
props: [{ value: { content: 'obj' }, handler: true }],
props: [
{
kind: IRDynamicPropsKind.EXPRESSION,
value: { content: 'obj' },
handler: true,
},
],
},
])
})
Expand Down Expand Up @@ -444,6 +465,7 @@ describe('compiler: element transform', () => {
element: 0,
props: [
{
kind: IRDynamicPropsKind.EXPRESSION,
value: {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'obj',
Expand Down Expand Up @@ -479,6 +501,7 @@ describe('compiler: element transform', () => {
props: [
[{ key: { content: 'id' }, values: [{ content: 'foo' }] }],
{
kind: IRDynamicPropsKind.EXPRESSION,
value: {
type: NodeTypes.SIMPLE_EXPRESSION,
content: 'obj',
Expand Down Expand Up @@ -506,7 +529,10 @@ describe('compiler: element transform', () => {
type: IRNodeTypes.SET_DYNAMIC_PROPS,
element: 0,
props: [
{ value: { content: 'obj' } },
{
kind: IRDynamicPropsKind.EXPRESSION,
value: { content: 'obj' },
},
[{ key: { content: 'id' }, values: [{ content: 'foo' }] }],
],
},
Expand All @@ -530,7 +556,10 @@ describe('compiler: element transform', () => {
element: 0,
props: [
[{ key: { content: 'id' }, values: [{ content: 'foo' }] }],
{ value: { content: 'obj' } },
{
kind: IRDynamicPropsKind.EXPRESSION,
value: { content: 'obj' },
},
[{ key: { content: 'class' }, values: [{ content: 'bar' }] }],
],
},
Expand Down Expand Up @@ -714,10 +743,12 @@ describe('compiler: element transform', () => {
tag: 'Foo',
props: [
{
kind: IRDynamicPropsKind.ATTRIBUTE,
key: { content: 'foo-bar' },
values: [{ content: 'bar' }],
},
{
kind: IRDynamicPropsKind.ATTRIBUTE,
key: { content: 'baz' },
values: [{ content: 'qux' }],
},
Expand All @@ -737,11 +768,13 @@ describe('compiler: element transform', () => {
tag: 'Foo',
props: [
{
kind: IRDynamicPropsKind.ATTRIBUTE,
key: { content: 'foo-bar' },
values: [{ content: 'bar' }],
handler: true,
},
{
kind: IRDynamicPropsKind.ATTRIBUTE,
key: { content: 'baz' },
values: [{ content: 'qux' }],
handler: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-vapor/src/generators/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { camelize, extend, isArray } from '@vue/shared'
import type { CodegenContext } from '../generate'
import {
type CreateComponentIRNode,
DynamicPropsKind,
IRDynamicPropsKind,
type IRProp,
type IRProps,
type IRPropsStatic,
Expand Down Expand Up @@ -66,7 +66,7 @@ export function genRawProps(props: IRProps[], context: CodegenContext) {
return genStaticProps(props, context)
} else {
let expr: CodeFragment[]
if (props.kind === DynamicPropsKind.ATTRIBUTE)
if (props.kind === IRDynamicPropsKind.ATTRIBUTE)
expr = genMulti(SEGMENTS_OBJECT, genProp(props, context))
else {
expr = genExpression(props.value, context)
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-vapor/src/generators/prop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@vue/compiler-core'
import type { CodegenContext } from '../generate'
import {
DynamicPropsKind,
IRDynamicPropsKind,
type IRProp,
type SetDynamicPropsIRNode,
type SetPropIRNode,
Expand Down Expand Up @@ -74,7 +74,7 @@ export function genDynamicProps(
props =>
Array.isArray(props)
? genLiteralObjectProps(props, context) // static and dynamic arg props
: props.kind === DynamicPropsKind.ATTRIBUTE
: props.kind === IRDynamicPropsKind.ATTRIBUTE
? genLiteralObjectProps([props], context) // dynamic arg props
: genExpression(props.value, context), // v-bind=""
),
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler-vapor/src/ir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ export interface IRProp extends Omit<DirectiveTransformResult, 'value'> {
values: SimpleExpressionNode[]
}

export enum DynamicPropsKind {
export enum IRDynamicPropsKind {
EXPRESSION, // v-bind="value"
ATTRIBUTE, // v-bind:[foo]="value"
}

export type IRPropsStatic = IRProp[]
export interface IRPropsDynamicExpression {
kind: DynamicPropsKind.EXPRESSION
kind: IRDynamicPropsKind.EXPRESSION
value: SimpleExpressionNode
handler?: boolean
}
export interface IRPropsDynamicAttribute extends IRProp {
kind: DynamicPropsKind.ATTRIBUTE
kind: IRDynamicPropsKind.ATTRIBUTE
}
export type IRProps =
| IRPropsStatic
Expand Down
8 changes: 4 additions & 4 deletions packages/compiler-vapor/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type {
} from '../transform'
import {
DynamicFlag,
DynamicPropsKind,
IRDynamicPropsKind,
IRNodeTypes,
type IRProp,
type IRProps,
Expand Down Expand Up @@ -208,7 +208,7 @@ function buildProps(
dynamicExpr.push(prop.exp)
pushMergeArg()
dynamicArgs.push({
kind: DynamicPropsKind.EXPRESSION,
kind: IRDynamicPropsKind.EXPRESSION,
value: prop.exp,
})
} else {
Expand All @@ -224,7 +224,7 @@ function buildProps(
dynamicExpr.push(prop.exp)
pushMergeArg()
dynamicArgs.push({
kind: DynamicPropsKind.EXPRESSION,
kind: IRDynamicPropsKind.EXPRESSION,
value: prop.exp,
handler: true,
})
Expand Down Expand Up @@ -256,7 +256,7 @@ function buildProps(
pushMergeArg()
dynamicArgs.push(
extend(resolveDirectiveResult(result), {
kind: DynamicPropsKind.ATTRIBUTE,
kind: IRDynamicPropsKind.ATTRIBUTE,
}) as IRPropsDynamicAttribute,
)
} else {
Expand Down

0 comments on commit 273336c

Please sign in to comment.