@vue/compiler-dom 3.4.26 → 3.5.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/compiler-dom v3.4.26
2
+ * @vue/compiler-dom v3.5.0-alpha.1
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -664,9 +664,183 @@ const ignoreSideEffectTags = (node, context) => {
664
664
  }
665
665
  };
666
666
 
667
+ function isValidHTMLNesting(parent, child) {
668
+ if (parent in onlyValidChildren) {
669
+ return onlyValidChildren[parent].has(child);
670
+ }
671
+ if (child in onlyValidParents) {
672
+ return onlyValidParents[child].has(parent);
673
+ }
674
+ if (parent in knownInvalidChildren) {
675
+ if (knownInvalidChildren[parent].has(child))
676
+ return false;
677
+ }
678
+ if (child in knownInvalidParents) {
679
+ if (knownInvalidParents[child].has(parent))
680
+ return false;
681
+ }
682
+ return true;
683
+ }
684
+ const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
685
+ const emptySet = /* @__PURE__ */ new Set([]);
686
+ const onlyValidChildren = {
687
+ head: /* @__PURE__ */ new Set([
688
+ "base",
689
+ "basefront",
690
+ "bgsound",
691
+ "link",
692
+ "meta",
693
+ "title",
694
+ "noscript",
695
+ "noframes",
696
+ "style",
697
+ "script",
698
+ "template"
699
+ ]),
700
+ optgroup: /* @__PURE__ */ new Set(["option"]),
701
+ select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
702
+ // table
703
+ table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
704
+ tr: /* @__PURE__ */ new Set(["td", "th"]),
705
+ colgroup: /* @__PURE__ */ new Set(["col"]),
706
+ tbody: /* @__PURE__ */ new Set(["tr"]),
707
+ thead: /* @__PURE__ */ new Set(["tr"]),
708
+ tfoot: /* @__PURE__ */ new Set(["tr"]),
709
+ // these elements can not have any children elements
710
+ script: emptySet,
711
+ iframe: emptySet,
712
+ option: emptySet,
713
+ textarea: emptySet,
714
+ style: emptySet,
715
+ title: emptySet
716
+ };
717
+ const onlyValidParents = {
718
+ // sections
719
+ html: emptySet,
720
+ body: /* @__PURE__ */ new Set(["html"]),
721
+ head: /* @__PURE__ */ new Set(["html"]),
722
+ // table
723
+ td: /* @__PURE__ */ new Set(["tr"]),
724
+ colgroup: /* @__PURE__ */ new Set(["table"]),
725
+ caption: /* @__PURE__ */ new Set(["table"]),
726
+ tbody: /* @__PURE__ */ new Set(["table"]),
727
+ tfoot: /* @__PURE__ */ new Set(["table"]),
728
+ col: /* @__PURE__ */ new Set(["colgroup"]),
729
+ th: /* @__PURE__ */ new Set(["tr"]),
730
+ thead: /* @__PURE__ */ new Set(["table"]),
731
+ tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
732
+ // data list
733
+ dd: /* @__PURE__ */ new Set(["dl", "div"]),
734
+ dt: /* @__PURE__ */ new Set(["dl", "div"]),
735
+ // other
736
+ figcaption: /* @__PURE__ */ new Set(["figure"]),
737
+ // li: new Set(["ul", "ol"]),
738
+ summary: /* @__PURE__ */ new Set(["details"]),
739
+ area: /* @__PURE__ */ new Set(["map"])
740
+ };
741
+ const knownInvalidChildren = {
742
+ p: /* @__PURE__ */ new Set([
743
+ "address",
744
+ "article",
745
+ "aside",
746
+ "blockquote",
747
+ "center",
748
+ "details",
749
+ "dialog",
750
+ "dir",
751
+ "div",
752
+ "dl",
753
+ "fieldset",
754
+ "figure",
755
+ "footer",
756
+ "form",
757
+ "h1",
758
+ "h2",
759
+ "h3",
760
+ "h4",
761
+ "h5",
762
+ "h6",
763
+ "header",
764
+ "hgroup",
765
+ "hr",
766
+ "li",
767
+ "main",
768
+ "nav",
769
+ "menu",
770
+ "ol",
771
+ "p",
772
+ "pre",
773
+ "section",
774
+ "table",
775
+ "ul"
776
+ ]),
777
+ svg: /* @__PURE__ */ new Set([
778
+ "b",
779
+ "blockquote",
780
+ "br",
781
+ "code",
782
+ "dd",
783
+ "div",
784
+ "dl",
785
+ "dt",
786
+ "em",
787
+ "embed",
788
+ "h1",
789
+ "h2",
790
+ "h3",
791
+ "h4",
792
+ "h5",
793
+ "h6",
794
+ "hr",
795
+ "i",
796
+ "img",
797
+ "li",
798
+ "menu",
799
+ "meta",
800
+ "ol",
801
+ "p",
802
+ "pre",
803
+ "ruby",
804
+ "s",
805
+ "small",
806
+ "span",
807
+ "strong",
808
+ "sub",
809
+ "sup",
810
+ "table",
811
+ "u",
812
+ "ul",
813
+ "var"
814
+ ])
815
+ };
816
+ const knownInvalidParents = {
817
+ a: /* @__PURE__ */ new Set(["a"]),
818
+ button: /* @__PURE__ */ new Set(["button"]),
819
+ dd: /* @__PURE__ */ new Set(["dd", "dt"]),
820
+ dt: /* @__PURE__ */ new Set(["dd", "dt"]),
821
+ form: /* @__PURE__ */ new Set(["form"]),
822
+ li: /* @__PURE__ */ new Set(["li"]),
823
+ h1: headings,
824
+ h2: headings,
825
+ h3: headings,
826
+ h4: headings,
827
+ h5: headings,
828
+ h6: headings
829
+ };
830
+
831
+ const validateHtmlNesting = (node, context) => {
832
+ if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
833
+ const error = new SyntaxError(
834
+ `<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
835
+ );
836
+ error.loc = node.loc;
837
+ context.onWarn(error);
838
+ }
839
+ };
840
+
667
841
  const DOMNodeTransforms = [
668
842
  transformStyle,
669
- ...[transformTransition]
843
+ ...[transformTransition, validateHtmlNesting]
670
844
  ];
671
845
  const DOMDirectiveTransforms = {
672
846
  cloak: compilerCore.noopDirectiveTransform,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/compiler-dom v3.4.26
2
+ * @vue/compiler-dom v3.5.0-alpha.1
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/compiler-dom v3.4.26
2
+ * @vue/compiler-dom v3.5.0-alpha.1
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -2085,10 +2085,11 @@ const tokenizer = new Tokenizer(stack, {
2085
2085
  }
2086
2086
  },
2087
2087
  onselfclosingtag(end) {
2088
+ var _a;
2088
2089
  const name = currentOpenTag.tag;
2089
2090
  currentOpenTag.isSelfClosing = true;
2090
2091
  endOpenTag(end);
2091
- if (stack[0] && stack[0].tag === name) {
2092
+ if (((_a = stack[0]) == null ? void 0 : _a.tag) === name) {
2092
2093
  onCloseTag(stack.shift(), end);
2093
2094
  }
2094
2095
  },
@@ -2399,15 +2400,16 @@ function endOpenTag(end) {
2399
2400
  currentOpenTag = null;
2400
2401
  }
2401
2402
  function onText(content, start, end) {
2403
+ var _a;
2402
2404
  {
2403
- const tag = stack[0] && stack[0].tag;
2405
+ const tag = (_a = stack[0]) == null ? void 0 : _a.tag;
2404
2406
  if (tag !== "script" && tag !== "style" && content.includes("&")) {
2405
2407
  content = currentOptions.decodeEntities(content, false);
2406
2408
  }
2407
2409
  }
2408
2410
  const parent = stack[0] || currentRoot;
2409
2411
  const lastNode = parent.children[parent.children.length - 1];
2410
- if (lastNode && lastNode.type === 2) {
2412
+ if ((lastNode == null ? void 0 : lastNode.type) === 2) {
2411
2413
  lastNode.content += content;
2412
2414
  setLocEnd(lastNode.loc, end);
2413
2415
  } else {
@@ -2541,10 +2543,11 @@ function isFragmentTemplate({ tag, props }) {
2541
2543
  return false;
2542
2544
  }
2543
2545
  function isComponent({ tag, props }) {
2546
+ var _a;
2544
2547
  if (currentOptions.isCustomElement(tag)) {
2545
2548
  return false;
2546
2549
  }
2547
- if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
2550
+ if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || ((_a = currentOptions.isBuiltInComponent) == null ? void 0 : _a.call(currentOptions, tag)) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
2548
2551
  return true;
2549
2552
  }
2550
2553
  for (let i = 0; i < props.length; i++) {
@@ -2577,6 +2580,7 @@ function isUpperCase(c) {
2577
2580
  }
2578
2581
  const windowsNewlineRE = /\r\n/g;
2579
2582
  function condenseWhitespace(nodes, tag) {
2583
+ var _a, _b;
2580
2584
  const shouldCondense = currentOptions.whitespace !== "preserve";
2581
2585
  let removedWhitespace = false;
2582
2586
  for (let i = 0; i < nodes.length; i++) {
@@ -2584,8 +2588,8 @@ function condenseWhitespace(nodes, tag) {
2584
2588
  if (node.type === 2) {
2585
2589
  if (!inPre) {
2586
2590
  if (isAllWhitespace(node.content)) {
2587
- const prev = nodes[i - 1] && nodes[i - 1].type;
2588
- const next = nodes[i + 1] && nodes[i + 1].type;
2591
+ const prev = (_a = nodes[i - 1]) == null ? void 0 : _a.type;
2592
+ const next = (_b = nodes[i + 1]) == null ? void 0 : _b.type;
2589
2593
  if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
2590
2594
  removedWhitespace = true;
2591
2595
  nodes[i] = null;
@@ -2723,7 +2727,7 @@ function baseParse(input, options) {
2723
2727
  }
2724
2728
  tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
2725
2729
  tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
2726
- const delimiters = options && options.delimiters;
2730
+ const delimiters = options == null ? void 0 : options.delimiters;
2727
2731
  if (delimiters) {
2728
2732
  tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
2729
2733
  tokenizer.delimiterClose = toCharCodes(delimiters[1]);
@@ -6270,9 +6274,183 @@ const ignoreSideEffectTags = (node, context) => {
6270
6274
  }
6271
6275
  };
6272
6276
 
6277
+ function isValidHTMLNesting(parent, child) {
6278
+ if (parent in onlyValidChildren) {
6279
+ return onlyValidChildren[parent].has(child);
6280
+ }
6281
+ if (child in onlyValidParents) {
6282
+ return onlyValidParents[child].has(parent);
6283
+ }
6284
+ if (parent in knownInvalidChildren) {
6285
+ if (knownInvalidChildren[parent].has(child))
6286
+ return false;
6287
+ }
6288
+ if (child in knownInvalidParents) {
6289
+ if (knownInvalidParents[child].has(parent))
6290
+ return false;
6291
+ }
6292
+ return true;
6293
+ }
6294
+ const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
6295
+ const emptySet = /* @__PURE__ */ new Set([]);
6296
+ const onlyValidChildren = {
6297
+ head: /* @__PURE__ */ new Set([
6298
+ "base",
6299
+ "basefront",
6300
+ "bgsound",
6301
+ "link",
6302
+ "meta",
6303
+ "title",
6304
+ "noscript",
6305
+ "noframes",
6306
+ "style",
6307
+ "script",
6308
+ "template"
6309
+ ]),
6310
+ optgroup: /* @__PURE__ */ new Set(["option"]),
6311
+ select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
6312
+ // table
6313
+ table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
6314
+ tr: /* @__PURE__ */ new Set(["td", "th"]),
6315
+ colgroup: /* @__PURE__ */ new Set(["col"]),
6316
+ tbody: /* @__PURE__ */ new Set(["tr"]),
6317
+ thead: /* @__PURE__ */ new Set(["tr"]),
6318
+ tfoot: /* @__PURE__ */ new Set(["tr"]),
6319
+ // these elements can not have any children elements
6320
+ script: emptySet,
6321
+ iframe: emptySet,
6322
+ option: emptySet,
6323
+ textarea: emptySet,
6324
+ style: emptySet,
6325
+ title: emptySet
6326
+ };
6327
+ const onlyValidParents = {
6328
+ // sections
6329
+ html: emptySet,
6330
+ body: /* @__PURE__ */ new Set(["html"]),
6331
+ head: /* @__PURE__ */ new Set(["html"]),
6332
+ // table
6333
+ td: /* @__PURE__ */ new Set(["tr"]),
6334
+ colgroup: /* @__PURE__ */ new Set(["table"]),
6335
+ caption: /* @__PURE__ */ new Set(["table"]),
6336
+ tbody: /* @__PURE__ */ new Set(["table"]),
6337
+ tfoot: /* @__PURE__ */ new Set(["table"]),
6338
+ col: /* @__PURE__ */ new Set(["colgroup"]),
6339
+ th: /* @__PURE__ */ new Set(["tr"]),
6340
+ thead: /* @__PURE__ */ new Set(["table"]),
6341
+ tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
6342
+ // data list
6343
+ dd: /* @__PURE__ */ new Set(["dl", "div"]),
6344
+ dt: /* @__PURE__ */ new Set(["dl", "div"]),
6345
+ // other
6346
+ figcaption: /* @__PURE__ */ new Set(["figure"]),
6347
+ // li: new Set(["ul", "ol"]),
6348
+ summary: /* @__PURE__ */ new Set(["details"]),
6349
+ area: /* @__PURE__ */ new Set(["map"])
6350
+ };
6351
+ const knownInvalidChildren = {
6352
+ p: /* @__PURE__ */ new Set([
6353
+ "address",
6354
+ "article",
6355
+ "aside",
6356
+ "blockquote",
6357
+ "center",
6358
+ "details",
6359
+ "dialog",
6360
+ "dir",
6361
+ "div",
6362
+ "dl",
6363
+ "fieldset",
6364
+ "figure",
6365
+ "footer",
6366
+ "form",
6367
+ "h1",
6368
+ "h2",
6369
+ "h3",
6370
+ "h4",
6371
+ "h5",
6372
+ "h6",
6373
+ "header",
6374
+ "hgroup",
6375
+ "hr",
6376
+ "li",
6377
+ "main",
6378
+ "nav",
6379
+ "menu",
6380
+ "ol",
6381
+ "p",
6382
+ "pre",
6383
+ "section",
6384
+ "table",
6385
+ "ul"
6386
+ ]),
6387
+ svg: /* @__PURE__ */ new Set([
6388
+ "b",
6389
+ "blockquote",
6390
+ "br",
6391
+ "code",
6392
+ "dd",
6393
+ "div",
6394
+ "dl",
6395
+ "dt",
6396
+ "em",
6397
+ "embed",
6398
+ "h1",
6399
+ "h2",
6400
+ "h3",
6401
+ "h4",
6402
+ "h5",
6403
+ "h6",
6404
+ "hr",
6405
+ "i",
6406
+ "img",
6407
+ "li",
6408
+ "menu",
6409
+ "meta",
6410
+ "ol",
6411
+ "p",
6412
+ "pre",
6413
+ "ruby",
6414
+ "s",
6415
+ "small",
6416
+ "span",
6417
+ "strong",
6418
+ "sub",
6419
+ "sup",
6420
+ "table",
6421
+ "u",
6422
+ "ul",
6423
+ "var"
6424
+ ])
6425
+ };
6426
+ const knownInvalidParents = {
6427
+ a: /* @__PURE__ */ new Set(["a"]),
6428
+ button: /* @__PURE__ */ new Set(["button"]),
6429
+ dd: /* @__PURE__ */ new Set(["dd", "dt"]),
6430
+ dt: /* @__PURE__ */ new Set(["dd", "dt"]),
6431
+ form: /* @__PURE__ */ new Set(["form"]),
6432
+ li: /* @__PURE__ */ new Set(["li"]),
6433
+ h1: headings,
6434
+ h2: headings,
6435
+ h3: headings,
6436
+ h4: headings,
6437
+ h5: headings,
6438
+ h6: headings
6439
+ };
6440
+
6441
+ const validateHtmlNesting = (node, context) => {
6442
+ if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
6443
+ const error = new SyntaxError(
6444
+ `<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
6445
+ );
6446
+ error.loc = node.loc;
6447
+ context.onWarn(error);
6448
+ }
6449
+ };
6450
+
6273
6451
  const DOMNodeTransforms = [
6274
6452
  transformStyle,
6275
- ...[transformTransition]
6453
+ ...[transformTransition, validateHtmlNesting]
6276
6454
  ];
6277
6455
  const DOMDirectiveTransforms = {
6278
6456
  cloak: noopDirectiveTransform,