fix: generated builder parameter should respect builder keys (#11002)
This commit is contained in:
parent
8fce431d88
commit
6874c244ab
@ -54,6 +54,7 @@ for (const type in t.NODE_FIELDS) {
|
||||
|
||||
const struct = ['type: "' + type + '";'];
|
||||
const args = [];
|
||||
const builderNames = t.BUILDER_KEYS[type];
|
||||
|
||||
Object.keys(t.NODE_FIELDS[type])
|
||||
.sort((fieldA, fieldB) => {
|
||||
@ -80,8 +81,9 @@ for (const type in t.NODE_FIELDS) {
|
||||
if (typeAnnotation) {
|
||||
suffix += ": " + typeAnnotation;
|
||||
}
|
||||
|
||||
args.push(t.toBindingIdentifierName(fieldName) + suffix);
|
||||
if (builderNames.includes(fieldName)) {
|
||||
args.push(t.toBindingIdentifierName(fieldName) + suffix);
|
||||
}
|
||||
|
||||
if (t.isValidIdentifier(fieldName)) {
|
||||
struct.push(fieldName + suffix + ";");
|
||||
|
||||
@ -56,6 +56,7 @@ const lines = [];
|
||||
for (const type in t.NODE_FIELDS) {
|
||||
const fields = t.NODE_FIELDS[type];
|
||||
const fieldNames = sortFieldNames(Object.keys(t.NODE_FIELDS[type]), type);
|
||||
const builderNames = t.BUILDER_KEYS[type];
|
||||
|
||||
const struct = ['type: "' + type + '";'];
|
||||
const args = [];
|
||||
@ -75,18 +76,20 @@ for (const type in t.NODE_FIELDS) {
|
||||
typeAnnotation += " | null";
|
||||
}
|
||||
|
||||
if (areAllRemainingFieldsNullable(fieldName, fieldNames, fields)) {
|
||||
args.push(
|
||||
`${t.toBindingIdentifierName(fieldName)}${
|
||||
isNullable(field) ? "?:" : ":"
|
||||
} ${typeAnnotation}`
|
||||
);
|
||||
} else {
|
||||
args.push(
|
||||
`${t.toBindingIdentifierName(fieldName)}: ${typeAnnotation}${
|
||||
isNullable(field) ? " | undefined" : ""
|
||||
}`
|
||||
);
|
||||
if (builderNames.includes(fieldName)) {
|
||||
if (areAllRemainingFieldsNullable(fieldName, builderNames, fields)) {
|
||||
args.push(
|
||||
`${t.toBindingIdentifierName(fieldName)}${
|
||||
isNullable(field) ? "?:" : ":"
|
||||
} ${typeAnnotation}`
|
||||
);
|
||||
} else {
|
||||
args.push(
|
||||
`${t.toBindingIdentifierName(fieldName)}: ${typeAnnotation}${
|
||||
isNullable(field) ? " | undefined" : ""
|
||||
}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const alphaNumeric = /^\w+$/;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user