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4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/index.ts
var src_exports = {};
__export(src_exports, {
  default: () => src_default
});
module.exports = __toCommonJS(src_exports);
var t5 = __toESM(require("@babel/types"));
var import_template = __toESM(require("@babel/template"));
var import_plugin_syntax_jsx = __toESM(require("@babel/plugin-syntax-jsx"));
var import_helper_module_imports2 = require("@babel/helper-module-imports");
var import_babel_plugin_resolve_type = __toESM(require("@vue/babel-plugin-resolve-type"));
var import_helper_plugin_utils = require("@babel/helper-plugin-utils");

// src/transform-vue-jsx.ts
var t3 = __toESM(require("@babel/types"));
var import_helper_module_imports = require("@babel/helper-module-imports");

// src/utils.ts
var t = __toESM(require("@babel/types"));
var import_html_tags = __toESM(require("html-tags"));
var import_svg_tags = __toESM(require("svg-tags"));

// src/slotFlags.ts
var SlotFlags = /* @__PURE__ */ ((SlotFlags2) => {
  SlotFlags2[SlotFlags2["STABLE"] = 1] = "STABLE";
  SlotFlags2[SlotFlags2["DYNAMIC"] = 2] = "DYNAMIC";
  SlotFlags2[SlotFlags2["FORWARDED"] = 3] = "FORWARDED";
  return SlotFlags2;
})(SlotFlags || {});
var slotFlags_default = SlotFlags;

