feat(vue): add tsx/jsx injection queries (#4550)

* feat(vue): add tsx/jsx injection queries

- add a test

- style: format vue/injections.scm
This commit is contained in:
Lucario387 2023-03-24 23:38:19 +09:00 committed by GitHub
parent 17a81d7b35
commit c7b9f68d03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 30 deletions

View file

@ -1,53 +1,55 @@
; inherits html_tags ; inherits html_tags
; <script lang="css"> ; <script lang="css">
( ((style_element
(style_element
(start_tag (start_tag
(attribute (attribute
(attribute_name) @_lang (attribute_name) @_lang
(quoted_attribute_value (attribute_value) @_css))) (quoted_attribute_value (attribute_value) @_css)))
(raw_text) @css) (#eq? @_lang "lang")
(#eq? @_lang "lang") (#eq? @_css "css")
(#eq? @_css "css") (raw_text) @css))
)
; TODO: When nvim-treesitter have postcss and less parser, use @language and @content instead ; TODO: When nvim-treesitter have postcss and less parser, use @language and @content instead
; <script lang="scss"> ; <script lang="scss">
( ((style_element
(style_element
(start_tag (start_tag
(attribute (attribute
(attribute_name) @_lang (attribute_name) @_lang
(quoted_attribute_value (attribute_value) @_scss))) (quoted_attribute_value (attribute_value) @_scss)))
(raw_text) @scss) (#eq? @_lang "lang")
(#eq? @_lang "lang") (#any-of? @_scss "scss" "less" "postcss")
(#any-of? @_scss "scss" "less" "postcss") (raw_text) @scss))
)
; <script lang="js"> ; <script lang="js">
( ((script_element
(script_element
(start_tag (start_tag
(attribute (attribute
(attribute_name) @_lang (attribute_name) @_lang
(quoted_attribute_value (attribute_value) @_js))) (quoted_attribute_value (attribute_value) @_js)))
(raw_text) @javascript) (#eq? @_lang "lang")
(#eq? @_lang "lang") (#eq? @_js "js")
(#eq? @_js "js") (raw_text) @javascript))
)
; <script lang="ts"> ; <script lang="ts">
( ((script_element
(script_element
(start_tag (start_tag
(attribute (attribute
(attribute_name) @_lang (attribute_name) @_lang
(quoted_attribute_value (attribute_value) @_ts))) (quoted_attribute_value (attribute_value) @_ts)))
(raw_text) @typescript) (#eq? @_lang "lang")
(#eq? @_lang "lang") (#eq? @_ts "ts")
(#eq? @_ts "ts") (raw_text) @typescript))
)
; <script lang="tsx">
; <script lang="jsx">
((script_element
(start_tag
(attribute
(attribute_name) @_attr
(quoted_attribute_value (attribute_value) @language)))
(#eq? @_attr "lang")
(#any-of? @language "tsx" "jsx")
(raw_text) @content))
((interpolation ((interpolation
(raw_text) @javascript)) (raw_text) @javascript))
@ -56,11 +58,9 @@
(quoted_attribute_value (quoted_attribute_value
(attribute_value) @javascript))) (attribute_value) @javascript)))
( ((template_element
(template_element
(start_tag (start_tag
(attribute (attribute
(quoted_attribute_value (attribute_value) @_lang))) (quoted_attribute_value (attribute_value) @_lang)))
(text) @pug) (#eq? @_lang "pug")
(#eq? @_lang "pug") (text) @pug))
)

View file

@ -20,6 +20,10 @@
<script lang="ts" defer>const foo: number = 1 </script> <script lang="ts" defer>const foo: number = 1 </script>
<!-- ^ typescript --> <!-- ^ typescript -->
<!-- ^ !javascript --> <!-- ^ !javascript -->
<script lang="tsx" defer>const foo: number = 1</script>
<!-- ^ tsx -->
<!-- ^ !jsx -->
<!-- ^ !typescript -->
<style> .bar { .foo{ } } </style> <style> .bar { .foo{ } } </style>
<!-- ^ css --> <!-- ^ css -->
<style scoped> .page.page--news { background: rebeccapurple; } </style> <style scoped> .page.page--news { background: rebeccapurple; } </style>