-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow custom preprocessors for 'vue' injections #5268
Allow custom preprocessors for 'vue' injections #5268
Conversation
runtime/queries/vue/injections.scm
Outdated
; <script> | ||
((script_element | ||
(raw_text) @injection.content) | ||
(#set! injection.language "javascript")) | ||
(start_tag) @_no_lang | ||
(raw_text) @injection.content) | ||
(#not-match? @_no_lang "lang=") | ||
(#set! injection.language "javascript")) | ||
|
||
; <script lang="js|javascript"> | ||
((script_element | ||
(start_tag (attribute (quoted_attribute_value (attribute_value) @_lang))) | ||
(raw_text) @injection.content) | ||
(#match? @_lang "^(js|javascript)$") | ||
(#set! injection.language "javascript")) | ||
|
||
; <script lang="ts|typescript"> | ||
((script_element | ||
(start_tag (attribute (quoted_attribute_value (attribute_value) @_lang))) | ||
(raw_text) @injection.content) | ||
(#match? @_lang "^(ts|typescript)$") | ||
(#set! injection.language "typescript")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be a little cleaner by matching on the attribute_name
:
((script_element
(start_tag
(attribute
(attribute_name) @_attr_name
(quoted_attribute_value (attribute_value) @injection.language)))
(raw_text) @injection.content)
(#eq? @_attr_name "lang"))
((script_element (raw_text) @injection.content)
(#set! injection.language "javascript"))
and similar for the style tags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@the-mikedavis thanks! that is much better. i totally forgot about injection-regex.
i am not sure if you intended this...
((script_element (raw_text) @injection.content)
(#set! injection.language "javascript"))
to act as a fallback for the no-lang case. that doesn't seem to work. it just overwrites the language to js because it will match any form of script tag.
i left in the no-lang query but updated the script/style matches with the lang attribute.
Changes the injections for Vue
script
andstyle
tags to allow for custom preprocessors. Before they were hardcoded to plainjavascript
andcss
.Vue tooling can specify a preprocessor via the
lang
attribute.This only adds injections for languages that helix already supports.
e.g.
<script lang="typescript">
or very commonly used
<style lang="scss">