injections(html): fix faulty css/js injections

Group queries to reduce duplicate injection tree

use only regex
This commit is contained in:
Pham Huy Hoang 2023-03-03 09:09:52 +07:00 committed by ObserverOfTime
parent 3731cf1c0c
commit d11dd552db
3 changed files with 17 additions and 27 deletions

View file

@ -1,22 +1,12 @@
; <style>...</style>
(
(style_element
(start_tag
(tag_name) .)
(raw_text) @css)
)
; <style blocking> ...</style>
; Add "lang" to predicate check so that vue/svelte can inherit this
; without having this element being captured twice
(
(style_element
(start_tag
(attribute
(attribute_name) @_no_set_type))
(raw_text) @css)
(#not-any-of? @_no_set_type "type" "lang")
)
(start_tag) @_no_type_lang
(#not-match? @_no_type_lang "\\s(lang|type)\\s*\\=")
(raw_text) @css))
(
(style_element
@ -30,22 +20,12 @@
)
; <script>...</script>
(
(script_element
(start_tag
(tag_name) .)
(raw_text) @javascript)
)
; <script defer>...</script>
(
(script_element
(start_tag
(attribute
(attribute_name) @_no_set_type))
(raw_text) @javascript)
(#not-any-of? @_no_set_type "type" "lang")
)
(start_tag) @_no_type_lang
(#not-match? @_no_type_lang "\\s(lang|type)\\s*\\=")
(raw_text) @javascript))
(
(script_element
@ -55,7 +35,7 @@
(quoted_attribute_value (attribute_value) @_javascript)))
(raw_text) @javascript)
(#eq? @_type "type")
(#eq? @_javascript "text/javascript")
(#any-of? @_javascript "text/javascript" "module")
)
((attribute

View file

@ -19,6 +19,10 @@
<!-- ^ javascript -->
<script type="text/javascript"> const x = 1 </script>
<!-- ^ javascript -->
<script type="module"> import { foo } from "bar" </script>
<!-- ^ javascript -->
<script defer type="text/javascript"> const x = 1 </script>
<!-- ^ javascript -->
<div style="height: 100%">
<!-- ^ css -->
Test div to test css injections for style attributes

View file

@ -17,6 +17,9 @@
<script lang="ts"> const foo: number = "1" </script>
<!-- ^ typescript -->
<!-- ^ !javascript -->
<script lang="ts" defer>const foo: number = 1 </script>
<!-- ^ typescript -->
<!-- ^ !javascript -->
<style> .bar { .foo{ } } </style>
<!-- ^ css -->
<style scoped> .page.page--news { background: rebeccapurple; } </style>
@ -26,3 +29,6 @@
<style lang="scss"> .bar { &-baz { } } </style>
<!-- ^ scss -->
<!-- ^ !css -->
<style scoped lang="scss">body{} </style>
<!-- ^ scss -->
<!-- ^ !css -->