@@ -9,46 +9,6 @@ interface IVueHandlerOptions extends IJsHandlerOptions {
99 preserveScoped ?: boolean
1010}
1111
12- export async function vueHandler (
13- rawSource : string ,
14- options : IVueHandlerOptions ,
15- ) : Promise < IHandlerTransformResult > {
16- const { ctx, id } = options
17- const ms = new MagicString ( rawSource )
18-
19- try {
20- const { descriptor } = parse ( rawSource , {
21- filename : id || 'unknown.vue' ,
22- } )
23-
24- // Process template section
25- if ( descriptor . template ) {
26- await processTemplate ( descriptor . template , ms , ctx , id )
27- }
28-
29- // Process script section
30- if ( descriptor . script || descriptor . scriptSetup ) {
31- await processScript ( descriptor , ms , ctx , id )
32- }
33-
34- // Process style sections
35- if ( descriptor . styles && descriptor . styles . length > 0 ) {
36- await processStyles ( descriptor . styles , ms , ctx , id )
37- }
38-
39- return {
40- code : ms . toString ( ) ,
41- get map ( ) {
42- return ms . generateMap ( )
43- } ,
44- }
45- }
46- catch ( error ) {
47- // Fallback to jsHandler if Vue parsing fails
48- return jsHandler ( rawSource , options )
49- }
50- }
51-
5212async function processTemplate (
5313 template : any ,
5414 ms : MagicString ,
@@ -59,7 +19,7 @@ async function processTemplate(
5919
6020 if ( ! template . ast ) {
6121 try {
62- const compiled = compileTemplate ( {
22+ compileTemplate ( {
6323 source : template . content ,
6424 filename : id || 'unknown.vue' ,
6525 id : `${ id || 'unknown' } ?template` ,
@@ -74,7 +34,6 @@ async function processTemplate(
7434
7535 // Process static class attributes in template
7636 const classAttrRegex = / \s c l a s s \s * = \s * [ " ' ] ( [ ^ " ' ] + ) [ " ' ] / g
77- let match
7837
7938 // We need to search within the template section
8039 const templateStart = template . loc . start . offset
@@ -83,7 +42,7 @@ async function processTemplate(
8342
8443 const replacements : Array < { start : number , end : number , value : string } > = [ ]
8544
86- while ( ( match = classAttrRegex . exec ( templateContent ) ) !== null ) {
45+ for ( const match of templateContent . matchAll ( classAttrRegex ) ) {
8746 const fullMatch = match [ 0 ]
8847 const classValue = match [ 1 ]
8948 if ( classValue === undefined ) {
@@ -129,7 +88,9 @@ async function processScript(
12988 id ?: string ,
13089) : Promise < void > {
13190 const script = descriptor . scriptSetup || descriptor . script
132- if ( ! script ) { return }
91+ if ( ! script ) {
92+ return
93+ }
13394
13495 const scriptContent = ms . original . slice (
13596 script . loc . start . offset ,
@@ -173,3 +134,43 @@ async function processStyles(
173134 }
174135 }
175136}
137+
138+ export async function vueHandler (
139+ rawSource : string ,
140+ options : IVueHandlerOptions ,
141+ ) : Promise < IHandlerTransformResult > {
142+ const { ctx, id } = options
143+ const ms = new MagicString ( rawSource )
144+
145+ try {
146+ const { descriptor } = parse ( rawSource , {
147+ filename : id || 'unknown.vue' ,
148+ } )
149+
150+ // Process template section
151+ if ( descriptor . template ) {
152+ await processTemplate ( descriptor . template , ms , ctx , id )
153+ }
154+
155+ // Process script section
156+ if ( descriptor . script || descriptor . scriptSetup ) {
157+ await processScript ( descriptor , ms , ctx , id )
158+ }
159+
160+ // Process style sections
161+ if ( descriptor . styles && descriptor . styles . length > 0 ) {
162+ await processStyles ( descriptor . styles , ms , ctx , id )
163+ }
164+
165+ return {
166+ code : ms . toString ( ) ,
167+ get map ( ) {
168+ return ms . generateMap ( )
169+ } ,
170+ }
171+ }
172+ catch {
173+ // Fallback to jsHandler if Vue parsing fails
174+ return jsHandler ( rawSource , options )
175+ }
176+ }
0 commit comments