Skip to content

Commit

Permalink
external deshadowing fix for #1930
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored and lukastaegert committed Feb 9, 2018
1 parent fd6c187 commit 0e84d4b
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -14,7 +14,7 @@
"test": "npm run test:only && npm run test:typescript",
"test:only": "mocha",
"test:leak": "node --expose-gc test/leak/index.js",
"test:quick": "rollup -c && mocha -b",
"test:quick": "mocha -b",
"pretest:typescript": "rm -rf test/typescript/dist && rm -rf test/typescript/typings && cp -r dist test/typescript/ && cp -r typings test/typescript/",
"test:typescript": "tsc -p test/typescript",
"pretest-coverage": "npm run build",
Expand Down Expand Up @@ -111,4 +111,4 @@
"url": "https://opencollective.com/rollup",
"logo": "https://opencollective.com/rollup/logo.txt"
}
}
}
11 changes: 6 additions & 5 deletions src/Chunk.ts
Expand Up @@ -468,13 +468,13 @@ export default class Chunk {

const toDeshadow: Set<string> = new Set();

this.externalModules.forEach(module => {
if (!es || module.exportsNamespace) {
if (!es) {
this.externalModules.forEach(module => {
const safeName = getSafeName(module.name);
toDeshadow.add(safeName);
module.name = safeName;
}
});
});
}

this.imports.forEach(impt => {
impt.variables.forEach(({ name, module, variable }) => {
Expand All @@ -489,9 +489,10 @@ export default class Chunk {
safeName = module.name;
}
} else {
safeName = (es || system) ? getSafeName(variable.name) : `${module.name}.${name}`;
safeName = (es || system) ? variable.name : `${module.name}.${name}`;
}
if (es || system) {
safeName = getSafeName(safeName);
toDeshadow.add(safeName);
}
} else if (es || system) {
Expand Down
6 changes: 6 additions & 0 deletions test/form/samples/external-deshadowing/_config.js
@@ -0,0 +1,6 @@
module.exports = {
description: 'Externals aliases with deshadowing',
options: {
name: 'myBundle'
}
};
18 changes: 18 additions & 0 deletions test/form/samples/external-deshadowing/_expected/amd.js
@@ -0,0 +1,18 @@
define(['exports', 'a', 'b'], function (exports, a, Test) { 'use strict';

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

const Test$1 = () => {
console.log(a.Test);
};

const Test1 = () => {
console.log(Test);
};

exports.Test = Test$1;
exports.Test1 = Test1;

Object.defineProperty(exports, '__esModule', { value: true });

});
19 changes: 19 additions & 0 deletions test/form/samples/external-deshadowing/_expected/cjs.js
@@ -0,0 +1,19 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var a = require('a');
var Test = _interopDefault(require('b'));

const Test$1 = () => {
console.log(a.Test);
};

const Test1 = () => {
console.log(Test);
};

exports.Test = Test$1;
exports.Test1 = Test1;
12 changes: 12 additions & 0 deletions test/form/samples/external-deshadowing/_expected/es.js
@@ -0,0 +1,12 @@
import { Test } from 'a';
import Test$1 from 'b';

const Test$2 = () => {
console.log(Test);
};

const Test1 = () => {
console.log(Test$1);
};

export { Test$2 as Test, Test1 };
19 changes: 19 additions & 0 deletions test/form/samples/external-deshadowing/_expected/iife.js
@@ -0,0 +1,19 @@
var myBundle = (function (exports,a,Test) {
'use strict';

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

const Test$1 = () => {
console.log(a.Test);
};

const Test1 = () => {
console.log(Test);
};

exports.Test = Test$1;
exports.Test1 = Test1;

return exports;

}({},a,Test));
22 changes: 22 additions & 0 deletions test/form/samples/external-deshadowing/_expected/umd.js
@@ -0,0 +1,22 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('a'), require('b')) :
typeof define === 'function' && define.amd ? define(['exports', 'a', 'b'], factory) :
(factory((global.myBundle = {}),global.a,global.Test));
}(this, (function (exports,a,Test) { 'use strict';

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

const Test$1 = () => {
console.log(a.Test);
};

const Test1 = () => {
console.log(Test);
};

exports.Test = Test$1;
exports.Test1 = Test1;

Object.defineProperty(exports, '__esModule', { value: true });

})));
5 changes: 5 additions & 0 deletions test/form/samples/external-deshadowing/component-one.js
@@ -0,0 +1,5 @@
import { Test as Test1 } from 'a';

export const Test = () => {
console.log(Test1);
};
5 changes: 5 additions & 0 deletions test/form/samples/external-deshadowing/component-two.js
@@ -0,0 +1,5 @@
import Test from 'b';

export const Test1 = () => {
console.log(Test);
};
2 changes: 2 additions & 0 deletions test/form/samples/external-deshadowing/main.js
@@ -0,0 +1,2 @@
export { Test } from './component-one.js';
export { Test1 } from './component-two.js';

0 comments on commit 0e84d4b

Please sign in to comment.