question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Beautification problem with JS Single Line Comment <!--

See original GitHub issue

In Javascript <!-- is treated as a single-line comment just like //.

js-beautify works as expected when the line starts with <!--:

Input: <!--alert(1)commented

Output: <!--alert(1)commented

Otherwise it will break the syntax:

Input: alert(1)<!--commented

Output: alert(1) < !--commented

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Nowaskycommented, Sep 1, 2020

Please refer to annex B1.3 of the ES6 espec. https://www.ecma-international.org/ecma-262/11.0/index.html#prod-annexB-SingleLineHTMLOpenComment

B.1.3 HTML-like Comments

Comment:: MultiLineComment SingleLineComment SingleLineHTMLOpenComment SingleLineHTMLCloseComment SingleLineDelimitedComment

SingleLineHTMLOpenComment:: <!–SingleLineCommentCharsopt

Although it’s a legacy support as noted:

This annex describes various legacy features and other characteristics of web browser based ECMAScript implementations. All of the language features and behaviours specified in this annex have one or more undesirable characteristics and in the absence of legacy usage would be removed from this specification. However, the usage of these features by large numbers of existing web pages means that web browsers must continue to support them. The specifications in this annex define the requirements for interoperable implementations of these legacy features.

These features are not considered part of the core ECMAScript language. Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code. ECMAScript implementations are discouraged from implementing these features unless the implementation is part of a web browser or is required to run the same legacy ECMAScript code that web browsers encounter.

1reaction
bitwisemancommented, Jun 16, 2021

Switch to JavaScript beautification an try the example from the original description.

alert(1)<!--commented

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disable/Skip HTML single-line comment · Issue #426 - GitHub
I usually have a comment after the closing html tag in order to identify the tag on big files with a lot of...
Read more >
Js-beautify wrap inline comments near css rules - html
I have a small issue with js beautify when I try to format my scss codebase. Input. The code looked like this before...
Read more >
JavaScript Comments - W3Schools
JavaScript comments can be used to explain JavaScript code, and to make it more readable. ... This example uses a single-line comment before...
Read more >
mjmlTest/node_modules/js-beautify/CHANGELOG.md - GitLab
css-beautify sibling combinator space issue (#1001); Bug: Breaks when the source code it found an unclosed multiline comment.
Read more >
Comments in Julia - GeeksforGeeks
A multiline comment is useful when the comment text does not fit into one line; therefore needs to span across lines. Multi-line comments...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found