The code looked like this before beautification:
frontend = Async(() => import('../frontend').then(m => m.default ))
The code should have looked like this after beautification:
frontend = Async(() => import('../frontend').then(m => m.default))
The code actually looked like this after beautification:
frontend = Async(() =>
import('../frontend').then(m => m.default))
OS: Linux 4.10, node 7.10
Example:
{
"brace_style": "collapse,preserve-inline",
"break_chained_methods": false,
"end_with_newline": false,
"eol": "\n",
"e4x": true,
"eval_code": false,
"indent_char": " ",
"indent_level": 0,
"indent_with_tabs": false,
"jslint_happy": false,
"keep_array_indentation": false,
"keep_function_indentation": false,
"max_preserve_newlines": 2,
"preserve_newlines": true,
"selector_separator_newline": false,
"space_after_anon_function": false,
"space_before_conditional": true,
"unescape_strings": false,
"wrap_attributes": "auto",
"wrap_attributes_indent_size": 4,
"wrap_line_length": 0,
"indent_size": 4
}
the same need
Please? This is much needed for me. Kills the the point of using the formatter for me.
In the meanwhile if you can use async/await you can use async () => await import()
(https://github.com/beautify-web/js-beautify/pull/1433)
@laggingreflex Thanks for the work around. That will help with with implementing a fix.
Note, in the original input there is a space. It is preserved in the output in rc6, exactly as you had above.
In rc6 if you pass:
frontend = Async(() => import('../frontend').then(m => m.default))
You get:
frontend = Async(() =>
import('../frontend').then(m => m.default))
Which is also valid.
What??? You gotta be kidding, man. No way you dare to label this as resolved simply because the resulting output is valid syntax.
@ZzZombo
Are you joking or not? I can't tell.
The input is valid, that output is also valid and has the same meaning as the input. How is that wrong?
Oh my god, you weren't kidding, holy shit. It's so fucking stupid that I even have to explain to you why it's wrong that a code formatter makes formatting worse, and BTW, nothing was even "fixed" because nothing was changed. The described – and wrong – behavior remained the same ever since. I mean, if you still don't get it, one can write code with trailing whitespace, it's valid JS still, yea, but wrong nonetheless, so that's why code formatters exist in the first place, to fix such issues, not make even more of them, especially where were none to begin with.
@renatofdds
Did you mean to have a space between import
and (
in your input but not in your output?
@bitwiseman yes.
@renatofdds
Just to be clear, I thought dynamic import was specifically import(
(without the space). So, you want to beautifier to remove the space to make a method call into a dynamic import call when it wasn't such in the input?
@bitwiseman I am sorry, i just used it as an example while writing this issue without thinking too much about it. I think too that beautifier shouldn't handle that space since it's a syntax error. However, the initial issue could be written as:
The code looked like this before beautification:
frontend = Async(() => import('../frontend').then(m => m.default ))
The code should have looked like this after beautification:
frontend = Async(() => import('../frontend').then(m => m.default))
The code actually looked like this after beautification:
frontend = Async(() =>
import('../frontend').then(m => m.default))
I no longer use beautifier so i have no way to tell if this issue is already fixed, i am sorry. If it is already fixed please go ahead and close this.
Thank you very much!
No, it is not fixed, but thanks for taking the time to give cleaned up info. I've updated the original description.
Implementation note: import()
needs to be treated by the beautifier as a not a "line-starter". Changing it from reserved
to word
when it is immediately followed by (
without whitespace would work (similar to get/set
at the top of handle_word
).