Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rollup/rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jul 13, 2017
2 parents 3b2363f + e1e0f5a commit 66a6e88
Show file tree
Hide file tree
Showing 27 changed files with 65 additions and 30 deletions.
4 changes: 4 additions & 0 deletions bin/src/runRollup.js
Expand Up @@ -161,6 +161,10 @@ function execute ( options, command ) {
external = ( optionsExternal || [] ).concat( commandExternal );
}

if (typeof command.extend !== 'undefined') {
options.extend = command.extend;
}

if ( command.silent ) {
options.onwarn = () => {};
}
Expand Down
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
2 changes: 1 addition & 1 deletion src/finalisers/shared/getInteropBlock.js
Expand Up @@ -11,7 +11,7 @@ export default function getInteropBlock ( bundle, options ) {
return `${bundle.varOrConst} ${module.name}__default = 'default' in ${module.name} ? ${module.name}['default'] : ${module.name};`;
}

return `${module.name} = ${module.name} && 'default' in ${module.name} ? ${module.name}['default'] : ${module.name};`;
return `${module.name} = ${module.name} && ${module.name}.hasOwnProperty('default') ? ${module.name}['default'] : ${module.name};`;
})
.filter( Boolean )
.join( '\n' );
Expand Down
2 changes: 1 addition & 1 deletion test/form/export-default-import/_expected/amd.js
@@ -1,6 +1,6 @@
define(['exports', 'x'], function (exports, x) { 'use strict';

x = x && 'default' in x ? x['default'] : x;
x = x && x.hasOwnProperty('default') ? x['default'] : x;



Expand Down
2 changes: 1 addition & 1 deletion test/form/export-default-import/_expected/iife.js
@@ -1,7 +1,7 @@
var myBundle = (function (exports,x) {
'use strict';

x = x && 'default' in x ? x['default'] : x;
x = x && x.hasOwnProperty('default') ? x['default'] : x;



Expand Down
2 changes: 1 addition & 1 deletion test/form/export-default-import/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(factory((global.myBundle = {}),global.x));
}(this, (function (exports,x) { 'use strict';

x = x && 'default' in x ? x['default'] : x;
x = x && x.hasOwnProperty('default') ? x['default'] : x;



Expand Down
2 changes: 1 addition & 1 deletion test/form/external-imports-custom-names/_expected/amd.js
@@ -1,6 +1,6 @@
define(['jquery'], function ($) { 'use strict';

$ = $ && 'default' in $ ? $['default'] : $;
$ = $ && $.hasOwnProperty('default') ? $['default'] : $;

$( function () {
$( 'body' ).html( '<h1>hello world!</h1>' );
Expand Down
2 changes: 1 addition & 1 deletion test/form/external-imports-custom-names/_expected/iife.js
@@ -1,7 +1,7 @@
(function ($) {
'use strict';

$ = $ && 'default' in $ ? $['default'] : $;
$ = $ && $.hasOwnProperty('default') ? $['default'] : $;

$( function () {
$( 'body' ).html( '<h1>hello world!</h1>' );
Expand Down
2 changes: 1 addition & 1 deletion test/form/external-imports-custom-names/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(factory(global.jQuery));
}(this, (function ($) { 'use strict';

$ = $ && 'default' in $ ? $['default'] : $;
$ = $ && $.hasOwnProperty('default') ? $['default'] : $;

$( function () {
$( 'body' ).html( '<h1>hello world!</h1>' );
Expand Down
2 changes: 1 addition & 1 deletion test/form/external-imports/_expected/amd.js
@@ -1,6 +1,6 @@
define(['factory', 'baz', 'shipping-port', 'alphabet'], function (factory, baz, containers, alphabet) { 'use strict';

factory = factory && 'default' in factory ? factory['default'] : factory;
factory = factory && factory.hasOwnProperty('default') ? factory['default'] : factory;
var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet;

factory( null );
Expand Down
2 changes: 1 addition & 1 deletion test/form/external-imports/_expected/iife.js
@@ -1,7 +1,7 @@
(function (factory,baz,containers,alphabet) {
'use strict';

factory = factory && 'default' in factory ? factory['default'] : factory;
factory = factory && factory.hasOwnProperty('default') ? factory['default'] : factory;
var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet;

factory( null );
Expand Down
2 changes: 1 addition & 1 deletion test/form/external-imports/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(factory(global.factory,global.baz,global.containers,global.alphabet));
}(this, (function (factory,baz,containers,alphabet) { 'use strict';

factory = factory && 'default' in factory ? factory['default'] : factory;
factory = factory && factory.hasOwnProperty('default') ? factory['default'] : factory;
var alphabet__default = 'default' in alphabet ? alphabet['default'] : alphabet;

factory( null );
Expand Down
2 changes: 1 addition & 1 deletion test/form/paths-function/_expected/amd.js
@@ -1,6 +1,6 @@
define(['https://unpkg.com/foo'], function (foo) { 'use strict';

foo = foo && 'default' in foo ? foo['default'] : foo;
foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/paths-function/_expected/iife.js
@@ -1,7 +1,7 @@
(function (foo) {
'use strict';

foo = foo && 'default' in foo ? foo['default'] : foo;
foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/paths-function/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(factory(global.foo));
}(this, (function (foo) { 'use strict';

foo = foo && 'default' in foo ? foo['default'] : foo;
foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/paths-relative/_expected/amd.js
@@ -1,6 +1,6 @@
define(['../foo'], function (foo) { 'use strict';

foo = foo && 'default' in foo ? foo['default'] : foo;
foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/paths-relative/_expected/iife.js
@@ -1,7 +1,7 @@
(function (foo) {
'use strict';

foo = foo && 'default' in foo ? foo['default'] : foo;
foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/paths-relative/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(factory(global.foo));
}(this, (function (foo) { 'use strict';

foo = foo && 'default' in foo ? foo['default'] : foo;
foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/paths/_expected/amd.js
@@ -1,6 +1,6 @@
define(['https://unpkg.com/foo'], function (foo) { 'use strict';

foo = foo && 'default' in foo ? foo['default'] : foo;
foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/paths/_expected/iife.js
@@ -1,7 +1,7 @@
(function (foo) {
'use strict';

foo = foo && 'default' in foo ? foo['default'] : foo;
foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/paths/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(factory(global.foo));
}(this, (function (foo) { 'use strict';

foo = foo && 'default' in foo ? foo['default'] : foo;
foo = foo && foo.hasOwnProperty('default') ? foo['default'] : foo;

assert.equal( foo, 42 );

Expand Down
2 changes: 1 addition & 1 deletion test/form/relative-external-with-global/_expected/amd.js
@@ -1,6 +1,6 @@
define(['./lib/throttle.js'], function (throttle) { 'use strict';

throttle = throttle && 'default' in throttle ? throttle['default'] : throttle;
throttle = throttle && throttle.hasOwnProperty('default') ? throttle['default'] : throttle;

const fn = throttle( () => {
console.log( '.' );
Expand Down
2 changes: 1 addition & 1 deletion test/form/relative-external-with-global/_expected/iife.js
@@ -1,7 +1,7 @@
(function (throttle) {
'use strict';

throttle = throttle && 'default' in throttle ? throttle['default'] : throttle;
throttle = throttle && throttle.hasOwnProperty('default') ? throttle['default'] : throttle;

const fn = throttle( () => {
console.log( '.' );
Expand Down
2 changes: 1 addition & 1 deletion test/form/relative-external-with-global/_expected/umd.js
Expand Up @@ -4,7 +4,7 @@
(factory(global.Lib.throttle));
}(this, (function (throttle) { 'use strict';

throttle = throttle && 'default' in throttle ? throttle['default'] : throttle;
throttle = throttle && throttle.hasOwnProperty('default') ? throttle['default'] : throttle;

const fn = throttle( () => {
console.log( '.' );
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 66a6e88

Please sign in to comment.