File tree Expand file tree Collapse file tree 5 files changed +247
-92
lines changed
src/compiler/phases/1-parse/state
parser-legacy/samples/loose-unclosed-tag
parser-modern/samples/loose-unclosed-tag Expand file tree Collapse file tree 5 files changed +247
-92
lines changed Original file line number Diff line number Diff line change @@ -123,8 +123,11 @@ export default function element(parser) {
123123 }
124124
125125 if ( ! regex_valid_element_name . test ( name ) && ! regex_valid_component_name . test ( name ) ) {
126- const bounds = { start : start + 1 , end : start + 1 + name . length } ;
127- e . tag_invalid_name ( bounds ) ;
126+ // <div. -> in the middle of typing -> allow in loose mode
127+ if ( ! parser . loose || ! name . endsWith ( '.' ) ) {
128+ const bounds = { start : start + 1 , end : start + 1 + name . length } ;
129+ e . tag_invalid_name ( bounds ) ;
130+ }
128131 }
129132
130133 if ( root_only_meta_tags . has ( name ) ) {
@@ -141,7 +144,7 @@ export default function element(parser) {
141144
142145 const type = meta_tags . has ( name )
143146 ? meta_tags . get ( name )
144- : regex_valid_component_name . test ( name )
147+ : regex_valid_component_name . test ( name ) || ( parser . loose && name . endsWith ( '.' ) )
145148 ? 'Component'
146149 : name === 'title' && parent_is_head ( parser . stack )
147150 ? 'TitleElement'
Original file line number Diff line number Diff line change 1010 <span
1111</div >
1212
13+ <div >
14+ <Comp .
15+ </div >
16+
17+ <div >
18+ <comp .
19+ </div >
20+
1321{#if foo }
1422 <div >
1523{/if }
Original file line number Diff line number Diff line change 22 "html" : {
33 "type" : " Fragment" ,
44 "start" : 0 ,
5- "end" : 160 ,
5+ "end" : 204 ,
66 "children" : [
77 {
88 "type" : " Element" ,
136136 "data" : " \n\n "
137137 },
138138 {
139- "type" : " IfBlock " ,
139+ "type" : " Element " ,
140140 "start" : 74 ,
141+ "end" : 94 ,
142+ "name" : " div" ,
143+ "attributes" : [],
144+ "children" : [
145+ {
146+ "type" : " Text" ,
147+ "start" : 79 ,
148+ "end" : 81 ,
149+ "raw" : " \n\t " ,
150+ "data" : " \n\t "
151+ },
152+ {
153+ "type" : " InlineComponent" ,
154+ "start" : 81 ,
155+ "end" : 88 ,
156+ "name" : " Comp." ,
157+ "attributes" : [],
158+ "children" : []
159+ }
160+ ]
161+ },
162+ {
163+ "type" : " Text" ,
164+ "start" : 94 ,
141165 "end" : 96 ,
166+ "raw" : " \n\n " ,
167+ "data" : " \n\n "
168+ },
169+ {
170+ "type" : " Element" ,
171+ "start" : 96 ,
172+ "end" : 116 ,
173+ "name" : " div" ,
174+ "attributes" : [],
175+ "children" : [
176+ {
177+ "type" : " Text" ,
178+ "start" : 101 ,
179+ "end" : 103 ,
180+ "raw" : " \n\t " ,
181+ "data" : " \n\t "
182+ },
183+ {
184+ "type" : " InlineComponent" ,
185+ "start" : 103 ,
186+ "end" : 110 ,
187+ "name" : " comp." ,
188+ "attributes" : [],
189+ "children" : []
190+ }
191+ ]
192+ },
193+ {
194+ "type" : " Text" ,
195+ "start" : 116 ,
196+ "end" : 118 ,
197+ "raw" : " \n\n " ,
198+ "data" : " \n\n "
199+ },
200+ {
201+ "type" : " IfBlock" ,
202+ "start" : 118 ,
203+ "end" : 140 ,
142204 "expression" : {
143205 "type" : " Identifier" ,
144- "start" : 79 ,
145- "end" : 82 ,
206+ "start" : 123 ,
207+ "end" : 126 ,
146208 "loc" : {
147209 "start" : {
148- "line" : 13 ,
210+ "line" : 21 ,
149211 "column" : 5
150212 },
151213 "end" : {
152- "line" : 13 ,
214+ "line" : 21 ,
153215 "column" : 8
154216 }
155217 },
158220 "children" : [
159221 {
160222 "type" : " Element" ,
161- "start" : 85 ,
162- "end" : 91 ,
223+ "start" : 129 ,
224+ "end" : 135 ,
163225 "name" : " div" ,
164226 "attributes" : [],
165227 "children" : [
166228 {
167229 "type" : " Text" ,
168- "start" : 90 ,
169- "end" : 91 ,
230+ "start" : 134 ,
231+ "end" : 135 ,
170232 "raw" : " \n " ,
171233 "data" : " \n "
172234 }
176238 },
177239 {
178240 "type" : " Text" ,
179- "start" : 96 ,
180- "end" : 98 ,
241+ "start" : 140 ,
242+ "end" : 142 ,
181243 "raw" : " \n\n " ,
182244 "data" : " \n\n "
183245 },
184246 {
185247 "type" : " IfBlock" ,
186- "start" : 98 ,
187- "end" : 130 ,
248+ "start" : 142 ,
249+ "end" : 174 ,
188250 "expression" : {
189251 "type" : " Identifier" ,
190- "start" : 103 ,
191- "end" : 106 ,
252+ "start" : 147 ,
253+ "end" : 150 ,
192254 "loc" : {
193255 "start" : {
194- "line" : 17 ,
256+ "line" : 25 ,
195257 "column" : 5
196258 },
197259 "end" : {
198- "line" : 17 ,
260+ "line" : 25 ,
199261 "column" : 8
200262 }
201263 },
204266 "children" : [
205267 {
206268 "type" : " InlineComponent" ,
207- "start" : 109 ,
208- "end" : 125 ,
269+ "start" : 153 ,
270+ "end" : 169 ,
209271 "name" : " Comp" ,
210272 "attributes" : [
211273 {
212274 "type" : " Attribute" ,
213- "start" : 115 ,
214- "end" : 124 ,
275+ "start" : 159 ,
276+ "end" : 168 ,
215277 "name" : " foo" ,
216278 "value" : [
217279 {
218280 "type" : " MustacheTag" ,
219- "start" : 119 ,
220- "end" : 124 ,
281+ "start" : 163 ,
282+ "end" : 168 ,
221283 "expression" : {
222284 "type" : " Identifier" ,
223- "start" : 120 ,
224- "end" : 123 ,
285+ "start" : 164 ,
286+ "end" : 167 ,
225287 "loc" : {
226288 "start" : {
227- "line" : 18 ,
289+ "line" : 26 ,
228290 "column" : 12
229291 },
230292 "end" : {
231- "line" : 18 ,
293+ "line" : 26 ,
232294 "column" : 15
233295 }
234296 },
244306 },
245307 {
246308 "type" : " Text" ,
247- "start" : 130 ,
248- "end" : 132 ,
309+ "start" : 174 ,
310+ "end" : 176 ,
249311 "raw" : " \n\n " ,
250312 "data" : " \n\n "
251313 },
252314 {
253315 "type" : " Element" ,
254- "start" : 132 ,
255- "end" : 160 ,
316+ "start" : 176 ,
317+ "end" : 204 ,
256318 "name" : " div" ,
257319 "attributes" : [],
258320 "children" : [
259321 {
260322 "type" : " Text" ,
261- "start" : 137 ,
262- "end" : 138 ,
323+ "start" : 181 ,
324+ "end" : 182 ,
263325 "raw" : " \n " ,
264326 "data" : " \n "
265327 },
266328 {
267329 "type" : " Element" ,
268- "start" : 138 ,
269- "end" : 147 ,
330+ "start" : 182 ,
331+ "end" : 191 ,
270332 "name" : " p" ,
271333 "attributes" : [],
272334 "children" : [
273335 {
274336 "type" : " Text" ,
275- "start" : 141 ,
276- "end" : 143 ,
337+ "start" : 185 ,
338+ "end" : 187 ,
277339 "raw" : " hi" ,
278340 "data" : " hi"
279341 }
280342 ]
281343 },
282344 {
283345 "type" : " Text" ,
284- "start" : 147 ,
285- "end" : 149 ,
346+ "start" : 191 ,
347+ "end" : 193 ,
286348 "raw" : " \n\n " ,
287349 "data" : " \n\n "
288350 },
289351 {
290352 "type" : " Element" ,
291- "start" : 149 ,
292- "end" : 160 ,
353+ "start" : 193 ,
354+ "end" : 204 ,
293355 "name" : " open-ended" ,
294356 "attributes" : [],
295357 "children" : []
Original file line number Diff line number Diff line change 1010 <span
1111</div >
1212
13+ <div >
14+ <Comp .
15+ </div >
16+
17+ <div >
18+ <comp .
19+ </div >
20+
1321{#if foo }
1422 <div >
1523{/if }
You can’t perform that action at this time.
0 commit comments