@vue-jsx-vapor/compiler 0.2.4 → 0.2.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.
package/dist/index.js CHANGED
@@ -59,47 +59,13 @@ var DynamicFlag = /* @__PURE__ */ ((DynamicFlag2) => {
59
59
  })(DynamicFlag || {});
60
60
 
61
61
  // src/transforms/utils.ts
62
- import { createSimpleExpression } from "@vue/compiler-dom";
62
+ import { createSimpleExpression as createSimpleExpression2 } from "@vue/compiler-dom";
63
63
  import {
64
64
  jsxClosingFragment,
65
65
  jsxExpressionContainer,
66
66
  jsxFragment,
67
67
  jsxOpeningFragment
68
68
  } from "@babel/types";
69
- function newDynamic() {
70
- return {
71
- flags: 1 /* REFERENCED */,
72
- children: []
73
- };
74
- }
75
- function newBlock(node) {
76
- return {
77
- type: 1,
78
- node,
79
- dynamic: newDynamic(),
80
- effect: [],
81
- operation: [],
82
- returns: [],
83
- expressions: [],
84
- tempId: 0
85
- };
86
- }
87
- function createBranch(node, context, isVFor) {
88
- context.node = node = wrapFragment(node);
89
- const branch = newBlock(node);
90
- const exitBlock = context.enterBlock(branch, isVFor);
91
- context.reference();
92
- return [branch, exitBlock];
93
- }
94
- function wrapFragment(node) {
95
- if (node.type === "JSXFragment") {
96
- return node;
97
- }
98
- return jsxFragment(jsxOpeningFragment(), jsxClosingFragment(), [
99
- node.type === "JSXElement" ? node : jsxExpressionContainer(node)
100
- ]);
101
- }
102
- var EMPTY_EXPRESSION = createSimpleExpression("", true);
103
69
 
104
70
  // src/utils.ts
105
71
  import { isGloballyAllowed, isHTMLTag, isSVGTag, isString } from "@vue/shared";
@@ -107,13 +73,14 @@ import {
107
73
  ElementTypes,
108
74
  Namespaces,
109
75
  NodeTypes,
110
- createSimpleExpression as createSimpleExpression2,
76
+ createSimpleExpression,
111
77
  isLiteralWhitelisted,
112
78
  walkIdentifiers
113
79
  } from "@vue/compiler-dom";
114
80
  import {
115
81
  isLiteral
116
82
  } from "@babel/types";
83
+ import { parseExpression } from "@babel/parser";
117
84
  function propToExpression(prop, context) {
118
85
  return prop.type === "JSXAttribute" && prop.value?.type === "JSXExpressionContainer" ? resolveExpression(prop.value.expression, context) : EMPTY_EXPRESSION;
119
86
  }
