[feature request] Convert functions to arrow functions
See original GitHub issueI think Babili could save a lot of bytes with a plugin that converts functions that do not make use of this
to arrow functions:
Input (34):
function foo() {
return 'bar';
}
Output(18):
let foo=()=>'bar';
// or 20 with `const`
Current result: https://babeljs.io/repl/#?babili=true&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&code=function foo() { return ‘bar’%3B }
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Arrow function expressions - JavaScript - MDN Web Docs
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate ...
Read more >feature request: arrow function transformation #182 - GitHub
The minimum language target for esbuild is set at ES6, which supports arrow functions. It's not possible to set the language target to...
Read more >Convert to arrow function in WebStorm - Darek Kay
Configure an intention action using Structural Search and Replace to transform JavaScript functions into arrow functions.
Read more >Arrow functions, the basics - The Modern JavaScript Tutorial
Arrow functions can be used in the same way as Function Expressions. For instance, to dynamically create a function:.
Read more >Are 'Arrow Functions' and 'Functions' equivalent ...
tl;dr: No! Arrow functions and function declarations / expressions are not equivalent and cannot be replaced blindly. If the function you want to...
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 FreeTop 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
Top GitHub Comments
Actually I think it could be determined (to some extent) if
new
is gonna be used. If resultingfoo
is local, not exported, not assigned to any object or reassigned it would be safe to apply such transformation. Wouldnt it?yeah, but unsafe flags means most people would never use this feature and its not worth developing.
i would rather program a better static analyzer where if you can prove the closure is never
new
ed then do the transform. it would be pretty tricky and you would need to add ability to recognize and follow promises.