compiler-dom.cjs.prod.js 20 KB

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