Skip to content

Incorrect emit for hoisted variables and "use strict" at the top of a file. #33217

Closed
@rbuckton

Description

@rbuckton

TypeScript Version: 3.5.1 (possibly earlier)

Search Terms:
use strict emit file

Code

// @target: esnext
// @module: commonjs
"use strict";
let x = "x" as const;
class A {
  [x] = 1;
}

Expected behavior:

Should emit the following:

"use strict";
var _a;
let x = "x";
class A {
    constructor() {
        this[_a] = 1;
    }
}
_a = x;

Actual behavior:

Emits the following ("use strict" is not at the top of the file):

var _a;
"use strict";
let x = "x";
class A {
    constructor() {
        this[_a] = 1;
    }
}
_a = x;

Playground Link: http://www.typescriptlang.org/play/index.html#code/MYewdgzgLgBAHjAvDARHFBuAUMANgQwghgEEYBvLGamAbTgF0kYBGbAXyA

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions