object rest spread useBuiltIns option (#4491)
* feat(transform-object-rest-spread): add polyfill=false option to avoid extends helper * object-rest-spread: add useBuiltIns option * add test for invalid option
This commit is contained in:
@@ -15,6 +15,11 @@ export default function ({ types: t }) {
|
||||
ObjectExpression(path, file) {
|
||||
if (!hasSpread(path.node)) return;
|
||||
|
||||
let useBuiltIns = file.opts.useBuiltIns || false;
|
||||
if (typeof useBuiltIns !== "boolean") {
|
||||
throw new Error("transform-object-rest-spread currently only accepts a boolean option for useBuiltIns (defaults to false)");
|
||||
}
|
||||
|
||||
let args = [];
|
||||
let props = [];
|
||||
|
||||
@@ -39,7 +44,11 @@ export default function ({ types: t }) {
|
||||
args.unshift(t.objectExpression([]));
|
||||
}
|
||||
|
||||
path.replaceWith(t.callExpression(file.addHelper("extends"), args));
|
||||
const helper = useBuiltIns ?
|
||||
t.memberExpression(t.identifier("Object"), t.identifier("assign")) :
|
||||
file.addHelper("extends");
|
||||
|
||||
path.replaceWith(t.callExpression(helper, args));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user