Skip to content

a?.b.c() produces different result than a?.b!.c() #10959

@alex-kinokon

Description

@alex-kinokon

Bug Report

  • I would like to work on a fix!

Input Code

  • REPL or Repo link if applicable:
a?.b.c()
a?.b!.c()

Actual behavior

"use strict";

var _a, _a2;

(_a = a) === null || _a === void 0 ? void 0 : _a.b.c();
((_a2 = a) === null || _a2 === void 0 ? void 0 : _a2.b).c();

Expected behavior/code
The ! should have no effect on the produced code.

Problem: Suppose a is null, then the second line can be reduced to:

   ((_a2 = a) === null || _a2 === void 0 ? void 0 : _a2.b).c()
=> ((a2 = null) === null || _a2 === void 0 ? void 0 : _a2.b).c()
=> (null === null || _a2 === void 0 ? void 0 : _a2.b).c()
=> (true ? void 0 : _a2.b).c()
=> undefined.c()

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

  • Filename: babel.config.js
{
  "presets": ["@babel/preset-typescript", "@babel/preset-stage-3"]
}

Environment

Possible Solution
¯\_(ツ)_/

Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions