@vue/compiler-vapor 3.6.0-alpha.2 → 3.6.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @vue/compiler-vapor v3.6.0-alpha.2
2
+ * @vue/compiler-vapor v3.6.0-alpha.3
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -25,7 +25,8 @@ const newBlock = (node) => ({
25
25
  effect: [],
26
26
  operation: [],
27
27
  returns: [],
28
- tempId: 0
28
+ tempId: 0,
29
+ hasDeferredVShow: false
29
30
  });
30
31
  function wrapTemplate(node, dirs) {
31
32
  if (node.tagType === 3) {
@@ -89,6 +90,40 @@ function getLiteralExpressionValue(exp) {
89
90
  }
90
91
  return exp.isStatic ? exp.content : null;
91
92
  }
93
+ function isInTransition(context) {
94
+ const parentNode = context.parent && context.parent.node;
95
+ return !!(parentNode && isTransitionNode(parentNode));
96
+ }
97
+ function isTransitionNode(node) {
98
+ return node.type === 1 && isTransitionTag(node.tag);
99
+ }
100
+ function isTransitionTag(tag) {
101
+ tag = tag.toLowerCase();
102
+ return tag === "transition" || tag === "vaportransition";
103
+ }
104
+ function isTransitionGroupTag(tag) {
105
+ tag = tag.toLowerCase().replace(/-/g, "");
106
+ return tag === "transitiongroup" || tag === "vaportransitiongroup";
107
+ }
108
+ function isKeepAliveTag(tag) {
109
+ tag = tag.toLowerCase();
110
+ return tag === "keepalive" || tag === "vaporkeepalive";
111
+ }
112
+ function isTeleportTag(tag) {
113
+ tag = tag.toLowerCase();
114
+ return tag === "teleport" || tag === "vaporteleport";
115
+ }
116
+ function isBuiltInComponent(tag) {
117
+ if (isTeleportTag(tag)) {
118
+ return "VaporTeleport";
119
+ } else if (isKeepAliveTag(tag)) {
120
+ return "VaporKeepAlive";
121
+ } else if (isTransitionTag(tag)) {
122
+ return "VaporTransition";
123
+ } else if (isTransitionGroupTag(tag)) {
124
+ return "VaporTransitionGroup";
125
+ }
126
+ }
92
127
 
93
128
  class TransformContext {
94
129
  constructor(ir, node, options = {}) {
@@ -301,13 +336,13 @@ const DELIMITERS_ARRAY = ["[", "]", ", "];
301
336
  const DELIMITERS_ARRAY_NEWLINE = [
302
337
  ["[", INDENT_START, NEWLINE],
303
338
  [INDENT_END, NEWLINE, "]"],
304
- [", ", NEWLINE]
339
+ [",", NEWLINE]
305
340
  ];
306
341
  const DELIMITERS_OBJECT = ["{ ", " }", ", "];
307
342
  const DELIMITERS_OBJECT_NEWLINE = [
308
343
  ["{", INDENT_START, NEWLINE],
309
344
  [INDENT_END, NEWLINE, "}"],
310
- [", ", NEWLINE]
345
+ [",", NEWLINE]
311
346
  ];
312
347
  function genCall(name, ...frags) {
313
348
  const hasPlaceholder = shared.isArray(name);
@@ -1423,10 +1458,15 @@ function isKeyOnlyBinding(expr, keyAst) {
1423
1458
 
1424
1459
  function genSetHtml(oper, context) {
1425
1460
  const { helper } = context;
1426
- const { value, element } = oper;
1461
+ const { value, element, isComponent } = oper;
1427
1462
  return [
1428
1463
  NEWLINE,
1429
- ...genCall(helper("setHtml"), `n${element}`, genExpression(value, context))
1464
+ ...genCall(
1465
+ // use setBlockHtml for component
1466
+ isComponent ? helper("setBlockHtml") : helper("setHtml"),
1467
+ `n${element}`,
1468
+ genExpression(value, context)
1469
+ )
1430
1470
  ];
1431
1471
  }
1432
1472
 
@@ -1515,7 +1555,7 @@ function genLiteralObjectProps(props, context) {
1515
1555
  }
1516
1556
  function genPropKey({ key: node, modifier, runtimeCamelize, handler, handlerModifiers }, context) {
1517
1557
  const { helper } = context;
1518
- const handlerModifierPostfix = handlerModifiers ? handlerModifiers.map(shared.capitalize).join("") : "";
1558
+ const handlerModifierPostfix = handlerModifiers && handlerModifiers.options ? handlerModifiers.options.map(shared.capitalize).join("") : "";
1519
1559
  if (node.isStatic) {
1520
1560
  const keyName = (handler ? shared.toHandlerKey(node.content) : node.content) + handlerModifierPostfix;
1521
1561
  return [
@@ -1590,6 +1630,7 @@ function getSpecialHelper(keyName, tagName) {
1590
1630
 
1591
1631
  const setTemplateRefIdent = `_setTemplateRef`;
1592
1632
  function genSetTemplateRef(oper, context) {
1633
+ const [refValue, refKey] = genRefValue(oper.value, context);
1593
1634
  return [
1594
1635
  NEWLINE,
1595
1636
  oper.effect && `r${oper.element} = `,
@@ -1597,9 +1638,10 @@ function genSetTemplateRef(oper, context) {
1597
1638
  setTemplateRefIdent,
1598
1639
  // will be generated in root scope
1599
1640
  `n${oper.element}`,
1600
- genRefValue(oper.value, context),
1641
+ refValue,
1601
1642
  oper.effect ? `r${oper.element}` : oper.refFor ? "void 0" : void 0,
1602
- oper.refFor && "true"
1643
+ oper.refFor && "true",
1644
+ refKey
1603
1645
  )
1604
1646
  ];
1605
1647
  }
@@ -1610,19 +1652,24 @@ function genRefValue(value, context) {
1610
1652
  if (value && context.options.inline) {
1611
1653
  const binding = context.options.bindingMetadata[value.content];
1612
1654
  if (binding === "setup-let" || binding === "setup-ref" || binding === "setup-maybe-ref") {
1613
- return [value.content];
1655
+ return [[value.content], JSON.stringify(value.content)];
1614
1656
  }
1615
1657
  }
1616
- return genExpression(value, context);
1658
+ return [genExpression(value, context)];
1617
1659
  }
1618
1660
 
1619
1661
  function genSetText(oper, context) {
1620
1662
  const { helper } = context;
1621
- const { element, values, generated, jsx } = oper;
1663
+ const { element, values, generated, jsx, isComponent } = oper;
1622
1664
  const texts = combineValues(values, context, jsx);
1623
1665
  return [
1624
1666
  NEWLINE,
1625
- ...genCall(helper("setText"), `${generated ? "x" : "n"}${element}`, texts)
1667
+ ...genCall(
1668
+ // use setBlockText for component
1669
+ isComponent ? helper("setBlockText") : helper("setText"),
1670
+ `${generated && !isComponent ? "x" : "n"}${element}`,
1671
+ texts
1672
+ )
1626
1673
  ];
1627
1674
  }
1628
1675
  function combineValues(values, context, jsx) {
@@ -1640,18 +1687,21 @@ function combineValues(values, context, jsx) {
1640
1687
  function genGetTextChild(oper, context) {
1641
1688
  return [
1642
1689
  NEWLINE,
1643
- `const x${oper.parent} = ${context.helper("child")}(n${oper.parent})`
1690
+ `const x${oper.parent} = ${context.helper("txt")}(n${oper.parent})`
1644
1691
  ];
1645
1692
  }
1646
1693
 
1647
1694
  function genVShow(oper, context) {
1695
+ const { deferred, element } = oper;
1648
1696
  return [
1649
1697
  NEWLINE,
1650
- ...genCall(context.helper("applyVShow"), `n${oper.element}`, [
1698
+ deferred ? `deferredApplyVShows.push(() => ` : void 0,
1699
+ ...genCall(context.helper("applyVShow"), `n${element}`, [
1651
1700
  `() => (`,
1652
1701
  ...genExpression(oper.dir.exp, context),
1653
1702
  `)`
1654
- ])
1703
+ ]),
1704
+ deferred ? `)` : void 0
1655
1705
  ];
1656
1706
  }
1657
1707
 
@@ -1790,8 +1840,14 @@ function genCreateComponent(operation, context) {
1790
1840
  } else if (operation.asset) {
1791
1841
  return compilerDom.toValidAssetId(operation.tag, "component");
1792
1842
  } else {
1843
+ const { tag: tag2 } = operation;
1844
+ const builtInTag = isBuiltInComponent(tag2);
1845
+ if (builtInTag) {
1846
+ helper(builtInTag);
1847
+ return `_${builtInTag}`;
1848
+ }
1793
1849
  return genExpression(
1794
- shared.extend(compilerDom.createSimpleExpression(operation.tag, false), { ast: null }),
1850
+ shared.extend(compilerDom.createSimpleExpression(tag2, false), { ast: null }),
1795
1851
  context
1796
1852
  );
1797
1853
  }
@@ -1815,7 +1871,10 @@ function processInlineHandlers(props, context) {
1815
1871
  prop.values.forEach((value, i2) => {
1816
1872
  const isMemberExp = compilerDom.isMemberExpression(value, context.options);
1817
1873
  if (!isMemberExp) {
1818
- const name = getUniqueHandlerName(context, `_on_${prop.key.content}`);
1874
+ const name = getUniqueHandlerName(
1875
+ context,
1876
+ `_on_${prop.key.content.replace(/-/g, "_")}`
1877
+ );
1819
1878
  handlers.push({ name, value });
1820
1879
  ids[name] = null;
1821
1880
  prop.values[i2] = shared.extend({ ast: null }, compilerDom.createSimpleExpression(name));
@@ -1882,7 +1941,7 @@ function genProp(prop, context, isStatic) {
1882
1941
  ...prop.handler ? genEventHandler(
1883
1942
  context,
1884
1943
  prop.values[0],
1885
- void 0,
1944
+ prop.handlerModifiers,
1886
1945
  true
1887
1946
  ) : isStatic ? ["() => (", ...values, ")"] : values,
1888
1947
  ...prop.model ? [...genModelEvent(prop, context), ...genModelModifiers(prop, context)] : []
@@ -2014,7 +2073,7 @@ function genSlotBlockWithProps(oper, context) {
2014
2073
  let propsName;
2015
2074
  let exitScope;
2016
2075
  let depth;
2017
- const { props } = oper;
2076
+ const { props, key, node } = oper;
2018
2077
  const idsOfProps = /* @__PURE__ */ new Set();
2019
2078
  if (props) {
2020
2079
  rawProps = props.content;
@@ -2036,17 +2095,39 @@ function genSlotBlockWithProps(oper, context) {
2036
2095
  idsOfProps.forEach(
2037
2096
  (id) => idMap[id] = isDestructureAssignment ? `${propsName}[${JSON.stringify(id)}]` : null
2038
2097
  );
2039
- const blockFn = context.withId(
2098
+ let blockFn = context.withId(
2040
2099
  () => genBlock(oper, context, [propsName]),
2041
2100
  idMap
2042
2101
  );
2043
2102
  exitScope && exitScope();
2103
+ if (key) {
2104
+ blockFn = [
2105
+ `() => {`,
2106
+ INDENT_START,
2107
+ NEWLINE,
2108
+ `return `,
2109
+ ...genCall(
2110
+ context.helper("createKeyedFragment"),
2111
+ [`() => `, ...genExpression(key, context)],
2112
+ blockFn
2113
+ ),
2114
+ INDENT_END,
2115
+ NEWLINE,
2116
+ `}`
2117
+ ];
2118
+ }
2119
+ if (node.type === 1 && // Not a real component
2120
+ !isTeleportTag(node.tag) && // Needs to determine whether to activate/deactivate based on instance.parent being KeepAlive
2121
+ !isKeepAliveTag(node.tag) && // Slot updates need to trigger TransitionGroup's onBeforeUpdate/onUpdated hook
2122
+ !isTransitionGroupTag(node.tag)) {
2123
+ blockFn = [`${context.helper("withVaporCtx")}(`, ...blockFn, `)`];
2124
+ }
2044
2125
  return blockFn;
2045
2126
  }
2046
2127
 
2047
2128
  function genSlotOutlet(oper, context) {
2048
2129
  const { helper } = context;
2049
- const { id, name, fallback } = oper;
2130
+ const { id, name, fallback, noSlotted } = oper;
2050
2131
  const [frag, push] = buildCodeFragment();
2051
2132
  const nameExpr = name.isStatic ? genExpression(name, context) : ["() => (", ...genExpression(name, context), ")"];
2052
2133
  let fallbackArg;
@@ -2060,7 +2141,11 @@ function genSlotOutlet(oper, context) {
2060
2141
  helper("createSlot"),
2061
2142
  nameExpr,
2062
2143
  genRawProps(oper.props, context) || "null",
2063
- fallbackArg
2144
+ fallbackArg,
2145
+ noSlotted && "undefined",
2146
+ // instance
2147
+ noSlotted && "true"
2148
+ // noSlotted
2064
2149
  )
2065
2150
  );
2066
2151
  return frag;
@@ -2176,12 +2261,18 @@ function genEffect({ operations }, context) {
2176
2261
  return frag;
2177
2262
  }
2178
2263
  function genInsertionState(operation, context) {
2264
+ const { parent, anchor, append, last } = operation;
2179
2265
  return [
2180
2266
  NEWLINE,
2181
2267
  ...genCall(
2182
2268
  context.helper("setInsertionState"),
2183
- `n${operation.parent}`,
2184
- operation.anchor == null ? void 0 : operation.anchor === -1 ? `0` : `n${operation.anchor}`
2269
+ `n${parent}`,
2270
+ anchor == null ? void 0 : anchor === -1 ? `0` : append ? (
2271
+ // null or anchor > 0 for append
2272
+ // anchor > 0 is the logical index of append node - used for locate node during hydration
2273
+ anchor === 0 ? "null" : `${anchor}`
2274
+ ) : `n${anchor}`,
2275
+ last && "true"
2185
2276
  )
2186
2277
  ];
2187
2278
  }
@@ -2196,7 +2287,7 @@ function genTemplates(templates, rootIndex, { helper }) {
2196
2287
  }
2197
2288
  function genSelf(dynamic, context) {
2198
2289
  const [frag, push] = buildCodeFragment();
2199
- const { id, template, operation } = dynamic;
2290
+ const { id, template, operation, hasDynamicChild } = dynamic;
2200
2291
  if (id !== void 0 && template !== void 0) {
2201
2292
  push(NEWLINE, `const n${id} = t${template}()`);
2202
2293
  push(...genDirectivesForElement(id, context));
@@ -2204,6 +2295,9 @@ function genSelf(dynamic, context) {
2204
2295
  if (operation) {
2205
2296
  push(...genOperationWithInsertionState(operation, context));
2206
2297
  }
2298
+ if (hasDynamicChild) {
2299
+ push(...genChildren(dynamic, context, push, `n${id}`));
2300
+ }
2207
2301
  return frag;
2208
2302
  }
2209
2303
  function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`) {
@@ -2212,51 +2306,65 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`) {
2212
2306
  const { children } = dynamic;
2213
2307
  let offset = 0;
2214
2308
  let prev;
2215
- const childrenToGen = [];
2309
+ let ifBranchCount = 0;
2310
+ let prependCount = 0;
2216
2311
  for (const [index, child] of children.entries()) {
2312
+ if (child.operation && child.operation.anchor === -1) {
2313
+ prependCount++;
2314
+ }
2217
2315
  if (child.flags & 2) {
2218
2316
  offset--;
2317
+ } else if (child.ifBranch) {
2318
+ ifBranchCount++;
2219
2319
  }
2220
2320
  const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
2221
2321
  if (id === void 0 && !child.hasDynamicChild) {
2222
2322
  push(...genSelf(child, context));
2223
2323
  continue;
2224
2324
  }
2225
- const elementIndex = Number(index) + offset;
2325
+ const elementIndex = index + offset;
2326
+ const logicalIndex = elementIndex - ifBranchCount + prependCount;
2226
2327
  const variable = id === void 0 ? `p${context.block.tempId++}` : `n${id}`;
2227
2328
  pushBlock(NEWLINE, `const ${variable} = `);
2228
2329
  if (prev) {
2229
2330
  if (elementIndex - prev[1] === 1) {
2230
- pushBlock(...genCall(helper("next"), prev[0]));
2331
+ pushBlock(...genCall(helper("next"), prev[0], String(logicalIndex)));
2231
2332
  } else {
2232
- pushBlock(...genCall(helper("nthChild"), from, String(elementIndex)));
2333
+ pushBlock(
2334
+ ...genCall(
2335
+ helper("nthChild"),
2336
+ from,
2337
+ String(elementIndex),
2338
+ String(logicalIndex)
2339
+ )
2340
+ );
2233
2341
  }
2234
2342
  } else {
2235
2343
  if (elementIndex === 0) {
2236
- pushBlock(...genCall(helper("child"), from));
2344
+ pushBlock(...genCall(helper("child"), from, String(logicalIndex)));
2237
2345
  } else {
2238
2346
  let init = genCall(helper("child"), from);
2239
2347
  if (elementIndex === 1) {
2240
- init = genCall(helper("next"), init);
2348
+ init = genCall(helper("next"), init, String(logicalIndex));
2241
2349
  } else if (elementIndex > 1) {
2242
- init = genCall(helper("nthChild"), from, String(elementIndex));
2350
+ init = genCall(
2351
+ helper("nthChild"),
2352
+ from,
2353
+ String(elementIndex),
2354
+ String(logicalIndex)
2355
+ );
2243
2356
  }
2244
2357
  pushBlock(...init);
2245
2358
  }
2246
2359
  }
2247
- if (id === child.anchor) {
2360
+ if (id === child.anchor && !child.hasDynamicChild) {
2248
2361
  push(...genSelf(child, context));
2249
2362
  }
2250
2363
  if (id !== void 0) {
2251
2364
  push(...genDirectivesForElement(id, context));
2252
2365
  }
2253
2366
  prev = [variable, elementIndex];
2254
- childrenToGen.push([child, variable]);
2255
- }
2256
- if (childrenToGen.length) {
2257
- for (const [child, from2] of childrenToGen) {
2258
- push(...genChildren(child, context, pushBlock, from2));
2259
- }
2367
+ push(...genChildren(child, context, pushBlock, variable));
2260
2368
  }
2261
2369
  return frag;
2262
2370
  }
@@ -2275,8 +2383,11 @@ function genBlock(oper, context, args = [], root) {
2275
2383
  }
2276
2384
  function genBlockContent(block, context, root, genEffectsExtraFrag) {
2277
2385
  const [frag, push] = buildCodeFragment();
2278
- const { dynamic, effect, operation, returns } = block;
2386
+ const { dynamic, effect, operation, returns, key } = block;
2279
2387
  const resetBlock = context.enterBlock(block);
2388
+ if (block.hasDeferredVShow) {
2389
+ push(NEWLINE, `const deferredApplyVShows = []`);
2390
+ }
2280
2391
  if (root) {
2281
2392
  for (let name of context.ir.component) {
2282
2393
  const id = compilerDom.toValidAssetId(name, "component");
@@ -2299,10 +2410,21 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
2299
2410
  push(...genSelf(child, context));
2300
2411
  }
2301
2412
  for (const child of dynamic.children) {
2302
- push(...genChildren(child, context, push, `n${child.id}`));
2413
+ if (!child.hasDynamicChild) {
2414
+ push(...genChildren(child, context, push, `n${child.id}`));
2415
+ }
2303
2416
  }
2304
2417
  push(...genOperations(operation, context));
2305
2418
  push(...genEffects(effect, context, genEffectsExtraFrag));
2419
+ if (block.hasDeferredVShow) {
2420
+ push(NEWLINE, `deferredApplyVShows.forEach(fn => fn())`);
2421
+ }
2422
+ if (dynamic.needsKey) {
2423
+ for (const child of dynamic.children) {
2424
+ const keyValue = key ? genExpression(key, context) : JSON.stringify(child.id);
2425
+ push(NEWLINE, `n${child.id}.$key = `, ...keyValue);
2426
+ }
2427
+ }
2306
2428
  push(NEWLINE, `return `);
2307
2429
  const returnNodes = returns.map((n) => `n${n}`);
2308
2430
  const returnsCode = returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"];
@@ -2461,15 +2583,17 @@ const transformChildren = (node, context) => {
2461
2583
  };
2462
2584
  function processDynamicChildren(context) {
2463
2585
  let prevDynamics = [];
2464
- let hasStaticTemplate = false;
2586
+ let staticCount = 0;
2587
+ let dynamicCount = 0;
2588
+ let lastInsertionChild;
2465
2589
  const children = context.dynamic.children;
2466
2590
  for (const [index, child] of children.entries()) {
2467
2591
  if (child.flags & 4) {
2468
- prevDynamics.push(child);
2592
+ prevDynamics.push(lastInsertionChild = child);
2469
2593
  }
2470
2594
  if (!(child.flags & 2)) {
2471
2595
  if (prevDynamics.length) {
2472
- if (hasStaticTemplate) {
2596
+ if (staticCount) {
2473
2597
  context.childrenTemplate[index - prevDynamics.length] = `<!>`;
2474
2598
  prevDynamics[0].flags -= 2;
2475
2599
  const anchor = prevDynamics[0].anchor = context.increaseId();
@@ -2482,27 +2606,38 @@ function processDynamicChildren(context) {
2482
2606
  /* prepend */
2483
2607
  );
2484
2608
  }
2609
+ dynamicCount += prevDynamics.length;
2485
2610
  prevDynamics = [];
2486
2611
  }
2487
- hasStaticTemplate = true;
2612
+ staticCount++;
2488
2613
  }
2489
2614
  }
2490
2615
  if (prevDynamics.length) {
2491
- registerInsertion(prevDynamics, context);
2616
+ registerInsertion(
2617
+ prevDynamics,
2618
+ context,
2619
+ // the logical index of append child
2620
+ dynamicCount + staticCount,
2621
+ true
2622
+ );
2623
+ }
2624
+ if (lastInsertionChild && lastInsertionChild.operation) {
2625
+ lastInsertionChild.operation.last = true;
2492
2626
  }
2493
2627
  }
2494
- function registerInsertion(dynamics, context, anchor) {
2628
+ function registerInsertion(dynamics, context, anchor, append) {
2495
2629
  for (const child of dynamics) {
2496
2630
  if (child.template != null) {
2497
2631
  context.registerOperation({
2498
2632
  type: 9,
2499
2633
  elements: dynamics.map((child2) => child2.id),
2500
2634
  parent: context.reference(),
2501
- anchor
2635
+ anchor: append ? void 0 : anchor
2502
2636
  });
2503
2637
  } else if (child.operation && isBlockOperation(child.operation)) {
2504
2638
  child.operation.parent = context.reference();
2505
2639
  child.operation.anchor = anchor;
2640
+ child.operation.append = append;
2506
2641
  }
2507
2642
  }
2508
2643
  }
@@ -2570,6 +2705,11 @@ function transformComponentElement(node, propsResult, singleRoot, context, isDyn
2570
2705
  tag = fromSetup;
2571
2706
  asset = false;
2572
2707
  }
2708
+ const builtInTag = isBuiltInComponent(tag);
2709
+ if (builtInTag) {
2710
+ tag = builtInTag;
2711
+ asset = false;
2712
+ }
2573
2713
  const dotIndex = tag.indexOf(".");
2574
2714
  if (dotIndex > 0) {
2575
2715
  const ns = resolveSetupReference(tag.slice(0, dotIndex), context);
@@ -2626,6 +2766,7 @@ function resolveSetupReference(name, context) {
2626
2766
  const PascalName = shared.capitalize(camelName);
2627
2767
  return bindings[name] ? name : bindings[camelName] ? camelName : bindings[PascalName] ? PascalName : void 0;
2628
2768
  }
2769
+ const dynamicKeys = ["indeterminate"];
2629
2770
  function transformNativeElement(node, propsResult, singleRoot, context, getEffectIndex) {
2630
2771
  const { tag } = node;
2631
2772
  const { scopeId } = context.options;
@@ -2648,7 +2789,7 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
2648
2789
  } else {
2649
2790
  for (const prop of propsResult[1]) {
2650
2791
  const { key, values } = prop;
2651
- if (key.isStatic && values.length === 1 && values[0].isStatic) {
2792
+ if (key.isStatic && values.length === 1 && values[0].isStatic && !dynamicKeys.includes(key.content)) {
2652
2793
  template += ` ${key.content}`;
2653
2794
  if (values[0].content) template += `="${values[0].content}"`;
2654
2795
  } else {
@@ -2804,7 +2945,7 @@ function dedupeProperties(results) {
2804
2945
  }
2805
2946
  const name = prop.key.content;
2806
2947
  const existing = knownProps.get(name);
2807
- if (existing) {
2948
+ if (existing && existing.handler === prop.handler) {
2808
2949
  if (name === "style" || name === "class") {
2809
2950
  mergePropValues(existing, prop);
2810
2951
  }
@@ -2846,11 +2987,11 @@ const transformVHtml = (dir, node, context) => {
2846
2987
  context.registerEffect([exp], {
2847
2988
  type: 7,
2848
2989
  element: context.reference(),
2849
- value: exp
2990
+ value: exp,
2991
+ isComponent: node.tagType === 1
2850
2992
  });
2851
2993
  };
2852
2994
 
2853
- /*! #__NO_SIDE_EFFECTS__ */
2854
2995
  // @__NO_SIDE_EFFECTS__
2855
2996
  function makeMap(str) {
2856
2997
  const map = /* @__PURE__ */ Object.create(null);
@@ -2883,15 +3024,19 @@ const transformVText = (dir, node, context) => {
2883
3024
  context.childrenTemplate = [String(literal)];
2884
3025
  } else {
2885
3026
  context.childrenTemplate = [" "];
2886
- context.registerOperation({
2887
- type: 17,
2888
- parent: context.reference()
2889
- });
3027
+ const isComponent = node.tagType === 1;
3028
+ if (!isComponent) {
3029
+ context.registerOperation({
3030
+ type: 17,
3031
+ parent: context.reference()
3032
+ });
3033
+ }
2890
3034
  context.registerEffect([exp], {
2891
3035
  type: 4,
2892
3036
  element: context.reference(),
2893
3037
  values: [exp],
2894
- generated: true
3038
+ generated: true,
3039
+ isComponent
2895
3040
  });
2896
3041
  }
2897
3042
  };
@@ -2984,7 +3129,11 @@ const transformVOn = (dir, node, context) => {
2984
3129
  key: arg,
2985
3130
  value: handler,
2986
3131
  handler: true,
2987
- handlerModifiers: eventOptionModifiers
3132
+ handlerModifiers: {
3133
+ keys: keyModifiers,
3134
+ nonKeys: nonKeyModifiers,
3135
+ options: eventOptionModifiers
3136
+ }
2988
3137
  };
2989
3138
  }
2990
3139
  const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
@@ -3022,12 +3171,21 @@ const transformVShow = (dir, node, context) => {
3022
3171
  );
3023
3172
  return;
3024
3173
  }
3174
+ let shouldDeferred = false;
3175
+ const parentNode = context.parent && context.parent.node;
3176
+ if (parentNode && parentNode.type === 1) {
3177
+ shouldDeferred = !!(isTransitionTag(parentNode.tag) && findProp(parentNode, "appear", false, true));
3178
+ if (shouldDeferred) {
3179
+ context.parent.parent.block.hasDeferredVShow = true;
3180
+ }
3181
+ }
3025
3182
  context.registerOperation({
3026
3183
  type: 13,
3027
3184
  element: context.reference(),
3028
3185
  dir,
3029
3186
  name: "show",
3030
- builtin: true
3187
+ builtin: true,
3188
+ deferred: shouldDeferred
3031
3189
  });
3032
3190
  };
3033
3191
 
@@ -3097,7 +3255,7 @@ const transformText = (node, context) => {
3097
3255
  } else if (node.type === 5) {
3098
3256
  processInterpolation(context);
3099
3257
  } else if (node.type === 2) {
3100
- context.template += node.content;
3258
+ context.template += shared.escapeHtml(node.content);
3101
3259
  }
3102
3260
  };
3103
3261
  function processInterpolation(context) {
@@ -3141,7 +3299,7 @@ function processTextContainer(children, context) {
3141
3299
  const values = processTextLikeChildren(children, context);
3142
3300
  const literals = values.map(getLiteralExpressionValue);
3143
3301
  if (literals.every((l) => l != null)) {
3144
- context.childrenTemplate = literals.map((l) => String(l));
3302
+ context.childrenTemplate = literals.map((l) => shared.escapeHtml(String(l)));
3145
3303
  } else {
3146
3304
  context.childrenTemplate = [" "];
3147
3305
  context.registerOperation({
@@ -3292,7 +3450,7 @@ const transformComment = (node, context) => {
3292
3450
  context.comment.push(node);
3293
3451
  context.dynamic.flags |= 2;
3294
3452
  } else {
3295
- context.template += `<!--${node.content}-->`;
3453
+ context.template += `<!--${shared.escapeHtml(node.content)}-->`;
3296
3454
  }
3297
3455
  };
3298
3456
  function getSiblingIf(context, reverse) {
@@ -3346,6 +3504,7 @@ function processIf(node, dir, context) {
3346
3504
  };
3347
3505
  } else {
3348
3506
  const siblingIf = getSiblingIf(context, true);
3507
+ context.dynamic.ifBranch = true;
3349
3508
  const siblings = context.parent && context.parent.dynamic.children;
3350
3509
  let lastIfNode;
3351
3510
  if (siblings) {
@@ -3402,6 +3561,7 @@ function createIfBranch(node, context) {
3402
3561
  const branch = newBlock(node);
3403
3562
  const exitBlock = context.enterBlock(branch);
3404
3563
  context.reference();
3564
+ branch.dynamic.needsKey = isInTransition(context);
3405
3565
  return [branch, exitBlock];
3406
3566
  }
3407
3567
 
@@ -3426,7 +3586,8 @@ function processFor(node, dir, context) {
3426
3586
  const { source, value, key, index } = parseResult;
3427
3587
  const keyProp = findProp(node, "key");
3428
3588
  const keyProperty = keyProp && propToExpression(keyProp);
3429
- const isComponent = node.tagType === 1;
3589
+ const isComponent = node.tagType === 1 || // template v-for with a single component child
3590
+ isTemplateWithSingleComponent(node);
3430
3591
  context.node = node = wrapTemplate(node, ["for"]);
3431
3592
  context.dynamic.flags |= 2 | 4;
3432
3593
  const id = context.reference();
@@ -3455,6 +3616,13 @@ function processFor(node, dir, context) {
3455
3616
  };
3456
3617
  };
3457
3618
  }
3619
+ function isTemplateWithSingleComponent(node) {
3620
+ if (node.tag !== "template") return false;
3621
+ const nonCommentChildren = node.children.filter(
3622
+ (c) => c.type !== 3
3623
+ );
3624
+ return nonCommentChildren.length === 1 && nonCommentChildren[0].type === 1 && nonCommentChildren[0].tagType === 1;
3625
+ }
3458
3626
 
3459
3627
  const transformSlotOutlet = (node, context) => {
3460
3628
  if (node.type !== 1 || node.tag !== "slot") {
@@ -3528,7 +3696,8 @@ const transformSlotOutlet = (node, context) => {
3528
3696
  id,
3529
3697
  name: slotName,
3530
3698
  props: irProps,
3531
- fallback
3699
+ fallback,
3700
+ noSlotted: !!(context.options.scopeId && !context.options.slotted)
3532
3701
  };
3533
3702
  };
3534
3703
  };
@@ -3590,7 +3759,22 @@ function transformComponentSlot(node, dir, context) {
3590
3759
  markNonTemplate(n, context);
3591
3760
  });
3592
3761
  }
3593
- const [block, onExit] = createSlotBlock(node, dir, context);
3762
+ let slotKey;
3763
+ if (isTransitionNode(node) && nonSlotTemplateChildren.length) {
3764
+ const nonCommentChild = nonSlotTemplateChildren.find(
3765
+ (n) => n.type !== 3
3766
+ );
3767
+ if (nonCommentChild) {
3768
+ const keyProp = findProp(
3769
+ nonCommentChild,
3770
+ "key"
3771
+ );
3772
+ if (keyProp) {
3773
+ slotKey = keyProp.exp;
3774
+ }
3775
+ }
3776
+ }
3777
+ const [block, onExit] = createSlotBlock(node, dir, context, slotKey);
3594
3778
  const { slots } = context;
3595
3779
  return () => {
3596
3780
  onExit();
@@ -3724,9 +3908,13 @@ function hasStaticSlot(slots, name) {
3724
3908
  if (slot.slotType === 0) return !!slot.slots[name];
3725
3909
  });
3726
3910
  }
3727
- function createSlotBlock(slotNode, dir, context) {
3911
+ function createSlotBlock(slotNode, dir, context, key = void 0) {
3728
3912
  const block = newBlock(slotNode);
3729
3913
  block.props = dir && dir.exp;
3914
+ if (key) {
3915
+ block.key = key;
3916
+ block.dynamic.needsKey = true;
3917
+ }
3730
3918
  const exitBlock = context.enterBlock(block);
3731
3919
  return [block, exitBlock];
3732
3920
  }
@@ -3735,6 +3923,37 @@ function isNonWhitespaceContent(node) {
3735
3923
  return !!node.content.trim();
3736
3924
  }
3737
3925
 
3926
+ const transformTransition = (node, context) => {
3927
+ if (node.type === 1 && node.tagType === 1) {
3928
+ if (isTransitionTag(node.tag)) {
3929
+ return compilerDom.postTransformTransition(
3930
+ node,
3931
+ context.options.onError,
3932
+ hasMultipleChildren
3933
+ );
3934
+ }
3935
+ }
3936
+ };
3937
+ function hasMultipleChildren(node) {
3938
+ const children = node.children = node.children.filter(
3939
+ (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
3940
+ );
3941
+ const first = children[0];
3942
+ if (children.length === 1 && first.type === 1 && (findDir(first, "for") || compilerDom.isTemplateNode(first))) {
3943
+ return true;
3944
+ }
3945
+ const hasElse = (node2) => findDir(node2, "else-if") || findDir(node2, "else", true);
3946
+ if (children.every(
3947
+ (c, index) => c.type === 1 && // not template
3948
+ !compilerDom.isTemplateNode(c) && // not has v-for
3949
+ !findDir(c, "for") && // if the first child has v-if, the rest should also have v-else-if/v-else
3950
+ (index === 0 ? findDir(c, "if") : hasElse(c)) && !hasMultipleChildren(c)
3951
+ )) {
3952
+ return false;
3953
+ }
3954
+ return children.length > 1;
3955
+ }
3956
+
3738
3957
  function compile(source, options = {}) {
3739
3958
  const resolvedOptions = shared.extend({}, options);
3740
3959
  const ast = shared.isString(source) ? compilerDom.parse(source, resolvedOptions) : source;
@@ -3753,6 +3972,7 @@ function compile(source, options = {}) {
3753
3972
  shared.extend({}, resolvedOptions, {
3754
3973
  nodeTransforms: [
3755
3974
  ...nodeTransforms,
3975
+ ...[transformTransition] ,
3756
3976
  ...options.nodeTransforms || []
3757
3977
  // user transforms
3758
3978
  ],