@vue-jsx-vapor/compiler 0.1.6 → 0.2.1
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 +112 -305
- package/dist/index.d.cts +33 -41
- package/dist/index.d.ts +33 -41
- package/dist/index.js +119 -312
- package/package.json +7 -8
package/dist/index.js
CHANGED
@@ -1,17 +1,8 @@
|
|
1
|
-
// src/index.ts
|
2
|
-
import { generate as generate2 } from "@vue/compiler-vapor";
|
3
|
-
|
4
1
|
// 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";
|
2
|
+
import { extend as extend5 } from "@vue/shared";
|
11
3
|
import {
|
12
4
|
generate
|
13
5
|
} from "@vue/compiler-vapor";
|
14
|
-
import { parse } from "@babel/parser";
|
15
6
|
|
16
7
|
// src/transform.ts
|
17
8
|
import {
|
@@ -20,10 +11,53 @@ import {
|
|
20
11
|
} from "@vue/compiler-dom";
|
21
12
|
import { EMPTY_OBJ, NOOP, extend, isArray } from "@vue/shared";
|
22
13
|
|
14
|
+
// src/ir/component.ts
|
15
|
+
var IRDynamicPropsKind = /* @__PURE__ */ ((IRDynamicPropsKind2) => {
|
16
|
+
IRDynamicPropsKind2[IRDynamicPropsKind2["EXPRESSION"] = 0] = "EXPRESSION";
|
17
|
+
IRDynamicPropsKind2[IRDynamicPropsKind2["ATTRIBUTE"] = 1] = "ATTRIBUTE";
|
18
|
+
return IRDynamicPropsKind2;
|
19
|
+
})(IRDynamicPropsKind || {});
|
20
|
+
var IRSlotType = /* @__PURE__ */ ((IRSlotType2) => {
|
21
|
+
IRSlotType2[IRSlotType2["STATIC"] = 0] = "STATIC";
|
22
|
+
IRSlotType2[IRSlotType2["DYNAMIC"] = 1] = "DYNAMIC";
|
23
|
+
IRSlotType2[IRSlotType2["LOOP"] = 2] = "LOOP";
|
24
|
+
IRSlotType2[IRSlotType2["CONDITIONAL"] = 3] = "CONDITIONAL";
|
25
|
+
IRSlotType2[IRSlotType2["EXPRESSION"] = 4] = "EXPRESSION";
|
26
|
+
return IRSlotType2;
|
27
|
+
})(IRSlotType || {});
|
28
|
+
|
29
|
+
// src/ir/index.ts
|
30
|
+
var IRNodeTypes = /* @__PURE__ */ ((IRNodeTypes2) => {
|
31
|
+
IRNodeTypes2[IRNodeTypes2["ROOT"] = 0] = "ROOT";
|
32
|
+
IRNodeTypes2[IRNodeTypes2["BLOCK"] = 1] = "BLOCK";
|
33
|
+
IRNodeTypes2[IRNodeTypes2["SET_PROP"] = 2] = "SET_PROP";
|
34
|
+
IRNodeTypes2[IRNodeTypes2["SET_DYNAMIC_PROPS"] = 3] = "SET_DYNAMIC_PROPS";
|
35
|
+
IRNodeTypes2[IRNodeTypes2["SET_TEXT"] = 4] = "SET_TEXT";
|
36
|
+
IRNodeTypes2[IRNodeTypes2["SET_EVENT"] = 5] = "SET_EVENT";
|
37
|
+
IRNodeTypes2[IRNodeTypes2["SET_DYNAMIC_EVENTS"] = 6] = "SET_DYNAMIC_EVENTS";
|
38
|
+
IRNodeTypes2[IRNodeTypes2["SET_HTML"] = 7] = "SET_HTML";
|
39
|
+
IRNodeTypes2[IRNodeTypes2["SET_TEMPLATE_REF"] = 8] = "SET_TEMPLATE_REF";
|
40
|
+
IRNodeTypes2[IRNodeTypes2["INSERT_NODE"] = 9] = "INSERT_NODE";
|
41
|
+
IRNodeTypes2[IRNodeTypes2["PREPEND_NODE"] = 10] = "PREPEND_NODE";
|
42
|
+
IRNodeTypes2[IRNodeTypes2["CREATE_TEXT_NODE"] = 11] = "CREATE_TEXT_NODE";
|
43
|
+
IRNodeTypes2[IRNodeTypes2["CREATE_COMPONENT_NODE"] = 12] = "CREATE_COMPONENT_NODE";
|
44
|
+
IRNodeTypes2[IRNodeTypes2["SLOT_OUTLET_NODE"] = 13] = "SLOT_OUTLET_NODE";
|
45
|
+
IRNodeTypes2[IRNodeTypes2["DIRECTIVE"] = 14] = "DIRECTIVE";
|
46
|
+
IRNodeTypes2[IRNodeTypes2["DECLARE_OLD_REF"] = 15] = "DECLARE_OLD_REF";
|
47
|
+
IRNodeTypes2[IRNodeTypes2["IF"] = 16] = "IF";
|
48
|
+
IRNodeTypes2[IRNodeTypes2["FOR"] = 17] = "FOR";
|
49
|
+
IRNodeTypes2[IRNodeTypes2["GET_TEXT_CHILD"] = 18] = "GET_TEXT_CHILD";
|
50
|
+
return IRNodeTypes2;
|
51
|
+
})(IRNodeTypes || {});
|
52
|
+
var DynamicFlag = /* @__PURE__ */ ((DynamicFlag2) => {
|
53
|
+
DynamicFlag2[DynamicFlag2["NONE"] = 0] = "NONE";
|
54
|
+
DynamicFlag2[DynamicFlag2["REFERENCED"] = 1] = "REFERENCED";
|
55
|
+
DynamicFlag2[DynamicFlag2["NON_TEMPLATE"] = 2] = "NON_TEMPLATE";
|
56
|
+
DynamicFlag2[DynamicFlag2["INSERT"] = 4] = "INSERT";
|
57
|
+
return DynamicFlag2;
|
58
|
+
})(DynamicFlag || {});
|
59
|
+
|
23
60
|
// src/transforms/utils.ts
|
24
|
-
import {
|
25
|
-
DynamicFlag
|
26
|
-
} from "@vue/compiler-vapor";
|
27
61
|
import { createSimpleExpression as createSimpleExpression2 } from "@vue/compiler-dom";
|
28
62
|
import {
|
29
63
|
arrowFunctionExpression,
|
@@ -36,23 +70,23 @@ import {
|
|
36
70
|
} from "@babel/types";
|
37
71
|
|
38
72
|
// src/utils.ts
|
39
|
-
import { isGloballyAllowed,
|
73
|
+
import { isGloballyAllowed, isHTMLTag, isSVGTag, isString } from "@vue/shared";
|
40
74
|
import {
|
41
75
|
ElementTypes,
|
42
76
|
Namespaces,
|
43
77
|
NodeTypes,
|
44
78
|
createSimpleExpression,
|
45
|
-
isLiteralWhitelisted
|
79
|
+
isLiteralWhitelisted,
|
80
|
+
walkIdentifiers
|
46
81
|
} from "@vue/compiler-dom";
|
47
82
|
import {
|
48
83
|
isLiteral
|
49
84
|
} from "@babel/types";
|
50
|
-
var __BROWSER__ = false;
|
51
85
|
function isConstantExpression(exp) {
|
52
86
|
return isLiteralWhitelisted(exp.content) || isGloballyAllowed(exp.content) || getLiteralExpressionValue(exp) !== null;
|
53
87
|
}
|
54
88
|
function getLiteralExpressionValue(exp) {
|
55
|
-
if (
|
89
|
+
if (exp.ast) {
|
56
90
|
if (["StringLiteral", "NumericLiteral", "BigIntLiteral"].includes(
|
57
91
|
exp.ast.type
|
58
92
|
)) {
|
@@ -106,11 +140,26 @@ function resolveExpression(node, context, effect = false) {
|
|
106
140
|
const isStatic = !!node && (node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier");
|
107
141
|
let source = !node || node.type === "JSXEmptyExpression" ? "" : node.type === "JSXIdentifier" ? node.name : node.type === "StringLiteral" ? node.value : node.type === "JSXText" ? resolveJSXText(node) : node.type === "Identifier" ? node.name : context.ir.source.slice(node.start, node.end);
|
108
142
|
const location = node ? node.loc : null;
|
109
|
-
let ast;
|
110
143
|
if (source && !isStatic && effect && !isConstant(node)) {
|
111
144
|
source = `() => (${source})`;
|
145
|
+
if (location && node) {
|
146
|
+
location.start.column -= 7;
|
147
|
+
node.start -= 7;
|
148
|
+
}
|
149
|
+
}
|
150
|
+
if (node) {
|
151
|
+
const offset = node.start - 1;
|
152
|
+
walkIdentifiers(
|
153
|
+
node,
|
154
|
+
(id) => {
|
155
|
+
if (!id.loc) return;
|
156
|
+
id.start = id.loc.start.index - offset;
|
157
|
+
id.end = id.loc.end.index - offset;
|
158
|
+
},
|
159
|
+
true
|
160
|
+
);
|
112
161
|
}
|
113
|
-
return resolveSimpleExpression(source, isStatic, location,
|
162
|
+
return resolveSimpleExpression(source, isStatic, location, node);
|
114
163
|
}
|
115
164
|
function resolveSimpleExpression(source, isStatic, location, ast) {
|
116
165
|
const result = createSimpleExpression(
|
@@ -202,18 +251,12 @@ function resolveDirectiveNode(node, context) {
|
|
202
251
|
modifiers: modifiers.map((modifier) => createSimpleExpression(modifier))
|
203
252
|
};
|
204
253
|
}
|
205
|
-
var isHtmlTags = makeMap(
|
206
|
-
"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"
|
207
|
-
);
|
208
|
-
var isSvgTags = makeMap(
|
209
|
-
"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"
|
210
|
-
);
|
211
254
|
function isJSXComponent(node) {
|
212
255
|
if (node.type !== "JSXElement") return false;
|
213
256
|
const { openingElement } = node;
|
214
257
|
if (openingElement.name.type === "JSXIdentifier") {
|
215
258
|
const name = openingElement.name.name;
|
216
|
-
return !
|
259
|
+
return !isHTMLTag(name) && !isSVGTag(name);
|
217
260
|
} else {
|
218
261
|
return openingElement.name.type === "JSXMemberExpression";
|
219
262
|
}
|
@@ -234,7 +277,7 @@ function isJSXElement(node) {
|
|
234
277
|
// src/transforms/utils.ts
|
235
278
|
function newDynamic() {
|
236
279
|
return {
|
237
|
-
flags:
|
280
|
+
flags: 1 /* REFERENCED */,
|
238
281
|
children: []
|
239
282
|
};
|
240
283
|
}
|
@@ -245,7 +288,9 @@ function newBlock(node) {
|
|
245
288
|
dynamic: newDynamic(),
|
246
289
|
effect: [],
|
247
290
|
operation: [],
|
248
|
-
returns: []
|
291
|
+
returns: [],
|
292
|
+
expressions: [],
|
293
|
+
tempId: 0
|
249
294
|
};
|
250
295
|
}
|
251
296
|
function createBranch(node, context, isVFor) {
|
@@ -281,53 +326,6 @@ function wrapFragment(node, isVFor) {
|
|
281
326
|
}
|
282
327
|
var EMPTY_EXPRESSION = createSimpleExpression2("", true);
|
283
328
|
|
284
|
-
// src/ir/component.ts
|
285
|
-
var IRDynamicPropsKind = /* @__PURE__ */ ((IRDynamicPropsKind2) => {
|
286
|
-
IRDynamicPropsKind2[IRDynamicPropsKind2["EXPRESSION"] = 0] = "EXPRESSION";
|
287
|
-
IRDynamicPropsKind2[IRDynamicPropsKind2["ATTRIBUTE"] = 1] = "ATTRIBUTE";
|
288
|
-
return IRDynamicPropsKind2;
|
289
|
-
})(IRDynamicPropsKind || {});
|
290
|
-
var IRSlotType = /* @__PURE__ */ ((IRSlotType2) => {
|
291
|
-
IRSlotType2[IRSlotType2["STATIC"] = 0] = "STATIC";
|
292
|
-
IRSlotType2[IRSlotType2["DYNAMIC"] = 1] = "DYNAMIC";
|
293
|
-
IRSlotType2[IRSlotType2["LOOP"] = 2] = "LOOP";
|
294
|
-
IRSlotType2[IRSlotType2["CONDITIONAL"] = 3] = "CONDITIONAL";
|
295
|
-
IRSlotType2[IRSlotType2["EXPRESSION"] = 4] = "EXPRESSION";
|
296
|
-
return IRSlotType2;
|
297
|
-
})(IRSlotType || {});
|
298
|
-
|
299
|
-
// src/ir/index.ts
|
300
|
-
var IRNodeTypes = /* @__PURE__ */ ((IRNodeTypes2) => {
|
301
|
-
IRNodeTypes2[IRNodeTypes2["ROOT"] = 0] = "ROOT";
|
302
|
-
IRNodeTypes2[IRNodeTypes2["BLOCK"] = 1] = "BLOCK";
|
303
|
-
IRNodeTypes2[IRNodeTypes2["SET_PROP"] = 2] = "SET_PROP";
|
304
|
-
IRNodeTypes2[IRNodeTypes2["SET_DYNAMIC_PROPS"] = 3] = "SET_DYNAMIC_PROPS";
|
305
|
-
IRNodeTypes2[IRNodeTypes2["SET_TEXT"] = 4] = "SET_TEXT";
|
306
|
-
IRNodeTypes2[IRNodeTypes2["SET_EVENT"] = 5] = "SET_EVENT";
|
307
|
-
IRNodeTypes2[IRNodeTypes2["SET_DYNAMIC_EVENTS"] = 6] = "SET_DYNAMIC_EVENTS";
|
308
|
-
IRNodeTypes2[IRNodeTypes2["SET_HTML"] = 7] = "SET_HTML";
|
309
|
-
IRNodeTypes2[IRNodeTypes2["SET_TEMPLATE_REF"] = 8] = "SET_TEMPLATE_REF";
|
310
|
-
IRNodeTypes2[IRNodeTypes2["SET_MODEL_VALUE"] = 9] = "SET_MODEL_VALUE";
|
311
|
-
IRNodeTypes2[IRNodeTypes2["SET_INHERIT_ATTRS"] = 10] = "SET_INHERIT_ATTRS";
|
312
|
-
IRNodeTypes2[IRNodeTypes2["INSERT_NODE"] = 11] = "INSERT_NODE";
|
313
|
-
IRNodeTypes2[IRNodeTypes2["PREPEND_NODE"] = 12] = "PREPEND_NODE";
|
314
|
-
IRNodeTypes2[IRNodeTypes2["CREATE_TEXT_NODE"] = 13] = "CREATE_TEXT_NODE";
|
315
|
-
IRNodeTypes2[IRNodeTypes2["CREATE_COMPONENT_NODE"] = 14] = "CREATE_COMPONENT_NODE";
|
316
|
-
IRNodeTypes2[IRNodeTypes2["SLOT_OUTLET_NODE"] = 15] = "SLOT_OUTLET_NODE";
|
317
|
-
IRNodeTypes2[IRNodeTypes2["WITH_DIRECTIVE"] = 16] = "WITH_DIRECTIVE";
|
318
|
-
IRNodeTypes2[IRNodeTypes2["DECLARE_OLD_REF"] = 17] = "DECLARE_OLD_REF";
|
319
|
-
IRNodeTypes2[IRNodeTypes2["IF"] = 18] = "IF";
|
320
|
-
IRNodeTypes2[IRNodeTypes2["FOR"] = 19] = "FOR";
|
321
|
-
return IRNodeTypes2;
|
322
|
-
})(IRNodeTypes || {});
|
323
|
-
var DynamicFlag2 = /* @__PURE__ */ ((DynamicFlag3) => {
|
324
|
-
DynamicFlag3[DynamicFlag3["NONE"] = 0] = "NONE";
|
325
|
-
DynamicFlag3[DynamicFlag3["REFERENCED"] = 1] = "REFERENCED";
|
326
|
-
DynamicFlag3[DynamicFlag3["NON_TEMPLATE"] = 2] = "NON_TEMPLATE";
|
327
|
-
DynamicFlag3[DynamicFlag3["INSERT"] = 4] = "INSERT";
|
328
|
-
return DynamicFlag3;
|
329
|
-
})(DynamicFlag2 || {});
|
330
|
-
|
331
329
|
// src/transform.ts
|
332
330
|
var defaultOptions = {
|
333
331
|
filename: "",
|
@@ -450,7 +448,8 @@ function transform(node, options = {}) {
|
|
450
448
|
template: [],
|
451
449
|
component: /* @__PURE__ */ new Set(),
|
452
450
|
directive: /* @__PURE__ */ new Set(),
|
453
|
-
block: newBlock(node)
|
451
|
+
block: newBlock(node),
|
452
|
+
hasTemplateRef: false
|
454
453
|
};
|
455
454
|
const context = new TransformContext(ir, node, options);
|
456
455
|
transformNode(context);
|
@@ -486,180 +485,14 @@ function transformNode(context) {
|
|
486
485
|
}
|
487
486
|
|
488
487
|
// src/transforms/transformElement.ts
|
489
|
-
import { extend as extend2, isBuiltInDirective, isVoidTag, makeMap
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
return onlyValidChildren[parent].has(child);
|
495
|
-
}
|
496
|
-
if (child in onlyValidParents) {
|
497
|
-
return onlyValidParents[child].has(parent);
|
498
|
-
}
|
499
|
-
if (parent in knownInvalidChildren && // check if the child is in the list of invalid children
|
500
|
-
// if so, return false
|
501
|
-
knownInvalidChildren[parent].has(child))
|
502
|
-
return false;
|
503
|
-
if (child in knownInvalidParents && // check if the parent is in the list of invalid parents
|
504
|
-
// if so, return false
|
505
|
-
knownInvalidParents[child].has(parent))
|
506
|
-
return false;
|
507
|
-
return true;
|
508
|
-
}
|
509
|
-
var headings = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
|
510
|
-
var emptySet = /* @__PURE__ */ new Set([]);
|
511
|
-
var onlyValidChildren = {
|
512
|
-
head: /* @__PURE__ */ new Set([
|
513
|
-
"base",
|
514
|
-
"basefront",
|
515
|
-
"bgsound",
|
516
|
-
"link",
|
517
|
-
"meta",
|
518
|
-
"title",
|
519
|
-
"noscript",
|
520
|
-
"noframes",
|
521
|
-
"style",
|
522
|
-
"script",
|
523
|
-
"template"
|
524
|
-
]),
|
525
|
-
optgroup: /* @__PURE__ */ new Set(["option"]),
|
526
|
-
select: /* @__PURE__ */ new Set(["optgroup", "option"]),
|
527
|
-
math: /* @__PURE__ */ new Set(["mrow"]),
|
528
|
-
script: /* @__PURE__ */ new Set(),
|
529
|
-
// table
|
530
|
-
table: /* @__PURE__ */ new Set(["caption", "colgroup", "tbody", "tfoot", "thead"]),
|
531
|
-
tr: /* @__PURE__ */ new Set(["td", "th"]),
|
532
|
-
colgroup: /* @__PURE__ */ new Set(["col"]),
|
533
|
-
tbody: /* @__PURE__ */ new Set(["tr"]),
|
534
|
-
thead: /* @__PURE__ */ new Set(["tr"]),
|
535
|
-
tfoot: /* @__PURE__ */ new Set(["tr"]),
|
536
|
-
// these elements can not have any children elements
|
537
|
-
iframe: emptySet,
|
538
|
-
option: emptySet,
|
539
|
-
textarea: emptySet,
|
540
|
-
style: emptySet,
|
541
|
-
title: emptySet
|
542
|
-
};
|
543
|
-
var onlyValidParents = {
|
544
|
-
// sections
|
545
|
-
html: emptySet,
|
546
|
-
body: /* @__PURE__ */ new Set(["html"]),
|
547
|
-
head: /* @__PURE__ */ new Set(["html"]),
|
548
|
-
// table
|
549
|
-
td: /* @__PURE__ */ new Set(["tr"]),
|
550
|
-
colgroup: /* @__PURE__ */ new Set(["table"]),
|
551
|
-
caption: /* @__PURE__ */ new Set(["table"]),
|
552
|
-
tbody: /* @__PURE__ */ new Set(["table"]),
|
553
|
-
tfoot: /* @__PURE__ */ new Set(["table"]),
|
554
|
-
col: /* @__PURE__ */ new Set(["colgroup"]),
|
555
|
-
th: /* @__PURE__ */ new Set(["tr"]),
|
556
|
-
thead: /* @__PURE__ */ new Set(["table"]),
|
557
|
-
tr: /* @__PURE__ */ new Set(["tbody", "thead", "tfoot"]),
|
558
|
-
// data list
|
559
|
-
dd: /* @__PURE__ */ new Set(["dl", "div"]),
|
560
|
-
dt: /* @__PURE__ */ new Set(["dl", "div"]),
|
561
|
-
// other
|
562
|
-
figcaption: /* @__PURE__ */ new Set(["figure"]),
|
563
|
-
// li: new Set(["ul", "ol"]),
|
564
|
-
summary: /* @__PURE__ */ new Set(["details"]),
|
565
|
-
area: /* @__PURE__ */ new Set(["map"])
|
566
|
-
};
|
567
|
-
var knownInvalidChildren = {
|
568
|
-
p: /* @__PURE__ */ new Set([
|
569
|
-
"address",
|
570
|
-
"article",
|
571
|
-
"aside",
|
572
|
-
"blockquote",
|
573
|
-
"center",
|
574
|
-
"details",
|
575
|
-
"dialog",
|
576
|
-
"dir",
|
577
|
-
"div",
|
578
|
-
"dl",
|
579
|
-
"fieldset",
|
580
|
-
"figure",
|
581
|
-
"footer",
|
582
|
-
"form",
|
583
|
-
"h1",
|
584
|
-
"h2",
|
585
|
-
"h3",
|
586
|
-
"h4",
|
587
|
-
"h5",
|
588
|
-
"h6",
|
589
|
-
"header",
|
590
|
-
"hgroup",
|
591
|
-
"hr",
|
592
|
-
"li",
|
593
|
-
"main",
|
594
|
-
"nav",
|
595
|
-
"menu",
|
596
|
-
"ol",
|
597
|
-
"p",
|
598
|
-
"pre",
|
599
|
-
"section",
|
600
|
-
"table",
|
601
|
-
"ul"
|
602
|
-
]),
|
603
|
-
svg: /* @__PURE__ */ new Set([
|
604
|
-
"b",
|
605
|
-
"blockquote",
|
606
|
-
"br",
|
607
|
-
"code",
|
608
|
-
"dd",
|
609
|
-
"div",
|
610
|
-
"dl",
|
611
|
-
"dt",
|
612
|
-
"em",
|
613
|
-
"embed",
|
614
|
-
"h1",
|
615
|
-
"h2",
|
616
|
-
"h3",
|
617
|
-
"h4",
|
618
|
-
"h5",
|
619
|
-
"h6",
|
620
|
-
"hr",
|
621
|
-
"i",
|
622
|
-
"img",
|
623
|
-
"li",
|
624
|
-
"menu",
|
625
|
-
"meta",
|
626
|
-
"ol",
|
627
|
-
"p",
|
628
|
-
"pre",
|
629
|
-
"ruby",
|
630
|
-
"s",
|
631
|
-
"small",
|
632
|
-
"span",
|
633
|
-
"strong",
|
634
|
-
"sub",
|
635
|
-
"sup",
|
636
|
-
"table",
|
637
|
-
"u",
|
638
|
-
"ul",
|
639
|
-
"var"
|
640
|
-
])
|
641
|
-
};
|
642
|
-
var knownInvalidParents = {
|
643
|
-
a: /* @__PURE__ */ new Set(["a"]),
|
644
|
-
button: /* @__PURE__ */ new Set(["button"]),
|
645
|
-
dd: /* @__PURE__ */ new Set(["dd", "dt"]),
|
646
|
-
dt: /* @__PURE__ */ new Set(["dd", "dt"]),
|
647
|
-
form: /* @__PURE__ */ new Set(["form"]),
|
648
|
-
li: /* @__PURE__ */ new Set(["li"]),
|
649
|
-
h1: headings,
|
650
|
-
h2: headings,
|
651
|
-
h3: headings,
|
652
|
-
h4: headings,
|
653
|
-
h5: headings,
|
654
|
-
h6: headings
|
655
|
-
};
|
656
|
-
|
657
|
-
// src/transforms/transformElement.ts
|
658
|
-
var isReservedProp = /* @__PURE__ */ makeMap2(
|
488
|
+
import { extend as extend2, isBuiltInDirective, isVoidTag, makeMap } from "@vue/shared";
|
489
|
+
import {
|
490
|
+
isValidHTMLNesting
|
491
|
+
} from "@vue/compiler-dom";
|
492
|
+
var isReservedProp = /* @__PURE__ */ makeMap(
|
659
493
|
// the leading comma is intentional so empty string "" is also included
|
660
494
|
",key,ref,ref_for,ref_key,"
|
661
495
|
);
|
662
|
-
var __BROWSER__2 = false;
|
663
496
|
var isEventRegex = /^on[A-Z]/;
|
664
497
|
var isDirectiveRegex = /^v-[a-z]/;
|
665
498
|
var transformElement = (node, context) => {
|
@@ -688,27 +521,25 @@ var transformElement = (node, context) => {
|
|
688
521
|
};
|
689
522
|
function transformComponentElement(tag, propsResult, singleRoot, context) {
|
690
523
|
let asset = true;
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
524
|
+
const fromSetup = tag;
|
525
|
+
if (fromSetup) {
|
526
|
+
tag = fromSetup;
|
527
|
+
asset = false;
|
528
|
+
}
|
529
|
+
const dotIndex = tag.indexOf(".");
|
530
|
+
if (dotIndex > 0) {
|
531
|
+
const ns = tag.slice(0, dotIndex);
|
532
|
+
if (ns) {
|
533
|
+
tag = ns + tag.slice(dotIndex);
|
695
534
|
asset = false;
|
696
535
|
}
|
697
|
-
const dotIndex = tag.indexOf(".");
|
698
|
-
if (dotIndex > 0) {
|
699
|
-
const ns = tag.slice(0, dotIndex);
|
700
|
-
if (ns) {
|
701
|
-
tag = ns + tag.slice(dotIndex);
|
702
|
-
asset = false;
|
703
|
-
}
|
704
|
-
}
|
705
536
|
}
|
706
537
|
if (asset) {
|
707
538
|
context.component.add(tag);
|
708
539
|
}
|
709
540
|
context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
|
710
541
|
context.registerOperation({
|
711
|
-
type:
|
542
|
+
type: 12 /* CREATE_COMPONENT_NODE */,
|
712
543
|
id: context.reference(),
|
713
544
|
tag,
|
714
545
|
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
|
@@ -724,7 +555,6 @@ function transformNativeElement(tag, propsResult, singleRoot, context) {
|
|
724
555
|
let template = "";
|
725
556
|
template += `<${tag}`;
|
726
557
|
if (scopeId) template += ` ${scopeId}`;
|
727
|
-
let staticProps = false;
|
728
558
|
const dynamicProps = [];
|
729
559
|
if (propsResult[0]) {
|
730
560
|
const [, dynamicArgs, expressions] = propsResult;
|
@@ -738,7 +568,6 @@ function transformNativeElement(tag, propsResult, singleRoot, context) {
|
|
738
568
|
for (const prop of propsResult[1]) {
|
739
569
|
const { key, values } = prop;
|
740
570
|
if (key.isStatic && values.length === 1 && values[0].isStatic) {
|
741
|
-
staticProps = true;
|
742
571
|
template += ` ${key.content}`;
|
743
572
|
if (values[0].content) template += `="${values[0].content}"`;
|
744
573
|
} else {
|
@@ -753,17 +582,13 @@ function transformNativeElement(tag, propsResult, singleRoot, context) {
|
|
753
582
|
}
|
754
583
|
}
|
755
584
|
}
|
756
|
-
if (singleRoot) {
|
757
|
-
context.registerOperation({
|
758
|
-
type: 10 /* SET_INHERIT_ATTRS */,
|
759
|
-
staticProps,
|
760
|
-
dynamicProps: propsResult[0] ? true : dynamicProps
|
761
|
-
});
|
762
|
-
}
|
763
585
|
template += `>${context.childrenTemplate.join("")}`;
|
764
586
|
if (!isVoidTag(tag)) {
|
765
587
|
template += `</${tag}>`;
|
766
588
|
}
|
589
|
+
if (singleRoot) {
|
590
|
+
context.ir.rootTemplateIndex = context.ir.template.length;
|
591
|
+
}
|
767
592
|
if (context.parent && context.parent.node.type === "JSXElement" && context.parent.node.openingElement.name.type === "JSXIdentifier" && !isValidHTMLNesting(context.parent.node.openingElement.name.name, tag)) {
|
768
593
|
context.reference();
|
769
594
|
context.dynamic.template = context.pushTemplate(template);
|
@@ -833,7 +658,7 @@ function transformProp(prop, node, context) {
|
|
833
658
|
return directiveTransform(prop, node, context);
|
834
659
|
}
|
835
660
|
if (!isBuiltInDirective(name)) {
|
836
|
-
const fromSetup =
|
661
|
+
const fromSetup = `v-${name}`;
|
837
662
|
if (fromSetup) {
|
838
663
|
name = fromSetup;
|
839
664
|
} else {
|
@@ -911,14 +736,14 @@ function processDynamicChildren(context) {
|
|
911
736
|
prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
|
912
737
|
const anchor = prevDynamics[0].anchor = context.increaseId();
|
913
738
|
context.registerOperation({
|
914
|
-
type:
|
739
|
+
type: 9 /* INSERT_NODE */,
|
915
740
|
elements: prevDynamics.map((child2) => child2.id),
|
916
741
|
parent: context.reference(),
|
917
742
|
anchor
|
918
743
|
});
|
919
744
|
} else {
|
920
745
|
context.registerOperation({
|
921
|
-
type:
|
746
|
+
type: 10 /* PREPEND_NODE */,
|
922
747
|
elements: prevDynamics.map((child2) => child2.id),
|
923
748
|
parent: context.reference()
|
924
749
|
});
|
@@ -930,7 +755,7 @@ function processDynamicChildren(context) {
|
|
930
755
|
}
|
931
756
|
if (prevDynamics.length) {
|
932
757
|
context.registerOperation({
|
933
|
-
type:
|
758
|
+
type: 9 /* INSERT_NODE */,
|
934
759
|
elements: prevDynamics.map((child) => child.id),
|
935
760
|
parent: context.reference()
|
936
761
|
});
|
@@ -942,12 +767,13 @@ var transformTemplateRef = (node, context) => {
|
|
942
767
|
if (node.type !== "JSXElement") return;
|
943
768
|
const dir = findProp(node, "ref");
|
944
769
|
if (!dir?.value) return;
|
770
|
+
context.ir.hasTemplateRef = true;
|
945
771
|
const value = resolveExpression(dir.value, context);
|
946
772
|
return () => {
|
947
773
|
const id = context.reference();
|
948
774
|
const effect = !isConstantExpression(value);
|
949
775
|
effect && context.registerOperation({
|
950
|
-
type:
|
776
|
+
type: 15 /* DECLARE_OLD_REF */,
|
951
777
|
id
|
952
778
|
});
|
953
779
|
context.registerEffect([value], {
|
@@ -961,6 +787,7 @@ var transformTemplateRef = (node, context) => {
|
|
961
787
|
};
|
962
788
|
|
963
789
|
// src/transforms/vIf.ts
|
790
|
+
import { isStaticNode } from "@vue/compiler-dom";
|
964
791
|
function processConditionalExpression(node, context) {
|
965
792
|
const { test, consequent, alternate } = node;
|
966
793
|
context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
|
@@ -968,11 +795,11 @@ function processConditionalExpression(node, context) {
|
|
968
795
|
const condition = resolveExpression(test, context);
|
969
796
|
const [branch, onExit] = createBranch(consequent, context);
|
970
797
|
const operation = {
|
971
|
-
type:
|
798
|
+
type: 16 /* IF */,
|
972
799
|
id,
|
973
800
|
condition,
|
974
801
|
positive: branch,
|
975
|
-
once: context.inVOnce
|
802
|
+
once: context.inVOnce || isStaticNode(test)
|
976
803
|
};
|
977
804
|
return [
|
978
805
|
() => {
|
@@ -998,7 +825,7 @@ function processLogicalExpression(node, context) {
|
|
998
825
|
context
|
999
826
|
);
|
1000
827
|
const operation = {
|
1001
|
-
type:
|
828
|
+
type: 16 /* IF */,
|
1002
829
|
id,
|
1003
830
|
condition,
|
1004
831
|
positive: branch,
|
@@ -1057,10 +884,10 @@ function processTextLike(context) {
|
|
1057
884
|
const nodes = idx > -1 ? nexts.slice(0, idx) : nexts;
|
1058
885
|
context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
|
1059
886
|
context.registerOperation({
|
1060
|
-
type:
|
887
|
+
type: 11 /* CREATE_TEXT_NODE */,
|
1061
888
|
id: context.reference(),
|
1062
889
|
values: createTextLikeExpressions(nodes, context),
|
1063
|
-
|
890
|
+
jsx: true
|
1064
891
|
});
|
1065
892
|
}
|
1066
893
|
function processTextLikeContainer(children, context) {
|
@@ -1072,7 +899,8 @@ function processTextLikeContainer(children, context) {
|
|
1072
899
|
context.registerOperation({
|
1073
900
|
type: 4 /* SET_TEXT */,
|
1074
901
|
element: context.reference(),
|
1075
|
-
values
|
902
|
+
values,
|
903
|
+
jsx: true
|
1076
904
|
});
|
1077
905
|
}
|
1078
906
|
}
|
@@ -1126,8 +954,8 @@ import {
|
|
1126
954
|
createSimpleExpression as createSimpleExpression3,
|
1127
955
|
resolveModifiers
|
1128
956
|
} from "@vue/compiler-dom";
|
1129
|
-
import { extend as extend4, makeMap as
|
1130
|
-
var delegatedEvents = /* @__PURE__ */
|
957
|
+
import { extend as extend4, makeMap as makeMap2 } from "@vue/shared";
|
958
|
+
var delegatedEvents = /* @__PURE__ */ makeMap2(
|
1131
959
|
"beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart"
|
1132
960
|
);
|
1133
961
|
var transformVOn = (dir, node, context) => {
|
@@ -1153,7 +981,6 @@ var transformVOn = (dir, node, context) => {
|
|
1153
981
|
);
|
1154
982
|
let keyOverride;
|
1155
983
|
const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
|
1156
|
-
const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
|
1157
984
|
if (nonKeyModifiers.includes("middle")) {
|
1158
985
|
if (keyOverride) {
|
1159
986
|
}
|
@@ -1175,9 +1002,11 @@ var transformVOn = (dir, node, context) => {
|
|
1175
1002
|
return {
|
1176
1003
|
key: arg,
|
1177
1004
|
value: handler,
|
1178
|
-
handler: true
|
1005
|
+
handler: true,
|
1006
|
+
handlerModifiers: eventOptionModifiers
|
1179
1007
|
};
|
1180
1008
|
}
|
1009
|
+
const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
|
1181
1010
|
const operation = {
|
1182
1011
|
type: 5 /* SET_EVENT */,
|
1183
1012
|
element: context.reference(),
|
@@ -1289,13 +1118,9 @@ var transformVHtml = (dir, node, context) => {
|
|
1289
1118
|
};
|
1290
1119
|
|
1291
1120
|
// src/compile.ts
|
1292
|
-
function compile(
|
1293
|
-
const onError = options.onError || defaultOnError2;
|
1294
|
-
const isModuleMode = options.mode === "module";
|
1295
|
-
if (options.scopeId && !isModuleMode) {
|
1296
|
-
onError(createCompilerError2(ErrorCodes2.X_SCOPE_ID_NOT_SUPPORTED));
|
1297
|
-
}
|
1121
|
+
function compile(root, options = {}) {
|
1298
1122
|
const resolvedOptions = extend5({}, options, {
|
1123
|
+
inline: true,
|
1299
1124
|
prefixIdentifiers: false,
|
1300
1125
|
expressionPlugins: options.expressionPlugins || ["jsx"]
|
1301
1126
|
});
|
@@ -1308,29 +1133,11 @@ function compile(source, options = {}) {
|
|
1308
1133
|
];
|
1309
1134
|
}
|
1310
1135
|
}
|
1311
|
-
|
1312
|
-
if (isString2(source)) {
|
1313
|
-
const {
|
1314
|
-
body: [statement]
|
1315
|
-
} = parse(source, {
|
1316
|
-
sourceType: "module",
|
1317
|
-
plugins: resolvedOptions.expressionPlugins
|
1318
|
-
}).program;
|
1319
|
-
if (statement.type === "ExpressionStatement") {
|
1320
|
-
expression = statement.expression;
|
1321
|
-
}
|
1322
|
-
} else {
|
1323
|
-
expression = source;
|
1324
|
-
}
|
1325
|
-
const children = expression.type === "JSXFragment" ? expression.children : expression.type === "JSXElement" ? [expression] : [];
|
1136
|
+
const children = root.type === "JSXFragment" ? root.children : root.type === "JSXElement" ? [root] : [];
|
1326
1137
|
const ast = {
|
1327
1138
|
type: 0 /* ROOT */,
|
1328
1139
|
children,
|
1329
|
-
source:
|
1330
|
-
components: [],
|
1331
|
-
directives: [],
|
1332
|
-
helpers: /* @__PURE__ */ new Set(),
|
1333
|
-
temps: 0
|
1140
|
+
source: options.source || ""
|
1334
1141
|
};
|
1335
1142
|
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
|
1336
1143
|
const ir = transform(
|
@@ -1370,13 +1177,13 @@ function getBaseTransformPreset() {
|
|
1370
1177
|
];
|
1371
1178
|
}
|
1372
1179
|
export {
|
1373
|
-
|
1180
|
+
DynamicFlag,
|
1374
1181
|
IRDynamicPropsKind,
|
1375
1182
|
IRNodeTypes,
|
1376
1183
|
IRSlotType,
|
1377
1184
|
TransformContext,
|
1378
1185
|
compile,
|
1379
|
-
|
1186
|
+
generate,
|
1380
1187
|
resolveDirectiveNode,
|
1381
1188
|
resolveNode,
|
1382
1189
|
transform,
|