From 0df5d9b1775d617512f59238b7e26841a3b119c4 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 22 Aug 2015 21:03:31 -0400 Subject: [PATCH] syncify more code, remove unused promise utils --- src/Bundle.js | 43 ++++++++++++++----------------------------- src/Module.js | 1 - src/Statement.js | 1 - src/utils/promise.js | 42 ------------------------------------------ 4 files changed, 14 insertions(+), 73 deletions(-) delete mode 100644 src/utils/promise.js diff --git a/src/Bundle.js b/src/Bundle.js index fe31f9e..ffb3fc2 100644 --- a/src/Bundle.js +++ b/src/Bundle.js @@ -82,12 +82,8 @@ export default class Bundle { } } - return entryModule.markAllStatements( true ); - }) - .then( () => { - return this.markAllModifierStatements(); - }) - .then( () => { + entryModule.markAllStatements( true ); + this.markAllModifierStatements(); this.orderedModules = this.sort(); }); } @@ -231,7 +227,6 @@ export default class Bundle { markAllModifierStatements () { let settled = true; - let promises = []; this.modules.forEach( module => { module.statements.forEach( statement => { @@ -248,38 +243,28 @@ export default class Bundle { if ( shouldMark ) { settled = false; - promises.push( statement.mark() ); + statement.mark(); return; } // special case - https://github.com/rollup/rollup/pull/40 + // TODO refactor this? it's a bit confusing const importDeclaration = module.imports[ name ]; - if ( !importDeclaration ) return; - - const promise = Promise.resolve( importDeclaration.module || this.fetchModule( importDeclaration.source, module.id ) ) - .then( module => { - if ( module.isExternal ) return null; - - 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(); - }); + if ( !importDeclaration || importDeclaration.module.isExternal ) return; + + const otherExportDeclaration = importDeclaration.module.exports[ importDeclaration.name ]; + // TODO things like `export default a + b` don't apply here... right? + const otherDefiningStatement = module.findDefiningStatement( otherExportDeclaration.localName ); - promises.push( promise ); + if ( !otherDefiningStatement ) return; + + settled = false; + statement.mark(); }); }); }); - return Promise.all( promises ).then( () => { - if ( !settled ) return this.markAllModifierStatements(); - }); + if ( !settled ) this.markAllModifierStatements(); } render ( options = {} ) { diff --git a/src/Module.js b/src/Module.js index fefdecd..3eb47df 100644 --- a/src/Module.js +++ b/src/Module.js @@ -4,7 +4,6 @@ import MagicString from 'magic-string'; import Statement from './Statement'; import walk from './ast/walk'; import { blank, keys } from './utils/object'; -import { first, sequence } from './utils/promise'; import getLocation from './utils/getLocation'; import makeLegalIdentifier from './utils/makeLegalIdentifier'; diff --git a/src/Statement.js b/src/Statement.js index ff7ef9c..27b70d8 100644 --- a/src/Statement.js +++ b/src/Statement.js @@ -1,5 +1,4 @@ import { blank, keys } from './utils/object'; -import { sequence } from './utils/promise'; import getLocation from './utils/getLocation'; import walk from './ast/walk'; import Scope from './ast/Scope'; diff --git a/src/utils/promise.js b/src/utils/promise.js deleted file mode 100644 index e37489d..0000000 --- a/src/utils/promise.js +++ /dev/null @@ -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; -}