@@ -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);
|
||||
}
|
||||
|
||||
@@ -38,12 +38,15 @@ function getMarkerLines(
|
||||
source: Array<string>,
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
@@ -34,7 +34,10 @@ function copyApiObject(api) {
|
||||
}
|
||||
}
|
||||
|
||||
return Object.assign({}, proto, api);
|
||||
return {
|
||||
...proto,
|
||||
...api,
|
||||
};
|
||||
}
|
||||
|
||||
function has(obj, key) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -62,7 +62,9 @@ export default function cloneNode<T: Object>(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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user