Skip to content

In JS, both module.exports assignments and property assignments should be allowed in a single file #22461

Closed

Description

Code

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

// modified from graceful-fs
module.exports = patch
module.exports.close = function (fs$close) {
}
function patch(fs) {
    // do something with Fs
}

Expected behavior:
No errors, and graceful-fs creates a callable module with an exported member patch.

Actual behavior:
Lots of errors, and no exported member patch.

Activity

  1. sandersn commented on Mar 10, 2018

    @sandersn
    MemberAuthor

    This should be true for exports assignments too, and when the assignments are out of order, and when some property assignments are to exports and some to the alias. Here's an example based on uglify's code:

    // @noEmit: true
    // @allowJs: true
    // @checkJs: true
    // @Filename: ugly.js
    // from uglify-js
    var FILES = exports.FILES = [
        "./a.js",
        "./b.js"
    ]
    var ugly = exports
    ugly.ast.warn = function (txt) {
        return "WARN: " + txt
    }
    exports.other = function(files) {
    }
    
    // @Filename: use.js
    var ugly = require('./ugly')
    ugly.ast.warn('oh no')
    ugly.other(ugly.FILES)
  2. sandersn commented on Apr 4, 2018

    @sandersn
    MemberAuthor
  3. locked and limited conversation to collaborators on Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issuecheckJsRelates to checking JavaScript using TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions