Skip to content

Commit bb770b8

Browse files
committed
Merge branch 'feat/0228' of github.com:alibaba/lowcode-engine into feat/0228
2 parents 3ddc8f1 + b3a2991 commit bb770b8

File tree

38 files changed

+231
-114
lines changed

38 files changed

+231
-114
lines changed

modules/code-generator/example-schema.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
},
7272
"lifeCycles": {
7373
"componentDidMount": {
74-
"type": "JSExpression",
74+
"type": "JSFunction",
7575
"value": "function() { console.log('componentDidMount'); }"
7676
}
7777
},
@@ -91,7 +91,7 @@
9191
"isSync": true
9292
},
9393
"dataHandler": {
94-
"type": "JSExpression",
94+
"type": "JSFunction",
9595
"value": "function (response) {\nif (!response.data.success){\n throw new Error(response.data.message);\n }\n return response.data.data;\n}"
9696
}
9797
},
@@ -105,13 +105,13 @@
105105
"isSync": true
106106
},
107107
"dataHandler": {
108-
"type": "JSExpression",
108+
"type": "JSFunction",
109109
"value": "function (response) {\nif (!response.data.success){\n throw new Error(response.data.message);\n }\n return response.data.data.result;\n}"
110110
}
111111
}
112112
],
113113
"dataHandler": {
114-
"type": "JSExpression",
114+
"type": "JSFunction",
115115
"value": "function (dataMap) {\n console.info(\"All datasources loaded:\", dataMap);\n}"
116116
}
117117
},

modules/code-generator/example-schema.json5

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
},
7272
lifeCycles: {
7373
componentDidMount: {
74-
type: 'JSExpression',
74+
type: 'JSFunction',
7575
value: "function() { console.log('componentDidMount'); }",
7676
},
7777
},
@@ -91,7 +91,7 @@
9191
isSync: true,
9292
},
9393
dataHandler: {
94-
type: 'JSExpression',
94+
type: 'JSFunction',
9595
value: 'function (response) {\nif (!response.data.success){\n throw new Error(response.data.message);\n }\n return response.data.data;\n}',
9696
},
9797
},
@@ -105,13 +105,13 @@
105105
isSync: true,
106106
},
107107
dataHandler: {
108-
type: 'JSExpression',
108+
type: 'JSFunction',
109109
value: 'function (response) {\nif (!response.data.success){\n throw new Error(response.data.message);\n }\n return response.data.data.result;\n}',
110110
},
111111
},
112112
],
113113
dataHandler: {
114-
type: 'JSExpression',
114+
type: 'JSFunction',
115115
value: 'function (dataMap) {\n console.info("All datasources loaded:", dataMap);\n}',
116116
},
117117
},

