Support for inline <script> tags
Would be nice to have support for inline script tags (please disregard the gibberish JS)
I like this idea! I can work on a PR adding JS injections to https://github.com/phoenixframework/tree-sitter-heex/blob/main/queries/injections.scm. Depending on what text editor you use you may need to port those queries to the format your text editor understands. For example, nvim-treesitter uses a different set of captures to handle language injection.
Update on this: I believe we need to introduce a new node type for <script> that allows {} characters. Once I have more time for open source I'll get started on that.
We could support script (and maybe style too?) elements as separate nodes like tree-sitter-html: https://github.com/tree-sitter/tree-sitter-html/blob/d742025fa2d8e6100f134a6ea990443aa1f074b3/grammar.js#L64-L68. It looks like we have some parsing errors currently where do is mistaken by the error recovery mechanism and I think using a custom element might eliminate that
I started working on this last night, see https://github.com/phoenixframework/tree-sitter-heex/pull/38. I'm currently struggling to get the contents of a <script> tag to parse correctly. It is running into issues when there are {} characters and I'm not sure how to proceed.
Looking at tree-sitter-html they solve this via an external scanner written in C. Given how similar HEEx is I could copy that over if we are willing to introduce native code into this grammar.
@the-mikedavis If you have any ideas, I'd love to hear them!
For posterity, it appears that we do need to implement an external scanner to write a node that captures all text until hitting </script> or </style>: https://github.com/tree-sitter/tree-sitter/discussions/1252