Skip to content

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

Merged
existentialism merged 2 commits intobabel:mainfrom
jayaddison:dependencies/reduce-lodash-usage-clone
Jul 9, 2020
Merged

Replace lodash 'clone' usage with ES6 Spread initializer#11811
existentialism merged 2 commits intobabel:mainfrom
jayaddison:dependencies/reduce-lodash-usage-clone

Conversation

@jayaddison
Copy link
Copy Markdown
Contributor

@jayaddison jayaddison commented Jul 9, 2020

Q                       A
Patch: Bug Fix? No
Major: Breaking Change? No
Minor: New Feature? No
Tests Added + Pass? No
Any Dependency Changes? No
License MIT

Continues removal of lodash function dependencies identified per #11789.

@babel-bot
Copy link
Copy Markdown
Collaborator

babel-bot commented Jul 9, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/25669/

@codesandbox-ci
Copy link
Copy Markdown

codesandbox-ci Bot commented Jul 9, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 6da65ba:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@nicolo-ribaudo nicolo-ribaudo added the PR: Internal 🏠 A type of pull request used for our changelog categories label Jul 9, 2020
@existentialism existentialism merged commit 55ce749 into babel:main Jul 9, 2020
mergePair(existing, fns);
} else {
visitor[alias] = clone(fns);
visitor[alias] = { ...fns };
Copy link
Copy Markdown
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
Copy Markdown
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.

@jayaddison jayaddison deleted the dependencies/reduce-lodash-usage-clone branch July 10, 2020 16:24
@github-actions github-actions Bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 10, 2020
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Internal 🏠 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants