Unnamed repository; edit this file 'description' to name the repository.
feat: inject css into standard browser API methods that expect css selector as argument (#14181)
Kristoffer Plagborg Bak Sørensen 7 months ago
parent b5a9c34 · commit 56fa9bf
-rw-r--r--runtime/queries/ecma/injections.scm15
1 files changed, 15 insertions, 0 deletions
diff --git a/runtime/queries/ecma/injections.scm b/runtime/queries/ecma/injections.scm
index 72ad31da..8430994d 100644
--- a/runtime/queries/ecma/injections.scm
+++ b/runtime/queries/ecma/injections.scm
@@ -47,3 +47,18 @@
(#set! injection.language "comment")
(#match? @injection.content "^//"))
+; Match string literals passed to standard browser API methods that expects a
+; css selector as argument.
+; - https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
+; - https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
+; - https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
+; - https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
+; e.g.
+; `const el = document.querySelector("div.user-panel.main input[name='login']");`
+(call_expression
+ function: (member_expression
+ object: (identifier) @_object
+ property: (property_identifier) @_property (#any-of? @_property "querySelector" "querySelectorAll" "closest" "matches"))
+ arguments: (arguments
+ (string (string_fragment) @injection.content))
+ (#set! injection.language "css"))