Browse Source

more deconflicting

contingency-plan
Rich Harris 10 years ago
parent
commit
aaa2234741
  1. 21
      src/Bundle.js
  2. 3
      test/function/imports-are-deconflicted-redux/_config.js
  3. 5
      test/function/imports-are-deconflicted-redux/bar.js
  4. 2
      test/function/imports-are-deconflicted-redux/foo.js
  5. 5
      test/function/imports-are-deconflicted-redux/main.js
  6. 3
      test/function/imports-are-deconflicted/_config.js
  7. 5
      test/function/imports-are-deconflicted/bar.js
  8. 1
      test/function/imports-are-deconflicted/foo.js
  9. 5
      test/function/imports-are-deconflicted/main.js

21
src/Bundle.js

@ -94,7 +94,24 @@ export default class Bundle {
// Discover conflicts (i.e. two statements in separate modules both define `foo`) // Discover conflicts (i.e. two statements in separate modules both define `foo`)
this.statements.forEach( statement => { this.statements.forEach( statement => {
keys( statement.defines ).forEach( name => { const module = statement.module;
const names = keys( statement.defines );
// with default exports that are expressions (`export default 42`),
// we need to ensure that the name chosen for the expression does
// not conflict
if ( statement.node.type === 'ExportDefaultDeclaration' ) {
const name = module.getCanonicalName( 'default' );
const isProxy = statement.node.declaration && statement.node.declaration.type === 'Identifier';
const shouldDeconflict = !isProxy || ( module.getCanonicalName( statement.node.declaration.name ) !== name );
if ( shouldDeconflict && !~names.indexOf( name ) ) {
names.push( name );
}
}
names.forEach( name => {
if ( has( definers, name ) ) { if ( has( definers, name ) ) {
conflicts[ name ] = true; conflicts[ name ] = true;
} else { } else {
@ -103,7 +120,7 @@ export default class Bundle {
// TODO in good js, there shouldn't be duplicate definitions // TODO in good js, there shouldn't be duplicate definitions
// per module... but some people write bad js // per module... but some people write bad js
definers[ name ].push( statement.module ); definers[ name ].push( module );
}); });
}); });

3
test/function/imports-are-deconflicted-redux/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'deconflicts imports (redux)'
};

5
test/function/imports-are-deconflicted-redux/bar.js

@ -0,0 +1,5 @@
import foo from 'path';
export default function () {
return foo.relative( 'foo/bar/baz', 'foo/baz/bar' );
};

2
test/function/imports-are-deconflicted-redux/foo.js

@ -0,0 +1,2 @@
var z = 'foo';
export default z;

5
test/function/imports-are-deconflicted-redux/main.js

@ -0,0 +1,5 @@
import foo from './foo';
import bar from './bar';
assert.equal( foo, 'foo' );
assert.equal( bar(), '../../baz/bar' );

3
test/function/imports-are-deconflicted/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'deconflicts imports'
};

5
test/function/imports-are-deconflicted/bar.js

@ -0,0 +1,5 @@
import foo from 'path';
export default function () {
return foo.relative( 'foo/bar/baz', 'foo/baz/bar' );
};

1
test/function/imports-are-deconflicted/foo.js

@ -0,0 +1 @@
export default 'foo';

5
test/function/imports-are-deconflicted/main.js

@ -0,0 +1,5 @@
import foo from './foo';
import bar from './bar';
assert.equal( foo, 'foo' );
assert.equal( bar(), '../../baz/bar' );
Loading…
Cancel
Save