Skip to content

In JS, module.exports should be aliasable with a var declaration #22460

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

Closed
sandersn opened this issue Mar 10, 2018 · 2 comments
Closed

In JS, module.exports should be aliasable with a var declaration #22460

sandersn opened this issue Mar 10, 2018 · 2 comments
Assignees
Labels
checkJs Relates to checking JavaScript using TypeScript Suggestion An idea for TypeScript

Comments

@sandersn
Copy link
Member

Code

// @noEmit: true
// @allowJs: true
// @checkJs: true
// @strict: true
// @Filename: a.js

// from assert
var assert = module.exports = ok;
function fail() {
}
assert.fail = fail;
function ok() {

}
assert.ok = ok;

assert.AssertionError = function (actual, expect) {
    this.name = 'AssertionError';
    this.actual = actual;
    this.expected = expected;
}

Expected behavior:
No errors, and assert results in a module that is callable with exports { ok, fail, AssertionError }.
Actual behavior:
Lots of errors, and no exports, just a callable module.

@sandersn
Copy link
Member Author

This should also be true when the initializer is a call expression, not just an identifier. Here's an example from npm's code:

// @noEmit: true
// @allowJs: true
// @checkJs: true
// @Filename: npm-log.js
// from npm
var EE = require('events').EventEmitter
var log = exports = module.exports = new EE()
log.useColor = function () {
    this.eventNames()
}
log.enableColors = function () {
    this.useColor()
}

// @Filename: npm-cli.js

var log = require('./npm-log')
log.enableColors()
log.useColor()
log.eventNames()

@DanielRosenwasser DanielRosenwasser added the checkJs Relates to checking JavaScript using TypeScript label Mar 16, 2018
@mhegazy mhegazy added the Suggestion An idea for TypeScript label Mar 28, 2018
@sandersn sandersn changed the title In JS, module.exports should support chained assignments In JS, module.exports should be aliasable with a var declaration Apr 10, 2018
@sandersn
Copy link
Member Author

This is fixed, although it appears to expose a follow-on error with static properties that have this-assignments. I filed #25906 to track it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checkJs Relates to checking JavaScript using TypeScript Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants