Skip to content

Commit

Permalink
Handles default exporting global variables (#3526)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Apr 30, 2020
1 parent a2b4883 commit 1b588b6
Show file tree
Hide file tree
Showing 13 changed files with 348 additions and 454 deletions.
738 changes: 297 additions & 441 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-replace": "^2.3.2",
"@types/micromatch": "^4.0.1",
"@types/node": "^13.13.2",
"@types/node": "^13.13.4",
"@types/require-relative": "^0.8.0",
"@types/signal-exit": "^3.0.0",
"@types/yargs-parser": "^15.0.0",
Expand All @@ -83,7 +83,7 @@
"acorn-static-class-features": "^0.2.1",
"acorn-walk": "^7.1.1",
"buble": "^0.20.0",
"chokidar": "^3.3.1",
"chokidar": "^3.4.0",
"codecov": "^3.6.5",
"colorette": "^1.1.0",
"core-js": "^3.6.5",
Expand All @@ -98,20 +98,20 @@
"hash.js": "^1.1.7",
"husky": "^4.2.5",
"is-reference": "^1.1.4",
"lint-staged": "^10.1.7",
"lint-staged": "^10.2.1",
"locate-character": "^2.0.5",
"magic-string": "^0.25.7",
"markdownlint-cli": "^0.22.0",
"micromatch": "^4.0.2",
"mocha": "^7.1.1",
"mocha": "^7.1.2",
"node-fetch": "^2.6.0",
"nyc": "^15.0.1",
"prettier": "^2.0.5",
"pretty-bytes": "^5.3.0",
"pretty-ms": "^6.0.1",
"pretty-ms": "^7.0.0",
"require-relative": "^0.8.7",
"requirejs": "^2.3.6",
"rollup": "^2.7.1",
"rollup": "^2.7.5",
"rollup-plugin-license": "^2.0.0",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-terser": "^5.3.0",
Expand All @@ -122,12 +122,12 @@
"shx": "^0.3.2",
"signal-exit": "^3.0.3",
"source-map": "^0.7.3",
"source-map-support": "^0.5.18",
"source-map-support": "^0.5.19",
"sourcemap-codec": "^1.4.8",
"systemjs": "^6.3.1",
"terser": "^4.6.11",
"terser": "^4.6.13",
"tslib": "^1.11.1",
"tslint": "^6.1.1",
"tslint": "^6.1.2",
"typescript": "^3.8.3",
"url-parse": "^1.4.7",
"yargs-parser": "^18.1.3"
Expand Down
3 changes: 2 additions & 1 deletion scripts/test-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const pkg = require('../package.json');

function checkChokidar() {
const chokidarPkg = require('../node_modules/chokidar/package.json');
const chokidarFsevents = chokidarPkg.dependencies.fsevents;
const chokidarFsevents =
chokidarPkg.dependencies.fsevents || chokidarPkg.optionalDependencies.fsevents;
if (!chokidarFsevents) return;
const pkgFsevents = pkg.optionalDependencies.fsevents;
if (chokidarFsevents !== pkgFsevents) {
Expand Down
2 changes: 1 addition & 1 deletion src/Chunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ export default class Chunk {
} else if (variable instanceof ExportDefaultVariable) {
variable = variable.getOriginalVariable();
}
if ((variable.module as Module).chunk !== this) {
if (variable.module && (variable.module as Module).chunk !== this) {
this.imports.add(variable);
if (
!(variable instanceof NamespaceVariable && this.graph.preserveModules) &&
Expand Down
8 changes: 6 additions & 2 deletions src/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ export default class Module {
} else if (variable instanceof ExportDefaultVariable) {
variable = variable.getOriginalVariable();
}
relevantDependencies.add(variable.module!);
if (variable.module) {
relevantDependencies.add(variable.module);
}
}
if (this.isEntryPoint || this.dynamicallyImportedBy.length > 0 || this.graph.preserveModules) {
for (const exportName of [...this.getReexports(), ...this.getExports()]) {
Expand All @@ -355,7 +357,9 @@ export default class Module {
} else if (variable instanceof ExportDefaultVariable) {
variable = variable.getOriginalVariable();
}
relevantDependencies.add(variable.module!);
if (variable.module) {
relevantDependencies.add(variable.module);
}
}
}
if (this.graph.treeshakingOptions) {
Expand Down
3 changes: 3 additions & 0 deletions test/chunking-form/samples/export-default-global/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
description: 'handles default exporting global variables'
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
define(function () { 'use strict';

console.log(global);

return global;

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

console.log(global);

module.exports = global;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
console.log(global);

export default global;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
System.register([], function (exports) {
'use strict';
return {
execute: function () {

console.log(global);

}
};
});
Empty file.
1 change: 1 addition & 0 deletions test/chunking-form/samples/export-default-global/lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default global;
4 changes: 4 additions & 0 deletions test/chunking-form/samples/export-default-global/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import value from './lib.js';

console.log(value);
export default value;

0 comments on commit 1b588b6

Please sign in to comment.