Skip to content

Commit

Permalink
Allow disabling spread properties transpiling
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianheine committed Oct 12, 2018
1 parent 9a79122 commit 24b1fab
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/program/types/AssignmentExpression.js
Expand Up @@ -30,7 +30,7 @@ export default class AssignmentExpression extends Node {
if (this.operator === '**=' && transforms.exponentiation) {
this.transpileExponentiation(code, transforms);
} else if (/Pattern/.test(this.left.type) && transforms.destructuring) {
this.transpileDestructuring(code, transforms);
this.transpileDestructuring(code);
}

super.transpile(code, transforms);
Expand Down
2 changes: 1 addition & 1 deletion src/program/types/ObjectExpression.js
Expand Up @@ -25,7 +25,7 @@ export default class ObjectExpression extends Node {
}
}

if (spreadPropertyCount) {
if (spreadPropertyCount && transforms.objectRestSpread) {
if (!this.program.options.objectAssign) {
throw new CompileError(
"Object spread operator requires specified objectAssign option with 'Object.assign' or polyfill helper.",
Expand Down
2 changes: 1 addition & 1 deletion src/program/types/SpreadElement.js
Expand Up @@ -2,7 +2,7 @@ import Node from '../Node.js';

export default class SpreadElement extends Node {
transpile(code, transforms) {
if (this.parent.type == 'ObjectExpression') {
if (transforms.objectRestSpread && this.parent.type == 'ObjectExpression') {
code.remove(this.start, this.argument.start);
code.remove(this.argument.end, this.end);
}
Expand Down
38 changes: 37 additions & 1 deletion test/samples/object-rest-spread.js
Expand Up @@ -89,7 +89,43 @@ module.exports = [
var a12 = Object.assign({}, b, ( obj$8 = {}, obj$8[c] = 3, obj$8 ), {d:4});
`
},

{
description: 'doesn\'t transpile objects with spread with computed property if disabled',
options: {
objectAssign: 'Object.assign',
transforms: { objectRestSpread: false, computedProperty: false, conciseMethodProperty: false }
},
input: `
var a0 = { [ x ] : true , ... y };
var a1 = { [ w ] : 0 , [ x ] : true , ... y };
var a2 = { v, [ w ] : 0, [ x ] : true, ... y };
var a3 = { [ w ] : 0, [ x ] : true };
var a4 = { [ w ] : 0 , [ x ] : true , y };
var a5 = { k : 9 , [ x ] : true, ... y };
var a6 = { ... y, [ x ] : true };
var a7 = { ... y, [ w ] : 0, [ x ] : true };
var a8 = { k : 9, ... y, [ x ] : true };
var a9 = { [ x ] : true , [ y ] : false , [ z ] : 9 };
var a10 = { [ x ] : true, ...y, p, ...q };
var a11 = { x, [c] : 9 , y };
var a12 = { ...b, [c]:3, d:4 };
`,
output: `
var a0 = { [ x ] : true , ... y };
var a1 = { [ w ] : 0 , [ x ] : true , ... y };
var a2 = { v, [ w ] : 0, [ x ] : true, ... y };
var a3 = { [ w ] : 0, [ x ] : true };
var a4 = { [ w ] : 0 , [ x ] : true , y };
var a5 = { k : 9 , [ x ] : true, ... y };
var a6 = { ... y, [ x ] : true };
var a7 = { ... y, [ w ] : 0, [ x ] : true };
var a8 = { k : 9, ... y, [ x ] : true };
var a9 = { [ x ] : true , [ y ] : false , [ z ] : 9 };
var a10 = { [ x ] : true, ...y, p, ...q };
var a11 = { x, [c] : 9 , y };
var a12 = { ...b, [c]:3, d:4 };
`
},
{
description:
'transpiles inline objects with spread with computed property (#144)',
Expand Down

0 comments on commit 24b1fab

Please sign in to comment.