@vue/compiler-vapor 3.6.0-alpha.4 → 3.6.0-alpha.6

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.4
2
+ * @vue/compiler-vapor v3.6.0-alpha.6
3
3
  * (c) 2018-present Yuxi (Evan) You and Vue contributors
4
4
  * @license MIT
5
5
  **/
@@ -17084,7 +17084,43 @@ function toValidAssetId(name, type) {
17084
17084
  return searchValue === "-" ? "_" : name.charCodeAt(replaceValue).toString();
17085
17085
  })}`;
17086
17086
  }
17087
+ function filterNonCommentChildren(node) {
17088
+ return node.children.filter((n) => n.type !== 3);
17089
+ }
17090
+ function hasSingleChild(node) {
17091
+ return filterNonCommentChildren(node).length === 1;
17092
+ }
17093
+ function isSingleIfBlock(parent) {
17094
+ let hasEncounteredIf = false;
17095
+ for (const c of filterNonCommentChildren(parent)) {
17096
+ if (c.type === 9 || c.type === 1 && findDir$1(c, "if")) {
17097
+ if (hasEncounteredIf) return false;
17098
+ hasEncounteredIf = true;
17099
+ } else if (
17100
+ // node before v-if
17101
+ !hasEncounteredIf || // non else nodes
17102
+ !(c.type === 1 && findDir$1(c, /^else(-if)?$/, true))
17103
+ ) {
17104
+ return false;
17105
+ }
17106
+ }
17107
+ return true;
17108
+ }
17087
17109
  const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
17110
+ function isAllWhitespace(str) {
17111
+ for (let i = 0; i < str.length; i++) {
17112
+ if (!isWhitespace(str.charCodeAt(i))) {
17113
+ return false;
17114
+ }
17115
+ }
17116
+ return true;
17117
+ }
17118
+ function isWhitespaceText(node) {
17119
+ return node.type === 2 && isAllWhitespace(node.content) || node.type === 12 && isWhitespaceText(node.content);
17120
+ }
17121
+ function isCommentOrWhitespace(node) {
17122
+ return node.type === 3 || isWhitespaceText(node);
17123
+ }
17088
17124
 
17089
17125
  const defaultParserOptions = {
17090
17126
  parseMode: "base",
@@ -17621,14 +17657,6 @@ function condenseWhitespace(nodes) {
17621
17657
  }
17622
17658
  return removedWhitespace ? nodes.filter(Boolean) : nodes;
17623
17659
  }
17624
- function isAllWhitespace(str) {
17625
- for (let i = 0; i < str.length; i++) {
17626
- if (!isWhitespace(str.charCodeAt(i))) {
17627
- return false;
17628
- }
17629
- }
17630
- return true;
17631
- }
17632
17660
  function hasNewlineChar(str) {
17633
17661
  for (let i = 0; i < str.length; i++) {
17634
17662
  const c = str.charCodeAt(i);
@@ -21312,7 +21340,9 @@ const isNonKeyModifier = /* @__PURE__ */ makeMap(
21312
21340
  `stop,prevent,self,ctrl,shift,alt,meta,exact,middle`
21313
21341
  );
21314
21342
  const maybeKeyModifier = /* @__PURE__ */ makeMap("left,right");
21315
- const isKeyboardEvent = /* @__PURE__ */ makeMap(`onkeyup,onkeydown,onkeypress`);
21343
+ const isKeyboardEvent = /* @__PURE__ */ makeMap(
21344
+ `onkeyup,onkeydown,onkeypress`
21345
+ );
21316
21346
  const resolveModifiers = (key, modifiers, context, loc) => {
21317
21347
  const keyModifiers = [];
21318
21348
  const nonKeyModifiers = [];
@@ -21382,7 +21412,7 @@ function postTransformTransition(node, onError, hasMultipleChildren = defaultHas
21382
21412
  }
21383
21413
  function defaultHasMultipleChildren(node) {
21384
21414
  const children = node.children = node.children.filter(
21385
- (c) => c.type !== 3 && !(c.type === 2 && !c.content.trim())
21415
+ (c) => !isCommentOrWhitespace(c)
21386
21416
  );
21387
21417
  const child = children[0];
21388
21418
  return children.length !== 1 || child.type === 11 || child.type === 9 && child.branches.some(defaultHasMultipleChildren);
@@ -21568,8 +21598,7 @@ const newBlock = (node) => ({
21568
21598
  effect: [],
21569
21599
  operation: [],
21570
21600
  returns: [],
21571
- tempId: 0,
21572
- hasDeferredVShow: false
21601
+ tempId: 0
21573
21602
  });
21574
21603
  function wrapTemplate(node, dirs) {
21575
21604
  if (node.tagType === 3) {
@@ -21826,10 +21855,12 @@ function transform(node, options = {}) {
21826
21855
  source: node.source,
21827
21856
  template: /* @__PURE__ */ new Map(),
21828
21857
  templateIndexMap: /* @__PURE__ */ new Map(),
21858
+ rootTemplateIndexes: /* @__PURE__ */ new Set(),
21829
21859
  component: /* @__PURE__ */ new Set(),
21830
21860
  directive: /* @__PURE__ */ new Set(),
21831
21861
  block: newBlock(node),
21832
- hasTemplateRef: false
21862
+ hasTemplateRef: false,
21863
+ hasDeferredVShow: false
21833
21864
  };
21834
21865
  const context = new TransformContext(ir, node, options);
21835
21866
  transformNode(context);
@@ -22322,8 +22353,10 @@ function analyzeExpressions(expressions) {
22322
22353
  exp.ast === null && registerVariable(exp.content, exp, true);
22323
22354
  continue;
22324
22355
  }
22356
+ const seenParents = /* @__PURE__ */ new Set();
22325
22357
  walkIdentifiers(exp.ast, (currentNode, parent, parentStack) => {
22326
- if (parent && isMemberExpression(parent)) {
22358
+ if (parent && isMemberExpression(parent) && !seenParents.has(parent)) {
22359
+ seenParents.add(parent);
22327
22360
  const memberExp = extractMemberExpression(parent, (id) => {
22328
22361
  registerVariable(id.name, exp, true, {
22329
22362
  start: id.start,
@@ -22425,7 +22458,7 @@ function shouldDeclareVariable(name, expToVariableMap, exps) {
22425
22458
  }
22426
22459
  return true;
22427
22460
  }
22428
- if (vars.some((v) => v.some((e) => first.includes(e)))) {
22461
+ if (vars.every((v) => v.every((e, idx) => e === first[idx]))) {
22429
22462
  return false;
22430
22463
  }
22431
22464
  return true;
@@ -22434,7 +22467,9 @@ function processRepeatedExpressions(context, expressions, varDeclarations, updat
22434
22467
  const declarations = [];
22435
22468
  const seenExp = expressions.reduce(
22436
22469
  (acc, exp) => {
22437
- const variables = expToVariableMap.get(exp).map((v) => v.name);
22470
+ const vars = expToVariableMap.get(exp);
22471
+ if (!vars) return acc;
22472
+ const variables = vars.map((v) => v.name);
22438
22473
  if (exp.ast && exp.ast.type !== "Identifier" && !(variables && variables.some((v) => updatedVariable.has(v)))) {
22439
22474
  acc[exp.content] = (acc[exp.content] || 0) + 1;
22440
22475
  }
@@ -22550,12 +22585,14 @@ function extractMemberExpression(exp, onIdentifier) {
22550
22585
  const object = extractMemberExpression(exp.object, onIdentifier);
22551
22586
  const prop = exp.computed ? `[${extractMemberExpression(exp.property, onIdentifier)}]` : `.${extractMemberExpression(exp.property, NOOP)}`;
22552
22587
  return `${object}${prop}`;
22588
+ case "TSNonNullExpression":
22589
+ return `${extractMemberExpression(exp.expression, onIdentifier)}`;
22553
22590
  default:
22554
22591
  return "";
22555
22592
  }
22556
22593
  }
22557
22594
  const isMemberExpression = (node) => {
22558
- return node.type === "MemberExpression" || node.type === "OptionalMemberExpression";
22595
+ return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "TSNonNullExpression";
22559
22596
  };
22560
22597
 
22561
22598
  function genSetEvent(oper, context) {
@@ -22564,7 +22601,7 @@ function genSetEvent(oper, context) {
22564
22601
  const name = genName();
22565
22602
  const handler = [
22566
22603
  `${context.helper("createInvoker")}(`,
22567
- ...genEventHandler(context, value, modifiers),
22604
+ ...genEventHandler(context, [value], modifiers),
22568
22605
  `)`
22569
22606
  ];
22570
22607
  const eventOptions = genEventOptions();
@@ -22621,37 +22658,47 @@ function genSetDynamicEvents(oper, context) {
22621
22658
  )
22622
22659
  ];
22623
22660
  }
22624
- function genEventHandler(context, value, modifiers = { nonKeys: [], keys: [] }, extraWrap = false) {
22625
- let handlerExp = [`() => {}`];
22626
- if (value && value.content.trim()) {
22627
- if (isMemberExpression$1(value, context.options)) {
22628
- handlerExp = genExpression(value, context);
22629
- if (!isConstantBinding(value, context) && !extraWrap) {
22630
- const isTSNode = value.ast && TS_NODE_TYPES.includes(value.ast.type);
22631
- handlerExp = [
22632
- `e => `,
22633
- isTSNode ? "(" : "",
22634
- ...handlerExp,
22635
- isTSNode ? ")" : "",
22636
- `(e)`
22637
- ];
22661
+ function genEventHandler(context, values, modifiers = { nonKeys: [], keys: [] }, extraWrap = false) {
22662
+ let handlerExp = [];
22663
+ if (values) {
22664
+ values.forEach((value, index) => {
22665
+ let exp = [];
22666
+ if (value && value.content.trim()) {
22667
+ if (isMemberExpression$1(value, context.options)) {
22668
+ exp = genExpression(value, context);
22669
+ if (!isConstantBinding(value, context) && !extraWrap) {
22670
+ const isTSNode = value.ast && TS_NODE_TYPES.includes(value.ast.type);
22671
+ exp = [
22672
+ `e => `,
22673
+ isTSNode ? "(" : "",
22674
+ ...exp,
22675
+ isTSNode ? ")" : "",
22676
+ `(e)`
22677
+ ];
22678
+ }
22679
+ } else if (isFnExpression(value, context.options)) {
22680
+ exp = genExpression(value, context);
22681
+ } else {
22682
+ const referencesEvent = value.content.includes("$event");
22683
+ const hasMultipleStatements = value.content.includes(`;`);
22684
+ const expr = referencesEvent ? context.withId(() => genExpression(value, context), {
22685
+ $event: null
22686
+ }) : genExpression(value, context);
22687
+ exp = [
22688
+ referencesEvent ? "$event => " : "() => ",
22689
+ hasMultipleStatements ? "{" : "(",
22690
+ ...expr,
22691
+ hasMultipleStatements ? "}" : ")"
22692
+ ];
22693
+ }
22694
+ handlerExp = handlerExp.concat([index !== 0 ? ", " : "", ...exp]);
22638
22695
  }
22639
- } else if (isFnExpression(value, context.options)) {
22640
- handlerExp = genExpression(value, context);
22641
- } else {
22642
- const referencesEvent = value.content.includes("$event");
22643
- const hasMultipleStatements = value.content.includes(`;`);
22644
- const expr = referencesEvent ? context.withId(() => genExpression(value, context), {
22645
- $event: null
22646
- }) : genExpression(value, context);
22647
- handlerExp = [
22648
- referencesEvent ? "$event => " : "() => ",
22649
- hasMultipleStatements ? "{" : "(",
22650
- ...expr,
22651
- hasMultipleStatements ? "}" : ")"
22652
- ];
22696
+ });
22697
+ if (values.length > 1) {
22698
+ handlerExp = ["[", ...handlerExp, "]"];
22653
22699
  }
22654
22700
  }
22701
+ if (handlerExp.length === 0) handlerExp = ["() => {}"];
22655
22702
  const { keys, nonKeys } = modifiers;
22656
22703
  if (nonKeys.length)
22657
22704
  handlerExp = genWithModifiers(context, handlerExp, nonKeys);
@@ -22692,35 +22739,19 @@ function genFor(oper, context) {
22692
22739
  component,
22693
22740
  onlyChild
22694
22741
  } = oper;
22695
- let rawValue = null;
22742
+ const rawValue = value && value.content;
22696
22743
  const rawKey = key && key.content;
22697
22744
  const rawIndex = index && index.content;
22698
22745
  const sourceExpr = ["() => (", ...genExpression(source, context), ")"];
22699
- const idToPathMap = parseValueDestructure();
22746
+ const idToPathMap = parseValueDestructure(value, context);
22700
22747
  const [depth, exitScope] = context.enterScope();
22701
- const idMap = {};
22702
22748
  const itemVar = `_for_item${depth}`;
22749
+ const idMap = buildDestructureIdMap(
22750
+ idToPathMap,
22751
+ `${itemVar}.value`,
22752
+ context.options.expressionPlugins
22753
+ );
22703
22754
  idMap[itemVar] = null;
22704
- idToPathMap.forEach((pathInfo, id2) => {
22705
- let path = `${itemVar}.value${pathInfo ? pathInfo.path : ""}`;
22706
- if (pathInfo) {
22707
- if (pathInfo.helper) {
22708
- idMap[pathInfo.helper] = null;
22709
- path = `${pathInfo.helper}(${path}, ${pathInfo.helperArgs})`;
22710
- }
22711
- if (pathInfo.dynamic) {
22712
- const node = idMap[id2] = createSimpleExpression(path);
22713
- const plugins = context.options.expressionPlugins;
22714
- node.ast = libExports.parseExpression(`(${path})`, {
22715
- plugins: plugins ? [...plugins, "typescript"] : ["typescript"]
22716
- });
22717
- } else {
22718
- idMap[id2] = path;
22719
- }
22720
- } else {
22721
- idMap[id2] = path;
22722
- }
22723
- });
22724
22755
  const args = [itemVar];
22725
22756
  if (rawKey) {
22726
22757
  const keyVar = `_for_key${depth}`;
@@ -22818,77 +22849,6 @@ function genFor(oper, context) {
22818
22849
  // todo: hydrationNode
22819
22850
  )
22820
22851
  ];
22821
- function parseValueDestructure() {
22822
- const map = /* @__PURE__ */ new Map();
22823
- if (value) {
22824
- rawValue = value && value.content;
22825
- if (value.ast) {
22826
- walkIdentifiers(
22827
- value.ast,
22828
- (id2, _, parentStack, ___, isLocal) => {
22829
- if (isLocal) {
22830
- let path = "";
22831
- let isDynamic = false;
22832
- let helper2;
22833
- let helperArgs;
22834
- for (let i = 0; i < parentStack.length; i++) {
22835
- const parent = parentStack[i];
22836
- const child = parentStack[i + 1] || id2;
22837
- if (parent.type === "ObjectProperty" && parent.value === child) {
22838
- if (parent.key.type === "StringLiteral") {
22839
- path += `[${JSON.stringify(parent.key.value)}]`;
22840
- } else if (parent.computed) {
22841
- isDynamic = true;
22842
- path += `[${value.content.slice(
22843
- parent.key.start - 1,
22844
- parent.key.end - 1
22845
- )}]`;
22846
- } else {
22847
- path += `.${parent.key.name}`;
22848
- }
22849
- } else if (parent.type === "ArrayPattern") {
22850
- const index2 = parent.elements.indexOf(child);
22851
- if (child.type === "RestElement") {
22852
- path += `.slice(${index2})`;
22853
- } else {
22854
- path += `[${index2}]`;
22855
- }
22856
- } else if (parent.type === "ObjectPattern" && child.type === "RestElement") {
22857
- helper2 = context.helper("getRestElement");
22858
- helperArgs = "[" + parent.properties.filter((p) => p.type === "ObjectProperty").map((p) => {
22859
- if (p.key.type === "StringLiteral") {
22860
- return JSON.stringify(p.key.value);
22861
- } else if (p.computed) {
22862
- isDynamic = true;
22863
- return value.content.slice(
22864
- p.key.start - 1,
22865
- p.key.end - 1
22866
- );
22867
- } else {
22868
- return JSON.stringify(p.key.name);
22869
- }
22870
- }).join(", ") + "]";
22871
- }
22872
- if (child.type === "AssignmentPattern" && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
22873
- isDynamic = true;
22874
- helper2 = context.helper("getDefaultValue");
22875
- helperArgs = value.content.slice(
22876
- child.right.start - 1,
22877
- child.right.end - 1
22878
- );
22879
- }
22880
- }
22881
- map.set(id2.name, { path, dynamic: isDynamic, helper: helper2, helperArgs });
22882
- }
22883
- },
22884
- true
22885
- );
22886
- } else {
22887
- map.set(rawValue, null);
22888
- }
22889
- }
22890
- return map;
22891
- }
22892
22852
  function genCallback(expr) {
22893
22853
  if (!expr) return false;
22894
22854
  const res = context.withId(
@@ -22915,6 +22875,98 @@ function genFor(oper, context) {
22915
22875
  return idMap2;
22916
22876
  }
22917
22877
  }
22878
+ function parseValueDestructure(value, context) {
22879
+ const map = /* @__PURE__ */ new Map();
22880
+ if (value) {
22881
+ const rawValue = value.content;
22882
+ if (value.ast) {
22883
+ walkIdentifiers(
22884
+ value.ast,
22885
+ (id, _, parentStack, ___, isLocal) => {
22886
+ if (isLocal) {
22887
+ let path = "";
22888
+ let isDynamic = false;
22889
+ let helper;
22890
+ let helperArgs;
22891
+ for (let i = 0; i < parentStack.length; i++) {
22892
+ const parent = parentStack[i];
22893
+ const child = parentStack[i + 1] || id;
22894
+ if (parent.type === "ObjectProperty" && parent.value === child) {
22895
+ if (parent.key.type === "StringLiteral") {
22896
+ path += `[${JSON.stringify(parent.key.value)}]`;
22897
+ } else if (parent.computed) {
22898
+ isDynamic = true;
22899
+ path += `[${rawValue.slice(
22900
+ parent.key.start - 1,
22901
+ parent.key.end - 1
22902
+ )}]`;
22903
+ } else {
22904
+ path += `.${parent.key.name}`;
22905
+ }
22906
+ } else if (parent.type === "ArrayPattern") {
22907
+ const index = parent.elements.indexOf(child);
22908
+ if (child.type === "RestElement") {
22909
+ path += `.slice(${index})`;
22910
+ } else {
22911
+ path += `[${index}]`;
22912
+ }
22913
+ } else if (parent.type === "ObjectPattern" && child.type === "RestElement") {
22914
+ helper = context.helper("getRestElement");
22915
+ helperArgs = "[" + parent.properties.filter((p) => p.type === "ObjectProperty").map((p) => {
22916
+ if (p.key.type === "StringLiteral") {
22917
+ return JSON.stringify(p.key.value);
22918
+ } else if (p.computed) {
22919
+ isDynamic = true;
22920
+ return rawValue.slice(p.key.start - 1, p.key.end - 1);
22921
+ } else {
22922
+ return JSON.stringify(p.key.name);
22923
+ }
22924
+ }).join(", ") + "]";
22925
+ }
22926
+ if (child.type === "AssignmentPattern" && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
22927
+ isDynamic = true;
22928
+ helper = context.helper("getDefaultValue");
22929
+ helperArgs = rawValue.slice(
22930
+ child.right.start - 1,
22931
+ child.right.end - 1
22932
+ );
22933
+ }
22934
+ }
22935
+ map.set(id.name, { path, dynamic: isDynamic, helper, helperArgs });
22936
+ }
22937
+ },
22938
+ true
22939
+ );
22940
+ } else if (rawValue) {
22941
+ map.set(rawValue, null);
22942
+ }
22943
+ }
22944
+ return map;
22945
+ }
22946
+ function buildDestructureIdMap(idToPathMap, baseAccessor, plugins) {
22947
+ const idMap = {};
22948
+ idToPathMap.forEach((pathInfo, id) => {
22949
+ let path = baseAccessor;
22950
+ if (pathInfo) {
22951
+ path = `${baseAccessor}${pathInfo.path}`;
22952
+ if (pathInfo.helper) {
22953
+ idMap[pathInfo.helper] = null;
22954
+ path = pathInfo.helperArgs ? `${pathInfo.helper}(${path}, ${pathInfo.helperArgs})` : `${pathInfo.helper}(${path})`;
22955
+ }
22956
+ if (pathInfo.dynamic) {
22957
+ const node = idMap[id] = createSimpleExpression(path);
22958
+ node.ast = libExports.parseExpression(`(${path})`, {
22959
+ plugins: plugins ? [...plugins, "typescript"] : ["typescript"]
22960
+ });
22961
+ } else {
22962
+ idMap[id] = path;
22963
+ }
22964
+ } else {
22965
+ idMap[id] = path;
22966
+ }
22967
+ });
22968
+ return idMap;
22969
+ }
22918
22970
  function matchPatterns(render, keyProp, idMap) {
22919
22971
  const selectorPatterns = [];
22920
22972
  const keyOnlyBindingPatterns = [];
@@ -23126,7 +23178,6 @@ function genDynamicProps$1(oper, context) {
23126
23178
  helper("setDynamicProps"),
23127
23179
  `n${oper.element}`,
23128
23180
  genMulti(DELIMITERS_ARRAY, ...values),
23129
- oper.root && "true",
23130
23181
  isSVG && "true"
23131
23182
  )
23132
23183
  ];
@@ -23156,6 +23207,7 @@ function genPropKey({ key: node, modifier, runtimeCamelize, handler, handlerModi
23156
23207
  }
23157
23208
  let key = genExpression(node, context);
23158
23209
  if (runtimeCamelize) {
23210
+ key.push(' || ""');
23159
23211
  key = genCall(helper("camelize"), key);
23160
23212
  }
23161
23213
  if (handler) {
@@ -23397,7 +23449,7 @@ function genCreateComponent(operation, context) {
23397
23449
  const rawProps = context.withId(() => genRawProps(props, context), ids);
23398
23450
  const inlineHandlers = handlers.reduce(
23399
23451
  (acc, { name, value }) => {
23400
- const handler = genEventHandler(context, value, void 0, false);
23452
+ const handler = genEventHandler(context, [value], void 0, false);
23401
23453
  return [...acc, `const ${name} = `, ...handler, NEWLINE];
23402
23454
  },
23403
23455
  []
@@ -23531,7 +23583,7 @@ function genProp(prop, context, isStatic) {
23531
23583
  ": ",
23532
23584
  ...prop.handler ? genEventHandler(
23533
23585
  context,
23534
- prop.values[0],
23586
+ prop.values,
23535
23587
  prop.handlerModifiers,
23536
23588
  true
23537
23589
  ) : isStatic ? ["() => (", ...values, ")"] : values,
@@ -23659,35 +23711,29 @@ function genConditionalSlot(slot, context) {
23659
23711
  ];
23660
23712
  }
23661
23713
  function genSlotBlockWithProps(oper, context) {
23662
- let isDestructureAssignment = false;
23663
- let rawProps;
23664
23714
  let propsName;
23665
23715
  let exitScope;
23666
23716
  let depth;
23667
23717
  const { props, key, node } = oper;
23668
- const idsOfProps = /* @__PURE__ */ new Set();
23718
+ const idToPathMap = props ? parseValueDestructure(props, context) : /* @__PURE__ */ new Map();
23669
23719
  if (props) {
23670
- rawProps = props.content;
23671
- if (isDestructureAssignment = !!props.ast) {
23720
+ if (props.ast) {
23672
23721
  [depth, exitScope] = context.enterScope();
23673
23722
  propsName = `_slotProps${depth}`;
23674
- walkIdentifiers(
23675
- props.ast,
23676
- (id, _, __, ___, isLocal) => {
23677
- if (isLocal) idsOfProps.add(id.name);
23678
- },
23679
- true
23680
- );
23681
23723
  } else {
23682
- idsOfProps.add(propsName = rawProps);
23724
+ propsName = props.content;
23683
23725
  }
23684
23726
  }
23685
- const idMap = {};
23686
- idsOfProps.forEach(
23687
- (id) => idMap[id] = isDestructureAssignment ? `${propsName}[${JSON.stringify(id)}]` : null
23688
- );
23727
+ const idMap = idToPathMap.size ? buildDestructureIdMap(
23728
+ idToPathMap,
23729
+ propsName || "",
23730
+ context.options.expressionPlugins
23731
+ ) : {};
23732
+ if (propsName) {
23733
+ idMap[propsName] = null;
23734
+ }
23689
23735
  let blockFn = context.withId(
23690
- () => genBlock(oper, context, [propsName]),
23736
+ () => genBlock(oper, context, propsName ? [propsName] : []),
23691
23737
  idMap
23692
23738
  );
23693
23739
  exitScope && exitScope();
@@ -23708,14 +23754,69 @@ function genSlotBlockWithProps(oper, context) {
23708
23754
  ];
23709
23755
  }
23710
23756
  if (node.type === 1) {
23711
- blockFn = [`${context.helper("withVaporCtx")}(`, ...blockFn, `)`];
23757
+ if (needsVaporCtx(oper)) {
23758
+ blockFn = [`${context.helper("withVaporCtx")}(`, ...blockFn, `)`];
23759
+ }
23712
23760
  }
23713
23761
  return blockFn;
23714
23762
  }
23763
+ function needsVaporCtx(block) {
23764
+ return hasComponentOrSlotInBlock(block);
23765
+ }
23766
+ function hasComponentOrSlotInBlock(block) {
23767
+ if (hasComponentOrSlotInOperations(block.operation)) return true;
23768
+ return hasComponentOrSlotInDynamic(block.dynamic);
23769
+ }
23770
+ function hasComponentOrSlotInDynamic(dynamic) {
23771
+ if (dynamic.operation) {
23772
+ const type = dynamic.operation.type;
23773
+ if (type === 11 || type === 12) {
23774
+ return true;
23775
+ }
23776
+ if (type === 15) {
23777
+ if (hasComponentOrSlotInIf(dynamic.operation)) return true;
23778
+ }
23779
+ if (type === 16) {
23780
+ if (hasComponentOrSlotInBlock(dynamic.operation.render))
23781
+ return true;
23782
+ }
23783
+ }
23784
+ for (const child of dynamic.children) {
23785
+ if (hasComponentOrSlotInDynamic(child)) return true;
23786
+ }
23787
+ return false;
23788
+ }
23789
+ function hasComponentOrSlotInOperations(operations) {
23790
+ for (const op of operations) {
23791
+ switch (op.type) {
23792
+ case 11:
23793
+ case 12:
23794
+ return true;
23795
+ case 15:
23796
+ if (hasComponentOrSlotInIf(op)) return true;
23797
+ break;
23798
+ case 16:
23799
+ if (hasComponentOrSlotInBlock(op.render)) return true;
23800
+ break;
23801
+ }
23802
+ }
23803
+ return false;
23804
+ }
23805
+ function hasComponentOrSlotInIf(node) {
23806
+ if (hasComponentOrSlotInBlock(node.positive)) return true;
23807
+ if (node.negative) {
23808
+ if ("positive" in node.negative) {
23809
+ return hasComponentOrSlotInIf(node.negative);
23810
+ } else {
23811
+ return hasComponentOrSlotInBlock(node.negative);
23812
+ }
23813
+ }
23814
+ return false;
23815
+ }
23715
23816
 
23716
23817
  function genSlotOutlet(oper, context) {
23717
23818
  const { helper } = context;
23718
- const { id, name, fallback, noSlotted } = oper;
23819
+ const { id, name, fallback, noSlotted, once } = oper;
23719
23820
  const [frag, push] = buildCodeFragment();
23720
23821
  const nameExpr = name.isStatic ? genExpression(name, context) : ["() => (", ...genExpression(name, context), ")"];
23721
23822
  let fallbackArg;
@@ -23730,8 +23831,10 @@ function genSlotOutlet(oper, context) {
23730
23831
  nameExpr,
23731
23832
  genRawProps(oper.props, context) || "null",
23732
23833
  fallbackArg,
23733
- noSlotted && "true"
23834
+ noSlotted && "true",
23734
23835
  // noSlotted
23836
+ once && "true"
23837
+ // v-once
23735
23838
  )
23736
23839
  );
23737
23840
  return frag;
@@ -23863,7 +23966,7 @@ function genInsertionState(operation, context) {
23863
23966
  ];
23864
23967
  }
23865
23968
 
23866
- function genTemplates(templates, rootIndex, context) {
23969
+ function genTemplates(templates, rootIndexes, context) {
23867
23970
  const result = [];
23868
23971
  let i = 0;
23869
23972
  templates.forEach((ns, template) => {
@@ -23874,7 +23977,7 @@ function genTemplates(templates, rootIndex, context) {
23874
23977
  // replace import expressions with string concatenation
23875
23978
  IMPORT_EXPR_RE,
23876
23979
  `" + $1 + "`
23877
- )}${i === rootIndex ? ", true" : ns ? ", false" : ""}${ns ? `, ${ns}` : ""})
23980
+ )}${rootIndexes.has(i) ? ", true" : ns ? ", false" : ""}${ns ? `, ${ns}` : ""})
23878
23981
  `
23879
23982
  );
23880
23983
  i++;
@@ -23981,9 +24084,6 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
23981
24084
  const [frag, push] = buildCodeFragment();
23982
24085
  const { dynamic, effect, operation, returns, key } = block;
23983
24086
  const resetBlock = context.enterBlock(block);
23984
- if (block.hasDeferredVShow) {
23985
- push(NEWLINE, `const deferredApplyVShows = []`);
23986
- }
23987
24087
  if (root) {
23988
24088
  for (let name of context.ir.component) {
23989
24089
  const id = toValidAssetId(name, "component");
@@ -24012,7 +24112,7 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
24012
24112
  }
24013
24113
  push(...genOperations(operation, context));
24014
24114
  push(...genEffects(effect, context, genEffectsExtraFrag));
24015
- if (block.hasDeferredVShow) {
24115
+ if (root && context.ir.hasDeferredVShow) {
24016
24116
  push(NEWLINE, `deferredApplyVShows.forEach(fn => fn())`);
24017
24117
  }
24018
24118
  if (dynamic.needsKey) {
@@ -24168,13 +24268,16 @@ function generate(ir, options = {}) {
24168
24268
  `const ${setTemplateRefIdent} = ${context.helper("createTemplateRefSetter")}()`
24169
24269
  );
24170
24270
  }
24271
+ if (ir.hasDeferredVShow) {
24272
+ push(NEWLINE, `const deferredApplyVShows = []`);
24273
+ }
24171
24274
  push(...genBlockContent(ir.block, context, true));
24172
24275
  push(INDENT_END, NEWLINE);
24173
24276
  if (!inline) {
24174
24277
  push("}");
24175
24278
  }
24176
24279
  const delegates = genDelegates(context);
24177
- const templates = genTemplates(ir.template, ir.rootTemplateIndex, context);
24280
+ const templates = genTemplates(ir.template, ir.rootTemplateIndexes, context);
24178
24281
  const imports = genHelperImports(context) + genAssetImports(context);
24179
24282
  const preamble = imports + templates + delegates;
24180
24283
  const newlineCount = [...preamble].filter((c) => c === "\n").length;
@@ -24321,6 +24424,11 @@ const isReservedProp = /* @__PURE__ */ makeMap(
24321
24424
  const transformElement = (node, context) => {
24322
24425
  let effectIndex = context.block.effect.length;
24323
24426
  const getEffectIndex = () => effectIndex++;
24427
+ let parentSlots;
24428
+ if (node.type === 1 && (node.tagType === 1 || context.options.isCustomElement(node.tag))) {
24429
+ parentSlots = context.slots;
24430
+ context.slots = [];
24431
+ }
24324
24432
  return function postTransformElement() {
24325
24433
  ({ node } = context);
24326
24434
  if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1)))
@@ -24335,11 +24443,7 @@ const transformElement = (node, context) => {
24335
24443
  isDynamicComponent,
24336
24444
  getEffectIndex
24337
24445
  );
24338
- let { parent } = context;
24339
- while (parent && parent.parent && parent.node.type === 1 && parent.node.tagType === 3) {
24340
- parent = parent.parent;
24341
- }
24342
- const singleRoot = context.root === parent && parent.node.children.filter((child) => child.type !== 3).length === 1 || isCustomElement;
24446
+ const singleRoot = isSingleRoot(context);
24343
24447
  if (isComponent) {
24344
24448
  transformComponentElement(
24345
24449
  node,
@@ -24358,8 +24462,27 @@ const transformElement = (node, context) => {
24358
24462
  getEffectIndex
24359
24463
  );
24360
24464
  }
24465
+ if (parentSlots) {
24466
+ context.slots = parentSlots;
24467
+ }
24361
24468
  };
24362
24469
  };
24470
+ function isSingleRoot(context) {
24471
+ if (context.inVFor) {
24472
+ return false;
24473
+ }
24474
+ let { parent } = context;
24475
+ if (parent && !(hasSingleChild(parent.node) || isSingleIfBlock(parent.node))) {
24476
+ return false;
24477
+ }
24478
+ while (parent && parent.parent && parent.node.type === 1 && parent.node.tagType === 3) {
24479
+ parent = parent.parent;
24480
+ if (!(hasSingleChild(parent.node) || isSingleIfBlock(parent.node))) {
24481
+ return false;
24482
+ }
24483
+ }
24484
+ return context.root === parent;
24485
+ }
24363
24486
  function transformComponentElement(node, propsResult, singleRoot, context, isDynamicComponent, isCustomElement) {
24364
24487
  const dynamicComponent = isDynamicComponent ? resolveDynamicComponent(node) : void 0;
24365
24488
  let { tag } = node;
@@ -24397,7 +24520,7 @@ function transformComponentElement(node, propsResult, singleRoot, context, isDyn
24397
24520
  tag,
24398
24521
  props: propsResult[0] ? propsResult[1] : [propsResult[1]],
24399
24522
  asset,
24400
- root: singleRoot && !context.inVFor,
24523
+ root: singleRoot,
24401
24524
  slots: [...context.slots],
24402
24525
  once: context.inVOnce,
24403
24526
  dynamic: dynamicComponent,
@@ -24448,7 +24571,6 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
24448
24571
  type: 3,
24449
24572
  element: context.reference(),
24450
24573
  props: dynamicArgs,
24451
- root: singleRoot,
24452
24574
  tag
24453
24575
  },
24454
24576
  getEffectIndex
@@ -24472,7 +24594,6 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
24472
24594
  type: 2,
24473
24595
  element: context.reference(),
24474
24596
  prop,
24475
- root: singleRoot,
24476
24597
  tag
24477
24598
  },
24478
24599
  getEffectIndex
@@ -24485,7 +24606,7 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
24485
24606
  template += `</${tag}>`;
24486
24607
  }
