a?.b.c() produces different result than a?.b!.c()
See original GitHub issueBug 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
- Babel version(s): 7.7.7
- How you are using Babel: https://babeljs.io/repl
Possible Solution ¯\_(ツ)_/
Additional context/Screenshots Add any other context about the problem here. If applicable, add screenshots to help explain.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
ABC conjecture - Wikipedia
The conjecture essentially states that the product of the distinct prime factors of abc is usually not much smaller than c. A number...
Read more >Whats the difference between "abc" and {"abc"} in C?
The first line line defines an array of four bytes. These two are equivalent: char str[4] = "abc"; char str[4] = {'a', 'b',...
Read more >Activity-based costing (ABC)
ABC focuses attention on cost drivers, the activities that cause costs to increase.
Read more >collections.abc — Abstract Base Classes for Containers ...
An issubclass() or isinstance() test for an interface works in one of three ways. 1) A newly written class can inherit directly from...
Read more >The Disadvantages & Advantages of Activity-Based Costing
ABC produces more accurate costing of products by essentially converting broad indirect costs into direct costs of production. It determines the costs of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m working in a fix to this bug.
@nicolo-ribaudo There’s a bug filed at the TypeScript repo.