js-beautify
js-beautify copied to clipboard
E4X misinterpretation
Description
When E4X options is enabled, some pure (non-e4x) javascript statement is misinterpreted as xml.
Input
The code looked like this before beautification:
str =A++<22 ? "</x>" : "";
Expected Output
The code should have looked like this after beautification:
str = A++ < 22 ? "</x>" : "";
Actual Output
The code actually looked like this after beautification:
str = A++<22 ? "</x>
" : "
";
Steps to Reproduce
The followings are dump of tokens generated in beautify.js
.
If e4x options is enabled, _read_xml()
in beautify.js
treats <22 ? "</x>
as TK_STRING
.
Object { type: "TK_WORD", text: "str", comments_before: null, newlines: 0, whitespace_before: "", parent: null, next: null, previous: null, opened: null, closed: null, … }
Object { type: "TK_EQUALS", text: "=", comments_before: null, newlines: 0, whitespace_before: " ", parent: null, next: null, previous: null, opened: null, closed: null, … }
Object { type: "TK_WORD", text: "A", comments_before: null, newlines: 0, whitespace_before: "", parent: null, next: null, previous: null, opened: null, closed: null, … }
Object { type: "TK_OPERATOR", text: "++", comments_before: null, newlines: 0, whitespace_before: "", parent: null, next: null, previous: null, opened: null, closed: null, … }
Object { type: "TK_STRING", text: '<22 ? "</x>', comments_before: null, newlines: 0, whitespace_before: "", parent: null, next: null, previous: null, opened: null, closed: null, … }
Settings
js-beautify v1.15.1
{
indent_size: 2,
indent_char: ' ',
eol: '\n',
max_preserve_newlines: 5,
preserve_newlines: true,
keep_array_indentation: false,
break_chained_methods: false,
indent_scripts: false,
brace_style: 'collapse',
space_before_conditional: true,
unescape_strings: false,
wrap_line_length: 150,
e4x: true,
}