Skip to content

JavaScript in HTML: fails to parse after an HTML commen since JSX support #4373

@b4n

Description

@b4n

Parser: HTML or JS? I'm not sure at which level this should be fixed.
CTags version: master (b11e39a)

If JS embedded in HTML starts with <!--, the next symbol won't be properly recognized. For example:

$ cat /tmp/a.html
<!DOCTYPE html>
<head>
<script type="text/javascript">
<!--
function message() { alert( "Hello."); }
//-->
</script>
</head>
</html>
$ ./ctags -o- --extras=+g  /tmp/a.html
$ sed 's,^<!--,//&,' < /tmp/a.html > /tmp/b.html
$ cat /tmp/b.html
<!DOCTYPE html>
<head>
<script type="text/javascript">
//<!--
function message() { alert( "Hello."); }
//-->
</script>
</head>
</html>
$ ./ctags -o- --extras=+g  /tmp/b.html
message	/tmp/b.html	/^function message() { alert( "Hello."); }$/;"	f

This used to work before the JSX support (6c6799a).

I'm not quite sure whether the first (non-working) example works in a web browser because ECMAScript supports this special case, or if it's the browser doing this (so whether it should be on the JS or HTML side), but they seem to be happy with it, so we probably should be as well. This breaks Geany's simple.html test case (although it supposedly came from here, I couldn't find it in the history).

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions