Skip to content

Commit

Permalink
handle system reserved identifier dedupes (#3614)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Jun 4, 2020
1 parent a1c075e commit 22e372b
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 14 deletions.
21 changes: 11 additions & 10 deletions src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1088,16 +1088,17 @@ export default class Chunk {
if (this.needsExportsShim) {
usedNames.add(MISSING_EXPORT_SHIM_VARIABLE);
}
if (options.format !== 'es') {
usedNames.add('exports');
if (options.format === 'cjs') {
usedNames
.add(INTEROP_DEFAULT_VARIABLE)
.add('require')
.add('module')
.add('__filename')
.add('__dirname');
}
switch (options.format) {
case 'es':
break;
case 'cjs':
usedNames.add(INTEROP_DEFAULT_VARIABLE).add('require').add('__filename').add('__dirname');
// fallthrough
case 'system':
usedNames.add('module');
// fallthrough
default:
usedNames.add('exports');
}

deconflictChunk(
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/protect-cjs-globals/_expected/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ System.register('bundle', [], function (exports) {

const exports$1 = exports('exports', 1);
const require = exports('require', 2);
const module = exports('module', 3);
const module$1 = exports('module', 3);
const __filename = exports('__filename', 4);
const __dirname = exports('__dirname', 5);

Expand Down
6 changes: 3 additions & 3 deletions test/form/samples/sequence-expression/_expected/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ System.register([], function () {
var g = ((() => {console.log(foo$1());})(), 1);

// should maintain this context
var module = {};
module.bar = function () { console.log( 'bar' );};
var h = (0, module.bar)();
var module$1 = {};
module$1.bar = function () { console.log( 'bar' );};
var h = (0, module$1.bar)();

}
};
Expand Down
10 changes: 10 additions & 0 deletions test/form/samples/system-module-reserved/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
description: 'does not output reserved system format identifiers',
options: {
external: ['test'],
output: {
name: 'systemReserved',
globals: { test: 'test' }
}
}
};
5 changes: 5 additions & 0 deletions test/form/samples/system-module-reserved/_expected/amd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define(['test'], function (test) { 'use strict';

console.log(test.module, test.other);

});
5 changes: 5 additions & 0 deletions test/form/samples/system-module-reserved/_expected/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

var test = require('test');

console.log(test.module, test.other);
3 changes: 3 additions & 0 deletions test/form/samples/system-module-reserved/_expected/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { module, other } from 'test';

console.log(module, other);
6 changes: 6 additions & 0 deletions test/form/samples/system-module-reserved/_expected/iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(function (test) {
'use strict';

console.log(test.module, test.other);

}(test));
15 changes: 15 additions & 0 deletions test/form/samples/system-module-reserved/_expected/system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
System.register('systemReserved', ['test'], function () {
'use strict';
var module$1, other;
return {
setters: [function (module) {
module$1 = module.module;
other = module.other;
}],
execute: function () {

console.log(module$1, other);

}
};
});
9 changes: 9 additions & 0 deletions test/form/samples/system-module-reserved/_expected/umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('test')) :
typeof define === 'function' && define.amd ? define(['test'], factory) :
(global = global || self, factory(global.test));
}(this, (function (test) { 'use strict';

console.log(test.module, test.other);

})));
3 changes: 3 additions & 0 deletions test/form/samples/system-module-reserved/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { module, other } from 'test';

console.log(module, other);

0 comments on commit 22e372b

Please sign in to comment.