Commit 772ef241 by kzc Committed by Marijn Haverbeke

fix some cases involving assignment of exponentiation assignment #122

parent 1fa59fbd
Pipeline #5380596 passed with stage
in 2 minutes 39 seconds
......@@ -223,7 +223,10 @@ export default class AssignmentExpression extends Node {
let declarators = [];
if ( needsObjectVar ) declarators.push( object );
if ( needsPropertyVar ) declarators.push( property );
code.insertRight( statement.start, `var ${declarators.join( ', ' )};\n${i0}` );
if ( declarators.length ) {
code.insertRight( statement.start, `var ${declarators.join( ', ' )};\n${i0}` );
}
if ( needsObjectVar && needsPropertyVar ) {
code.insertRight( left.start, `( ${object} = ` );
......@@ -245,7 +248,9 @@ export default class AssignmentExpression extends Node {
code.remove( left.property.end, left.end );
}
code.insertLeft( this.end, ` )` );
if ( needsPropertyVar ) {
code.insertLeft( this.end, ` )` );
}
}
base = object + ( left.computed || needsPropertyVar ? `[${property}]` : `.${property}` );
......
......@@ -139,5 +139,40 @@ module.exports = [
for ( var i$1 = 1.1; i$1 < 1e6; i$1 = Math.pow( i$1, i$1 ) ) loop( i$1 );
}`
}
},
{
description: 'handles assignment of exponentiation assignment to property',
input: `
x=a.b**=2;
`,
output: `
x=a.b=Math.pow( a.b, 2 );
`
},
{
description: 'handles assignment of exponentiation assignment to property with side effect',
input: `
x=a[bar()]**=2;
`,
output: `
var property;
x=( property = bar(), a[property]=Math.pow( a[property], 2 ) );
`
},
/* TODO: Test currently errors out with: TypeError: Cannot read property 'property' of null
{
description: 'handles assignment of exponentiation assignment to property with side effect within a block-less if',
input: `
if(y)x=a[foo()]**=2;
`,
output: `
`
},
*/
];
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