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-ssr.cjs.js 44KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  1. /**
  2. * @vue/compiler-ssr 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 compilerDom = require('@vue/compiler-dom');
  9. var shared = require('@vue/shared');
  10. const SSR_INTERPOLATE = Symbol(`ssrInterpolate`);
  11. const SSR_RENDER_VNODE = Symbol(`ssrRenderVNode`);
  12. const SSR_RENDER_COMPONENT = Symbol(`ssrRenderComponent`);
  13. const SSR_RENDER_SLOT = Symbol(`ssrRenderSlot`);
  14. const SSR_RENDER_SLOT_INNER = Symbol(`ssrRenderSlotInner`);
  15. const SSR_RENDER_CLASS = Symbol(`ssrRenderClass`);
  16. const SSR_RENDER_STYLE = Symbol(`ssrRenderStyle`);
  17. const SSR_RENDER_ATTRS = Symbol(`ssrRenderAttrs`);
  18. const SSR_RENDER_ATTR = Symbol(`ssrRenderAttr`);
  19. const SSR_RENDER_DYNAMIC_ATTR = Symbol(`ssrRenderDynamicAttr`);
  20. const SSR_RENDER_LIST = Symbol(`ssrRenderList`);
  21. const SSR_INCLUDE_BOOLEAN_ATTR = Symbol(`ssrIncludeBooleanAttr`);
  22. const SSR_LOOSE_EQUAL = Symbol(`ssrLooseEqual`);
  23. const SSR_LOOSE_CONTAIN = Symbol(`ssrLooseContain`);
  24. const SSR_RENDER_DYNAMIC_MODEL = Symbol(`ssrRenderDynamicModel`);
  25. const SSR_GET_DYNAMIC_MODEL_PROPS = Symbol(`ssrGetDynamicModelProps`);
  26. const SSR_RENDER_TELEPORT = Symbol(`ssrRenderTeleport`);
  27. const SSR_RENDER_SUSPENSE = Symbol(`ssrRenderSuspense`);
  28. const SSR_GET_DIRECTIVE_PROPS = Symbol(`ssrGetDirectiveProps`);
  29. const ssrHelpers = {
  30. [SSR_INTERPOLATE]: `ssrInterpolate`,
  31. [SSR_RENDER_VNODE]: `ssrRenderVNode`,
  32. [SSR_RENDER_COMPONENT]: `ssrRenderComponent`,
  33. [SSR_RENDER_SLOT]: `ssrRenderSlot`,
  34. [SSR_RENDER_SLOT_INNER]: `ssrRenderSlotInner`,
  35. [SSR_RENDER_CLASS]: `ssrRenderClass`,
  36. [SSR_RENDER_STYLE]: `ssrRenderStyle`,
  37. [SSR_RENDER_ATTRS]: `ssrRenderAttrs`,
  38. [SSR_RENDER_ATTR]: `ssrRenderAttr`,
  39. [SSR_RENDER_DYNAMIC_ATTR]: `ssrRenderDynamicAttr`,
  40. [SSR_RENDER_LIST]: `ssrRenderList`,
  41. [SSR_INCLUDE_BOOLEAN_ATTR]: `ssrIncludeBooleanAttr`,
  42. [SSR_LOOSE_EQUAL]: `ssrLooseEqual`,
  43. [SSR_LOOSE_CONTAIN]: `ssrLooseContain`,
  44. [SSR_RENDER_DYNAMIC_MODEL]: `ssrRenderDynamicModel`,
  45. [SSR_GET_DYNAMIC_MODEL_PROPS]: `ssrGetDynamicModelProps`,
  46. [SSR_RENDER_TELEPORT]: `ssrRenderTeleport`,
  47. [SSR_RENDER_SUSPENSE]: `ssrRenderSuspense`,
  48. [SSR_GET_DIRECTIVE_PROPS]: `ssrGetDirectiveProps`
  49. };
  50. compilerDom.registerRuntimeHelpers(ssrHelpers);
  51. const ssrTransformIf = compilerDom.createStructuralDirectiveTransform(
  52. /^(if|else|else-if)$/,
  53. compilerDom.processIf
  54. );
  55. function ssrProcessIf(node, context, disableNestedFragments = false, disableCommentAsIfAlternate = false) {
  56. const [rootBranch] = node.branches;
  57. const ifStatement = compilerDom.createIfStatement(
  58. rootBranch.condition,
  59. processIfBranch(rootBranch, context, disableNestedFragments)
  60. );
  61. context.pushStatement(ifStatement);
  62. let currentIf = ifStatement;
  63. for (let i = 1; i < node.branches.length; i++) {
  64. const branch = node.branches[i];
  65. const branchBlockStatement = processIfBranch(
  66. branch,
  67. context,
  68. disableNestedFragments
  69. );
  70. if (branch.condition) {
  71. currentIf = currentIf.alternate = compilerDom.createIfStatement(
  72. branch.condition,
  73. branchBlockStatement
  74. );
  75. } else {
  76. currentIf.alternate = branchBlockStatement;
  77. }
  78. }
  79. if (!currentIf.alternate && !disableCommentAsIfAlternate) {
  80. currentIf.alternate = compilerDom.createBlockStatement([
  81. compilerDom.createCallExpression(`_push`, ["`<!---->`"])
  82. ]);
  83. }
  84. }
  85. function processIfBranch(branch, context, disableNestedFragments = false) {
  86. const { children } = branch;
  87. const needFragmentWrapper = !disableNestedFragments && (children.length !== 1 || children[0].type !== 1) && // optimize away nested fragments when the only child is a ForNode
  88. !(children.length === 1 && children[0].type === 11);
  89. return processChildrenAsStatement(branch, context, needFragmentWrapper);
  90. }
  91. const ssrTransformFor = compilerDom.createStructuralDirectiveTransform(
  92. "for",
  93. compilerDom.processFor
  94. );
  95. function ssrProcessFor(node, context, disableNestedFragments = false) {
  96. const needFragmentWrapper = !disableNestedFragments && (node.children.length !== 1 || node.children[0].type !== 1);
  97. const renderLoop = compilerDom.createFunctionExpression(
  98. compilerDom.createForLoopParams(node.parseResult)
  99. );
  100. renderLoop.body = processChildrenAsStatement(
  101. node,
  102. context,
  103. needFragmentWrapper
  104. );
  105. if (!disableNestedFragments) {
  106. context.pushStringPart(`<!--[-->`);
  107. }
  108. context.pushStatement(
  109. compilerDom.createCallExpression(context.helper(SSR_RENDER_LIST), [
  110. node.source,
  111. renderLoop
  112. ])
  113. );
  114. if (!disableNestedFragments) {
  115. context.pushStringPart(`<!--]-->`);
  116. }
  117. }
  118. const ssrTransformSlotOutlet = (node, context) => {
  119. if (compilerDom.isSlotOutlet(node)) {
  120. const { slotName, slotProps } = compilerDom.processSlotOutlet(node, context);
  121. const args = [
  122. `_ctx.$slots`,
  123. slotName,
  124. slotProps || `{}`,
  125. // fallback content placeholder. will be replaced in the process phase
  126. `null`,
  127. `_push`,
  128. `_parent`
  129. ];
  130. if (context.scopeId && context.slotted !== false) {
  131. args.push(`"${context.scopeId}-s"`);
  132. }
  133. let method = SSR_RENDER_SLOT;
  134. let parent = context.parent;
  135. if (parent) {
  136. const children = parent.children;
  137. if (parent.type === 10) {
  138. parent = context.grandParent;
  139. }
  140. let componentType;
  141. if (parent.type === 1 && parent.tagType === 1 && ((componentType = compilerDom.resolveComponentType(parent, context, true)) === compilerDom.TRANSITION || componentType === compilerDom.TRANSITION_GROUP) && children.filter((c) => c.type === 1).length === 1) {
  142. method = SSR_RENDER_SLOT_INNER;
  143. if (!(context.scopeId && context.slotted !== false)) {
  144. args.push("null");
  145. }
  146. args.push("true");
  147. }
  148. }
  149. node.ssrCodegenNode = compilerDom.createCallExpression(context.helper(method), args);
  150. }
  151. };
  152. function ssrProcessSlotOutlet(node, context) {
  153. const renderCall = node.ssrCodegenNode;
  154. if (node.children.length) {
  155. const fallbackRenderFn = compilerDom.createFunctionExpression([]);
  156. fallbackRenderFn.body = processChildrenAsStatement(node, context);
  157. renderCall.arguments[3] = fallbackRenderFn;
  158. }
  159. if (context.withSlotScopeId) {
  160. const slotScopeId = renderCall.arguments[6];
  161. renderCall.arguments[6] = slotScopeId ? `${slotScopeId} + _scopeId` : `_scopeId`;
  162. }
  163. context.pushStatement(node.ssrCodegenNode);
  164. }
  165. function createSSRCompilerError(code, loc) {
  166. return compilerDom.createCompilerError(code, loc, SSRErrorMessages);
  167. }
  168. const SSRErrorMessages = {
  169. [65]: `Unsafe attribute name for SSR.`,
  170. [66]: `Missing the 'to' prop on teleport element.`,
  171. [67]: `Invalid AST node during SSR transform.`
  172. };
  173. function ssrProcessTeleport(node, context) {
  174. const targetProp = compilerDom.findProp(node, "to");
  175. if (!targetProp) {
  176. context.onError(
  177. createSSRCompilerError(66, node.loc)
  178. );
  179. return;
  180. }
  181. let target;
  182. if (targetProp.type === 6) {
  183. target = targetProp.value && compilerDom.createSimpleExpression(targetProp.value.content, true);
  184. } else {
  185. target = targetProp.exp;
  186. }
  187. if (!target) {
  188. context.onError(
  189. createSSRCompilerError(
  190. 66,
  191. targetProp.loc
  192. )
  193. );
  194. return;
  195. }
  196. const disabledProp = compilerDom.findProp(
  197. node,
  198. "disabled",
  199. false,
  200. true
  201. /* allow empty */
  202. );
  203. const disabled = disabledProp ? disabledProp.type === 6 ? `true` : disabledProp.exp || `false` : `false`;
  204. const contentRenderFn = compilerDom.createFunctionExpression(
  205. [`_push`],
  206. void 0,
  207. // Body is added later
  208. true,
  209. // newline
  210. false,
  211. // isSlot
  212. node.loc
  213. );
  214. contentRenderFn.body = processChildrenAsStatement(node, context);
  215. context.pushStatement(
  216. compilerDom.createCallExpression(context.helper(SSR_RENDER_TELEPORT), [
  217. `_push`,
  218. contentRenderFn,
  219. target,
  220. disabled,
  221. `_parent`
  222. ])
  223. );
  224. }
  225. const wipMap$3 = /* @__PURE__ */ new WeakMap();
  226. function ssrTransformSuspense(node, context) {
  227. return () => {
  228. if (node.children.length) {
  229. const wipEntry = {
  230. slotsExp: null,
  231. // to be immediately set
  232. wipSlots: []
  233. };
  234. wipMap$3.set(node, wipEntry);
  235. wipEntry.slotsExp = compilerDom.buildSlots(
  236. node,
  237. context,
  238. (_props, _vForExp, children, loc) => {
  239. const fn = compilerDom.createFunctionExpression(
  240. [],
  241. void 0,
  242. // no return, assign body later
  243. true,
  244. // newline
  245. false,
  246. // suspense slots are not treated as normal slots
  247. loc
  248. );
  249. wipEntry.wipSlots.push({
  250. fn,
  251. children
  252. });
  253. return fn;
  254. }
  255. ).slots;
  256. }
  257. };
  258. }
  259. function ssrProcessSuspense(node, context) {
  260. const wipEntry = wipMap$3.get(node);
  261. if (!wipEntry) {
  262. return;
  263. }
  264. const { slotsExp, wipSlots } = wipEntry;
  265. for (let i = 0; i < wipSlots.length; i++) {
  266. const slot = wipSlots[i];
  267. slot.fn.body = processChildrenAsStatement(slot, context);
  268. }
  269. context.pushStatement(
  270. compilerDom.createCallExpression(context.helper(SSR_RENDER_SUSPENSE), [
  271. `_push`,
  272. slotsExp
  273. ])
  274. );
  275. }
  276. const rawChildrenMap = /* @__PURE__ */ new WeakMap();
  277. const ssrTransformElement = (node, context) => {
  278. if (node.type !== 1 || node.tagType !== 0) {
  279. return;
  280. }
  281. return function ssrPostTransformElement() {
  282. const openTag = [`<${node.tag}`];
  283. const needTagForRuntime = node.tag === "textarea" || node.tag.indexOf("-") > 0;
  284. const hasDynamicVBind = compilerDom.hasDynamicKeyVBind(node);
  285. const hasCustomDir = node.props.some(
  286. (p) => p.type === 7 && !shared.isBuiltInDirective(p.name)
  287. );
  288. const needMergeProps = hasDynamicVBind || hasCustomDir;
  289. if (needMergeProps) {
  290. const { props, directives } = compilerDom.buildProps(
  291. node,
  292. context,
  293. node.props,
  294. false,
  295. false,
  296. true
  297. );
  298. if (props || directives.length) {
  299. const mergedProps = buildSSRProps(props, directives, context);
  300. const propsExp = compilerDom.createCallExpression(
  301. context.helper(SSR_RENDER_ATTRS),
  302. [mergedProps]
  303. );
  304. if (node.tag === "textarea") {
  305. const existingText = node.children[0];
  306. if (!existingText || existingText.type !== 5) {
  307. const tempId = `_temp${context.temps++}`;
  308. propsExp.arguments = [
  309. compilerDom.createAssignmentExpression(
  310. compilerDom.createSimpleExpression(tempId, false),
  311. mergedProps
  312. )
  313. ];
  314. rawChildrenMap.set(
  315. node,
  316. compilerDom.createCallExpression(context.helper(SSR_INTERPOLATE), [
  317. compilerDom.createConditionalExpression(
  318. compilerDom.createSimpleExpression(`"value" in ${tempId}`, false),
  319. compilerDom.createSimpleExpression(`${tempId}.value`, false),
  320. compilerDom.createSimpleExpression(
  321. existingText ? existingText.content : ``,
  322. true
  323. ),
  324. false
  325. )
  326. ])
  327. );
  328. }
  329. } else if (node.tag === "input") {
  330. const vModel = findVModel(node);
  331. if (vModel) {
  332. const tempId = `_temp${context.temps++}`;
  333. const tempExp = compilerDom.createSimpleExpression(tempId, false);
  334. propsExp.arguments = [
  335. compilerDom.createSequenceExpression([
  336. compilerDom.createAssignmentExpression(tempExp, mergedProps),
  337. compilerDom.createCallExpression(context.helper(compilerDom.MERGE_PROPS), [
  338. tempExp,
  339. compilerDom.createCallExpression(
  340. context.helper(SSR_GET_DYNAMIC_MODEL_PROPS),
  341. [
  342. tempExp,
  343. // existing props
  344. vModel.exp
  345. // model
  346. ]
  347. )
  348. ])
  349. ])
  350. ];
  351. }
  352. } else if (directives.length && !node.children.length) {
  353. const tempId = `_temp${context.temps++}`;
  354. propsExp.arguments = [
  355. compilerDom.createAssignmentExpression(
  356. compilerDom.createSimpleExpression(tempId, false),
  357. mergedProps
  358. )
  359. ];
  360. rawChildrenMap.set(
  361. node,
  362. compilerDom.createConditionalExpression(
  363. compilerDom.createSimpleExpression(`"textContent" in ${tempId}`, false),
  364. compilerDom.createCallExpression(context.helper(SSR_INTERPOLATE), [
  365. compilerDom.createSimpleExpression(`${tempId}.textContent`, false)
  366. ]),
  367. compilerDom.createSimpleExpression(`${tempId}.innerHTML ?? ''`, false),
  368. false
  369. )
  370. );
  371. }
  372. if (needTagForRuntime) {
  373. propsExp.arguments.push(`"${node.tag}"`);
  374. }
  375. openTag.push(propsExp);
  376. }
  377. }
  378. let dynamicClassBinding = void 0;
  379. let staticClassBinding = void 0;
  380. let dynamicStyleBinding = void 0;
  381. for (let i = 0; i < node.props.length; i++) {
  382. const prop = node.props[i];
  383. if (node.tag === "input" && isTrueFalseValue(prop)) {
  384. continue;
  385. }
  386. if (prop.type === 7) {
  387. if (prop.name === "html" && prop.exp) {
  388. rawChildrenMap.set(
  389. node,
  390. compilerDom.createCompoundExpression([`(`, prop.exp, `) ?? ''`])
  391. );
  392. } else if (prop.name === "text" && prop.exp) {
  393. node.children = [compilerDom.createInterpolation(prop.exp, prop.loc)];
  394. } else if (prop.name === "slot") {
  395. context.onError(
  396. compilerDom.createCompilerError(40, prop.loc)
  397. );
  398. } else if (isTextareaWithValue(node, prop) && prop.exp) {
  399. if (!needMergeProps) {
  400. node.children = [compilerDom.createInterpolation(prop.exp, prop.loc)];
  401. }
  402. } else if (!needMergeProps && prop.name !== "on") {
  403. const directiveTransform = context.directiveTransforms[prop.name];
  404. if (directiveTransform) {
  405. const { props, ssrTagParts } = directiveTransform(
  406. prop,
  407. node,
  408. context
  409. );
  410. if (ssrTagParts) {
  411. openTag.push(...ssrTagParts);
  412. }
  413. for (let j = 0; j < props.length; j++) {
  414. const { key, value } = props[j];
  415. if (compilerDom.isStaticExp(key)) {
  416. let attrName = key.content;
  417. if (attrName === "key" || attrName === "ref") {
  418. continue;
  419. }
  420. if (attrName === "class") {
  421. openTag.push(
  422. ` class="`,
  423. dynamicClassBinding = compilerDom.createCallExpression(
  424. context.helper(SSR_RENDER_CLASS),
  425. [value]
  426. ),
  427. `"`
  428. );
  429. } else if (attrName === "style") {
  430. if (dynamicStyleBinding) {
  431. mergeCall(dynamicStyleBinding, value);
  432. } else {
  433. openTag.push(
  434. ` style="`,
  435. dynamicStyleBinding = compilerDom.createCallExpression(
  436. context.helper(SSR_RENDER_STYLE),
  437. [value]
  438. ),
  439. `"`
  440. );
  441. }
  442. } else {
  443. attrName = node.tag.indexOf("-") > 0 ? attrName : shared.propsToAttrMap[attrName] || attrName.toLowerCase();
  444. if (shared.isBooleanAttr(attrName)) {
  445. openTag.push(
  446. compilerDom.createConditionalExpression(
  447. compilerDom.createCallExpression(
  448. context.helper(SSR_INCLUDE_BOOLEAN_ATTR),
  449. [value]
  450. ),
  451. compilerDom.createSimpleExpression(" " + attrName, true),
  452. compilerDom.createSimpleExpression("", true),
  453. false
  454. )
  455. );
  456. } else if (shared.isSSRSafeAttrName(attrName)) {
  457. openTag.push(
  458. compilerDom.createCallExpression(context.helper(SSR_RENDER_ATTR), [
  459. key,
  460. value
  461. ])
  462. );
  463. } else {
  464. context.onError(
  465. createSSRCompilerError(
  466. 65,
  467. key.loc
  468. )
  469. );
  470. }
  471. }
  472. } else {
  473. const args = [key, value];
  474. if (needTagForRuntime) {
  475. args.push(`"${node.tag}"`);
  476. }
  477. openTag.push(
  478. compilerDom.createCallExpression(
  479. context.helper(SSR_RENDER_DYNAMIC_ATTR),
  480. args
  481. )
  482. );
  483. }
  484. }
  485. }
  486. }
  487. } else {
  488. const name = prop.name;
  489. if (node.tag === "textarea" && name === "value" && prop.value) {
  490. rawChildrenMap.set(node, shared.escapeHtml(prop.value.content));
  491. } else if (!needMergeProps) {
  492. if (name === "key" || name === "ref") {
  493. continue;
  494. }
  495. if (name === "class" && prop.value) {
  496. staticClassBinding = JSON.stringify(prop.value.content);
  497. }
  498. openTag.push(
  499. ` ${prop.name}` + (prop.value ? `="${shared.escapeHtml(prop.value.content)}"` : ``)
  500. );
  501. }
  502. }
  503. }
  504. if (dynamicClassBinding && staticClassBinding) {
  505. mergeCall(dynamicClassBinding, staticClassBinding);
  506. removeStaticBinding(openTag, "class");
  507. }
  508. if (context.scopeId) {
  509. openTag.push(` ${context.scopeId}`);
  510. }
  511. node.ssrCodegenNode = compilerDom.createTemplateLiteral(openTag);
  512. };
  513. };
  514. function buildSSRProps(props, directives, context) {
  515. let mergePropsArgs = [];
  516. if (props) {
  517. if (props.type === 14) {
  518. mergePropsArgs = props.arguments;
  519. } else {
  520. mergePropsArgs.push(props);
  521. }
  522. }
  523. if (directives.length) {
  524. for (const dir of directives) {
  525. mergePropsArgs.push(
  526. compilerDom.createCallExpression(context.helper(SSR_GET_DIRECTIVE_PROPS), [
  527. `_ctx`,
  528. ...compilerDom.buildDirectiveArgs(dir, context).elements
  529. ])
  530. );
  531. }
  532. }
  533. return mergePropsArgs.length > 1 ? compilerDom.createCallExpression(context.helper(compilerDom.MERGE_PROPS), mergePropsArgs) : mergePropsArgs[0];
  534. }
  535. function isTrueFalseValue(prop) {
  536. if (prop.type === 7) {
  537. return prop.name === "bind" && prop.arg && compilerDom.isStaticExp(prop.arg) && (prop.arg.content === "true-value" || prop.arg.content === "false-value");
  538. } else {
  539. return prop.name === "true-value" || prop.name === "false-value";
  540. }
  541. }
  542. function isTextareaWithValue(node, prop) {
  543. return !!(node.tag === "textarea" && prop.name === "bind" && compilerDom.isStaticArgOf(prop.arg, "value"));
  544. }
  545. function mergeCall(call, arg) {
  546. const existing = call.arguments[0];
  547. if (existing.type === 17) {
  548. existing.elements.push(arg);
  549. } else {
  550. call.arguments[0] = compilerDom.createArrayExpression([existing, arg]);
  551. }
  552. }
  553. function removeStaticBinding(tag, binding) {
  554. const regExp = new RegExp(`^ ${binding}=".+"$`);
  555. const i = tag.findIndex((e) => typeof e === "string" && regExp.test(e));
  556. if (i > -1) {
  557. tag.splice(i, 1);
  558. }
  559. }
  560. function findVModel(node) {
  561. return node.props.find(
  562. (p) => p.type === 7 && p.name === "model" && p.exp
  563. );
  564. }
  565. function ssrProcessElement(node, context) {
  566. const isVoidTag = context.options.isVoidTag || shared.NO;
  567. const elementsToAdd = node.ssrCodegenNode.elements;
  568. for (let j = 0; j < elementsToAdd.length; j++) {
  569. context.pushStringPart(elementsToAdd[j]);
  570. }
  571. if (context.withSlotScopeId) {
  572. context.pushStringPart(compilerDom.createSimpleExpression(`_scopeId`, false));
  573. }
  574. context.pushStringPart(`>`);
  575. const rawChildren = rawChildrenMap.get(node);
  576. if (rawChildren) {
  577. context.pushStringPart(rawChildren);
  578. } else if (node.children.length) {
  579. processChildren(node, context);
  580. }
  581. if (!isVoidTag(node.tag)) {
  582. context.pushStringPart(`</${node.tag}>`);
  583. }
  584. }
  585. const wipMap$2 = /* @__PURE__ */ new WeakMap();
  586. function ssrTransformTransitionGroup(node, context) {
  587. return () => {
  588. const tag = compilerDom.findProp(node, "tag");
  589. if (tag) {
  590. const otherProps = node.props.filter((p) => p !== tag);
  591. const { props, directives } = compilerDom.buildProps(
  592. node,
  593. context,
  594. otherProps,
  595. true,
  596. false,
  597. true
  598. );
  599. let propsExp = null;
  600. if (props || directives.length) {
  601. propsExp = compilerDom.createCallExpression(context.helper(SSR_RENDER_ATTRS), [
  602. buildSSRProps(props, directives, context)
  603. ]);
  604. }
  605. wipMap$2.set(node, {
  606. tag,
  607. propsExp,
  608. scopeId: context.scopeId || null
  609. });
  610. }
  611. };
  612. }
  613. function ssrProcessTransitionGroup(node, context) {
  614. const entry = wipMap$2.get(node);
  615. if (entry) {
  616. const { tag, propsExp, scopeId } = entry;
  617. if (tag.type === 7) {
  618. context.pushStringPart(`<`);
  619. context.pushStringPart(tag.exp);
  620. if (propsExp) {
  621. context.pushStringPart(propsExp);
  622. }
  623. if (scopeId) {
  624. context.pushStringPart(` ${scopeId}`);
  625. }
  626. context.pushStringPart(`>`);
  627. processChildren(
  628. node,
  629. context,
  630. false,
  631. /**
  632. * TransitionGroup has the special runtime behavior of flattening and
  633. * concatenating all children into a single fragment (in order for them to
  634. * be patched using the same key map) so we need to account for that here
  635. * by disabling nested fragment wrappers from being generated.
  636. */
  637. true,
  638. /**
  639. * TransitionGroup filters out comment children at runtime and thus
  640. * doesn't expect comments to be present during hydration. We need to
  641. * account for that by disabling the empty comment that is otherwise
  642. * rendered for a falsy v-if that has no v-else specified. (#6715)
  643. */
  644. true
  645. );
  646. context.pushStringPart(`</`);
  647. context.pushStringPart(tag.exp);
  648. context.pushStringPart(`>`);
  649. } else {
  650. context.pushStringPart(`<${tag.value.content}`);
  651. if (propsExp) {
  652. context.pushStringPart(propsExp);
  653. }
  654. if (scopeId) {
  655. context.pushStringPart(` ${scopeId}`);
  656. }
  657. context.pushStringPart(`>`);
  658. processChildren(node, context, false, true, true);
  659. context.pushStringPart(`</${tag.value.content}>`);
  660. }
  661. } else {
  662. processChildren(node, context, true, true, true);
  663. }
  664. }
  665. const wipMap$1 = /* @__PURE__ */ new WeakMap();
  666. function ssrTransformTransition(node, context) {
  667. return () => {
  668. const appear = compilerDom.findProp(node, "appear", false, true);
  669. wipMap$1.set(node, !!appear);
  670. };
  671. }
  672. function ssrProcessTransition(node, context) {
  673. node.children = node.children.filter((c) => c.type !== 3);
  674. const appear = wipMap$1.get(node);
  675. if (appear) {
  676. context.pushStringPart(`<template>`);
  677. processChildren(node, context, false, true);
  678. context.pushStringPart(`</template>`);
  679. } else {
  680. processChildren(node, context, false, true);
  681. }
  682. }
  683. const wipMap = /* @__PURE__ */ new WeakMap();
  684. const WIP_SLOT = Symbol();
  685. const componentTypeMap = /* @__PURE__ */ new WeakMap();
  686. const ssrTransformComponent = (node, context) => {
  687. if (node.type !== 1 || node.tagType !== 1) {
  688. return;
  689. }
  690. const component = compilerDom.resolveComponentType(
  691. node,
  692. context,
  693. true
  694. /* ssr */
  695. );
  696. const isDynamicComponent = shared.isObject(component) && component.callee === compilerDom.RESOLVE_DYNAMIC_COMPONENT;
  697. componentTypeMap.set(node, component);
  698. if (shared.isSymbol(component)) {
  699. if (component === compilerDom.SUSPENSE) {
  700. return ssrTransformSuspense(node, context);
  701. } else if (component === compilerDom.TRANSITION_GROUP) {
  702. return ssrTransformTransitionGroup(node, context);
  703. } else if (component === compilerDom.TRANSITION) {
  704. return ssrTransformTransition(node);
  705. }
  706. return;
  707. }
  708. const vnodeBranches = [];
  709. const clonedNode = clone(node);
  710. return function ssrPostTransformComponent() {
  711. if (clonedNode.children.length) {
  712. compilerDom.buildSlots(clonedNode, context, (props, vFor, children) => {
  713. vnodeBranches.push(
  714. createVNodeSlotBranch(props, vFor, children, context)
  715. );
  716. return compilerDom.createFunctionExpression(void 0);
  717. });
  718. }
  719. let propsExp = `null`;
  720. if (node.props.length) {
  721. const { props, directives } = compilerDom.buildProps(
  722. node,
  723. context,
  724. void 0,
  725. true,
  726. isDynamicComponent
  727. );
  728. if (props || directives.length) {
  729. propsExp = buildSSRProps(props, directives, context);
  730. }
  731. }
  732. const wipEntries = [];
  733. wipMap.set(node, wipEntries);
  734. const buildSSRSlotFn = (props, _vForExp, children, loc) => {
  735. const param0 = props && compilerDom.stringifyExpression(props) || `_`;
  736. const fn = compilerDom.createFunctionExpression(
  737. [param0, `_push`, `_parent`, `_scopeId`],
  738. void 0,
  739. // no return, assign body later
  740. true,
  741. // newline
  742. true,
  743. // isSlot
  744. loc
  745. );
  746. wipEntries.push({
  747. type: WIP_SLOT,
  748. fn,
  749. children,
  750. // also collect the corresponding vnode branch built earlier
  751. vnodeBranch: vnodeBranches[wipEntries.length]
  752. });
  753. return fn;
  754. };
  755. const slots = node.children.length ? compilerDom.buildSlots(node, context, buildSSRSlotFn).slots : `null`;
  756. if (typeof component !== "string") {
  757. node.ssrCodegenNode = compilerDom.createCallExpression(
  758. context.helper(SSR_RENDER_VNODE),
  759. [
  760. `_push`,
  761. compilerDom.createCallExpression(context.helper(compilerDom.CREATE_VNODE), [
  762. component,
  763. propsExp,
  764. slots
  765. ]),
  766. `_parent`
  767. ]
  768. );
  769. } else {
  770. node.ssrCodegenNode = compilerDom.createCallExpression(
  771. context.helper(SSR_RENDER_COMPONENT),
  772. [component, propsExp, slots, `_parent`]
  773. );
  774. }
  775. };
  776. };
  777. function ssrProcessComponent(node, context, parent) {
  778. const component = componentTypeMap.get(node);
  779. if (!node.ssrCodegenNode) {
  780. if (component === compilerDom.TELEPORT) {
  781. return ssrProcessTeleport(node, context);
  782. } else if (component === compilerDom.SUSPENSE) {
  783. return ssrProcessSuspense(node, context);
  784. } else if (component === compilerDom.TRANSITION_GROUP) {
  785. return ssrProcessTransitionGroup(node, context);
  786. } else {
  787. if (parent.type === WIP_SLOT) {
  788. context.pushStringPart(``);
  789. }
  790. if (component === compilerDom.TRANSITION) {
  791. return ssrProcessTransition(node, context);
  792. }
  793. processChildren(node, context);
  794. }
  795. } else {
  796. const wipEntries = wipMap.get(node) || [];
  797. for (let i = 0; i < wipEntries.length; i++) {
  798. const { fn, vnodeBranch } = wipEntries[i];
  799. fn.body = compilerDom.createIfStatement(
  800. compilerDom.createSimpleExpression(`_push`, false),
  801. processChildrenAsStatement(
  802. wipEntries[i],
  803. context,
  804. false,
  805. true
  806. ),
  807. vnodeBranch
  808. );
  809. }
  810. if (context.withSlotScopeId) {
  811. node.ssrCodegenNode.arguments.push(`_scopeId`);
  812. }
  813. if (typeof component === "string") {
  814. context.pushStatement(
  815. compilerDom.createCallExpression(`_push`, [node.ssrCodegenNode])
  816. );
  817. } else {
  818. context.pushStatement(node.ssrCodegenNode);
  819. }
  820. }
  821. }
  822. const rawOptionsMap = /* @__PURE__ */ new WeakMap();
  823. const [baseNodeTransforms, baseDirectiveTransforms] = compilerDom.getBaseTransformPreset(true);
  824. const vnodeNodeTransforms = [...baseNodeTransforms, ...compilerDom.DOMNodeTransforms];
  825. const vnodeDirectiveTransforms = {
  826. ...baseDirectiveTransforms,
  827. ...compilerDom.DOMDirectiveTransforms
  828. };
  829. function createVNodeSlotBranch(slotProps, vFor, children, parentContext) {
  830. const rawOptions = rawOptionsMap.get(parentContext.root);
  831. const subOptions = {
  832. ...rawOptions,
  833. // overwrite with vnode-based transforms
  834. nodeTransforms: [
  835. ...vnodeNodeTransforms,
  836. ...rawOptions.nodeTransforms || []
  837. ],
  838. directiveTransforms: {
  839. ...vnodeDirectiveTransforms,
  840. ...rawOptions.directiveTransforms || {}
  841. }
  842. };
  843. const wrapperProps = [];
  844. if (slotProps) {
  845. wrapperProps.push({
  846. type: 7,
  847. name: "slot",
  848. exp: slotProps,
  849. arg: void 0,
  850. modifiers: [],
  851. loc: compilerDom.locStub
  852. });
  853. }
  854. if (vFor) {
  855. wrapperProps.push(shared.extend({}, vFor));
  856. }
  857. const wrapperNode = {
  858. type: 1,
  859. ns: 0,
  860. tag: "template",
  861. tagType: 3,
  862. props: wrapperProps,
  863. children,
  864. loc: compilerDom.locStub,
  865. codegenNode: void 0
  866. };
  867. subTransform(wrapperNode, subOptions, parentContext);
  868. return compilerDom.createReturnStatement(children);
  869. }
  870. function subTransform(node, options, parentContext) {
  871. const childRoot = compilerDom.createRoot([node]);
  872. const childContext = compilerDom.createTransformContext(childRoot, options);
  873. childContext.ssr = false;
  874. childContext.scopes = { ...parentContext.scopes };
  875. childContext.identifiers = { ...parentContext.identifiers };
  876. childContext.imports = parentContext.imports;
  877. compilerDom.traverseNode(childRoot, childContext);
  878. ["helpers", "components", "directives"].forEach((key) => {
  879. childContext[key].forEach((value, helperKey) => {
  880. if (key === "helpers") {
  881. const parentCount = parentContext.helpers.get(helperKey);
  882. if (parentCount === void 0) {
  883. parentContext.helpers.set(helperKey, value);
  884. } else {
  885. parentContext.helpers.set(helperKey, value + parentCount);
  886. }
  887. } else {
  888. parentContext[key].add(value);
  889. }
  890. });
  891. });
  892. }
  893. function clone(v) {
  894. if (shared.isArray(v)) {
  895. return v.map(clone);
  896. } else if (shared.isPlainObject(v)) {
  897. const res = {};
  898. for (const key in v) {
  899. res[key] = clone(v[key]);
  900. }
  901. return res;
  902. } else {
  903. return v;
  904. }
  905. }
  906. function ssrCodegenTransform(ast, options) {
  907. const context = createSSRTransformContext(ast, options);
  908. if (options.ssrCssVars) {
  909. const cssContext = compilerDom.createTransformContext(compilerDom.createRoot([]), options);
  910. const varsExp = compilerDom.processExpression(
  911. compilerDom.createSimpleExpression(options.ssrCssVars, false),
  912. cssContext
  913. );
  914. context.body.push(
  915. compilerDom.createCompoundExpression([`const _cssVars = { style: `, varsExp, `}`])
  916. );
  917. Array.from(cssContext.helpers.keys()).forEach((helper) => {
  918. ast.helpers.add(helper);
  919. });
  920. }
  921. const isFragment = ast.children.length > 1 && ast.children.some((c) => !compilerDom.isText(c));
  922. processChildren(ast, context, isFragment);
  923. ast.codegenNode = compilerDom.createBlockStatement(context.body);
  924. ast.ssrHelpers = Array.from(
  925. /* @__PURE__ */ new Set([
  926. ...Array.from(ast.helpers).filter((h) => h in ssrHelpers),
  927. ...context.helpers
  928. ])
  929. );
  930. ast.helpers = new Set(Array.from(ast.helpers).filter((h) => !(h in ssrHelpers)));
  931. }
  932. function createSSRTransformContext(root, options, helpers = /* @__PURE__ */ new Set(), withSlotScopeId = false) {
  933. const body = [];
  934. let currentString = null;
  935. return {
  936. root,
  937. options,
  938. body,
  939. helpers,
  940. withSlotScopeId,
  941. onError: options.onError || ((e) => {
  942. throw e;
  943. }),
  944. helper(name) {
  945. helpers.add(name);
  946. return name;
  947. },
  948. pushStringPart(part) {
  949. if (!currentString) {
  950. const currentCall = compilerDom.createCallExpression(`_push`);
  951. body.push(currentCall);
  952. currentString = compilerDom.createTemplateLiteral([]);
  953. currentCall.arguments.push(currentString);
  954. }
  955. const bufferedElements = currentString.elements;
  956. const lastItem = bufferedElements[bufferedElements.length - 1];
  957. if (shared.isString(part) && shared.isString(lastItem)) {
  958. bufferedElements[bufferedElements.length - 1] += part;
  959. } else {
  960. bufferedElements.push(part);
  961. }
  962. },
  963. pushStatement(statement) {
  964. currentString = null;
  965. body.push(statement);
  966. }
  967. };
  968. }
  969. function createChildContext(parent, withSlotScopeId = parent.withSlotScopeId) {
  970. return createSSRTransformContext(
  971. parent.root,
  972. parent.options,
  973. parent.helpers,
  974. withSlotScopeId
  975. );
  976. }
  977. function processChildren(parent, context, asFragment = false, disableNestedFragments = false, disableCommentAsIfAlternate = false) {
  978. if (asFragment) {
  979. context.pushStringPart(`<!--[-->`);
  980. }
  981. const { children } = parent;
  982. for (let i = 0; i < children.length; i++) {
  983. const child = children[i];
  984. switch (child.type) {
  985. case 1:
  986. switch (child.tagType) {
  987. case 0:
  988. ssrProcessElement(child, context);
  989. break;
  990. case 1:
  991. ssrProcessComponent(child, context, parent);
  992. break;
  993. case 2:
  994. ssrProcessSlotOutlet(child, context);
  995. break;
  996. case 3:
  997. break;
  998. default:
  999. context.onError(
  1000. createSSRCompilerError(
  1001. 67,
  1002. child.loc
  1003. )
  1004. );
  1005. const exhaustiveCheck2 = child;
  1006. return exhaustiveCheck2;
  1007. }
  1008. break;
  1009. case 2:
  1010. context.pushStringPart(shared.escapeHtml(child.content));
  1011. break;
  1012. case 3:
  1013. context.pushStringPart(`<!--${child.content}-->`);
  1014. break;
  1015. case 5:
  1016. context.pushStringPart(
  1017. compilerDom.createCallExpression(context.helper(SSR_INTERPOLATE), [
  1018. child.content
  1019. ])
  1020. );
  1021. break;
  1022. case 9:
  1023. ssrProcessIf(
  1024. child,
  1025. context,
  1026. disableNestedFragments,
  1027. disableCommentAsIfAlternate
  1028. );
  1029. break;
  1030. case 11:
  1031. ssrProcessFor(child, context, disableNestedFragments);
  1032. break;
  1033. case 10:
  1034. break;
  1035. case 12:
  1036. case 8:
  1037. break;
  1038. default:
  1039. context.onError(
  1040. createSSRCompilerError(
  1041. 67,
  1042. child.loc
  1043. )
  1044. );
  1045. const exhaustiveCheck = child;
  1046. return exhaustiveCheck;
  1047. }
  1048. }
  1049. if (asFragment) {
  1050. context.pushStringPart(`<!--]-->`);
  1051. }
  1052. }
  1053. function processChildrenAsStatement(parent, parentContext, asFragment = false, withSlotScopeId = parentContext.withSlotScopeId) {
  1054. const childContext = createChildContext(parentContext, withSlotScopeId);
  1055. processChildren(parent, childContext, asFragment);
  1056. return compilerDom.createBlockStatement(childContext.body);
  1057. }
  1058. const ssrTransformModel = (dir, node, context) => {
  1059. const model = dir.exp;
  1060. function checkDuplicatedValue() {
  1061. const value = compilerDom.findProp(node, "value");
  1062. if (value) {
  1063. context.onError(
  1064. compilerDom.createDOMCompilerError(
  1065. 60,
  1066. value.loc
  1067. )
  1068. );
  1069. }
  1070. }
  1071. function processOption(plainNode) {
  1072. if (plainNode.tag === "option") {
  1073. if (plainNode.props.findIndex((p) => p.name === "selected") === -1) {
  1074. const value = findValueBinding(plainNode);
  1075. plainNode.ssrCodegenNode.elements.push(
  1076. compilerDom.createConditionalExpression(
  1077. compilerDom.createCallExpression(context.helper(SSR_INCLUDE_BOOLEAN_ATTR), [
  1078. compilerDom.createConditionalExpression(
  1079. compilerDom.createCallExpression(`Array.isArray`, [model]),
  1080. compilerDom.createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  1081. model,
  1082. value
  1083. ]),
  1084. compilerDom.createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  1085. model,
  1086. value
  1087. ])
  1088. )
  1089. ]),
  1090. compilerDom.createSimpleExpression(" selected", true),
  1091. compilerDom.createSimpleExpression("", true),
  1092. false
  1093. )
  1094. );
  1095. }
  1096. } else if (plainNode.tag === "optgroup") {
  1097. plainNode.children.forEach(
  1098. (option) => processOption(option)
  1099. );
  1100. }
  1101. }
  1102. if (node.tagType === 0) {
  1103. const res = { props: [] };
  1104. const defaultProps = [
  1105. // default value binding for text type inputs
  1106. compilerDom.createObjectProperty(`value`, model)
  1107. ];
  1108. if (node.tag === "input") {
  1109. const type = compilerDom.findProp(node, "type");
  1110. if (type) {
  1111. const value = findValueBinding(node);
  1112. if (type.type === 7) {
  1113. res.ssrTagParts = [
  1114. compilerDom.createCallExpression(context.helper(SSR_RENDER_DYNAMIC_MODEL), [
  1115. type.exp,
  1116. model,
  1117. value
  1118. ])
  1119. ];
  1120. } else if (type.value) {
  1121. switch (type.value.content) {
  1122. case "radio":
  1123. res.props = [
  1124. compilerDom.createObjectProperty(
  1125. `checked`,
  1126. compilerDom.createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  1127. model,
  1128. value
  1129. ])
  1130. )
  1131. ];
  1132. break;
  1133. case "checkbox":
  1134. const trueValueBinding = compilerDom.findProp(node, "true-value");
  1135. if (trueValueBinding) {
  1136. const trueValue = trueValueBinding.type === 6 ? JSON.stringify(trueValueBinding.value.content) : trueValueBinding.exp;
  1137. res.props = [
  1138. compilerDom.createObjectProperty(
  1139. `checked`,
  1140. compilerDom.createCallExpression(context.helper(SSR_LOOSE_EQUAL), [
  1141. model,
  1142. trueValue
  1143. ])
  1144. )
  1145. ];
  1146. } else {
  1147. res.props = [
  1148. compilerDom.createObjectProperty(
  1149. `checked`,
  1150. compilerDom.createConditionalExpression(
  1151. compilerDom.createCallExpression(`Array.isArray`, [model]),
  1152. compilerDom.createCallExpression(context.helper(SSR_LOOSE_CONTAIN), [
  1153. model,
  1154. value
  1155. ]),
  1156. model
  1157. )
  1158. )
  1159. ];
  1160. }
  1161. break;
  1162. case "file":
  1163. context.onError(
  1164. compilerDom.createDOMCompilerError(
  1165. 59,
  1166. dir.loc
  1167. )
  1168. );
  1169. break;
  1170. default:
  1171. checkDuplicatedValue();
  1172. res.props = defaultProps;
  1173. break;
  1174. }
  1175. }
  1176. } else if (compilerDom.hasDynamicKeyVBind(node)) ; else {
  1177. checkDuplicatedValue();
  1178. res.props = defaultProps;
  1179. }
  1180. } else if (node.tag === "textarea") {
  1181. checkDuplicatedValue();
  1182. node.children = [compilerDom.createInterpolation(model, model.loc)];
  1183. } else if (node.tag === "select") {
  1184. node.children.forEach((child) => {
  1185. if (child.type === 1) {
  1186. processOption(child);
  1187. }
  1188. });
  1189. } else {
  1190. context.onError(
  1191. compilerDom.createDOMCompilerError(
  1192. 57,
  1193. dir.loc
  1194. )
  1195. );
  1196. }
  1197. return res;
  1198. } else {
  1199. return compilerDom.transformModel(dir, node, context);
  1200. }
  1201. };
  1202. function findValueBinding(node) {
  1203. const valueBinding = compilerDom.findProp(node, "value");
  1204. return valueBinding ? valueBinding.type === 7 ? valueBinding.exp : compilerDom.createSimpleExpression(valueBinding.value.content, true) : compilerDom.createSimpleExpression(`null`, false);
  1205. }
  1206. const ssrTransformShow = (dir, node, context) => {
  1207. if (!dir.exp) {
  1208. context.onError(
  1209. compilerDom.createDOMCompilerError(61)
  1210. );
  1211. }
  1212. return {
  1213. props: [
  1214. compilerDom.createObjectProperty(
  1215. `style`,
  1216. compilerDom.createConditionalExpression(
  1217. dir.exp,
  1218. compilerDom.createSimpleExpression(`null`, false),
  1219. compilerDom.createObjectExpression([
  1220. compilerDom.createObjectProperty(
  1221. `display`,
  1222. compilerDom.createSimpleExpression(`none`, true)
  1223. )
  1224. ]),
  1225. false
  1226. )
  1227. )
  1228. ]
  1229. };
  1230. };
  1231. const filterChild = (node) => node.children.filter((n) => n.type !== 3);
  1232. const hasSingleChild = (node) => filterChild(node).length === 1;
  1233. const ssrInjectFallthroughAttrs = (node, context) => {
  1234. if (node.type === 0) {
  1235. context.identifiers._attrs = 1;
  1236. }
  1237. if (node.type === 1 && node.tagType === 1 && (node.tag === "transition" || node.tag === "Transition" || node.tag === "KeepAlive" || node.tag === "keep-alive")) {
  1238. const rootChildren = filterChild(context.root);
  1239. if (rootChildren.length === 1 && rootChildren[0] === node) {
  1240. if (hasSingleChild(node)) {
  1241. injectFallthroughAttrs(node.children[0]);
  1242. }
  1243. return;
  1244. }
  1245. }
  1246. const parent = context.parent;
  1247. if (!parent || parent.type !== 0) {
  1248. return;
  1249. }
  1250. if (node.type === 10 && hasSingleChild(node)) {
  1251. let hasEncounteredIf = false;
  1252. for (const c of filterChild(parent)) {
  1253. if (c.type === 9 || c.type === 1 && compilerDom.findDir(c, "if")) {
  1254. if (hasEncounteredIf) return;
  1255. hasEncounteredIf = true;
  1256. } else if (
  1257. // node before v-if
  1258. !hasEncounteredIf || // non else nodes
  1259. !(c.type === 1 && compilerDom.findDir(c, /else/, true))
  1260. ) {
  1261. return;
  1262. }
  1263. }
  1264. injectFallthroughAttrs(node.children[0]);
  1265. } else if (hasSingleChild(parent)) {
  1266. injectFallthroughAttrs(node);
  1267. }
  1268. };
  1269. function injectFallthroughAttrs(node) {
  1270. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !compilerDom.findDir(node, "for")) {
  1271. node.props.push({
  1272. type: 7,
  1273. name: "bind",
  1274. arg: void 0,
  1275. exp: compilerDom.createSimpleExpression(`_attrs`, false),
  1276. modifiers: [],
  1277. loc: compilerDom.locStub
  1278. });
  1279. }
  1280. }
  1281. const ssrInjectCssVars = (node, context) => {
  1282. if (!context.ssrCssVars) {
  1283. return;
  1284. }
  1285. if (node.type === 0) {
  1286. context.identifiers._cssVars = 1;
  1287. }
  1288. const parent = context.parent;
  1289. if (!parent || parent.type !== 0) {
  1290. return;
  1291. }
  1292. if (node.type === 10) {
  1293. for (const child of node.children) {
  1294. injectCssVars(child);
  1295. }
  1296. } else {
  1297. injectCssVars(node);
  1298. }
  1299. };
  1300. function injectCssVars(node) {
  1301. if (node.type === 1 && (node.tagType === 0 || node.tagType === 1) && !compilerDom.findDir(node, "for")) {
  1302. if (node.tag === "suspense" || node.tag === "Suspense") {
  1303. for (const child of node.children) {
  1304. if (child.type === 1 && child.tagType === 3) {
  1305. child.children.forEach(injectCssVars);
  1306. } else {
  1307. injectCssVars(child);
  1308. }
  1309. }
  1310. } else {
  1311. node.props.push({
  1312. type: 7,
  1313. name: "bind",
  1314. arg: void 0,
  1315. exp: compilerDom.createSimpleExpression(`_cssVars`, false),
  1316. modifiers: [],
  1317. loc: compilerDom.locStub
  1318. });
  1319. }
  1320. }
  1321. }
  1322. function compile(source, options = {}) {
  1323. options = {
  1324. ...options,
  1325. ...compilerDom.parserOptions,
  1326. ssr: true,
  1327. inSSR: true,
  1328. scopeId: options.mode === "function" ? null : options.scopeId,
  1329. // always prefix since compiler-ssr doesn't have size concern
  1330. prefixIdentifiers: true,
  1331. // disable optimizations that are unnecessary for ssr
  1332. cacheHandlers: false,
  1333. hoistStatic: false
  1334. };
  1335. const ast = typeof source === "string" ? compilerDom.baseParse(source, options) : source;
  1336. rawOptionsMap.set(ast, options);
  1337. compilerDom.transform(ast, {
  1338. ...options,
  1339. hoistStatic: false,
  1340. nodeTransforms: [
  1341. ssrTransformIf,
  1342. ssrTransformFor,
  1343. compilerDom.trackVForSlotScopes,
  1344. compilerDom.transformExpression,
  1345. ssrTransformSlotOutlet,
  1346. ssrInjectFallthroughAttrs,
  1347. ssrInjectCssVars,
  1348. ssrTransformElement,
  1349. ssrTransformComponent,
  1350. compilerDom.trackSlotScopes,
  1351. compilerDom.transformStyle,
  1352. ...options.nodeTransforms || []
  1353. // user transforms
  1354. ],
  1355. directiveTransforms: {
  1356. // reusing core v-bind
  1357. bind: compilerDom.transformBind,
  1358. on: compilerDom.transformOn,
  1359. // model and show have dedicated SSR handling
  1360. model: ssrTransformModel,
  1361. show: ssrTransformShow,
  1362. // the following are ignored during SSR
  1363. // on: noopDirectiveTransform,
  1364. cloak: compilerDom.noopDirectiveTransform,
  1365. once: compilerDom.noopDirectiveTransform,
  1366. memo: compilerDom.noopDirectiveTransform,
  1367. ...options.directiveTransforms || {}
  1368. // user transforms
  1369. }
  1370. });
  1371. ssrCodegenTransform(ast, options);
  1372. return compilerDom.generate(ast, options);
  1373. }
  1374. exports.compile = compile;