From 5778e44ac0df24d8fc82df1257c796c021a3722c Mon Sep 17 00:00:00 2001 From: xiao xin Date: Sun, 26 Nov 2023 21:51:45 +0800 Subject: [PATCH] Fixed babel plugin add extra name properties --- packages/babel-plugin/src/plugin/index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/babel-plugin/src/plugin/index.ts b/packages/babel-plugin/src/plugin/index.ts index 0aa1105e54..7b6db1b51d 100644 --- a/packages/babel-plugin/src/plugin/index.ts +++ b/packages/babel-plugin/src/plugin/index.ts @@ -402,11 +402,16 @@ function visitRealmClass(path: NodePath) { .map(visitRealmClassStatic) .filter((property) => property) as types.ObjectProperty[]; - const schema = types.objectExpression([ - types.objectProperty(types.identifier("name"), types.stringLiteral(className)), - types.objectProperty(types.identifier("properties"), types.objectExpression(schemaProperties)), + const hasStaticName = schemaStatics.some(p => p.key.name === "name"); + const properties = [ + types.objectProperty(types.identifier("properties"), + types.objectExpression(schemaProperties)), ...schemaStatics, - ]); + ]; + if (!hasStaticName) { + properties.unshift(types.objectProperty(types.identifier("name"), types.stringLiteral(className))) + } + const schema = types.objectExpression(properties); // Add the schema as a static const schemaStatic = types.classProperty(types.identifier("schema"), schema, undefined, undefined, undefined, true);