@vue-jsx-vapor/compiler 0.0.0

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 ADDED
@@ -0,0 +1,1439 @@
1
+ // src/index.ts
2
+ import { generate as generate2 } from "@vue/compiler-vapor";
3
+
4
+ // src/compile.ts
5
+ import {
6
+ ErrorCodes as ErrorCodes2,
7
+ createCompilerError as createCompilerError2,
8
+ defaultOnError as defaultOnError2
9
+ } from "@vue/compiler-dom";
10
+ import { extend as extend5, isString as isString2 } from "@vue/shared";
11
+ import {
12
+ generate
13
+ } from "@vue/compiler-vapor";
14
+ import { parse } from "@babel/parser";
15
+
16
+ // src/transform.ts
17
+ import {
18
+ defaultOnError,
19
+ defaultOnWarn
20
+ } from "@vue/compiler-dom";
21
+ import { EMPTY_OBJ, NOOP, extend, isArray } from "@vue/shared";
22
+
23
+ // src/transforms/utils.ts
24
+ import {
25
+ DynamicFlag
26
+ } from "@vue/compiler-vapor";
27
+ import { createSimpleExpression as createSimpleExpression2 } from "@vue/compiler-dom";
28
+ import {
29
+ arrowFunctionExpression,
30
+ callExpression,
31
+ jsxClosingFragment,
32
+ jsxExpressionContainer,
33
+ jsxFragment,
34
+ jsxOpeningFragment,
35
+ parenthesizedExpression
36
+ } from "@babel/types";
37
+
38
+ // src/utils.ts
39
+ import { isGloballyAllowed, isString, makeMap } from "@vue/shared";
40
+ import {
41
+ ElementTypes,
42
+ Namespaces,
43
+ NodeTypes,
44
+ createSimpleExpression,
45
+ isLiteralWhitelisted
46
+ } from "@vue/compiler-dom";
47
+ import { parseExpression } from "@babel/parser";
48
+ var __BROWSER__ = false;
49
+ function isConstantExpression(exp) {
50
+ return isLiteralWhitelisted(exp.content) || isGloballyAllowed(exp.content) || getLiteralExpressionValue(exp) !== null;
51
+ }
52
+ function getLiteralExpressionValue(exp) {
53
+ if (!__BROWSER__ && exp.ast) {
54
+ if (["StringLiteral", "NumericLiteral", "BigIntLiteral"].includes(
55
+ exp.ast.type
56
+ )) {
57
+ return exp.ast.value;
58
+ } else if (exp.ast.type === "TemplateLiteral" && exp.ast.expressions.length === 0) {
59
+ return exp.ast.quasis[0].value.cooked;
60
+ }
61
+ }
62
+ return exp.isStatic ? exp.content : null;
63
+ }
64
+ function resolveExpression(node, context) {
65
+ const isStatic = !!node && (node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier");
66
+ const source = !node ? "" : node.type === "JSXIdentifier" ? node.name : isStatic ? node.value : node.type === "JSXExpressionContainer" ? node.expression.type === "Identifier" ? node.expression.name : context.ir.source.slice(
67
+ node.expression.start,
68
+ node.expression.end
69
+ ) : context.ir.source.slice(node.start, node.end);
70
+ const location = node ? node.loc : null;
71
+ let ast = false;
72
+ if (!isStatic && context.options.prefixIdentifiers) {
73
+ ast = parseExpression(` ${source}`, {
74
+ sourceType: "module",
75
+ plugins: context.options.expressionPlugins
76
+ });
77
+ }
78
+ return resolveSimpleExpression(source, isStatic, location, ast);
79
+ }
80
+ function resolveSimpleExpression(source, isStatic, location, ast) {
81
+ const result = createSimpleExpression(
82
+ source,
83
+ isStatic,
84
+ resolveLocation(location, source)
85
+ );
86
+ result.ast = ast ?? null;
87
+ return result;
88
+ }
89
+ function resolveLocation(location, context) {
90
+ return location ? {
91
+ start: {
92
+ line: location.start.line,
93
+ column: location.start.column + 1,
94
+ offset: location.start.index
95
+ },
96
+ end: {
97
+ line: location.end.line,
98
+ column: location.end.column + 1,
99
+ offset: location.end.index
100
+ },
101
+ source: isString(context) ? context : context.ir.source.slice(location.start.index, location.end.index)
102
+ } : {
103
+ start: { line: 1, column: 1, offset: 0 },
104
+ end: { line: 1, column: 1, offset: 0 },
105
+ source: ""
106
+ };
107
+ }
108
+ function resolveValue(value, context) {
109
+ return value ? {
110
+ type: NodeTypes.TEXT,
111
+ content: value.type === "StringLiteral" ? value.value : value.type === "JSXExpressionContainer" ? context.ir.source.slice(
112
+ value.expression.start,
113
+ value.expression.end
114
+ ) : "",
115
+ loc: resolveLocation(value.loc, context)
116
+ } : void 0;
117
+ }
118
+ function resolveNode(node, context) {
119
+ const tag = node.openingElement.name.type === "JSXIdentifier" ? node.openingElement.name.name : "";
120
+ const loc = resolveLocation(node.loc, context);
121
+ const tagType = isJSXComponent(node) ? ElementTypes.COMPONENT : ElementTypes.ELEMENT;
122
+ const props = node.openingElement.attributes.reduce(
123
+ (result, attr) => {
124
+ if (attr.type === "JSXAttribute") {
125
+ if (tagType === ElementTypes.COMPONENT) {
126
+ result.push(resolveDirectiveNode(attr, context));
127
+ } else {
128
+ result.push({
129
+ type: NodeTypes.ATTRIBUTE,
130
+ name: `${attr.name.name}`,
131
+ nameLoc: resolveLocation(attr.name.loc, context),
132
+ value: resolveValue(attr.value, context),
133
+ loc: resolveLocation(attr.loc, context)
134
+ });
135
+ }
136
+ }
137
+ return result;
138
+ },
139
+ []
140
+ );
141
+ return {
142
+ type: NodeTypes.ELEMENT,
143
+ props,
144
+ children: node.children,
145
+ tag,
146
+ loc,
147
+ ns: Namespaces.HTML,
148
+ tagType,
149
+ isSelfClosing: !!node.selfClosing,
150
+ codegenNode: void 0
151
+ };
152
+ }
153
+ function resolveDirectiveNode(node, context) {
154
+ const { value, name } = node;
155
+ const nameString = name.type === "JSXIdentifier" ? name.name : "";
156
+ const argString = name.type === "JSXNamespacedName" ? name.namespace.name : "";
157
+ const arg = name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, true, name.namespace.loc) : void 0;
158
+ const exp = value ? resolveExpression(value, context) : void 0;
159
+ const [tag, ...modifiers] = argString.split("_");
160
+ return {
161
+ type: NodeTypes.DIRECTIVE,
162
+ name: nameString,
163
+ rawName: `${name}:${tag}`,
164
+ exp,
165
+ arg,
166
+ loc: resolveLocation(node.loc, context),
167
+ modifiers: modifiers.map((modifier) => createSimpleExpression(modifier))
168
+ };
169
+ }
170
+ var isHtmlTags = makeMap(
171
+ "a,abbr,address,area,article,aside,audio,b,base,bdi,bdo,blockquote,body,br,button,canvas,caption,cite,code,col,colgroup,data,datalist,dd,del,details,dfn,dialog,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,head,header,hgroup,hr,html,i,iframe,img,input,ins,kbd,label,legend,li,link,main,map,mark,math,menu,menuitem,meta,meter,nav,noscript,object,ol,optgroup,option,output,p,param,picture,pre,progress,q,rb,rp,rt,rtc,ruby,s,samp,script,search,section,select,slot,small,source,span,strong,style,sub,summary,sup,svg,table,tbody,td,template,textarea,tfoot,th,thead,time,title,tr,track,u,ul,var,video,wbr"
172
+ );
173
+ var isSvgTags = makeMap(
174
+ "a,altGlyph,altGlyphDef,altGlyphItem,animate,animateColor,animateMotion,animateTransform,circle,clipPath,color-profile,cursor,defs,desc,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,font,font-face,font-face-format,font-face-name,font-face-src,font-face-uri,foreignObject,g,glyph,glyphRef,hkern,image,line,linearGradient,marker,mask,metadata,missing-glyph,mpath,path,pattern,polygon,polyline,radialGradient,rect,script,set,stop,style,svg,switch,symbol,text,textPath,title,tref,tspan,use,view,vkern"
175
+ );
176
+ function isJSXComponent(node) {
177
+ if (node.type !== "JSXElement") return false;
178
+ const { openingElement } = node;
179
+ if (openingElement.name.type === "JSXIdentifier") {
180
+ const name = openingElement.name.name;
181
+ return !isHtmlTags(name) && !isSvgTags(name);
182
+ } else {
183
+ return openingElement.name.type === "JSXMemberExpression";
184
+ }
185
+ }
186
+ function isMapCallExpression(node) {
187
+ return !!node && node.type === "CallExpression" && node.callee.type === "MemberExpression" && node.callee.property.type === "Identifier" && node.callee.property.name === "map";
188
+ }
189
+ function findProp(expression, key) {
190
+ if (expression?.type === "JSXElement") {
191
+ for (const attr of expression.openingElement.attributes) {
192
+ if (attr.type === "JSXAttribute" && attr.name.name === key) {
193
+ return attr;
194
+ }
195
+ }
196
+ }
197
+ }
198
+ function getReturnExpression(node) {
199
+ if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") {
200
+ if (node.body.type !== "BlockStatement") {
201
+ return node.body;
202
+ } else {
203
+ for (const statement of node.body.body) {
204
+ if (statement.type === "ReturnStatement" && statement.argument)
205
+ return statement.argument;
206
+ }
207
+ }
208
+ }
209
+ }
210
+ function isJSXElement(node) {
211
+ return !!node && (node.type === "JSXElement" || node.type === "JSXFragment");
212
+ }
213
+
214
+ // src/transforms/utils.ts
215
+ function newDynamic() {
216
+ return {
217
+ flags: DynamicFlag.REFERENCED,
218
+ children: []
219
+ };
220
+ }
221
+ function newBlock(node) {
222
+ return {
223
+ type: 1,
224
+ node,
225
+ dynamic: newDynamic(),
226
+ effect: [],
227
+ operation: [],
228
+ returns: []
229
+ };
230
+ }
231
+ function createBranch(node, context, isVFor) {
232
+ context.node = node = wrapFragment(node, isVFor);
233
+ const branch = newBlock(node);
234
+ const exitBlock = context.enterBlock(branch, isVFor);
235
+ context.reference();
236
+ return [branch, exitBlock];
237
+ }
238
+ function wrapFragment(node, isVFor) {
239
+ if (node.type === "JSXFragment") {
240
+ return node;
241
+ }
242
+ if (isVFor && (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression")) {
243
+ if (isJSXElement(node.body)) {
244
+ node = node.body;
245
+ } else if (node.body.type === "BlockStatement" && node.body.body[0].type === "ReturnStatement" && node.body.body[0].argument) {
246
+ node = node.body.body[0].argument;
247
+ } else {
248
+ node = {
249
+ ...callExpression(
250
+ parenthesizedExpression(arrowFunctionExpression([], node.body)),
251
+ []
252
+ ),
253
+ start: node.body.start,
254
+ end: node.body.end
255
+ };
256
+ }
257
+ }
258
+ return jsxFragment(jsxOpeningFragment(), jsxClosingFragment(), [
259
+ node.type === "JSXElement" ? node : jsxExpressionContainer(node)
260
+ ]);
261
+ }
262
+ var EMPTY_EXPRESSION = createSimpleExpression2("", true);
263
+
264
+ // src/ir/component.ts
265
+ var IRDynamicPropsKind = /* @__PURE__ */ ((IRDynamicPropsKind2) => {
266
+ IRDynamicPropsKind2[IRDynamicPropsKind2["EXPRESSION"] = 0] = "EXPRESSION";
267
+ IRDynamicPropsKind2[IRDynamicPropsKind2["ATTRIBUTE"] = 1] = "ATTRIBUTE";
268
+ return IRDynamicPropsKind2;
269
+ })(IRDynamicPropsKind || {});
270
+ var IRSlotType = /* @__PURE__ */ ((IRSlotType2) => {
271
+ IRSlotType2[IRSlotType2["STATIC"] = 0] = "STATIC";
272
+ IRSlotType2[IRSlotType2["DYNAMIC"] = 1] = "DYNAMIC";
273
+ IRSlotType2[IRSlotType2["LOOP"] = 2] = "LOOP";
274
+ IRSlotType2[IRSlotType2["CONDITIONAL"] = 3] = "CONDITIONAL";
275
+ IRSlotType2[IRSlotType2["EXPRESSION"] = 4] = "EXPRESSION";
276
+ return IRSlotType2;
277
+ })(IRSlotType || {});
278
+
279
+ // src/ir/index.ts
280
+ var IRNodeTypes = /* @__PURE__ */ ((IRNodeTypes2) => {
281
+ IRNodeTypes2[IRNodeTypes2["ROOT"] = 0] = "ROOT";
282
+ IRNodeTypes2[IRNodeTypes2["BLOCK"] = 1] = "BLOCK";
283
+ IRNodeTypes2[IRNodeTypes2["SET_PROP"] = 2] = "SET_PROP";
284
+ IRNodeTypes2[IRNodeTypes2["SET_DYNAMIC_PROPS"] = 3] = "SET_DYNAMIC_PROPS";
285
+ IRNodeTypes2[IRNodeTypes2["SET_TEXT"] = 4] = "SET_TEXT";
286
+ IRNodeTypes2[IRNodeTypes2["SET_EVENT"] = 5] = "SET_EVENT";
287
+ IRNodeTypes2[IRNodeTypes2["SET_DYNAMIC_EVENTS"] = 6] = "SET_DYNAMIC_EVENTS";
288
+ IRNodeTypes2[IRNodeTypes2["SET_HTML"] = 7] = "SET_HTML";
289
+ IRNodeTypes2[IRNodeTypes2["SET_TEMPLATE_REF"] = 8] = "SET_TEMPLATE_REF";
290
+ IRNodeTypes2[IRNodeTypes2["SET_MODEL_VALUE"] = 9] = "SET_MODEL_VALUE";
291
+ IRNodeTypes2[IRNodeTypes2["INSERT_NODE"] = 10] = "INSERT_NODE";
292
+ IRNodeTypes2[IRNodeTypes2["PREPEND_NODE"] = 11] = "PREPEND_NODE";
293
+ IRNodeTypes2[IRNodeTypes2["CREATE_TEXT_NODE"] = 12] = "CREATE_TEXT_NODE";
294
+ IRNodeTypes2[IRNodeTypes2["CREATE_COMPONENT_NODE"] = 13] = "CREATE_COMPONENT_NODE";
295
+ IRNodeTypes2[IRNodeTypes2["SLOT_OUTLET_NODE"] = 14] = "SLOT_OUTLET_NODE";
296
+ IRNodeTypes2[IRNodeTypes2["WITH_DIRECTIVE"] = 15] = "WITH_DIRECTIVE";
297
+ IRNodeTypes2[IRNodeTypes2["DECLARE_OLD_REF"] = 16] = "DECLARE_OLD_REF";
298
+ IRNodeTypes2[IRNodeTypes2["IF"] = 17] = "IF";
299
+ IRNodeTypes2[IRNodeTypes2["FOR"] = 18] = "FOR";
300
+ return IRNodeTypes2;
301
+ })(IRNodeTypes || {});
302
+ var DynamicFlag2 = /* @__PURE__ */ ((DynamicFlag3) => {
303
+ DynamicFlag3[DynamicFlag3["NONE"] = 0] = "NONE";
304
+ DynamicFlag3[DynamicFlag3["REFERENCED"] = 1] = "REFERENCED";
305
+ DynamicFlag3[DynamicFlag3["NON_TEMPLATE"] = 2] = "NON_TEMPLATE";
306
+ DynamicFlag3[DynamicFlag3["INSERT"] = 4] = "INSERT";
307
+ return DynamicFlag3;
308
+ })(DynamicFlag2 || {});
309
+
310
+ // src/transform.ts
311
+ var defaultOptions = {
312
+ filename: "",
313
+ prefixIdentifiers: false,
314
+ hoistStatic: false,
315
+ hmr: false,
316
+ cacheHandlers: false,
317
+ nodeTransforms: [],
318
+ directiveTransforms: {},
319
+ transformHoist: null,
320
+ isBuiltInComponent: NOOP,
321
+ isCustomElement: NOOP,
322
+ expressionPlugins: [],
323
+ scopeId: null,
324
+ slotted: true,
325
+ ssr: false,
326
+ inSSR: false,
327
+ ssrCssVars: ``,
328
+ bindingMetadata: EMPTY_OBJ,
329
+ inline: false,
330
+ isTS: false,
331
+ onError: defaultOnError,
332
+ onWarn: defaultOnWarn
333
+ };
334
+ var TransformContext = class _TransformContext {
335
+ constructor(ir, node, options = {}) {
336
+ this.ir = ir;
337
+ this.node = node;
338
+ this.parent = null;
339
+ this.index = 0;
340
+ this.block = this.ir.block;
341
+ this.template = "";
342
+ this.childrenTemplate = [];
343
+ this.dynamic = this.ir.block.dynamic;
344
+ this.inVOnce = false;
345
+ this.inVFor = 0;
346
+ this.comment = [];
347
+ this.component = this.ir.component;
348
+ this.directive = this.ir.directive;
349
+ this.slots = [];
350
+ this.globalId = 0;
351
+ this.increaseId = () => this.globalId++;
352
+ this.options = extend({}, defaultOptions, options);
353
+ this.root = this;
354
+ }
355
+ enterBlock(ir, isVFor = false) {
356
+ const { block, template, dynamic, childrenTemplate, slots } = this;
357
+ this.block = ir;
358
+ this.dynamic = ir.dynamic;
359
+ this.template = "";
360
+ this.childrenTemplate = [];
361
+ this.slots = [];
362
+ isVFor && this.inVFor++;
363
+ return () => {
364
+ this.registerTemplate();
365
+ this.block = block;
366
+ this.template = template;
367
+ this.dynamic = dynamic;
368
+ this.childrenTemplate = childrenTemplate;
369
+ this.slots = slots;
370
+ isVFor && this.inVFor--;
371
+ };
372
+ }
373
+ reference() {
374
+ if (this.dynamic.id !== void 0) return this.dynamic.id;
375
+ this.dynamic.flags |= 1 /* REFERENCED */;
376
+ return this.dynamic.id = this.increaseId();
377
+ }
378
+ pushTemplate(content) {
379
+ const existing = this.ir.template.indexOf(content);
380
+ if (existing !== -1) return existing;
381
+ this.ir.template.push(content);
382
+ return this.ir.template.length - 1;
383
+ }
384
+ registerTemplate() {
385
+ if (!this.template) return -1;
386
+ const id = this.pushTemplate(this.template);
387
+ return this.dynamic.template = id;
388
+ }
389
+ registerEffect(expressions, ...operations) {
390
+ expressions = expressions.filter((exp) => !isConstantExpression(exp));
391
+ if (this.inVOnce || expressions.length === 0) {
392
+ return this.registerOperation(...operations);
393
+ }
394
+ const existing = this.block.effect.find(
395
+ (e) => isSameExpression(e.expressions, expressions)
396
+ );
397
+ if (existing) {
398
+ existing.operations.push(...operations);
399
+ } else {
400
+ this.block.effect.push({
401
+ expressions,
402
+ operations
403
+ });
404
+ }
405
+ function isSameExpression(a, b) {
406
+ if (a.length !== b.length) return false;
407
+ return a.every((exp, i) => exp.content === b[i].content);
408
+ }
409
+ }
410
+ registerOperation(...node) {
411
+ this.block.operation.push(...node);
412
+ }
413
+ create(node, index) {
414
+ return Object.assign(Object.create(_TransformContext.prototype), this, {
415
+ node,
416
+ parent: this,
417
+ index,
418
+ template: "",
419
+ childrenTemplate: [],
420
+ dynamic: newDynamic()
421
+ });
422
+ }
423
+ };
424
+ function transform(node, options = {}) {
425
+ const ir = {
426
+ type: 0 /* ROOT */,
427
+ node,
428
+ source: node.source,
429
+ template: [],
430
+ component: /* @__PURE__ */ new Set(),
431
+ directive: /* @__PURE__ */ new Set(),
432
+ block: newBlock(node)
433
+ };
434
+ const context = new TransformContext(ir, node, options);
435
+ transformNode(context);
436
+ return ir;
437
+ }
438
+ function transformNode(context) {
439
+ let { node } = context;
440
+ const { nodeTransforms } = context.options;
441
+ const exitFns = [];
442
+ for (const nodeTransform of nodeTransforms) {
443
+ const onExit = nodeTransform(node, context);
444
+ if (onExit) {
445
+ if (isArray(onExit)) {
446
+ exitFns.push(...onExit);
447
+ } else {
448
+ exitFns.push(onExit);
449
+ }
450
+ }
451
+ if (!context.node) {
452
+ return;
453
+ } else {
454
+ node = context.node;
455
+ }
456
+ }
457
+ context.node = node;
458
+ let i = exitFns.length;
459
+ while (i--) {
460
+ exitFns[i]();
461
+ }
462
+ if (context.node.type === 0 /* ROOT */) {
463
+ context.registerTemplate();
464
+ }
465
+ }
466
+
467
+ // src/transforms/transformElement.ts
468
+ import {
469
+ camelize,
470
+ capitalize,
471
+ extend as extend2,
472
+ isBuiltInDirective,
473
+ isVoidTag,
474
+ makeMap as makeMap2
475
+ } from "@vue/shared";
476
+
477
+ // src/html-nesting.ts
478
+ function isValidHTMLNesting(parent, child) {
479
+ if (parent in onlyValidChildren) {
480
+ return onlyValidChildren[parent].has(child);
481
+ }
482
+ if (child in onlyValidParents) {
483
+ return onlyValidParents[child].has(parent);
484
+ }
485
+ if (parent in knownInvalidChildren && // check if the child is in the list of invalid children
486
+ // if so, return false
487
+ knownInvalidChildren[parent].has(child))
488
+ return false;
489
+ if (child in knownInvalidParents && // check if the parent is in the list of invalid parents
490
+ // if so, return false
491
+ knownInvalidParents[child].has(parent))
492
+ return false;
493
+ return true;
494
+ }
495
+ var headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
496
+ var emptySet = /* @__PURE__ */ new Set([]);
497
+ var onlyValidChildren = {
498
+ head: /* @__PURE__ */ new Set([
499
+ "base",
500
+ "basefront",
501
+ "bgsound",
502
+ "link",
503
+ "meta",
504
+ "title",
505
+ "noscript",
506
+ "noframes",
507
+ "style",
508
+ "script",
509
+ "template"
510
+ ]),
511
+ optgroup: /* @__PURE__ */ new Set(["option"]),
512
+ select: /* @__PURE__ */ new Set(["optgroup", "option"]),
513
+ math: /* @__PURE__ */ new Set(["mrow"]),
514
+ script: /* @__PURE__ */ new Set(),
515
+ // table
516
+ table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
517
+ tr: /* @__PURE__ */ new Set(["td", "th"]),
518
+ colgroup: /* @__PURE__ */ new Set(["col"]),
519
+ tbody: /* @__PURE__ */ new Set(["tr"]),
520
+ thead: /* @__PURE__ */ new Set(["tr"]),
521
+ tfoot: /* @__PURE__ */ new Set(["tr"]),
522
+ // these elements can not have any children elements
523
+ iframe: emptySet,
524
+ option: emptySet,
525
+ textarea: emptySet,
526
+ style: emptySet,
527
+ title: emptySet
528
+ };
529
+ var onlyValidParents = {
530
+ // sections
531
+ html: emptySet,
532
+ body: /* @__PURE__ */ new Set(["html"]),
533
+ head: /* @__PURE__ */ new Set(["html"]),
534
+ // table
535
+ td: /* @__PURE__ */ new Set(["tr"]),
536
+ colgroup: /* @__PURE__ */ new Set(["table"]),
537
+ caption: /* @__PURE__ */ new Set(["table"]),
538
+ tbody: /* @__PURE__ */ new Set(["table"]),
539
+ tfoot: /* @__PURE__ */ new Set(["table"]),
540
+ col: /* @__PURE__ */ new Set(["colgroup"]),
541
+ th: /* @__PURE__ */ new Set(["tr"]),
542
+ thead: /* @__PURE__ */ new Set(["table"]),
543
+ tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
544
+ // data list
545
+ dd: /* @__PURE__ */ new Set(["dl", "div"]),
546
+ dt: /* @__PURE__ */ new Set(["dl", "div"]),
547
+ // other
548
+ figcaption: /* @__PURE__ */ new Set(["figure"]),
549
+ // li: new Set(["ul", "ol"]),
550
+ summary: /* @__PURE__ */ new Set(["details"]),
551
+ area: /* @__PURE__ */ new Set(["map"])
552
+ };
553
+ var knownInvalidChildren = {
554
+ p: /* @__PURE__ */ new Set([
555
+ "address",
556
+ "article",
557
+ "aside",
558
+ "blockquote",
559
+ "center",
560
+ "details",
561
+ "dialog",
562
+ "dir",
563
+ "div",
564
+ "dl",
565
+ "fieldset",
566
+ "figure",
567
+ "footer",
568
+ "form",
569
+ "h1",
570
+ "h2",
571
+ "h3",
572
+ "h4",
573
+ "h5",
574
+ "h6",
575
+ "header",
576
+ "hgroup",
577
+ "hr",
578
+ "li",
579
+ "main",
580
+ "nav",
581
+ "menu",
582
+ "ol",
583
+ "p",
584
+ "pre",
585
+ "section",
586
+ "table",
587
+ "ul"
588
+ ]),
589
+ svg: /* @__PURE__ */ new Set([
590
+ "b",
591
+ "blockquote",
592
+ "br",
593
+ "code",
594
+ "dd",
595
+ "div",
596
+ "dl",
597
+ "dt",
598
+ "em",
599
+ "embed",
600
+ "h1",
601
+ "h2",
602
+ "h3",
603
+ "h4",
604
+ "h5",
605
+ "h6",
606
+ "hr",
607
+ "i",
608
+ "img",
609
+ "li",
610
+ "menu",
611
+ "meta",
612
+ "ol",
613
+ "p",
614
+ "pre",
615
+ "ruby",
616
+ "s",
617
+ "small",
618
+ "span",
619
+ "strong",
620
+ "sub",
621
+ "sup",
622
+ "table",
623
+ "u",
624
+ "ul",
625
+ "var"
626
+ ])
627
+ };
628
+ var knownInvalidParents = {
629
+ a: /* @__PURE__ */ new Set(["a"]),
630
+ button: /* @__PURE__ */ new Set(["button"]),
631
+ dd: /* @__PURE__ */ new Set(["dd", "dt"]),
632
+ dt: /* @__PURE__ */ new Set(["dd", "dt"]),
633
+ form: /* @__PURE__ */ new Set(["form"]),
634
+ li: /* @__PURE__ */ new Set(["li"]),
635
+ h1: headings,
636
+ h2: headings,
637
+ h3: headings,
638
+ h4: headings,
639
+ h5: headings,
640
+ h6: headings
641
+ };
642
+
643
+ // src/transforms/transformElement.ts
644
+ var isReservedProp = /* @__PURE__ */ makeMap2(
645
+ // the leading comma is intentional so empty string "" is also included
646
+ ",key,ref,ref_for,ref_key,"
647
+ );
648
+ var __BROWSER__2 = false;
649
+ var isEventRegex = /^on[A-Z]/;
650
+ var isDirectiveRegex = /^v-[a-z]/;
651
+ var transformElement = (node, context) => {
652
+ return function postTransformElement() {
653
+ ;
654
+ ({ node } = context);
655
+ if (node.type !== "JSXElement") return;
656
+ const {
657
+ openingElement: { name }
658
+ } = node;
659
+ const tag = name.type === "JSXIdentifier" ? name.name : name.type === "JSXMemberExpression" ? context.ir.source.slice(name.start, name.end) : "";
660
+ const isComponent = isJSXComponent(node);
661
+ const propsResult = buildProps(
662
+ node,
663
+ context,
664
+ isComponent
665
+ );
666
+ (isComponent ? transformComponentElement : transformNativeElement)(
667
+ tag,
668
+ propsResult,
669
+ context
670
+ );
671
+ };
672
+ };
673
+ function transformComponentElement(tag, propsResult, context) {
674
+ let asset = true;
675
+ if (!__BROWSER__2) {
676
+ const fromSetup = resolveSetupReference(tag, context);
677
+ if (fromSetup) {
678
+ tag = fromSetup;
679
+ asset = false;
680
+ }
681
+ const dotIndex = tag.indexOf(".");
682
+ if (dotIndex > 0) {
683
+ const ns = resolveSetupReference(tag.slice(0, dotIndex), context);
684
+ if (ns) {
685
+ tag = ns + tag.slice(dotIndex);
686
+ asset = false;
687
+ }
688
+ }
689
+ }
690
+ if (asset) {
691
+ context.component.add(tag);
692
+ }
693
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
694
+ const root = context.root === context.parent && context.parent.node.children.length === 1;
695
+ context.registerOperation({
696
+ type: 13 /* CREATE_COMPONENT_NODE */,
697
+ id: context.reference(),
698
+ tag,
699
+ props: propsResult[0] ? propsResult[1] : [propsResult[1]],
700
+ asset,
701
+ root,
702
+ slots: context.slots,
703
+ once: context.inVOnce
704
+ });
705
+ context.slots = [];
706
+ }
707
+ function resolveSetupReference(name, context) {
708
+ const bindings = context.options.bindingMetadata;
709
+ if (!context.options.prefixIdentifiers) return name;
710
+ if (!bindings || bindings.__isScriptSetup === false) {
711
+ return;
712
+ }
713
+ const camelName = camelize(name);
714
+ const PascalName = capitalize(camelName);
715
+ return bindings[name] ? name : bindings[camelName] ? camelName : bindings[PascalName] ? PascalName : void 0;
716
+ }
717
+ function transformNativeElement(tag, propsResult, context) {
718
+ const { scopeId } = context.options;
719
+ let template = "";
720
+ template += `<${tag}`;
721
+ if (scopeId) template += ` ${scopeId}`;
722
+ if (propsResult[0]) {
723
+ const [, dynamicArgs, expressions] = propsResult;
724
+ context.registerEffect(expressions, {
725
+ type: 3 /* SET_DYNAMIC_PROPS */,
726
+ element: context.reference(),
727
+ props: dynamicArgs
728
+ });
729
+ } else {
730
+ for (const prop of propsResult[1]) {
731
+ const { key, values } = prop;
732
+ if (key.isStatic && values.length === 1 && values[0].isStatic) {
733
+ template += ` ${key.content}`;
734
+ if (values[0].content) template += `="${values[0].content}"`;
735
+ } else {
736
+ context.registerEffect(values, {
737
+ type: 2 /* SET_PROP */,
738
+ element: context.reference(),
739
+ prop
740
+ });
741
+ }
742
+ }
743
+ }
744
+ template += `>${context.childrenTemplate.join("")}`;
745
+ if (!isVoidTag(tag)) {
746
+ template += `</${tag}>`;
747
+ }
748
+ if (context.parent && context.parent.node.type === "JSXElement" && context.parent.node.openingElement.name.type === "JSXIdentifier" && !isValidHTMLNesting(context.parent.node.openingElement.name.name, tag)) {
749
+ context.reference();
750
+ context.dynamic.template = context.pushTemplate(template);
751
+ context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
752
+ } else {
753
+ context.template += template;
754
+ }
755
+ }
756
+ function buildProps(node, context, isComponent) {
757
+ const props = node.openingElement.attributes;
758
+ if (props.length === 0) return [false, []];
759
+ const dynamicArgs = [];
760
+ const dynamicExpr = [];
761
+ let results = [];
762
+ function pushMergeArg() {
763
+ if (results.length) {
764
+ dynamicArgs.push(dedupeProperties(results));
765
+ results = [];
766
+ }
767
+ }
768
+ for (const prop of props) {
769
+ if (prop.type === "JSXSpreadAttribute" && prop.argument) {
770
+ const value = resolveExpression(prop.argument, context);
771
+ dynamicExpr.push(value);
772
+ pushMergeArg();
773
+ dynamicArgs.push({
774
+ kind: 0 /* EXPRESSION */,
775
+ value
776
+ });
777
+ continue;
778
+ }
779
+ const result = transformProp(prop, node, context);
780
+ if (result) {
781
+ dynamicExpr.push(result.key, result.value);
782
+ if (isComponent && !result.key.isStatic) {
783
+ pushMergeArg();
784
+ dynamicArgs.push(
785
+ extend2(resolveDirectiveResult(result), {
786
+ kind: 1 /* ATTRIBUTE */
787
+ })
788
+ );
789
+ } else {
790
+ results.push(result);
791
+ }
792
+ }
793
+ }
794
+ if (dynamicArgs.length || results.some(({ key }) => !key.isStatic)) {
795
+ pushMergeArg();
796
+ return [true, dynamicArgs, dynamicExpr];
797
+ }
798
+ const irProps = dedupeProperties(results);
799
+ return [false, irProps];
800
+ }
801
+ function transformProp(prop, node, context) {
802
+ if (prop.type === "JSXSpreadAttribute") return;
803
+ let name = prop.name.type === "JSXIdentifier" ? prop.name.name : prop.name.type === "JSXNamespacedName" ? prop.name.namespace.name : "";
804
+ if (!isDirectiveRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
805
+ if (isReservedProp(name)) return;
806
+ return {
807
+ key: resolveSimpleExpression(name, true, prop.name.loc),
808
+ value: prop.value && prop.value.type === "StringLiteral" ? resolveSimpleExpression(prop.value.value, true, prop.value.loc) : EMPTY_EXPRESSION
809
+ };
810
+ }
811
+ name = isEventRegex.test(name) ? "on" : isDirectiveRegex.test(name) ? name.slice(2) : "bind";
812
+ const directiveTransform = context.options.directiveTransforms[name];
813
+ if (directiveTransform) {
814
+ return directiveTransform(prop, node, context);
815
+ }
816
+ if (!isBuiltInDirective(name)) {
817
+ const fromSetup = !__BROWSER__2 && resolveSetupReference(`v-${name}`, context);
818
+ if (fromSetup) {
819
+ name = fromSetup;
820
+ } else {
821
+ context.directive.add(name);
822
+ }
823
+ }
824
+ }
825
+ function dedupeProperties(results) {
826
+ const knownProps = /* @__PURE__ */ new Map();
827
+ const deduped = [];
828
+ for (const result of results) {
829
+ const prop = resolveDirectiveResult(result);
830
+ if (!prop.key.isStatic) {
831
+ deduped.push(prop);
832
+ continue;
833
+ }
834
+ const name = prop.key.content;
835
+ const existing = knownProps.get(name);
836
+ if (existing) {
837
+ if (name === "style" || name === "class") {
838
+ mergePropValues(existing, prop);
839
+ }
840
+ } else {
841
+ knownProps.set(name, prop);
842
+ deduped.push(prop);
843
+ }
844
+ }
845
+ return deduped;
846
+ }
847
+ function resolveDirectiveResult(prop) {
848
+ return extend2({}, prop, {
849
+ value: void 0,
850
+ values: [prop.value]
851
+ });
852
+ }
853
+ function mergePropValues(existing, incoming) {
854
+ const newValues = incoming.values;
855
+ existing.values.push(...newValues);
856
+ }
857
+
858
+ // src/transforms/transformChildren.ts
859
+ var transformChildren = (node, context) => {
860
+ const isFragment = node.type === 0 /* ROOT */ || node.type === "JSXFragment" || isJSXComponent(node);
861
+ if (node.type !== "JSXElement" && !isFragment) return;
862
+ Array.from(node.children).forEach((child, index) => {
863
+ if (child.type === "JSXText" && !child.value.trim()) {
864
+ child.value = " ";
865
+ if (!index) {
866
+ node.children.splice(0, 1);
867
+ } else if (index === node.children.length) {
868
+ node.children.splice(-1, 1);
869
+ }
870
+ }
871
+ });
872
+ for (const [i, child] of node.children.entries()) {
873
+ const childContext = context.create(child, i);
874
+ transformNode(childContext);
875
+ if (isFragment) {
876
+ childContext.reference();
877
+ childContext.registerTemplate();
878
+ if (!(childContext.dynamic.flags & 2 /* NON_TEMPLATE */) || childContext.dynamic.flags & 4 /* INSERT */) {
879
+ context.block.returns.push(childContext.dynamic.id);
880
+ }
881
+ } else {
882
+ context.childrenTemplate.push(childContext.template);
883
+ }
884
+ context.dynamic.children[i] = childContext.dynamic;
885
+ }
886
+ if (!isFragment) {
887
+ processDynamicChildren(context);
888
+ }
889
+ };
890
+ function processDynamicChildren(context) {
891
+ let prevDynamics = [];
892
+ let hasStaticTemplate = false;
893
+ const children = context.dynamic.children;
894
+ for (const [index, child] of children.entries()) {
895
+ if (child.flags & 4 /* INSERT */) {
896
+ prevDynamics.push(child);
897
+ }
898
+ if (!(child.flags & 2 /* NON_TEMPLATE */)) {
899
+ if (prevDynamics.length) {
900
+ if (hasStaticTemplate) {
901
+ context.childrenTemplate[index - prevDynamics.length] = `<!>`;
902
+ prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
903
+ const anchor = prevDynamics[0].anchor = context.increaseId();
904
+ context.registerOperation({
905
+ type: 10 /* INSERT_NODE */,
906
+ elements: prevDynamics.map((child2) => child2.id),
907
+ parent: context.reference(),
908
+ anchor
909
+ });
910
+ } else {
911
+ context.registerOperation({
912
+ type: 11 /* PREPEND_NODE */,
913
+ elements: prevDynamics.map((child2) => child2.id),
914
+ parent: context.reference()
915
+ });
916
+ }
917
+ prevDynamics = [];
918
+ }
919
+ hasStaticTemplate = true;
920
+ }
921
+ }
922
+ if (prevDynamics.length) {
923
+ context.registerOperation({
924
+ type: 10 /* INSERT_NODE */,
925
+ elements: prevDynamics.map((child) => child.id),
926
+ parent: context.reference()
927
+ });
928
+ }
929
+ }
930
+
931
+ // src/transforms/transformTemplateRef.ts
932
+ var transformTemplateRef = (node, context) => {
933
+ if (node.type !== "JSXElement") return;
934
+ const dir = findProp(node, "ref");
935
+ if (!dir?.value) return;
936
+ const value = resolveExpression(dir.value, context);
937
+ return () => {
938
+ const id = context.reference();
939
+ const effect = !isConstantExpression(value);
940
+ effect && context.registerOperation({
941
+ type: 16 /* DECLARE_OLD_REF */,
942
+ id
943
+ });
944
+ context.registerEffect([value], {
945
+ type: 8 /* SET_TEMPLATE_REF */,
946
+ element: id,
947
+ value,
948
+ refFor: !!context.inVFor,
949
+ effect
950
+ });
951
+ };
952
+ };
953
+
954
+ // src/transforms/vIf.ts
955
+ function processConditionalExpression(node, context) {
956
+ const { test, consequent, alternate } = node;
957
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
958
+ const id = context.reference();
959
+ const condition = resolveExpression(test, context);
960
+ const [branch, onExit] = createBranch(consequent, context);
961
+ const operation = {
962
+ type: 17 /* IF */,
963
+ id,
964
+ condition,
965
+ positive: branch,
966
+ once: context.inVOnce
967
+ };
968
+ return [
969
+ () => {
970
+ onExit();
971
+ context.registerOperation(operation);
972
+ },
973
+ () => {
974
+ const [branch2, onExit2] = createBranch(alternate, context);
975
+ operation.negative = branch2;
976
+ transformNode(context);
977
+ onExit2();
978
+ }
979
+ ];
980
+ }
981
+ function processLogicalExpression(node, context) {
982
+ const { left, right, operator } = node;
983
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */;
984
+ context.dynamic.flags |= 4 /* INSERT */;
985
+ const id = context.reference();
986
+ const condition = resolveExpression(left, context);
987
+ const [branch, onExit] = createBranch(
988
+ operator === "&&" ? right : left,
989
+ context
990
+ );
991
+ const operation = {
992
+ type: 17 /* IF */,
993
+ id,
994
+ condition,
995
+ positive: branch,
996
+ once: context.inVOnce
997
+ };
998
+ return [
999
+ () => {
1000
+ onExit();
1001
+ context.registerOperation(operation);
1002
+ },
1003
+ () => {
1004
+ const [branch2, onExit2] = createBranch(
1005
+ operator === "&&" ? left : right,
1006
+ context
1007
+ );
1008
+ operation.negative = branch2;
1009
+ transformNode(context);
1010
+ onExit2();
1011
+ }
1012
+ ];
1013
+ }
1014
+
1015
+ // src/transforms/vFor.ts
1016
+ function processMapCallExpression(node, context) {
1017
+ const {
1018
+ callee,
1019
+ arguments: [argument]
1020
+ } = node;
1021
+ if (!(argument.type === "FunctionExpression" || argument.type === "ArrowFunctionExpression") || callee?.type !== "MemberExpression")
1022
+ return;
1023
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
1024
+ const id = context.reference();
1025
+ const [render, exitBlock] = createBranch(argument, context, true);
1026
+ const source = resolveExpression(callee.object, context);
1027
+ const value = argument.params[0] && resolveExpression(argument.params[0], context);
1028
+ const key = argument.params[1] && resolveExpression(argument.params[1], context);
1029
+ const index = argument.params[2] && resolveExpression(argument.params[2], context);
1030
+ const returnExpression = getReturnExpression(argument);
1031
+ const keyProp = findProp(returnExpression, "key");
1032
+ const keyProperty = keyProp && resolveExpression(keyProp.value, context);
1033
+ return () => {
1034
+ exitBlock();
1035
+ context.registerOperation({
1036
+ type: 18 /* FOR */,
1037
+ id,
1038
+ source,
1039
+ value,
1040
+ key,
1041
+ index,
1042
+ keyProp: keyProperty,
1043
+ render,
1044
+ once: context.inVOnce
1045
+ });
1046
+ };
1047
+ }
1048
+
1049
+ // src/transforms/transformText.ts
1050
+ var seen = /* @__PURE__ */ new WeakMap();
1051
+ var transformText = (node, context) => {
1052
+ if (!seen.has(context.root)) seen.set(context.root, /* @__PURE__ */ new WeakSet());
1053
+ if (seen.get(context.root).has(node)) {
1054
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */;
1055
+ return;
1056
+ }
1057
+ if (node.type === "JSXElement" && !isJSXComponent(node) && isAllTextLike(node.children)) {
1058
+ processTextLikeContainer(
1059
+ node.children,
1060
+ context
1061
+ );
1062
+ } else if (node.type === "JSXExpressionContainer") {
1063
+ if (node.expression.type === "ConditionalExpression") {
1064
+ return processConditionalExpression(node.expression, context);
1065
+ } else if (node.expression.type === "LogicalExpression") {
1066
+ return processLogicalExpression(node.expression, context);
1067
+ } else if (node.expression.type === "CallExpression") {
1068
+ if (isMapCallExpression(node.expression)) {
1069
+ return processMapCallExpression(node.expression, context);
1070
+ } else {
1071
+ processCallExpression(node.expression, context);
1072
+ }
1073
+ } else {
1074
+ processTextLike(context);
1075
+ }
1076
+ } else if (node.type === "JSXText") {
1077
+ context.template += node.value;
1078
+ }
1079
+ };
1080
+ function processTextLike(context) {
1081
+ const nexts = context.parent.node.children?.slice(context.index);
1082
+ const idx = nexts.findIndex((n) => !isTextLike(n));
1083
+ const nodes = idx > -1 ? nexts.slice(0, idx) : nexts;
1084
+ const id = context.reference();
1085
+ const values = nodes.map((node) => createTextLikeExpression(node, context));
1086
+ context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
1087
+ context.registerOperation({
1088
+ type: 12 /* CREATE_TEXT_NODE */,
1089
+ id,
1090
+ values,
1091
+ effect: !values.every(isConstantExpression) && !context.inVOnce
1092
+ });
1093
+ }
1094
+ function processTextLikeContainer(children, context) {
1095
+ const values = children.map(
1096
+ (child) => createTextLikeExpression(child, context)
1097
+ );
1098
+ const literals = values.map(getLiteralExpressionValue);
1099
+ if (literals.every((l) => l != null)) {
1100
+ context.childrenTemplate = literals.map((l) => String(l));
1101
+ } else {
1102
+ context.registerEffect(values, {
1103
+ type: 4 /* SET_TEXT */,
1104
+ element: context.reference(),
1105
+ values
1106
+ });
1107
+ }
1108
+ }
1109
+ function createTextLikeExpression(node, context) {
1110
+ seen.get(context.root).add(node);
1111
+ return resolveExpression(node, context);
1112
+ }
1113
+ function isAllTextLike(children) {
1114
+ return !!children.length && children.every(isTextLike) && // at least one an interpolation
1115
+ children.some((n) => n.type === "JSXExpressionContainer");
1116
+ }
1117
+ function isTextLike(node) {
1118
+ return node.type === "JSXExpressionContainer" && !(node.expression.type === "ConditionalExpression" || node.expression.type === "LogicalExpression") && node.expression.type !== "CallExpression" || node.type === "JSXText";
1119
+ }
1120
+ function processCallExpression(node, context) {
1121
+ context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
1122
+ const root = context.root === context.parent && context.parent.node.children.length === 1;
1123
+ const tag = `() => ${context.ir.source.slice(node.start, node.end)}`;
1124
+ context.registerOperation({
1125
+ type: 13 /* CREATE_COMPONENT_NODE */,
1126
+ id: context.reference(),
1127
+ tag,
1128
+ props: [],
1129
+ asset: false,
1130
+ root,
1131
+ slots: context.slots,
1132
+ once: context.inVOnce
1133
+ });
1134
+ }
1135
+
1136
+ // src/transforms/vBind.ts
1137
+ import { camelize as camelize2, extend as extend3 } from "@vue/shared";
1138
+ var transformVBind = (dir, node, context) => {
1139
+ const { name, value, loc } = dir;
1140
+ if (!loc || name.type === "JSXNamespacedName") return;
1141
+ const [nameString, ...modifiers] = name.name.split("_");
1142
+ const exp = resolveExpression(value, context);
1143
+ let arg = resolveSimpleExpression(nameString, true, dir.name.loc);
1144
+ if (arg.isStatic && isReservedProp(arg.content)) return;
1145
+ let camel = false;
1146
+ if (modifiers.includes("camel")) {
1147
+ if (arg.isStatic) {
1148
+ arg = extend3({}, arg, { content: camelize2(arg.content) });
1149
+ } else {
1150
+ camel = true;
1151
+ }
1152
+ }
1153
+ return {
1154
+ key: arg,
1155
+ value: exp,
1156
+ loc,
1157
+ runtimeCamelize: camel,
1158
+ modifier: modifiers.includes("prop") ? "." : modifiers.includes("attr") ? "^" : void 0
1159
+ };
1160
+ };
1161
+
1162
+ // src/transforms/vOn.ts
1163
+ import {
1164
+ ErrorCodes,
1165
+ createCompilerError,
1166
+ createSimpleExpression as createSimpleExpression3,
1167
+ resolveModifiers
1168
+ } from "@vue/compiler-dom";
1169
+ import { extend as extend4, makeMap as makeMap3 } from "@vue/shared";
1170
+ var delegatedEvents = /* @__PURE__ */ makeMap3(
1171
+ "beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart"
1172
+ );
1173
+ var transformVOn = (dir, node, context) => {
1174
+ const { name, loc, value } = dir;
1175
+ if (name.type === "JSXNamespacedName") return;
1176
+ const isComponent = isJSXComponent(node);
1177
+ const [nameString, ...modifiers] = name.name.replace(/^on([A-Z])/, (_, $1) => $1.toLowerCase()).split("_");
1178
+ if (!value && !modifiers.length) {
1179
+ context.options.onError(
1180
+ createCompilerError(
1181
+ ErrorCodes.X_V_ON_NO_EXPRESSION,
1182
+ resolveLocation(loc, context)
1183
+ )
1184
+ );
1185
+ }
1186
+ let arg = resolveSimpleExpression(nameString, true, dir.name.loc);
1187
+ const exp = resolveExpression(dir.value, context);
1188
+ const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(
1189
+ arg.isStatic ? `on${nameString}` : arg,
1190
+ modifiers.map((modifier) => createSimpleExpression3(modifier)),
1191
+ null,
1192
+ resolveLocation(loc, context)
1193
+ );
1194
+ let keyOverride;
1195
+ const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
1196
+ const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
1197
+ if (nonKeyModifiers.includes("middle")) {
1198
+ if (keyOverride) {
1199
+ }
1200
+ if (isStaticClick) {
1201
+ arg = extend4({}, arg, { content: "mouseup" });
1202
+ } else if (!arg.isStatic) {
1203
+ keyOverride = ["click", "mouseup"];
1204
+ }
1205
+ }
1206
+ if (nonKeyModifiers.includes("right")) {
1207
+ if (isStaticClick) {
1208
+ arg = extend4({}, arg, { content: "contextmenu" });
1209
+ } else if (!arg.isStatic) {
1210
+ keyOverride = ["click", "contextmenu"];
1211
+ }
1212
+ }
1213
+ if (isComponent) {
1214
+ const handler = exp || EMPTY_EXPRESSION;
1215
+ return {
1216
+ key: arg,
1217
+ value: handler,
1218
+ handler: true
1219
+ };
1220
+ }
1221
+ const operation = {
1222
+ type: 5 /* SET_EVENT */,
1223
+ element: context.reference(),
1224
+ key: arg,
1225
+ value: exp,
1226
+ modifiers: {
1227
+ keys: keyModifiers,
1228
+ nonKeys: nonKeyModifiers,
1229
+ options: eventOptionModifiers
1230
+ },
1231
+ keyOverride,
1232
+ delegate,
1233
+ effect: !arg.isStatic
1234
+ };
1235
+ context.registerEffect([arg], operation);
1236
+ };
1237
+
1238
+ // src/transforms/vSlot.ts
1239
+ var transformVSlot = (node, context) => {
1240
+ if (node.type !== "JSXElement") return;
1241
+ if (!isJSXComponent(node)) return;
1242
+ const { openingElement, children } = node;
1243
+ const vSlotsIndex = openingElement.attributes.findIndex(
1244
+ (attr) => attr.type === "JSXAttribute" && ["v-slots", "vSlots"].includes(attr.name.name.toString())
1245
+ );
1246
+ const vSlotsDir = openingElement.attributes[vSlotsIndex];
1247
+ if (vSlotsDir && vSlotsDir.value?.type === "JSXExpressionContainer") {
1248
+ node.openingElement.attributes.splice(vSlotsIndex, 1);
1249
+ context.slots = [
1250
+ {
1251
+ slotType: 4 /* EXPRESSION */,
1252
+ slots: resolveExpression(vSlotsDir.value.expression, context)
1253
+ }
1254
+ ];
1255
+ }
1256
+ if (children.length) {
1257
+ return transformComponentSlot(node, context);
1258
+ }
1259
+ };
1260
+ function transformComponentSlot(node, context) {
1261
+ const { children } = node;
1262
+ const nonWhitespaceChildren = children.filter(
1263
+ () => isNonWhitespaceContent(node)
1264
+ );
1265
+ const [block, onExit] = createSlotBlock(node, context);
1266
+ const { slots } = context;
1267
+ return () => {
1268
+ onExit();
1269
+ if (nonWhitespaceChildren.length) {
1270
+ registerSlot(slots, block);
1271
+ context.slots = slots;
1272
+ }
1273
+ };
1274
+ }
1275
+ function ensureStaticSlots(slots) {
1276
+ let lastSlots = slots.at(-1);
1277
+ if (!slots.length || lastSlots.slotType !== 0 /* STATIC */) {
1278
+ slots.push(
1279
+ lastSlots = {
1280
+ slotType: 0 /* STATIC */,
1281
+ slots: {}
1282
+ }
1283
+ );
1284
+ }
1285
+ return lastSlots;
1286
+ }
1287
+ function registerSlot(slots, block) {
1288
+ const staticSlots = ensureStaticSlots(slots);
1289
+ staticSlots.slots.default = block;
1290
+ }
1291
+ function createSlotBlock(slotNode, context) {
1292
+ const block = newBlock(slotNode);
1293
+ const exitBlock = context.enterBlock(block);
1294
+ return [block, exitBlock];
1295
+ }
1296
+ function isNonWhitespaceContent(node) {
1297
+ if (node.type !== "JSXText") return true;
1298
+ return !!node.value.trim();
1299
+ }
1300
+
1301
+ // src/transforms/vModel.ts
1302
+ import { transformVModel as _transformVModel } from "@vue/compiler-vapor";
1303
+ var transformVModel = (dir, node, context) => {
1304
+ return _transformVModel(
1305
+ resolveDirectiveNode(dir, context),
1306
+ resolveNode(node, context),
1307
+ context
1308
+ );
1309
+ };
1310
+
1311
+ // src/transforms/vShow.ts
1312
+ import { transformVShow as _transformVShow } from "@vue/compiler-vapor";
1313
+ var transformVShow = (dir, node, context) => {
1314
+ return _transformVShow(
1315
+ resolveDirectiveNode(dir, context),
1316
+ resolveNode(node, context),
1317
+ context
1318
+ );
1319
+ };
1320
+
1321
+ // src/transforms/vHtml.ts
1322
+ import { transformVHtml as _transformVHtml } from "@vue/compiler-vapor";
1323
+ var transformVHtml = (dir, node, context) => {
1324
+ return _transformVHtml(
1325
+ resolveDirectiveNode(dir, context),
1326
+ resolveNode(node, context),
1327
+ context
1328
+ );
1329
+ };
1330
+
1331
+ // src/compile.ts
1332
+ function compile(source, options = {}) {
1333
+ const onError = options.onError || defaultOnError2;
1334
+ const isModuleMode = options.mode === "module";
1335
+ const __BROWSER__3 = false;
1336
+ if (__BROWSER__3) {
1337
+ if (options.prefixIdentifiers === true) {
1338
+ onError(createCompilerError2(ErrorCodes2.X_PREFIX_ID_NOT_SUPPORTED));
1339
+ } else if (isModuleMode) {
1340
+ onError(createCompilerError2(ErrorCodes2.X_MODULE_MODE_NOT_SUPPORTED));
1341
+ }
1342
+ }
1343
+ const prefixIdentifiers = !__BROWSER__3 && options.prefixIdentifiers === true;
1344
+ if (options.scopeId && !isModuleMode) {
1345
+ onError(createCompilerError2(ErrorCodes2.X_SCOPE_ID_NOT_SUPPORTED));
1346
+ }
1347
+ const resolvedOptions = extend5({}, options, {
1348
+ prefixIdentifiers,
1349
+ expressionPlugins: options.expressionPlugins || ["jsx"]
1350
+ });
1351
+ if (!__BROWSER__3 && options.isTS) {
1352
+ const { expressionPlugins } = resolvedOptions;
1353
+ if (!expressionPlugins.includes("typescript")) {
1354
+ resolvedOptions.expressionPlugins = [
1355
+ ...expressionPlugins || [],
1356
+ "typescript"
1357
+ ];
1358
+ }
1359
+ }
1360
+ const {
1361
+ body: [statement]
1362
+ } = isString2(source) ? parse(source, {
1363
+ sourceType: "module",
1364
+ plugins: resolvedOptions.expressionPlugins
1365
+ }).program : source;
1366
+ let children;
1367
+ if (statement.type === "ExpressionStatement") {
1368
+ children = statement.expression.type === "JSXFragment" ? statement.expression.children : statement.expression.type === "JSXElement" ? [statement.expression] : [];
1369
+ }
1370
+ const ast = {
1371
+ type: 0 /* ROOT */,
1372
+ children,
1373
+ source: isString2(source) ? source : "",
1374
+ // TODO
1375
+ components: [],
1376
+ directives: [],
1377
+ helpers: /* @__PURE__ */ new Set(),
1378
+ temps: 0
1379
+ };
1380
+ const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(prefixIdentifiers);
1381
+ const ir = transform(
1382
+ ast,
1383
+ extend5({}, resolvedOptions, {
1384
+ nodeTransforms: [
1385
+ ...nodeTransforms,
1386
+ ...options.nodeTransforms || []
1387
+ // user transforms
1388
+ ],
1389
+ directiveTransforms: extend5(
1390
+ {},
1391
+ directiveTransforms,
1392
+ options.directiveTransforms || {}
1393
+ // user transforms
1394
+ )
1395
+ })
1396
+ );
1397
+ return generate(ir, resolvedOptions);
1398
+ }
1399
+ function getBaseTransformPreset(prefixIdentifiers) {
1400
+ return [
1401
+ [
1402
+ transformTemplateRef,
1403
+ transformText,
1404
+ transformElement,
1405
+ transformVSlot,
1406
+ transformChildren
1407
+ ],
1408
+ {
1409
+ bind: transformVBind,
1410
+ on: transformVOn,
1411
+ model: transformVModel,
1412
+ show: transformVShow,
1413
+ html: transformVHtml
1414
+ }
1415
+ ];
1416
+ }
1417
+ export {
1418
+ DynamicFlag2 as DynamicFlag,
1419
+ IRDynamicPropsKind,
1420
+ IRNodeTypes,
1421
+ IRSlotType,
1422
+ TransformContext,
1423
+ compile,
1424
+ generate2 as generate,
1425
+ resolveDirectiveNode,
1426
+ resolveNode,
1427
+ transform,
1428
+ transformChildren,
1429
+ transformElement,
1430
+ transformNode,
1431
+ transformTemplateRef,
1432
+ transformText,
1433
+ transformVBind,
1434
+ transformVHtml,
1435
+ transformVModel,
1436
+ transformVOn,
1437
+ transformVShow,
1438
+ transformVSlot
1439
+ };