Browse Source

merge master -> gh-30

contingency-plan
Rich-Harris 10 years ago
parent
commit
0b92d5296d
  1. 9
      CHANGELOG.md
  2. 4
      bin/runRollup.js
  3. 2
      package.json
  4. 22
      src/Module.js
  5. 13
      src/Statement.js
  6. 4
      test/cli/module-name/_config.js
  7. 11
      test/cli/module-name/_expected.js
  8. 1
      test/cli/module-name/main.js
  9. 9
      test/function/rename-default-export/_config.js
  10. 3
      test/function/rename-default-export/bar.js
  11. 5
      test/function/rename-default-export/baz.js
  12. 3
      test/function/rename-default-export/foo.js
  13. 7
      test/function/rename-default-export/main.js
  14. 10
      test/function/renamed-arguments/_config.js
  15. 5
      test/function/renamed-arguments/bar.js
  16. 5
      test/function/renamed-arguments/foo.js
  17. 7
      test/function/renamed-arguments/main.js
  18. 14
      test/test.js

9
CHANGELOG.md

@ -1,5 +1,14 @@
# rollup changelog # rollup changelog
## 0.8.3
* Correctly rename functions that have arguments with the same name ([#32](https://github.com/rollup/rollup/issues/32))
* Ensure unused default exports are given a legal name ([#33](https://github.com/rollup/rollup/issues/33))
## 0.8.2
* Support `moduleId` and `moduleName` via CLI ([#24](https://github.com/rollup/rollup/issues/24))
## 0.8.1 ## 0.8.1
* Anonymous functions that are exported as default are converted to named function declarations for correct hoisting, rather than being bound to functions ([#29](https://github.com/rollup/rollup/issues/29)) * Anonymous functions that are exported as default are converted to named function declarations for correct hoisting, rather than being bound to functions ([#29](https://github.com/rollup/rollup/issues/29))

4
bin/runRollup.js

@ -39,7 +39,9 @@ function bundle ( options, method ) {
}).then( function ( bundle ) { }).then( function ( bundle ) {
var generateOptions = { var generateOptions = {
dest: options.output, dest: options.output,
format: options.format format: options.format,
moduleId: options.id,
moduleName: options.name
}; };
if ( options.output ) { if ( options.output ) {

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "rollup", "name": "rollup",
"version": "0.8.1", "version": "0.8.3",
"description": "Next-generation ES6 module bundler", "description": "Next-generation ES6 module bundler",
"main": "dist/rollup.js", "main": "dist/rollup.js",
"jsnext:main": "src/rollup.js", "jsnext:main": "src/rollup.js",

22
src/Module.js

@ -13,6 +13,14 @@ import makeLegalIdentifier from './utils/makeLegalIdentifier';
const emptyArrayPromise = Promise.resolve([]); const emptyArrayPromise = Promise.resolve([]);
function deconflict ( name, names ) {
while ( name in names ) {
name = `_${name}`;
}
return name;
}
export default class Module { export default class Module {
constructor ({ path, source, bundle }) { constructor ({ path, source, bundle }) {
this.source = source; this.source = source;
@ -251,13 +259,9 @@ export default class Module {
getCanonicalName ( localName ) { getCanonicalName ( localName ) {
// Special case // Special case
if ( localName === 'default' && this.exports.default && this.exports.default.isModified ) { if ( localName === 'default' && ( this.exports.default.isModified || !this.suggestedNames.default ) ) {
let canonicalName = makeLegalIdentifier( this.path.replace( dirname( this.bundle.entryModule.path ) + '/', '' ).replace( /\.js$/, '' ) ); let canonicalName = makeLegalIdentifier( this.path.replace( dirname( this.bundle.entryModule.path ) + '/', '' ).replace( /\.js$/, '' ) );
while ( this.definitions[ canonicalName ] ) { return deconflict( canonicalName, this.definitions );
canonicalName = `_${canonicalName}`;
}
return canonicalName;
} }
if ( this.suggestedNames[ localName ] ) { if ( this.suggestedNames[ localName ] ) {
@ -472,11 +476,7 @@ export default class Module {
// deconflict anonymous default exports with this module's definitions // deconflict anonymous default exports with this module's definitions
const shouldDeconflict = this.exports.default && this.exports.default.isAnonymous; const shouldDeconflict = this.exports.default && this.exports.default.isAnonymous;
if ( shouldDeconflict ) { if ( shouldDeconflict ) suggestion = deconflict( suggestion, this.definitions );
while ( suggestion in this.definitions ) {
suggestion = `_${suggestion}`;
}
}
if ( !this.suggestedNames[ defaultOrBatch ] ) { if ( !this.suggestedNames[ defaultOrBatch ] ) {
this.suggestedNames[ defaultOrBatch ] = makeLegalIdentifier( suggestion ); this.suggestedNames[ defaultOrBatch ] = makeLegalIdentifier( suggestion );

13
src/Statement.js

@ -315,15 +315,20 @@ export default class Statement {
let newNames = blank(); let newNames = blank();
let hasReplacements; let hasReplacements;
keys( names ).forEach( key => { // special case = function foo ( foo ) {...}
if ( !scope.declarations[ key ] ) { if ( node.id && names[ node.id.name ] && scope.declarations[ node.id.name ] ) {
newNames[ key ] = names[ key ]; magicString.overwrite( node.id.start, node.id.end, names[ node.id.name ] );
}
keys( names ).forEach( name => {
if ( !scope.declarations[ name ] ) {
newNames[ name ] = names[ name ];
hasReplacements = true; hasReplacements = true;
} }
}); });
deshadowList.forEach( name => { deshadowList.forEach( name => {
if ( ~scope.declarations[ name ] ) { if ( ~scope.declarations[ name ] ) { // TODO is this right? no indexOf?
newNames[ name ] = name + '$$'; // TODO better mechanism newNames[ name ] = name + '$$'; // TODO better mechanism
hasReplacements = true; hasReplacements = true;
} }

4
test/cli/module-name/_config.js

@ -0,0 +1,4 @@
module.exports = {
description: 'generates UMD export with correct moduleName',
command: 'rollup main.js --format umd --name myBundle'
}

11
test/cli/module-name/_expected.js

@ -0,0 +1,11 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
global.myBundle = factory();
}(this, function () { 'use strict';
var main = 42;
return main;
}));

1
test/cli/module-name/main.js

@ -0,0 +1 @@
export default 42;

9
test/function/rename-default-export/_config.js

@ -0,0 +1,9 @@
var assert = require( 'assert' );
module.exports = {
description: 'avoids SyntaxError with default token (#33)',
exports: function ( exports ) {
assert.equal( exports.foo, 42 );
assert.equal( exports.bar, 42 );
}
};

3
test/function/rename-default-export/bar.js

@ -0,0 +1,3 @@
import { baz } from './baz';
export default baz;

5
test/function/rename-default-export/baz.js

@ -0,0 +1,5 @@
function Baz () {}
export var baz = 42;
export default Baz( baz );

3
test/function/rename-default-export/foo.js

@ -0,0 +1,3 @@
import { baz } from './baz';
export default baz;

7
test/function/rename-default-export/main.js

@ -0,0 +1,7 @@
import foo from './foo';
import bar from './bar';
export {
foo,
bar
};

10
test/function/renamed-arguments/_config.js

@ -0,0 +1,10 @@
var assert = require( 'assert' );
module.exports = {
description: 'function arguments are renamed as appropriate (#32)',
exports: function ( exports ) {
var obj = {};
assert.strictEqual( exports.foo(), 42 );
assert.strictEqual( exports.bar( obj ), obj );
}
};

5
test/function/renamed-arguments/bar.js

@ -0,0 +1,5 @@
function thing ( thing ) {
return thing;
}
export default thing;

5
test/function/renamed-arguments/foo.js

@ -0,0 +1,5 @@
function thing () {
return 42;
}
export default thing;

7
test/function/renamed-arguments/main.js

@ -0,0 +1,7 @@
import foo from './foo';
import bar from './bar';
export {
foo,
bar
};

14
test/test.js

@ -295,6 +295,20 @@ describe( 'rollup', function () {
unintendedError ? done( unintendedError ) : done(); unintendedError ? done( unintendedError ) : done();
} }
else if ( config.result ) {
try {
config.result( code );
} catch ( err ) {
done( err );
}
}
else {
var expected = sander.readFileSync( '_expected.js' ).toString();
assert.equal( code.trim(), expected.trim() );
done();
}
}); });
}); });
}); });

Loading…
Cancel
Save