Browse Source

deconflict external imports

contingency-plan
Rich-Harris 10 years ago
parent
commit
f35d453c72
  1. 8
      src/Bundle.js
  2. 13
      test/function/deconflicts-external-imports/_config.js
  3. 5
      test/function/deconflicts-external-imports/a.js
  4. 5
      test/function/deconflicts-external-imports/b.js
  5. 5
      test/function/deconflicts-external-imports/main.js

8
src/Bundle.js

@ -91,16 +91,14 @@ export default class Bundle {
// Assign names to external modules
this.externalModules.forEach( module => {
// TODO is this right?
let name = makeLegalIdentifier( module.suggestedNames['*'] || module.suggestedNames.default || module.id );
if ( definers[ name ] ) {
while ( definers[ name ] ) {
conflicts[ name ] = true;
} else {
definers[ name ] = [];
name = `_${name}`;
}
definers[ name ].push( module );
definers[ name ] = [ module ];
module.name = name;
this.assumedGlobals[ name ] = true;
});

13
test/function/deconflicts-external-imports/_config.js

@ -0,0 +1,13 @@
module.exports = {
description: 'deconflicts external imports',
context: {
require: function ( id ) {
return function () {
return id;
};
}
},
options: {
external: [ 'foo', 'bar' ]
}
};

5
test/function/deconflicts-external-imports/a.js

@ -0,0 +1,5 @@
import foo from 'foo';
export default function () {
assert.equal( foo(), 'foo' );
}

5
test/function/deconflicts-external-imports/b.js

@ -0,0 +1,5 @@
import foo from 'bar';
export default function () {
assert.equal( foo(), 'bar' );
}

5
test/function/deconflicts-external-imports/main.js

@ -0,0 +1,5 @@
import a from './a';
import b from './b';
a();
b();
Loading…
Cancel
Save