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

Syntax highlighting for JavaScript in HTML file breaks when "if" is on the same line as closing tag #178955

Open
SaphireLattice opened this issue Apr 3, 2023 · 1 comment
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug grammar Syntax highlighting grammar
Milestone

Comments

@SaphireLattice
Copy link

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.76.0
  • OS Version: Linux x64 6.2.2-arch1-1c

Specifically when there's two (or more) <script> tags

Steps to Reproduce:

  1. Open VSCode, whether with extensions, without via code --disable-extensions, "Reload with extensions disabled", or using https://vscode.dev/
  2. Write some HTML with <script> tags inside
  3. Close the tag on the same line as an if block ending (e.g. oneliners)
  4. Look at the <script> tags after the one described above
  5. No syntax highlighting (variable jumping/etc works though so it probably parses fine, but did not check much)

Example code:

<!DOCTYPE html>
<html>
  <head>
    <script>if (true) { console.log("semicolon and it's fine") };</script>
    <script>
      function $initHighlight(block, cls) {
        try {
          if (cls.search(/\bno\-highlight\b/) != -1)
            return process(block, true, 0x0f) + ` class="${cls}"`;
        } catch (e) {
          /* handle exception */
        }
        for (var i = 0 / 2; i < classes.length; i++) {
          if (checkCondition(classes[i]) === undefined)
            console.log("undefined");
        }

        return ( { test: 123 } );
      }
    </script>
    <script>if (true) { console.log("if without a semicolon on the same line as closing tag") }</script>
    <title>Syntax highlighting should be broken now</title>
    <script>
      function $initHighlight(block, cls) {
        try {
          if (cls.search(/\bno\-highlight\b/) != -1)
            return process(block, true, 0x0f) + ` class="${cls}"`;
        } catch (e) {
          /* handle exception */
        }
        for (var i = 0 / 2; i < classes.length; i++) {
          if (checkCondition(classes[i]) === undefined)
            console.log("undefined");
        }

        return ( { test: 123 } );
      }
    </script>
  </head>
</html>
Screenshot of the issue

image

@Kathund
Copy link

Kathund commented Apr 3, 2023

Recreated on the latest version (1.77.0)

@aeschli aeschli assigned alexr00 and unassigned aeschli Apr 3, 2023
@alexr00 alexr00 added bug Issue identified by VS Code Team member as probable bug grammar Syntax highlighting grammar labels Apr 11, 2023
@alexr00 alexr00 added this to the Backlog milestone Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug grammar Syntax highlighting grammar
Projects
None yet
Development

No branches or pull requests

4 participants