mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-05 17:57:13 +00:00
fix: fix bug of needless undefined in oneOfType and flatten oneOfType with only one level
This commit is contained in:
parent
1f355c6a58
commit
ff9c208c05
@ -1,4 +1,4 @@
|
||||
import { omit, pick, isNil, uniq } from 'lodash';
|
||||
import { omit, pick, isNil, uniq, pull } from 'lodash';
|
||||
import { safeEval, isEvaluable } from '../utils';
|
||||
import { debug } from '../core';
|
||||
|
||||
@ -38,6 +38,7 @@ export function transformType(itemType: any) {
|
||||
case 'element':
|
||||
case 'node':
|
||||
case 'void':
|
||||
case 'undefined':
|
||||
break;
|
||||
case 'func':
|
||||
if (params) {
|
||||
@ -205,6 +206,7 @@ function combineOneOfValues(propType) {
|
||||
const newValue = [];
|
||||
let oneOfItem = null;
|
||||
let firstBooleanIndex = -1;
|
||||
|
||||
propType.value.forEach((item) => {
|
||||
if (item?.type === 'oneOf') {
|
||||
if (!oneOfItem) {
|
||||
@ -228,7 +230,14 @@ function combineOneOfValues(propType) {
|
||||
newValue.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
let result = propType;
|
||||
|
||||
if (!result.isRequired && result.value.includes('undefined')) {
|
||||
pull(result.value, 'undefined');
|
||||
pull(newValue, 'undefined');
|
||||
}
|
||||
|
||||
const oneOfItemLength = oneOfItem?.value?.length;
|
||||
if (oneOfItemLength) {
|
||||
newValue.push(oneOfItem);
|
||||
@ -247,6 +256,11 @@ function combineOneOfValues(propType) {
|
||||
};
|
||||
}
|
||||
result.value = uniq(result.value);
|
||||
|
||||
if (result.type === 'oneOfType' && result.value.length === 1) {
|
||||
result = result.value[0];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -294,6 +294,10 @@ function getDocgenTypeHelper(
|
||||
return makeResult({
|
||||
name: 'any',
|
||||
});
|
||||
} else if (type.flags & TypeFlags.Undefined) {
|
||||
return makeResult({
|
||||
name: 'undefined',
|
||||
});
|
||||
} else if (type.flags & TypeFlags.Union && !isComplexType(type)) {
|
||||
return makeResult({
|
||||
name: 'union',
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user