[JS] Wrong formatting: invalid syntax

Author: larmcrCreated Jul 28, 2019Updated Jun 30, 2026
Labelstype: buglanguage: javascript

Description

I found an issue by using the VSCodeBeautify (Visual Studio Code Extension) and they indicated me to submit the issue here.

Input

The code looked like this before beautification (valid according to Esprima Syntax Validator):

javascript
var a = true
!function foo(b) { a = b; }(false)

Expected Output

The code should have looked like this after beautification (valid according to Esprima Syntax Validator):

javascript
var a = true
!function foo(b) {
    a = b;
}(false)

Actual Output

The code actually looked like this after beautification (invalid according to Esprima Syntax Validator):

javascript
var a = true! function foo(b) {
    a = b;
}(false)

Steps to Reproduce

I checked it out in https://beautifier.io by using default settings:

Settings

json
{
  "indent_size": "4",
  "indent_char": " ",
  "max_preserve_newlines": "5",
  "preserve_newlines": true,
  "keep_array_indentation": false,
  "break_chained_methods": false,
  "indent_scripts": "normal",
  "brace_style": "collapse",
  "space_before_conditional": true,
  "unescape_strings": false,
  "jslint_happy": false,
  "end_with_newline": false,
  "wrap_line_length": "0",
  "indent_inner_html": false,
  "comma_first": false,
  "e4x": false,
  "indent_empty_lines": false
}