question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[feature request] Convert functions to arrow functions

See original GitHub issue

I 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:open
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Andaristcommented, Oct 3, 2017

Actually I think it could be determined (to some extent) if new is gonna be used. If resulting foo is local, not exported, not assigned to any object or reassigned it would be safe to apply such transformation. Wouldnt it?

0reactions
Pyrolisticalcommented, Oct 3, 2017

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 newed then do the transform. it would be pretty tricky and you would need to add ability to recognize and follow promises.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found