0

This question is similar to: Why do we have newlines in minified JavaScript?

In this case, I would prefer half a dozen or so newlines. Why do minifiers reduce code and style to one line? Even on production code, I might have bugs that I didn't consider. While, other may be professional-100% perfect developers, I'd like an option to at least insert a dozen or so newlines. I have avoided minifying code for a bit. Until now, I'd like a bit more performance but some balance of code review as well.

Maybe not a newline for every function, but at least for every class object since I use a lot of custom React Component classes.

Pretty:

var num = 10;
const dothis = function() {
 let x = 0;
 for(x = 0; x < num; x++) {
    ...
};
function dothat(){
  var foo = 'Hello';
  let name = 'World';
  var bar = foo + name;
  console.log(bar);
}

Uglified

var num=10;const dothis=function(){let x=0;for(x=0;x<num;x++){...}};function dothat(){var foo = 'Hello';let name = 'World';var bar = foo + name;console.log(bar);}

Something in between

var num = 10;
const dothis = function() { let x=0; for(x = 0; x < num; x++) {...};
function dothat(){ var foo = 'Hello'; let name = 'World'; var bar = foo + name; console.log(bar); }

Having half a dozen or so newline would allow me to narrow down the function or class causing the problem. I understand this shouldn't replace testing during development.

Community
  • 1
  • 1
Cit5
  • 400
  • 5
  • 19
  • You are aware of the "pretty print" feature in Chrome devtools (the icon which looks like `{}`) which will put newlines into your source, right? –  May 20 '17 at 02:33
  • Be gentle @torazaburo . I'm not a smart man ... Wanna put that as an answer for best vote? – Cit5 May 20 '17 at 02:49

1 Answers1

1

Use the pretty-print option in devtools.

enter image description here

This will give you:

enter image description here

Documentation is here.