X Tutup
Skip to content

Markup beautification issue for do while in <% templates #445

@lenilsondc

Description

@lenilsondc

Found a minor defect while beautifying markup jsp and asp like template delimiters (i.e., <% .. %>), the parse is interpreting <% do %> as template_start and it causes the beautifier to indent one extra level when sometimes it shouldn't do this. I believe the reason for this feature to exist is to support <% do %> like loops or something similar, but it's matching every template that has a do within the delimiters.

For example, this:

<%
    int i = 0;
    
    do {
        i++;
    }while(i < 3);
%>
<!DOCTYPE html>
<html>
    ...
</html>

Is beautified to:

<%
    int i = 0;
    
    do {
        i++;
    }while(i < 3);
%>
    <!DOCTYPE html>
    <html>
        ...
    </html>

The example above describe the do while case, but it can also be triggered if you have any "\sdo\s" within the template.

<%
   // do the harlem shake
%>
    <!DOCTYPE html>
    <html> ...</html>

I found out which part of the code is doing this, check the code below:

...
else if ((/\sdo\s/).test(element) === true || (/^(<%(%|-)?\s*if)/).test(element) === true) {
    types[types.length - 1] = "template_start";
}
....

I managed to solve this by changing the regex to /^<%\s*do\s so that the do will match the beginning of a template but not every word in the template.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup