Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

compiler-dom.cjs.js 22KB

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