Skip to content

javascript: exports and module.exports are the file's own surface, and a member export lands on the module.exports value #463

Description

@swapnilpaliwal-sd

Part of #456.

Symptom

exports.clone(x), var self = exports; self.run(), module.exports.helper() inside a CommonJS file were ambient_terminal — the binder marks exports and module GLOBAL_BUILTIN — although they call into the file itself. And exports = module.exports = Base; exports.list = function ...; Base.list(...) found no list on Base: the member was written through one name of an object that has two.

Fix

  • Inside a module, exports and module.exports evaluate to that module's own surface (the module value); a GLOBAL_BUILTIN receiver that got a value is not ambient.
  • A member export row (exports.x =, module.exports.x =) is a property of the module's CommonJS default value as well, when there is one — module.exports = Base and exports.list = ... name one object.
exports = module.exports = Base;
exports.list = function (failures) {};
function Base() {}
Base.list(this.failures);   // -> the function assigned to exports.list

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingengineResolution / call-graph engine rulesjavascriptJavaScript

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions