Skip to content

A require call that isn't the global require will clobber bindings #10931

@krisselden

Description

@krisselden

TypeScript Version: 1.8.0 / nightly (2.0.0-dev.201xxxxx)
typescript@beta or typescript@next
Code

// A *self-contained* demonstration of the problem follows...
import require from "some/module"

export foo from "some/other/module"

require("a single arg")

Expected behavior:
has a binding for foo
Actual behavior:
require() call expression is not checked for scope, that it is the module's require or that externalModuleIndicator already is present, it will redefine the symbol.

workaround in a custom host getSourceFile

      Object.defineProperty(sourceFile, "commonJsModuleIndicator", {
        get: () => sourceFile["externalModuleIndicator"]
      });

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions