@vue-jsx-vapor/compiler 0.2.4 → 0.2.5

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.cjs CHANGED
@@ -66,40 +66,6 @@ var DynamicFlag = /* @__PURE__ */ ((DynamicFlag2) => {
66
66
 
67
67
 
68
68
  var _types = require('@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 _types.jsxFragment.call(void 0, _types.jsxOpeningFragment.call(void 0, ), _types.jsxClosingFragment.call(void 0, ), [
99
- node.type === "JSXElement" ? node : _types.jsxExpressionContainer.call(void 0, node)
100
- ]);
101
- }
102
- var EMPTY_EXPRESSION = _compilerdom.createSimpleExpression.call(void 0, "", true);
103
69
 
104
70
  // src/utils.ts
105
71
 
@@ -114,6 +80,7 @@ var EMPTY_EXPRESSION = _compilerdom.createSimpleExpression.call(void 0, "", true
114
80
 
115
81
 
116
82
 
83
+
117
84
  function propToExpression(prop, context) {
118
85
  return prop.type === "JSXAttribute" && _optionalChain([prop, 'access', _2 => _2.value, 'optionalAccess', _3 => _3.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(`${_optionalChain([node, 'access', _6 => _6.extra, 'optionalAccess', _7 => _7.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 _compilerdom.createSimpleExpression.call(void 0, `${value}`, true, exp.loc);
145
+ }
146
+ }
147
+ return exp;
148
+ }
173
149
  function resolveExpression(node, context, effect = false) {
174
150
  node = _optionalChain([node, 'optionalAccess', _8 => _8.type]) === "JSXExpressionContainer" ? node.expression : node;
175
151
  const isStatic = !!node && (node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier");
@@ -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: _compilerdom.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
282
  modifiers: modifiers.map((modifier) => _compilerdom.createSimpleExpression.call(void 0, 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
+ _parser.parseExpression.call(void 0, `(${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 (_optionalChain([expression, 'optionalAccess', _9 => _9.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 && (_shared.isString.call(void 0, 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 _types.jsxFragment.call(void 0, _types.jsxOpeningFragment.call(void 0, ), _types.jsxClosingFragment.call(void 0, ), [
356
+ node.type === "JSXElement" ? node : _types.jsxExpressionContainer.call(void 0, node)
357
+ ]);
358
+ }
359
+ var EMPTY_EXPRESSION = _compilerdom.createSimpleExpression.call(void 0, "", 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
@@ -1037,42 +1091,211 @@ var transformVOn = (dir, node, context) => {
1037
1091
  };
1038
1092
 
1039
1093
  // 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 && _optionalChain([vSlotsDir, 'access', _16 => _16.value, 'optionalAccess', _17 => _17.type]) === "JSXExpressionContainer") {
1049
- node.openingElement.attributes.splice(vSlotsIndex, 1);
1050
- context.slots = [
1051
- {
1052
- slotType: 4 /* EXPRESSION */,
1053
- slots: resolveExpression(vSlotsDir.value.expression, context)
1094
+
1095
+
1096
+
1097
+
1098
+
1099
+ // src/transforms/vFor.ts
1100
+
1101
+
1102
+
1103
+
1104
+
1105
+ var transformVFor = createStructuralDirectiveTransform(
1106
+ "for",
1107
+ processFor
1108
+ );
1109
+ function processFor(node, dir, context) {
1110
+ const { value, index, key, source } = getForParseResult(dir, context);
1111
+ if (!source) {
1112
+ context.options.onError(
1113
+ _compilerdom.createCompilerError.call(void 0,
1114
+ _compilerdom.ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION,
1115
+ resolveLocation(dir.loc, context)
1116
+ )
1117
+ );
1118
+ return;
1119
+ }
1120
+ const keyProp = findProp(node, "key");
1121
+ const keyProperty = keyProp && propToExpression(keyProp, context);
1122
+ const isComponent = isJSXComponent(node);
1123
+ const id = context.reference();
1124
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
1125
+ const [render, exitBlock] = createBranch(node, context, true);
1126
+ return () => {
1127
+ exitBlock();
1128
+ const { parent } = context;
1129
+ const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
1130
+ context.registerOperation({
1131
+ type: 17 /* FOR */,
1132
+ id,
1133
+ source,
1134
+ value,
1135
+ key,
1136
+ index,
1137
+ keyProp: keyProperty,
1138
+ render,
1139
+ once: context.inVOnce || !!(source.ast && _compilerdom.isConstantNode.call(void 0, source.ast, {})),
1140
+ component: isComponent,
1141
+ onlyChild: !!isOnlyChild
1142
+ });
1143
+ };
1144
+ }
1145
+ function getForParseResult(dir, context) {
1146
+ let value, index, key, source;
1147
+ if (dir.value) {
1148
+ if (dir.value.type === "JSXExpressionContainer" && dir.value.expression.type === "BinaryExpression") {
1149
+ if (dir.value.expression.left.type === "SequenceExpression") {
1150
+ const expressions = dir.value.expression.left.expressions;
1151
+ value = expressions[0] && resolveExpressionWithFn(expressions[0], context);
1152
+ key = expressions[1] && resolveExpression(expressions[1], context);
1153
+ index = expressions[2] && resolveExpression(expressions[2], context);
1154
+ } else {
1155
+ value = resolveExpressionWithFn(dir.value.expression.left, context);
1054
1156
  }
1055
- ];
1157
+ source = resolveExpression(dir.value.expression.right, context);
1158
+ }
1159
+ } else {
1160
+ context.options.onError(
1161
+ _compilerdom.createCompilerError.call(void 0,
1162
+ _compilerdom.ErrorCodes.X_V_FOR_NO_EXPRESSION,
1163
+ resolveLocation(dir.loc, context)
1164
+ )
1165
+ );
1056
1166
  }
1057
- if (children.length) {
1058
- return transformComponentSlot(node, context);
1167
+ return {
1168
+ value,
1169
+ index,
1170
+ key,
1171
+ source
1172
+ };
1173
+ }
1174
+
1175
+ // src/transforms/vSlot.ts
1176
+ var transformVSlot = (node, context) => {
1177
+ if (node.type !== "JSXElement") return;
1178
+ const { children } = node;
1179
+ const dir = findProp(node, "v-slot");
1180
+ const resolvedDirective = dir ? resolveDirectiveNode(dir, context, true) : void 0;
1181
+ const { parent } = context;
1182
+ const isComponent = isJSXComponent(node);
1183
+ const isSlotTemplate = isTemplate(node) && parent && parent.node.type === "JSXElement" && isJSXComponent(parent.node);
1184
+ if (isComponent && children.length) {
1185
+ return transformComponentSlot(node, resolvedDirective, context);
1186
+ } else if (isSlotTemplate && resolvedDirective) {
1187
+ return transformTemplateSlot(node, resolvedDirective, context);
1188
+ } else if (!isComponent && dir) {
1189
+ context.options.onError(
1190
+ _compilerdom.createCompilerError.call(void 0,
1191
+ _compilerdom.ErrorCodes.X_V_SLOT_MISPLACED,
1192
+ resolveLocation(dir.loc, context)
1193
+ )
1194
+ );
1059
1195
  }
1060
1196
  };
1061
- function transformComponentSlot(node, context) {
1197
+ function transformComponentSlot(node, dir, context) {
1062
1198
  const { children } = node;
1063
- const nonWhitespaceChildren = children.filter(
1064
- () => isNonWhitespaceContent(node)
1199
+ const arg = dir && dir.arg;
1200
+ const nonSlotTemplateChildren = children.filter(
1201
+ (n) => isNonWhitespaceContent(n) && !(n.type === "JSXElement" && findProp(n, "v-slot"))
1065
1202
  );
1066
- const [block, onExit] = createSlotBlock(node, context);
1203
+ const [block, onExit] = createSlotBlock(node, dir, context);
1067
1204
  const { slots } = context;
1068
1205
  return () => {
1069
1206
  onExit();
1070
- if (nonWhitespaceChildren.length) {
1071
- registerSlot(slots, block);
1207
+ const hasOtherSlots = !!slots.length;
1208
+ if (dir && hasOtherSlots) {
1209
+ context.options.onError(
1210
+ _compilerdom.createCompilerError.call(void 0, _compilerdom.ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE, dir.loc)
1211
+ );
1212
+ return;
1213
+ }
1214
+ if (nonSlotTemplateChildren.length) {
1215
+ if (hasStaticSlot(slots, "default")) {
1216
+ context.options.onError(
1217
+ _compilerdom.createCompilerError.call(void 0,
1218
+ _compilerdom.ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN,
1219
+ resolveLocation(nonSlotTemplateChildren[0].loc, context)
1220
+ )
1221
+ );
1222
+ } else {
1223
+ registerSlot(slots, arg, block);
1224
+ context.slots = slots;
1225
+ }
1226
+ } else if (hasOtherSlots) {
1072
1227
  context.slots = slots;
1073
1228
  }
1074
1229
  };
1075
1230
  }
1231
+ var elseIfRE = /^else(-if)?$/;
1232
+ function transformTemplateSlot(node, dir, context) {
1233
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */;
1234
+ const arg = dir.arg && resolveSimpleExpressionNode(dir.arg);
1235
+ const vFor = findProp(node, "v-for");
1236
+ const vIf = findProp(node, "v-if");
1237
+ const vElse = findProp(node, elseIfRE);
1238
+ const { slots } = context;
1239
+ const [block, onExit] = createSlotBlock(node, dir, context);
1240
+ if (!vFor && !vIf && !vElse) {
1241
+ const slotName = arg ? arg.isStatic && arg.content : "default";
1242
+ if (slotName && hasStaticSlot(slots, slotName)) {
1243
+ context.options.onError(
1244
+ _compilerdom.createCompilerError.call(void 0, _compilerdom.ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES, dir.loc)
1245
+ );
1246
+ } else {
1247
+ registerSlot(slots, arg, block);
1248
+ }
1249
+ } else if (vIf) {
1250
+ const vIfDir = resolveDirectiveNode(vIf, context);
1251
+ registerDynamicSlot(slots, {
1252
+ slotType: 3 /* CONDITIONAL */,
1253
+ condition: vIfDir.exp,
1254
+ positive: {
1255
+ slotType: 1 /* DYNAMIC */,
1256
+ name: arg,
1257
+ fn: block
1258
+ }
1259
+ });
1260
+ } else if (vElse) {
1261
+ const vElseDir = resolveDirectiveNode(vElse, context);
1262
+ const vIfSlot = slots.at(-1);
1263
+ if (vIfSlot.slotType === 3 /* CONDITIONAL */) {
1264
+ let ifNode = vIfSlot;
1265
+ while (ifNode.negative && ifNode.negative.slotType === 3 /* CONDITIONAL */)
1266
+ ifNode = ifNode.negative;
1267
+ const negative = vElseDir.exp ? {
1268
+ slotType: 3 /* CONDITIONAL */,
1269
+ condition: vElseDir.exp,
1270
+ positive: {
1271
+ slotType: 1 /* DYNAMIC */,
1272
+ name: arg,
1273
+ fn: block
1274
+ }
1275
+ } : {
1276
+ slotType: 1 /* DYNAMIC */,
1277
+ name: arg,
1278
+ fn: block
1279
+ };
1280
+ ifNode.negative = negative;
1281
+ } else {
1282
+ context.options.onError(
1283
+ _compilerdom.createCompilerError.call(void 0, _compilerdom.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, vElseDir.loc)
1284
+ );
1285
+ }
1286
+ } else if (vFor) {
1287
+ const forParseResult = getForParseResult(vFor, context);
1288
+ if (forParseResult.source) {
1289
+ registerDynamicSlot(slots, {
1290
+ slotType: 2 /* LOOP */,
1291
+ name: arg,
1292
+ fn: block,
1293
+ loop: forParseResult
1294
+ });
1295
+ }
1296
+ }
1297
+ return onExit;
1298
+ }
1076
1299
  function ensureStaticSlots(slots) {
1077
1300
  let lastSlots = slots.at(-1);
1078
1301
  if (!slots.length || lastSlots.slotType !== 0 /* STATIC */) {
@@ -1083,14 +1306,32 @@ function ensureStaticSlots(slots) {
1083
1306
  }
1084
1307
  );
1085
1308
  }
1086
- return lastSlots;
1309
+ return lastSlots.slots;
1087
1310
  }
1088
- function registerSlot(slots, block) {
1089
- const staticSlots = ensureStaticSlots(slots);
1090
- staticSlots.slots.default = block;
1311
+ function registerSlot(slots, name, block) {
1312
+ const isStatic = !name || name.isStatic;
1313
+ if (isStatic) {
1314
+ const staticSlots = ensureStaticSlots(slots);
1315
+ staticSlots[name ? name.content : "default"] = block;
1316
+ } else {
1317
+ slots.push({
1318
+ slotType: 1 /* DYNAMIC */,
1319
+ name,
1320
+ fn: block
1321
+ });
1322
+ }
1091
1323
  }
1092
- function createSlotBlock(slotNode, context) {
1324
+ function registerDynamicSlot(allSlots, dynamic) {
1325
+ allSlots.push(dynamic);
1326
+ }
1327
+ function hasStaticSlot(slots, name) {
1328
+ return slots.some(
1329
+ (slot) => slot.slotType === 0 /* STATIC */ ? !!slot.slots[name] : false
1330
+ );
1331
+ }
1332
+ function createSlotBlock(slotNode, dir, context) {
1093
1333
  const block = newBlock(slotNode);
1334
+ block.props = dir && dir.exp;
1094
1335
  const exitBlock = context.enterBlock(block);
1095
1336
  return [block, exitBlock];
1096
1337
  }
@@ -1099,6 +1340,37 @@ function isNonWhitespaceContent(node) {
1099
1340
  return !!node.value.trim();
1100
1341
  }
1101
1342
 
1343
+ // src/transforms/vSlots.ts
1344
+
1345
+ var transformVSlots = (node, context) => {
1346
+ if (node.type !== "JSXElement" || !isJSXComponent(node)) return;
1347
+ const {
1348
+ openingElement: { attributes },
1349
+ children
1350
+ } = node;
1351
+ const vSlotsIndex = attributes.findIndex(
1352
+ (attr) => attr.type === "JSXAttribute" && attr.name.name.toString() === "v-slots"
1353
+ );
1354
+ const vSlotsDir = attributes[vSlotsIndex];
1355
+ if (vSlotsDir && _optionalChain([vSlotsDir, 'access', _16 => _16.value, 'optionalAccess', _17 => _17.type]) === "JSXExpressionContainer") {
1356
+ attributes.splice(vSlotsIndex, 1);
1357
+ context.slots = [
1358
+ {
1359
+ slotType: 4 /* EXPRESSION */,
1360
+ slots: resolveExpression(vSlotsDir.value.expression, context)
1361
+ }
1362
+ ];
1363
+ if (children.length) {
1364
+ context.options.onError(
1365
+ _compilerdom.createCompilerError.call(void 0,
1366
+ _compilerdom.ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE,
1367
+ resolveLocation(children[0].loc, context)
1368
+ )
1369
+ );
1370
+ }
1371
+ }
1372
+ };
1373
+
1102
1374
  // src/transforms/vModel.ts
1103
1375
 
1104
1376
  var transformVModel = (dir, node, context) => {
@@ -1129,86 +1401,6 @@ var transformVHtml = (dir, node, context) => {
1129
1401
  );
1130
1402
  };
1131
1403
 
1132
- // src/transforms/vFor.ts
1133
-
1134
-
1135
-
1136
-
1137
-
1138
-
1139
-
1140
- var transformVFor = createStructuralDirectiveTransform(
1141
- "for",
1142
- processFor
1143
- );
1144
- function processFor(node, dir, context) {
1145
- if (!dir.value) {
1146
- context.options.onError(
1147
- _compilerdom.createCompilerError.call(void 0,
1148
- _compilerdom.ErrorCodes.X_V_FOR_NO_EXPRESSION,
1149
- resolveLocation(dir.loc, context)
1150
- )
1151
- );
1152
- return;
1153
- }
1154
- if (!_compilerdom.forAliasRE) {
1155
- context.options.onError(
1156
- _compilerdom.createCompilerError.call(void 0,
1157
- _compilerdom.ErrorCodes.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 && _compilerdom.isConstantNode.call(void 0, 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
- _parser.parseExpression.call(void 0, `(${text})=>{}`, {
1207
- plugins: ["typescript"]
1208
- })
1209
- );
1210
- }
1211
-
1212
1404
  // src/compile.ts
1213
1405
  function compile(source, options = {}) {
1214
1406
  const resolvedOptions = _shared.extend.call(void 0, {}, options, {
@@ -1264,6 +1456,7 @@ function getBaseTransformPreset() {
1264
1456
  transformTemplateRef,
1265
1457
  transformText,
1266
1458
  transformElement,
1459
+ transformVSlots,
1267
1460
  transformVSlot,
1268
1461
  transformChildren
1269
1462
  ],
@@ -1300,4 +1493,5 @@ function getBaseTransformPreset() {
1300
1493
 
1301
1494
 
1302
1495
 
1303
- exports.DynamicFlag = DynamicFlag; exports.IRDynamicPropsKind = IRDynamicPropsKind; exports.IRNodeTypes = IRNodeTypes; exports.IRSlotType = IRSlotType; exports.TransformContext = TransformContext; exports.compile = compile; exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform; exports.generate = _compilervapor.generate; exports.resolveDirectiveNode = resolveDirectiveNode; exports.resolveNode = resolveNode; exports.transform = transform; exports.transformChildren = transformChildren; exports.transformElement = transformElement; exports.transformNode = transformNode; exports.transformTemplateRef = transformTemplateRef; exports.transformText = transformText; exports.transformVBind = transformVBind; exports.transformVFor = transformVFor; exports.transformVHtml = transformVHtml; exports.transformVModel = transformVModel; exports.transformVOn = transformVOn; exports.transformVShow = transformVShow; exports.transformVSlot = transformVSlot;
1496
+
1497
+ exports.DynamicFlag = DynamicFlag; exports.IRDynamicPropsKind = IRDynamicPropsKind; exports.IRNodeTypes = IRNodeTypes; exports.IRSlotType = IRSlotType; exports.TransformContext = TransformContext; exports.compile = compile; exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform; exports.generate = _compilervapor.generate; exports.resolveDirectiveNode = resolveDirectiveNode; exports.resolveNode = resolveNode; exports.transform = transform; exports.transformChildren = transformChildren; exports.transformElement = transformElement; exports.transformNode = transformNode; exports.transformTemplateRef = transformTemplateRef; exports.transformText = transformText; exports.transformVBind = transformVBind; exports.transformVFor = transformVFor; exports.transformVHtml = transformVHtml; exports.transformVModel = transformVModel; exports.transformVOn = transformVOn; exports.transformVShow = transformVShow; exports.transformVSlot = transformVSlot; exports.transformVSlots = transformVSlots;
package/dist/index.d.cts CHANGED
@@ -334,7 +334,7 @@ type TransformPreset = [
334
334
  ];
335
335
 
336
336
  declare function resolveNode(node: JSXElement, context: TransformContext): ElementNode;
337
- declare function resolveDirectiveNode(node: JSXAttribute, context: TransformContext): VaporDirectiveNode;
337
+ declare function resolveDirectiveNode(node: JSXAttribute, context: TransformContext, withFn?: boolean): VaporDirectiveNode;
338
338
 
339
339
  declare const transformText: NodeTransform;
340
340
 
@@ -350,6 +350,8 @@ declare const transformVOn: DirectiveTransform;
350
350
 
351
351
  declare const transformVSlot: NodeTransform;
352
352
 
353
+ declare const transformVSlots: NodeTransform;
354
+
353
355
  declare const transformVModel: DirectiveTransform;
354
356
 
355
357
  declare const transformVShow: DirectiveTransform;
@@ -358,4 +360,4 @@ declare const transformVHtml: DirectiveTransform;
358
360
 
359
361
  declare const transformVFor: NodeTransform;
360
362
 
361
- export { type BaseIRNode, type BlockIRNode, type CompilerOptions, type CreateComponentIRNode, type CreateTextNodeIRNode, type DeclareOldRefIRNode, type DirectiveIRNode, type DirectiveTransform, type DirectiveTransformResult, DynamicFlag, type ForIRNode, type GetTextChildIRNode, type HackOptions, type IRDynamicInfo, IRDynamicPropsKind, type IREffect, type IRFor, type IRNode, IRNodeTypes, type IRProp, type IRProps, type IRPropsDynamicAttribute, type IRPropsDynamicExpression, type IRPropsStatic, type IRSlotDynamic, type IRSlotDynamicBasic, type IRSlotDynamicConditional, type IRSlotDynamicLoop, IRSlotType, type IRSlots, type IRSlotsExpression, type IRSlotsStatic, type IfIRNode, type InsertNodeIRNode, type KeyOverride, type NodeTransform, type OperationNode, type PrependNodeIRNode, type RootIRNode, type RootNode, type SetDynamicEventsIRNode, type SetDynamicPropsIRNode, type SetEventIRNode, type SetHtmlIRNode, type SetPropIRNode, type SetTemplateRefIRNode, type SetTextIRNode, type SlotBlockIRNode, type SlotOutletIRNode, type StructuralDirectiveTransform, TransformContext, type TransformOptions, type TransformPreset, type VaporDirectiveNode, compile, createStructuralDirectiveTransform, resolveDirectiveNode, resolveNode, transform, transformChildren, transformElement, transformNode, transformTemplateRef, transformText, transformVBind, transformVFor, transformVHtml, transformVModel, transformVOn, transformVShow, transformVSlot };
363
+ export { type BaseIRNode, type BlockIRNode, type CompilerOptions, type CreateComponentIRNode, type CreateTextNodeIRNode, type DeclareOldRefIRNode, type DirectiveIRNode, type DirectiveTransform, type DirectiveTransformResult, DynamicFlag, type ForIRNode, type GetTextChildIRNode, type HackOptions, type IRDynamicInfo, IRDynamicPropsKind, type IREffect, type IRFor, type IRNode, IRNodeTypes, type IRProp, type IRProps, type IRPropsDynamicAttribute, type IRPropsDynamicExpression, type IRPropsStatic, type IRSlotDynamic, type IRSlotDynamicBasic, type IRSlotDynamicConditional, type IRSlotDynamicLoop, IRSlotType, type IRSlots, type IRSlotsExpression, type IRSlotsStatic, type IfIRNode, type InsertNodeIRNode, type KeyOverride, type NodeTransform, type OperationNode, type PrependNodeIRNode, type RootIRNode, type RootNode, type SetDynamicEventsIRNode, type SetDynamicPropsIRNode, type SetEventIRNode, type SetHtmlIRNode, type SetPropIRNode, type SetTemplateRefIRNode, type SetTextIRNode, type SlotBlockIRNode, type SlotOutletIRNode, type StructuralDirectiveTransform, TransformContext, type TransformOptions, type TransformPreset, type VaporDirectiveNode, compile, createStructuralDirectiveTransform, resolveDirectiveNode, resolveNode, transform, transformChildren, transformElement, transformNode, transformTemplateRef, transformText, transformVBind, transformVFor, transformVHtml, transformVModel, transformVOn, transformVShow, transformVSlot, transformVSlots };