@@ -33,19 +33,23 @@ function parseAttributes(str: string, start: number) {
33
33
}
34
34
35
35
function extractTag ( htmlx : string , tag : 'script' | 'style' ) {
36
- const exp = new RegExp ( `(<${ tag } ([\\S\\s]*?)>)([\\S\\s]*?)<\\/${ tag } >` , 'g' ) ;
36
+ const exp = new RegExp ( `(<!--[^]*?-->)|(< ${ tag } ([\\S\\s]*?)>)([\\S\\s]*?)<\\/${ tag } >` , 'g' ) ;
37
37
const matches : Node [ ] = [ ] ;
38
38
39
39
let match : RegExpExecArray | null = null ;
40
40
while ( ( match = exp . exec ( htmlx ) ) != null ) {
41
- const content = match [ 3 ] ;
41
+ if ( match [ 0 ] . startsWith ( '<!--' ) ) {
42
+ // Tag is inside comment
43
+ continue ;
44
+ }
42
45
46
+ const content = match [ 4 ] ;
43
47
if ( ! content ) {
44
48
// Self-closing/empty tags don't need replacement
45
49
continue ;
46
50
}
47
51
48
- const start = match . index + match [ 1 ] . length ;
52
+ const start = match . index + match [ 2 ] . length ;
49
53
const end = start + content . length ;
50
54
const containerStart = match . index ;
51
55
const containerEnd = match . index + match [ 0 ] . length ;
@@ -55,7 +59,7 @@ function extractTag(htmlx: string, tag: 'script' | 'style') {
55
59
end : containerEnd ,
56
60
name : tag ,
57
61
type : tag === 'style' ? 'Style' : 'Script' ,
58
- attributes : parseAttributes ( match [ 2 ] , containerStart + `<${ tag } ` . length ) ,
62
+ attributes : parseAttributes ( match [ 3 ] , containerStart + `<${ tag } ` . length ) ,
59
63
content : {
60
64
type : 'Text' ,
61
65
start,
0 commit comments