Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace lodash 'clone' usage with ES6 Spread initializer #11811

Merged
merged 2 commits into from Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/babel-helper-fixtures/src/index.js
@@ -1,5 +1,4 @@
import cloneDeep from "lodash/cloneDeep";
import clone from "lodash/clone";
import semver from "semver";
import path from "path";
import fs from "fs";
Expand Down Expand Up @@ -262,7 +261,7 @@ export default function get(entryLoc): Array<Suite> {
if (shouldIgnore(suiteName)) continue;

const suite = {
options: clone(rootOpts),
options: { ...rootOpts },
tests: [],
title: humanize(suiteName),
filename: entryLoc + "/" + suiteName,
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-traverse/src/visitors.js
@@ -1,6 +1,5 @@
import * as virtualTypes from "./path/lib/virtual-types";
import * as t from "@babel/types";
import clone from "lodash/clone";

/**
* explode() will take a visitor object with all of the various shorthands
Expand Down Expand Up @@ -106,7 +105,7 @@ export function explode(visitor) {
if (existing) {
mergePair(existing, fns);
} else {
visitor[alias] = clone(fns);
visitor[alias] = { ...fns };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jayaddison Sorry I missed this while it was open but I think this could introduce an edge case behavior change if fns has any non-enumerable values in the prototype chain. A better replacement might be:

visitor[alias] = Object.create(Object.getPrototypeOf(fns));
Object.assign(visitor[alias], fns);

Here the cloned object is created with the prototype of fns, then Object.assign copies only the own iterable properties from fns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem at all, thanks for catching this. Fixup opened in #11820.

}
}
}
Expand Down