Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not export null as module.exports in amd.js. Resolves #2332. #2334

Merged
merged 5 commits into from
Jun 7, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/extras/amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ import { errMsg } from '../err-msg.js';
var amdResult = amdExec.apply(exports, depModules);
if (amdResult !== undefined)
module.exports = amdResult;
_export(module.exports);
// https://github.com/systemjs/systemjs/issues/2332
if (module.exports !== null)
_export(module.exports);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the core change we shouldn't need this null check anymore:

Suggested change
// https://github.com/systemjs/systemjs/issues/2332
if (module.exports !== null)
_export(module.exports);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏿 updated

_export('default', module.exports);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/extras/named-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
// hook the _export function to note the default export
var defaultExport, hasDefaultExport = false;
var declaration = registerDeclare.call(this, function (name, value) {
if (typeof name === 'object' && name.__useDefault)
if (typeof name === 'object' && name && name.__useDefault)
guybedford marked this conversation as resolved.
Show resolved Hide resolved
defaultExport = name.default, hasDefaultExport = true;
else if (name === 'default')
defaultExport = value;
Expand Down
2 changes: 1 addition & 1 deletion src/system-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function getOrCreateLoad (loader, id, firstParentUrl) {
}
}

if (name.__esModule) {
if (name && name.__esModule) {
ns.__esModule = name.__esModule;
}
}
Expand Down
7 changes: 7 additions & 0 deletions test/browser/amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,11 @@ suite('AMD tests', function () {
assert.equal(m.default, false);
});
});

// https://github.com/systemjs/systemjs/issues/2332
test('loading an AMD module that sets module.exports to null', function () {
return System.import('fixtures/amd-null-module.js').then(function (m) {
assert.equal(m.default, null);
});
});
});
3 changes: 3 additions & 0 deletions test/fixtures/browser/amd-null-module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
define([], function () {
return null;
});