Skip to content

Regression: Incorrect emit of when adding async function to const export in JS file #21620

@bsouthga

Description

@bsouthga

The following occurs in 2.7.1 and next, but does not occur in 2.6.2 (emit is correct, no runtime error).

TypeScript Version: 2.7.1

Search Terms:
export, emit, es2017, class

Code

// this is a javascript file...

export const Adapter = {};

Adapter.prop = {};

// comment this out, and it works
Adapter.asyncMethod = async function() {}

tsconfig.json:

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "strict": true,
    "sourceMap": true,
    "allowJs": true,
    "outDir": "dist",
    "noLib": false,
    "skipLibCheck": true,
    "strictFunctionTypes": false,
    "lib": ["es2017"],
  }
}

Expected behavior:

Code compiles and runs successfully, the emit should look like...

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Adapter = {};
exports.Adapter.prop = {};
// comment this out, and it works
exports.Adapter.asyncMethod = async function () { };
//# sourceMappingURL=test.js.map

Actual behavior:

The following gets emitted:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Adapter = {};
Adapter.prop = {};
// comment this out, and it works
Adapter.asyncMethod = async function () { };
//# sourceMappingURL=test.js.map

which causes a runtime error as Adapter is not defined.

Playground Link:

Can't configure playground to the same setup, so here is a link to self contained repo: https://github.com/bsouthga/typescript-js-const-export-bug

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: TransformsRelates to the public transform APIFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions