From 2afe9404fed628bcbc084d125d1939bfee79254a Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Mon, 23 Apr 2018 21:44:27 -0400 Subject: [PATCH] Use Object Spread Syntax (#7777) * Use Object Spread Syntax * Nits --- .../.npmignore | 3 + .../README.md | 57 ++++++++++++++++++ .../package.json | 22 +++++++ .../src/index.js | 35 +++++++++++ .../multiple-objects/input.js | 1 + .../multiple-objects/options.json | 3 + .../multiple-objects/output.js | 4 ++ .../multiple/input.js | 1 + .../multiple/options.json | 3 + .../multiple/output.js | 6 ++ .../single-non-object/input.js | 1 + .../single-non-object/options.json | 3 + .../single-non-object/output.js | 1 + .../single/input.js | 1 + .../single/options.json | 3 + .../single/output.js | 3 + .../test/index.js | 3 + .../package.json | 3 +- .../src/index.js | 3 +- packages/babel-cli/src/babel/util.js | 5 +- packages/babel-code-frame/src/index.js | 15 +++-- .../babel-core/src/config/config-chain.js | 4 +- packages/babel-core/src/config/full.js | 13 +++- .../babel-core/src/transform-file-sync.js | 5 +- packages/babel-core/src/transform-file.js | 5 +- .../src/transformation/normalize-opts.js | 60 ++++++++++--------- .../src/index.js | 5 +- .../src/import-injector.js | 4 +- .../babel-helper-plugin-utils/src/index.js | 5 +- packages/babel-preset-env/src/index.js | 4 +- .../babel-preset-env/src/normalize-options.js | 4 +- packages/babel-register/src/node.js | 19 +++--- packages/babel-template/src/options.js | 5 +- packages/babel-template/src/parse.js | 14 ++--- packages/babel-types/src/clone/cloneNode.js | 4 +- packages/babylon/src/index.js | 4 +- scripts/test.sh | 2 +- 37 files changed, 263 insertions(+), 70 deletions(-) create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/.npmignore create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/README.md create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/package.json create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/src/index.js create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple-objects/input.js create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple-objects/options.json create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple-objects/output.js create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple/input.js create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple/options.json create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple/output.js create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single-non-object/input.js create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single-non-object/options.json create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single-non-object/output.js create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single/input.js create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single/options.json create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single/output.js create mode 100644 codemods/babel-plugin-codemod-object-assign-to-object-spread/test/index.js diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/.npmignore b/codemods/babel-plugin-codemod-object-assign-to-object-spread/.npmignore new file mode 100644 index 000000000000..f9806945836e --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/.npmignore @@ -0,0 +1,3 @@ +src +test +*.log diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/README.md b/codemods/babel-plugin-codemod-object-assign-to-object-spread/README.md new file mode 100644 index 000000000000..d33028bcad42 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/README.md @@ -0,0 +1,57 @@ +# @babel/plugin-codemod-object-assign-to-object-spread + +Transforms old code that uses `Object.assign` with an Object Literal as +the first param to use Object Spread syntax. + +## Examples + +```js +const obj = Object.assign({ + test1: 1, +}, other, { + test2: 2, +}, other2); +``` + +Is transformed to: + +```js +const obj = { + test1: 1, + ...other, + test2: 2, + ...other2, +}; +``` + +## Installation + +```sh +npm install --save-dev @babel/plugin-codemod-object-assign-to-object-spread +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["@babel/plugin-codemod-object-assign-to-object-spread"] +} +``` + +### Via CLI + +```sh +babel --plugins @babel/plugin-codemod-object-assign-to-object-spread script.js +``` + +### Via Node API + +```javascript +require("@babel/core").transform("code", { + plugins: ["@babel/plugin-codemod-object-assign-to-object-spread"] +}); +``` diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/package.json b/codemods/babel-plugin-codemod-object-assign-to-object-spread/package.json new file mode 100644 index 000000000000..10531d8ad302 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/package.json @@ -0,0 +1,22 @@ +{ + "name": "@babel/plugin-codemod-object-assign-to-object-spread", + "version": "7.0.0-beta.44", + "description": "Transforms Object.assign into object spread syntax", + "repository": "https://github.com/babel/babel/tree/master/codemods/babel-plugin-codemod-object-assign-to-object-spread", + "license": "MIT", + "main": "lib/index.js", + "keywords": [ + "@babel/codemod", + "@babel/plugin" + ], + "dependencies": { + "@babel/plugin-syntax-object-rest-spread": "7.0.0-beta.44" + }, + "peerDependencies": { + "@babel/core": "7.0.0-beta.44" + }, + "devDependencies": { + "@babel/core": "7.0.0-beta.44", + "@babel/helper-plugin-test-runner": "7.0.0-beta.44" + } +} diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/src/index.js b/codemods/babel-plugin-codemod-object-assign-to-object-spread/src/index.js new file mode 100644 index 000000000000..b926f40e7341 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/src/index.js @@ -0,0 +1,35 @@ +import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread"; + +export default function({ types: t }) { + return { + inherits: syntaxObjectRestSpread, + + visitor: { + CallExpression(path) { + if (!path.get("callee").matchesPattern("Object.assign")) return; + + const args = path.get("arguments"); + if (args.length === 0) return; + + const [objPath] = args; + if (!objPath.isObjectExpression()) return; + + const obj = objPath.node; + const { properties } = obj; + + for (let i = 1; i < args.length; i++) { + const arg = args[i]; + const { node } = arg; + + if (arg.isObjectExpression()) { + properties.push(...node.properties); + } else { + properties.push(t.spreadElement(node)); + } + } + + path.replaceWith(obj); + }, + }, + }; +} diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple-objects/input.js b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple-objects/input.js new file mode 100644 index 000000000000..c088e0488140 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple-objects/input.js @@ -0,0 +1 @@ +Object.assign({test: 1}, {test: 2}); diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple-objects/options.json b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple-objects/options.json new file mode 100644 index 000000000000..cbe0e9893752 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple-objects/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple-objects/output.js b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple-objects/output.js new file mode 100644 index 000000000000..a31326ad6988 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple-objects/output.js @@ -0,0 +1,4 @@ +({ + test: 1, + test: 2 +}); diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple/input.js b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple/input.js new file mode 100644 index 000000000000..d3ebd70db199 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple/input.js @@ -0,0 +1 @@ +Object.assign({test: 1}, test2, {test: 2}, test3); diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple/options.json b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple/options.json new file mode 100644 index 000000000000..cbe0e9893752 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple/output.js b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple/output.js new file mode 100644 index 000000000000..06faee7f78e0 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/multiple/output.js @@ -0,0 +1,6 @@ +({ + test: 1, + ...test2, + test: 2, + ...test3 +}); diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single-non-object/input.js b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single-non-object/input.js new file mode 100644 index 000000000000..df0f3d6dd344 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single-non-object/input.js @@ -0,0 +1 @@ +Object.assign(test); diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single-non-object/options.json b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single-non-object/options.json new file mode 100644 index 000000000000..cbe0e9893752 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single-non-object/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single-non-object/output.js b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single-non-object/output.js new file mode 100644 index 000000000000..df0f3d6dd344 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single-non-object/output.js @@ -0,0 +1 @@ +Object.assign(test); diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single/input.js b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single/input.js new file mode 100644 index 000000000000..f50c5bafbbbc --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single/input.js @@ -0,0 +1 @@ +Object.assign({test: 1}); diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single/options.json b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single/options.json new file mode 100644 index 000000000000..cbe0e9893752 --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["../../../../lib"] +} diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single/output.js b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single/output.js new file mode 100644 index 000000000000..091d7d94634e --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/fixtures/object-assign-to-object-spread/single/output.js @@ -0,0 +1,3 @@ +({ + test: 1 +}); diff --git a/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/index.js b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/index.js new file mode 100644 index 000000000000..1b534b8fc64a --- /dev/null +++ b/codemods/babel-plugin-codemod-object-assign-to-object-spread/test/index.js @@ -0,0 +1,3 @@ +import runner from "@babel/helper-plugin-test-runner"; + +runner(__dirname); diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/package.json b/codemods/babel-plugin-codemod-optional-catch-binding/package.json index 14cbdcfc54f4..5005b397e49e 100644 --- a/codemods/babel-plugin-codemod-optional-catch-binding/package.json +++ b/codemods/babel-plugin-codemod-optional-catch-binding/package.json @@ -2,10 +2,11 @@ "name": "@babel/plugin-codemod-optional-catch-binding", "version": "7.0.0-beta.46", "description": "Remove unused catch bindings", - "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-remove-unused-catch-binding", + "repository": "https://github.com/babel/babel/tree/master/codemods/babel-plugin-codemod-remove-unused-catch-binding", "license": "MIT", "main": "lib/index.js", "keywords": [ + "@babel/codemod", "@babel/plugin" ], "dependencies": { diff --git a/codemods/babel-plugin-codemod-optional-catch-binding/src/index.js b/codemods/babel-plugin-codemod-optional-catch-binding/src/index.js index 01e64898d16c..8087226dfef5 100644 --- a/codemods/babel-plugin-codemod-optional-catch-binding/src/index.js +++ b/codemods/babel-plugin-codemod-optional-catch-binding/src/index.js @@ -1,7 +1,6 @@ import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding"; -import { types as t } from "@babel/core"; -export default function() { +export default function({ types: t }) { return { inherits: syntaxOptionalCatchBinding, diff --git a/packages/babel-cli/src/babel/util.js b/packages/babel-cli/src/babel/util.js index d2b1c7795856..9baa0c72efee 100644 --- a/packages/babel-cli/src/babel/util.js +++ b/packages/babel-cli/src/babel/util.js @@ -51,9 +51,10 @@ export function log(msg, force) { } export function transform(filename, code, opts, callback) { - opts = Object.assign({}, opts, { + opts = { + ...opts, filename, - }); + }; babel.transform(code, opts, callback); } diff --git a/packages/babel-code-frame/src/index.js b/packages/babel-code-frame/src/index.js index 70237db65192..11e0095aa8ab 100644 --- a/packages/babel-code-frame/src/index.js +++ b/packages/babel-code-frame/src/index.js @@ -38,12 +38,15 @@ function getMarkerLines( source: Array, opts: Object, ): { start: number, end: number, markerLines: Object } { - const startLoc: Location = Object.assign( - {}, - { column: 0, line: -1 }, - loc.start, - ); - const endLoc: Location = Object.assign({}, startLoc, loc.end); + const startLoc: Location = { + column: 0, + line: -1, + ...loc.start, + }; + const endLoc: Location = { + ...startLoc, + ...loc.end, + }; const { linesAbove = 2, linesBelow = 3 } = opts || {}; const startLine = startLoc.line; const startColumn = startLoc.column; diff --git a/packages/babel-core/src/config/config-chain.js b/packages/babel-core/src/config/config-chain.js index 1038652bc261..05faa1cf977d 100644 --- a/packages/babel-core/src/config/config-chain.js +++ b/packages/babel-core/src/config/config-chain.js @@ -480,7 +480,9 @@ function emptyChain(): ConfigChain { } function normalizeOptions(opts: ValidatedOptions): ValidatedOptions { - const options = Object.assign({}, opts); + const options = { + ...opts, + }; delete options.extends; delete options.env; delete options.plugins; diff --git a/packages/babel-core/src/config/full.js b/packages/babel-core/src/config/full.js index 0ae4ade63bc8..8892056f7673 100644 --- a/packages/babel-core/src/config/full.js +++ b/packages/babel-core/src/config/full.js @@ -174,7 +174,10 @@ const loadDescriptor = makeWeakCache( let item = value; if (typeof value === "function") { - const api = Object.assign({}, context, makeAPI(cache)); + const api = { + ...context, + ...makeAPI(cache), + }; try { item = value(api, options, dirname); } catch (e) { @@ -229,9 +232,13 @@ const instantiatePlugin = makeWeakCache( ): Plugin => { const pluginObj = validatePluginObject(value); - const plugin = Object.assign({}, pluginObj); + const plugin = { + ...pluginObj, + }; if (plugin.visitor) { - plugin.visitor = traverse.explode(Object.assign({}, plugin.visitor)); + plugin.visitor = traverse.explode({ + ...plugin.visitor, + }); } if (plugin.inherits) { diff --git a/packages/babel-core/src/transform-file-sync.js b/packages/babel-core/src/transform-file-sync.js index 28b89e05c984..6ffc747c4a19 100644 --- a/packages/babel-core/src/transform-file-sync.js +++ b/packages/babel-core/src/transform-file-sync.js @@ -12,7 +12,10 @@ export default function transformFileSync( if (opts == null) { options = { filename }; } else if (opts && typeof opts === "object") { - options = Object.assign({}, opts, { filename }); + options = { + ...opts, + filename, + }; } const config = loadConfig(options); diff --git a/packages/babel-core/src/transform-file.js b/packages/babel-core/src/transform-file.js index e73b855c0ceb..8c16a0370733 100644 --- a/packages/babel-core/src/transform-file.js +++ b/packages/babel-core/src/transform-file.js @@ -19,7 +19,10 @@ export default ((function transformFile(filename, opts, callback) { if (opts == null) { options = { filename }; } else if (opts && typeof opts === "object") { - options = Object.assign({}, opts, { filename }); + options = { + ...opts, + filename, + }; } process.nextTick(() => { diff --git a/packages/babel-core/src/transformation/normalize-opts.js b/packages/babel-core/src/transformation/normalize-opts.js index 6cd0f32447f1..0b5dedffb2d7 100644 --- a/packages/babel-core/src/transformation/normalize-opts.js +++ b/packages/babel-core/src/transformation/normalize-opts.js @@ -22,36 +22,38 @@ export default function normalizeOptions(config: ResolvedConfig): {} { const opts = config.options; - const options = Object.assign({}, opts, { - parserOpts: Object.assign( - { - sourceType: - path.extname(filenameRelative) === ".mjs" ? "module" : sourceType, - sourceFileName: filename, - plugins: [], - }, - opts.parserOpts, - ), - generatorOpts: Object.assign( - { - // General generator flags. - filename, - auxiliaryCommentBefore: opts.auxiliaryCommentBefore, - auxiliaryCommentAfter: opts.auxiliaryCommentAfter, - retainLines: opts.retainLines, - comments, - shouldPrintComment: opts.shouldPrintComment, - compact, - minified: opts.minified, + const options = { + ...opts, - // Source-map generation flags. - sourceMaps, - sourceRoot, - sourceFileName, - }, - opts.generatorOpts, - ), - }); + parserOpts: { + sourceType: + path.extname(filenameRelative) === ".mjs" ? "module" : sourceType, + + sourceFileName: filename, + plugins: [], + ...opts.parserOpts, + }, + + generatorOpts: { + // General generator flags. + filename, + + auxiliaryCommentBefore: opts.auxiliaryCommentBefore, + auxiliaryCommentAfter: opts.auxiliaryCommentAfter, + retainLines: opts.retainLines, + comments, + shouldPrintComment: opts.shouldPrintComment, + compact, + minified: opts.minified, + + // Source-map generation flags. + sourceMaps, + + sourceRoot, + sourceFileName, + ...opts.generatorOpts, + }, + }; for (const plugins of config.passes) { for (const plugin of plugins) { diff --git a/packages/babel-helper-member-expression-to-functions/src/index.js b/packages/babel-helper-member-expression-to-functions/src/index.js index 2f6d980b6f49..b57a5e0a7e88 100644 --- a/packages/babel-helper-member-expression-to-functions/src/index.js +++ b/packages/babel-helper-member-expression-to-functions/src/index.js @@ -82,5 +82,8 @@ const handle = { // Optionally, a memoize method may be defined on the state, which will be // called when the member is a self-referential update. export default function memberExpressionToFunctions(path, visitor, state) { - path.traverse(visitor, Object.assign({}, state, handle)); + path.traverse(visitor, { + ...state, + ...handle, + }); } diff --git a/packages/babel-helper-module-imports/src/import-injector.js b/packages/babel-helper-module-imports/src/import-injector.js index bd1214c54b0f..5574ba2a3236 100644 --- a/packages/babel-helper-module-imports/src/import-injector.js +++ b/packages/babel-helper-module-imports/src/import-injector.js @@ -170,7 +170,9 @@ export default class ImportInjector { optsList.push(importedSource); } - const newOpts = Object.assign({}, this._defaultOpts); + const newOpts = { + ...this._defaultOpts, + }; for (const opts of optsList) { if (!opts) continue; Object.keys(newOpts).forEach(key => { diff --git a/packages/babel-helper-plugin-utils/src/index.js b/packages/babel-helper-plugin-utils/src/index.js index e8534608d821..f0ecb83a22e2 100644 --- a/packages/babel-helper-plugin-utils/src/index.js +++ b/packages/babel-helper-plugin-utils/src/index.js @@ -34,7 +34,10 @@ function copyApiObject(api) { } } - return Object.assign({}, proto, api); + return { + ...proto, + ...api, + }; } function has(obj, key) { diff --git a/packages/babel-preset-env/src/index.js b/packages/babel-preset-env/src/index.js index 249c46876728..bed18c728b98 100644 --- a/packages/babel-preset-env/src/index.js +++ b/packages/babel-preset-env/src/index.js @@ -95,7 +95,9 @@ export const isPluginRequired = ( }; const getBuiltInTargets = targets => { - const builtInTargets = Object.assign({}, targets); + const builtInTargets = { + ...targets, + }; if (builtInTargets.uglify != null) { delete builtInTargets.uglify; } diff --git a/packages/babel-preset-env/src/normalize-options.js b/packages/babel-preset-env/src/normalize-options.js index 8f4d3c2b2f51..5339eed6254e 100644 --- a/packages/babel-preset-env/src/normalize-options.js +++ b/packages/babel-preset-env/src/normalize-options.js @@ -177,7 +177,9 @@ export default function normalizeOptions(opts: Options) { false, ), spec: validateBoolOption("loose", opts.spec, false), - targets: Object.assign({}, opts.targets), + targets: { + ...opts.targets, + }, useBuiltIns: validateUseBuiltInsOption(opts.useBuiltIns), }; } diff --git a/packages/babel-register/src/node.js b/packages/babel-register/src/node.js index c3db5104cbfb..4d05a313e9e8 100644 --- a/packages/babel-register/src/node.js +++ b/packages/babel-register/src/node.js @@ -39,11 +39,12 @@ function mtime(filename) { function compile(code, filename) { // merge in base options and resolve all the plugins and presets relative to this file const opts = new OptionManager().init( - Object.assign( - { sourceRoot: path.dirname(filename) }, // sourceRoot can be overwritten - deepClone(transformOpts), - { filename }, - ), + // sourceRoot can be overwritten + { + sourceRoot: path.dirname(filename), + ...deepClone(transformOpts), + filename, + }, ); // Bail out ASAP if the file has been ignored. @@ -109,7 +110,9 @@ register({ export default function register(opts?: Object = {}) { // Clone to avoid mutating the arguments object with the 'delete's below. - opts = Object.assign({}, opts); + opts = { + ...opts, + }; if (opts.extensions) hookExtensions(opts.extensions); if (opts.cache === false && cache) { @@ -123,7 +126,9 @@ export default function register(opts?: Object = {}) { delete opts.extensions; delete opts.cache; - transformOpts = Object.assign({}, opts); + transformOpts = { + ...opts, + }; let { cwd = "." } = transformOpts; diff --git a/packages/babel-template/src/options.js b/packages/babel-template/src/options.js index 81fafb7ae608..fa1e275a64e9 100644 --- a/packages/babel-template/src/options.js +++ b/packages/babel-template/src/options.js @@ -44,7 +44,10 @@ export function merge(a: TemplateOpts, b: TemplateOpts): TemplateOpts { } = b; return { - parser: Object.assign({}, a.parser, b.parser), + parser: { + ...a.parser, + ...b.parser, + }, placeholderWhitelist, placeholderPattern, preserveComments, diff --git a/packages/babel-template/src/parse.js b/packages/babel-template/src/parse.js index 8599a1637f41..3e0e1264f77c 100644 --- a/packages/babel-template/src/parse.js +++ b/packages/babel-template/src/parse.js @@ -134,14 +134,12 @@ type MetadataState = { }; function parseWithCodeFrame(code: string, parserOpts: {}): BabelNodeFile { - parserOpts = Object.assign( - { - allowReturnOutsideFunction: true, - allowSuperOutsideMethod: true, - sourceType: "module", - }, - parserOpts, - ); + parserOpts = { + allowReturnOutsideFunction: true, + allowSuperOutsideMethod: true, + sourceType: "module", + ...parserOpts, + }; try { return parse(code, parserOpts); diff --git a/packages/babel-types/src/clone/cloneNode.js b/packages/babel-types/src/clone/cloneNode.js index 1fc1896fde86..6e43d191aa66 100644 --- a/packages/babel-types/src/clone/cloneNode.js +++ b/packages/babel-types/src/clone/cloneNode.js @@ -62,7 +62,9 @@ export default function cloneNode(node: T, deep: boolean = true): T { newNode.trailingComments = node.trailingComments; } if (has(node, "extra")) { - newNode.extra = Object.assign({}, node.extra); + newNode.extra = { + ...node.extra, + }; } return newNode; diff --git a/packages/babylon/src/index.js b/packages/babylon/src/index.js index a90f0af0f67a..2c1f03c66af8 100755 --- a/packages/babylon/src/index.js +++ b/packages/babylon/src/index.js @@ -19,7 +19,9 @@ plugins.typescript = typescriptPlugin; export function parse(input: string, options?: Options): File { if (options && options.sourceType === "unambiguous") { - options = Object.assign({}, options); + options = { + ...options, + }; try { options.sourceType = "module"; const parser = getParser(options, input); diff --git a/scripts/test.sh b/scripts/test.sh index c5cb866956b7..bfc5038a0d48 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -20,7 +20,7 @@ if [ -n "$TEST_GREP" ]; then fi if [ -n "$TEST_ONLY" ]; then - jestArgs+=("packages/.*$TEST_ONLY.*/test") + jestArgs+=("(packages|codemods)/.*$TEST_ONLY.*/test") fi $node node_modules/.bin/jest "${jestArgs[@]}"