compiler-dom.esm-bundler.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /**
  2. * @vue/compiler-dom v3.5.12
  3. * (c) 2018-present Yuxi (Evan) You and Vue contributors
  4. * @license MIT
  5. **/
  6. import { registerRuntimeHelpers, createSimpleExpression, createCompilerError, createObjectProperty, getConstantType, createCallExpression, TO_DISPLAY_STRING, transformModel as transformModel$1, findProp, hasDynamicKeyVBind, findDir, isStaticArgOf, transformOn as transformOn$1, isStaticExp, createCompoundExpression, checkCompatEnabled, noopDirectiveTransform, baseCompile, baseParse } from '@vue/compiler-core';
  7. export * from '@vue/compiler-core';
  8. import { isVoidTag, isHTMLTag, isSVGTag, isMathMLTag, parseStringStyle, capitalize, makeMap, extend } from '@vue/shared';
  9. const V_MODEL_RADIO = Symbol(!!(process.env.NODE_ENV !== "production") ? `vModelRadio` : ``);
  10. const V_MODEL_CHECKBOX = Symbol(
  11. !!(process.env.NODE_ENV !== "production") ? `vModelCheckbox` : ``
  12. );
  13. const V_MODEL_TEXT = Symbol(!!(process.env.NODE_ENV !== "production") ? `vModelText` : ``);
  14. const V_MODEL_SELECT = Symbol(
  15. !!(process.env.NODE_ENV !== "production") ? `vModelSelect` : ``
  16. );
  17. const V_MODEL_DYNAMIC = Symbol(
  18. !!(process.env.NODE_ENV !== "production") ? `vModelDynamic` : ``
  19. );
  20. const V_ON_WITH_MODIFIERS = Symbol(
  21. !!(process.env.NODE_ENV !== "production") ? `vOnModifiersGuard` : ``
  22. );
  23. const V_ON_WITH_KEYS = Symbol(
  24. !!(process.env.NODE_ENV !== "production") ? `vOnKeysGuard` : ``
  25. );
  26. const V_SHOW = Symbol(!!(process.env.NODE_ENV !== "production") ? `vShow` : ``);
  27. const TRANSITION = Symbol(!!(process.env.NODE_ENV !== "production") ? `Transition` : ``);
  28. const TRANSITION_GROUP = Symbol(
  29. !!(process.env.NODE_ENV !== "production") ? `TransitionGroup` : ``
  30. );
  31. registerRuntimeHelpers({
  32. [V_MODEL_RADIO]: `vModelRadio`,
  33. [V_MODEL_CHECKBOX]: `vModelCheckbox`,
  34. [V_MODEL_TEXT]: `vModelText`,
  35. [V_MODEL_SELECT]: `vModelSelect`,
  36. [V_MODEL_DYNAMIC]: `vModelDynamic`,
  37. [V_ON_WITH_MODIFIERS]: `withModifiers`,
  38. [V_ON_WITH_KEYS]: `withKeys`,
  39. [V_SHOW]: `vShow`,
  40. [TRANSITION]: `Transition`,
  41. [TRANSITION_GROUP]: `TransitionGroup`
  42. });
  43. let decoder;
  44. function decodeHtmlBrowser(raw, asAttr = false) {
  45. if (!decoder) {
  46. decoder = document.createElement("div");
  47. }
  48. if (asAttr) {
  49. decoder.innerHTML = `<div foo="${raw.replace(/"/g, "&quot;")}">`;
  50. return decoder.children[0].getAttribute("foo");
  51. } else {
  52. decoder.innerHTML = raw;
  53. return decoder.textContent;
  54. }
  55. }
  56. const parserOptions = {
  57. parseMode: "html",
  58. isVoidTag,
  59. isNativeTag: (tag) => isHTMLTag(tag) || isSVGTag(tag) || isMathMLTag(tag),
  60. isPreTag: (tag) => tag === "pre",
  61. isIgnoreNewlineTag: (tag) => tag === "pre" || tag === "textarea",
  62. decodeEntities: decodeHtmlBrowser ,
  63. isBuiltInComponent: (tag) => {
  64. if (tag === "Transition" || tag === "transition") {
  65. return TRANSITION;
  66. } else if (tag === "TransitionGroup" || tag === "transition-group") {
  67. return TRANSITION_GROUP;
  68. }
  69. },
  70. // https://html.spec.whatwg.org/multipage/parsing.html#tree-construction-dispatcher
  71. getNamespace(tag, parent, rootNamespace) {
  72. let ns = parent ? parent.ns : rootNamespace;
  73. if (parent && ns === 2) {
  74. if (parent.tag === "annotation-xml") {
  75. if (tag === "svg") {
  76. return 1;
  77. }
  78. if (parent.props.some(
  79. (a) => a.type === 6 && a.name === "encoding" && a.value != null && (a.value.content === "text/html" || a.value.content === "application/xhtml+xml")
  80. )) {
  81. ns = 0;
  82. }
  83. } else if (/^m(?:[ions]|text)$/.test(parent.tag) && tag !== "mglyph" && tag !== "malignmark") {
  84. ns = 0;
  85. }
  86. } else if (parent && ns === 1) {
  87. if (parent.tag === "foreignObject" || parent.tag === "desc" || parent.tag === "title") {
  88. ns = 0;
  89. }
  90. }
  91. if (ns === 0) {
  92. if (tag === "svg") {
  93. return 1;
  94. }
  95. if (tag === "math") {
  96. return 2;
  97. }
  98. }
  99. return ns;
  100. }
  101. };
  102. const transformStyle = (node) => {
  103. if (node.type === 1) {
  104. node.props.forEach((p, i) => {
  105. if (p.type === 6 && p.name === "style" && p.value) {
  106. node.props[i] = {
  107. type: 7,
  108. name: `bind`,
  109. arg: createSimpleExpression(`style`, true, p.loc),
  110. exp: parseInlineCSS(p.value.content, p.loc),
  111. modifiers: [],
  112. loc: p.loc
  113. };
  114. }
  115. });
  116. }
  117. };
  118. const parseInlineCSS = (cssText, loc) => {
  119. const normalized = parseStringStyle(cssText);
  120. return createSimpleExpression(
  121. JSON.stringify(normalized),
  122. false,
  123. loc,
  124. 3
  125. );
  126. };
  127. function createDOMCompilerError(code, loc) {
  128. return createCompilerError(
  129. code,
  130. loc,
  131. !!(process.env.NODE_ENV !== "production") || false ? DOMErrorMessages : void 0
  132. );
  133. }
  134. const DOMErrorCodes = {
  135. "X_V_HTML_NO_EXPRESSION": 53,
  136. "53": "X_V_HTML_NO_EXPRESSION",
  137. "X_V_HTML_WITH_CHILDREN": 54,
  138. "54": "X_V_HTML_WITH_CHILDREN",
  139. "X_V_TEXT_NO_EXPRESSION": 55,
  140. "55": "X_V_TEXT_NO_EXPRESSION",
  141. "X_V_TEXT_WITH_CHILDREN": 56,
  142. "56": "X_V_TEXT_WITH_CHILDREN",
  143. "X_V_MODEL_ON_INVALID_ELEMENT": 57,
  144. "57": "X_V_MODEL_ON_INVALID_ELEMENT",
  145. "X_V_MODEL_ARG_ON_ELEMENT": 58,
  146. "58": "X_V_MODEL_ARG_ON_ELEMENT",
  147. "X_V_MODEL_ON_FILE_INPUT_ELEMENT": 59,
  148. "59": "X_V_MODEL_ON_FILE_INPUT_ELEMENT",
  149. "X_V_MODEL_UNNECESSARY_VALUE": 60,
  150. "60": "X_V_MODEL_UNNECESSARY_VALUE",
  151. "X_V_SHOW_NO_EXPRESSION": 61,
  152. "61": "X_V_SHOW_NO_EXPRESSION",
  153. "X_TRANSITION_INVALID_CHILDREN": 62,
  154. "62": "X_TRANSITION_INVALID_CHILDREN",
  155. "X_IGNORED_SIDE_EFFECT_TAG": 63,
  156. "63": "X_IGNORED_SIDE_EFFECT_TAG",
  157. "__EXTEND_POINT__": 64,
  158. "64": "__EXTEND_POINT__"
  159. };
  160. const DOMErrorMessages = {
  161. [53]: `v-html is missing expression.`,
  162. [54]: `v-html will override element children.`,
  163. [55]: `v-text is missing expression.`,
  164. [56]: `v-text will override element children.`,
  165. [57]: `v-model can only be used on <input>, <textarea> and <select> elements.`,
  166. [58]: `v-model argument is not supported on plain elements.`,
  167. [59]: `v-model cannot be used on file inputs since they are read-only. Use a v-on:change listener instead.`,
  168. [60]: `Unnecessary value binding used alongside v-model. It will interfere with v-model's behavior.`,
  169. [61]: `v-show is missing expression.`,
  170. [62]: `<Transition> expects exactly one child element or component.`,
  171. [63]: `Tags with side effect (<script> and <style>) are ignored in client component templates.`
  172. };
  173. const transformVHtml = (dir, node, context) => {
  174. const { exp, loc } = dir;
  175. if (!exp) {
  176. context.onError(
  177. createDOMCompilerError(53, loc)
  178. );
  179. }
  180. if (node.children.length) {
  181. context.onError(
  182. createDOMCompilerError(54, loc)
  183. );
  184. node.children.length = 0;
  185. }
  186. return {
  187. props: [
  188. createObjectProperty(
  189. createSimpleExpression(`innerHTML`, true, loc),
  190. exp || createSimpleExpression("", true)
  191. )
  192. ]
  193. };
  194. };
  195. const transformVText = (dir, node, context) => {
  196. const { exp, loc } = dir;
  197. if (!exp) {
  198. context.onError(
  199. createDOMCompilerError(55, loc)
  200. );
  201. }
  202. if (node.children.length) {
  203. context.onError(
  204. createDOMCompilerError(56, loc)
  205. );
  206. node.children.length = 0;
  207. }
  208. return {
  209. props: [
  210. createObjectProperty(
  211. createSimpleExpression(`textContent`, true),
  212. exp ? getConstantType(exp, context) > 0 ? exp : createCallExpression(
  213. context.helperString(TO_DISPLAY_STRING),
  214. [exp],
  215. loc
  216. ) : createSimpleExpression("", true)
  217. )
  218. ]
  219. };
  220. };
  221. const transformModel = (dir, node, context) => {
  222. const baseResult = transformModel$1(dir, node, context);
  223. if (!baseResult.props.length || node.tagType === 1) {
  224. return baseResult;
  225. }
  226. if (dir.arg) {
  227. context.onError(
  228. createDOMCompilerError(
  229. 58,
  230. dir.arg.loc
  231. )
  232. );
  233. }
  234. function checkDuplicatedValue() {
  235. const value = findDir(node, "bind");
  236. if (value && isStaticArgOf(value.arg, "value")) {
  237. context.onError(
  238. createDOMCompilerError(
  239. 60,
  240. value.loc
  241. )
  242. );
  243. }
  244. }
  245. const { tag } = node;
  246. const isCustomElement = context.isCustomElement(tag);
  247. if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) {
  248. let directiveToUse = V_MODEL_TEXT;
  249. let isInvalidType = false;
  250. if (tag === "input" || isCustomElement) {
  251. const type = findProp(node, `type`);
  252. if (type) {
  253. if (type.type === 7) {
  254. directiveToUse = V_MODEL_DYNAMIC;
  255. } else if (type.value) {
  256. switch (type.value.content) {
  257. case "radio":
  258. directiveToUse = V_MODEL_RADIO;
  259. break;
  260. case "checkbox":
  261. directiveToUse = V_MODEL_CHECKBOX;
  262. break;
  263. case "file":
  264. isInvalidType = true;
  265. context.onError(
  266. createDOMCompilerError(
  267. 59,
  268. dir.loc
  269. )
  270. );
  271. break;
  272. default:
  273. !!(process.env.NODE_ENV !== "production") && checkDuplicatedValue();
  274. break;
  275. }
  276. }
  277. } else if (hasDynamicKeyVBind(node)) {
  278. directiveToUse = V_MODEL_DYNAMIC;
  279. } else {
  280. !!(process.env.NODE_ENV !== "production") && checkDuplicatedValue();
  281. }
  282. } else if (tag === "select") {
  283. directiveToUse = V_MODEL_SELECT;
  284. } else {
  285. !!(process.env.NODE_ENV !== "production") && checkDuplicatedValue();
  286. }
  287. if (!isInvalidType) {
  288. baseResult.needRuntime = context.helper(directiveToUse);
  289. }
  290. } else {
  291. context.onError(
  292. createDOMCompilerError(
  293. 57,
  294. dir.loc
  295. )
  296. );
  297. }
  298. baseResult.props = baseResult.props.filter(
  299. (p) => !(p.key.type === 4 && p.key.content === "modelValue")
  300. );
  301. return baseResult;
  302. };
  303. const isEventOptionModifier = /* @__PURE__ */ makeMap(`passive,once,capture`);
  304. const isNonKeyModifier = /* @__PURE__ */ makeMap(
  305. // event propagation management
  306. `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
  307. );
  308. const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
  309. const isKeyboardEvent = /* @__PURE__ */ makeMap(`onkeyup,onkeydown,onkeypress`);
  310. const resolveModifiers = (key, modifiers, context, loc) => {
  311. const keyModifiers = [];
  312. const nonKeyModifiers = [];
  313. const eventOptionModifiers = [];
  314. for (let i = 0; i < modifiers.length; i++) {
  315. const modifier = modifiers[i].content;
  316. if (modifier === "native" && checkCompatEnabled(
  317. "COMPILER_V_ON_NATIVE",
  318. context,
  319. loc
  320. )) {
  321. eventOptionModifiers.push(modifier);
  322. } else if (isEventOptionModifier(modifier)) {
  323. eventOptionModifiers.push(modifier);
  324. } else {
  325. if (maybeKeyModifier(modifier)) {
  326. if (isStaticExp(key)) {
  327. if (isKeyboardEvent(key.content.toLowerCase())) {
  328. keyModifiers.push(modifier);
  329. } else {
  330. nonKeyModifiers.push(modifier);
  331. }
  332. } else {
  333. keyModifiers.push(modifier);
  334. nonKeyModifiers.push(modifier);
  335. }
  336. } else {
  337. if (isNonKeyModifier(modifier)) {
  338. nonKeyModifiers.push(modifier);
  339. } else {
  340. keyModifiers.push(modifier);
  341. }
  342. }
  343. }
  344. }
  345. return {
  346. keyModifiers,
  347. nonKeyModifiers,
  348. eventOptionModifiers
  349. };
  350. };
  351. const transformClick = (key, event) => {
  352. const isStaticClick = isStaticExp(key) && key.content.toLowerCase() === "onclick";
  353. return isStaticClick ? createSimpleExpression(event, true) : key.type !== 4 ? createCompoundExpression([
  354. `(`,
  355. key,
  356. `) === "onClick" ? "${event}" : (`,
  357. key,
  358. `)`
  359. ]) : key;
  360. };
  361. const transformOn = (dir, node, context) => {
  362. return transformOn$1(dir, node, context, (baseResult) => {
  363. const { modifiers } = dir;
  364. if (!modifiers.length) return baseResult;
  365. let { key, value: handlerExp } = baseResult.props[0];
  366. const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
  367. if (nonKeyModifiers.includes("right")) {
  368. key = transformClick(key, `onContextmenu`);
  369. }
  370. if (nonKeyModifiers.includes("middle")) {
  371. key = transformClick(key, `onMouseup`);
  372. }
  373. if (nonKeyModifiers.length) {
  374. handlerExp = createCallExpression(context.helper(V_ON_WITH_MODIFIERS), [
  375. handlerExp,
  376. JSON.stringify(nonKeyModifiers)
  377. ]);
  378. }
  379. if (keyModifiers.length && // if event name is dynamic, always wrap with keys guard
  380. (!isStaticExp(key) || isKeyboardEvent(key.content.toLowerCase()))) {
  381. handlerExp = createCallExpression(context.helper(V_ON_WITH_KEYS), [
  382. handlerExp,
  383. JSON.stringify(keyModifiers)
  384. ]);
  385. }
  386. if (eventOptionModifiers.length) {
  387. const modifierPostfix = eventOptionModifiers.map(capitalize).join("");
  388. key = isStaticExp(key) ? createSimpleExpression(`${key.content}${modifierPostfix}`, true) : createCompoundExpression([`(`, key, `) + "${modifierPostfix}"`]);
  389. }
  390. return {
  391. props: [createObjectProperty(key, handlerExp)]
  392. };
  393. });
  394. };
  395. const transformShow = (dir, node, context) => {
  396. const { exp, loc } = dir;
  397. if (!exp) {
  398. context.onError(
  399. createDOMCompilerError(61, loc)
  400. );
  401. }
  402. return {
  403. props: [],
  404. needRuntime: context.helper(V_SHOW)
  405. };
  406. };
  407. const transformTransition = (node, context) => {
  408. if (node.type === 1 && node.tagType === 1) {
  409. const component = context.isBuiltInComponent(node.tag);
  410. if (component === TRANSITION) {
  411. return () => {
  412. if (!node.children.length) {
  413. return;
  414. }
  415. if (hasMultipleChildren(node)) {
  416. context.onError(
  417. createDOMCompilerError(
  418. 62,
  419. {
  420. start: node.children[0].loc.start,
  421. end: node.children[node.children.length - 1].loc.end,
  422. source: ""
  423. }
  424. )
  425. );
  426. }
  427. const child = node.children[0];
  428. if (child.type === 1) {
  429. for (const p of child.props) {
  430. if (p.type === 7 && p.name === "show") {
  431. node.props.push({
  432. type: 6,
  433. name: "persisted",
  434. nameLoc: node.loc,
  435. value: void 0,
  436. loc: node.loc
  437. });
  438. }
  439. }
  440. }
  441. };
  442. }
  443. }
  444. };
  445. function hasMultipleChildren(node) {
  446. const children = node.children = node.children.filter(
  447. (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
  448. );
  449. const child = children[0];
  450. return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(hasMultipleChildren);
  451. }
  452. const ignoreSideEffectTags = (node, context) => {
  453. if (node.type === 1 && node.tagType === 0 && (node.tag === "script" || node.tag === "style")) {
  454. !!(process.env.NODE_ENV !== "production") && context.onError(
  455. createDOMCompilerError(
  456. 63,
  457. node.loc
  458. )
  459. );
  460. context.removeNode();
  461. }
  462. };
  463. function isValidHTMLNesting(parent, child) {
  464. if (parent in onlyValidChildren) {
  465. return onlyValidChildren[parent].has(child);
  466. }
  467. if (child in onlyValidParents) {
  468. return onlyValidParents[child].has(parent);
  469. }
  470. if (parent in knownInvalidChildren) {
  471. if (knownInvalidChildren[parent].has(child)) return false;
  472. }
  473. if (child in knownInvalidParents) {
  474. if (knownInvalidParents[child].has(parent)) return false;
  475. }
  476. return true;
  477. }
  478. const headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
  479. const emptySet = /* @__PURE__ */ new Set([]);
  480. const onlyValidChildren = {
  481. head: /* @__PURE__ */ new Set([
  482. "base",
  483. "basefront",
  484. "bgsound",
  485. "link",
  486. "meta",
  487. "title",
  488. "noscript",
  489. "noframes",
  490. "style",
  491. "script",
  492. "template"
  493. ]),
  494. optgroup: /* @__PURE__ */ new Set(["option"]),
  495. select: /* @__PURE__ */ new Set(["optgroup", "option", "hr"]),
  496. // table
  497. table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
  498. tr: /* @__PURE__ */ new Set(["td", "th"]),
  499. colgroup: /* @__PURE__ */ new Set(["col"]),
  500. tbody: /* @__PURE__ */ new Set(["tr"]),
  501. thead: /* @__PURE__ */ new Set(["tr"]),
  502. tfoot: /* @__PURE__ */ new Set(["tr"]),
  503. // these elements can not have any children elements
  504. script: emptySet,
  505. iframe: emptySet,
  506. option: emptySet,
  507. textarea: emptySet,
  508. style: emptySet,
  509. title: emptySet
  510. };
  511. const onlyValidParents = {
  512. // sections
  513. html: emptySet,
  514. body: /* @__PURE__ */ new Set(["html"]),
  515. head: /* @__PURE__ */ new Set(["html"]),
  516. // table
  517. td: /* @__PURE__ */ new Set(["tr"]),
  518. colgroup: /* @__PURE__ */ new Set(["table"]),
  519. caption: /* @__PURE__ */ new Set(["table"]),
  520. tbody: /* @__PURE__ */ new Set(["table"]),
  521. tfoot: /* @__PURE__ */ new Set(["table"]),
  522. col: /* @__PURE__ */ new Set(["colgroup"]),
  523. th: /* @__PURE__ */ new Set(["tr"]),
  524. thead: /* @__PURE__ */ new Set(["table"]),
  525. tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
  526. // data list
  527. dd: /* @__PURE__ */ new Set(["dl", "div"]),
  528. dt: /* @__PURE__ */ new Set(["dl", "div"]),
  529. // other
  530. figcaption: /* @__PURE__ */ new Set(["figure"]),
  531. // li: new Set(["ul", "ol"]),
  532. summary: /* @__PURE__ */ new Set(["details"]),
  533. area: /* @__PURE__ */ new Set(["map"])
  534. };
  535. const knownInvalidChildren = {
  536. p: /* @__PURE__ */ new Set([
  537. "address",
  538. "article",
  539. "aside",
  540. "blockquote",
  541. "center",
  542. "details",
  543. "dialog",
  544. "dir",
  545. "div",
  546. "dl",
  547. "fieldset",
  548. "figure",
  549. "footer",
  550. "form",
  551. "h1",
  552. "h2",
  553. "h3",
  554. "h4",
  555. "h5",
  556. "h6",
  557. "header",
  558. "hgroup",
  559. "hr",
  560. "li",
  561. "main",
  562. "nav",
  563. "menu",
  564. "ol",
  565. "p",
  566. "pre",
  567. "section",
  568. "table",
  569. "ul"
  570. ]),
  571. svg: /* @__PURE__ */ new Set([
  572. "b",
  573. "blockquote",
  574. "br",
  575. "code",
  576. "dd",
  577. "div",
  578. "dl",
  579. "dt",
  580. "em",
  581. "embed",
  582. "h1",
  583. "h2",
  584. "h3",
  585. "h4",
  586. "h5",
  587. "h6",
  588. "hr",
  589. "i",
  590. "img",
  591. "li",
  592. "menu",
  593. "meta",
  594. "ol",
  595. "p",
  596. "pre",
  597. "ruby",
  598. "s",
  599. "small",
  600. "span",
  601. "strong",
  602. "sub",
  603. "sup",
  604. "table",
  605. "u",
  606. "ul",
  607. "var"
  608. ])
  609. };
  610. const knownInvalidParents = {
  611. a: /* @__PURE__ */ new Set(["a"]),
  612. button: /* @__PURE__ */ new Set(["button"]),
  613. dd: /* @__PURE__ */ new Set(["dd", "dt"]),
  614. dt: /* @__PURE__ */ new Set(["dd", "dt"]),
  615. form: /* @__PURE__ */ new Set(["form"]),
  616. li: /* @__PURE__ */ new Set(["li"]),
  617. h1: headings,
  618. h2: headings,
  619. h3: headings,
  620. h4: headings,
  621. h5: headings,
  622. h6: headings
  623. };
  624. const validateHtmlNesting = (node, context) => {
  625. if (node.type === 1 && node.tagType === 0 && context.parent && context.parent.type === 1 && context.parent.tagType === 0 && !isValidHTMLNesting(context.parent.tag, node.tag)) {
  626. const error = new SyntaxError(
  627. `<${node.tag}> cannot be child of <${context.parent.tag}>, according to HTML specifications. This can cause hydration errors or potentially disrupt future functionality.`
  628. );
  629. error.loc = node.loc;
  630. context.onWarn(error);
  631. }
  632. };
  633. const DOMNodeTransforms = [
  634. transformStyle,
  635. ...!!(process.env.NODE_ENV !== "production") ? [transformTransition, validateHtmlNesting] : []
  636. ];
  637. const DOMDirectiveTransforms = {
  638. cloak: noopDirectiveTransform,
  639. html: transformVHtml,
  640. text: transformVText,
  641. model: transformModel,
  642. // override compiler-core
  643. on: transformOn,
  644. // override compiler-core
  645. show: transformShow
  646. };
  647. function compile(src, options = {}) {
  648. return baseCompile(
  649. src,
  650. extend({}, parserOptions, options, {
  651. nodeTransforms: [
  652. // ignore <script> and <tag>
  653. // this is not put inside DOMNodeTransforms because that list is used
  654. // by compiler-ssr to generate vnode fallback branches
  655. ignoreSideEffectTags,
  656. ...DOMNodeTransforms,
  657. ...options.nodeTransforms || []
  658. ],
  659. directiveTransforms: extend(
  660. {},
  661. DOMDirectiveTransforms,
  662. options.directiveTransforms || {}
  663. ),
  664. transformHoist: null
  665. })
  666. );
  667. }
  668. function parse(template, options = {}) {
  669. return baseParse(template, extend({}, parserOptions, options));
  670. }
  671. export { DOMDirectiveTransforms, DOMErrorCodes, DOMErrorMessages, DOMNodeTransforms, TRANSITION, TRANSITION_GROUP, V_MODEL_CHECKBOX, V_MODEL_DYNAMIC, V_MODEL_RADIO, V_MODEL_SELECT, V_MODEL_TEXT, V_ON_WITH_KEYS, V_ON_WITH_MODIFIERS, V_SHOW, compile, createDOMCompilerError, parse, parserOptions, transformStyle };