fix: generated builder parameter should respect builder keys (#11002)

This commit is contained in:
Huáng Jùnliàng 2020-01-13 16:30:24 -05:00 committed by Nicolò Ribaudo
parent 8fce431d88
commit 6874c244ab
2 changed files with 19 additions and 14 deletions

View File

@ -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;
}
if (builderNames.includes(fieldName)) {
args.push(t.toBindingIdentifierName(fieldName) + suffix);
}
if (t.isValidIdentifier(fieldName)) {
struct.push(fieldName + suffix + ";");

View File

@ -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,7 +76,8 @@ for (const type in t.NODE_FIELDS) {
typeAnnotation += " | null";
}
if (areAllRemainingFieldsNullable(fieldName, fieldNames, fields)) {
if (builderNames.includes(fieldName)) {
if (areAllRemainingFieldsNullable(fieldName, builderNames, fields)) {
args.push(
`${t.toBindingIdentifierName(fieldName)}${
isNullable(field) ? "?:" : ":"
@ -88,6 +90,7 @@ for (const type in t.NODE_FIELDS) {
}`
);
}
}
const alphaNumeric = /^\w+$/;