Commit 4adeb4eb by kzc Committed by Marijn Haverbeke

fix object literal with computed property within arrow expression #126

parent 1bf8b124
......@@ -74,7 +74,7 @@ export default class ObjectExpression extends Node {
name = this.findScope( true ).createIdentifier( 'obj' );
const statement = this.findNearest( /(?:Statement|Declaration)$/ );
code.insertRight( statement.start, `var ${name};\n${i0}` );
code.insertLeft( statement.end, `\n${i0}var ${name};` );
code.insertRight( this.start, `( ${name} = ` );
}
......
......@@ -106,8 +106,8 @@ module.exports = [
var a = 'foo', obj = { [a]: 'bar', x: 42 }, bar = obj.foo;`,
output: `
var obj$1;
var a = 'foo', obj = ( obj$1 = { x: 42 }, obj$1[a] = 'bar', obj$1 ), bar = obj.foo;`
var a = 'foo', obj = ( obj$1 = { x: 42 }, obj$1[a] = 'bar', obj$1 ), bar = obj.foo;
var obj$1;`
},
{
......@@ -138,8 +138,8 @@ module.exports = [
call({ [a]: 5 });`,
output: `
var obj;
call(( obj = {}, obj[a] = 5, obj ));`
call(( obj = {}, obj[a] = 5, obj ));
var obj;`
},
{
......@@ -215,4 +215,17 @@ module.exports = [
};
`
},
{
description: 'object literal with computed property within arrow expression (#126)',
input: `
foo => bar({[x - y]: obj});
`,
output: `
(function(foo) { return bar(( obj$1 = {}, obj$1[x - y] = obj, obj$1 ))
var obj$1;; });
`
},
];
......@@ -102,11 +102,11 @@ module.exports = [
`,
output: `
if (1)
{ var obj;
console.log(JSON.stringify(( obj = {}, obj['com'+'puted'] = 1, obj['foo'] = 2, obj ))); }
{ console.log(JSON.stringify(( obj = {}, obj['com'+'puted'] = 1, obj['foo'] = 2, obj )));
var obj; }
else
{ var obj$1;
console.log(JSON.stringify(( obj$1 = {}, obj$1['bar'] = 3, obj$1 ))); }
{ console.log(JSON.stringify(( obj$1 = {}, obj$1['bar'] = 3, obj$1 )));
var obj$1; }
`
},
];
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment