Browse Source

insert export default statement after previous, rather than before next

contingency-plan
Rich-Harris 10 years ago
parent
commit
0406e7f578
  1. 9
      src/Module.js
  2. 9
      test/function/default-export-is-not-bound-b/_config.js
  3. 10
      test/function/default-export-is-not-bound-b/foo.js
  4. 3
      test/function/default-export-is-not-bound-b/main.js

9
src/Module.js

@ -355,13 +355,12 @@ export default class Module {
// TODO could this be statements.pop()?
statements.splice( statements.indexOf( defaultExportStatement ), 1 );
const len = statements.length;
let i;
let i = statements.length;
let inserted = false;
for ( i = 0; i < len; i += 1 ) {
if ( statements[i].module === this && statements[i].index > defaultExportStatement.index ) {
statements.splice( i, 0, defaultExportStatement );
while ( i-- ) {
if ( statements[i].module === this && statements[i].index < defaultExportStatement.index ) {
statements.splice( i + 1, 0, defaultExportStatement );
inserted = true;
break;
}

9
test/function/default-export-is-not-bound-b/_config.js

@ -0,0 +1,9 @@
var assert = require( 'assert' );
module.exports = {
description: 'does not move default export statement above earlier statements',
exports: function ( exports ) {
assert.equal( exports.bar, 42 );
},
// solo: true
};

10
test/function/default-export-is-not-bound-b/foo.js

@ -0,0 +1,10 @@
var Foo = function () {
this.bar = bar();
}
export default Foo;
Foo = 'something else';
function bar() {
return 42;
}

3
test/function/default-export-is-not-bound-b/main.js

@ -0,0 +1,3 @@
import Foo from './Foo';
export default new Foo();
Loading…
Cancel
Save