@@ -81,6 +81,17 @@ let vueStates = {
8181 } ,
8282 html : {
8383 htmlBlockEnd : { match : '</template>' , pop : 1 } ,
84+ nestedBlockStart : { match : '<template' , push : 'nestedBlock' } ,
85+ ...text ,
86+ } ,
87+ nestedBlock : {
88+ nestedStart : { match : '>' , next : 'nested' } ,
89+ nestedBlockEnd : { match : '/>' , pop : 1 } ,
90+ ...text ,
91+ } ,
92+ nested : {
93+ nestedBlockEnd : { match : '</template>' , pop : 1 } ,
94+ nestedBlockStart : { match : '<template' , push : 'nestedBlock' } ,
8495 ...text ,
8596 } ,
8697}
@@ -124,19 +135,21 @@ export function getLanguageBoundaries(
124135
125136 try {
126137 for ( let token of lexer ) {
127- if ( token . type . endsWith ( 'BlockStart' ) ) {
128- let position = indexToPosition ( text , offset )
129- if ( ! boundaries [ boundaries . length - 1 ] . range . end ) {
138+ if ( ! token . type . startsWith ( 'nested' ) ) {
139+ if ( token . type . endsWith ( 'BlockStart' ) ) {
140+ let position = indexToPosition ( text , offset )
141+ if ( ! boundaries [ boundaries . length - 1 ] . range . end ) {
142+ boundaries [ boundaries . length - 1 ] . range . end = position
143+ }
144+ type = token . type . replace ( / B l o c k S t a r t $ / , '' )
145+ boundaries . push ( { type, range : { start : position , end : undefined } } )
146+ } else if ( token . type . endsWith ( 'BlockEnd' ) ) {
147+ let position = indexToPosition ( text , offset )
130148 boundaries [ boundaries . length - 1 ] . range . end = position
149+ boundaries . push ( { type : defaultType , range : { start : position , end : undefined } } )
150+ } else if ( token . type === 'lang' ) {
151+ boundaries [ boundaries . length - 1 ] . type = token . text
131152 }
132- type = token . type . replace ( / B l o c k S t a r t $ / , '' )
133- boundaries . push ( { type, range : { start : position , end : undefined } } )
134- } else if ( token . type . endsWith ( 'BlockEnd' ) ) {
135- let position = indexToPosition ( text , offset )
136- boundaries [ boundaries . length - 1 ] . range . end = position
137- boundaries . push ( { type : defaultType , range : { start : position , end : undefined } } )
138- } else if ( token . type === 'lang' ) {
139- boundaries [ boundaries . length - 1 ] . type = token . text
140153 }
141154 offset += token . text . length
142155 }
0 commit comments