// src/utils.ts
var FRAGMENT = "Fragment";
var KEEP_ALIVE = "KeepAlive";
var createIdentifier = (state, name) => state.get(name)();
var isDirective = (src) => src.startsWith("v-") || src.startsWith("v") && src.length >= 2 && src[1] >= "A" && src[1] <= "Z";
var shouldTransformedToSlots = (tag) => !(tag.match(RegExp(`^_?${FRAGMENT}\\d*$`)) || tag === KEEP_ALIVE);
var checkIsComponent = (path, state) => {
  var _a, _b;
  const namePath = path.get("name");
  if (namePath.isJSXMemberExpression()) {
    return shouldTransformedToSlots(namePath.node.property.name);
  }
  const tag = namePath.node.name;
  return !((_b = (_a = state.opts).isCustomElement) == null ? void 0 : _b.call(_a, tag)) && shouldTransformedToSlots(tag) && !import_html_tags.default.includes(tag) && !import_svg_tags.default.includes(tag);
};
var transformJSXMemberExpression = (path) => {
  const objectPath = path.node.object;
  const propertyPath = path.node.property;
  const transformedObject = t.isJSXMemberExpression(objectPath) ? transformJSXMemberExpression(
    path.get("object")
  ) : t.isJSXIdentifier(objectPath) ? t.identifier(objectPath.name) : t.nullLiteral();
  const transformedProperty = t.identifier(propertyPath.name);
  return t.memberExpression(transformedObject, transformedProperty);
};
var getTag = (path, state) => {
  var _a, _b;
  const namePath = path.get("openingElement").get("name");
  if (namePath.isJSXIdentifier()) {
    const { name } = namePath.node;
    if (!import_html_tags.default.includes(name) && !import_svg_tags.default.includes(name)) {
      return name === FRAGMENT ? createIdentifier(state, FRAGMENT) : path.scope.hasBinding(name) ? t.identifier(name) : ((_b = (_a = state.opts).isCustomElement) == null ? void 0 : _b.call(_a, name)) ? t.stringLiteral(name) : t.callExpression(createIdentifier(state, "resolveComponent"), [
        t.stringLiteral(name)
      ]);
    }
    return t.stringLiteral(name);
  }
  if (namePath.isJSXMemberExpression()) {
    return transformJSXMemberExpression(namePath);
  }
  throw new Error(`getTag: ${namePath.type} is not supported`);
};
var getJSXAttributeName = (path) => {
  const nameNode = path.node.name;
  if (t.isJSXIdentifier(nameNode)) {
    return nameNode.name;
  }
  return `${nameNode.namespace.name}:${nameNode.name.name}`;
};
var transformJSXText = (path) => {
  const str = transformText(path.node.value);
  return str !== "" ? t.stringLiteral(str) : null;
};
var transformText = (text) => {
  const lines = text.split(/\r\n|\n|\r/);
  let lastNonEmptyLine = 0;
  for (let i = 0; i < lines.length; i++) {
    if (lines[i].match(/[^ \t]/)) {
      lastNonEmptyLine = i;
    }
  }
  let str = "";
  for (let i = 0; i < lines.length; i++) {
    const line = lines[i];
    const isFirstLine = i === 0;
    const isLastLine = i === lines.length - 1;
    const isLastNonEmptyLine = i === lastNonEmptyLine;
    let trimmedLine = line.replace(/\t/g, " ");
    if (!isFirstLine) {
      trimmedLine = trimmedLine.replace(/^[ ]+/, "");
    }
    if (!isLastLine) {
      trimmedLine = trimmedLine.replace(/[ ]+$/, "");
    }
    if (trimmedLine) {
      if (!isLastNonEmptyLine) {
        trimmedLine += " ";
      }
      str += trimmedLine;
    }
  }
  return str;
};
var transformJSXExpressionContainer = (path) => path.get("expression").node;
var transformJSXSpreadChild = (path) => t.spreadElement(path.get("expression").node);
var walksScope = (path, name, slotFlag) => {
  if (path.scope.hasBinding(name) && path.parentPath) {
    if (t.isJSXElement(path.parentPath.node)) {
      path.parentPath.setData("slotFlag", slotFlag);
    }
    walksScope(path.parentPath, name, slotFlag);
  }
};
var buildIIFE = (path, children) => {
  const { parentPath } = path;
  if (parentPath.isAssignmentExpression()) {
    const { left } = parentPath.node;
    if (t.isIdentifier(left)) {
      return children.map((child) => {
        if (t.isIdentifier(child) && child.name === left.name) {
          const insertName = path.scope.generateUidIdentifier(child.name);
          parentPath.insertBefore(
            t.variableDeclaration("const", [
              t.variableDeclarator(
                insertName,
                t.callExpression(
                  t.functionExpression(
                    null,
                    [],
                    t.blockStatement([t.returnStatement(child)])
                  ),
                  []
                )
              )
            ])
          );
          return insertName;
        }
        return child;
      });
    }
  }
  return children;
};
var onRE = /^on[^a-z]/;
var isOn = (key) => onRE.test(key);
var mergeAsArray = (existing, incoming) => {
  if (t.isArrayExpression(existing.value)) {
    existing.value.elements.push(incoming.value);
  } else {
    existing.value = t.arrayExpression([
      existing.value,
      incoming.value
    ]);
  }
};
var dedupeProperties = (properties = [], mergeProps) => {
  if (!mergeProps) {
    return properties;
  }
  const knownProps = /* @__PURE__ */ new Map();
  const deduped = [];
  properties.forEach((prop) => {
    if (t.isStringLiteral(prop.key)) {
      const { value: name } = prop.key;
      const existing = knownProps.get(name);
      if (existing) {
        if (name === "style" || name === "class" || name.startsWith("on")) {
          mergeAsArray(existing, prop);
        }
      } else {
        knownProps.set(name, prop);
        deduped.push(prop);
      }
    } else {
      deduped.push(prop);
    }
  });
  return deduped;
};
var isConstant = (node) => {
  if (t.isIdentifier(node)) {
    return node.name === "undefined";
  }
  if (t.isArrayExpression(node)) {
    const { elements } = node;
    return elements.every((element) => element && isConstant(element));
  }
  if (t.isObjectExpression(node)) {
    return node.properties.every(
      (property) => isConstant(property.value)
    );
  }
  if (t.isLiteral(node)) {
    return true;
  }
  return false;
};
var transformJSXSpreadAttribute = (nodePath, path, mergeProps, args) => {
  const argument = path.get("argument");
  const properties = t.isObjectExpression(argument.node) ? argument.node.properties : void 0;
  if (!properties) {
    if (argument.isIdentifier()) {
      walksScope(
        nodePath,
        argument.node.name,
        slotFlags_default.DYNAMIC
      );
    }
    args.push(mergeProps ? argument.node : t.spreadElement(argument.node));
  } else if (mergeProps) {
    args.push(t.objectExpression(properties));
  } else {
    args.push(...properties);
  }
};

// src/parseDirectives.ts
var t2 = __toESM(require("@babel/types"));
var getType = (path) => {
  const typePath = path.get("attributes").find((attribute) => {
    if (!attribute.isJSXAttribute()) {
      return false;
    }
    return attribute.get("name").isJSXIdentifier() && attribute.get("name").node.name === "type";
  });
  return typePath ? typePath.get("value").node : null;
};
var parseModifiers = (value) => t2.isArrayExpression(value) ? value.elements.map((el) => t2.isStringLiteral(el) ? el.value : "").filter(Boolean) : [];
var parseDirectives = (params) => {
  var _a, _b;
  const { path, value, state, tag, isComponent } = params;
  const args = [];
  const vals = [];
  const modifiersSet = [];
  let directiveName;
  let directiveArgument;
  let directiveModifiers;
  if ("namespace" in path.node.name) {
    [directiveName, directiveArgument] = params.name.split(":");
    directiveName = path.node.name.namespace.name;
    directiveArgument = path.node.name.name.name;
    directiveModifiers = directiveArgument.split("_").slice(1);
  } else {
    const underscoreModifiers = params.name.split("_");
    directiveName = underscoreModifiers.shift() || "";
    directiveModifiers = underscoreModifiers;
  }
  directiveName = directiveName.replace(/^v/, "").replace(/^-/, "").replace(/^\S/, (s) => s.toLowerCase());
  if (directiveArgument) {
    args.push(t2.stringLiteral(directiveArgument.split("_")[0]));
  }
  const isVModels = directiveName === "models";
  const isVModel = directiveName === "model";
  if (isVModel && !path.get("value").isJSXExpressionContainer()) {
    throw new Error("You have to use JSX Expression inside your v-model");
  }
  if (isVModels && !isComponent) {
    throw new Error("v-models can only use in custom components");
  }
  const shouldResolve = !["html", "text", "model", "slots", "models"].includes(directiveName) || isVModel && !isComponent;
  let modifiers = directiveModifiers;
  if (t2.isArrayExpression(value)) {
    const elementsList = isVModels ? value.elements : [value];
    elementsList.forEach((element) => {
      if (isVModels && !t2.isArrayExpression(element)) {
        throw new Error("You should pass a Two-dimensional Arrays to v-models");
      }
      const { elements } = element;
      const [first, second, third] = elements;
      if (second && !t2.isArrayExpression(second) && !t2.isSpreadElement(second)) {
        args.push(second);
        modifiers = parseModifiers(third);
      } else if (t2.isArrayExpression(second)) {
        if (!shouldResolve) {
          args.push(t2.nullLiteral());
        }
        modifiers = parseModifiers(second);
      } else if (!shouldResolve) {
        args.push(t2.nullLiteral());
      }
      modifiersSet.push(new Set(modifiers));
      vals.push(first);
    });
  } else if (isVModel && !shouldResolve) {
    args.push(t2.nullLiteral());
    modifiersSet.push(new Set(directiveModifiers));
  } else {
    modifiersSet.push(new Set(directiveModifiers));
  }
  return {
    directiveName,
    modifiers: modifiersSet,
    values: vals.length ? vals : [value],
    args,
    directive: shouldResolve ? [
      resolveDirective(path, state, tag, directiveName),
      vals[0] || value,
      ((_a = modifiersSet[0]) == null ? void 0 : _a.size) ? args[0] || t2.unaryExpression("void", t2.numericLiteral(0), true) : args[0],
      !!((_b = modifiersSet[0]) == null ? void 0 : _b.size) && t2.objectExpression(
        [...modifiersSet[0]].map(
          (modifier) => t2.objectProperty(t2.identifier(modifier), t2.booleanLiteral(true))
        )
      )
    ].filter(Boolean) : void 0
  };
};
var resolveDirective = (path, state, tag, directiveName) => {
  if (directiveName === "show") {
    return createIdentifier(state, "vShow");
  }
  if (directiveName === "model") {
    let modelToUse;
    const type = getType(path.parentPath);
    switch (tag.value) {
      case "select":
        modelToUse = createIdentifier(state, "vModelSelect");
        break;
      case "textarea":
        modelToUse = createIdentifier(state, "vModelText");
        break;
      default:
        if (t2.isStringLiteral(type) || !type) {
          switch (type == null ? void 0 : type.value) {
            case "checkbox":
              modelToUse = createIdentifier(state, "vModelCheckbox");
              break;
            case "radio":
              modelToUse = createIdentifier(state, "vModelRadio");
              break;
            default:
              modelToUse = createIdentifier(state, "vModelText");
          }
        } else {
          modelToUse = createIdentifier(state, "vModelDynamic");
        }
    }
    return modelToUse;
  }
  return t2.callExpression(createIdentifier(state, "resolveDirective"), [
    t2.stringLiteral(directiveName)
  ]);
};
var parseDirectives_default = parseDirectives;

// src/transform-vue-jsx.ts
var xlinkRE = /^xlink([A-Z])/;
var getJSXAttributeValue = (path, state) => {
  const valuePath = path.get("value");
  if (valuePath.isJSXElement()) {
    return transformJSXElement(valuePath, state);
  }
  if (valuePath.isStringLiteral()) {
    return t3.stringLiteral(transformText(valuePath.node.value));
  }
  if (valuePath.isJSXExpressionContainer()) {
    return transformJSXExpressionContainer(valuePath);
  }
  return null;
};
var buildProps = (path, state) => {
  const tag = getTag(path, state);
  const isComponent = checkIsComponent(path.get("openingElement"), state);
  const props = path.get("openingElement").get("attributes");
  const directives = [];
  const dynamicPropNames = /* @__PURE__ */ new Set();
  let slots = null;
  let patchFlag = 0;
  if (props.length === 0) {
    return {
      tag,
      isComponent,
      slots,
      props: t3.nullLiteral(),
      directives,
      patchFlag,
      dynamicPropNames
    };
  }
  let properties = [];
  let hasRef = false;
  let hasClassBinding = false;
  let hasStyleBinding = false;
  let hasHydrationEventBinding = false;
  let hasDynamicKeys = false;
  const mergeArgs = [];
  const { mergeProps = true } = state.opts;
  props.forEach((prop) => {
    if (prop.isJSXAttribute()) {
      let name = getJSXAttributeName(prop);
      const attributeValue = getJSXAttributeValue(prop, state);
      if (!isConstant(attributeValue) || name === "ref") {
        if (!isComponent && isOn(name) && // omit the flag for click handlers becaues hydration gives click
        // dedicated fast path.
        name.toLowerCase() !== "onclick" && // omit v-model handlers
        name !== "onUpdate:modelValue") {
          hasHydrationEventBinding = true;
        }
        if (name === "ref") {
          hasRef = true;
        } else if (name === "class" && !isComponent) {
          hasClassBinding = true;
        } else if (name === "style" && !isComponent) {
          hasStyleBinding = true;
        } else if (name !== "key" && !isDirective(name) && name !== "on") {
          dynamicPropNames.add(name);
        }
      }
      if (state.opts.transformOn && (name === "on" || name === "nativeOn")) {
        if (!state.get("transformOn")) {
          state.set(
            "transformOn",
            (0, import_helper_module_imports.addDefault)(path, "@vue/babel-helper-vue-transform-on", {
              nameHint: "_transformOn"
            })
          );
        }
        mergeArgs.push(
          t3.callExpression(state.get("transformOn"), [
            attributeValue || t3.booleanLiteral(true)
          ])
        );
        return;
      }
      if (isDirective(name)) {
        const { directive, modifiers, values, args, directiveName } = parseDirectives_default({
          tag,
          isComponent,
          name,
          path: prop,
          state,
          value: attributeValue
        });
        if (directiveName === "slots") {
          slots = attributeValue;
          return;
        }
        if (directive) {
          directives.push(t3.arrayExpression(directive));
        } else if (directiveName === "html") {
          properties.push(
            t3.objectProperty(t3.stringLiteral("innerHTML"), values[0])
          );
          dynamicPropNames.add("innerHTML");
        } else if (directiveName === "text") {
          properties.push(
            t3.objectProperty(t3.stringLiteral("textContent"), values[0])
          );
          dynamicPropNames.add("textContent");
        }
        if (["models", "model"].includes(directiveName)) {
          values.forEach((value, index) => {
            var _a;
            const propName = args[index];
            const isDynamic = propName && !t3.isStringLiteral(propName) && !t3.isNullLiteral(propName);
            if (!directive) {
              properties.push(
                t3.objectProperty(
                  t3.isNullLiteral(propName) ? t3.stringLiteral("modelValue") : propName,
                  value,
                  isDynamic
                )
              );
              if (!isDynamic) {
                dynamicPropNames.add(
                  (propName == null ? void 0 : propName.value) || "modelValue"
                );
              }
              if ((_a = modifiers[index]) == null ? void 0 : _a.size) {
                properties.push(
                  t3.objectProperty(
                    isDynamic ? t3.binaryExpression(
                      "+",
                      propName,
                      t3.stringLiteral("Modifiers")
                    ) : t3.stringLiteral(
                      `${(propName == null ? void 0 : propName.value) || "model"}Modifiers`
                    ),
                    t3.objectExpression(
                      [...modifiers[index]].map(
                        (modifier) => t3.objectProperty(
                          t3.stringLiteral(modifier),
                          t3.booleanLiteral(true)
                        )
                      )
                    ),
                    isDynamic
                  )
                );
              }
            }
            const updateName = isDynamic ? t3.binaryExpression("+", t3.stringLiteral("onUpdate:"), propName) : t3.stringLiteral(
              `onUpdate:${(propName == null ? void 0 : propName.value) || "modelValue"}`
            );
            properties.push(
              t3.objectProperty(
                updateName,
                t3.arrowFunctionExpression(
                  [t3.identifier("$event")],
                  t3.assignmentExpression(
                    "=",
                    value,
                    t3.identifier("$event")
                  )
                ),
                isDynamic
              )
            );
            if (!isDynamic) {
              dynamicPropNames.add(updateName.value);
            } else {
              hasDynamicKeys = true;
            }
          });
        }
      } else {
        if (name.match(xlinkRE)) {
          name = name.replace(
            xlinkRE,
            (_, firstCharacter) => `xlink:${firstCharacter.toLowerCase()}`
          );
        }
        properties.push(
          t3.objectProperty(
            t3.stringLiteral(name),
            attributeValue || t3.booleanLiteral(true)
          )
        );
      }
    } else {
      if (properties.length && mergeProps) {
        mergeArgs.push(
          t3.objectExpression(dedupeProperties(properties, mergeProps))
        );
        properties = [];
      }
      hasDynamicKeys = true;
      transformJSXSpreadAttribute(
        path,
        prop,
        mergeProps,
        mergeProps ? mergeArgs : properties
      );
    }
  });
  if (hasDynamicKeys) {
    patchFlag |= 16 /* FULL_PROPS */;
  } else {
    if (hasClassBinding) {
      patchFlag |= 2 /* CLASS */;
    }
    if (hasStyleBinding) {
      patchFlag |= 4 /* STYLE */;
    }
    if (dynamicPropNames.size) {
      patchFlag |= 8 /* PROPS */;
    }
    if (hasHydrationEventBinding) {
      patchFlag |= 32 /* HYDRATE_EVENTS */;
    }
  }
  if ((patchFlag === 0 || patchFlag === 32 /* HYDRATE_EVENTS */) && (hasRef || directives.length > 0)) {
    patchFlag |= 512 /* NEED_PATCH */;
  }
  let propsExpression = t3.nullLiteral();
  if (mergeArgs.length) {
    if (properties.length) {
      mergeArgs.push(
        t3.objectExpression(dedupeProperties(properties, mergeProps))
      );
    }
    if (mergeArgs.length > 1) {
      propsExpression = t3.callExpression(
        createIdentifier(state, "mergeProps"),
        mergeArgs
      );
    } else {
      propsExpression = mergeArgs[0];
    }
  } else if (properties.length) {
    if (properties.length === 1 && t3.isSpreadElement(properties[0])) {
      propsExpression = properties[0].argument;
    } else {
      propsExpression = t3.objectExpression(
        dedupeProperties(properties, mergeProps)
      );
    }
  }
  return {
    tag,
    props: propsExpression,
    isComponent,
    slots,
    directives,
    patchFlag,
    dynamicPropNames
  };
};
var getChildren = (paths, state) => paths.map((path) => {
  if (path.isJSXText()) {
    const transformedText = transformJSXText(path);
    if (transformedText) {
      return t3.callExpression(createIdentifier(state, "createTextVNode"), [
        transformedText
      ]);
    }
    return transformedText;
  }
  if (path.isJSXExpressionContainer()) {
    const expression = transformJSXExpressionContainer(path);
    if (t3.isIdentifier(expression)) {
      const { name } = expression;
      const { referencePaths = [] } = path.scope.getBinding(name) || {};
      referencePaths.forEach((referencePath) => {
        walksScope(referencePath, name, slotFlags_default.DYNAMIC);
      });
    }
    return expression;
  }
  if (path.isJSXSpreadChild()) {
    return transformJSXSpreadChild(path);
  }
  if (path.isCallExpression()) {
    return path.node;
  }
  if (path.isJSXElement()) {
    return transformJSXElement(path, state);
  }
  throw new Error(`getChildren: ${path.type} is not supported`);
}).filter(
  (value) => value != null && !t3.isJSXEmptyExpression(value)
);
var transformJSXElement = (path, state) => {
  const children = getChildren(path.get("children"), state);
  const {
    tag,
    props,
    isComponent,
    directives,
    patchFlag,
    dynamicPropNames,
    slots
  } = buildProps(path, state);
  const { optimize = false } = state.opts;
  const slotFlag = path.getData("slotFlag") || slotFlags_default.STABLE;
  let VNodeChild;
  if (children.length > 1 || slots) {
    VNodeChild = isComponent ? children.length ? t3.objectExpression(
      [
        !!children.length && t3.objectProperty(
          t3.identifier("default"),
          t3.arrowFunctionExpression(
            [],
            t3.arrayExpression(buildIIFE(path, children))
          )
        ),
        ...slots ? t3.isObjectExpression(slots) ? slots.properties : [t3.spreadElement(slots)] : [],
        optimize && t3.objectProperty(t3.identifier("_"), t3.numericLiteral(slotFlag))
      ].filter(Boolean)
    ) : slots : t3.arrayExpression(children);
  } else if (children.length === 1) {
    const { enableObjectSlots = true } = state.opts;
    const child = children[0];
    const objectExpression4 = t3.objectExpression(
      [
        t3.objectProperty(
          t3.identifier("default"),
          t3.arrowFunctionExpression(
            [],
            t3.arrayExpression(buildIIFE(path, [child]))
          )
        ),
        optimize && t3.objectProperty(
          t3.identifier("_"),
          t3.numericLiteral(slotFlag)
        )
      ].filter(Boolean)
    );
    if (t3.isIdentifier(child) && isComponent) {
      VNodeChild = enableObjectSlots ? t3.conditionalExpression(
        t3.callExpression(
          state.get("@vue/babel-plugin-jsx/runtimeIsSlot")(),
          [child]
        ),
        child,
        objectExpression4
      ) : objectExpression4;
    } else if (t3.isCallExpression(child) && child.loc && isComponent) {
      if (enableObjectSlots) {
        const { scope } = path;
        const slotId = scope.generateUidIdentifier("slot");
        if (scope) {
          scope.push({
            id: slotId,
            kind: "let"
          });
        }
        const alternate = t3.objectExpression(
          [
            t3.objectProperty(
              t3.identifier("default"),
              t3.arrowFunctionExpression(
                [],
                t3.arrayExpression(buildIIFE(path, [slotId]))
              )
            ),
            optimize && t3.objectProperty(
              t3.identifier("_"),
              t3.numericLiteral(slotFlag)
            )
          ].filter(Boolean)
        );
        const assignment = t3.assignmentExpression("=", slotId, child);
        const condition = t3.callExpression(
          state.get("@vue/babel-plugin-jsx/runtimeIsSlot")(),
          [assignment]
        );
        VNodeChild = t3.conditionalExpression(condition, slotId, alternate);
      } else {
        VNodeChild = objectExpression4;
      }
    } else if (t3.isFunctionExpression(child) || t3.isArrowFunctionExpression(child)) {
      VNodeChild = t3.objectExpression([
        t3.objectProperty(t3.identifier("default"), child)
      ]);
    } else if (t3.isObjectExpression(child)) {
      VNodeChild = t3.objectExpression(
        [
          ...child.properties,
          optimize && t3.objectProperty(t3.identifier("_"), t3.numericLiteral(slotFlag))
        ].filter(Boolean)
      );
    } else {
      VNodeChild = isComponent ? t3.objectExpression([
        t3.objectProperty(
          t3.identifier("default"),
          t3.arrowFunctionExpression([], t3.arrayExpression([child]))
        )
      ]) : t3.arrayExpression([child]);
    }
  }
  const createVNode = t3.callExpression(
    createIdentifier(state, "createVNode"),
    [
      tag,
      props,
      VNodeChild || t3.nullLiteral(),
      !!patchFlag && optimize && t3.numericLiteral(patchFlag),
      !!dynamicPropNames.size && optimize && t3.arrayExpression(
        [...dynamicPropNames.keys()].map((name) => t3.stringLiteral(name))
      )
    ].filter(Boolean)
  );
  if (!directives.length) {
    return createVNode;
  }
  return t3.callExpression(createIdentifier(state, "withDirectives"), [
    createVNode,
    t3.arrayExpression(directives)
  ]);
};
var visitor = {
  JSXElement: {
    exit(path, state) {
      path.replaceWith(transformJSXElement(path, state));
    }
  }
};
var transform_vue_jsx_default = visitor;

