From 273336c61fa852e2c133466680f4c9ef3d7fdd66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Wed, 1 May 2024 03:07:12 +0900 Subject: [PATCH] test: check IRDynamicPropsKind --- .../transforms/transformElement.spec.ts | 47 ++++++++++++++++--- .../src/generators/component.ts | 4 +- .../compiler-vapor/src/generators/prop.ts | 4 +- packages/compiler-vapor/src/ir.ts | 6 +-- .../src/transforms/transformElement.ts | 8 ++-- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts b/packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts index 2faad78dd..4bf38ba3e 100644 --- a/packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts +++ b/packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts @@ -1,5 +1,6 @@ import { makeCompile } from './_utils' import { + IRDynamicPropsKind, IRNodeTypes, transformChildren, transformElement, @@ -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 }, + }, + ], }, ]) }) @@ -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' }, + }, ], }, ]) @@ -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' }] }], ], }, @@ -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' }] }], ], }, @@ -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, + }, + ], }, ]) }) @@ -444,6 +465,7 @@ describe('compiler: element transform', () => { element: 0, props: [ { + kind: IRDynamicPropsKind.EXPRESSION, value: { type: NodeTypes.SIMPLE_EXPRESSION, content: 'obj', @@ -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', @@ -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' }] }], ], }, @@ -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' }] }], ], }, @@ -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' }], }, @@ -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, diff --git a/packages/compiler-vapor/src/generators/component.ts b/packages/compiler-vapor/src/generators/component.ts index ef2ba8b7a..fba45ab1e 100644 --- a/packages/compiler-vapor/src/generators/component.ts +++ b/packages/compiler-vapor/src/generators/component.ts @@ -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, @@ -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) diff --git a/packages/compiler-vapor/src/generators/prop.ts b/packages/compiler-vapor/src/generators/prop.ts index e172ce5db..861397c9a 100644 --- a/packages/compiler-vapor/src/generators/prop.ts +++ b/packages/compiler-vapor/src/generators/prop.ts @@ -5,7 +5,7 @@ import { } from '@vue/compiler-core' import type { CodegenContext } from '../generate' import { - DynamicPropsKind, + IRDynamicPropsKind, type IRProp, type SetDynamicPropsIRNode, type SetPropIRNode, @@ -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="" ), diff --git a/packages/compiler-vapor/src/ir.ts b/packages/compiler-vapor/src/ir.ts index 0232a49c4..408e37557 100644 --- a/packages/compiler-vapor/src/ir.ts +++ b/packages/compiler-vapor/src/ir.ts @@ -84,19 +84,19 @@ export interface IRProp extends Omit { 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 diff --git a/packages/compiler-vapor/src/transforms/transformElement.ts b/packages/compiler-vapor/src/transforms/transformElement.ts index e700146dd..b7de58506 100644 --- a/packages/compiler-vapor/src/transforms/transformElement.ts +++ b/packages/compiler-vapor/src/transforms/transformElement.ts @@ -24,7 +24,7 @@ import type { } from '../transform' import { DynamicFlag, - DynamicPropsKind, + IRDynamicPropsKind, IRNodeTypes, type IRProp, type IRProps, @@ -208,7 +208,7 @@ function buildProps( dynamicExpr.push(prop.exp) pushMergeArg() dynamicArgs.push({ - kind: DynamicPropsKind.EXPRESSION, + kind: IRDynamicPropsKind.EXPRESSION, value: prop.exp, }) } else { @@ -224,7 +224,7 @@ function buildProps( dynamicExpr.push(prop.exp) pushMergeArg() dynamicArgs.push({ - kind: DynamicPropsKind.EXPRESSION, + kind: IRDynamicPropsKind.EXPRESSION, value: prop.exp, handler: true, }) @@ -256,7 +256,7 @@ function buildProps( pushMergeArg() dynamicArgs.push( extend(resolveDirectiveResult(result), { - kind: DynamicPropsKind.ATTRIBUTE, + kind: IRDynamicPropsKind.ATTRIBUTE, }) as IRPropsDynamicAttribute, ) } else {