Skip to content

Commit

Permalink
add error for field defaults that are not primitives or empty arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo committed Mar 26, 2021
1 parent aa897f8 commit 0639927
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/babel-types/src/definitions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,16 @@ export default function defineType(
const keys = Object.getOwnPropertyNames(inherits.fields);
for (const key of keys) {
const field = inherits.fields[key];
const def = field.default;
if (
Array.isArray(def) ? def.length > 0 : def && typeof def === "object"
) {
throw new Error(
"field defaults can only be primitives or empty arrays currently",
);
}
fields[key] = {
default: Array.isArray(field.default) ? [] : field.default,
default: Array.isArray(def) ? [] : def,
optional: field.optional,
validate: field.validate,
};
Expand Down

0 comments on commit 0639927

Please sign in to comment.