Use Object Spread Syntax (#7777)

* Use Object Spread Syntax

* Nits
This commit is contained in:
Justin Ridgewell
2018-04-23 21:44:27 -04:00
committed by GitHub
parent 037fee8ffb
commit 2afe9404fe
37 changed files with 263 additions and 70 deletions

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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(() => {

View File

@@ -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) {