Browse Source

fix tricky edge case with deconflicted default imports

contingency-plan
Rich Harris 10 years ago
parent
commit
6b83a24176
  1. 10
      src/Module.js
  2. 4
      src/utils/object.js

10
src/Module.js

@ -4,7 +4,7 @@ import { parse } from 'acorn';
import MagicString from 'magic-string'; import MagicString from 'magic-string';
import Statement from './Statement'; import Statement from './Statement';
import analyse from './ast/analyse'; import analyse from './ast/analyse';
import { has, keys } from './utils/object'; import { blank, has, keys } from './utils/object';
import { sequence } from './utils/promise'; import { sequence } from './utils/promise';
import { isImportDeclaration, isExportDeclaration } from './utils/map-helpers'; import { isImportDeclaration, isExportDeclaration } from './utils/map-helpers';
import getLocation from './utils/getLocation'; import getLocation from './utils/getLocation';
@ -229,7 +229,13 @@ export default class Module {
if ( importDeclaration.name === 'default' ) { if ( importDeclaration.name === 'default' ) {
// TODO this seems ropey // TODO this seems ropey
const localName = importDeclaration.localName; const localName = importDeclaration.localName;
const suggestion = has( this.suggestedNames, localName ) ? this.suggestedNames[ localName ] : localName; let suggestion = has( this.suggestedNames, localName ) ? this.suggestedNames[ localName ] : localName;
// special case - the module has its own import by this name
while ( !module.isExternal && has( module.imports, suggestion ) ) {
suggestion = `_${suggestion}`;
}
module.suggestName( 'default', suggestion ); module.suggestName( 'default', suggestion );
} else if ( importDeclaration.name === '*' ) { } else if ( importDeclaration.name === '*' ) {
const localName = importDeclaration.localName; const localName = importDeclaration.localName;

4
src/utils/object.js

@ -5,3 +5,7 @@ export const hasOwnProp = Object.prototype.hasOwnProperty;
export function has ( obj, prop ) { export function has ( obj, prop ) {
return hasOwnProp.call( obj, prop ); return hasOwnProp.call( obj, prop );
} }
export function blank () {
return Object.create( null );
}

Loading…
Cancel
Save