Skip to content

Optional chaining is emitting not recognizable JavaScript code in lower level than ES Next #33737

@Jack-Works

Description

@Jack-Works

In the TypeScript design goal it writes Emit clean, idiomatic, recognizable JavaScript code, but the optional chaining breaks this.

TypeScript Version: 3.7.0-beta

Search Terms: Optional chaining

Code

const a = globalThis?.browser?.runtime?.getBackgroundPage?.()?.location?.href ?? location.href

Expected behavior:

Generate a recognizable JavaScript code.

Actual behavior:

var _a, _b, _c, _d, _e, _f, _g, _h;
const a = (_h = (_g = (_f = (_e = (_c = (_b = (_a = globalThis) === null || _a === void 0 ? void 0 : _a.browser) === null || _b === void 0 ? void 0 : _b.runtime) === null || _c === void 0 ? void 0 : (_d = _c).getBackgroundPage) === null || _e === void 0 ? void 0 : _e.call(_d)) === null || _f === void 0 ? void 0 : _f.location) === null || _g === void 0 ? void 0 : _g.href, (_h !== null && _h !== void 0 ? _h : location.href));

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions