From bdf26fe38ad0106346ac221c5a9c017df6268bcb Mon Sep 17 00:00:00 2001 From: Florian Sanders Date: Fri, 23 Aug 2024 08:53:03 +0200 Subject: [PATCH] Fix JavaScript and TypeScript HTML injections (#16479) Fixes #16199 ## Description Recently added template string injections do not completely work for because any time there is an interpolation (`${// some js content}`) within an element, its closing tag is not highlighted properly: ![image](https://github.com/user-attachments/assets/e660894b-6e4b-4300-b8d9-2757fa235679) This PR fixes the issue: ![image](https://github.com/user-attachments/assets/629a30c3-9b3a-4338-aee9-622dbb19581c) Release Notes: - Fixed incomplete syntax highlighting for HTML injections inside JavaScript template tags. ## Note I'm a beginner with treesitter so I only modified the part for HTML usecase. Should the same solution be applied to other injections (`css`, `js`, etc.)? --- crates/languages/src/javascript/injections.scm | 4 ++-- crates/languages/src/typescript/injections.scm | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/languages/src/javascript/injections.scm b/crates/languages/src/javascript/injections.scm index 681e476b181f5357003f6935888d10e9d85358c3..d629a2b3df970e46ef394809c96cff1fca8da82a 100644 --- a/crates/languages/src/javascript/injections.scm +++ b/crates/languages/src/javascript/injections.scm @@ -13,8 +13,8 @@ (call_expression function: (identifier) @_name (#eq? @_name "html") - arguments: (template_string (string_fragment) @content - (#set! "language" "html")) + arguments: (template_string) @content + (#set! "language" "html") ) (call_expression diff --git a/crates/languages/src/typescript/injections.scm b/crates/languages/src/typescript/injections.scm index 46d60254ce81c11232415ac4966fde3404396430..c47fc5efb4631ce2554f50d45a816a6a495ca6c1 100644 --- a/crates/languages/src/typescript/injections.scm +++ b/crates/languages/src/typescript/injections.scm @@ -17,8 +17,8 @@ (call_expression function: (identifier) @_name (#eq? @_name "html") - arguments: (template_string (string_fragment) @content - (#set! "language" "html")) + arguments: (template_string) @content + (#set! "language" "html") ) (call_expression @@ -50,4 +50,3 @@ arguments: (template_string (string_fragment) @content (#set! "language" "yaml")) ) -