Debian Codegraph @

runtime/queries/ecma/injections.scm

raw symbols SCIP
1 ; Parse the contents of tagged template literals using
2 ; a language inferred from the tag.
3
4 (call_expression
5 function: [
6 (identifier) @injection.language
7 (member_expression
8 property: (property_identifier) @injection.language)
9 ]
10 arguments: (template_string (string_fragment) @injection.content)
11 (#any-of? @injection.language "html" "css" "json" "sql" "js" "ts" "bash"))
12
13 ; Parse the contents of $ template literals as shell commands
14
15 (call_expression
16 function: [
17 (identifier) @_template_function_name
18 (member_expression
19 property: (property_identifier) @_template_function_name)
20 ]
21 arguments: (template_string (string_fragment) @injection.content)
22 (#eq? @_template_function_name "$")
23 (#set! injection.language "bash"))
24
25 ; GraphQL detection generally matches the rules provided by the 'GraphQL: Syntax Highlighting'
26 ; VSCode extension: https://github.com/graphql/graphiql/blob/8f25b38f4ab14dc99c046109f255fb283bccde52/packages/vscode-graphql-syntax/grammars/graphql.js.json
27
28 ; Parse the contents of 'gql' and 'graphql' template literals and function calls
29 (
30 (call_expression
31 function: (identifier) @_template_function_name
32 arguments: [
33 ; Tagged template literal: NAME``
34 (template_string (string_fragment) @injection.content)
35 (
36 arguments . [
37 ; Function call containing a string literal: NAME('')
38 (string (string_fragment) @injection.content)
39 ; Function call containing a template literal: NAME(``)
40 (template_string (string_fragment) @injection.content)
41 ]
42 )
43 ]
44 )
45 (#any-of? @_template_function_name "gql" "graphql")
46 (#set! injection.language "graphql")
47 )
48
49 ; Parse the contents of strings and tagged template literals that begin with a GraphQL comment '#graphql'
50 (
51 [
52 (string (string_fragment) @injection.content)
53 (template_string (string_fragment) @injection.content)
54 ]
55 (#match? @injection.content "^\\s*#graphql")
56 (#set! injection.language "graphql")
57 )
58
59 ; Parse the contents of strings and tagged template literals with leading ECMAScript comments '/* GraphQL */'
60 (
61 ((comment) @_ecma_comment) . [
62 (string (string_fragment) @injection.content)
63 (template_string (string_fragment) @injection.content)
64 (call_expression
65 arguments: (template_string (string_fragment) @injection.content)
66 )
67 ]
68 (#eq? @_ecma_comment "/* GraphQL */")
69 (#set! injection.language "graphql")
70 )
71
72 ; Parse regex syntax within regex literals
73
74 ((regex_pattern) @injection.content
75 (#set! injection.language "regex"))
76
77 ; Parse JSDoc annotations in multiline comments
78
79 ((comment) @injection.content
80 (#set! injection.language "jsdoc")
81 (#match? @injection.content "^/\\*+"))
82
83 ; Parse general tags in single line comments
84
85 ((comment) @injection.content
86 (#set! injection.language "comment")
87 (#match? @injection.content "^//"))
88
89 ; Match string literals passed to standard browser API methods that expects a
90 ; css selector as argument.
91 ; - https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector
92 ; - https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll
93 ; - https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
94 ; - https://developer.mozilla.org/en-US/docs/Web/API/Element/matches
95 ; e.g.
96 ; `const el = document.querySelector("div.user-panel.main input[name='login']");`
97 (call_expression
98 function: (member_expression
99 object: (identifier) @_object
100 property: (property_identifier) @_property (#any-of? @_property "querySelector" "querySelectorAll" "closest" "matches"))
101 arguments: (arguments
102 (string (string_fragment) @injection.content))
103 (#set! injection.language "css"))
104
105 ; styled-components / emotion: inject CSS into styled template literals.
106 ; `createGlobalStyle``, `keyframes``, `injectGlobal``
107 (call_expression
108 function: (identifier) @_name
109 (#any-of? @_name "createGlobalStyle" "keyframes" "injectGlobal")
110 arguments: (template_string (string_fragment) @injection.content)
111 (#set! injection.language "css"))
112
113 ; `styled.div``, `styled.button``, ...
114 (call_expression
115 function: (member_expression
116 object: (identifier) @_styled (#eq? @_styled "styled"))
117 arguments: (template_string (string_fragment) @injection.content)
118 (#set! injection.language "css"))
119
120 ; `styled(Component)``
121 (call_expression
122 function: (call_expression
123 function: (identifier) @_styled (#eq? @_styled "styled"))
124 arguments: (template_string (string_fragment) @injection.content)
125 (#set! injection.language "css"))