diff options
| author | Christian Clason <c.clason@uni-graz.at> | 2023-06-12 09:54:30 -0600 |
|---|---|---|
| committer | Christian Clason <c.clason@uni-graz.at> | 2025-05-12 18:43:40 +0200 |
| commit | 692b051b09935653befdb8f7ba8afdb640adf17b (patch) | |
| tree | 167162b6b129ae04f68c5735078521a72917c742 /runtime/queries/ecma/injections.scm | |
| parent | feat(c-family): inherit injections (diff) | |
| download | nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.gz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.bz2 nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.lz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.xz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.zst nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.zip | |
feat!: drop modules, general refactor and cleanup
Diffstat (limited to 'runtime/queries/ecma/injections.scm')
| -rw-r--r-- | runtime/queries/ecma/injections.scm | 203 |
1 files changed, 203 insertions, 0 deletions
diff --git a/runtime/queries/ecma/injections.scm b/runtime/queries/ecma/injections.scm new file mode 100644 index 000000000..04abafcde --- /dev/null +++ b/runtime/queries/ecma/injections.scm @@ -0,0 +1,203 @@ +(((comment) @_jsdoc_comment + (#lua-match? @_jsdoc_comment "^/[*][*][^*].*[*]/$")) @injection.content + (#set! injection.language "jsdoc")) + +((comment) @injection.content + (#set! injection.language "comment")) + +; html(`...`), html`...`, sql(`...`), etc. +(call_expression + function: (identifier) @injection.language + arguments: [ + (arguments + (template_string) @injection.content) + (template_string) @injection.content + ] + (#lua-match? @injection.language "^[a-zA-Z][a-zA-Z0-9]*$") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + ; Languages excluded from auto-injection due to special rules + ; - svg uses the html parser + ; - css uses the styled parser + (#not-any-of? @injection.language "svg" "css")) + +; svg`...` or svg(`...`) +(call_expression + function: (identifier) @_name + (#eq? @_name "svg") + arguments: [ + (arguments + (template_string) @injection.content) + (template_string) @injection.content + ] + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "html")) + +; Vercel PostgreSQL +; foo.sql`...` or foo.sql(`...`) +(call_expression + function: (member_expression + property: (property_identifier) @injection.language) + arguments: [ + (arguments + (template_string) @injection.content) + (template_string) @injection.content + ] + (#eq? @injection.language "sql") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children)) + +(call_expression + function: (identifier) @_name + (#eq? @_name "gql") + arguments: (template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "graphql")) + +(call_expression + function: (identifier) @_name + (#eq? @_name "hbs") + arguments: (template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "glimmer")) + +; css`<css>`, keyframes`<css>` +(call_expression + function: (identifier) @_name + (#any-of? @_name "css" "keyframes") + arguments: (template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "styled")) + +; styled.div`<css>` +(call_expression + function: (member_expression + object: (identifier) @_name + (#eq? @_name "styled")) + arguments: ((template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "styled"))) + +; styled(Component)`<css>` +(call_expression + function: (call_expression + function: (identifier) @_name + (#eq? @_name "styled")) + arguments: ((template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "styled"))) + +; styled.div.attrs({ prop: "foo" })`<css>` +(call_expression + function: (call_expression + function: (member_expression + object: (member_expression + object: (identifier) @_name + (#eq? @_name "styled")))) + arguments: ((template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "styled"))) + +; styled(Component).attrs({ prop: "foo" })`<css>` +(call_expression + function: (call_expression + function: (member_expression + object: (call_expression + function: (identifier) @_name + (#eq? @_name "styled")))) + arguments: ((template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "styled"))) + +((regex_pattern) @injection.content + (#set! injection.language "regex")) + +; ((comment) @_gql_comment +; (#eq? @_gql_comment "/* GraphQL */") +; (template_string) @injection.content +; (#set! injection.language "graphql")) +((template_string) @injection.content + (#lua-match? @injection.content "^`#graphql") + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "graphql")) + +; el.innerHTML = `<html>` +(assignment_expression + left: (member_expression + property: (property_identifier) @_prop + (#any-of? @_prop "outerHTML" "innerHTML")) + right: (template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "html")) + +; el.innerHTML = '<html>' +(assignment_expression + left: (member_expression + property: (property_identifier) @_prop + (#any-of? @_prop "outerHTML" "innerHTML")) + right: (string + (string_fragment) @injection.content) + (#set! injection.language "html")) + +;---- Angular injections ----- +; @Component({ +; template: `<html>` +; }) +(decorator + (call_expression + function: ((identifier) @_name + (#eq? @_name "Component")) + arguments: (arguments + (object + (pair + key: ((property_identifier) @_prop + (#eq? @_prop "template")) + value: ((template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "angular"))))))) + +; @Component({ +; styles: [`<css>`] +; }) +(decorator + (call_expression + function: ((identifier) @_name + (#eq? @_name "Component")) + arguments: (arguments + (object + (pair + key: ((property_identifier) @_prop + (#eq? @_prop "styles")) + value: (array + ((template_string) @injection.content + (#offset! @injection.content 0 1 0 -1) + (#set! injection.include-children) + (#set! injection.language "css")))))))) + +; @Component({ +; styles: `<css>` +; }) +(decorator + (call_expression + function: ((identifier) @_name + (#eq? @_name "Component")) + arguments: (arguments + (object + (pair + key: ((property_identifier) @_prop + (#eq? @_prop "styles")) + value: ((template_string) @injection.content + (#set! injection.include-children) + (#offset! @injection.content 0 1 0 -1) + (#set! injection.language "css"))))))) |
