@vue-jsx-vapor/compiler 1.6.0 → 1.7.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 +323 -325
- package/dist/index.d.cts +47 -47
- package/dist/index.d.ts +47 -47
- package/dist/index.js +332 -334
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
@@ -1,16 +1,9 @@
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/compile.ts
|
2
|
-
var _shared = require('@vue/shared');
|
3
|
-
|
4
|
-
|
5
|
-
var _compilervapor = require('@vue/compiler-vapor');
|
6
2
|
var _parser = require('@babel/parser');
|
7
3
|
|
8
|
-
// src/transform.ts
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
var _compilerdom = require('@vue/compiler-dom');
|
13
4
|
|
5
|
+
var _compilervapor = require('@vue/compiler-vapor');
|
6
|
+
var _shared = require('@vue/shared');
|
14
7
|
|
15
8
|
// src/ir/component.ts
|
16
9
|
var IRDynamicPropsKind = /* @__PURE__ */ ((IRDynamicPropsKind2) => {
|
@@ -58,8 +51,14 @@ var DynamicFlag = /* @__PURE__ */ ((DynamicFlag2) => {
|
|
58
51
|
return DynamicFlag2;
|
59
52
|
})(DynamicFlag || {});
|
60
53
|
|
61
|
-
// src/
|
54
|
+
// src/transform.ts
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
var _compilerdom = require('@vue/compiler-dom');
|
59
|
+
|
62
60
|
|
61
|
+
// src/transforms/utils.ts
|
63
62
|
|
64
63
|
|
65
64
|
|
@@ -67,6 +66,7 @@ var DynamicFlag = /* @__PURE__ */ ((DynamicFlag2) => {
|
|
67
66
|
|
68
67
|
var _types = require('@babel/types');
|
69
68
|
|
69
|
+
|
70
70
|
// src/utils.ts
|
71
71
|
|
72
72
|
|
@@ -118,11 +118,11 @@ var isConstant = (node) => {
|
|
118
118
|
}
|
119
119
|
return false;
|
120
120
|
};
|
121
|
-
var EMPTY_TEXT_REGEX =
|
121
|
+
var EMPTY_TEXT_REGEX = /^[\t\v\f \u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*[\n\r]\s*$/;
|
122
122
|
var START_EMPTY_TEXT_REGEX = /^\s*[\n\r]/;
|
123
123
|
var END_EMPTY_TEXT_REGEX = /[\n\r]\s*$/;
|
124
124
|
function resolveJSXText(node) {
|
125
|
-
if (EMPTY_TEXT_REGEX.test(
|
125
|
+
if (EMPTY_TEXT_REGEX.test(String(_optionalChain([node, 'access', _4 => _4.extra, 'optionalAccess', _5 => _5.raw])))) {
|
126
126
|
return "";
|
127
127
|
}
|
128
128
|
let value = node.value;
|
@@ -135,13 +135,13 @@ function resolveJSXText(node) {
|
|
135
135
|
return value;
|
136
136
|
}
|
137
137
|
function isEmptyText(node) {
|
138
|
-
return node.type === "JSXText" && EMPTY_TEXT_REGEX.test(
|
138
|
+
return node.type === "JSXText" && EMPTY_TEXT_REGEX.test(String(_optionalChain([node, 'access', _6 => _6.extra, 'optionalAccess', _7 => _7.raw]))) || node.type === "JSXExpressionContainer" && node.expression.type === "JSXEmptyExpression";
|
139
139
|
}
|
140
140
|
function resolveSimpleExpressionNode(exp) {
|
141
141
|
if (!exp.isStatic) {
|
142
142
|
const value = getLiteralExpressionValue(exp);
|
143
143
|
if (value !== null) {
|
144
|
-
return _compilerdom.createSimpleExpression.call(void 0,
|
144
|
+
return _compilerdom.createSimpleExpression.call(void 0, String(value), true, exp.loc);
|
145
145
|
}
|
146
146
|
}
|
147
147
|
return exp;
|
@@ -222,7 +222,7 @@ function resolveNode(node, context) {
|
|
222
222
|
} else {
|
223
223
|
result.push({
|
224
224
|
type: _compilerdom.NodeTypes.ATTRIBUTE,
|
225
|
-
name:
|
225
|
+
name: String(attr.name.name),
|
226
226
|
nameLoc: resolveLocation(attr.name.loc, context),
|
227
227
|
value: resolveValue(attr.value, context),
|
228
228
|
loc: resolveLocation(attr.loc, context)
|
@@ -542,6 +542,73 @@ function createStructuralDirectiveTransform(name, fn) {
|
|
542
542
|
};
|
543
543
|
}
|
544
544
|
|
545
|
+
// src/transforms/transformChildren.ts
|
546
|
+
var transformChildren = (node, context) => {
|
547
|
+
const isFragment = node.type === 0 /* ROOT */ || node.type === "JSXFragment" || node.type === "JSXElement" && (isTemplate(node) || isJSXComponent(node));
|
548
|
+
if (node.type !== "JSXElement" && !isFragment) return;
|
549
|
+
for (const [i, child] of node.children.entries()) {
|
550
|
+
const childContext = context.create(child, i);
|
551
|
+
transformNode(childContext);
|
552
|
+
const childDynamic = childContext.dynamic;
|
553
|
+
if (isFragment) {
|
554
|
+
childContext.reference();
|
555
|
+
childContext.registerTemplate();
|
556
|
+
if (!(childDynamic.flags & 2 /* NON_TEMPLATE */) || childDynamic.flags & 4 /* INSERT */) {
|
557
|
+
context.block.returns.push(childDynamic.id);
|
558
|
+
}
|
559
|
+
} else {
|
560
|
+
context.childrenTemplate.push(childContext.template);
|
561
|
+
}
|
562
|
+
if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & 2 /* NON_TEMPLATE */ || childDynamic.flags & 4 /* INSERT */) {
|
563
|
+
context.dynamic.hasDynamicChild = true;
|
564
|
+
}
|
565
|
+
context.dynamic.children[i] = childContext.dynamic;
|
566
|
+
}
|
567
|
+
if (!isFragment) {
|
568
|
+
processDynamicChildren(context);
|
569
|
+
}
|
570
|
+
};
|
571
|
+
function processDynamicChildren(context) {
|
572
|
+
let prevDynamics = [];
|
573
|
+
let hasStaticTemplate = false;
|
574
|
+
const children = context.dynamic.children;
|
575
|
+
for (const [index, child] of children.entries()) {
|
576
|
+
if (child.flags & 4 /* INSERT */) {
|
577
|
+
prevDynamics.push(child);
|
578
|
+
}
|
579
|
+
if (!(child.flags & 2 /* NON_TEMPLATE */)) {
|
580
|
+
if (prevDynamics.length) {
|
581
|
+
if (hasStaticTemplate) {
|
582
|
+
context.childrenTemplate[index - prevDynamics.length] = `<!>`;
|
583
|
+
prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
|
584
|
+
const anchor = prevDynamics[0].anchor = context.increaseId();
|
585
|
+
context.registerOperation({
|
586
|
+
type: 9 /* INSERT_NODE */,
|
587
|
+
elements: prevDynamics.map((child2) => child2.id),
|
588
|
+
parent: context.reference(),
|
589
|
+
anchor
|
590
|
+
});
|
591
|
+
} else {
|
592
|
+
context.registerOperation({
|
593
|
+
type: 10 /* PREPEND_NODE */,
|
594
|
+
elements: prevDynamics.map((child2) => child2.id),
|
595
|
+
parent: context.reference()
|
596
|
+
});
|
597
|
+
}
|
598
|
+
prevDynamics = [];
|
599
|
+
}
|
600
|
+
hasStaticTemplate = true;
|
601
|
+
}
|
602
|
+
}
|
603
|
+
if (prevDynamics.length) {
|
604
|
+
context.registerOperation({
|
605
|
+
type: 9 /* INSERT_NODE */,
|
606
|
+
elements: prevDynamics.map((child) => child.id),
|
607
|
+
parent: context.reference()
|
608
|
+
});
|
609
|
+
}
|
610
|
+
}
|
611
|
+
|
545
612
|
// src/transforms/transformElement.ts
|
546
613
|
|
547
614
|
|
@@ -762,73 +829,6 @@ function mergePropValues(existing, incoming) {
|
|
762
829
|
existing.values.push(...newValues);
|
763
830
|
}
|
764
831
|
|
765
|
-
// src/transforms/transformChildren.ts
|
766
|
-
var transformChildren = (node, context) => {
|
767
|
-
const isFragment = node.type === 0 /* ROOT */ || node.type === "JSXFragment" || node.type === "JSXElement" && (isTemplate(node) || isJSXComponent(node));
|
768
|
-
if (node.type !== "JSXElement" && !isFragment) return;
|
769
|
-
for (const [i, child] of node.children.entries()) {
|
770
|
-
const childContext = context.create(child, i);
|
771
|
-
transformNode(childContext);
|
772
|
-
const childDynamic = childContext.dynamic;
|
773
|
-
if (isFragment) {
|
774
|
-
childContext.reference();
|
775
|
-
childContext.registerTemplate();
|
776
|
-
if (!(childDynamic.flags & 2 /* NON_TEMPLATE */) || childDynamic.flags & 4 /* INSERT */) {
|
777
|
-
context.block.returns.push(childDynamic.id);
|
778
|
-
}
|
779
|
-
} else {
|
780
|
-
context.childrenTemplate.push(childContext.template);
|
781
|
-
}
|
782
|
-
if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & 2 /* NON_TEMPLATE */ || childDynamic.flags & 4 /* INSERT */) {
|
783
|
-
context.dynamic.hasDynamicChild = true;
|
784
|
-
}
|
785
|
-
context.dynamic.children[i] = childContext.dynamic;
|
786
|
-
}
|
787
|
-
if (!isFragment) {
|
788
|
-
processDynamicChildren(context);
|
789
|
-
}
|
790
|
-
};
|
791
|
-
function processDynamicChildren(context) {
|
792
|
-
let prevDynamics = [];
|
793
|
-
let hasStaticTemplate = false;
|
794
|
-
const children = context.dynamic.children;
|
795
|
-
for (const [index, child] of children.entries()) {
|
796
|
-
if (child.flags & 4 /* INSERT */) {
|
797
|
-
prevDynamics.push(child);
|
798
|
-
}
|
799
|
-
if (!(child.flags & 2 /* NON_TEMPLATE */)) {
|
800
|
-
if (prevDynamics.length) {
|
801
|
-
if (hasStaticTemplate) {
|
802
|
-
context.childrenTemplate[index - prevDynamics.length] = `<!>`;
|
803
|
-
prevDynamics[0].flags -= 2 /* NON_TEMPLATE */;
|
804
|
-
const anchor = prevDynamics[0].anchor = context.increaseId();
|
805
|
-
context.registerOperation({
|
806
|
-
type: 9 /* INSERT_NODE */,
|
807
|
-
elements: prevDynamics.map((child2) => child2.id),
|
808
|
-
parent: context.reference(),
|
809
|
-
anchor
|
810
|
-
});
|
811
|
-
} else {
|
812
|
-
context.registerOperation({
|
813
|
-
type: 10 /* PREPEND_NODE */,
|
814
|
-
elements: prevDynamics.map((child2) => child2.id),
|
815
|
-
parent: context.reference()
|
816
|
-
});
|
817
|
-
}
|
818
|
-
prevDynamics = [];
|
819
|
-
}
|
820
|
-
hasStaticTemplate = true;
|
821
|
-
}
|
822
|
-
}
|
823
|
-
if (prevDynamics.length) {
|
824
|
-
context.registerOperation({
|
825
|
-
type: 9 /* INSERT_NODE */,
|
826
|
-
elements: prevDynamics.map((child) => child.id),
|
827
|
-
parent: context.reference()
|
828
|
-
});
|
829
|
-
}
|
830
|
-
}
|
831
|
-
|
832
832
|
// src/transforms/transformTemplateRef.ts
|
833
833
|
var transformTemplateRef = (node, context) => {
|
834
834
|
if (node.type !== "JSXElement") return;
|
@@ -948,7 +948,7 @@ var transformText = (node, context) => {
|
|
948
948
|
function processTextLike(context) {
|
949
949
|
const nexts = _optionalChain([context, 'access', _11 => _11.parent, 'access', _12 => _12.node, 'access', _13 => _13.children, 'optionalAccess', _14 => _14.slice, 'call', _15 => _15(context.index)]);
|
950
950
|
const idx = nexts.findIndex((n) => !isTextLike(n));
|
951
|
-
const nodes = idx
|
951
|
+
const nodes = idx !== -1 ? nexts.slice(0, idx) : nexts;
|
952
952
|
const values = createTextLikeExpressions(nodes, context);
|
953
953
|
if (!values.length) {
|
954
954
|
context.dynamic.flags |= 2 /* NON_TEMPLATE */;
|
@@ -991,7 +991,7 @@ function isAllTextLike(children) {
|
|
991
991
|
children.some((n) => n.type === "JSXExpressionContainer");
|
992
992
|
}
|
993
993
|
function isTextLike(node) {
|
994
|
-
return node.type === "JSXExpressionContainer" &&
|
994
|
+
return node.type === "JSXExpressionContainer" && node.expression.type !== "ConditionalExpression" && node.expression.type !== "LogicalExpression" || node.type === "JSXText";
|
995
995
|
}
|
996
996
|
|
997
997
|
// src/transforms/vBind.ts
|
@@ -1020,89 +1020,6 @@ var transformVBind = (dir, node, context) => {
|
|
1020
1020
|
};
|
1021
1021
|
};
|
1022
1022
|
|
1023
|
-
// src/transforms/vOn.ts
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
var delegatedEvents = /* @__PURE__ */ _shared.makeMap.call(void 0,
|
1032
|
-
"beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart"
|
1033
|
-
);
|
1034
|
-
var transformVOn = (dir, node, context) => {
|
1035
|
-
const { name, loc, value } = dir;
|
1036
|
-
if (name.type === "JSXNamespacedName") return;
|
1037
|
-
const isComponent = isJSXComponent(node);
|
1038
|
-
const [nameString, ...modifiers] = name.name.replace(/^on([A-Z])/, (_, $1) => $1.toLowerCase()).split("_");
|
1039
|
-
if (!value && !modifiers.length) {
|
1040
|
-
context.options.onError(
|
1041
|
-
_compilerdom.createCompilerError.call(void 0,
|
1042
|
-
_compilerdom.ErrorCodes.X_V_ON_NO_EXPRESSION,
|
1043
|
-
resolveLocation(loc, context)
|
1044
|
-
)
|
1045
|
-
);
|
1046
|
-
}
|
1047
|
-
let arg = resolveSimpleExpression(nameString, true, dir.name.loc);
|
1048
|
-
const exp = resolveExpression(dir.value, context);
|
1049
|
-
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = _compilerdom.resolveModifiers.call(void 0,
|
1050
|
-
arg.isStatic ? `on${nameString}` : arg,
|
1051
|
-
modifiers.map((modifier) => _compilerdom.createSimpleExpression.call(void 0, modifier)),
|
1052
|
-
null,
|
1053
|
-
resolveLocation(loc, context)
|
1054
|
-
);
|
1055
|
-
let keyOverride;
|
1056
|
-
const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
|
1057
|
-
if (nonKeyModifiers.includes("middle")) {
|
1058
|
-
if (keyOverride) {
|
1059
|
-
}
|
1060
|
-
if (isStaticClick) {
|
1061
|
-
arg = _shared.extend.call(void 0, {}, arg, { content: "mouseup" });
|
1062
|
-
} else if (!arg.isStatic) {
|
1063
|
-
keyOverride = ["click", "mouseup"];
|
1064
|
-
}
|
1065
|
-
}
|
1066
|
-
if (nonKeyModifiers.includes("right")) {
|
1067
|
-
if (isStaticClick) {
|
1068
|
-
arg = _shared.extend.call(void 0, {}, arg, { content: "contextmenu" });
|
1069
|
-
} else if (!arg.isStatic) {
|
1070
|
-
keyOverride = ["click", "contextmenu"];
|
1071
|
-
}
|
1072
|
-
}
|
1073
|
-
if (isComponent) {
|
1074
|
-
const handler = exp || EMPTY_EXPRESSION;
|
1075
|
-
return {
|
1076
|
-
key: arg,
|
1077
|
-
value: handler,
|
1078
|
-
handler: true,
|
1079
|
-
handlerModifiers: eventOptionModifiers
|
1080
|
-
};
|
1081
|
-
}
|
1082
|
-
const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
|
1083
|
-
const operation = {
|
1084
|
-
type: 5 /* SET_EVENT */,
|
1085
|
-
element: context.reference(),
|
1086
|
-
key: arg,
|
1087
|
-
value: exp,
|
1088
|
-
modifiers: {
|
1089
|
-
keys: keyModifiers,
|
1090
|
-
nonKeys: nonKeyModifiers,
|
1091
|
-
options: eventOptionModifiers
|
1092
|
-
},
|
1093
|
-
keyOverride,
|
1094
|
-
delegate,
|
1095
|
-
effect: !arg.isStatic
|
1096
|
-
};
|
1097
|
-
context.registerEffect([arg], operation);
|
1098
|
-
};
|
1099
|
-
|
1100
|
-
// src/transforms/vSlot.ts
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
1023
|
// src/transforms/vFor.ts
|
1107
1024
|
|
1108
1025
|
|
@@ -1179,25 +1096,244 @@ function getForParseResult(dir, context) {
|
|
1179
1096
|
};
|
1180
1097
|
}
|
1181
1098
|
|
1182
|
-
// src/transforms/
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1099
|
+
// src/transforms/vHtml.ts
|
1100
|
+
|
1101
|
+
var transformVHtml = (dir, node, context) => {
|
1102
|
+
return _compilervapor.transformVHtml.call(void 0,
|
1103
|
+
resolveDirectiveNode(dir, context),
|
1104
|
+
resolveNode(node, context),
|
1105
|
+
context
|
1106
|
+
);
|
1107
|
+
};
|
1108
|
+
|
1109
|
+
// src/transforms/vIf.ts
|
1110
|
+
|
1111
|
+
|
1112
|
+
|
1113
|
+
|
1114
|
+
|
1115
|
+
|
1116
|
+
var transformVIf = createStructuralDirectiveTransform(
|
1117
|
+
["if", "else", "else-if"],
|
1118
|
+
processIf
|
1119
|
+
);
|
1120
|
+
var transformedIfNode = /* @__PURE__ */ new WeakMap();
|
1121
|
+
function processIf(node, attribute, context) {
|
1122
|
+
const dir = resolveDirectiveNode(attribute, context);
|
1123
|
+
if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
|
1124
|
+
const loc = dir.exp ? dir.exp.loc : resolveLocation(node.loc, context);
|
1125
|
+
context.options.onError(
|
1126
|
+
_compilerdom.createCompilerError.call(void 0, _compilerdom.ErrorCodes.X_V_IF_NO_EXPRESSION, dir.loc)
|
1127
|
+
);
|
1128
|
+
dir.exp = _compilerdom.createSimpleExpression.call(void 0, `true`, false, loc);
|
1129
|
+
}
|
1130
|
+
context.dynamic.flags |= 2 /* NON_TEMPLATE */;
|
1131
|
+
transformedIfNode.set(node, dir);
|
1132
|
+
if (dir.name === "if") {
|
1133
|
+
const id = context.reference();
|
1134
|
+
context.dynamic.flags |= 4 /* INSERT */;
|
1135
|
+
const [branch, onExit] = createBranch(node, context);
|
1136
|
+
return () => {
|
1137
|
+
onExit();
|
1138
|
+
context.registerOperation({
|
1139
|
+
type: 16 /* IF */,
|
1140
|
+
id,
|
1141
|
+
condition: dir.exp,
|
1142
|
+
positive: branch,
|
1143
|
+
once: context.inVOnce || _compilerdom.isConstantNode.call(void 0, attribute.value, context.options.bindingMetadata)
|
1144
|
+
});
|
1145
|
+
};
|
1146
|
+
} else {
|
1147
|
+
const siblingIf = getSiblingIf(context);
|
1148
|
+
const { operation } = context.block;
|
1149
|
+
let lastIfNode = operation.at(-1);
|
1150
|
+
if (
|
1151
|
+
// check if v-if is the sibling node
|
1152
|
+
!siblingIf || // check if IfNode is the last operation and get the root IfNode
|
1153
|
+
!lastIfNode || lastIfNode.type !== 16 /* IF */
|
1154
|
+
) {
|
1155
|
+
context.options.onError(
|
1156
|
+
_compilerdom.createCompilerError.call(void 0,
|
1157
|
+
_compilerdom.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
|
1158
|
+
resolveLocation(node.loc, context)
|
1159
|
+
)
|
1160
|
+
);
|
1161
|
+
return;
|
1162
|
+
}
|
1163
|
+
while (lastIfNode.negative && lastIfNode.negative.type === 16 /* IF */) {
|
1164
|
+
lastIfNode = lastIfNode.negative;
|
1165
|
+
}
|
1166
|
+
if (dir.name === "else-if" && lastIfNode.negative) {
|
1167
|
+
context.options.onError(
|
1168
|
+
_compilerdom.createCompilerError.call(void 0,
|
1169
|
+
_compilerdom.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
|
1170
|
+
resolveLocation(node.loc, context)
|
1171
|
+
)
|
1172
|
+
);
|
1173
|
+
}
|
1174
|
+
context.root.comment = [];
|
1175
|
+
const [branch, onExit] = createBranch(node, context);
|
1176
|
+
if (dir.name === "else") {
|
1177
|
+
lastIfNode.negative = branch;
|
1178
|
+
} else {
|
1179
|
+
lastIfNode.negative = {
|
1180
|
+
type: 16 /* IF */,
|
1181
|
+
id: -1,
|
1182
|
+
condition: dir.exp,
|
1183
|
+
positive: branch,
|
1184
|
+
once: context.inVOnce
|
1185
|
+
};
|
1186
|
+
}
|
1187
|
+
return () => onExit();
|
1188
|
+
}
|
1189
|
+
}
|
1190
|
+
function getSiblingIf(context) {
|
1191
|
+
const parent = context.parent;
|
1192
|
+
if (!parent) return;
|
1193
|
+
const siblings = parent.node.children;
|
1194
|
+
let sibling;
|
1195
|
+
let i = siblings.indexOf(context.node);
|
1196
|
+
while (--i >= 0) {
|
1197
|
+
if (!isEmptyText(siblings[i])) {
|
1198
|
+
sibling = siblings[i];
|
1199
|
+
break;
|
1200
|
+
}
|
1201
|
+
}
|
1202
|
+
if (sibling && sibling.type === "JSXElement" && transformedIfNode.has(sibling)) {
|
1203
|
+
return sibling;
|
1204
|
+
}
|
1205
|
+
}
|
1206
|
+
|
1207
|
+
// src/transforms/vModel.ts
|
1208
|
+
|
1209
|
+
var transformVModel = (dir, node, context) => {
|
1210
|
+
return _compilervapor.transformVModel.call(void 0,
|
1211
|
+
resolveDirectiveNode(dir, context),
|
1212
|
+
resolveNode(node, context),
|
1213
|
+
context
|
1214
|
+
);
|
1215
|
+
};
|
1216
|
+
|
1217
|
+
// src/transforms/vOn.ts
|
1218
|
+
|
1219
|
+
|
1220
|
+
|
1221
|
+
|
1222
|
+
|
1223
|
+
|
1224
|
+
|
1225
|
+
var delegatedEvents = /* @__PURE__ */ _shared.makeMap.call(void 0,
|
1226
|
+
"beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart"
|
1227
|
+
);
|
1228
|
+
var transformVOn = (dir, node, context) => {
|
1229
|
+
const { name, loc, value } = dir;
|
1230
|
+
if (name.type === "JSXNamespacedName") return;
|
1231
|
+
const isComponent = isJSXComponent(node);
|
1232
|
+
const [nameString, ...modifiers] = name.name.replace(/^on([A-Z])/, (_, $1) => $1.toLowerCase()).split("_");
|
1233
|
+
if (!value && !modifiers.length) {
|
1234
|
+
context.options.onError(
|
1235
|
+
_compilerdom.createCompilerError.call(void 0,
|
1236
|
+
_compilerdom.ErrorCodes.X_V_ON_NO_EXPRESSION,
|
1237
|
+
resolveLocation(loc, context)
|
1238
|
+
)
|
1239
|
+
);
|
1240
|
+
}
|
1241
|
+
let arg = resolveSimpleExpression(nameString, true, dir.name.loc);
|
1242
|
+
const exp = resolveExpression(dir.value, context);
|
1243
|
+
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = _compilerdom.resolveModifiers.call(void 0,
|
1244
|
+
arg.isStatic ? `on${nameString}` : arg,
|
1245
|
+
modifiers.map((modifier) => _compilerdom.createSimpleExpression.call(void 0, modifier)),
|
1246
|
+
null,
|
1247
|
+
resolveLocation(loc, context)
|
1248
|
+
);
|
1249
|
+
let keyOverride;
|
1250
|
+
const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
|
1251
|
+
if (nonKeyModifiers.includes("middle")) {
|
1252
|
+
if (keyOverride) {
|
1253
|
+
}
|
1254
|
+
if (isStaticClick) {
|
1255
|
+
arg = _shared.extend.call(void 0, {}, arg, { content: "mouseup" });
|
1256
|
+
} else if (!arg.isStatic) {
|
1257
|
+
keyOverride = ["click", "mouseup"];
|
1258
|
+
}
|
1259
|
+
}
|
1260
|
+
if (nonKeyModifiers.includes("right")) {
|
1261
|
+
if (isStaticClick) {
|
1262
|
+
arg = _shared.extend.call(void 0, {}, arg, { content: "contextmenu" });
|
1263
|
+
} else if (!arg.isStatic) {
|
1264
|
+
keyOverride = ["click", "contextmenu"];
|
1265
|
+
}
|
1266
|
+
}
|
1267
|
+
if (isComponent) {
|
1268
|
+
const handler = exp || EMPTY_EXPRESSION;
|
1269
|
+
return {
|
1270
|
+
key: arg,
|
1271
|
+
value: handler,
|
1272
|
+
handler: true,
|
1273
|
+
handlerModifiers: eventOptionModifiers
|
1274
|
+
};
|
1275
|
+
}
|
1276
|
+
const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
|
1277
|
+
const operation = {
|
1278
|
+
type: 5 /* SET_EVENT */,
|
1279
|
+
element: context.reference(),
|
1280
|
+
key: arg,
|
1281
|
+
value: exp,
|
1282
|
+
modifiers: {
|
1283
|
+
keys: keyModifiers,
|
1284
|
+
nonKeys: nonKeyModifiers,
|
1285
|
+
options: eventOptionModifiers
|
1286
|
+
},
|
1287
|
+
keyOverride,
|
1288
|
+
delegate,
|
1289
|
+
effect: !arg.isStatic
|
1290
|
+
};
|
1291
|
+
context.registerEffect([arg], operation);
|
1292
|
+
};
|
1293
|
+
|
1294
|
+
// src/transforms/vOnce.ts
|
1295
|
+
var transformVOnce = (node, context) => {
|
1296
|
+
if (
|
1297
|
+
// !context.inSSR &&
|
1298
|
+
node.type === "JSXElement" && findProp(node, "v-once")
|
1299
|
+
) {
|
1300
|
+
context.inVOnce = true;
|
1301
|
+
}
|
1302
|
+
};
|
1303
|
+
|
1304
|
+
// src/transforms/vShow.ts
|
1305
|
+
|
1306
|
+
var transformVShow = (dir, node, context) => {
|
1307
|
+
return _compilervapor.transformVShow.call(void 0,
|
1308
|
+
resolveDirectiveNode(dir, context),
|
1309
|
+
resolveNode(node, context),
|
1310
|
+
context
|
1311
|
+
);
|
1312
|
+
};
|
1313
|
+
|
1314
|
+
// src/transforms/vSlot.ts
|
1315
|
+
|
1316
|
+
|
1317
|
+
|
1318
|
+
|
1319
|
+
var transformVSlot = (node, context) => {
|
1320
|
+
if (node.type !== "JSXElement") return;
|
1321
|
+
const { children } = node;
|
1322
|
+
const dir = findProp(node, "v-slot");
|
1323
|
+
const resolvedDirective = dir ? resolveDirectiveNode(dir, context, true) : void 0;
|
1324
|
+
const { parent } = context;
|
1325
|
+
const isComponent = isJSXComponent(node);
|
1326
|
+
const isSlotTemplate = isTemplate(node) && parent && parent.node.type === "JSXElement" && isJSXComponent(parent.node);
|
1327
|
+
if (isComponent && children.length) {
|
1328
|
+
return transformComponentSlot(node, resolvedDirective, context);
|
1329
|
+
} else if (isSlotTemplate && resolvedDirective) {
|
1330
|
+
return transformTemplateSlot(node, resolvedDirective, context);
|
1331
|
+
} else if (!isComponent && dir) {
|
1332
|
+
context.options.onError(
|
1333
|
+
_compilerdom.createCompilerError.call(void 0,
|
1334
|
+
_compilerdom.ErrorCodes.X_V_SLOT_MISPLACED,
|
1335
|
+
resolveLocation(dir.loc, context)
|
1336
|
+
)
|
1201
1337
|
);
|
1202
1338
|
}
|
1203
1339
|
};
|
@@ -1205,7 +1341,7 @@ function transformComponentSlot(node, dir, context) {
|
|
1205
1341
|
const { children } = node;
|
1206
1342
|
const arg = dir && dir.arg;
|
1207
1343
|
const nonSlotTemplateChildren = children.filter(
|
1208
|
-
(n) => !isEmptyText(n) &&
|
1344
|
+
(n) => !isEmptyText(n) && (n.type !== "JSXElement" || !findProp(n, "v-slot"))
|
1209
1345
|
);
|
1210
1346
|
const [block, onExit] = createSlotBlock(node, dir, context);
|
1211
1347
|
const { slots } = context;
|
@@ -1374,144 +1510,6 @@ var transformVSlots = (node, context) => {
|
|
1374
1510
|
}
|
1375
1511
|
};
|
1376
1512
|
|
1377
|
-
// src/transforms/vModel.ts
|
1378
|
-
|
1379
|
-
var transformVModel = (dir, node, context) => {
|
1380
|
-
return _compilervapor.transformVModel.call(void 0,
|
1381
|
-
resolveDirectiveNode(dir, context),
|
1382
|
-
resolveNode(node, context),
|
1383
|
-
context
|
1384
|
-
);
|
1385
|
-
};
|
1386
|
-
|
1387
|
-
// src/transforms/vShow.ts
|
1388
|
-
|
1389
|
-
var transformVShow = (dir, node, context) => {
|
1390
|
-
return _compilervapor.transformVShow.call(void 0,
|
1391
|
-
resolveDirectiveNode(dir, context),
|
1392
|
-
resolveNode(node, context),
|
1393
|
-
context
|
1394
|
-
);
|
1395
|
-
};
|
1396
|
-
|
1397
|
-
// src/transforms/vHtml.ts
|
1398
|
-
|
1399
|
-
var transformVHtml = (dir, node, context) => {
|
1400
|
-
return _compilervapor.transformVHtml.call(void 0,
|
1401
|
-
resolveDirectiveNode(dir, context),
|
1402
|
-
resolveNode(node, context),
|
1403
|
-
context
|
1404
|
-
);
|
1405
|
-
};
|
1406
|
-
|
1407
|
-
// src/transforms/vOnce.ts
|
1408
|
-
var transformVOnce = (node, context) => {
|
1409
|
-
if (
|
1410
|
-
// !context.inSSR &&
|
1411
|
-
node.type === "JSXElement" && findProp(node, "v-once")
|
1412
|
-
) {
|
1413
|
-
context.inVOnce = true;
|
1414
|
-
}
|
1415
|
-
};
|
1416
|
-
|
1417
|
-
// src/transforms/vIf.ts
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
var transformVIf = createStructuralDirectiveTransform(
|
1425
|
-
["if", "else", "else-if"],
|
1426
|
-
processIf
|
1427
|
-
);
|
1428
|
-
var transformedIfNode = /* @__PURE__ */ new WeakMap();
|
1429
|
-
function processIf(node, attribute, context) {
|
1430
|
-
const dir = resolveDirectiveNode(attribute, context);
|
1431
|
-
if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
|
1432
|
-
const loc = dir.exp ? dir.exp.loc : resolveLocation(node.loc, context);
|
1433
|
-
context.options.onError(
|
1434
|
-
_compilerdom.createCompilerError.call(void 0, _compilerdom.ErrorCodes.X_V_IF_NO_EXPRESSION, dir.loc)
|
1435
|
-
);
|
1436
|
-
dir.exp = _compilerdom.createSimpleExpression.call(void 0, `true`, false, loc);
|
1437
|
-
}
|
1438
|
-
context.dynamic.flags |= 2 /* NON_TEMPLATE */;
|
1439
|
-
transformedIfNode.set(node, dir);
|
1440
|
-
if (dir.name === "if") {
|
1441
|
-
const id = context.reference();
|
1442
|
-
context.dynamic.flags |= 4 /* INSERT */;
|
1443
|
-
const [branch, onExit] = createBranch(node, context);
|
1444
|
-
return () => {
|
1445
|
-
onExit();
|
1446
|
-
context.registerOperation({
|
1447
|
-
type: 16 /* IF */,
|
1448
|
-
id,
|
1449
|
-
condition: dir.exp,
|
1450
|
-
positive: branch,
|
1451
|
-
once: context.inVOnce || _compilerdom.isConstantNode.call(void 0, attribute.value, context.options.bindingMetadata)
|
1452
|
-
});
|
1453
|
-
};
|
1454
|
-
} else {
|
1455
|
-
const siblingIf = getSiblingIf(context);
|
1456
|
-
const { operation } = context.block;
|
1457
|
-
let lastIfNode = operation.at(-1);
|
1458
|
-
if (
|
1459
|
-
// check if v-if is the sibling node
|
1460
|
-
!siblingIf || // check if IfNode is the last operation and get the root IfNode
|
1461
|
-
!lastIfNode || lastIfNode.type !== 16 /* IF */
|
1462
|
-
) {
|
1463
|
-
context.options.onError(
|
1464
|
-
_compilerdom.createCompilerError.call(void 0,
|
1465
|
-
_compilerdom.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
|
1466
|
-
resolveLocation(node.loc, context)
|
1467
|
-
)
|
1468
|
-
);
|
1469
|
-
return;
|
1470
|
-
}
|
1471
|
-
while (lastIfNode.negative && lastIfNode.negative.type === 16 /* IF */) {
|
1472
|
-
lastIfNode = lastIfNode.negative;
|
1473
|
-
}
|
1474
|
-
if (dir.name === "else-if" && lastIfNode.negative) {
|
1475
|
-
context.options.onError(
|
1476
|
-
_compilerdom.createCompilerError.call(void 0,
|
1477
|
-
_compilerdom.ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
|
1478
|
-
resolveLocation(node.loc, context)
|
1479
|
-
)
|
1480
|
-
);
|
1481
|
-
}
|
1482
|
-
context.root.comment = [];
|
1483
|
-
const [branch, onExit] = createBranch(node, context);
|
1484
|
-
if (dir.name === "else") {
|
1485
|
-
lastIfNode.negative = branch;
|
1486
|
-
} else {
|
1487
|
-
lastIfNode.negative = {
|
1488
|
-
type: 16 /* IF */,
|
1489
|
-
id: -1,
|
1490
|
-
condition: dir.exp,
|
1491
|
-
positive: branch,
|
1492
|
-
once: context.inVOnce
|
1493
|
-
};
|
1494
|
-
}
|
1495
|
-
return () => onExit();
|
1496
|
-
}
|
1497
|
-
}
|
1498
|
-
function getSiblingIf(context) {
|
1499
|
-
const parent = context.parent;
|
1500
|
-
if (!parent) return;
|
1501
|
-
const siblings = parent.node.children;
|
1502
|
-
let sibling;
|
1503
|
-
let i = siblings.indexOf(context.node);
|
1504
|
-
while (--i >= 0) {
|
1505
|
-
if (!isEmptyText(siblings[i])) {
|
1506
|
-
sibling = siblings[i];
|
1507
|
-
break;
|
1508
|
-
}
|
1509
|
-
}
|
1510
|
-
if (sibling && sibling.type === "JSXElement" && transformedIfNode.has(sibling)) {
|
1511
|
-
return sibling;
|
1512
|
-
}
|
1513
|
-
}
|
1514
|
-
|
1515
1513
|
// src/compile.ts
|
1516
1514
|
function compile(source, options = {}) {
|
1517
1515
|
const resolvedOptions = _shared.extend.call(void 0, {}, options, {
|