@@ -170,6 +137,15 @@ function resolveJSXText(node) {
170
137
  function isEmptyText(node) {
171
138
  return node.type === "JSXText" && EMPTY_TEXT_REGEX.test(`${node.extra?.raw}`) || node.type === "JSXExpressionContainer" && node.expression.type === "JSXEmptyExpression";
172
139
  }
140
+ function resolveSimpleExpressionNode(exp) {
141
+ if (!exp.isStatic) {
142
+ const value = getLiteralExpressionValue(exp);
143
+ if (value !== null) {
144
+ return createSimpleExpression(`${value}`, true, exp.loc);
145
+ }
146
+ }
147
+ return exp;
148
+ }
173
149
  function resolveExpression(node, context, effect = false) {
174
150
  node = node?.type === "JSXExpressionContainer" ? node.expression : node;
175
151
  const isStatic = !!node && (node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier");
@@ -197,7 +173,7 @@ function resolveExpression(node, context, effect = false) {
197
173
  return resolveSimpleExpression(source, isStatic, location, node);
198
174
  }
199
175
  function resolveSimpleExpression(source, isStatic, location, ast) {
200
- const result = createSimpleExpression2(
176
+ const result = createSimpleExpression(
201
177
  source,
202
178
  isStatic,
203
179
  resolveLocation(location, source)
@@ -269,23 +245,54 @@ function resolveNode(node, context) {
269
245
  codegenNode: void 0
270
246
  };
271
247
  }
272
- function resolveDirectiveNode(node, context) {
248
+ var namespaceRE = /^(?:\$([\w-]+)\$)?([\w-]+)?/;
249
+ function resolveDirectiveNode(node, context, withFn = false) {
273
250
  const { value, name } = node;
274
- const nameString = name.type === "JSXIdentifier" ? name.name : "";
275
- const argString = name.type === "JSXNamespacedName" ? name.namespace.name : "";
276
- const arg = name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, true, name.namespace.loc) : void 0;
277
- const exp = value ? resolveExpression(value, context) : void 0;
278
- const [tag, ...modifiers] = argString.split("_");
251
+ const nameString = name.type === "JSXNamespacedName" ? name.namespace.name : name.type === "JSXIdentifier" ? name.name : "";
252
+ let argString = name.type === "JSXNamespacedName" ? name.name.name : "";
253
+ if (name.type !== "JSXNamespacedName" && !argString) {
254
+ const [, modifiers2] = nameString.split("_");
255
+ argString = `_${modifiers2}`;
256
+ }
257
+ let modifiers = [];
258
+ let isStatic = true;
259
+ const result = argString.match(namespaceRE);
260
+ if (result) {
261
+ let modifierString = "";
262
+ [, argString, modifierString] = result;
263
+ if (argString) {
264
+ argString = argString.replaceAll("_", ".");
265
+ isStatic = false;
266
+ if (modifierString && modifierString.startsWith("_"))
267
+ modifiers = modifierString.slice(1).split("_");
268
+ } else if (modifierString) {
269
+ ;
270
+ [argString, ...modifiers] = modifierString.split("_");
271
+ }
272
+ }
273
+ const arg = argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0;
274
+ const exp = value ? withFn && value.type === "JSXExpressionContainer" ? resolveExpressionWithFn(value.expression, context) : resolveExpression(value, context) : void 0;
279
275
  return {
280
276
  type: NodeTypes.DIRECTIVE,
281
277
  name: nameString,
282
- rawName: `${name}:${tag}`,
278
+ rawName: `${nameString}:${argString}`,
283
279
  exp,
284
280
  arg,
285
281
  loc: resolveLocation(node.loc, context),
286
- modifiers: modifiers.map((modifier) => createSimpleExpression2(modifier))
282
+ modifiers: modifiers.map((modifier) => createSimpleExpression(modifier))
287
283
  };
288
284
  }
285
+ function resolveExpressionWithFn(node, context) {
286
+ const text = getText(node, context);
287
+ return node.type === "Identifier" ? resolveSimpleExpression(text, false, node.loc) : resolveSimpleExpression(
288
+ text,
289
+ false,
290
+ node.loc,
291
+ parseExpression(`(${text})=>{}`, {
292
+ plugins: ["typescript"]
293
+ })
294
+ );
295
+ }
289
296
  function isJSXComponent(node) {
290
297
  if (node.type !== "JSXElement") return false;
291
298
  const { openingElement } = node;
@@ -299,7 +306,8 @@ function isJSXComponent(node) {
299
306
  function findProp(expression, key) {
300
307
  if (expression?.type === "JSXElement") {
301
308
  for (const attr of expression.openingElement.attributes) {
302
- if (attr.type === "JSXAttribute" && attr.name.name === key) {
309
+ const name = attr.type === "JSXAttribute" && (attr.name.type === "JSXIdentifier" ? attr.name.name : attr.name.type === "JSXNamespacedName" ? attr.name.namespace.name : "").split("_")[0];
310
+ if (name && (isString(key) ? name === key : key.test(name))) {
303
311
  return attr;
304
312
  }
305
313
  }
@@ -308,6 +316,47 @@ function findProp(expression, key) {
308
316
  function getText(node, content) {
309
317
  return content.ir.source.slice(node.start, node.end);
310
318
  }
319
+ function isTemplate(node) {
320
+ if (node.type === "JSXElement" && node.openingElement.name.type === "JSXIdentifier") {
321
+ return node.openingElement.name.name === "template";
322
+ }
323
+ }
324
+
325
+ // src/transforms/utils.ts
326
+ function newDynamic() {
327
+ return {
328
+ flags: 1 /* REFERENCED */,
329
+ children: []
330
+ };
331
+ }
332
+ function newBlock(node) {
333
+ return {
334
+ type: 1,
335
+ node,
336
+ dynamic: newDynamic(),
337
+ effect: [],
338
+ operation: [],
339
+ returns: [],
340
+ expressions: [],
341
+ tempId: 0
342
+ };
343
+ }
344
+ function createBranch(node, context, isVFor) {
345
+ context.node = node = wrapFragment(node);
346
+ const branch = newBlock(node);
347
+ const exitBlock = context.enterBlock(branch, isVFor);
348
+ context.reference();
349
+ return [branch, exitBlock];
350
+ }
351
+ function wrapFragment(node) {
352
+ if (node.type === "JSXFragment" || isTemplate(node)) {
353
+ return node;
354
+ }
355
+ return jsxFragment(jsxOpeningFragment(), jsxClosingFragment(), [
356
+ node.type === "JSXElement" ? node : jsxExpressionContainer(node)
357
+ ]);
358
+ }
359
+ var EMPTY_EXPRESSION = createSimpleExpression2("", true);
311
360
 
312
361
  // src/transform.ts
313
362
  var defaultOptions = {
@@ -471,9 +520,9 @@ function createStructuralDirectiveTransform(name, fn) {
471
520
  return (node, context) => {
472
521
  if (node.type === "JSXElement") {
473
522
  const {
474
- openingElement: { attributes, name: name2 }
523
+ openingElement: { attributes }
475
524
  } = node;
476
- if (getText(name2, context) === "template" && findProp(node, "v-slot")) {
525
+ if (isTemplate(node) && findProp(node, "v-slot")) {
477
526
  return;
478
527
  }
479
528
  const exitFns = [];
@@ -507,7 +556,7 @@ var transformElement = (node, context) => {
507
556
  return function postTransformElement() {
508
557
  ;
509
558
  ({ node } = context);
510
- if (node.type !== "JSXElement") return;
559
+ if (node.type !== "JSXElement" || isTemplate(node)) return;
511
560
  const {
512
561
  openingElement: { name }
513
562
  } = node;
@@ -518,7 +567,11 @@ var transformElement = (node, context) => {
518
567
  context,
519
568
  isComponent
520
569
  );
521
- const singleRoot = context.root === context.parent && context.parent.node.children.filter((child) => !isJSXComponent(child)).length === 1;
570
+ let { parent } = context;
571
+ while (parent && parent.parent && parent.node.type === "JSXElement" && isTemplate(parent.node)) {
572
+ parent = parent.parent;
573
+ }
574
+ const singleRoot = context.root === parent && parent.node.children.filter((child) => !isJSXComponent(child)).length === 1;
522
575
  (isComponent ? transformComponentElement : transformNativeElement)(
523
576
  tag,
524
577
  propsResult,
@@ -653,6 +706,7 @@ function buildProps(node, context, isComponent) {
653
706
  function transformProp(prop, node, context) {
654
707
  if (prop.type === "JSXSpreadAttribute") return;
655
708
  let name = prop.name.type === "JSXIdentifier" ? prop.name.name : prop.name.type === "JSXNamespacedName" ? prop.name.namespace.name : "";
709
+ name = name.split("_")[0];
656
710
  if (!isDirectiveRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
657
711
  if (isReservedProp(name)) return;
658
712
  return {
@@ -709,7 +763,7 @@ function mergePropValues(existing, incoming) {
709
763
 
710
764
  // src/transforms/transformChildren.ts
711
765
  var transformChildren = (node, context) => {
712
- const isFragment = node.type === 0 /* ROOT */ || node.type === "JSXFragment" || isJSXComponent(node);
766
+ const isFragment = node.type === 0 /* ROOT */ || node.type === "JSXFragment" || node.type === "JSXElement" && (isTemplate(node) || isJSXComponent(node));
713
767
  if (node.type !== "JSXElement" && !isFragment) return;
714
768
  for (const [i, child] of node.children.entries()) {
715
769
  const childContext = context.create(child, i);
@@ -868,7 +922,7 @@ var transformText = (node, context) => {
868
922
  context.dynamic.flags |= 2 /* NON_TEMPLATE */;
869
923
  return;
870
924
  }
871
- if (node.type === "JSXElement" && !isJSXComponent(node) && isAllTextLike(node.children)) {
925
+ if (node.type === "JSXElement" && !isTemplate(node) && !isJSXComponent(node) && isAllTextLike(node.children)) {
872
926
  processTextLikeContainer(
873
927
  node.children,
874
928
  context
@@ -894,11 +948,13 @@ function processTextLike(context) {
894
948
  const nexts = context.parent.node.children?.slice(context.index);
895
949
  const idx = nexts.findIndex((n) => !isTextLike(n));
896
950
  const nodes = idx > -1 ? nexts.slice(0, idx) : nexts;
951
+ const id = context.reference();
952
+ const values = createTextLikeExpressions(nodes, context);
897
953
  context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
898
954
  context.registerOperation({
899
955
  type: 11 /* CREATE_TEXT_NODE */,
900
- id: context.reference(),
901
- values: createTextLikeExpressions(nodes, context),
956
+ id,
957
+ values,
902
958
  jsx: true
903
959
  });
904
960
  }
@@ -921,7 +977,7 @@ function createTextLikeExpressions(nodes, context) {
921
977
  for (const node of nodes) {
922
978
  seen.get(context.root).add(node);
923
979
  if (isEmptyText(node)) continue;
924
- values.push(resolveExpression(node, context, true));
980
+ values.push(resolveExpression(node, context, !context.inVOnce));
925
981
  }
926
982
  return values;
927
983
  }
@@ -1037,42 +1093,211 @@ var transformVOn = (dir, node, context) => {
1037
1093
  };
1038
1094
 
1039
1095
  // src/transforms/vSlot.ts
1040
- var transformVSlot = (node, context) => {
1041
- if (node.type !== "JSXElement") return;
1042
- if (!isJSXComponent(node)) return;
1043
- const { openingElement, children } = node;
1044
- const vSlotsIndex = openingElement.attributes.findIndex(
1045
- (attr) => attr.type === "JSXAttribute" && ["v-slots", "vSlots"].includes(attr.name.name.toString())
1046
- );
1047
- const vSlotsDir = openingElement.attributes[vSlotsIndex];
1048
- if (vSlotsDir && vSlotsDir.value?.type === "JSXExpressionContainer") {
1049
- node.openingElement.attributes.splice(vSlotsIndex, 1);
1050
- context.slots = [
1051
- {
1052
- slotType: 4 /* EXPRESSION */,
1053
- slots: resolveExpression(vSlotsDir.value.expression, context)
1096
+ import {
1097
+ ErrorCodes as ErrorCodes3,
1098
+ createCompilerError as createCompilerError3
1099
+ } from "@vue/compiler-dom";
1100
+
1101
+ // src/transforms/vFor.ts
1102
+ import {
1103
+ ErrorCodes as ErrorCodes2,
1104
+ createCompilerError as createCompilerError2,
1105
+ isConstantNode
1106
+ } from "@vue/compiler-dom";
1107
+ var transformVFor = createStructuralDirectiveTransform(
1108
+ "for",
1109
+ processFor
1110
+ );
1111
+ function processFor(node, dir, context) {
1112
+ const { value, index, key, source } = getForParseResult(dir, context);
1113
+ if (!source) {
1114
+ context.options.onError(
1115
+ createCompilerError2(
1116
+ ErrorCodes2.X_V_FOR_MALFORMED_EXPRESSION,
1117
+ resolveLocation(dir.loc, context)
1118
+ )
1119
+ );
1120
+ return;
1121
+ }
1122
+ const keyProp = findProp(node, "key");
1123
+ const keyProperty = keyProp && propToExpression(keyProp, context);
1124
+ const isComponent = isJSXComponent(node);
1125
+ const id = context.reference();
1126
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
1127
+ const [render, exitBlock] = createBranch(node, context, true);
1128
+ return () => {
1129
+ exitBlock();
1130
+ const { parent } = context;
1131
+ const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
1132
+ context.registerOperation({
1133
+ type: 17 /* FOR */,
1134
+ id,
1135
+ source,
1136
+ value,
1137
+ key,
1138
+ index,
1139
+ keyProp: keyProperty,
1140
+ render,
1141
+ once: context.inVOnce || !!(source.ast && isConstantNode(source.ast, {})),
1142
+ component: isComponent,
1143
+ onlyChild: !!isOnlyChild
1144
+ });
1145
+ };
1146
+ }
1147
+ function getForParseResult(dir, context) {
1148
+ let value, index, key, source;
1149
+ if (dir.value) {
1150
+ if (dir.value.type === "JSXExpressionContainer" && dir.value.expression.type === "BinaryExpression") {
1151
+ if (dir.value.expression.left.type === "SequenceExpression") {
1152
+ const expressions = dir.value.expression.left.expressions;
1153
+ value = expressions[0] && resolveExpressionWithFn(expressions[0], context);
1154
+ key = expressions[1] && resolveExpression(expressions[1], context);
1155
+ index = expressions[2] && resolveExpression(expressions[2], context);
1156
+ } else {
1157
+ value = resolveExpressionWithFn(dir.value.expression.left, context);
1054
1158
  }
1055
- ];
1159
+ source = resolveExpression(dir.value.expression.right, context);
1160
+ }
1161
+ } else {
1162
+ context.options.onError(
1163
+ createCompilerError2(
1164
+ ErrorCodes2.X_V_FOR_NO_EXPRESSION,
1165
+ resolveLocation(dir.loc, context)
1166
+ )
1167
+ );
1056
1168
  }
1057
- if (children.length) {
1058
- return transformComponentSlot(node, context);
1169
+ return {
1170
+ value,
1171
+ index,
1172
+ key,
1173
+ source
1174
+ };
1175
+ }
1176
+
1177
+ // src/transforms/vSlot.ts
1178
+ var transformVSlot = (node, context) => {
1179
+ if (node.type !== "JSXElement") return;
1180
+ const { children } = node;
1181
+ const dir = findProp(node, "v-slot");
1182
+ const resolvedDirective = dir ? resolveDirectiveNode(dir, context, true) : void 0;
1183
+ const { parent } = context;
1184
+ const isComponent = isJSXComponent(node);
1185
+ const isSlotTemplate = isTemplate(node) && parent && parent.node.type === "JSXElement" && isJSXComponent(parent.node);
1186
+ if (isComponent && children.length) {
1187
+ return transformComponentSlot(node, resolvedDirective, context);
1188
+ } else if (isSlotTemplate && resolvedDirective) {
1189
+ return transformTemplateSlot(node, resolvedDirective, context);
1190
+ } else if (!isComponent && dir) {
1191
+ context.options.onError(
1192
+ createCompilerError3(
1193
+ ErrorCodes3.X_V_SLOT_MISPLACED,
1194
+ resolveLocation(dir.loc, context)
1195
+ )
1196
+ );
1059
1197
  }
1060
1198
  };
1061
- function transformComponentSlot(node, context) {
1199
+ function transformComponentSlot(node, dir, context) {
1062
1200
  const { children } = node;
1063
- const nonWhitespaceChildren = children.filter(
1064
- () => isNonWhitespaceContent(node)
1201
+ const arg = dir && dir.arg;
1202
+ const nonSlotTemplateChildren = children.filter(
1203
+ (n) => isNonWhitespaceContent(n) && !(n.type === "JSXElement" && findProp(n, "v-slot"))
1065
1204
  );
1066
- const [block, onExit] = createSlotBlock(node, context);
1205
+ const [block, onExit] = createSlotBlock(node, dir, context);
1067
1206
  const { slots } = context;
1068
1207
  return () => {
1069
1208
  onExit();
1070
- if (nonWhitespaceChildren.length) {
1071
- registerSlot(slots, block);
1209
+ const hasOtherSlots = !!slots.length;
1210
+ if (dir && hasOtherSlots) {
1211
+ context.options.onError(
1212
+ createCompilerError3(ErrorCodes3.X_V_SLOT_MIXED_SLOT_USAGE, dir.loc)
1213
+ );
1214
+ return;
1215
+ }
1216
+ if (nonSlotTemplateChildren.length) {
1217
+ if (hasStaticSlot(slots, "default")) {
1218
+ context.options.onError(
1219
+ createCompilerError3(
1220
+ ErrorCodes3.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN,
1221
+ resolveLocation(nonSlotTemplateChildren[0].loc, context)
1222
+ )
1223
+ );
1224
+ } else {
1225
+ registerSlot(slots, arg, block);
1226
+ context.slots = slots;
1227
+ }
1228
+ } else if (hasOtherSlots) {
1072
1229
  context.slots = slots;
1073
1230
  }
1074
1231
  };
1075
1232
  }
1233
+ var elseIfRE = /^else(-if)?$/;
1234
+ function transformTemplateSlot(node, dir, context) {
1235
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */;
1236
+ const arg = dir.arg && resolveSimpleExpressionNode(dir.arg);
1237
+ const vFor = findProp(node, "v-for");
1238
+ const vIf = findProp(node, "v-if");
1239
+ const vElse = findProp(node, elseIfRE);
1240
+ const { slots } = context;
1241
+ const [block, onExit] = createSlotBlock(node, dir, context);
1242
+ if (!vFor && !vIf && !vElse) {
1243
+ const slotName = arg ? arg.isStatic && arg.content : "default";
1244
+ if (slotName && hasStaticSlot(slots, slotName)) {
1245
+ context.options.onError(
1246
+ createCompilerError3(ErrorCodes3.X_V_SLOT_DUPLICATE_SLOT_NAMES, dir.loc)
1247
+ );
1248
+ } else {
1249
+ registerSlot(slots, arg, block);
1250
+ }
1251
+ } else if (vIf) {
1252
+ const vIfDir = resolveDirectiveNode(vIf, context);
1253
+ registerDynamicSlot(slots, {
1254
+ slotType: 3 /* CONDITIONAL */,
1255
+ condition: vIfDir.exp,
1256
+ positive: {
1257
+ slotType: 1 /* DYNAMIC */,
1258
+ name: arg,
1259
+ fn: block
1260
+ }
1261
+ });
1262
+ } else if (vElse) {
1263
+ const vElseDir = resolveDirectiveNode(vElse, context);
1264
+ const vIfSlot = slots.at(-1);
1265
+ if (vIfSlot.slotType === 3 /* CONDITIONAL */) {
1266
+ let ifNode = vIfSlot;
1267
+ while (ifNode.negative && ifNode.negative.slotType === 3 /* CONDITIONAL */)
1268
+ ifNode = ifNode.negative;
1269
+ const negative = vElseDir.exp ? {
1270
+ slotType: 3 /* CONDITIONAL */,
1271
+ condition: vElseDir.exp,
1272
+ positive: {
1273
+ slotType: 1 /* DYNAMIC */,
1274
+ name: arg,
1275
+ fn: block
1276
+ }
1277
+ } : {
1278
+ slotType: 1 /* DYNAMIC */,
1279
+ name: arg,
1280
+ fn: block
1281
+ };
1282
+ ifNode.negative = negative;
1283
+ } else {
1284
+ context.options.onError(
1285
+ createCompilerError3(ErrorCodes3.X_V_ELSE_NO_ADJACENT_IF, vElseDir.loc)
1286
+ );
1287
+ }
1288
+ } else if (vFor) {
1289
+ const forParseResult = getForParseResult(vFor, context);
1290
+ if (forParseResult.source) {
1291
+ registerDynamicSlot(slots, {
1292
+ slotType: 2 /* LOOP */,
1293
+ name: arg,
1294
+ fn: block,
1295
+ loop: forParseResult
1296
+ });
1297
+ }
1298
+ }
1299
+ return onExit;
1300
+ }
1076
1301
  function ensureStaticSlots(slots) {
1077
1302
  let lastSlots = slots.at(-1);
1078
1303
  if (!slots.length || lastSlots.slotType !== 0 /* STATIC */) {
@@ -1083,14 +1308,32 @@ function ensureStaticSlots(slots) {
1083
1308
  }
1084
1309
  );
1085
1310
  }
1086
- return lastSlots;
1311
+ return lastSlots.slots;
1312
+ }
1313
+ function registerSlot(slots, name, block) {
1314
+ const isStatic = !name || name.isStatic;
1315
+ if (isStatic) {
1316
+ const staticSlots = ensureStaticSlots(slots);
1317
+ staticSlots[name ? name.content : "default"] = block;
1318
+ } else {
1319
+ slots.push({
1320
+ slotType: 1 /* DYNAMIC */,
1321
+ name,
1322
+ fn: block
1323
+ });
1324
+ }
1087
1325
  }
1088
- function registerSlot(slots, block) {
1089
- const staticSlots = ensureStaticSlots(slots);
1090
- staticSlots.slots.default = block;
1326
+ function registerDynamicSlot(allSlots, dynamic) {
1327
+ allSlots.push(dynamic);
1328
+ }
1329
+ function hasStaticSlot(slots, name) {
1330
+ return slots.some(
1331
+ (slot) => slot.slotType === 0 /* STATIC */ ? !!slot.slots[name] : false
1332
+ );
1091
1333
  }
1092
- function createSlotBlock(slotNode, context) {
1334
+ function createSlotBlock(slotNode, dir, context) {
1093
1335
  const block = newBlock(slotNode);
1336
+ block.props = dir && dir.exp;
1094
1337
  const exitBlock = context.enterBlock(block);
1095
1338
  return [block, exitBlock];
1096
1339
  }
@@ -1099,6 +1342,37 @@ function isNonWhitespaceContent(node) {
1099
1342
  return !!node.value.trim();
1100
1343
  }
1101
1344
 
1345
+ // src/transforms/vSlots.ts
1346
+ import { ErrorCodes as ErrorCodes4, createCompilerError as createCompilerError4 } from "@vue/compiler-dom";
1347
+ var transformVSlots = (node, context) => {
1348
+ if (node.type !== "JSXElement" || !isJSXComponent(node)) return;
1349
+ const {
1350
+ openingElement: { attributes },
1351
+ children
1352
+ } = node;
1353
+ const vSlotsIndex = attributes.findIndex(
1354
+ (attr) => attr.type === "JSXAttribute" && attr.name.name.toString() === "v-slots"
1355
+ );
1356
+ const vSlotsDir = attributes[vSlotsIndex];
1357
+ if (vSlotsDir && vSlotsDir.value?.type === "JSXExpressionContainer") {
1358
+ attributes.splice(vSlotsIndex, 1);
1359
+ context.slots = [
1360
+ {
1361
+ slotType: 4 /* EXPRESSION */,
1362
+ slots: resolveExpression(vSlotsDir.value.expression, context)
1363
+ }
1364
+ ];
1365
+ if (children.length) {
1366
+ context.options.onError(
1367
+ createCompilerError4(
1368
+ ErrorCodes4.X_V_SLOT_MIXED_SLOT_USAGE,
1369
+ resolveLocation(children[0].loc, context)
1370
+ )
1371
+ );
1372
+ }
1373
+ }
1374
+ };
1375
+
1102
1376
  // src/transforms/vModel.ts
1103
1377
  import { transformVModel as _transformVModel } from "@vue/compiler-vapor";
1104
1378
  var transformVModel = (dir, node, context) => {
@@ -1129,85 +1403,15 @@ var transformVHtml = (dir, node, context) => {
1129
1403
  );
1130
1404
  };
1131
1405
 
1132
- // src/transforms/vFor.ts
1133
- import {
1134
- ErrorCodes as ErrorCodes2,
1135
- createCompilerError as createCompilerError2,
1136
- forAliasRE,
1137
- isConstantNode
1138
- } from "@vue/compiler-dom";
1139
- import { parseExpression } from "@babel/parser";
1140
- var transformVFor = createStructuralDirectiveTransform(
1141
- "for",
1142
- processFor
1143
- );
1144
- function processFor(node, dir, context) {
1145
- if (!dir.value) {
1146
- context.options.onError(
1147
- createCompilerError2(
1148
- ErrorCodes2.X_V_FOR_NO_EXPRESSION,
1149
- resolveLocation(dir.loc, context)
1150
- )
1151
- );
1152
- return;
1406
+ // src/transforms/vOnce.ts
1407
+ var transformVOnce = (node, context) => {
1408
+ if (
1409
+ // !context.inSSR &&
1410
+ node.type === "JSXElement" && findProp(node, "v-once")
1411
+ ) {
1412
+ context.inVOnce = true;
1153
1413
  }
1154
- if (!forAliasRE) {
1155
- context.options.onError(
1156
- createCompilerError2(
1157
- ErrorCodes2.X_V_FOR_MALFORMED_EXPRESSION,
1158
- resolveLocation(dir.loc, context)
1159
- )
1160
- );
1161
- return;
1162
- }
1163
- let value, index, key, source;
1164
- if (dir.value.type === "JSXExpressionContainer" && dir.value.expression.type === "BinaryExpression") {
1165
- if (dir.value.expression.left.type === "SequenceExpression") {
1166
- const expressions = dir.value.expression.left.expressions;
1167
- value = expressions[0] && resolveValueExpression(expressions[0], context);
1168
- key = expressions[1] && resolveExpression(expressions[1], context);
1169
- index = expressions[2] && resolveExpression(expressions[2], context);
1170
- } else {
1171
- value = resolveValueExpression(dir.value.expression.left, context);
1172
- }
1173
- source = resolveExpression(dir.value.expression.right, context);
1174
- }
1175
- const keyProp = findProp(node, "key");
1176
- const keyProperty = keyProp && propToExpression(keyProp, context);
1177
- const isComponent = isJSXComponent(node);
1178
- const id = context.reference();
1179
- context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
1180
- const [render, exitBlock] = createBranch(node, context, true);
1181
- return () => {
1182
- exitBlock();
1183
- const { parent } = context;
1184
- const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
1185
- context.registerOperation({
1186
- type: 17 /* FOR */,
1187
- id,
1188
- source,
1189
- value,
1190
- key,
1191
- index,
1192
- keyProp: keyProperty,
1193
- render,
1194
- once: context.inVOnce || !!(source.ast && isConstantNode(source.ast, {})),
1195
- component: isComponent,
1196
- onlyChild: !!isOnlyChild
1197
- });
1198
- };
1199
- }
1200
- function resolveValueExpression(node, context) {
1201
- const text = getText(node, context);
1202
- return node.type === "Identifier" ? resolveSimpleExpression(text, false, node.loc) : resolveSimpleExpression(
1203
- text,
1204
- false,
1205
- node.loc,
1206
- parseExpression(`(${text})=>{}`, {
1207
- plugins: ["typescript"]
1208
- })
1209
- );
1210
- }
1414
+ };
1211
1415
 
1212
1416
  // src/compile.ts
1213
1417
  function compile(source, options = {}) {
@@ -1260,10 +1464,12 @@ function compile(source, options = {}) {
1260
1464
  function getBaseTransformPreset() {
1261
1465
  return [
1262
1466
  [
1467
+ transformVOnce,
1263
1468
  transformVFor,
1264
1469
  transformTemplateRef,
1265
1470
  transformText,
1266
1471
  transformElement,
1472
+ transformVSlots,
1267
1473
  transformVSlot,
1268
1474
  transformChildren
1269
1475
  ],
@@ -1299,5 +1505,6 @@ export {
1299
1505
  transformVModel,
1300
1506
  transformVOn,
1301
1507
  transformVShow,
1302
- transformVSlot
1508
+ transformVSlot,
1509
+ transformVSlots
1303
1510
  };