Browse Source

Merge pull request #441 from rollup/external-import-alias-shadow

Add a failing test illustrating a renaming bug in ES6 output.
gh-438-b
Rich Harris 9 years ago
parent
commit
beec316553
  1. 7
      src/Bundle.js
  2. 8
      src/Declaration.js
  3. 6
      test/form/external-import-alias-shadow/_config.js
  4. 9
      test/form/external-import-alias-shadow/_expected/amd.js
  5. 9
      test/form/external-import-alias-shadow/_expected/cjs.js
  6. 7
      test/form/external-import-alias-shadow/_expected/es6.js
  7. 10
      test/form/external-import-alias-shadow/_expected/iife.js
  8. 13
      test/form/external-import-alias-shadow/_expected/umd.js
  9. 3
      test/form/external-import-alias-shadow/main.js
  10. 5
      test/form/external-import-alias-shadow/parse.js

7
src/Bundle.js

@ -127,6 +127,13 @@ export default class Bundle {
this.externalModules.forEach( module => {
module.name = getSafeName( module.name );
// ensure we don't shadow named external imports, if
// we're creating an ES6 bundle
keys( module.declarations ).forEach( name => {
const declaration = module.declarations[ name ];
declaration.setSafeName( getSafeName( name ) );
});
});
this.modules.forEach( module => {

8
src/Declaration.js

@ -221,6 +221,8 @@ export class ExternalDeclaration {
this.module = module;
this.name = name;
this.isExternal = true;
this.safeName = null;
}
addAlias () {
@ -246,13 +248,17 @@ export class ExternalDeclaration {
this.module.name;
}
return es6 ? this.name : `${this.module.name}.${this.name}`;
return es6 ? this.safeName : `${this.module.name}.${this.name}`;
}
run () {
return true;
}
setSafeName ( name ) {
this.safeName = name;
}
use () {
// noop?
}

6
test/form/external-import-alias-shadow/_config.js

@ -0,0 +1,6 @@
module.exports = {
description: 'handles external aliased named imports that shadow another name',
options: {
external: [ 'acorn' ]
}
};

9
test/form/external-import-alias-shadow/_expected/amd.js

@ -0,0 +1,9 @@
define(['acorn'], function (acorn) { 'use strict';
function parse$1(source) {
return acorn.parse(source, { ecmaVersion: 6 });
}
console.log(parse$1('foo'));
});

9
test/form/external-import-alias-shadow/_expected/cjs.js

@ -0,0 +1,9 @@
'use strict';
var acorn = require('acorn');
function parse$1(source) {
return acorn.parse(source, { ecmaVersion: 6 });
}
console.log(parse$1('foo'));

7
test/form/external-import-alias-shadow/_expected/es6.js

@ -0,0 +1,7 @@
import { parse } from 'acorn';
function parse$1(source) {
return parse(source, { ecmaVersion: 6 });
}
console.log(parse$1('foo'));

10
test/form/external-import-alias-shadow/_expected/iife.js

@ -0,0 +1,10 @@
(function (acorn) {
'use strict';
function parse$1(source) {
return acorn.parse(source, { ecmaVersion: 6 });
}
console.log(parse$1('foo'));
}(acorn));

13
test/form/external-import-alias-shadow/_expected/umd.js

@ -0,0 +1,13 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('acorn')) :
typeof define === 'function' && define.amd ? define(['acorn'], factory) :
(factory(global.acorn));
}(this, function (acorn) { 'use strict';
function parse$1(source) {
return acorn.parse(source, { ecmaVersion: 6 });
}
console.log(parse$1('foo'));
}));

3
test/form/external-import-alias-shadow/main.js

@ -0,0 +1,3 @@
import parse from './parse';
console.log(parse('foo'));

5
test/form/external-import-alias-shadow/parse.js

@ -0,0 +1,5 @@
import { parse as acornParse } from 'acorn';
export default function parse(source) {
return acornParse(source, { ecmaVersion: 6 });
}
Loading…
Cancel
Save