// src/sugar-fragment.ts
var t4 = __toESM(require("@babel/types"));
var transformFragment = (path, Fragment) => {
  const children = path.get("children") || [];
  return t4.jsxElement(
    t4.jsxOpeningElement(Fragment, []),
    t4.jsxClosingElement(Fragment),
    children.map(({ node }) => node),
    false
  );
};
var visitor2 = {
  JSXFragment: {
    enter(path, state) {
      const fragmentCallee = createIdentifier(state, FRAGMENT);
      path.replaceWith(
        transformFragment(
          path,
          t4.isIdentifier(fragmentCallee) ? t4.jsxIdentifier(fragmentCallee.name) : t4.jsxMemberExpression(
            t4.jsxIdentifier(fragmentCallee.object.name),
            t4.jsxIdentifier(fragmentCallee.property.name)
          )
        )
      );
    }
  }
};
var sugar_fragment_default = visitor2;

// src/index.ts
var hasJSX = (parentPath) => {
  let fileHasJSX = false;
  parentPath.traverse({
    JSXElement(path) {
      fileHasJSX = true;
      path.stop();
    },
    JSXFragment(path) {
      fileHasJSX = true;
      path.stop();
    }
  });
  return fileHasJSX;
};
var JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/;
// @__NO_SIDE_EFFECTS__
function interopDefault(m) {
  return m.default || m;
}
var syntaxJsx = /* @__PURE__ */ interopDefault(import_plugin_syntax_jsx.default);
var template = /* @__PURE__ */ interopDefault(import_template.default);
var src_default = (0, import_helper_plugin_utils.declare)(
  (api, opt, dirname) => {
    const { types } = api;
    let resolveType;
    if (opt.resolveType) {
      if (typeof opt.resolveType === "boolean") opt.resolveType = {};
      resolveType = (0, import_babel_plugin_resolve_type.default)(api, opt.resolveType, dirname);
    }
    return __spreadProps(__spreadValues({}, resolveType || {}), {
      name: "babel-plugin-jsx",
      inherits: /* @__PURE__ */ interopDefault(syntaxJsx),
      visitor: __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, resolveType == null ? void 0 : resolveType.visitor), transform_vue_jsx_default), sugar_fragment_default), {
        Program: {
          enter(path, state) {
            if (hasJSX(path)) {
              const importNames = [
                "createVNode",
                "Fragment",
                "resolveComponent",
                "withDirectives",
                "vShow",
                "vModelSelect",
                "vModelText",
                "vModelCheckbox",
                "vModelRadio",
                "vModelText",
                "vModelDynamic",
                "resolveDirective",
                "mergeProps",
                "createTextVNode",
                "isVNode"
              ];
              if ((0, import_helper_module_imports2.isModule)(path)) {
                const importMap = {};
                importNames.forEach((name) => {
                  state.set(name, () => {
                    if (importMap[name]) {
                      return types.cloneNode(importMap[name]);
                    }
                    const identifier5 = (0, import_helper_module_imports2.addNamed)(path, name, "vue", {
                      ensureLiveReference: true
                    });
                    importMap[name] = identifier5;
                    return identifier5;
                  });
                });
                const { enableObjectSlots = true } = state.opts;
                if (enableObjectSlots) {
                  state.set("@vue/babel-plugin-jsx/runtimeIsSlot", () => {
                    if (importMap.runtimeIsSlot) {
                      return importMap.runtimeIsSlot;
                    }
                    const { name: isVNodeName } = state.get(
                      "isVNode"
                    )();
                    const isSlot = path.scope.generateUidIdentifier("isSlot");
                    const ast = template.ast`
                    function ${isSlot.name}(s) {
                      return typeof s === 'function' || (Object.prototype.toString.call(s) === '[object Object]' && !${isVNodeName}(s));
                    }
                  `;
                    const lastImport = path.get("body").filter((p) => p.isImportDeclaration()).pop();
                    if (lastImport) {
                      lastImport.insertAfter(ast);
                    }
                    importMap.runtimeIsSlot = isSlot;
                    return isSlot;
                  });
                }
              } else {
                let sourceName;
                importNames.forEach((name) => {
                  state.set(name, () => {
                    if (!sourceName) {
                      sourceName = (0, import_helper_module_imports2.addNamespace)(path, "vue", {
                        ensureLiveReference: true
                      });
                    }
                    return t5.memberExpression(sourceName, t5.identifier(name));
                  });
                });
                const helpers = {};
                const { enableObjectSlots = true } = state.opts;
                if (enableObjectSlots) {
                  state.set("@vue/babel-plugin-jsx/runtimeIsSlot", () => {
                    if (helpers.runtimeIsSlot) {
                      return helpers.runtimeIsSlot;
                    }
                    const isSlot = path.scope.generateUidIdentifier("isSlot");
                    const { object: objectName } = state.get(
                      "isVNode"
                    )();
                    const ast = template.ast`
                    function ${isSlot.name}(s) {
                      return typeof s === 'function' || (Object.prototype.toString.call(s) === '[object Object]' && !${objectName.name}.isVNode(s));
                    }
                  `;
                    const nodePaths = path.get("body");
                    const lastImport = nodePaths.filter(
                      (p) => p.isVariableDeclaration() && p.node.declarations.some(
                        (d) => {
                          var _a;
                          return ((_a = d.id) == null ? void 0 : _a.name) === sourceName.name;
                        }
                      )
                    ).pop();
                    if (lastImport) {
                      lastImport.insertAfter(ast);
                    }
                    return isSlot;
                  });
                }
              }
              const {
                opts: { pragma = "" },
                file
              } = state;
              if (pragma) {
                state.set("createVNode", () => t5.identifier(pragma));
              }
              if (file.ast.comments) {
                for (const comment of file.ast.comments) {
                  const jsxMatches = JSX_ANNOTATION_REGEX.exec(comment.value);
                  if (jsxMatches) {
                    state.set("createVNode", () => t5.identifier(jsxMatches[1]));
                  }
                }
              }
            }
          }
        }
      })
    });
  }
);