Skip to content

Commit

Permalink
copy if array instead of using clone
Browse files Browse the repository at this point in the history
  • Loading branch information
hzoo committed Mar 26, 2021
1 parent 6bff19c commit 140441c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/babel-types/src/builders/builder.ts
@@ -1,4 +1,3 @@
import loClone from "lodash/clone";
import { NODE_FIELDS, BUILDER_KEYS } from "../definitions";
import validate from "../validators/validate";
import type * as t from "..";
Expand All @@ -23,7 +22,9 @@ export default function builder<T extends t.Node>(

let arg;
if (i < countArgs) arg = args[i];
if (arg === undefined) arg = loClone(field.default);
if (arg === undefined) {
arg = Array.isArray(field.default) ? [] : field.default;
}

node[key] = arg;
i++;
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-types/src/definitions/utils.ts
Expand Up @@ -280,7 +280,7 @@ export default function defineType(
for (const key of keys) {
const field = inherits.fields[key];
fields[key] = {
default: field.default,
default: Array.isArray(field.default) ? [] : field.default,
optional: field.optional,
validate: field.validate,
};
Expand Down

0 comments on commit 140441c

Please sign in to comment.