1
+ import {
2
+ disallowed_parapgraph_contents ,
3
+ interactive_elements ,
4
+ is_tag_valid_with_parent
5
+ } from '../../../constants.js' ;
1
6
import { error } from '../../errors.js' ;
2
7
import {
3
8
extract_identifiers ,
@@ -8,7 +13,6 @@ import {
8
13
} from '../../utils/ast.js' ;
9
14
import { warn } from '../../warnings.js' ;
10
15
import fuzzymatch from '../1-parse/utils/fuzzymatch.js' ;
11
- import { disallowed_parapgraph_contents , interactive_elements } from '../1-parse/utils/html.js' ;
12
16
import { binding_properties } from '../bindings.js' ;
13
17
import { ContentEditableBindings , EventModifiers , SVGElements } from '../constants.js' ;
14
18
import { is_custom_element_node } from '../nodes.js' ;
@@ -226,127 +230,6 @@ function validate_slot_attribute(context, attribute) {
226
230
}
227
231
}
228
232
229
- // https://html.spec.whatwg.org/multipage/syntax.html#generate-implied-end-tags
230
- const implied_end_tags = [ 'dd' , 'dt' , 'li' , 'option' , 'optgroup' , 'p' , 'rp' , 'rt' ] ;
231
-
232
- /**
233
- * @param {string } tag
234
- * @param {string } parent_tag
235
- * @returns {boolean }
236
- */
237
- function is_tag_valid_with_parent ( tag , parent_tag ) {
238
- // First, let's check if we're in an unusual parsing mode...
239
- switch ( parent_tag ) {
240
- // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inselect
241
- case 'select' :
242
- return tag === 'option' || tag === 'optgroup' || tag === '#text' ;
243
- case 'optgroup' :
244
- return tag === 'option' || tag === '#text' ;
245
- // Strictly speaking, seeing an <option> doesn't mean we're in a <select>
246
- // but
247
- case 'option' :
248
- return tag === '#text' ;
249
- // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intd
250
- // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incaption
251
- // No special behavior since these rules fall back to "in body" mode for
252
- // all except special table nodes which cause bad parsing behavior anyway.
253
-
254
- // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intr
255
- case 'tr' :
256
- return (
257
- tag === 'th' || tag === 'td' || tag === 'style' || tag === 'script' || tag === 'template'
258
- ) ;
259
- // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intbody
260
- case 'tbody' :
261
- case 'thead' :
262
- case 'tfoot' :
263
- return tag === 'tr' || tag === 'style' || tag === 'script' || tag === 'template' ;
264
- // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-incolgroup
265
- case 'colgroup' :
266
- return tag === 'col' || tag === 'template' ;
267
- // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-intable
268
- case 'table' :
269
- return (
270
- tag === 'caption' ||
271
- tag === 'colgroup' ||
272
- tag === 'tbody' ||
273
- tag === 'tfoot' ||
274
- tag === 'thead' ||
275
- tag === 'style' ||
276
- tag === 'script' ||
277
- tag === 'template'
278
- ) ;
279
- // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inhead
280
- case 'head' :
281
- return (
282
- tag === 'base' ||
283
- tag === 'basefont' ||
284
- tag === 'bgsound' ||
285
- tag === 'link' ||
286
- tag === 'meta' ||
287
- tag === 'title' ||
288
- tag === 'noscript' ||
289
- tag === 'noframes' ||
290
- tag === 'style' ||
291
- tag === 'script' ||
292
- tag === 'template'
293
- ) ;
294
- // https://html.spec.whatwg.org/multipage/semantics.html#the-html-element
295
- case 'html' :
296
- return tag === 'head' || tag === 'body' || tag === 'frameset' ;
297
- case 'frameset' :
298
- return tag === 'frame' ;
299
- case '#document' :
300
- return tag === 'html' ;
301
- }
302
-
303
- // Probably in the "in body" parsing mode, so we outlaw only tag combos
304
- // where the parsing rules cause implicit opens or closes to be added.
305
- // https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody
306
- switch ( tag ) {
307
- case 'h1' :
308
- case 'h2' :
309
- case 'h3' :
310
- case 'h4' :
311
- case 'h5' :
312
- case 'h6' :
313
- return (
314
- parent_tag !== 'h1' &&
315
- parent_tag !== 'h2' &&
316
- parent_tag !== 'h3' &&
317
- parent_tag !== 'h4' &&
318
- parent_tag !== 'h5' &&
319
- parent_tag !== 'h6'
320
- ) ;
321
-
322
- case 'rp' :
323
- case 'rt' :
324
- return implied_end_tags . indexOf ( parent_tag ) === - 1 ;
325
-
326
- case 'body' :
327
- case 'caption' :
328
- case 'col' :
329
- case 'colgroup' :
330
- case 'frameset' :
331
- case 'frame' :
332
- case 'head' :
333
- case 'html' :
334
- case 'tbody' :
335
- case 'td' :
336
- case 'tfoot' :
337
- case 'th' :
338
- case 'thead' :
339
- case 'tr' :
340
- // These tags are only valid with a few parents that have special child
341
- // parsing rules -- if we're down here, then none of those matched and
342
- // so we allow it only if we don't know what the parent is, as all other
343
- // cases are invalid.
344
- return parent_tag == null ;
345
- }
346
-
347
- return true ;
348
- }
349
-
350
233
/**
351
234
* @type {import('zimmerframe').Visitors<import('#compiler').SvelteNode, import('./types.js').AnalysisState> }
352
235
*/
0 commit comments