GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: 兼容 isJSExpression 不包含函数类型的修改 · Juny0117/lowcode-engine@da7ff59

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • modules/code-generator/src
    • plugins
      • component
        • rax
          • containerLifeCycle.ts
          • jsx.ts
        • react
          • containerInjectDataSourceEngine.ts
      • project
        • i18n.ts
    • utils
      • common.ts
      • compositeType.ts
      • dataSource.ts
      • jsExpression.ts
      • schema.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎modules/code-generator/src/plugins/component/rax/containerLifeCycle.ts‎

Copy file name to clipboardExpand all lines: modules/code-generator/src/plugins/component/rax/containerLifeCycle.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
IContainerInfo,
1414
} from '../../../types';
1515
import { debug } from '../../../utils/debug';
16+
import { isJSExpressionFn } from '../../../utils/common';
1617

1718
export interface PluginConfig {
1819
fileType: string;
@@ -49,6 +50,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
4950
// 过滤掉非法数据(有些场景下会误传入空字符串或 null)
5051
if (
5152
!isJSFunction(lifeCycles[lifeCycleName]) &&
53+
!isJSExpressionFn(lifeCycles[lifeCycleName]) &&
5254
!isJSExpression(lifeCycles[lifeCycleName])
5355
) {
5456
return;
Collapse file

‎modules/code-generator/src/plugins/component/rax/jsx.ts‎

Copy file name to clipboardExpand all lines: modules/code-generator/src/plugins/component/rax/jsx.ts
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
7575

7676
// 注意:这里其实隐含了一个假设:schema 中的 componentName 应该是一个有效的 JS 标识符,而且是大写字母打头的
7777
// FIXME: 为了快速修复临时加的逻辑,需要用 pre-process 的方式替代处理。
78-
const mapComponentNameToAliasOrKeepIt = (componentName: string) =>
79-
componentsNameAliasMap.get(componentName) || componentName;
78+
const mapComponentNameToAliasOrKeepIt = (componentName: string) => componentsNameAliasMap.get(componentName) || componentName;
8079

8180
// 然后过滤掉所有的别名 chunks
8281
next.chunks = next.chunks.filter((chunk) => !isImportAliasDefineChunk(chunk));
Collapse file

‎modules/code-generator/src/plugins/component/react/containerInjectDataSourceEngine.ts‎

Copy file name to clipboardExpand all lines: modules/code-generator/src/plugins/component/react/containerInjectDataSourceEngine.ts
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { generateCompositeType } from '../../../utils/compositeType';
2929
import { parseExpressionConvertThis2Context } from '../../../utils/expressionParser';
3030
import { isValidContainerType } from '../../../utils/schema';
3131
import { REACT_CHUNK_NAME } from './const';
32+
import { isJSExpressionFn } from '../../../utils/common';
3233

3334
export interface PluginConfig {
3435
fileType?: string;
@@ -37,6 +38,7 @@ export interface PluginConfig {
3738
* 数据源配置
3839
*/
3940
datasourceConfig?: {
41+
4042
/** 数据源引擎的版本 */
4143
engineVersion?: string;
4244

@@ -188,15 +190,15 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
188190
export default pluginFactory;
189191

190192
function wrapAsFunction(value: IPublicTypeCompositeValue, scope: IScope): IPublicTypeCompositeValue {
191-
if (isJSExpression(value) || isJSFunction(value)) {
193+
if (isJSExpression(value) || isJSFunction(value) || isJSExpressionFn(value)) {
192194
return {
193195
type: 'JSExpression',
194-
value: `function(){ return ((${value.value}))}`,
196+
value: `function(){ return ((${value.value}))}.bind(this)`,
195197
};
196198
}
197199

198200
return {
199201
type: 'JSExpression',
200-
value: `function(){return((${generateCompositeType(value, scope)}))}`,
202+
value: `function(){return((${generateCompositeType(value, scope)}))}.bind(this)`,
201203
};
202204
}
Collapse file

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

Copy file name to clipboardExpand all lines: modules/code-generator/src/plugins/project/i18n.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ 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';
28+
// let locale = typeof navigator === 'object' && typeof navigator.language === 'string' ? navigator.language : 'zh-CN';
29+
let locale = 'zh-CN';
2930
3031
const getLocale = () => locale;
3132
Collapse file

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

Copy file name to clipboardExpand all lines: modules/code-generator/src/utils/common.ts
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { IPublicTypeJSExpression, IPublicTypeJSFunction } from '@alilc/lowcode-types';
12
import changeCase from 'change-case';
23
import short from 'short-uuid';
34

@@ -39,3 +40,7 @@ export function getStaticExprValue<T>(expr: string): T {
3940
// eslint-disable-next-line no-new-func
4041
return Function(`"use strict";return (${expr})`)();
4142
}
43+
44+
export function isJSExpressionFn(data: any): data is IPublicTypeJSFunction {
45+
return data?.type === 'JSExpression' && data?.extType === 'function';
46+
}
Collapse file

‎modules/code-generator/src/utils/compositeType.ts‎

Copy file name to clipboardExpand all lines: modules/code-generator/src/utils/compositeType.ts
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { generateExpression, generateFunction } from './jsExpression';
1616
import { generateJsSlot } from './jsSlot';
1717
import { executeFunctionStack } from './aopHelper';
1818
import { parseExpressionGetKeywords } from './expressionParser';
19+
import { isJSExpressionFn } from './common';
1920

2021
interface ILegaoVariable {
2122
type: 'variable';
@@ -159,7 +160,7 @@ function generateUnknownType(
159160
return generateExpression(value, scope);
160161
}
161162

162-
if (isJSFunction(value)) {
163+
if (isJSFunction(value) || isJSExpressionFn(value)) {
163164
if (options.handlers?.function) {
164165
return executeFunctionStack(value, scope, options.handlers.function, genFunction, options);
165166
}
Collapse file

‎modules/code-generator/src/utils/dataSource.ts‎

Copy file name to clipboardExpand all lines: modules/code-generator/src/utils/dataSource.ts
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ import changeCase from 'change-case';
22
import type { IProjectInfo } from '../types/intermediate';
33

44
export interface DataSourceDependenciesConfig {
5+
56
/** 数据源引擎的版本 */
67
engineVersion?: string;
8+
79
/** 数据源引擎的包名 */
810
enginePackage?: string;
11+
912
/** 数据源 handlers 的版本 */
1013
handlersVersion?: {
1114
[key: string]: string;
1215
};
16+
1317
/** 数据源 handlers 的包名 */
1418
handlersPackages?: {
1519
[key: string]: string;
Collapse file

‎modules/code-generator/src/utils/jsExpression.ts‎

Copy file name to clipboardExpand all lines: modules/code-generator/src/utils/jsExpression.ts
+12-6Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as t from '@babel/types';
55
import { IPublicTypeJSExpression, IPublicTypeJSFunction, isJSExpression, isJSFunction } from '@alilc/lowcode-types';
66
import { CodeGeneratorError, IScope } from '../types';
77
import { transformExpressionLocalRef, ParseError } from './expressionParser';
8+
import { isJSExpressionFn } from './common';
89

910
function parseFunction(content: string): t.FunctionExpression | null {
1011
try {
@@ -79,7 +80,7 @@ function getBodyStatements(content: string) {
7980
}
8081

8182
export function isJsCode(value: unknown): boolean {
82-
return isJSExpression(value) || isJSFunction(value);
83+
return isJSExpressionFn(value) || isJSFunction(value);
8384
}
8485

8586
export function generateExpression(value: any, scope: IScope): string {
@@ -96,6 +97,10 @@ export function generateExpression(value: any, scope: IScope): string {
9697
throw new CodeGeneratorError('Not a JSExpression');
9798
}
9899

100+
function getFunctionSource(cfg: IPublicTypeJSFunction): string {
101+
return cfg.source || cfg.value || cfg.compiled;
102+
}
103+
99104
export function generateFunction(
100105
value: any,
101106
config: {
@@ -114,19 +119,20 @@ export function generateFunction(
114119
) {
115120
if (isJsCode(value)) {
116121
const functionCfg = value as IPublicTypeJSFunction;
122+
const functionSource = getFunctionSource(functionCfg);
117123
if (config.isMember) {
118-
return transformFuncExpr2MethodMember(config.name || '', functionCfg.value);
124+
return transformFuncExpr2MethodMember(config.name || '', functionSource);
119125
}
120126
if (config.isBlock) {
121-
return getBodyStatements(functionCfg.value);
127+
return getBodyStatements(functionSource);
122128
}
123129
if (config.isArrow) {
124-
return getArrowFunction(functionCfg.value);
130+
return getArrowFunction(functionSource);
125131
}
126132
if (config.isBindExpr) {
127-
return `(${functionCfg.value}).bind(this)`;
133+
return `(${functionSource}).bind(this)`;
128134
}
129-
return functionCfg.value;
135+
return functionSource;
130136
}
131137

132138
throw new CodeGeneratorError('Not a JSFunction or JSExpression');
Collapse file

‎modules/code-generator/src/utils/schema.ts‎

Copy file name to clipboardExpand all lines: modules/code-generator/src/utils/schema.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
isJSFunction,
1414
} from '@alilc/lowcode-types';
1515
import { CodeGeneratorError } from '../types/error';
16+
import { isJSExpressionFn } from './common';
1617

1718
export function isContainerSchema(x: any): x is IPublicTypeContainerSchema {
1819
return (
@@ -128,6 +129,7 @@ export function handleSubNodes<T>(
128129
// IPublicTypeCompositeObject
129130
if (
130131
!isJSExpression(value) &&
132+
!isJSExpressionFn(value) &&
131133
!isJSFunction(value) &&
132134
typeof value === 'object' &&
133135
value !== null

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.