Open Nowasky opened 4 years ago
In pure javascript, I don't think <!--
is a comment.
https://www.ecma-international.org/ecma-262/11.0/index.html#sec-comments
If that Javascript is inside a <script>
tag in an html file, then <!--
should be treated as a comment.
Beautifier currently supports these as the first element, but not after.
This was due to limitations in the beautifier at one time. At this time, it might be reasonable to remove the limitation.
This is has potential to break some cases so tests will need to be added.
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.
Just to be clear, I have no objection to someone filing a PR to fix this.
Hi I'm new to contributing a open source projects. Could I take this issue?
Go for it.
Could you give a example to replicate the ideal behavior? because I'm trying to comment a js code in script
tag using <!--
, but it doesn't work and I did some research I found that it just work in old browsers. Thanks for your time
Switch to JavaScript beautification an try the example from the original description.
alert(1)<!--commented
Hi Team, I'm new to contributing a open source projects. I'm unable to run the project in my local computer[windows OS]. it's throws error [make × ERR not found: make-$(BUILD_DIR)/node] could you tell me how to resolve the issue. link [https://user-images.githubusercontent.com/36472845/144790219-e9e8d060-8dd0-49a1-8fd8-8d662199126b.png]
Trying to raise a pr here but before seems stuck on make ci
command
virtualenv --version || pip install virtualenv
/bin/bash: virtualenv: command not found
Requirement already satisfied: virtualenv in /Users/myname/Library/Python/3.11/lib/python/site-packages (20.21.0)
Requirement already satisfied: distlib<1,>=0.3.6 in /Users/myname/Library/Python/3.11/lib/python/site-packages (from virtualenv) (0.3.6)
Requirement already satisfied: filelock<4,>=3.4.1 in /Users/myname/Library/Python/3.11/lib/python/site-packages (from virtualenv) (3.10.7)
Requirement already satisfied: platformdirs<4,>=2.4 in /opt/homebrew/lib/python3.11/site-packages (from virtualenv) (3.5.0)
virtualenv build/python-dev
make: virtualenv: No such file or directory
make: *** [/Users/myname/prs/js-beautify/build/virtualenv] Error 1
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