Browse Source

syncify more code, remove unused promise utils

contingency-plan
Rich-Harris 10 years ago
parent
commit
0df5d9b177
  1. 43
      src/Bundle.js
  2. 1
      src/Module.js
  3. 1
      src/Statement.js
  4. 42
      src/utils/promise.js

43
src/Bundle.js

@ -82,12 +82,8 @@ export default class Bundle {
} }
} }
return entryModule.markAllStatements( true ); entryModule.markAllStatements( true );
}) this.markAllModifierStatements();
.then( () => {
return this.markAllModifierStatements();
})
.then( () => {
this.orderedModules = this.sort(); this.orderedModules = this.sort();
}); });
} }
@ -231,7 +227,6 @@ export default class Bundle {
markAllModifierStatements () { markAllModifierStatements () {
let settled = true; let settled = true;
let promises = [];
this.modules.forEach( module => { this.modules.forEach( module => {
module.statements.forEach( statement => { module.statements.forEach( statement => {
@ -248,38 +243,28 @@ export default class Bundle {
if ( shouldMark ) { if ( shouldMark ) {
settled = false; settled = false;
promises.push( statement.mark() ); statement.mark();
return; return;
} }
// special case - https://github.com/rollup/rollup/pull/40 // special case - https://github.com/rollup/rollup/pull/40
// TODO refactor this? it's a bit confusing
const importDeclaration = module.imports[ name ]; const importDeclaration = module.imports[ name ];
if ( !importDeclaration ) return; if ( !importDeclaration || importDeclaration.module.isExternal ) return;
const promise = Promise.resolve( importDeclaration.module || this.fetchModule( importDeclaration.source, module.id ) ) const otherExportDeclaration = importDeclaration.module.exports[ importDeclaration.name ];
.then( module => { // TODO things like `export default a + b` don't apply here... right?
if ( module.isExternal ) return null; const otherDefiningStatement = module.findDefiningStatement( otherExportDeclaration.localName );
importDeclaration.module = module;
const exportDeclaration = module.exports[ importDeclaration.name ];
// TODO things like `export default a + b` don't apply here... right?
return module.findDefiningStatement( exportDeclaration.localName );
})
.then( definingStatement => {
if ( !definingStatement ) return;
settled = false;
return statement.mark();
});
promises.push( promise ); if ( !otherDefiningStatement ) return;
settled = false;
statement.mark();
}); });
}); });
}); });
return Promise.all( promises ).then( () => { if ( !settled ) this.markAllModifierStatements();
if ( !settled ) return this.markAllModifierStatements();
});
} }
render ( options = {} ) { render ( options = {} ) {

1
src/Module.js

@ -4,7 +4,6 @@ import MagicString from 'magic-string';
import Statement from './Statement'; import Statement from './Statement';
import walk from './ast/walk'; import walk from './ast/walk';
import { blank, keys } from './utils/object'; import { blank, keys } from './utils/object';
import { first, sequence } from './utils/promise';
import getLocation from './utils/getLocation'; import getLocation from './utils/getLocation';
import makeLegalIdentifier from './utils/makeLegalIdentifier'; import makeLegalIdentifier from './utils/makeLegalIdentifier';

1
src/Statement.js

@ -1,5 +1,4 @@
import { blank, keys } from './utils/object'; import { blank, keys } from './utils/object';
import { sequence } from './utils/promise';
import getLocation from './utils/getLocation'; import getLocation from './utils/getLocation';
import walk from './ast/walk'; import walk from './ast/walk';
import Scope from './ast/Scope'; import Scope from './ast/Scope';

42
src/utils/promise.js

@ -1,42 +0,0 @@
import { Promise } from 'sander';
export function sequence ( arr, callback ) {
const len = arr.length;
let results = new Array( len );
let promise = Promise.resolve();
function next ( i ) {
return promise
.then( () => callback( arr[i], i ) )
.then( result => results[i] = result );
}
let i;
for ( i = 0; i < len; i += 1 ) {
promise = next( i );
}
return promise.then( () => results );
}
export function first ( arr, fail, callback ) {
const len = arr.length;
let promise = Promise.reject( fail );
function next ( i ) {
return promise
.catch(() => callback( arr[i], i ));
}
let i;
for ( i = 0; i < len; i += 1 ) {
promise = next( i );
}
return promise;
}
Loading…
Cancel
Save