Skip to content

Commit

Permalink
separate resolvedIds from resolvedExternalIds
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jul 13, 2017
1 parent 87c4733 commit e9ea331
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Bundle.js
Expand Up @@ -348,7 +348,7 @@ export default class Bundle {
}
});
module.exportAllSources.forEach( source => {
const id = module.resolvedIds[ source ];
const id = module.resolvedIds[ source ] || module.resolvedExternalIds[ source ];
const exportAllModule = this.moduleById.get( id );
if ( exportAllModule.isExternal ) return;

Expand Down Expand Up @@ -396,7 +396,7 @@ export default class Bundle {
}

if ( isExternal ) {
module.resolvedIds[ source ] = externalId;
module.resolvedExternalIds[ source ] = externalId;

if ( !this.moduleById.has( externalId ) ) {
const module = new ExternalModule( externalId, this.getPath( externalId ) );
Expand Down
16 changes: 10 additions & 6 deletions src/Module.js
Expand Up @@ -32,7 +32,7 @@ function tryParse ( module, acornOptions ) {
}

export default class Module {
constructor ({ id, code, originalCode, originalSourceMap, ast, sourceMapChain, resolvedIds, bundle }) {
constructor ({ id, code, originalCode, originalSourceMap, ast, sourceMapChain, resolvedIds, resolvedExternalIds, bundle }) {
this.code = code;
this.id = id;
this.bundle = bundle;
Expand Down Expand Up @@ -63,6 +63,7 @@ export default class Module {
this.sources = [];
this.dependencies = [];
this.resolvedIds = resolvedIds || blank();
this.resolvedExternalIds = resolvedExternalIds || blank();

// imports and exports, indexed by local name
this.imports = blank();
Expand Down Expand Up @@ -259,21 +260,23 @@ export default class Module {
keys( specifiers ).forEach( name => {
const specifier = specifiers[ name ];

const id = this.resolvedIds[ specifier.source ];
const id = this.resolvedIds[ specifier.source ] || this.resolvedExternalIds[ specifier.source ];
specifier.module = this.bundle.moduleById.get( id );
});
});

this.exportAllModules = this.exportAllSources.map( source => {
const id = this.resolvedIds[ source ];
const id = this.resolvedIds[ source ] || this.resolvedExternalIds[ source ];
return this.bundle.moduleById.get( id );
});

this.sources.forEach( source => {
const id = this.resolvedIds[ source ];
const module = this.bundle.moduleById.get( id );

if ( !module.isExternal ) this.dependencies.push( module );
if ( id ) {
const module = this.bundle.moduleById.get( id );
this.dependencies.push( module );
}
});
}

Expand Down Expand Up @@ -376,7 +379,8 @@ export default class Module {
originalSourceMap: this.originalSourceMap,
ast: this.astClone,
sourceMapChain: this.sourceMapChain,
resolvedIds: this.resolvedIds
resolvedIds: this.resolvedIds,
resolvedExternalIds: this.resolvedExternalIds
};
}

Expand Down
1 change: 1 addition & 0 deletions test/mocha.opts
@@ -1,2 +1,3 @@
--bail
--compilers js:buble/register
test/test.js
26 changes: 26 additions & 0 deletions test/test.js
Expand Up @@ -808,6 +808,32 @@ describe( 'rollup', function () {
});
});
});

it( 'separates resolvedIds from resolvedExternalIds', () => {
modules = {
entry: `import foo from 'foo'; import external from 'external'; console.log(foo(external));`,
foo: `export default 42`
};

return rollup.rollup({
entry: 'entry',
external: ['external'],
plugins: [ plugin ]
}).then( bundle => {
assert.deepEqual(bundle.imports, ['external']);

assert.equal(bundle.modules[0].id, 'foo');
assert.equal(bundle.modules[1].id, 'entry');

assert.deepEqual(bundle.modules[1].resolvedIds, {
foo: 'foo'
});

assert.deepEqual(bundle.modules[1].resolvedExternalIds, {
external: 'external'
});
});
});
});

describe( 'hooks', () => {
Expand Down

0 comments on commit e9ea331

Please sign in to comment.