File tree 4 files changed +150
-2
lines changed
src/compiler/phases/1-parse
4 files changed +150
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: improve script ` lang ` attribute detection
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import read_options from './read/options.js';
11
11
const regex_position_indicator = / \( \d + : \d + \) $ / ;
12
12
13
13
const regex_lang_attribute =
14
- / < ! - - [ ^ ] * ?- - > | < s c r i p t \s + (?: [ ^ > ] * | (?: [ ^ = > ' " / ] + = (?: " [ ^ " ] * " | ' [ ^ ' ] * ' | [ ^ > \s ] + ) \s + ) * ) l a n g = ( [ " ' ] ) ? ( [ ^ " ' > ] + ) \1[ ^ > ] * > / ;
14
+ / < ! - - [ ^ ] * ?- - > | < s c r i p t \s + (?: [ ^ > ] * | (?: [ ^ = > ' " / ] + = (?: " [ ^ " ] * " | ' [ ^ ' ] * ' | [ ^ > \s ] + ) \s + ) * ) l a n g = ( [ " ' ] ) ? ( [ ^ " ' > ] + ) \1[ ^ > ] * > / g ;
15
15
16
16
export class Parser {
17
17
/**
@@ -49,7 +49,14 @@ export class Parser {
49
49
50
50
this . template = template . trimRight ( ) ;
51
51
52
- this . ts = regex_lang_attribute . exec ( template ) ?. [ 2 ] === 'ts' ;
52
+ let match_lang ;
53
+
54
+ do match_lang = regex_lang_attribute . exec ( template ) ;
55
+ while ( match_lang && match_lang [ 0 ] [ 1 ] !== 's' ) ; // ensure it starts with '<s' to match script tags
56
+
57
+ regex_lang_attribute . lastIndex = 0 ; // reset matched index to pass tests - otherwise declare the regex inside the constructor
58
+
59
+ this . ts = match_lang ?. [ 2 ] === 'ts' ;
53
60
54
61
this . root = {
55
62
css : null ,
Original file line number Diff line number Diff line change
1
+ <!--should not error out-->
2
+ <script lang =" ts" >
3
+ let count: number ;
4
+ </script >
Original file line number Diff line number Diff line change
1
+ {
2
+ "css" : null ,
3
+ "js" : [],
4
+ "start" : 0 ,
5
+ "end" : 27 ,
6
+ "type" : " Root" ,
7
+ "fragment" : {
8
+ "type" : " Fragment" ,
9
+ "nodes" : [
10
+ {
11
+ "type" : " Comment" ,
12
+ "start" : 0 ,
13
+ "end" : 27 ,
14
+ "data" : " should not error out" ,
15
+ "ignores" : []
16
+ },
17
+ {
18
+ "type" : " Text" ,
19
+ "start" : 27 ,
20
+ "end" : 28 ,
21
+ "raw" : " \n " ,
22
+ "data" : " \n "
23
+ }
24
+ ],
25
+ "transparent" : false
26
+ },
27
+ "options" : null ,
28
+ "instance" : {
29
+ "type" : " Script" ,
30
+ "start" : 28 ,
31
+ "end" : 76 ,
32
+ "context" : " default" ,
33
+ "content" : {
34
+ "type" : " Program" ,
35
+ "start" : 46 ,
36
+ "end" : 67 ,
37
+ "loc" : {
38
+ "start" : {
39
+ "line" : 1 ,
40
+ "column" : 0
41
+ },
42
+ "end" : {
43
+ "line" : 4 ,
44
+ "column" : 0
45
+ }
46
+ },
47
+ "body" : [
48
+ {
49
+ "type" : " VariableDeclaration" ,
50
+ "start" : 48 ,
51
+ "end" : 66 ,
52
+ "loc" : {
53
+ "start" : {
54
+ "line" : 3 ,
55
+ "column" : 1
56
+ },
57
+ "end" : {
58
+ "line" : 3 ,
59
+ "column" : 19
60
+ }
61
+ },
62
+ "declarations" : [
63
+ {
64
+ "type" : " VariableDeclarator" ,
65
+ "start" : 52 ,
66
+ "end" : 65 ,
67
+ "loc" : {
68
+ "start" : {
69
+ "line" : 3 ,
70
+ "column" : 5
71
+ },
72
+ "end" : {
73
+ "line" : 3 ,
74
+ "column" : 18
75
+ }
76
+ },
77
+ "id" : {
78
+ "type" : " Identifier" ,
79
+ "start" : 52 ,
80
+ "end" : 18 ,
81
+ "loc" : {
82
+ "start" : {
83
+ "line" : 3 ,
84
+ "column" : 5
85
+ },
86
+ "end" : {
87
+ "line" : 3 ,
88
+ "column" : 18
89
+ }
90
+ },
91
+ "name" : " count" ,
92
+ "typeAnnotation" : {
93
+ "type" : " TSTypeAnnotation" ,
94
+ "start" : 57 ,
95
+ "end" : 65 ,
96
+ "loc" : {
97
+ "start" : {
98
+ "line" : 3 ,
99
+ "column" : 10
100
+ },
101
+ "end" : {
102
+ "line" : 3 ,
103
+ "column" : 18
104
+ }
105
+ },
106
+ "typeAnnotation" : {
107
+ "type" : " TSNumberKeyword" ,
108
+ "start" : 59 ,
109
+ "end" : 65 ,
110
+ "loc" : {
111
+ "start" : {
112
+ "line" : 3 ,
113
+ "column" : 12
114
+ },
115
+ "end" : {
116
+ "line" : 3 ,
117
+ "column" : 18
118
+ }
119
+ }
120
+ }
121
+ }
122
+ },
123
+ "init" : null
124
+ }
125
+ ],
126
+ "kind" : " let"
127
+ }
128
+ ],
129
+ "sourceType" : " module"
130
+ }
131
+ }
132
+ }
You can’t perform that action at this time.
0 commit comments