You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Is it possible to not add line breaks every 500 characters? #4106
It looks like there is a setter for this on CompilerOptions (if you have your own subclass of either CommandLineRunner or AbstractCommandLineRunner, or if you directly create your own Compiler instance), but this isn't presently exposed via command line flags.
Removing the line breaks has no effect on a script's semantics.
Unfortunately, when the newline is placed here: "value"in[newline]var - it breaks when the newline is removed. Still holding out for an exposed option to disable the newlines 😅
I think the intent of that documentation was to say "the goal of adding these line breaks isn't preserving semantics", which is true, but "removing the line breaks has no effect on a script's semantics" is definitely incorrect.
I can update that document.
@kittenswolf as Bradford said in #4106 (comment), I think we'd still accept a PR if you want to contribute an option to not add the line breaks.
@niloc132 thanks for clarifying. It certainly isn't safe to remove a newline without replacing it with some other whitespace. I'm sure the author of the original documentation was thinking of "removing" a newline the same way the author of a text document would. If you remove the newline, you actually replace it with a space to keep word boundaries.
Activity
niloc132 commentedon Aug 4, 2023
It looks like there is a setter for this on CompilerOptions (if you have your own subclass of either CommandLineRunner or AbstractCommandLineRunner, or if you directly create your own Compiler instance), but this isn't presently exposed via command line flags.
closure-compiler/src/com/google/javascript/jscomp/CompilerOptions.java
Lines 65 to 66 in ff2c49e
closure-compiler/src/com/google/javascript/jscomp/CompilerOptions.java
Line 973 in ff2c49e
closure-compiler/src/com/google/javascript/jscomp/CompilerOptions.java
Lines 2489 to 2491 in ff2c49e
concavelenz commentedon Aug 4, 2023
Yes, setting it to 0 will tell it not to break at all.
ghnp5 commentedon Aug 4, 2023
How do I set it to 0? (I use the command line)
brad4d commentedon Sep 1, 2023
It seems we haven't exposed a command-line option for setting this value.
Here's the file where one would add that and an example option to copy.
https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/CommandLineRunner.java#L217
If you'd like to submit a PR, we'll be happy to review and merge it.
Or you could just change the constant value in your download of our sources and rebuild.
kittenswolf commentedon Feb 5, 2026
I noticed that the closure compiler FAQ regarding newlines is incorrect:
Unfortunately, when the newline is placed here:
"value"in[newline]var- it breaks when the newline is removed. Still holding out for an exposed option to disable the newlines 😅lauraharker commentedon Feb 9, 2026
What sort of breakage do you mean?
I tried reproducing in the Chrome console, but simply adding a new line after the
inkeyword still parses fine -If the compiler is outputting code that doesn't parse, that's definitely a bug.
niloc132 commentedon Feb 9, 2026
@lauraharker I believe you are reading @kittenswolf's comment backwards. The original documentation reads
so a user should be able to remove, not add, a newline, from the closure-generated output, and still see valid JS.
The counterexample is that closure is apparently generating
This code parses, but when that newline is removed the resulting JS is
which will definitely have an impact on the script's semantics.
Perhaps a regression occurred, or the documentation should indicate that in some cases the newline can't be removed, or must be replaced with a space?
lauraharker commentedon Feb 9, 2026
Ah, thanks for the correction @niloc132 .
I think the intent of that documentation was to say "the goal of adding these line breaks isn't preserving semantics", which is true, but "removing the line breaks has no effect on a script's semantics" is definitely incorrect.
I can update that document.
@kittenswolf as Bradford said in #4106 (comment), I think we'd still accept a PR if you want to contribute an option to not add the line breaks.
brad4d commentedon Feb 9, 2026
@niloc132 thanks for clarifying. It certainly isn't safe to remove a newline without replacing it with some other whitespace. I'm sure the author of the original documentation was thinking of "removing" a newline the same way the author of a text document would. If you remove the newline, you actually replace it with a space to keep word boundaries.