@vue-jsx-vapor/compiler 2.0.0 → 2.1.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.cjs +173 -63
- package/dist/index.d.cts +27 -16
- package/dist/index.d.ts +27 -16
- package/dist/index.js +171 -61
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
@@ -5,6 +5,13 @@ var _parser = require('@babel/parser');
|
|
5
5
|
var _compilervapor = require('@vue/compiler-vapor');
|
6
6
|
var _shared = require('@vue/shared');
|
7
7
|
|
8
|
+
// src/generate.ts
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
8
15
|
// src/ir/component.ts
|
9
16
|
var IRDynamicPropsKind = /* @__PURE__ */ ((IRDynamicPropsKind2) => {
|
10
17
|
IRDynamicPropsKind2[IRDynamicPropsKind2["EXPRESSION"] = 0] = "EXPRESSION";
|
@@ -33,14 +40,15 @@ var IRNodeTypes = /* @__PURE__ */ ((IRNodeTypes2) => {
|
|
33
40
|
IRNodeTypes2[IRNodeTypes2["SET_TEMPLATE_REF"] = 8] = "SET_TEMPLATE_REF";
|
34
41
|
IRNodeTypes2[IRNodeTypes2["INSERT_NODE"] = 9] = "INSERT_NODE";
|
35
42
|
IRNodeTypes2[IRNodeTypes2["PREPEND_NODE"] = 10] = "PREPEND_NODE";
|
36
|
-
IRNodeTypes2[IRNodeTypes2["
|
37
|
-
IRNodeTypes2[IRNodeTypes2["
|
38
|
-
IRNodeTypes2[IRNodeTypes2["
|
39
|
-
IRNodeTypes2[IRNodeTypes2["
|
40
|
-
IRNodeTypes2[IRNodeTypes2["
|
41
|
-
IRNodeTypes2[IRNodeTypes2["
|
42
|
-
IRNodeTypes2[IRNodeTypes2["
|
43
|
-
IRNodeTypes2[IRNodeTypes2["
|
43
|
+
IRNodeTypes2[IRNodeTypes2["CREATE_COMPONENT_NODE"] = 11] = "CREATE_COMPONENT_NODE";
|
44
|
+
IRNodeTypes2[IRNodeTypes2["SLOT_OUTLET_NODE"] = 12] = "SLOT_OUTLET_NODE";
|
45
|
+
IRNodeTypes2[IRNodeTypes2["DIRECTIVE"] = 13] = "DIRECTIVE";
|
46
|
+
IRNodeTypes2[IRNodeTypes2["DECLARE_OLD_REF"] = 14] = "DECLARE_OLD_REF";
|
47
|
+
IRNodeTypes2[IRNodeTypes2["IF"] = 15] = "IF";
|
48
|
+
IRNodeTypes2[IRNodeTypes2["FOR"] = 16] = "FOR";
|
49
|
+
IRNodeTypes2[IRNodeTypes2["GET_TEXT_CHILD"] = 17] = "GET_TEXT_CHILD";
|
50
|
+
IRNodeTypes2[IRNodeTypes2["CREATE_NODES"] = 18] = "CREATE_NODES";
|
51
|
+
IRNodeTypes2[IRNodeTypes2["SET_NODES"] = 19] = "SET_NODES";
|
44
52
|
return IRNodeTypes2;
|
45
53
|
})(IRNodeTypes || {});
|
46
54
|
var DynamicFlag = /* @__PURE__ */ ((DynamicFlag2) => {
|
@@ -50,6 +58,49 @@ var DynamicFlag = /* @__PURE__ */ ((DynamicFlag2) => {
|
|
50
58
|
DynamicFlag2[DynamicFlag2["INSERT"] = 4] = "INSERT";
|
51
59
|
return DynamicFlag2;
|
52
60
|
})(DynamicFlag || {});
|
61
|
+
function isBlockOperation(op) {
|
62
|
+
const type = op.type;
|
63
|
+
return type === 11 /* CREATE_COMPONENT_NODE */ || type === 12 /* SLOT_OUTLET_NODE */ || type === 15 /* IF */ || type === 16 /* FOR */;
|
64
|
+
}
|
65
|
+
|
66
|
+
// src/generate.ts
|
67
|
+
var customGenOperation = (oper, context) => {
|
68
|
+
if (oper.type === 18 /* CREATE_NODES */) {
|
69
|
+
return genCreateNodes(oper, context);
|
70
|
+
} else if (oper.type === 19 /* SET_NODES */) {
|
71
|
+
return genSetNodes(oper, context);
|
72
|
+
}
|
73
|
+
};
|
74
|
+
function genSetNodes(oper, context) {
|
75
|
+
const { helper } = context;
|
76
|
+
const { element, values, generated } = oper;
|
77
|
+
return [
|
78
|
+
_compilervapor.NEWLINE,
|
79
|
+
..._compilervapor.genCall.call(void 0,
|
80
|
+
helper("setNodes"),
|
81
|
+
`${generated ? "x" : "n"}${element}`,
|
82
|
+
combineValues(values, context)
|
83
|
+
)
|
84
|
+
];
|
85
|
+
}
|
86
|
+
function genCreateNodes(oper, context) {
|
87
|
+
const { helper } = context;
|
88
|
+
const { id, values } = oper;
|
89
|
+
return [
|
90
|
+
_compilervapor.NEWLINE,
|
91
|
+
`const n${id} = `,
|
92
|
+
..._compilervapor.genCall.call(void 0, helper("createNodes"), values && combineValues(values, context))
|
93
|
+
];
|
94
|
+
}
|
95
|
+
function combineValues(values, context) {
|
96
|
+
return values.flatMap((value, i) => {
|
97
|
+
const exp = _compilervapor.genExpression.call(void 0, value, context);
|
98
|
+
if (i > 0) {
|
99
|
+
exp.unshift(", ");
|
100
|
+
}
|
101
|
+
return exp;
|
102
|
+
});
|
103
|
+
}
|
53
104
|
|
54
105
|
// src/transform.ts
|
55
106
|
|
@@ -358,6 +409,7 @@ function wrapFragment(node) {
|
|
358
409
|
]);
|
359
410
|
}
|
360
411
|
var EMPTY_EXPRESSION = _compilerdom.createSimpleExpression.call(void 0, "", true);
|
412
|
+
var isFragmentNode = (node) => node.type === 0 /* ROOT */ || node.type === "JSXFragment" || node.type === "JSXElement" && !!isTemplate(node);
|
361
413
|
|
362
414
|
// src/transform.ts
|
363
415
|
var defaultOptions = {
|
@@ -582,18 +634,14 @@ function processDynamicChildren(context) {
|
|
582
634
|
context.childrenTemplate[index - prevDynamics.length] = `<!>`;
|
583
635
|
prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
|
584
636
|
const anchor = prevDynamics[0].anchor = context.increaseId();
|
585
|
-
context
|
586
|
-
type: 9 /* INSERT_NODE */,
|
587
|
-
elements: prevDynamics.map((child2) => child2.id),
|
588
|
-
parent: context.reference(),
|
589
|
-
anchor
|
590
|
-
});
|
637
|
+
registerInsertion(prevDynamics, context, anchor);
|
591
638
|
} else {
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
639
|
+
registerInsertion(
|
640
|
+
prevDynamics,
|
641
|
+
context,
|
642
|
+
-1
|
643
|
+
/* prepend */
|
644
|
+
);
|
597
645
|
}
|
598
646
|
prevDynamics = [];
|
599
647
|
}
|
@@ -608,6 +656,25 @@ function processDynamicChildren(context) {
|
|
608
656
|
});
|
609
657
|
}
|
610
658
|
}
|
659
|
+
function registerInsertion(dynamics, context, anchor) {
|
660
|
+
for (const child of dynamics) {
|
661
|
+
if (child.template != null) {
|
662
|
+
context.registerOperation({
|
663
|
+
type: 9 /* INSERT_NODE */,
|
664
|
+
elements: dynamics.map((child2) => child2.id),
|
665
|
+
parent: context.reference(),
|
666
|
+
anchor
|
667
|
+
});
|
668
|
+
} else {
|
669
|
+
for (const op of context.block.operation) {
|
670
|
+
if (isBlockOperation(op) && op.id === child.id) {
|
671
|
+
op.parent = context.reference();
|
672
|
+
op.anchor = anchor;
|
673
|
+
}
|
674
|
+
}
|
675
|
+
}
|
676
|
+
}
|
677
|
+
}
|
611
678
|
|
612
679
|
// src/transforms/transformElement.ts
|
613
680
|
|
@@ -667,8 +734,8 @@ function transformComponentElement(tag, propsResult, singleRoot, context) {
|
|
667
734
|
context.component.add(tag);
|
668
735
|
}
|
669
736
|
context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
|
670
|
-
context.
|
671
|
-
type:
|
737
|
+
context.dynamic.operation = {
|
738
|
+
type: 11 /* CREATE_COMPONENT_NODE */,
|
672
739
|
id: context.reference(),
|
673
740
|
tag,
|
674
741
|
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
|
@@ -676,7 +743,7 @@ function transformComponentElement(tag, propsResult, singleRoot, context) {
|
|
676
743
|
root: singleRoot,
|
677
744
|
slots: [...context.slots],
|
678
745
|
once: context.inVOnce
|
679
|
-
}
|
746
|
+
};
|
680
747
|
context.slots = [];
|
681
748
|
}
|
682
749
|
function transformNativeElement(tag, propsResult, singleRoot, context) {
|
@@ -840,7 +907,7 @@ var transformTemplateRef = (node, context) => {
|
|
840
907
|
const id = context.reference();
|
841
908
|
const effect = !isConstantExpression(value);
|
842
909
|
effect && context.registerOperation({
|
843
|
-
type:
|
910
|
+
type: 14 /* DECLARE_OLD_REF */,
|
844
911
|
id
|
845
912
|
});
|
846
913
|
context.registerEffect([value], {
|
@@ -862,7 +929,7 @@ function processConditionalExpression(node, context) {
|
|
862
929
|
const condition = resolveExpression(test, context);
|
863
930
|
const [branch, onExit] = createBranch(consequent, context);
|
864
931
|
const operation = {
|
865
|
-
type:
|
932
|
+
type: 15 /* IF */,
|
866
933
|
id,
|
867
934
|
condition,
|
868
935
|
positive: branch,
|
@@ -871,7 +938,7 @@ function processConditionalExpression(node, context) {
|
|
871
938
|
return [
|
872
939
|
() => {
|
873
940
|
onExit();
|
874
|
-
context.
|
941
|
+
context.dynamic.operation = operation;
|
875
942
|
},
|
876
943
|
() => {
|
877
944
|
const [branch2, onExit2] = createBranch(alternate, context);
|
@@ -892,7 +959,7 @@ function processLogicalExpression(node, context) {
|
|
892
959
|
context
|
893
960
|
);
|
894
961
|
const operation = {
|
895
|
-
type:
|
962
|
+
type: 15 /* IF */,
|
896
963
|
id,
|
897
964
|
condition,
|
898
965
|
positive: branch,
|
@@ -901,7 +968,7 @@ function processLogicalExpression(node, context) {
|
|
901
968
|
return [
|
902
969
|
() => {
|
903
970
|
onExit();
|
904
|
-
context.
|
971
|
+
context.dynamic.operation = operation;
|
905
972
|
},
|
906
973
|
() => {
|
907
974
|
const [branch2, onExit2] = createBranch(
|
@@ -923,18 +990,35 @@ var transformText = (node, context) => {
|
|
923
990
|
context.dynamic.flags |= 2 /* NON_TEMPLATE */;
|
924
991
|
return;
|
925
992
|
}
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
)
|
993
|
+
const isFragment = isFragmentNode(node);
|
994
|
+
if ((node.type === "JSXElement" && !isTemplate(node) && !isJSXComponent(node) || isFragment) && node.children.length) {
|
995
|
+
let hasInterp = false;
|
996
|
+
let isAllTextLike = true;
|
997
|
+
for (const c of node.children) {
|
998
|
+
if (c.type === "JSXExpressionContainer" && c.expression.type !== "ConditionalExpression" && c.expression.type !== "LogicalExpression") {
|
999
|
+
hasInterp = true;
|
1000
|
+
} else if (c.type !== "JSXText") {
|
1001
|
+
isAllTextLike = false;
|
1002
|
+
}
|
1003
|
+
}
|
1004
|
+
if (!isFragment && isAllTextLike && hasInterp) {
|
1005
|
+
processTextContainer(node.children, context);
|
1006
|
+
} else if (hasInterp) {
|
1007
|
+
for (let i = 0; i < node.children.length; i++) {
|
1008
|
+
const c = node.children[i];
|
1009
|
+
const prev = node.children[i - 1];
|
1010
|
+
if (c.type === "JSXExpressionContainer" && prev && prev.type === "JSXText") {
|
1011
|
+
seen.get(context.root).add(prev);
|
1012
|
+
}
|
1013
|
+
}
|
1014
|
+
}
|
931
1015
|
} else if (node.type === "JSXExpressionContainer") {
|
932
1016
|
if (node.expression.type === "ConditionalExpression") {
|
933
1017
|
return processConditionalExpression(node.expression, context);
|
934
1018
|
} else if (node.expression.type === "LogicalExpression") {
|
935
1019
|
return processLogicalExpression(node.expression, context);
|
936
1020
|
} else {
|
937
|
-
|
1021
|
+
processInterpolation(context);
|
938
1022
|
}
|
939
1023
|
} else if (node.type === "JSXText") {
|
940
1024
|
const value = resolveJSXText(node);
|
@@ -945,35 +1029,55 @@ var transformText = (node, context) => {
|
|
945
1029
|
}
|
946
1030
|
}
|
947
1031
|
};
|
948
|
-
function
|
949
|
-
const
|
1032
|
+
function processInterpolation(context) {
|
1033
|
+
const parent = context.parent.node;
|
1034
|
+
const children = parent.children;
|
1035
|
+
const nexts = children.slice(context.index);
|
950
1036
|
const idx = nexts.findIndex((n) => !isTextLike(n));
|
951
1037
|
const nodes = idx !== -1 ? nexts.slice(0, idx) : nexts;
|
1038
|
+
const prev = children[context.index - 1];
|
1039
|
+
if (prev && prev.type === "JSXText") {
|
1040
|
+
nodes.unshift(prev);
|
1041
|
+
}
|
952
1042
|
const values = createTextLikeExpressions(nodes, context);
|
953
1043
|
if (!values.length) {
|
954
1044
|
context.dynamic.flags |= 2 /* NON_TEMPLATE */;
|
955
1045
|
return;
|
956
1046
|
}
|
957
1047
|
const id = context.reference();
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
1048
|
+
if (isFragmentNode(parent)) {
|
1049
|
+
context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
|
1050
|
+
context.registerOperation({
|
1051
|
+
type: 18 /* CREATE_NODES */,
|
1052
|
+
id,
|
1053
|
+
values
|
1054
|
+
});
|
1055
|
+
} else {
|
1056
|
+
context.template += " ";
|
1057
|
+
context.registerOperation({
|
1058
|
+
type: 19 /* SET_NODES */,
|
1059
|
+
element: id,
|
1060
|
+
values
|
1061
|
+
});
|
1062
|
+
}
|
965
1063
|
}
|
966
|
-
function
|
1064
|
+
function processTextContainer(children, context) {
|
967
1065
|
const values = createTextLikeExpressions(children, context);
|
968
1066
|
const literals = values.map(getLiteralExpressionValue);
|
969
1067
|
if (literals.every((l) => l != null)) {
|
970
1068
|
context.childrenTemplate = literals.map((l) => String(l));
|
971
1069
|
} else {
|
1070
|
+
context.childrenTemplate = [" "];
|
1071
|
+
context.registerOperation({
|
1072
|
+
type: 17 /* GET_TEXT_CHILD */,
|
1073
|
+
parent: context.reference()
|
1074
|
+
});
|
972
1075
|
context.registerOperation({
|
973
|
-
type:
|
1076
|
+
type: 19 /* SET_NODES */,
|
974
1077
|
element: context.reference(),
|
975
1078
|
values,
|
976
|
-
|
1079
|
+
// indicates this node is generated, so prefix should be "x" instead of "n"
|
1080
|
+
generated: true
|
977
1081
|
});
|
978
1082
|
}
|
979
1083
|
}
|
@@ -986,10 +1090,6 @@ function createTextLikeExpressions(nodes, context) {
|
|
986
1090
|
}
|
987
1091
|
return values;
|
988
1092
|
}
|
989
|
-
function isAllTextLike(children) {
|
990
|
-
return !!children.length && children.every(isTextLike) && // at least one an interpolation
|
991
|
-
children.some((n) => n.type === "JSXExpressionContainer");
|
992
|
-
}
|
993
1093
|
function isTextLike(node) {
|
994
1094
|
return node.type === "JSXExpressionContainer" && node.expression.type !== "ConditionalExpression" && node.expression.type !== "LogicalExpression" || node.type === "JSXText";
|
995
1095
|
}
|
@@ -1051,8 +1151,8 @@ function processFor(node, dir, context) {
|
|
1051
1151
|
exitBlock();
|
1052
1152
|
const { parent } = context;
|
1053
1153
|
const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
|
1054
|
-
context.
|
1055
|
-
type:
|
1154
|
+
context.dynamic.operation = {
|
1155
|
+
type: 16 /* FOR */,
|
1056
1156
|
id,
|
1057
1157
|
source,
|
1058
1158
|
value,
|
@@ -1063,7 +1163,7 @@ function processFor(node, dir, context) {
|
|
1063
1163
|
once: context.inVOnce || !!(source.ast && _compilerdom.isConstantNode.call(void 0, source.ast, {})),
|
1064
1164
|
component: isComponent,
|
1065
1165
|
onlyChild: !!isOnlyChild
|
1066
|
-
}
|
1166
|
+
};
|
1067
1167
|
};
|
1068
1168
|
}
|
1069
1169
|
function getForParseResult(dir, context) {
|
@@ -1135,22 +1235,28 @@ function processIf(node, attribute, context) {
|
|
1135
1235
|
const [branch, onExit] = createBranch(node, context);
|
1136
1236
|
return () => {
|
1137
1237
|
onExit();
|
1138
|
-
context.
|
1139
|
-
type:
|
1238
|
+
context.dynamic.operation = {
|
1239
|
+
type: 15 /* IF */,
|
1140
1240
|
id,
|
1141
1241
|
condition: dir.exp,
|
1142
1242
|
positive: branch,
|
1143
1243
|
once: context.inVOnce || _compilerdom.isConstantNode.call(void 0, attribute.value, context.options.bindingMetadata)
|
1144
|
-
}
|
1244
|
+
};
|
1145
1245
|
};
|
1146
1246
|
} else {
|
1147
1247
|
const siblingIf = getSiblingIf(context);
|
1148
|
-
const
|
1149
|
-
let lastIfNode
|
1248
|
+
const siblings = context.parent && context.parent.dynamic.children;
|
1249
|
+
let lastIfNode;
|
1250
|
+
if (siblings) {
|
1251
|
+
let i = siblings.length;
|
1252
|
+
while (i--) {
|
1253
|
+
if (siblings[i].operation) lastIfNode = siblings[i].operation;
|
1254
|
+
}
|
1255
|
+
}
|
1150
1256
|
if (
|
1151
1257
|
// check if v-if is the sibling node
|
1152
1258
|
!siblingIf || // check if IfNode is the last operation and get the root IfNode
|
1153
|
-
!lastIfNode || lastIfNode.type !==
|
1259
|
+
!lastIfNode || lastIfNode.type !== 15 /* IF */
|
1154
1260
|
) {
|
1155
1261
|
context.options.onError(
|
1156
1262
|
_compilerdom.createCompilerError.call(void 0,
|
@@ -1160,7 +1266,7 @@ function processIf(node, attribute, context) {
|
|
1160
1266
|
);
|
1161
1267
|
return;
|
1162
1268
|
}
|
1163
|
-
while (lastIfNode.negative && lastIfNode.negative.type ===
|
1269
|
+
while (lastIfNode.negative && lastIfNode.negative.type === 15 /* IF */) {
|
1164
1270
|
lastIfNode = lastIfNode.negative;
|
1165
1271
|
}
|
1166
1272
|
if (dir.name === "else-if" && lastIfNode.negative) {
|
@@ -1177,7 +1283,7 @@ function processIf(node, attribute, context) {
|
|
1177
1283
|
lastIfNode.negative = branch;
|
1178
1284
|
} else {
|
1179
1285
|
lastIfNode.negative = {
|
1180
|
-
type:
|
1286
|
+
type: 15 /* IF */,
|
1181
1287
|
id: -1,
|
1182
1288
|
condition: dir.exp,
|
1183
1289
|
positive: branch,
|
@@ -1491,7 +1597,7 @@ var transformVSlots = (node, context) => {
|
|
1491
1597
|
(attr) => attr.type === "JSXAttribute" && attr.name.name.toString() === "v-slots"
|
1492
1598
|
);
|
1493
1599
|
const vSlotsDir = attributes[vSlotsIndex];
|
1494
|
-
if (vSlotsDir && _optionalChain([vSlotsDir, 'access',
|
1600
|
+
if (vSlotsDir && _optionalChain([vSlotsDir, 'access', _11 => _11.value, 'optionalAccess', _12 => _12.type]) === "JSXExpressionContainer") {
|
1495
1601
|
attributes.splice(vSlotsIndex, 1);
|
1496
1602
|
context.slots = [
|
1497
1603
|
{
|
@@ -1556,7 +1662,10 @@ function compile(source, options = {}) {
|
|
1556
1662
|
)
|
1557
1663
|
})
|
1558
1664
|
);
|
1559
|
-
return _compilervapor.generate.call(void 0, ir,
|
1665
|
+
return _compilervapor.generate.call(void 0, ir, {
|
1666
|
+
...resolvedOptions,
|
1667
|
+
customGenOperation
|
1668
|
+
});
|
1560
1669
|
}
|
1561
1670
|
function getBaseTransformPreset() {
|
1562
1671
|
return [
|
@@ -1618,4 +1727,5 @@ var transformVText = (dir, node, context) => {
|
|
1618
1727
|
|
1619
1728
|
|
1620
1729
|
|
1621
|
-
|
1730
|
+
|
1731
|
+
exports.DynamicFlag = DynamicFlag; exports.IRDynamicPropsKind = IRDynamicPropsKind; exports.IRNodeTypes = IRNodeTypes; exports.IRSlotType = IRSlotType; exports.TransformContext = TransformContext; exports.compile = compile; exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform; exports.generate = _compilervapor.generate; exports.isBlockOperation = isBlockOperation; exports.resolveDirectiveNode = resolveDirectiveNode; exports.resolveNode = resolveNode; exports.transform = transform; exports.transformChildren = transformChildren; exports.transformElement = transformElement; exports.transformNode = transformNode; exports.transformTemplateRef = transformTemplateRef; exports.transformText = transformText; exports.transformVBind = transformVBind; exports.transformVFor = transformVFor; exports.transformVHtml = transformVHtml; exports.transformVIf = transformVIf; exports.transformVModel = transformVModel; exports.transformVOn = transformVOn; exports.transformVOnce = transformVOnce; exports.transformVShow = transformVShow; exports.transformVSlot = transformVSlot; exports.transformVSlots = transformVSlots; exports.transformVText = transformVText;
|
package/dist/index.d.cts
CHANGED
@@ -116,14 +116,15 @@ declare enum IRNodeTypes {
|
|
116
116
|
SET_TEMPLATE_REF = 8,
|
117
117
|
INSERT_NODE = 9,
|
118
118
|
PREPEND_NODE = 10,
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
119
|
+
CREATE_COMPONENT_NODE = 11,
|
120
|
+
SLOT_OUTLET_NODE = 12,
|
121
|
+
DIRECTIVE = 13,
|
122
|
+
DECLARE_OLD_REF = 14,// consider make it more general
|
123
|
+
IF = 15,
|
124
|
+
FOR = 16,
|
125
|
+
GET_TEXT_CHILD = 17,
|
126
|
+
CREATE_NODES = 18,
|
127
|
+
SET_NODES = 19
|
127
128
|
}
|
128
129
|
interface BaseIRNode {
|
129
130
|
type: IRNodeTypes;
|
@@ -161,6 +162,8 @@ interface IfIRNode extends BaseIRNode {
|
|
161
162
|
positive: BlockIRNode;
|
162
163
|
negative?: BlockIRNode | IfIRNode;
|
163
164
|
once?: boolean;
|
165
|
+
parent?: number;
|
166
|
+
anchor?: number;
|
164
167
|
}
|
165
168
|
interface IRFor {
|
166
169
|
source: SimpleExpressionNode;
|
@@ -176,6 +179,8 @@ interface ForIRNode extends BaseIRNode, IRFor {
|
|
176
179
|
once: boolean;
|
177
180
|
component: boolean;
|
178
181
|
onlyChild: boolean;
|
182
|
+
parent?: number;
|
183
|
+
anchor?: number;
|
179
184
|
}
|
180
185
|
interface SetPropIRNode extends BaseIRNode {
|
181
186
|
type: IRNodeTypes.SET_PROP;
|
@@ -195,12 +200,11 @@ interface SetDynamicEventsIRNode extends BaseIRNode {
|
|
195
200
|
element: number;
|
196
201
|
event: SimpleExpressionNode;
|
197
202
|
}
|
198
|
-
interface
|
199
|
-
type: IRNodeTypes.
|
203
|
+
interface SetNodesIRNode extends BaseIRNode {
|
204
|
+
type: IRNodeTypes.SET_NODES;
|
200
205
|
element: number;
|
201
206
|
values: SimpleExpressionNode[];
|
202
207
|
generated?: boolean;
|
203
|
-
jsx?: boolean;
|
204
208
|
}
|
205
209
|
type KeyOverride = [find: string, replacement: string];
|
206
210
|
interface SetEventIRNode extends BaseIRNode {
|
@@ -230,11 +234,10 @@ interface SetTemplateRefIRNode extends BaseIRNode {
|
|
230
234
|
refFor: boolean;
|
231
235
|
effect: boolean;
|
232
236
|
}
|
233
|
-
interface
|
234
|
-
type: IRNodeTypes.
|
237
|
+
interface CreateNodesIRNode extends BaseIRNode {
|
238
|
+
type: IRNodeTypes.CREATE_NODES;
|
235
239
|
id: number;
|
236
240
|
values?: SimpleExpressionNode[];
|
237
|
-
jsx?: boolean;
|
238
241
|
}
|
239
242
|
interface InsertNodeIRNode extends BaseIRNode {
|
240
243
|
type: IRNodeTypes.INSERT_NODE;
|
@@ -266,6 +269,8 @@ interface CreateComponentIRNode extends BaseIRNode {
|
|
266
269
|
root: boolean;
|
267
270
|
once: boolean;
|
268
271
|
dynamic?: SimpleExpressionNode;
|
272
|
+
parent?: number;
|
273
|
+
anchor?: number;
|
269
274
|
}
|
270
275
|
interface DeclareOldRefIRNode extends BaseIRNode {
|
271
276
|
type: IRNodeTypes.DECLARE_OLD_REF;
|
@@ -277,13 +282,15 @@ interface SlotOutletIRNode extends BaseIRNode {
|
|
277
282
|
name: SimpleExpressionNode;
|
278
283
|
props: IRProps[];
|
279
284
|
fallback?: BlockIRNode;
|
285
|
+
parent?: number;
|
286
|
+
anchor?: number;
|
280
287
|
}
|
281
288
|
interface GetTextChildIRNode extends BaseIRNode {
|
282
289
|
type: IRNodeTypes.GET_TEXT_CHILD;
|
283
290
|
parent: number;
|
284
291
|
}
|
285
292
|
type IRNode = OperationNode | RootIRNode;
|
286
|
-
type OperationNode = SetPropIRNode | SetDynamicPropsIRNode |
|
293
|
+
type OperationNode = SetPropIRNode | SetDynamicPropsIRNode | SetNodesIRNode | SetEventIRNode | SetDynamicEventsIRNode | SetHtmlIRNode | SetTemplateRefIRNode | CreateNodesIRNode | InsertNodeIRNode | PrependNodeIRNode | DirectiveIRNode | IfIRNode | ForIRNode | CreateComponentIRNode | DeclareOldRefIRNode | SlotOutletIRNode | GetTextChildIRNode;
|
287
294
|
declare enum DynamicFlag {
|
288
295
|
NONE = 0,
|
289
296
|
/**
|
@@ -306,6 +313,7 @@ interface IRDynamicInfo {
|
|
306
313
|
children: IRDynamicInfo[];
|
307
314
|
template?: number;
|
308
315
|
hasDynamicChild?: boolean;
|
316
|
+
operation?: OperationNode;
|
309
317
|
}
|
310
318
|
interface IREffect {
|
311
319
|
expressions: SimpleExpressionNode[];
|
@@ -320,9 +328,12 @@ type VaporDirectiveNode = Overwrite<DirectiveNode, {
|
|
320
328
|
exp: Exclude<DirectiveNode['exp'], CompoundExpressionNode>;
|
321
329
|
arg: Exclude<DirectiveNode['arg'], CompoundExpressionNode>;
|
322
330
|
}>;
|
331
|
+
type InsertionStateTypes = IfIRNode | ForIRNode | SlotOutletIRNode | CreateComponentIRNode;
|
332
|
+
declare function isBlockOperation(op: OperationNode): op is InsertionStateTypes;
|
323
333
|
|
324
334
|
interface VaporCodegenResult extends Omit<VaporCodegenResult$1, 'ast'> {
|
325
335
|
ast: RootIRNode;
|
336
|
+
customHelpers: Set<string>;
|
326
337
|
}
|
327
338
|
declare function compile(source: JSXElement | JSXFragment | string, options?: CompilerOptions): VaporCodegenResult;
|
328
339
|
type CompilerOptions = HackOptions<CompilerOptions$1> & {
|
@@ -366,4 +377,4 @@ declare const transformVOnce: NodeTransform;
|
|
366
377
|
|
367
378
|
declare const transformVText: DirectiveTransform;
|
368
379
|
|
369
|
-
export { type BaseIRNode, type BlockIRNode, type CompilerOptions, type CreateComponentIRNode, type
|
380
|
+
export { type BaseIRNode, type BlockIRNode, type CompilerOptions, type CreateComponentIRNode, type CreateNodesIRNode, type DeclareOldRefIRNode, type DirectiveIRNode, type DirectiveTransform, type DirectiveTransformResult, DynamicFlag, type ForIRNode, type GetTextChildIRNode, type HackOptions, type IRDynamicInfo, IRDynamicPropsKind, type IREffect, type IRFor, type IRNode, IRNodeTypes, type IRProp, type IRProps, type IRPropsDynamicAttribute, type IRPropsDynamicExpression, type IRPropsStatic, type IRSlotDynamic, type IRSlotDynamicBasic, type IRSlotDynamicConditional, type IRSlotDynamicLoop, IRSlotType, type IRSlots, type IRSlotsExpression, type IRSlotsStatic, type IfIRNode, type InsertNodeIRNode, type InsertionStateTypes, type KeyOverride, type NodeTransform, type OperationNode, type PrependNodeIRNode, type RootIRNode, type RootNode, type SetDynamicEventsIRNode, type SetDynamicPropsIRNode, type SetEventIRNode, type SetHtmlIRNode, type SetNodesIRNode, type SetPropIRNode, type SetTemplateRefIRNode, type SlotBlockIRNode, type SlotOutletIRNode, type StructuralDirectiveTransform, TransformContext, type TransformOptions, type TransformPreset, type VaporDirectiveNode, compile, createStructuralDirectiveTransform, isBlockOperation, resolveDirectiveNode, resolveNode, transform, transformChildren, transformElement, transformNode, transformTemplateRef, transformText, transformVBind, transformVFor, transformVHtml, transformVIf, transformVModel, transformVOn, transformVOnce, transformVShow, transformVSlot, transformVSlots, transformVText };
|
package/dist/index.d.ts
CHANGED
@@ -116,14 +116,15 @@ declare enum IRNodeTypes {
|
|
116
116
|
SET_TEMPLATE_REF = 8,
|
117
117
|
INSERT_NODE = 9,
|
118
118
|
PREPEND_NODE = 10,
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
119
|
+
CREATE_COMPONENT_NODE = 11,
|
120
|
+
SLOT_OUTLET_NODE = 12,
|
121
|
+
DIRECTIVE = 13,
|
122
|
+
DECLARE_OLD_REF = 14,// consider make it more general
|
123
|
+
IF = 15,
|
124
|
+
FOR = 16,
|
125
|
+
GET_TEXT_CHILD = 17,
|
126
|
+
CREATE_NODES = 18,
|
127
|
+
SET_NODES = 19
|
127
128
|
}
|
128
129
|
interface BaseIRNode {
|
129
130
|
type: IRNodeTypes;
|
@@ -161,6 +162,8 @@ interface IfIRNode extends BaseIRNode {
|
|
161
162
|
positive: BlockIRNode;
|
162
163
|
negative?: BlockIRNode | IfIRNode;
|
163
164
|
once?: boolean;
|
165
|
+
parent?: number;
|
166
|
+
anchor?: number;
|
164
167
|
}
|
165
168
|
interface IRFor {
|
166
169
|
source: SimpleExpressionNode;
|
@@ -176,6 +179,8 @@ interface ForIRNode extends BaseIRNode, IRFor {
|
|
176
179
|
once: boolean;
|
177
180
|
component: boolean;
|
178
181
|
onlyChild: boolean;
|
182
|
+
parent?: number;
|
183
|
+
anchor?: number;
|
179
184
|
}
|
180
185
|
interface SetPropIRNode extends BaseIRNode {
|
181
186
|
type: IRNodeTypes.SET_PROP;
|
@@ -195,12 +200,11 @@ interface SetDynamicEventsIRNode extends BaseIRNode {
|
|
195
200
|
element: number;
|
196
201
|
event: SimpleExpressionNode;
|
197
202
|
}
|
198
|
-
interface
|
199
|
-
type: IRNodeTypes.
|
203
|
+
interface SetNodesIRNode extends BaseIRNode {
|
204
|
+
type: IRNodeTypes.SET_NODES;
|
200
205
|
element: number;
|
201
206
|
values: SimpleExpressionNode[];
|
202
207
|
generated?: boolean;
|
203
|
-
jsx?: boolean;
|
204
208
|
}
|
205
209
|
type KeyOverride = [find: string, replacement: string];
|
206
210
|
interface SetEventIRNode extends BaseIRNode {
|
@@ -230,11 +234,10 @@ interface SetTemplateRefIRNode extends BaseIRNode {
|
|
230
234
|
refFor: boolean;
|
231
235
|
effect: boolean;
|
232
236
|
}
|
233
|
-
interface
|
234
|
-
type: IRNodeTypes.
|
237
|
+
interface CreateNodesIRNode extends BaseIRNode {
|
238
|
+
type: IRNodeTypes.CREATE_NODES;
|
235
239
|
id: number;
|
236
240
|
values?: SimpleExpressionNode[];
|
237
|
-
jsx?: boolean;
|
238
241
|
}
|
239
242
|
interface InsertNodeIRNode extends BaseIRNode {
|
240
243
|
type: IRNodeTypes.INSERT_NODE;
|
@@ -266,6 +269,8 @@ interface CreateComponentIRNode extends BaseIRNode {
|
|
266
269
|
root: boolean;
|
267
270
|
once: boolean;
|
268
271
|
dynamic?: SimpleExpressionNode;
|
272
|
+
parent?: number;
|
273
|
+
anchor?: number;
|
269
274
|
}
|
270
275
|
interface DeclareOldRefIRNode extends BaseIRNode {
|
271
276
|
type: IRNodeTypes.DECLARE_OLD_REF;
|
@@ -277,13 +282,15 @@ interface SlotOutletIRNode extends BaseIRNode {
|
|
277
282
|
name: SimpleExpressionNode;
|
278
283
|
props: IRProps[];
|
279
284
|
fallback?: BlockIRNode;
|
285
|
+
parent?: number;
|
286
|
+
anchor?: number;
|
280
287
|
}
|
281
288
|
interface GetTextChildIRNode extends BaseIRNode {
|
282
289
|
type: IRNodeTypes.GET_TEXT_CHILD;
|
283
290
|
parent: number;
|
284
291
|
}
|
285
292
|
type IRNode = OperationNode | RootIRNode;
|
286
|
-
type OperationNode = SetPropIRNode | SetDynamicPropsIRNode |
|
293
|
+
type OperationNode = SetPropIRNode | SetDynamicPropsIRNode | SetNodesIRNode | SetEventIRNode | SetDynamicEventsIRNode | SetHtmlIRNode | SetTemplateRefIRNode | CreateNodesIRNode | InsertNodeIRNode | PrependNodeIRNode | DirectiveIRNode | IfIRNode | ForIRNode | CreateComponentIRNode | DeclareOldRefIRNode | SlotOutletIRNode | GetTextChildIRNode;
|
287
294
|
declare enum DynamicFlag {
|
288
295
|
NONE = 0,
|
289
296
|
/**
|
@@ -306,6 +313,7 @@ interface IRDynamicInfo {
|
|
306
313
|
children: IRDynamicInfo[];
|
307
314
|
template?: number;
|
308
315
|
hasDynamicChild?: boolean;
|
316
|
+
operation?: OperationNode;
|
309
317
|
}
|
310
318
|
interface IREffect {
|
311
319
|
expressions: SimpleExpressionNode[];
|
@@ -320,9 +328,12 @@ type VaporDirectiveNode = Overwrite<DirectiveNode, {
|
|
320
328
|
exp: Exclude<DirectiveNode['exp'], CompoundExpressionNode>;
|
321
329
|
arg: Exclude<DirectiveNode['arg'], CompoundExpressionNode>;
|
322
330
|
}>;
|
331
|
+
type InsertionStateTypes = IfIRNode | ForIRNode | SlotOutletIRNode | CreateComponentIRNode;
|
332
|
+
declare function isBlockOperation(op: OperationNode): op is InsertionStateTypes;
|
323
333
|
|
324
334
|
interface VaporCodegenResult extends Omit<VaporCodegenResult$1, 'ast'> {
|
325
335
|
ast: RootIRNode;
|
336
|
+
customHelpers: Set<string>;
|
326
337
|
}
|
327
338
|
declare function compile(source: JSXElement | JSXFragment | string, options?: CompilerOptions): VaporCodegenResult;
|
328
339
|
type CompilerOptions = HackOptions<CompilerOptions$1> & {
|
@@ -366,4 +377,4 @@ declare const transformVOnce: NodeTransform;
|
|
366
377
|
|
367
378
|
declare const transformVText: DirectiveTransform;
|
368
379
|
|
369
|
-
export { type BaseIRNode, type BlockIRNode, type CompilerOptions, type CreateComponentIRNode, type
|
380
|
+
export { type BaseIRNode, type BlockIRNode, type CompilerOptions, type CreateComponentIRNode, type CreateNodesIRNode, type DeclareOldRefIRNode, type DirectiveIRNode, type DirectiveTransform, type DirectiveTransformResult, DynamicFlag, type ForIRNode, type GetTextChildIRNode, type HackOptions, type IRDynamicInfo, IRDynamicPropsKind, type IREffect, type IRFor, type IRNode, IRNodeTypes, type IRProp, type IRProps, type IRPropsDynamicAttribute, type IRPropsDynamicExpression, type IRPropsStatic, type IRSlotDynamic, type IRSlotDynamicBasic, type IRSlotDynamicConditional, type IRSlotDynamicLoop, IRSlotType, type IRSlots, type IRSlotsExpression, type IRSlotsStatic, type IfIRNode, type InsertNodeIRNode, type InsertionStateTypes, type KeyOverride, type NodeTransform, type OperationNode, type PrependNodeIRNode, type RootIRNode, type RootNode, type SetDynamicEventsIRNode, type SetDynamicPropsIRNode, type SetEventIRNode, type SetHtmlIRNode, type SetNodesIRNode, type SetPropIRNode, type SetTemplateRefIRNode, type SlotBlockIRNode, type SlotOutletIRNode, type StructuralDirectiveTransform, TransformContext, type TransformOptions, type TransformPreset, type VaporDirectiveNode, compile, createStructuralDirectiveTransform, isBlockOperation, resolveDirectiveNode, resolveNode, transform, transformChildren, transformElement, transformNode, transformTemplateRef, transformText, transformVBind, transformVFor, transformVHtml, transformVIf, transformVModel, transformVOn, transformVOnce, transformVShow, transformVSlot, transformVSlots, transformVText };
|
package/dist/index.js
CHANGED
@@ -5,6 +5,13 @@ import {
|
|
5
5
|
} from "@vue/compiler-vapor";
|
6
6
|
import { extend as extend5, isString as isString3 } from "@vue/shared";
|
7
7
|
|
8
|
+
// src/generate.ts
|
9
|
+
import {
|
10
|
+
genCall,
|
11
|
+
genExpression,
|
12
|
+
NEWLINE
|
13
|
+
} from "@vue/compiler-vapor";
|
14
|
+
|
8
15
|
// src/ir/component.ts
|
9
16
|
var IRDynamicPropsKind = /* @__PURE__ */ ((IRDynamicPropsKind2) => {
|
10
17
|
IRDynamicPropsKind2[IRDynamicPropsKind2["EXPRESSION"] = 0] = "EXPRESSION";
|
@@ -33,14 +40,15 @@ var IRNodeTypes = /* @__PURE__ */ ((IRNodeTypes2) => {
|
|
33
40
|
IRNodeTypes2[IRNodeTypes2["SET_TEMPLATE_REF"] = 8] = "SET_TEMPLATE_REF";
|
34
41
|
IRNodeTypes2[IRNodeTypes2["INSERT_NODE"] = 9] = "INSERT_NODE";
|
35
42
|
IRNodeTypes2[IRNodeTypes2["PREPEND_NODE"] = 10] = "PREPEND_NODE";
|
36
|
-
IRNodeTypes2[IRNodeTypes2["
|
37
|
-
IRNodeTypes2[IRNodeTypes2["
|
38
|
-
IRNodeTypes2[IRNodeTypes2["
|
39
|
-
IRNodeTypes2[IRNodeTypes2["
|
40
|
-
IRNodeTypes2[IRNodeTypes2["
|
41
|
-
IRNodeTypes2[IRNodeTypes2["
|
42
|
-
IRNodeTypes2[IRNodeTypes2["
|
43
|
-
IRNodeTypes2[IRNodeTypes2["
|
43
|
+
IRNodeTypes2[IRNodeTypes2["CREATE_COMPONENT_NODE"] = 11] = "CREATE_COMPONENT_NODE";
|
44
|
+
IRNodeTypes2[IRNodeTypes2["SLOT_OUTLET_NODE"] = 12] = "SLOT_OUTLET_NODE";
|
45
|
+
IRNodeTypes2[IRNodeTypes2["DIRECTIVE"] = 13] = "DIRECTIVE";
|
46
|
+
IRNodeTypes2[IRNodeTypes2["DECLARE_OLD_REF"] = 14] = "DECLARE_OLD_REF";
|
47
|
+
IRNodeTypes2[IRNodeTypes2["IF"] = 15] = "IF";
|
48
|
+
IRNodeTypes2[IRNodeTypes2["FOR"] = 16] = "FOR";
|
49
|
+
IRNodeTypes2[IRNodeTypes2["GET_TEXT_CHILD"] = 17] = "GET_TEXT_CHILD";
|
50
|
+
IRNodeTypes2[IRNodeTypes2["CREATE_NODES"] = 18] = "CREATE_NODES";
|
51
|
+
IRNodeTypes2[IRNodeTypes2["SET_NODES"] = 19] = "SET_NODES";
|
44
52
|
return IRNodeTypes2;
|
45
53
|
})(IRNodeTypes || {});
|
46
54
|
var DynamicFlag = /* @__PURE__ */ ((DynamicFlag2) => {
|
@@ -50,6 +58,49 @@ var DynamicFlag = /* @__PURE__ */ ((DynamicFlag2) => {
|
|
50
58
|
DynamicFlag2[DynamicFlag2["INSERT"] = 4] = "INSERT";
|
51
59
|
return DynamicFlag2;
|
52
60
|
})(DynamicFlag || {});
|
61
|
+
function isBlockOperation(op) {
|
62
|
+
const type = op.type;
|
63
|
+
return type === 11 /* CREATE_COMPONENT_NODE */ || type === 12 /* SLOT_OUTLET_NODE */ || type === 15 /* IF */ || type === 16 /* FOR */;
|
64
|
+
}
|
65
|
+
|
66
|
+
// src/generate.ts
|
67
|
+
var customGenOperation = (oper, context) => {
|
68
|
+
if (oper.type === 18 /* CREATE_NODES */) {
|
69
|
+
return genCreateNodes(oper, context);
|
70
|
+
} else if (oper.type === 19 /* SET_NODES */) {
|
71
|
+
return genSetNodes(oper, context);
|
72
|
+
}
|
73
|
+
};
|
74
|
+
function genSetNodes(oper, context) {
|
75
|
+
const { helper } = context;
|
76
|
+
const { element, values, generated } = oper;
|
77
|
+
return [
|
78
|
+
NEWLINE,
|
79
|
+
...genCall(
|
80
|
+
helper("setNodes"),
|
81
|
+
`${generated ? "x" : "n"}${element}`,
|
82
|
+
combineValues(values, context)
|
83
|
+
)
|
84
|
+
];
|
85
|
+
}
|
86
|
+
function genCreateNodes(oper, context) {
|
87
|
+
const { helper } = context;
|
88
|
+
const { id, values } = oper;
|
89
|
+
return [
|
90
|
+
NEWLINE,
|
91
|
+
`const n${id} = `,
|
92
|
+
...genCall(helper("createNodes"), values && combineValues(values, context))
|
93
|
+
];
|
94
|
+
}
|
95
|
+
function combineValues(values, context) {
|
96
|
+
return values.flatMap((value, i) => {
|
97
|
+
const exp = genExpression(value, context);
|
98
|
+
if (i > 0) {
|
99
|
+
exp.unshift(", ");
|
100
|
+
}
|
101
|
+
return exp;
|
102
|
+
});
|
103
|
+
}
|
53
104
|
|
54
105
|
// src/transform.ts
|
55
106
|
import {
|
@@ -358,6 +409,7 @@ function wrapFragment(node) {
|
|
358
409
|
]);
|
359
410
|
}
|
360
411
|
var EMPTY_EXPRESSION = createSimpleExpression2("", true);
|
412
|
+
var isFragmentNode = (node) => node.type === 0 /* ROOT */ || node.type === "JSXFragment" || node.type === "JSXElement" && !!isTemplate(node);
|
361
413
|
|
362
414
|
// src/transform.ts
|
363
415
|
var defaultOptions = {
|
@@ -582,18 +634,14 @@ function processDynamicChildren(context) {
|
|
582
634
|
context.childrenTemplate[index - prevDynamics.length] = `<!>`;
|
583
635
|
prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
|
584
636
|
const anchor = prevDynamics[0].anchor = context.increaseId();
|
585
|
-
context
|
586
|
-
type: 9 /* INSERT_NODE */,
|
587
|
-
elements: prevDynamics.map((child2) => child2.id),
|
588
|
-
parent: context.reference(),
|
589
|
-
anchor
|
590
|
-
});
|
637
|
+
registerInsertion(prevDynamics, context, anchor);
|
591
638
|
} else {
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
639
|
+
registerInsertion(
|
640
|
+
prevDynamics,
|
641
|
+
context,
|
642
|
+
-1
|
643
|
+
/* prepend */
|
644
|
+
);
|
597
645
|
}
|
598
646
|
prevDynamics = [];
|
599
647
|
}
|
@@ -608,6 +656,25 @@ function processDynamicChildren(context) {
|
|
608
656
|
});
|
609
657
|
}
|
610
658
|
}
|
659
|
+
function registerInsertion(dynamics, context, anchor) {
|
660
|
+
for (const child of dynamics) {
|
661
|
+
if (child.template != null) {
|
662
|
+
context.registerOperation({
|
663
|
+
type: 9 /* INSERT_NODE */,
|
664
|
+
elements: dynamics.map((child2) => child2.id),
|
665
|
+
parent: context.reference(),
|
666
|
+
anchor
|
667
|
+
});
|
668
|
+
} else {
|
669
|
+
for (const op of context.block.operation) {
|
670
|
+
if (isBlockOperation(op) && op.id === child.id) {
|
671
|
+
op.parent = context.reference();
|
672
|
+
op.anchor = anchor;
|
673
|
+
}
|
674
|
+
}
|
675
|
+
}
|
676
|
+
}
|
677
|
+
}
|
611
678
|
|
612
679
|
// src/transforms/transformElement.ts
|
613
680
|
import {
|
@@ -667,8 +734,8 @@ function transformComponentElement(tag, propsResult, singleRoot, context) {
|
|
667
734
|
context.component.add(tag);
|
668
735
|
}
|
669
736
|
context.dynamic.flags |= 2 /* NON_TEMPLATE */ | 4 /* INSERT */;
|
670
|
-
context.
|
671
|
-
type:
|
737
|
+
context.dynamic.operation = {
|
738
|
+
type: 11 /* CREATE_COMPONENT_NODE */,
|
672
739
|
id: context.reference(),
|
673
740
|
tag,
|
674
741
|
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
|
@@ -676,7 +743,7 @@ function transformComponentElement(tag, propsResult, singleRoot, context) {
|
|
676
743
|
root: singleRoot,
|
677
744
|
slots: [...context.slots],
|
678
745
|
once: context.inVOnce
|
679
|
-
}
|
746
|
+
};
|
680
747
|
context.slots = [];
|
681
748
|
}
|
682
749
|
function transformNativeElement(tag, propsResult, singleRoot, context) {
|
@@ -840,7 +907,7 @@ var transformTemplateRef = (node, context) => {
|
|
840
907
|
const id = context.reference();
|
841
908
|
const effect = !isConstantExpression(value);
|
842
909
|
effect && context.registerOperation({
|
843
|
-
type:
|
910
|
+
type: 14 /* DECLARE_OLD_REF */,
|
844
911
|
id
|
845
912
|
});
|
846
913
|
context.registerEffect([value], {
|
@@ -862,7 +929,7 @@ function processConditionalExpression(node, context) {
|
|
862
929
|
const condition = resolveExpression(test, context);
|
863
930
|
const [branch, onExit] = createBranch(consequent, context);
|
864
931
|
const operation = {
|
865
|
-
type:
|
932
|
+
type: 15 /* IF */,
|
866
933
|
id,
|
867
934
|
condition,
|
868
935
|
positive: branch,
|
@@ -871,7 +938,7 @@ function processConditionalExpression(node, context) {
|
|
871
938
|
return [
|
872
939
|
() => {
|
873
940
|
onExit();
|
874
|
-
context.
|
941
|
+
context.dynamic.operation = operation;
|
875
942
|
},
|
876
943
|
() => {
|
877
944
|
const [branch2, onExit2] = createBranch(alternate, context);
|
@@ -892,7 +959,7 @@ function processLogicalExpression(node, context) {
|
|
892
959
|
context
|
893
960
|
);
|
894
961
|
const operation = {
|
895
|
-
type:
|
962
|
+
type: 15 /* IF */,
|
896
963
|
id,
|
897
964
|
condition,
|
898
965
|
positive: branch,
|
@@ -901,7 +968,7 @@ function processLogicalExpression(node, context) {
|
|
901
968
|
return [
|
902
969
|
() => {
|
903
970
|
onExit();
|
904
|
-
context.
|
971
|
+
context.dynamic.operation = operation;
|
905
972
|
},
|
906
973
|
() => {
|
907
974
|
const [branch2, onExit2] = createBranch(
|
@@ -923,18 +990,35 @@ var transformText = (node, context) => {
|
|
923
990
|
context.dynamic.flags |= 2 /* NON_TEMPLATE */;
|
924
991
|
return;
|
925
992
|
}
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
)
|
993
|
+
const isFragment = isFragmentNode(node);
|
994
|
+
if ((node.type === "JSXElement" && !isTemplate(node) && !isJSXComponent(node) || isFragment) && node.children.length) {
|
995
|
+
let hasInterp = false;
|
996
|
+
let isAllTextLike = true;
|
997
|
+
for (const c of node.children) {
|
998
|
+
if (c.type === "JSXExpressionContainer" && c.expression.type !== "ConditionalExpression" && c.expression.type !== "LogicalExpression") {
|
999
|
+
hasInterp = true;
|
1000
|
+
} else if (c.type !== "JSXText") {
|
1001
|
+
isAllTextLike = false;
|
1002
|
+
}
|
1003
|
+
}
|
1004
|
+
if (!isFragment && isAllTextLike && hasInterp) {
|
1005
|
+
processTextContainer(node.children, context);
|
1006
|
+
} else if (hasInterp) {
|
1007
|
+
for (let i = 0; i < node.children.length; i++) {
|
1008
|
+
const c = node.children[i];
|
1009
|
+
const prev = node.children[i - 1];
|
1010
|
+
if (c.type === "JSXExpressionContainer" && prev && prev.type === "JSXText") {
|
1011
|
+
seen.get(context.root).add(prev);
|
1012
|
+
}
|
1013
|
+
}
|
1014
|
+
}
|
931
1015
|
} else if (node.type === "JSXExpressionContainer") {
|
932
1016
|
if (node.expression.type === "ConditionalExpression") {
|
933
1017
|
return processConditionalExpression(node.expression, context);
|
934
1018
|
} else if (node.expression.type === "LogicalExpression") {
|
935
1019
|
return processLogicalExpression(node.expression, context);
|
936
1020
|
} else {
|
937
|
-
|
1021
|
+
processInterpolation(context);
|
938
1022
|
}
|
939
1023
|
} else if (node.type === "JSXText") {
|
940
1024
|
const value = resolveJSXText(node);
|
@@ -945,35 +1029,55 @@ var transformText = (node, context) => {
|
|
945
1029
|
}
|
946
1030
|
}
|
947
1031
|
};
|
948
|
-
function
|
949
|
-
const
|
1032
|
+
function processInterpolation(context) {
|
1033
|
+
const parent = context.parent.node;
|
1034
|
+
const children = parent.children;
|
1035
|
+
const nexts = children.slice(context.index);
|
950
1036
|
const idx = nexts.findIndex((n) => !isTextLike(n));
|
951
1037
|
const nodes = idx !== -1 ? nexts.slice(0, idx) : nexts;
|
1038
|
+
const prev = children[context.index - 1];
|
1039
|
+
if (prev && prev.type === "JSXText") {
|
1040
|
+
nodes.unshift(prev);
|
1041
|
+
}
|
952
1042
|
const values = createTextLikeExpressions(nodes, context);
|
953
1043
|
if (!values.length) {
|
954
1044
|
context.dynamic.flags |= 2 /* NON_TEMPLATE */;
|
955
1045
|
return;
|
956
1046
|
}
|
957
1047
|
const id = context.reference();
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
1048
|
+
if (isFragmentNode(parent)) {
|
1049
|
+
context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
|
1050
|
+
context.registerOperation({
|
1051
|
+
type: 18 /* CREATE_NODES */,
|
1052
|
+
id,
|
1053
|
+
values
|
1054
|
+
});
|
1055
|
+
} else {
|
1056
|
+
context.template += " ";
|
1057
|
+
context.registerOperation({
|
1058
|
+
type: 19 /* SET_NODES */,
|
1059
|
+
element: id,
|
1060
|
+
values
|
1061
|
+
});
|
1062
|
+
}
|
965
1063
|
}
|
966
|
-
function
|
1064
|
+
function processTextContainer(children, context) {
|
967
1065
|
const values = createTextLikeExpressions(children, context);
|
968
1066
|
const literals = values.map(getLiteralExpressionValue);
|
969
1067
|
if (literals.every((l) => l != null)) {
|
970
1068
|
context.childrenTemplate = literals.map((l) => String(l));
|
971
1069
|
} else {
|
1070
|
+
context.childrenTemplate = [" "];
|
1071
|
+
context.registerOperation({
|
1072
|
+
type: 17 /* GET_TEXT_CHILD */,
|
1073
|
+
parent: context.reference()
|
1074
|
+
});
|
972
1075
|
context.registerOperation({
|
973
|
-
type:
|
1076
|
+
type: 19 /* SET_NODES */,
|
974
1077
|
element: context.reference(),
|
975
1078
|
values,
|
976
|
-
|
1079
|
+
// indicates this node is generated, so prefix should be "x" instead of "n"
|
1080
|
+
generated: true
|
977
1081
|
});
|
978
1082
|
}
|
979
1083
|
}
|
@@ -986,10 +1090,6 @@ function createTextLikeExpressions(nodes, context) {
|
|
986
1090
|
}
|
987
1091
|
return values;
|
988
1092
|
}
|
989
|
-
function isAllTextLike(children) {
|
990
|
-
return !!children.length && children.every(isTextLike) && // at least one an interpolation
|
991
|
-
children.some((n) => n.type === "JSXExpressionContainer");
|
992
|
-
}
|
993
1093
|
function isTextLike(node) {
|
994
1094
|
return node.type === "JSXExpressionContainer" && node.expression.type !== "ConditionalExpression" && node.expression.type !== "LogicalExpression" || node.type === "JSXText";
|
995
1095
|
}
|
@@ -1051,8 +1151,8 @@ function processFor(node, dir, context) {
|
|
1051
1151
|
exitBlock();
|
1052
1152
|
const { parent } = context;
|
1053
1153
|
const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
|
1054
|
-
context.
|
1055
|
-
type:
|
1154
|
+
context.dynamic.operation = {
|
1155
|
+
type: 16 /* FOR */,
|
1056
1156
|
id,
|
1057
1157
|
source,
|
1058
1158
|
value,
|
@@ -1063,7 +1163,7 @@ function processFor(node, dir, context) {
|
|
1063
1163
|
once: context.inVOnce || !!(source.ast && isConstantNode(source.ast, {})),
|
1064
1164
|
component: isComponent,
|
1065
1165
|
onlyChild: !!isOnlyChild
|
1066
|
-
}
|
1166
|
+
};
|
1067
1167
|
};
|
1068
1168
|
}
|
1069
1169
|
function getForParseResult(dir, context) {
|
@@ -1135,22 +1235,28 @@ function processIf(node, attribute, context) {
|
|
1135
1235
|
const [branch, onExit] = createBranch(node, context);
|
1136
1236
|
return () => {
|
1137
1237
|
onExit();
|
1138
|
-
context.
|
1139
|
-
type:
|
1238
|
+
context.dynamic.operation = {
|
1239
|
+
type: 15 /* IF */,
|
1140
1240
|
id,
|
1141
1241
|
condition: dir.exp,
|
1142
1242
|
positive: branch,
|
1143
1243
|
once: context.inVOnce || isConstantNode2(attribute.value, context.options.bindingMetadata)
|
1144
|
-
}
|
1244
|
+
};
|
1145
1245
|
};
|
1146
1246
|
} else {
|
1147
1247
|
const siblingIf = getSiblingIf(context);
|
1148
|
-
const
|
1149
|
-
let lastIfNode
|
1248
|
+
const siblings = context.parent && context.parent.dynamic.children;
|
1249
|
+
let lastIfNode;
|
1250
|
+
if (siblings) {
|
1251
|
+
let i = siblings.length;
|
1252
|
+
while (i--) {
|
1253
|
+
if (siblings[i].operation) lastIfNode = siblings[i].operation;
|
1254
|
+
}
|
1255
|
+
}
|
1150
1256
|
if (
|
1151
1257
|
// check if v-if is the sibling node
|
1152
1258
|
!siblingIf || // check if IfNode is the last operation and get the root IfNode
|
1153
|
-
!lastIfNode || lastIfNode.type !==
|
1259
|
+
!lastIfNode || lastIfNode.type !== 15 /* IF */
|
1154
1260
|
) {
|
1155
1261
|
context.options.onError(
|
1156
1262
|
createCompilerError2(
|
@@ -1160,7 +1266,7 @@ function processIf(node, attribute, context) {
|
|
1160
1266
|
);
|
1161
1267
|
return;
|
1162
1268
|
}
|
1163
|
-
while (lastIfNode.negative && lastIfNode.negative.type ===
|
1269
|
+
while (lastIfNode.negative && lastIfNode.negative.type === 15 /* IF */) {
|
1164
1270
|
lastIfNode = lastIfNode.negative;
|
1165
1271
|
}
|
1166
1272
|
if (dir.name === "else-if" && lastIfNode.negative) {
|
@@ -1177,7 +1283,7 @@ function processIf(node, attribute, context) {
|
|
1177
1283
|
lastIfNode.negative = branch;
|
1178
1284
|
} else {
|
1179
1285
|
lastIfNode.negative = {
|
1180
|
-
type:
|
1286
|
+
type: 15 /* IF */,
|
1181
1287
|
id: -1,
|
1182
1288
|
condition: dir.exp,
|
1183
1289
|
positive: branch,
|
@@ -1556,7 +1662,10 @@ function compile(source, options = {}) {
|
|
1556
1662
|
)
|
1557
1663
|
})
|
1558
1664
|
);
|
1559
|
-
return generate(ir,
|
1665
|
+
return generate(ir, {
|
1666
|
+
...resolvedOptions,
|
1667
|
+
customGenOperation
|
1668
|
+
});
|
1560
1669
|
}
|
1561
1670
|
function getBaseTransformPreset() {
|
1562
1671
|
return [
|
@@ -1599,6 +1708,7 @@ export {
|
|
1599
1708
|
compile,
|
1600
1709
|
createStructuralDirectiveTransform,
|
1601
1710
|
generate,
|
1711
|
+
isBlockOperation,
|
1602
1712
|
resolveDirectiveNode,
|
1603
1713
|
resolveNode,
|
1604
1714
|
transform,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vue-jsx-vapor/compiler",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.1.0",
|
4
4
|
"description": "Vue JSX Vapor Compiler",
|
5
5
|
"type": "module",
|
6
6
|
"keywords": [
|
@@ -50,9 +50,9 @@
|
|
50
50
|
"dependencies": {
|
51
51
|
"@babel/parser": "^7.26.8",
|
52
52
|
"@babel/types": "^7.26.8",
|
53
|
-
"@vue/compiler-dom": "https://pkg.pr.new/@vue/compiler-dom@
|
54
|
-
"@vue/compiler-vapor": "https://pkg.pr.new/@vue/compiler-vapor@
|
55
|
-
"@vue/shared": "https://pkg.pr.new/@vue/shared@
|
53
|
+
"@vue/compiler-dom": "https://pkg.pr.new/@vue/compiler-dom@34957eb",
|
54
|
+
"@vue/compiler-vapor": "https://pkg.pr.new/@vue/compiler-vapor@13044",
|
55
|
+
"@vue/shared": "https://pkg.pr.new/@vue/shared@34957eb"
|
56
56
|
},
|
57
57
|
"scripts": {
|
58
58
|
"build": "tsup",
|