Skip to content

Merged object exports of globalThis broken #30159

Open
@sandersn

Description

@sandersn

From bluebird user test

// @Filename: release/util.js
var ret = {
  isNode: isNode,
  isClass: isClass, // etc
}
ret.isRecentNode = ret.isNode && (function() { ... })();
// @Filename: release/async.js
const util = require('./util')
util.isNode // error
util.isRecentNode // ok
// @Filename: util.js
var globalObject = this;
var ret = {
  x: 1,
  global: globalObject,
}
ret.extra = 2;
module.exports = ret;
// @Filename: user.js
var util = require('./util')
util.global // ok
util.x // ok 
util.extra // ok?

Expected behavior:
all util.* ok

Actual behavior:
error on global and x

Due to toplevel this now having a type in the globalThis PR.
Note that this is a dist file from bluebird, where the intent is to provide a consistent global object as well as a consistent module.exports. But we get confused early on by module.exports references and incorrectly assume that the file is intended to be a module, and that toplevel this refers to the module, not globalThis.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JavaScriptThe issue relates to JavaScript specifically

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions