GeezerVison is showing github.com — Incorrect imported function `this` context using ES6 module · Issue #4706 · microsoft/TypeScript
Incorrect imported function this context using ES6 module #4706
Description
Code
// export.ts
export function foo() {
'use strict'
console.log(this);
}
foo();
// import.ts
import { foo } from './export';
foo();
expected
$ node import.js
undefined
undefined
actual
$ node import.js
undefined
{ foo: [Function: foo] }
Activity
mhegazy commented on Sep 10, 2015
The emitter will need to identify call/new expressions from aliases, and rewrite them using as foo.call(void 0, arg)
A PR would be appreciated.
falsandtru commented on Sep 10, 2015
ContributorAuthor
More actions
Thanks for your acceptance.
added this to the
This milestone has been deleted milestone
on Sep 18, 2015falsandtru commented on Dec 14, 2015
ContributorAuthor
More actions
Babel's implementations:
(0, _assert2['default'])(true); // (A)
Note that the default export is always accessed via the exports object_assert2 (line A), never directly, like this:
var assert = _assert2.default;
The reason for that is support for cyclic dependencies.
http://www.2ality.com/2015/12/babel-commonjs.html
Andarist commented on Aug 1, 2023
As the current emit does this:
Object.defineProperty(exports, "__esModule", { value: true });
var export_1 = require("./export");
(0, export_1.foo)();
I think that the issue can be closed, cc Jake Bailey (@jakebailey)
locked as resolved and limited conversation to collaborators
on Oct 22, 2025
Metadata
Metadata
Development
No branches or pull requestsIssue actions