mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 11:20:11 +00:00
fix: fix empty string lost when generate variable
This commit is contained in:
parent
407a620b32
commit
3b72278867
@ -134,13 +134,14 @@ function generateUnknownType(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (options.handlers?.expression) {
|
if (options.handlers?.expression) {
|
||||||
return executeFunctionStack(
|
const expression = executeFunctionStack(
|
||||||
transValue,
|
transValue,
|
||||||
scope,
|
scope,
|
||||||
options.handlers.expression,
|
options.handlers.expression,
|
||||||
generateExpression,
|
generateExpression,
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
return expression || 'undefined';
|
||||||
}
|
}
|
||||||
return generateExpression(transValue, scope);
|
return generateExpression(transValue, scope);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { generateCompositeType } from '../../src/utils/compositeType';
|
import { generateCompositeType } from '../../src/utils/compositeType';
|
||||||
|
import { parseExpressionConvertThis2Context } from '../../src/utils/expressionParser';
|
||||||
import { Scope } from '../../src/utils/Scope';
|
import { Scope } from '../../src/utils/Scope';
|
||||||
|
|
||||||
test('single line string', () => {
|
test('single line string', () => {
|
||||||
@ -16,3 +17,125 @@ test('string with single quote', () => {
|
|||||||
test('string with double quote', () => {
|
test('string with double quote', () => {
|
||||||
expect(generateCompositeType('a"bc', Scope.createRootScope())).toEqual('"a\\"bc"');
|
expect(generateCompositeType('a"bc', Scope.createRootScope())).toEqual('"a\\"bc"');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const marcoFactory = () => {
|
||||||
|
const cases: any[] = [];
|
||||||
|
|
||||||
|
const marco = (value: any, cb: (expression: string) => void) => {
|
||||||
|
cases.push([value, cb]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const start = () => {
|
||||||
|
test.each(cases)('parse expression %s', (item, cb) => {
|
||||||
|
const testObj = {
|
||||||
|
globalConfig: {},
|
||||||
|
online: [
|
||||||
|
{
|
||||||
|
description: '表格(CnTable)的数据源',
|
||||||
|
initialData: {
|
||||||
|
type: 'variable',
|
||||||
|
variable: item,
|
||||||
|
value: '',
|
||||||
|
},
|
||||||
|
somethingelse: 'somethingelse',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const ret = generateCompositeType(testObj, Scope.createRootScope(), {
|
||||||
|
handlers: {
|
||||||
|
function: (jsFunc) => parseExpressionConvertThis2Context(jsFunc.value, '_this'),
|
||||||
|
expression: (jsExpr) => parseExpressionConvertThis2Context(jsExpr.value, '_this'),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
cb(ret);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return { marco, start };
|
||||||
|
};
|
||||||
|
|
||||||
|
const { marco: testMarco, start: startMarco } = marcoFactory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* dataSource 为低码编辑器里面数据源的输入
|
||||||
|
* variable 为 schema 存储的结果
|
||||||
|
* expect 为出码后期望生产的串
|
||||||
|
|
||||||
|
* |dataSource | variable | expect
|
||||||
|
* |-------------------|----------------------------|--------------
|
||||||
|
* |"" | "\"\"" | ""
|
||||||
|
* |"helo world" | "\"hello world\"" | "hello world"
|
||||||
|
* |true | "true" | true
|
||||||
|
* |false | "false" | false
|
||||||
|
* |{"name": gaokai} | "{\"name\": \"cone\"}" | {"name": gaokai}
|
||||||
|
* | | "" | undefined
|
||||||
|
* |undefined | "undefined" | undefined
|
||||||
|
* |null | "null" | null
|
||||||
|
*/
|
||||||
|
|
||||||
|
testMarco('""', (expression) => {
|
||||||
|
expect(expression).toMatchInlineSnapshot(`
|
||||||
|
"{\\"globalConfig\\": {},
|
||||||
|
\\"online\\": [{\\"description\\": \\"表格(CnTable)的数据源\\",
|
||||||
|
\\"initialData\\": \\"\\",
|
||||||
|
\\"somethingelse\\": \\"somethingelse\\"}]}"
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
testMarco('"hello world"', (expression) => {
|
||||||
|
expect(expression).toMatchInlineSnapshot(`
|
||||||
|
"{\\"globalConfig\\": {},
|
||||||
|
\\"online\\": [{\\"description\\": \\"表格(CnTable)的数据源\\",
|
||||||
|
\\"initialData\\": \\"hello world\\",
|
||||||
|
\\"somethingelse\\": \\"somethingelse\\"}]}"
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
testMarco('true', (expression) => {
|
||||||
|
expect(expression).toMatchInlineSnapshot(`
|
||||||
|
"{\\"globalConfig\\": {},
|
||||||
|
\\"online\\": [{\\"description\\": \\"表格(CnTable)的数据源\\",
|
||||||
|
\\"initialData\\": true,
|
||||||
|
\\"somethingelse\\": \\"somethingelse\\"}]}"
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
testMarco('{"name": "cone"}', (expression) => {
|
||||||
|
expect(expression).toMatchInlineSnapshot(`
|
||||||
|
"{\\"globalConfig\\": {},
|
||||||
|
\\"online\\": [{\\"description\\": \\"表格(CnTable)的数据源\\",
|
||||||
|
\\"initialData\\": {
|
||||||
|
\\"name\\": \\"cone\\"
|
||||||
|
},
|
||||||
|
\\"somethingelse\\": \\"somethingelse\\"}]}"
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
testMarco('', (expression) => {
|
||||||
|
expect(expression).toMatchInlineSnapshot(`
|
||||||
|
"{\\"globalConfig\\": {},
|
||||||
|
\\"online\\": [{\\"description\\": \\"表格(CnTable)的数据源\\",
|
||||||
|
\\"initialData\\": undefined,
|
||||||
|
\\"somethingelse\\": \\"somethingelse\\"}]}"
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
testMarco('undefined', (expression) => {
|
||||||
|
expect(expression).toMatchInlineSnapshot(`
|
||||||
|
"{\\"globalConfig\\": {},
|
||||||
|
\\"online\\": [{\\"description\\": \\"表格(CnTable)的数据源\\",
|
||||||
|
\\"initialData\\": undefined,
|
||||||
|
\\"somethingelse\\": \\"somethingelse\\"}]}"
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
testMarco('null', (expression) => {
|
||||||
|
expect(expression).toMatchInlineSnapshot(`
|
||||||
|
"{\\"globalConfig\\": {},
|
||||||
|
\\"online\\": [{\\"description\\": \\"表格(CnTable)的数据源\\",
|
||||||
|
\\"initialData\\": null,
|
||||||
|
\\"somethingelse\\": \\"somethingelse\\"}]}"
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
startMarco();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user