Browse Source

Merge pull request #956 from rollup/gh-930

include all ancestors of expression with effects, up to function boundary
legacy-quote-reserved-properties
Rich Harris 8 years ago
committed by GitHub
parent
commit
aedcb007d5
  1. 4
      src/Bundle.js
  2. 4
      src/ast/nodes/UpdateExpression.js
  3. 3
      test/function/if-statement-with-assignment/_config.js
  4. 6
      test/function/if-statement-with-assignment/main.js
  5. 3
      test/function/if-statement-with-update/_config.js
  6. 6
      test/function/if-statement-with-update/main.js

4
src/Bundle.js

@ -141,7 +141,9 @@ export default class Bundle {
let i = this.dependentExpressions.length;
while ( i-- ) {
const expression = this.dependentExpressions[i];
const statement = expression.findParent( /ExpressionStatement/ );
let statement = expression;
while ( statement.parent && !/Function/.test( statement.parent.type ) ) statement = statement.parent;
if ( !statement || statement.ran ) {
this.dependentExpressions.splice( i, 1 );

4
src/ast/nodes/UpdateExpression.js

@ -28,11 +28,13 @@ export default class UpdateExpression extends Node {
}
initialise ( scope ) {
this.scope = scope;
this.module.bundle.dependentExpressions.push( this );
super.initialise( scope );
}
isUsedByBundle () {
return isUsedByBundle( this.findScope(), this.subject );
return isUsedByBundle( this.scope, this.subject );
}
}

3
test/function/if-statement-with-assignment/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'update assignments to names are preserved (#930)'
};

6
test/function/if-statement-with-assignment/main.js

@ -0,0 +1,6 @@
var result = 0;
if ( Math.random() <= 1 ) {
if ( Math.random() <= 1 ) result += 1;
}
assert.equal( result, 1 );

3
test/function/if-statement-with-update/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'updates to names are preserved (#930)'
};

6
test/function/if-statement-with-update/main.js

@ -0,0 +1,6 @@
var result = 0;
if ( Math.random() <= 1 ) {
if ( Math.random() <= 1 ) ++result;
}
assert.equal( result, 1 );
Loading…
Cancel
Save