File tree 9 files changed +396
-2
lines changed
tests/parser-modern/samples 9 files changed +396
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " svelte " : patch
3
+ ---
4
+
5
+ fix: correct start of ` {:else if} ` and ` {:else} `
Original file line number Diff line number Diff line change @@ -353,11 +353,12 @@ export function convert(source, ast) {
353
353
} ;
354
354
}
355
355
356
+ const start = node . elseif ? node . consequent . nodes [ 0 ] . start : node . start ;
356
357
remove_surrounding_whitespace_nodes ( node . consequent . nodes ) ;
357
358
358
359
return {
359
360
type : 'IfBlock' ,
360
- start : node . start ,
361
+ start,
361
362
end : node . end ,
362
363
expression : node . test ,
363
364
children : node . consequent . nodes . map (
Original file line number Diff line number Diff line change @@ -345,7 +345,7 @@ function next(parser) {
345
345
346
346
/** @type {ReturnType<typeof parser.append<import('#compiler').IfBlock>> } */
347
347
const child = parser . append ( {
348
- start : parser . index ,
348
+ start : start - 1 ,
349
349
end : - 1 ,
350
350
type : 'IfBlock' ,
351
351
elseif : true ,
Original file line number Diff line number Diff line change
1
+ {#if foo }
2
+ <p >foo</p >
3
+ {:else }
4
+ <p >not foo</p >
5
+ {/if }
Original file line number Diff line number Diff line change
1
+ {
2
+ "css" : null ,
3
+ "js" : [],
4
+ "start" : 0 ,
5
+ "end" : 51 ,
6
+ "type" : " Root" ,
7
+ "fragment" : {
8
+ "type" : " Fragment" ,
9
+ "nodes" : [
10
+ {
11
+ "type" : " IfBlock" ,
12
+ "elseif" : false ,
13
+ "start" : 0 ,
14
+ "end" : 51 ,
15
+ "test" : {
16
+ "type" : " Identifier" ,
17
+ "start" : 5 ,
18
+ "end" : 8 ,
19
+ "loc" : {
20
+ "start" : {
21
+ "line" : 1 ,
22
+ "column" : 5
23
+ },
24
+ "end" : {
25
+ "line" : 1 ,
26
+ "column" : 8
27
+ }
28
+ },
29
+ "name" : " foo"
30
+ },
31
+ "consequent" : {
32
+ "type" : " Fragment" ,
33
+ "nodes" : [
34
+ {
35
+ "type" : " Text" ,
36
+ "start" : 9 ,
37
+ "end" : 11 ,
38
+ "raw" : " \n\t " ,
39
+ "data" : " \n\t "
40
+ },
41
+ {
42
+ "type" : " RegularElement" ,
43
+ "start" : 11 ,
44
+ "end" : 21 ,
45
+ "name" : " p" ,
46
+ "attributes" : [],
47
+ "fragment" : {
48
+ "type" : " Fragment" ,
49
+ "nodes" : [
50
+ {
51
+ "type" : " Text" ,
52
+ "start" : 14 ,
53
+ "end" : 17 ,
54
+ "raw" : " foo" ,
55
+ "data" : " foo"
56
+ }
57
+ ],
58
+ "transparent" : true
59
+ }
60
+ },
61
+ {
62
+ "type" : " Text" ,
63
+ "start" : 21 ,
64
+ "end" : 22 ,
65
+ "raw" : " \n " ,
66
+ "data" : " \n "
67
+ }
68
+ ],
69
+ "transparent" : false
70
+ },
71
+ "alternate" : {
72
+ "type" : " Fragment" ,
73
+ "nodes" : [
74
+ {
75
+ "type" : " Text" ,
76
+ "start" : 29 ,
77
+ "end" : 31 ,
78
+ "raw" : " \n\t " ,
79
+ "data" : " \n\t "
80
+ },
81
+ {
82
+ "type" : " RegularElement" ,
83
+ "start" : 31 ,
84
+ "end" : 45 ,
85
+ "name" : " p" ,
86
+ "attributes" : [],
87
+ "fragment" : {
88
+ "type" : " Fragment" ,
89
+ "nodes" : [
90
+ {
91
+ "type" : " Text" ,
92
+ "start" : 34 ,
93
+ "end" : 41 ,
94
+ "raw" : " not foo" ,
95
+ "data" : " not foo"
96
+ }
97
+ ],
98
+ "transparent" : true
99
+ }
100
+ },
101
+ {
102
+ "type" : " Text" ,
103
+ "start" : 45 ,
104
+ "end" : 46 ,
105
+ "raw" : " \n " ,
106
+ "data" : " \n "
107
+ }
108
+ ],
109
+ "transparent" : false
110
+ }
111
+ }
112
+ ],
113
+ "transparent" : false
114
+ },
115
+ "options" : null
116
+ }
Original file line number Diff line number Diff line change
1
+ {#if x > 10 }
2
+ <p >x is greater than 10</p >
3
+ {:else if x < 5 }
4
+ <p >x is less than 5</p >
5
+ {/if }
Original file line number Diff line number Diff line change
1
+ {
2
+ "css" : null ,
3
+ "js" : [],
4
+ "start" : 0 ,
5
+ "end" : 89 ,
6
+ "type" : " Root" ,
7
+ "fragment" : {
8
+ "type" : " Fragment" ,
9
+ "nodes" : [
10
+ {
11
+ "type" : " IfBlock" ,
12
+ "elseif" : false ,
13
+ "start" : 0 ,
14
+ "end" : 89 ,
15
+ "test" : {
16
+ "type" : " BinaryExpression" ,
17
+ "start" : 5 ,
18
+ "end" : 11 ,
19
+ "loc" : {
20
+ "start" : {
21
+ "line" : 1 ,
22
+ "column" : 5
23
+ },
24
+ "end" : {
25
+ "line" : 1 ,
26
+ "column" : 11
27
+ }
28
+ },
29
+ "left" : {
30
+ "type" : " Identifier" ,
31
+ "start" : 5 ,
32
+ "end" : 6 ,
33
+ "loc" : {
34
+ "start" : {
35
+ "line" : 1 ,
36
+ "column" : 5
37
+ },
38
+ "end" : {
39
+ "line" : 1 ,
40
+ "column" : 6
41
+ }
42
+ },
43
+ "name" : " x"
44
+ },
45
+ "operator" : " >" ,
46
+ "right" : {
47
+ "type" : " Literal" ,
48
+ "start" : 9 ,
49
+ "end" : 11 ,
50
+ "loc" : {
51
+ "start" : {
52
+ "line" : 1 ,
53
+ "column" : 9
54
+ },
55
+ "end" : {
56
+ "line" : 1 ,
57
+ "column" : 11
58
+ }
59
+ },
60
+ "value" : 10 ,
61
+ "raw" : " 10"
62
+ }
63
+ },
64
+ "consequent" : {
65
+ "type" : " Fragment" ,
66
+ "nodes" : [
67
+ {
68
+ "type" : " Text" ,
69
+ "start" : 12 ,
70
+ "end" : 14 ,
71
+ "raw" : " \n\t " ,
72
+ "data" : " \n\t "
73
+ },
74
+ {
75
+ "type" : " RegularElement" ,
76
+ "start" : 14 ,
77
+ "end" : 41 ,
78
+ "name" : " p" ,
79
+ "attributes" : [],
80
+ "fragment" : {
81
+ "type" : " Fragment" ,
82
+ "nodes" : [
83
+ {
84
+ "type" : " Text" ,
85
+ "start" : 17 ,
86
+ "end" : 37 ,
87
+ "raw" : " x is greater than 10" ,
88
+ "data" : " x is greater than 10"
89
+ }
90
+ ],
91
+ "transparent" : true
92
+ }
93
+ },
94
+ {
95
+ "type" : " Text" ,
96
+ "start" : 41 ,
97
+ "end" : 42 ,
98
+ "raw" : " \n " ,
99
+ "data" : " \n "
100
+ }
101
+ ],
102
+ "transparent" : false
103
+ },
104
+ "alternate" : {
105
+ "type" : " Fragment" ,
106
+ "nodes" : [
107
+ {
108
+ "start" : 42 ,
109
+ "end" : 89 ,
110
+ "type" : " IfBlock" ,
111
+ "elseif" : true ,
112
+ "test" : {
113
+ "type" : " BinaryExpression" ,
114
+ "start" : 52 ,
115
+ "end" : 57 ,
116
+ "loc" : {
117
+ "start" : {
118
+ "line" : 3 ,
119
+ "column" : 10
120
+ },
121
+ "end" : {
122
+ "line" : 3 ,
123
+ "column" : 15
124
+ }
125
+ },
126
+ "left" : {
127
+ "type" : " Identifier" ,
128
+ "start" : 52 ,
129
+ "end" : 53 ,
130
+ "loc" : {
131
+ "start" : {
132
+ "line" : 3 ,
133
+ "column" : 10
134
+ },
135
+ "end" : {
136
+ "line" : 3 ,
137
+ "column" : 11
138
+ }
139
+ },
140
+ "name" : " x"
141
+ },
142
+ "operator" : " <" ,
143
+ "right" : {
144
+ "type" : " Literal" ,
145
+ "start" : 56 ,
146
+ "end" : 57 ,
147
+ "loc" : {
148
+ "start" : {
149
+ "line" : 3 ,
150
+ "column" : 14
151
+ },
152
+ "end" : {
153
+ "line" : 3 ,
154
+ "column" : 15
155
+ }
156
+ },
157
+ "value" : 5 ,
158
+ "raw" : " 5"
159
+ }
160
+ },
161
+ "consequent" : {
162
+ "type" : " Fragment" ,
163
+ "nodes" : [
164
+ {
165
+ "type" : " Text" ,
166
+ "start" : 58 ,
167
+ "end" : 60 ,
168
+ "raw" : " \n\t " ,
169
+ "data" : " \n\t "
170
+ },
171
+ {
172
+ "type" : " RegularElement" ,
173
+ "start" : 60 ,
174
+ "end" : 83 ,
175
+ "name" : " p" ,
176
+ "attributes" : [],
177
+ "fragment" : {
178
+ "type" : " Fragment" ,
179
+ "nodes" : [
180
+ {
181
+ "type" : " Text" ,
182
+ "start" : 63 ,
183
+ "end" : 79 ,
184
+ "raw" : " x is less than 5" ,
185
+ "data" : " x is less than 5"
186
+ }
187
+ ],
188
+ "transparent" : true
189
+ }
190
+ },
191
+ {
192
+ "type" : " Text" ,
193
+ "start" : 83 ,
194
+ "end" : 84 ,
195
+ "raw" : " \n " ,
196
+ "data" : " \n "
197
+ }
198
+ ],
199
+ "transparent" : false
200
+ },
201
+ "alternate" : null
202
+ }
203
+ ],
204
+ "transparent" : false
205
+ }
206
+ }
207
+ ],
208
+ "transparent" : false
209
+ },
210
+ "options" : null
211
+ }
Original file line number Diff line number Diff line change
1
+ {#if foo }bar{/if }
You can’t perform that action at this time.
0 commit comments