24487
24608
  if (singleRoot) {
24488
- context.ir.rootTemplateIndex = context.ir.template.size;
24609
+ context.ir.rootTemplateIndexes.add(context.ir.template.size);
24489
24610
  }
24490
24611
  if (context.parent && context.parent.node.type === 1 && !isValidHTMLNesting(context.parent.node.tag, tag)) {
24491
24612
  context.reference();
@@ -24618,7 +24739,7 @@ function dedupeProperties(results) {
24618
24739
  const name = prop.key.content;
24619
24740
  const existing = knownProps.get(name);
24620
24741
  if (existing && existing.handler === prop.handler) {
24621
- if (name === "style" || name === "class") {
24742
+ if (name === "style" || name === "class" || prop.handler) {
24622
24743
  mergePropValues(existing, prop);
24623
24744
  }
24624
24745
  } else {
@@ -24783,6 +24904,9 @@ const transformVOn = (dir, node, context) => {
24783
24904
  keyOverride = ["click", "contextmenu"];
24784
24905
  }
24785
24906
  }
24907
+ if (keyModifiers.length && isStaticExp(arg) && !isKeyboardEvent(`on${arg.content.toLowerCase()}`)) {
24908
+ keyModifiers.length = 0;
24909
+ }
24786
24910
  if (isComponent || isSlotOutlet) {
24787
24911
  const handler = exp || EMPTY_EXPRESSION;
24788
24912
  return {
@@ -24836,7 +24960,7 @@ const transformVShow = (dir, node, context) => {
24836
24960
  if (parentNode && parentNode.type === 1) {
24837
24961
  shouldDeferred = !!(isTransitionTag(parentNode.tag) && findProp(parentNode, "appear", false, true));
24838
24962
  if (shouldDeferred) {
24839
- context.parent.parent.block.hasDeferredVShow = true;
24963
+ context.ir.hasDeferredVShow = true;
24840
24964
  }
24841
24965
  }
24842
24966
  context.registerOperation({
@@ -25109,7 +25233,7 @@ function getSiblingIf(context, reverse) {
25109
25233
  let i = siblings.indexOf(context.node);
25110
25234
  while (reverse ? --i >= 0 : ++i < siblings.length) {
25111
25235
  sibling = siblings[i];
25112
- if (!isCommentLike(sibling)) {
25236
+ if (!isCommentOrWhitespace(sibling)) {
25113
25237
  break;
25114
25238
  }
25115
25239
  }
@@ -25119,9 +25243,6 @@ function getSiblingIf(context, reverse) {
25119
25243
  return sibling;
25120
25244
  }
25121
25245
  }
25122
- function isCommentLike(node) {
25123
- return node.type === 3 || node.type === 2 && !node.content.trim().length;
25124
- }
25125
25246
 
25126
25247
  const transformVIf = createStructuralDirectiveTransform(
25127
25248
  ["if", "else", "else-if"],
@@ -25345,7 +25466,8 @@ const transformSlotOutlet = (node, context) => {
25345
25466
  name: slotName,
25346
25467
  props: irProps,
25347
25468
  fallback,
25348
- noSlotted: !!(context.options.scopeId && !context.options.slotted)
25469
+ noSlotted: !!(context.options.scopeId && !context.options.slotted),
25470
+ once: context.inVOnce
25349
25471
  };
25350
25472
  };
25351
25473
  };