GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Incorrect imported function this context using ES6 module#4706
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScriptES6Relates to the ES6 SpecRelates to the ES6 Spec
Milestone
Backlog

Description

@falsandtru
falsandtru (falsandtru)
opened on Sep 9, 2015
Issue body actions

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

  1. Mohamed Hegazy (mhegazy)
    added
    BugA bug in TypeScriptA bug in TypeScript
    Accepting PRs
    on Sep 10, 2015
  2. mhegazy commented on Sep 10, 2015

    @mhegazy
    Mohamed Hegazy (mhegazy)
    on Sep 10, 2015
    Contributor
    More actions

    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.

  3. falsandtru commented on Sep 10, 2015

    @falsandtru
    falsandtru (falsandtru)
    on Sep 10, 2015
    ContributorAuthor
    More actions

    Thanks for your acceptance.

  4. Mohamed Hegazy (mhegazy)
    added this to the This milestone has been deleted milestone on Sep 18, 2015
  5. falsandtru commented on Dec 14, 2015

    @falsandtru
    falsandtru (falsandtru)
    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

  6. Mohamed Hegazy (mhegazy)
    added
    ES6Relates to the ES6 SpecRelates to the ES6 Spec
    on Feb 22, 2016
  7. Ryan Cavanaugh (RyanCavanaugh)
    modified the milestones: Community, Backlog on Mar 7, 2019
  8. Andarist commented on Aug 1, 2023

    @Andarist
    Mateusz Burzyński (Andarist)
    on Aug 1, 2023
    Contributor
    More actions

    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)

  9. Jake Bailey (jakebailey)
    closed this as completedon Aug 1, 2023
  10. microsoft
    locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptA bug in TypeScriptES6Relates to the ES6 SpecRelates to the ES6 Spec

    Type

    No type

    Projects

    No projects

      Milestone

      • BacklogNo due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.