modules/code-generator/src/generator/ProjectBuilder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export class ProjectBuilder implements IProjectBuilder {
136136
const builders = this.createModuleBuilders({
137137
extraContextData: {
138138
projectRemark: parseResult?.project?.projectRemark,
139+
template: this.template,
139140
},
140141
});
141142
// Generator Code module
@@ -320,7 +321,7 @@ export class ProjectBuilder implements IProjectBuilder {
320321
// template: this.template,
321322
inStrictMode: this.inStrictMode,
322323
tolerateEvalErrors: true,
323-
evalErrorsHandler: 'console.error(error)',
324+
evalErrorsHandler: '',
324325
...this.extraContextData,
325326
...extraContextData,
326327
},

modules/code-generator/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* 低代码引擎的出码模块,负责将编排产出的 Schema 转换成实际可执行的代码。
3-
* 注意:为了保持 API 的稳定性, 这里所有导出的 API 均要显式命名方式导出
3+
* 注意:为了保持 API 的稳定性这里所有导出的 API 均要显式命名方式导出
44
* (即用 export { xxx } from 'xx' 的方式,不要直接 export * from 'xxx')
55
* 而且所有导出的 API 务必在 tests/public 中编写单元测试
66
*/
@@ -51,6 +51,7 @@ export default {
5151
},
5252
plugins: {
5353
common: {
54+
5455
/**
5556
* 处理 ES Module
5657
* @deprecated please use esModule

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import {
1313
} from '../../../types';
1414

1515
export interface PluginConfig {
16-
fileType: string;
16+
fileType?: string;
1717
implementType: 'inConstructor' | 'insMember' | 'hooks';
1818
}
1919

2020
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
21-
const cfg: PluginConfig = {
21+
const cfg: PluginConfig & { fileType: string } = {
2222
fileType: FileType.JSX,
2323
implementType: 'inConstructor',
2424
...config,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
FileType,
1212
ICodeStruct,
1313
} from '../../../types';
14+
import { getSlotRelativePath } from '../../../utils/pathHelper';
1415

1516
export interface PluginConfig {
1617
fileType: string;
@@ -31,9 +32,8 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
3132
type: ChunkType.STRING,
3233
fileType: cfg.fileType,
3334
name: COMMON_CHUNK_NAME.InternalDepsImport,
34-
// TODO: 下面这个路径有没有更好的方式来获取?而非写死
3535
content: `
36-
import * as __$$i18n from '../../i18n';
36+
import * as __$$i18n from '${getSlotRelativePath({ contextData: next.contextData, from: 'components', to: 'i18n' })}';
3737
`,
3838
linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport],
3939
});

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ import {
1111
FileType,
1212
ICodeStruct,
1313
IContainerInfo,
14-
IProjectTemplate,
1514
} from '../../../types';
15+
import { getSlotRelativePath } from '../../../utils/pathHelper';
1616

1717
export interface PluginConfig {
18-
fileType: string;
18+
fileType?: string;
1919

2020
/** prefer using class property to define utils */
2121
preferClassProperty?: boolean;
2222
}
2323

2424
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
25-
const cfg: PluginConfig = {
25+
const cfg: PluginConfig & { fileType: string } = {
2626
fileType: FileType.JSX,
2727
...config,
2828
};
@@ -36,26 +36,12 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
3636
next.contextData.useRefApi = true;
3737
const useRef = !!ir.analyzeResult?.isUsingRef;
3838

39-
// const isSingleComponent = next.contextData?.projectRemark?.isSingleComponent;
40-
// const template = next.contextData?.template;
41-
42-
// function getRelativeUtilsPath(template: IProjectTemplate, isSingleComponent: boolean) {
43-
// let relativeUtilsPath = '../../utils';
44-
// const utilsPath = template.slots.utils.path;
45-
// if (ir.containerType === 'Component') {
46-
// // TODO: isSingleComponent
47-
// relativeUtilsPath = getRelativePath(template.slots.components.path.join('/'), utilsPath.join('/'));
48-
// }
49-
// return relativeUtilsPath;
50-
// }
51-
5239
next.chunks.push({
5340
type: ChunkType.STRING,
5441
fileType: cfg.fileType,
5542
name: COMMON_CHUNK_NAME.InternalDepsImport,
56-
// TODO: 下面这个路径有没有更好的方式来获取?而非写死
5743
content: `
58-
import utils${useRef ? ', { RefsManager }' : ''} from '../../utils';
44+
import utils${useRef ? ', { RefsManager }' : ''} from '${getSlotRelativePath({ contextData: next.contextData, from: 'components', to: 'utils' })}';
5945
`,
6046
linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport],
6147
});

modules/code-generator/src/plugins/project/i18n.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
2525
content: `
2626
const i18nConfig = ${i18nStr};
2727
28-
// let locale = typeof navigator === 'object' && typeof navigator.language === 'string' ? navigator.language : 'zh-CN';
29-
let locale = 'zh-CN';
28+
let locale = typeof navigator === 'object' && typeof navigator.language === 'string' ? navigator.language : 'zh-CN';
3029
3130
const getLocale = () => locale;
3231

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export function parseExpressionConvertThis2Context(
271271

272272
const localVariablesSet = new Set(localVariables);
273273

274-
let thisScopeLevel = -1;
274+
let thisScopeLevel = CROSS_THIS_SCOPE_TYPE_NODE[exprAst.type] ? -1 : 0;
275275
traverse(fileAst, {
276276
enter(path) {
277277
if (CROSS_THIS_SCOPE_TYPE_NODE[path.node.type]) {
@@ -303,7 +303,7 @@ export function parseExpressionConvertThis2Context(
303303
}
304304

305305
// 替换 this (只在顶层替换)
306-
if (thisScopeLevel === 0) {
306+
if (thisScopeLevel <= 0) {
307307
obj.replaceWith(t.identifier(contextName));
308308
}
309309
},
@@ -317,7 +317,7 @@ export function parseExpressionConvertThis2Context(
317317
return;
318318
}
319319

320-
if (thisScopeLevel === 0) {
320+
if (thisScopeLevel <= 0) {
321321
path.replaceWith(t.identifier(contextName));
322322
}
323323
},

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import * as version from './version';
1212
import * as scope from './Scope';
1313
import * as expressionParser from './expressionParser';
1414
import * as dataSource from './dataSource';
15+
import * as pathHelper from './pathHelper';
1516

1617
export {
1718
common,
@@ -27,4 +28,5 @@ export {
2728
scope,
2829
expressionParser,
2930
dataSource,
31+
pathHelper,
3032
};

0 commit comments

Comments
 (0)