Browse Source

fix #34, albeit kludgily

contingency-plan
Rich Harris 10 years ago
parent
commit
1f2d719b89
  1. 10
      src/Bundle.js
  2. 8
      test/form/block-comments/_expected/amd.js
  3. 8
      test/form/block-comments/_expected/cjs.js
  4. 8
      test/form/block-comments/_expected/es6.js
  5. 8
      test/form/block-comments/_expected/iife.js
  6. 8
      test/form/block-comments/_expected/umd.js
  7. 8
      test/form/self-contained-bundle/_expected/amd.js
  8. 8
      test/form/self-contained-bundle/_expected/cjs.js
  9. 8
      test/form/self-contained-bundle/_expected/es6.js
  10. 8
      test/form/self-contained-bundle/_expected/iife.js
  11. 8
      test/form/self-contained-bundle/_expected/umd.js
  12. 8
      test/function/retains-sort-order/_config.js
  13. 1
      test/function/retains-sort-order/baz.js
  14. 15
      test/function/retains-sort-order/foobar.js
  15. 4
      test/function/retains-sort-order/main.js

10
src/Bundle.js

@ -247,6 +247,16 @@ export default class Bundle {
let previousIndex = -1;
let previousMargin = 0;
this.statements.forEach( ( statement, i ) => {
statement.bundleIndex = i;
});
this.statements.sort( ( a, b ) => {
return a.module !== b.module ?
a.bundleIndex - b.bundleIndex :
a.index - b.index;
});
this.statements.forEach( statement => {
// skip `export { foo, bar, baz }`
if ( statement.node.type === 'ExportNamedDeclaration' && statement.node.specifiers.length ) {

8
test/form/block-comments/_expected/amd.js

@ -1,5 +1,9 @@
define(function () { 'use strict';
function foo () {
return embiggen( 6, 7 );
}
/**
* Embiggens a number
* @param {number} num - the number to embiggen
@ -10,10 +14,6 @@ define(function () { 'use strict';
return num * factor;
}
function foo () {
return embiggen( 6, 7 );
}
alert( foo() );
});

8
test/form/block-comments/_expected/cjs.js

@ -1,5 +1,9 @@
'use strict';
function foo () {
return embiggen( 6, 7 );
}
/**
* Embiggens a number
* @param {number} num - the number to embiggen
@ -10,8 +14,4 @@ function embiggen ( num, factor ) {
return num * factor;
}
function foo () {
return embiggen( 6, 7 );
}
alert( foo() );

8
test/form/block-comments/_expected/es6.js

@ -1,3 +1,7 @@
function foo () {
return embiggen( 6, 7 );
}
/**
* Embiggens a number
* @param {number} num - the number to embiggen
@ -8,8 +12,4 @@ function embiggen ( num, factor ) {
return num * factor;
}
function foo () {
return embiggen( 6, 7 );
}
alert( foo() );

8
test/form/block-comments/_expected/iife.js

@ -1,5 +1,9 @@
(function () { 'use strict';
function foo () {
return embiggen( 6, 7 );
}
/**
* Embiggens a number
* @param {number} num - the number to embiggen
@ -10,10 +14,6 @@
return num * factor;
}
function foo () {
return embiggen( 6, 7 );
}
alert( foo() );
})();

8
test/form/block-comments/_expected/umd.js

@ -4,6 +4,10 @@
factory();
}(this, function () { 'use strict';
function foo () {
return embiggen( 6, 7 );
}
/**
* Embiggens a number
* @param {number} num - the number to embiggen
@ -14,10 +18,6 @@
return num * factor;
}
function foo () {
return embiggen( 6, 7 );
}
alert( foo() );
}));

8
test/form/self-contained-bundle/_expected/amd.js

@ -5,14 +5,14 @@ define(function () { 'use strict';
console.log( 1 );
console.log( 2 ); // comment alongside 2
function bar () {
return 42;
}
function foo () {
return bar();
}
function bar () {
return 42;
}
foo();
console.log( 3 );

8
test/form/self-contained-bundle/_expected/cjs.js

@ -5,13 +5,13 @@
console.log( 1 );
console.log( 2 ); // comment alongside 2
function bar () {
return 42;
}
function foo () {
return bar();
}
function bar () {
return 42;
}
foo();
console.log( 3 );

8
test/form/self-contained-bundle/_expected/es6.js

@ -3,13 +3,13 @@
console.log( 1 );
console.log( 2 ); // comment alongside 2
function bar () {
return 42;
}
function foo () {
return bar();
}
function bar () {
return 42;
}
foo();
console.log( 3 );

8
test/form/self-contained-bundle/_expected/iife.js

@ -5,14 +5,14 @@
console.log( 1 );
console.log( 2 ); // comment alongside 2
function bar () {
return 42;
}
function foo () {
return bar();
}
function bar () {
return 42;
}
foo();
console.log( 3 );

8
test/form/self-contained-bundle/_expected/umd.js

@ -9,14 +9,14 @@
console.log( 1 );
console.log( 2 ); // comment alongside 2
function bar () {
return 42;
}
function foo () {
return bar();
}
function bar () {
return 42;
}
foo();
console.log( 3 );

8
test/function/retains-sort-order/_config.js

@ -0,0 +1,8 @@
var assert = require( 'assert' );
module.exports = {
description: 'sorts statements according to their original order within modules',
exports: function ( exports ) {
assert.equal( exports, 'GREAT SUCCESS' );
}
};

1
test/function/retains-sort-order/baz.js

@ -0,0 +1 @@
export default 'GREAT SUCCESS';

15
test/function/retains-sort-order/foobar.js

@ -0,0 +1,15 @@
import baz from './baz';
export function Foo () {}
Foo.prototype.test = function () {
return 'nope';
};
export function Bar () {}
Bar.prototype = Object.create( Foo.prototype );
Bar.prototype.test = function () {
return baz;
};

4
test/function/retains-sort-order/main.js

@ -0,0 +1,4 @@
import { Foo, Bar } from './foobar';
new Foo();
export default new Bar().test();
Loading…
Cancel
Save