|
|
@ -247,14 +247,23 @@ export default class Bundle { |
|
|
|
// reinsert each statement, ensuring its strong dependencies appear first
|
|
|
|
let sorted = []; |
|
|
|
let included = blank(); |
|
|
|
let highestIndex = blank(); |
|
|
|
|
|
|
|
function include ( statement ) { |
|
|
|
if ( included[ statement.id ] ) return; |
|
|
|
included[ statement.id ] = true; |
|
|
|
|
|
|
|
let alreadyIncluded = false; |
|
|
|
|
|
|
|
const unordered = statement.index < highestIndex[ statement.module.id ]; |
|
|
|
highestIndex[ statement.module.id ] = Math.max( |
|
|
|
statement.index, |
|
|
|
highestIndex[ statement.module.id ] || 0 |
|
|
|
); |
|
|
|
|
|
|
|
if ( unordered ) { |
|
|
|
const len = sorted.length; |
|
|
|
let i = 0; |
|
|
|
let alreadyIncluded = false; |
|
|
|
|
|
|
|
for ( i = 0; i < len; i += 1 ) { |
|
|
|
// ensure that this statement appears above later statements
|
|
|
@ -263,11 +272,12 @@ export default class Bundle { |
|
|
|
const existing = sorted[i]; |
|
|
|
if ( existing.module === statement.module && existing.index > statement.index ) { |
|
|
|
sorted.splice( i, 0, statement ); |
|
|
|
alreadyIncluded = true; |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ( !alreadyIncluded ) sorted.push( statement ); |
|
|
|
sorted.push( statement ); |
|
|
|
} |
|
|
|
|
|
|
|
this.statements.forEach( statement => { |
|
|
|