@@ -7,7 +7,16 @@ import moo from 'moo'
7
7
import Cache from 'tmp-cache'
8
8
import { getTextWithoutComments } from './doc'
9
9
10
- export type LanguageBoundary = { type : 'html' | 'js' | 'css' | string ; range : Range }
10
+ export type LanguageBoundary = { type : 'html' | 'js' | 'css' | ( string & { } ) ; range : Range }
11
+
12
+ let htmlScriptTypes = [
13
+ // https://v3-migration.vuejs.org/breaking-changes/inline-template-attribute.html#option-1-use-script-tag
14
+ 'text/html' ,
15
+ // https://vuejs.org/guide/essentials/component-basics.html#dom-template-parsing-caveats
16
+ 'text/x-template' ,
17
+ // https://github.com/tailwindlabs/tailwindcss-intellisense/issues/722
18
+ 'text/x-handlebars-template' ,
19
+ ]
11
20
12
21
let text = { text : { match : / [ ^ ] / , lineBreaks : true } }
13
22
@@ -30,6 +39,8 @@ let states = {
30
39
jsBlockEnd : { match : '/>' , pop : 1 } ,
31
40
langAttrStartDouble : { match : 'lang="' , push : 'langAttrDouble' } ,
32
41
langAttrStartSingle : { match : "lang='" , push : 'langAttrSingle' } ,
42
+ typeAttrStartDouble : { match : 'type="' , push : 'typeAttrDouble' } ,
43
+ typeAttrStartSingle : { match : "type='" , push : 'typeAttrSingle' } ,
33
44
attrStartDouble : { match : '"' , push : 'attrDouble' } ,
34
45
attrStartSingle : { match : "'" , push : 'attrSingle' } ,
35
46
interp : { match : '{' , push : 'interp' } ,
@@ -48,6 +59,14 @@ let states = {
48
59
langAttrEnd : { match : "'" , pop : 1 } ,
49
60
lang : { match : / [ ^ ' ] + / , lineBreaks : true } ,
50
61
} ,
62
+ typeAttrDouble : {
63
+ langAttrEnd : { match : '"' , pop : 1 } ,
64
+ type : { match : / [ ^ " ] + / , lineBreaks : true } ,
65
+ } ,
66
+ typeAttrSingle : {
67
+ langAttrEnd : { match : "'" , pop : 1 } ,
68
+ type : { match : / [ ^ ' ] + / , lineBreaks : true } ,
69
+ } ,
51
70
attrDouble : {
52
71
attrEnd : { match : '"' , pop : 1 } ,
53
72
...text ,
@@ -156,6 +175,8 @@ export function getLanguageBoundaries(
156
175
boundaries . push ( { type : defaultType , range : { start : position , end : undefined } } )
157
176
} else if ( token . type === 'lang' ) {
158
177
boundaries [ boundaries . length - 1 ] . type = token . text
178
+ } else if ( token . type === 'type' && htmlScriptTypes . includes ( token . text ) ) {
179
+ boundaries [ boundaries . length - 1 ] . type = 'html'
159
180
}
160
181
}
161
182
offset += token . text . length
0 commit comments