Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E4X misinterpretation #2255

Open
t-tera opened this issue Feb 27, 2024 · 0 comments
Open

E4X misinterpretation #2255

t-tera opened this issue Feb 27, 2024 · 0 comments

Comments

@t-tera
Copy link

t-tera commented Feb 27, 2024

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,
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants