Skip to content

Commit a8ab86e

Browse files
committed
feat: add static field displayName for Component type
1 parent 676e49e commit a8ab86e

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

modules/code-generator/src/plugins/component/react/containerClass.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
2626

2727
// 将模块名转换成 PascalCase 的格式,并添加特定后缀,防止命名冲突
2828
const componentClassName = ensureValidClassName(
29-
`${changeCase.pascalCase(ir.moduleName)}$$Page`,
29+
`${changeCase.pascalCase(ir.moduleName)}$$${ir.containerType}`,
3030
);
3131

3232
next.chunks.push({
@@ -43,6 +43,18 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
4343
],
4444
});
4545

46+
if (ir.containerType === 'Component') {
47+
next.chunks.push({
48+
type: ChunkType.STRING,
49+
fileType: FileType.JSX,
50+
name: CLASS_DEFINE_CHUNK_NAME.InsVar,
51+
content: `static displayName = '${changeCase.pascalCase(ir.moduleName)}';`,
52+
linkAfter: [
53+
CLASS_DEFINE_CHUNK_NAME.Start,
54+
],
55+
});
56+
}
57+
4658
next.chunks.push({
4759
type: ChunkType.STRING,
4860
fileType: FileType.JSX,

modules/code-generator/src/types/deps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ export interface IDependency {
3535
main?: string; // 包导出组件入口文件路径 /lib/input
3636
dependencyType?: DependencyType; // 依赖类型 内/外
3737
componentName?: string; // 导入后名称
38-
}
38+
}

modules/code-generator/src/utils/common.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { IPublicTypeJSExpression, IPublicTypeJSFunction } from '@alilc/lowcode-types';
22
import changeCase from 'change-case';
33
import short from 'short-uuid';
4+
import { DependencyType, IDependency, IExternalDependency, IInternalDependency } from '../types';
45

56
// Doc: https://www.npmjs.com/package/change-case
67

@@ -43,4 +44,16 @@ export function getStaticExprValue<T>(expr: string): T {
4344

4445
export function isJSExpressionFn(data: any): data is IPublicTypeJSFunction {
4546
return data?.type === 'JSExpression' && data?.extType === 'function';
47+
}
48+
49+
export function isInternalDependency(
50+
dependency: IDependency,
51+
): dependency is IInternalDependency {
52+
return dependency.dependencyType === DependencyType.Internal;
53+
}
54+
55+
export function isExternalDependency(
56+
dependency: IDependency,
57+
): dependency is IExternalDependency {
58+
return dependency.dependencyType === DependencyType.External;
4659
}

0 commit comments

Comments
 (0)