Browse Source

include reassignments that are ignored on initial pass

better-aggressive
Rich-Harris 9 years ago
parent
commit
6c876bb110
  1. 17
      src/Bundle.js
  2. 6
      src/Module.js
  3. 3
      src/Statement.js
  4. 3
      test/function/includes-reassignments/_config.js
  5. 9
      test/function/includes-reassignments/foo.js
  6. 3
      test/function/includes-reassignments/main.js

17
src/Bundle.js

@ -75,10 +75,19 @@ export default class Bundle {
});
// mark statements that should appear in the bundle
if ( this.aggressive ) {
entryModule.markStatements();
} else {
this.modules.forEach( module => module.markStatements() );
let settled = false;
while ( !settled ) {
settled = true;
if ( this.aggressive ) {
settled = !entryModule.markStatements();
} else {
this.modules.forEach( module => {
if ( module.markStatements() ) {
settled = false;
}
});
}
}
this.orderedModules = this.sort();

6
src/Module.js

@ -279,9 +279,13 @@ export default class Module {
}
markStatements () {
let marked = false;
this.statements.forEach( statement => {
statement.secondPass( this.strongDependencies );
marked = marked || statement.secondPass( this.strongDependencies );
});
return marked;
}
namespace () {

3
src/Statement.js

@ -157,7 +157,8 @@ export default class Statement {
}
secondPass ( strongDependencies ) {
if ( this.isImportDeclaration || this.isFunctionDeclaration ) return;
if ( ( this.tested && this.isIncluded ) || this.isImportDeclaration || this.isFunctionDeclaration ) return;
this.tested = true;
if ( testForSideEffects( this.node, this.scope, this, strongDependencies ) ) {
this.mark();

3
test/function/includes-reassignments/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'includes reassignments that are ignored on an initial pass'
};

9
test/function/includes-reassignments/foo.js

@ -0,0 +1,9 @@
var answer, getAnswer;
getAnswer = function () {
return 42;
};
answer = getAnswer();
export default answer;

3
test/function/includes-reassignments/main.js

@ -0,0 +1,3 @@
import answer from './foo.js';
assert.equal( answer, 42 );
Loading…
Cancel
Save