[plugin-proposal-optional-chaining] Loose mode produces unoptimized code for class methods
See original GitHub issueBug Report
- I would like to work on a fix!
Current Behavior
The loose
mode of optional-chaining
plugin compiles class methods in non-optimized way repeating the call to the method instead of remembering its result.
It does not happen for function call though.
Input Code
- REPL or Repo link if applicable: Runkit.
a.get(b)?.();
compiles to:
a.get(b) == null ? void 0 : a.get(b)();
Expected behavior/code The result of method call should be memoized as it happens in the strict mode.
var a$get;
(a$get = a.get(b)) == null ? void 0 : a$get();
Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)
- Filename:
babel.config.js
{
plugins: [[require('@babel/plugin-proposal-optional-chaining'), {loose: true}]]
}
Environment
- Babel version(s): 7.8.4
- Node/npm version: v13.5.0/6.13.4
- OS: Windows 10
- Monorepo: Lerna
- How you are using Babel: cli/programmatically
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
babel/plugin-proposal-optional-chaining
Example · Accessing deeply nested properties · Calling deeply nested functions · Constructing deeply nested classes · Deleting deeply nested properties.
Read more >Learning JavaScript Design Patterns
To provide a holistic understanding of the past and present of design patterns, this book will present ES2015+ and class (ES5) versions of...
Read more >Read Understanding ECMAScript 6 | Leanpub
Chapter 9: Introducing JavaScript Classes introduces the first formal ... Each methods accept two arguments: the text to search for and an optional...
Read more >babel/plugin-proposal-optional-chaining Code Examples - Snyk
To help you get started, we've selected a few @babel/plugin-proposal-optional-chaining examples, based on popular ways it is used in public projects.
Read more >WebGPU - W3C
This is a general problem with all general-purpose computation capabilities on the Web: JavaScript, WebAssembly or WebGL. WebGPU only makes some workloads ...
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’d love to work on this one 😃
All good. Happy to review an unfinished PR, please open one when you can.