@vue-jsx-vapor/compiler 2.3.0 → 2.3.2
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 +1305 -1581
- package/dist/index.d.cts +52 -12
- package/dist/index.d.ts +52 -12
- package/dist/index.js +1254 -1579
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,1727 +1,1402 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
} from "@
|
|
6
|
-
import { extend as extend5, isString as isString3 } from "@vue/shared";
|
|
1
|
+
import { parse, parseExpression } from "@babel/parser";
|
|
2
|
+
import { NEWLINE, genCall, genExpression, generate } from "@vue/compiler-vapor";
|
|
3
|
+
import { EMPTY_OBJ, NOOP, camelize, extend, isArray, isBuiltInDirective, isGloballyAllowed, isHTMLTag, isSVGTag, isString, isVoidTag, makeMap } from "@vue/shared";
|
|
4
|
+
import { DOMErrorCodes, ErrorCodes, NodeTypes, createCompilerError, createDOMCompilerError, createSimpleExpression, defaultOnError, defaultOnWarn, isConstantNode, isLiteralWhitelisted, isMemberExpression, isStaticNode, isValidHTMLNesting, resolveModifiers, walkIdentifiers } from "@vue/compiler-dom";
|
|
5
|
+
import { isLiteral, jsxClosingFragment, jsxExpressionContainer, jsxFragment, jsxOpeningFragment } from "@babel/types";
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
7
|
+
//#region src/ir/component.ts
|
|
8
|
+
let IRDynamicPropsKind = /* @__PURE__ */ function(IRDynamicPropsKind$1) {
|
|
9
|
+
IRDynamicPropsKind$1[IRDynamicPropsKind$1["EXPRESSION"] = 0] = "EXPRESSION";
|
|
10
|
+
IRDynamicPropsKind$1[IRDynamicPropsKind$1["ATTRIBUTE"] = 1] = "ATTRIBUTE";
|
|
11
|
+
return IRDynamicPropsKind$1;
|
|
12
|
+
}({});
|
|
13
|
+
let IRSlotType = /* @__PURE__ */ function(IRSlotType$1) {
|
|
14
|
+
IRSlotType$1[IRSlotType$1["STATIC"] = 0] = "STATIC";
|
|
15
|
+
IRSlotType$1[IRSlotType$1["DYNAMIC"] = 1] = "DYNAMIC";
|
|
16
|
+
IRSlotType$1[IRSlotType$1["LOOP"] = 2] = "LOOP";
|
|
17
|
+
IRSlotType$1[IRSlotType$1["CONDITIONAL"] = 3] = "CONDITIONAL";
|
|
18
|
+
IRSlotType$1[IRSlotType$1["EXPRESSION"] = 4] = "EXPRESSION";
|
|
19
|
+
return IRSlotType$1;
|
|
20
|
+
}({});
|
|
14
21
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
DynamicFlag2[DynamicFlag2["REFERENCED"] = 1] = "REFERENCED";
|
|
57
|
-
DynamicFlag2[DynamicFlag2["NON_TEMPLATE"] = 2] = "NON_TEMPLATE";
|
|
58
|
-
DynamicFlag2[DynamicFlag2["INSERT"] = 4] = "INSERT";
|
|
59
|
-
return DynamicFlag2;
|
|
60
|
-
})(DynamicFlag || {});
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/ir/index.ts
|
|
24
|
+
let IRNodeTypes = /* @__PURE__ */ function(IRNodeTypes$1) {
|
|
25
|
+
IRNodeTypes$1[IRNodeTypes$1["ROOT"] = 0] = "ROOT";
|
|
26
|
+
IRNodeTypes$1[IRNodeTypes$1["BLOCK"] = 1] = "BLOCK";
|
|
27
|
+
IRNodeTypes$1[IRNodeTypes$1["SET_PROP"] = 2] = "SET_PROP";
|
|
28
|
+
IRNodeTypes$1[IRNodeTypes$1["SET_DYNAMIC_PROPS"] = 3] = "SET_DYNAMIC_PROPS";
|
|
29
|
+
IRNodeTypes$1[IRNodeTypes$1["SET_TEXT"] = 4] = "SET_TEXT";
|
|
30
|
+
IRNodeTypes$1[IRNodeTypes$1["SET_EVENT"] = 5] = "SET_EVENT";
|
|
31
|
+
IRNodeTypes$1[IRNodeTypes$1["SET_DYNAMIC_EVENTS"] = 6] = "SET_DYNAMIC_EVENTS";
|
|
32
|
+
IRNodeTypes$1[IRNodeTypes$1["SET_HTML"] = 7] = "SET_HTML";
|
|
33
|
+
IRNodeTypes$1[IRNodeTypes$1["SET_TEMPLATE_REF"] = 8] = "SET_TEMPLATE_REF";
|
|
34
|
+
IRNodeTypes$1[IRNodeTypes$1["INSERT_NODE"] = 9] = "INSERT_NODE";
|
|
35
|
+
IRNodeTypes$1[IRNodeTypes$1["PREPEND_NODE"] = 10] = "PREPEND_NODE";
|
|
36
|
+
IRNodeTypes$1[IRNodeTypes$1["CREATE_COMPONENT_NODE"] = 11] = "CREATE_COMPONENT_NODE";
|
|
37
|
+
IRNodeTypes$1[IRNodeTypes$1["SLOT_OUTLET_NODE"] = 12] = "SLOT_OUTLET_NODE";
|
|
38
|
+
IRNodeTypes$1[IRNodeTypes$1["DIRECTIVE"] = 13] = "DIRECTIVE";
|
|
39
|
+
IRNodeTypes$1[IRNodeTypes$1["DECLARE_OLD_REF"] = 14] = "DECLARE_OLD_REF";
|
|
40
|
+
IRNodeTypes$1[IRNodeTypes$1["IF"] = 15] = "IF";
|
|
41
|
+
IRNodeTypes$1[IRNodeTypes$1["FOR"] = 16] = "FOR";
|
|
42
|
+
IRNodeTypes$1[IRNodeTypes$1["GET_TEXT_CHILD"] = 17] = "GET_TEXT_CHILD";
|
|
43
|
+
IRNodeTypes$1[IRNodeTypes$1["CREATE_NODES"] = 18] = "CREATE_NODES";
|
|
44
|
+
IRNodeTypes$1[IRNodeTypes$1["SET_NODES"] = 19] = "SET_NODES";
|
|
45
|
+
return IRNodeTypes$1;
|
|
46
|
+
}({});
|
|
47
|
+
let DynamicFlag = /* @__PURE__ */ function(DynamicFlag$1) {
|
|
48
|
+
DynamicFlag$1[DynamicFlag$1["NONE"] = 0] = "NONE";
|
|
49
|
+
/**
|
|
50
|
+
* This node is referenced and needs to be saved as a variable.
|
|
51
|
+
*/
|
|
52
|
+
DynamicFlag$1[DynamicFlag$1["REFERENCED"] = 1] = "REFERENCED";
|
|
53
|
+
/**
|
|
54
|
+
* This node is not generated from template, but is generated dynamically.
|
|
55
|
+
*/
|
|
56
|
+
DynamicFlag$1[DynamicFlag$1["NON_TEMPLATE"] = 2] = "NON_TEMPLATE";
|
|
57
|
+
/**
|
|
58
|
+
* This node needs to be inserted back into the template.
|
|
59
|
+
*/
|
|
60
|
+
DynamicFlag$1[DynamicFlag$1["INSERT"] = 4] = "INSERT";
|
|
61
|
+
return DynamicFlag$1;
|
|
62
|
+
}({});
|
|
61
63
|
function isBlockOperation(op) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
+
const type = op.type;
|
|
65
|
+
return type === IRNodeTypes.CREATE_COMPONENT_NODE || type === IRNodeTypes.SLOT_OUTLET_NODE || type === IRNodeTypes.IF || type === IRNodeTypes.FOR;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return genSetNodes(oper, context);
|
|
72
|
-
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/generate.ts
|
|
70
|
+
const customGenOperation = (oper, context) => {
|
|
71
|
+
if (oper.type === IRNodeTypes.CREATE_NODES) return genCreateNodes(oper, context);
|
|
72
|
+
else if (oper.type === IRNodeTypes.SET_NODES) return genSetNodes(oper, context);
|
|
73
73
|
};
|
|
74
74
|
function genSetNodes(oper, context) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
NEWLINE,
|
|
79
|
-
...genCall(
|
|
80
|
-
helper("setNodes"),
|
|
81
|
-
`${generated ? "x" : "n"}${element}`,
|
|
82
|
-
combineValues(values, context)
|
|
83
|
-
)
|
|
84
|
-
];
|
|
75
|
+
const { helper } = context;
|
|
76
|
+
const { element, values, generated } = oper;
|
|
77
|
+
return [NEWLINE, ...genCall(helper("setNodes"), `${generated ? "x" : "n"}${element}`, combineValues(values, context))];
|
|
85
78
|
}
|
|
86
79
|
function genCreateNodes(oper, context) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
80
|
+
const { helper } = context;
|
|
81
|
+
const { id, values } = oper;
|
|
82
|
+
return [
|
|
83
|
+
NEWLINE,
|
|
84
|
+
`const n${id} = `,
|
|
85
|
+
...genCall(helper("createNodes"), values && combineValues(values, context))
|
|
86
|
+
];
|
|
94
87
|
}
|
|
95
88
|
function combineValues(values, context) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return exp;
|
|
102
|
-
});
|
|
89
|
+
return values.flatMap((value, i) => {
|
|
90
|
+
const exp = genExpression(value, context);
|
|
91
|
+
if (i > 0) exp.unshift(", ");
|
|
92
|
+
return exp;
|
|
93
|
+
});
|
|
103
94
|
}
|
|
104
95
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
defaultOnError,
|
|
108
|
-
defaultOnWarn
|
|
109
|
-
} from "@vue/compiler-dom";
|
|
110
|
-
import { EMPTY_OBJ, extend, isArray, isString as isString2, NOOP } from "@vue/shared";
|
|
111
|
-
|
|
112
|
-
// src/transforms/utils.ts
|
|
113
|
-
import {
|
|
114
|
-
jsxClosingFragment,
|
|
115
|
-
jsxExpressionContainer,
|
|
116
|
-
jsxFragment,
|
|
117
|
-
jsxOpeningFragment
|
|
118
|
-
} from "@babel/types";
|
|
119
|
-
import { createSimpleExpression as createSimpleExpression2 } from "@vue/compiler-dom";
|
|
120
|
-
|
|
121
|
-
// src/utils.ts
|
|
122
|
-
import { parseExpression } from "@babel/parser";
|
|
123
|
-
import {
|
|
124
|
-
isLiteral
|
|
125
|
-
} from "@babel/types";
|
|
126
|
-
import {
|
|
127
|
-
createSimpleExpression,
|
|
128
|
-
ElementTypes,
|
|
129
|
-
isLiteralWhitelisted,
|
|
130
|
-
Namespaces,
|
|
131
|
-
NodeTypes,
|
|
132
|
-
walkIdentifiers
|
|
133
|
-
} from "@vue/compiler-dom";
|
|
134
|
-
import { isGloballyAllowed, isHTMLTag, isString, isSVGTag } from "@vue/shared";
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/utils.ts
|
|
135
98
|
function propToExpression(prop, context) {
|
|
136
|
-
|
|
99
|
+
return prop.type === "JSXAttribute" && prop.value?.type === "JSXExpressionContainer" ? resolveExpression(prop.value.expression, context) : EMPTY_EXPRESSION;
|
|
137
100
|
}
|
|
138
101
|
function isConstantExpression(exp) {
|
|
139
|
-
|
|
102
|
+
return isLiteralWhitelisted(exp.content) || isGloballyAllowed(exp.content) || getLiteralExpressionValue(exp) !== null;
|
|
140
103
|
}
|
|
141
104
|
function getLiteralExpressionValue(exp) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return exp.isStatic ? exp.content : null;
|
|
105
|
+
if (exp.ast) {
|
|
106
|
+
if ([
|
|
107
|
+
"StringLiteral",
|
|
108
|
+
"NumericLiteral",
|
|
109
|
+
"BigIntLiteral"
|
|
110
|
+
].includes(exp.ast.type)) return exp.ast.value;
|
|
111
|
+
else if (exp.ast.type === "TemplateLiteral" && exp.ast.expressions.length === 0) return exp.ast.quasis[0].value.cooked;
|
|
112
|
+
}
|
|
113
|
+
return exp.isStatic ? exp.content : null;
|
|
152
114
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return node.properties.every(
|
|
164
|
-
(property) => isConstant(property.value)
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
if (node.type === "TemplateLiteral" ? !node.expressions.length : isLiteral(node)) {
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
170
|
-
return false;
|
|
115
|
+
const isConstant = (node) => {
|
|
116
|
+
if (!node) return false;
|
|
117
|
+
if (node.type === "Identifier") return node.name === "undefined";
|
|
118
|
+
if (node.type === "ArrayExpression") {
|
|
119
|
+
const { elements } = node;
|
|
120
|
+
return elements.every((element) => element && isConstant(element));
|
|
121
|
+
}
|
|
122
|
+
if (node.type === "ObjectExpression") return node.properties.every((property) => isConstant(property.value));
|
|
123
|
+
if (node.type === "TemplateLiteral" ? !node.expressions.length : isLiteral(node)) return true;
|
|
124
|
+
return false;
|
|
171
125
|
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
126
|
+
const EMPTY_TEXT_REGEX = /^[\t\v\f \u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*[\n\r]\s*$/;
|
|
127
|
+
const START_EMPTY_TEXT_REGEX = /^\s*[\n\r]/;
|
|
128
|
+
const END_EMPTY_TEXT_REGEX = /[\n\r]\s*$/;
|
|
175
129
|
function resolveJSXText(node) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
value = value.trimStart();
|
|
182
|
-
}
|
|
183
|
-
if (END_EMPTY_TEXT_REGEX.test(value)) {
|
|
184
|
-
value = value.trimEnd();
|
|
185
|
-
}
|
|
186
|
-
return value;
|
|
130
|
+
if (EMPTY_TEXT_REGEX.test(String(node.extra?.raw))) return "";
|
|
131
|
+
let value = node.value;
|
|
132
|
+
if (START_EMPTY_TEXT_REGEX.test(value)) value = value.trimStart();
|
|
133
|
+
if (END_EMPTY_TEXT_REGEX.test(value)) value = value.trimEnd();
|
|
134
|
+
return value;
|
|
187
135
|
}
|
|
188
136
|
function isEmptyText(node) {
|
|
189
|
-
|
|
137
|
+
return node.type === "JSXText" && EMPTY_TEXT_REGEX.test(String(node.extra?.raw)) || node.type === "JSXExpressionContainer" && node.expression.type === "JSXEmptyExpression";
|
|
190
138
|
}
|
|
191
139
|
function resolveSimpleExpressionNode(exp) {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
return exp;
|
|
140
|
+
if (!exp.isStatic) {
|
|
141
|
+
const value = getLiteralExpressionValue(exp);
|
|
142
|
+
if (value !== null) return createSimpleExpression(String(value), true, exp.loc);
|
|
143
|
+
}
|
|
144
|
+
return exp;
|
|
199
145
|
}
|
|
146
|
+
const resolvedExpressions = new WeakSet();
|
|
200
147
|
function resolveExpression(node, context, effect = false) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
return resolveSimpleExpression(source, isStatic, location, node);
|
|
148
|
+
node = node?.type === "JSXExpressionContainer" ? node.expression : node;
|
|
149
|
+
const isStatic = !!node && (node.type === "StringLiteral" || node.type === "JSXText" || node.type === "JSXIdentifier");
|
|
150
|
+
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);
|
|
151
|
+
const location = node ? node.loc : null;
|
|
152
|
+
const isResolved = node && resolvedExpressions.has(node);
|
|
153
|
+
if (source && !isStatic && effect && !isConstant(node)) {
|
|
154
|
+
source = `() => (${source})`;
|
|
155
|
+
if (location && node && !isResolved) {
|
|
156
|
+
location.start.column -= 7;
|
|
157
|
+
node.start -= 7;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (node && !isResolved) {
|
|
161
|
+
const offset = node.start - 1;
|
|
162
|
+
walkIdentifiers(node, (id) => {
|
|
163
|
+
if (!id.loc) return;
|
|
164
|
+
id.start = id.loc.start.index - offset;
|
|
165
|
+
id.end = id.loc.end.index - offset;
|
|
166
|
+
}, true);
|
|
167
|
+
resolvedExpressions.add(node);
|
|
168
|
+
}
|
|
169
|
+
return resolveSimpleExpression(source, isStatic, location, node);
|
|
225
170
|
}
|
|
226
171
|
function resolveSimpleExpression(source, isStatic, location, ast) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
resolveLocation(location, source)
|
|
231
|
-
);
|
|
232
|
-
result.ast = ast ?? null;
|
|
233
|
-
return result;
|
|
172
|
+
const result = createSimpleExpression(source, isStatic, resolveLocation(location, source));
|
|
173
|
+
result.ast = ast ?? null;
|
|
174
|
+
return result;
|
|
234
175
|
}
|
|
235
176
|
function resolveLocation(location, context) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
177
|
+
return location ? {
|
|
178
|
+
start: {
|
|
179
|
+
line: location.start.line,
|
|
180
|
+
column: location.start.column + 1,
|
|
181
|
+
offset: location.start.index
|
|
182
|
+
},
|
|
183
|
+
end: {
|
|
184
|
+
line: location.end.line,
|
|
185
|
+
column: location.end.column + 1,
|
|
186
|
+
offset: location.end.index
|
|
187
|
+
},
|
|
188
|
+
source: isString(context) ? context : context.ir.source.slice(location.start.index, location.end.index)
|
|
189
|
+
} : {
|
|
190
|
+
start: {
|
|
191
|
+
line: 1,
|
|
192
|
+
column: 1,
|
|
193
|
+
offset: 0
|
|
194
|
+
},
|
|
195
|
+
end: {
|
|
196
|
+
line: 1,
|
|
197
|
+
column: 1,
|
|
198
|
+
offset: 0
|
|
199
|
+
},
|
|
200
|
+
source: ""
|
|
201
|
+
};
|
|
253
202
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
arg: void 0,
|
|
287
|
-
loc: resolveLocation(node.loc, context),
|
|
288
|
-
modifiers: []
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
return result;
|
|
292
|
-
},
|
|
293
|
-
[]
|
|
294
|
-
);
|
|
295
|
-
return {
|
|
296
|
-
type: NodeTypes.ELEMENT,
|
|
297
|
-
props,
|
|
298
|
-
children: node.children,
|
|
299
|
-
tag,
|
|
300
|
-
loc,
|
|
301
|
-
ns: Namespaces.HTML,
|
|
302
|
-
tagType,
|
|
303
|
-
isSelfClosing: !!node.selfClosing,
|
|
304
|
-
codegenNode: void 0
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
var namespaceRE = /^(?:\$([\w-]+)\$)?([\w-]+)?/;
|
|
308
|
-
function resolveDirectiveNode(node, context, withFn = false) {
|
|
309
|
-
const { value, name } = node;
|
|
310
|
-
let nameString = name.type === "JSXNamespacedName" ? name.namespace.name : name.type === "JSXIdentifier" ? name.name : "";
|
|
311
|
-
const isDirective = nameString.startsWith("v-");
|
|
312
|
-
let modifiers = [];
|
|
313
|
-
let isStatic = true;
|
|
314
|
-
let argString = name.type === "JSXNamespacedName" ? name.name.name : "";
|
|
315
|
-
if (name.type !== "JSXNamespacedName" && !argString) {
|
|
316
|
-
;
|
|
317
|
-
[nameString, ...modifiers] = nameString.split("_");
|
|
318
|
-
} else {
|
|
319
|
-
const result = argString.match(namespaceRE);
|
|
320
|
-
if (result) {
|
|
321
|
-
let modifierString = "";
|
|
322
|
-
[, argString, modifierString] = result;
|
|
323
|
-
if (argString) {
|
|
324
|
-
argString = argString.replaceAll("_", ".");
|
|
325
|
-
isStatic = false;
|
|
326
|
-
if (modifierString && modifierString.startsWith("_"))
|
|
327
|
-
modifiers = modifierString.slice(1).split("_");
|
|
328
|
-
} else if (modifierString) {
|
|
329
|
-
;
|
|
330
|
-
[argString, ...modifiers] = modifierString.split("_");
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
const arg = isDirective ? argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0 : resolveSimpleExpression(nameString, true, name.loc);
|
|
335
|
-
const exp = value ? withFn && value.type === "JSXExpressionContainer" ? resolveExpressionWithFn(value.expression, context) : resolveExpression(value, context) : void 0;
|
|
336
|
-
return {
|
|
337
|
-
type: NodeTypes.DIRECTIVE,
|
|
338
|
-
name: isDirective ? nameString.slice(2) : "bind",
|
|
339
|
-
rawName: getText(name, context),
|
|
340
|
-
exp,
|
|
341
|
-
arg,
|
|
342
|
-
loc: resolveLocation(node.loc, context),
|
|
343
|
-
modifiers: modifiers.map((modifier) => createSimpleExpression(modifier))
|
|
344
|
-
};
|
|
203
|
+
const namespaceRE = /^(?:\$([\w-]+)\$)?([\w-]+)?/;
|
|
204
|
+
function resolveDirective(node, context, withFn = false) {
|
|
205
|
+
const { value, name } = node;
|
|
206
|
+
let nameString = name.type === "JSXNamespacedName" ? name.namespace.name : name.type === "JSXIdentifier" ? name.name : "";
|
|
207
|
+
const isDirective = nameString.startsWith("v-");
|
|
208
|
+
let modifiers = [];
|
|
209
|
+
let isStatic = true;
|
|
210
|
+
let argString = name.type === "JSXNamespacedName" ? name.name.name : "";
|
|
211
|
+
if (name.type !== "JSXNamespacedName" && !argString) [nameString, ...modifiers] = nameString.split("_");
|
|
212
|
+
else {
|
|
213
|
+
const result = argString.match(namespaceRE);
|
|
214
|
+
if (result) {
|
|
215
|
+
let modifierString = "";
|
|
216
|
+
[, argString, modifierString] = result;
|
|
217
|
+
if (argString) {
|
|
218
|
+
argString = argString.replaceAll("_", ".");
|
|
219
|
+
isStatic = false;
|
|
220
|
+
if (modifierString && modifierString.startsWith("_")) modifiers = modifierString.slice(1).split("_");
|
|
221
|
+
} else if (modifierString) [argString, ...modifiers] = modifierString.split("_");
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const arg = isDirective ? argString && name.type === "JSXNamespacedName" ? resolveSimpleExpression(argString, isStatic, name.name.loc) : void 0 : resolveSimpleExpression(nameString, true, name.loc);
|
|
225
|
+
const exp = value ? withFn && value.type === "JSXExpressionContainer" ? resolveExpressionWithFn(value.expression, context) : resolveExpression(value, context) : void 0;
|
|
226
|
+
return {
|
|
227
|
+
type: NodeTypes.DIRECTIVE,
|
|
228
|
+
name: isDirective ? nameString.slice(2) : "bind",
|
|
229
|
+
rawName: getText(name, context),
|
|
230
|
+
exp,
|
|
231
|
+
arg,
|
|
232
|
+
loc: resolveLocation(node.loc, context),
|
|
233
|
+
modifiers: modifiers.map((modifier) => createSimpleExpression(modifier))
|
|
234
|
+
};
|
|
345
235
|
}
|
|
346
236
|
function resolveExpressionWithFn(node, context) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
text,
|
|
350
|
-
false,
|
|
351
|
-
node.loc,
|
|
352
|
-
parseExpression(`(${text})=>{}`, {
|
|
353
|
-
plugins: ["typescript"]
|
|
354
|
-
})
|
|
355
|
-
);
|
|
237
|
+
const text = getText(node, context);
|
|
238
|
+
return node.type === "Identifier" ? resolveSimpleExpression(text, false, node.loc) : resolveSimpleExpression(text, false, node.loc, parseExpression(`(${text})=>{}`, { plugins: ["typescript"] }));
|
|
356
239
|
}
|
|
357
240
|
function isJSXComponent(node) {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
return openingElement.name.type === "JSXMemberExpression";
|
|
365
|
-
}
|
|
241
|
+
if (node.type !== "JSXElement") return false;
|
|
242
|
+
const { openingElement } = node;
|
|
243
|
+
if (openingElement.name.type === "JSXIdentifier") {
|
|
244
|
+
const name = openingElement.name.name;
|
|
245
|
+
return !isHTMLTag(name) && !isSVGTag(name);
|
|
246
|
+
} else return openingElement.name.type === "JSXMemberExpression";
|
|
366
247
|
}
|
|
367
248
|
function findProp(expression, key) {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
return attr;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
249
|
+
if (expression?.type === "JSXElement") for (const attr of expression.openingElement.attributes) {
|
|
250
|
+
const name = attr.type === "JSXAttribute" && (attr.name.type === "JSXIdentifier" ? attr.name.name : attr.name.type === "JSXNamespacedName" ? attr.name.namespace.name : "").split("_")[0];
|
|
251
|
+
if (name && (isString(key) ? name === key : key.test(name))) return attr;
|
|
252
|
+
}
|
|
376
253
|
}
|
|
377
254
|
function getText(node, content) {
|
|
378
|
-
|
|
255
|
+
return content.ir.source.slice(node.start, node.end);
|
|
379
256
|
}
|
|
380
257
|
function isTemplate(node) {
|
|
381
|
-
|
|
382
|
-
return node.openingElement.name.name === "template";
|
|
383
|
-
}
|
|
258
|
+
if (node.type === "JSXElement" && node.openingElement.name.type === "JSXIdentifier") return node.openingElement.name.name === "template";
|
|
384
259
|
}
|
|
385
260
|
|
|
386
|
-
|
|
261
|
+
//#endregion
|
|
262
|
+
//#region src/transforms/utils.ts
|
|
387
263
|
function newDynamic() {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
264
|
+
return {
|
|
265
|
+
flags: DynamicFlag.REFERENCED,
|
|
266
|
+
children: []
|
|
267
|
+
};
|
|
392
268
|
}
|
|
393
269
|
function newBlock(node) {
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
270
|
+
return {
|
|
271
|
+
type: 1,
|
|
272
|
+
node,
|
|
273
|
+
dynamic: newDynamic(),
|
|
274
|
+
effect: [],
|
|
275
|
+
operation: [],
|
|
276
|
+
returns: [],
|
|
277
|
+
expressions: [],
|
|
278
|
+
tempId: 0
|
|
279
|
+
};
|
|
404
280
|
}
|
|
405
281
|
function createBranch(node, context, isVFor) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
282
|
+
context.node = node = wrapFragment(node);
|
|
283
|
+
const branch = newBlock(node);
|
|
284
|
+
const exitBlock = context.enterBlock(branch, isVFor);
|
|
285
|
+
context.reference();
|
|
286
|
+
return [branch, exitBlock];
|
|
411
287
|
}
|
|
412
288
|
function wrapFragment(node) {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
return jsxFragment(jsxOpeningFragment(), jsxClosingFragment(), [
|
|
417
|
-
node.type === "JSXElement" ? node : jsxExpressionContainer(node)
|
|
418
|
-
]);
|
|
289
|
+
if (node.type === "JSXFragment" || isTemplate(node)) return node;
|
|
290
|
+
return jsxFragment(jsxOpeningFragment(), jsxClosingFragment(), [node.type === "JSXElement" ? node : jsxExpressionContainer(node)]);
|
|
419
291
|
}
|
|
420
|
-
|
|
421
|
-
|
|
292
|
+
const EMPTY_EXPRESSION = createSimpleExpression("", true);
|
|
293
|
+
const isFragmentNode = (node) => node.type === IRNodeTypes.ROOT || node.type === "JSXFragment" || node.type === "JSXElement" && !!isTemplate(node);
|
|
422
294
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/transform.ts
|
|
297
|
+
const defaultOptions = {
|
|
298
|
+
filename: "",
|
|
299
|
+
prefixIdentifiers: false,
|
|
300
|
+
hoistStatic: false,
|
|
301
|
+
hmr: false,
|
|
302
|
+
cacheHandlers: false,
|
|
303
|
+
nodeTransforms: [],
|
|
304
|
+
directiveTransforms: {},
|
|
305
|
+
transformHoist: null,
|
|
306
|
+
isBuiltInComponent: NOOP,
|
|
307
|
+
isCustomElement: NOOP,
|
|
308
|
+
expressionPlugins: [],
|
|
309
|
+
scopeId: null,
|
|
310
|
+
slotted: true,
|
|
311
|
+
ssr: false,
|
|
312
|
+
inSSR: false,
|
|
313
|
+
ssrCssVars: ``,
|
|
314
|
+
bindingMetadata: EMPTY_OBJ,
|
|
315
|
+
inline: false,
|
|
316
|
+
isTS: false,
|
|
317
|
+
onError: defaultOnError,
|
|
318
|
+
onWarn: defaultOnWarn
|
|
446
319
|
};
|
|
447
|
-
var TransformContext = class
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
320
|
+
var TransformContext = class TransformContext {
|
|
321
|
+
parent = null;
|
|
322
|
+
root;
|
|
323
|
+
index = 0;
|
|
324
|
+
block;
|
|
325
|
+
options;
|
|
326
|
+
template = "";
|
|
327
|
+
childrenTemplate = [];
|
|
328
|
+
dynamic;
|
|
329
|
+
inVOnce = false;
|
|
330
|
+
inVFor = 0;
|
|
331
|
+
comment = [];
|
|
332
|
+
component;
|
|
333
|
+
directive;
|
|
334
|
+
slots = [];
|
|
335
|
+
globalId = 0;
|
|
336
|
+
constructor(ir, node, options = {}) {
|
|
337
|
+
this.ir = ir;
|
|
338
|
+
this.node = node;
|
|
339
|
+
this.options = extend({}, defaultOptions, options);
|
|
340
|
+
this.block = this.ir.block;
|
|
341
|
+
this.dynamic = this.ir.block.dynamic;
|
|
342
|
+
this.component = this.ir.component;
|
|
343
|
+
this.directive = this.ir.directive;
|
|
344
|
+
this.root = this;
|
|
345
|
+
}
|
|
346
|
+
enterBlock(ir, isVFor = false) {
|
|
347
|
+
const { block, template, dynamic, childrenTemplate, slots } = this;
|
|
348
|
+
this.block = ir;
|
|
349
|
+
this.dynamic = ir.dynamic;
|
|
350
|
+
this.template = "";
|
|
351
|
+
this.childrenTemplate = [];
|
|
352
|
+
this.slots = [];
|
|
353
|
+
isVFor && this.inVFor++;
|
|
354
|
+
return () => {
|
|
355
|
+
this.registerTemplate();
|
|
356
|
+
this.block = block;
|
|
357
|
+
this.template = template;
|
|
358
|
+
this.dynamic = dynamic;
|
|
359
|
+
this.childrenTemplate = childrenTemplate;
|
|
360
|
+
this.slots = slots;
|
|
361
|
+
isVFor && this.inVFor--;
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
increaseId = () => this.globalId++;
|
|
365
|
+
reference() {
|
|
366
|
+
if (this.dynamic.id !== void 0) return this.dynamic.id;
|
|
367
|
+
this.dynamic.flags |= DynamicFlag.REFERENCED;
|
|
368
|
+
return this.dynamic.id = this.increaseId();
|
|
369
|
+
}
|
|
370
|
+
pushTemplate(content) {
|
|
371
|
+
const existing = this.ir.template.indexOf(content);
|
|
372
|
+
if (existing !== -1) return existing;
|
|
373
|
+
this.ir.template.push(content);
|
|
374
|
+
return this.ir.template.length - 1;
|
|
375
|
+
}
|
|
376
|
+
registerTemplate() {
|
|
377
|
+
if (!this.template) return -1;
|
|
378
|
+
const id = this.pushTemplate(this.template);
|
|
379
|
+
return this.dynamic.template = id;
|
|
380
|
+
}
|
|
381
|
+
registerEffect(expressions, ...operations) {
|
|
382
|
+
expressions = expressions.filter((exp) => !isConstantExpression(exp));
|
|
383
|
+
if (this.inVOnce || expressions.length === 0 || expressions.every((e) => e.ast && isConstantNode(e.ast, {}))) return this.registerOperation(...operations);
|
|
384
|
+
this.block.expressions.push(...expressions);
|
|
385
|
+
const existing = this.block.effect.find((e) => isSameExpression(e.expressions, expressions));
|
|
386
|
+
if (existing) existing.operations.push(...operations);
|
|
387
|
+
else this.block.effect.push({
|
|
388
|
+
expressions,
|
|
389
|
+
operations
|
|
390
|
+
});
|
|
391
|
+
function isSameExpression(a, b) {
|
|
392
|
+
if (a.length !== b.length) return false;
|
|
393
|
+
return a.every((exp, i) => exp.content === b[i].content);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
registerOperation(...node) {
|
|
397
|
+
this.block.operation.push(...node);
|
|
398
|
+
}
|
|
399
|
+
create(node, index) {
|
|
400
|
+
return Object.assign(Object.create(TransformContext.prototype), this, {
|
|
401
|
+
node,
|
|
402
|
+
parent: this,
|
|
403
|
+
index,
|
|
404
|
+
template: "",
|
|
405
|
+
childrenTemplate: [],
|
|
406
|
+
dynamic: newDynamic()
|
|
407
|
+
});
|
|
408
|
+
}
|
|
536
409
|
};
|
|
537
410
|
function transform(node, options = {}) {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
411
|
+
const ir = {
|
|
412
|
+
type: IRNodeTypes.ROOT,
|
|
413
|
+
node,
|
|
414
|
+
source: node.source,
|
|
415
|
+
template: [],
|
|
416
|
+
component: new Set(),
|
|
417
|
+
directive: new Set(),
|
|
418
|
+
block: newBlock(node),
|
|
419
|
+
hasTemplateRef: false
|
|
420
|
+
};
|
|
421
|
+
const context = new TransformContext(ir, node, options);
|
|
422
|
+
transformNode(context);
|
|
423
|
+
return ir;
|
|
551
424
|
}
|
|
552
425
|
function transformNode(context) {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
} else {
|
|
568
|
-
node = context.node;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
context.node = node;
|
|
572
|
-
let i = exitFns.length;
|
|
573
|
-
while (i--) {
|
|
574
|
-
exitFns[i]();
|
|
575
|
-
}
|
|
576
|
-
if (context.node.type === 0 /* ROOT */) {
|
|
577
|
-
context.registerTemplate();
|
|
578
|
-
}
|
|
426
|
+
let { node } = context;
|
|
427
|
+
const { nodeTransforms } = context.options;
|
|
428
|
+
const exitFns = [];
|
|
429
|
+
for (const nodeTransform of nodeTransforms) {
|
|
430
|
+
const onExit = nodeTransform(node, context);
|
|
431
|
+
if (onExit) if (isArray(onExit)) exitFns.push(...onExit);
|
|
432
|
+
else exitFns.push(onExit);
|
|
433
|
+
if (!context.node) return;
|
|
434
|
+
else node = context.node;
|
|
435
|
+
}
|
|
436
|
+
context.node = node;
|
|
437
|
+
let i = exitFns.length;
|
|
438
|
+
while (i--) exitFns[i]();
|
|
439
|
+
if (context.node.type === IRNodeTypes.ROOT) context.registerTemplate();
|
|
579
440
|
}
|
|
580
441
|
function createStructuralDirectiveTransform(name, fn) {
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
}
|
|
601
|
-
return exitFns;
|
|
602
|
-
}
|
|
603
|
-
};
|
|
442
|
+
const matches = (n) => isString(name) ? n === name : name.includes(n);
|
|
443
|
+
return (node, context) => {
|
|
444
|
+
if (node.type === "JSXElement") {
|
|
445
|
+
const { openingElement: { attributes } } = node;
|
|
446
|
+
if (isTemplate(node) && findProp(node, "v-slot")) return;
|
|
447
|
+
const exitFns = [];
|
|
448
|
+
for (const prop of attributes) {
|
|
449
|
+
if (prop.type !== "JSXAttribute") continue;
|
|
450
|
+
const propName = getText(prop.name, context);
|
|
451
|
+
if (propName.startsWith("v-") && matches(propName.slice(2))) {
|
|
452
|
+
attributes.splice(attributes.indexOf(prop), 1);
|
|
453
|
+
const onExit = fn(node, prop, context);
|
|
454
|
+
if (onExit) exitFns.push(onExit);
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return exitFns;
|
|
459
|
+
}
|
|
460
|
+
};
|
|
604
461
|
}
|
|
605
462
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
context.dynamic.hasDynamicChild = true;
|
|
625
|
-
}
|
|
626
|
-
context.dynamic.children[i] = childContext.dynamic;
|
|
627
|
-
}
|
|
628
|
-
if (!isFragment) {
|
|
629
|
-
processDynamicChildren(context);
|
|
630
|
-
}
|
|
463
|
+
//#endregion
|
|
464
|
+
//#region src/transforms/transformChildren.ts
|
|
465
|
+
const transformChildren = (node, context) => {
|
|
466
|
+
const isFragment = node.type === IRNodeTypes.ROOT || node.type === "JSXFragment" || node.type === "JSXElement" && (isTemplate(node) || isJSXComponent(node));
|
|
467
|
+
if (node.type !== "JSXElement" && !isFragment) return;
|
|
468
|
+
for (const [i, child] of node.children.entries()) {
|
|
469
|
+
const childContext = context.create(child, i);
|
|
470
|
+
transformNode(childContext);
|
|
471
|
+
const childDynamic = childContext.dynamic;
|
|
472
|
+
if (isFragment) {
|
|
473
|
+
childContext.reference();
|
|
474
|
+
childContext.registerTemplate();
|
|
475
|
+
if (!(childDynamic.flags & DynamicFlag.NON_TEMPLATE) || childDynamic.flags & DynamicFlag.INSERT) context.block.returns.push(childDynamic.id);
|
|
476
|
+
} else context.childrenTemplate.push(childContext.template);
|
|
477
|
+
if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & DynamicFlag.NON_TEMPLATE || childDynamic.flags & DynamicFlag.INSERT) context.dynamic.hasDynamicChild = true;
|
|
478
|
+
context.dynamic.children[i] = childContext.dynamic;
|
|
479
|
+
}
|
|
480
|
+
if (!isFragment) processDynamicChildren(context);
|
|
631
481
|
};
|
|
632
482
|
function processDynamicChildren(context) {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
hasStaticTemplate = true;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
if (prevDynamics.length) {
|
|
661
|
-
registerInsertion(prevDynamics, context);
|
|
662
|
-
}
|
|
483
|
+
let prevDynamics = [];
|
|
484
|
+
let hasStaticTemplate = false;
|
|
485
|
+
const children = context.dynamic.children;
|
|
486
|
+
for (const [index, child] of children.entries()) {
|
|
487
|
+
if (child.flags & DynamicFlag.INSERT) prevDynamics.push(child);
|
|
488
|
+
if (!(child.flags & DynamicFlag.NON_TEMPLATE)) {
|
|
489
|
+
if (prevDynamics.length) {
|
|
490
|
+
if (hasStaticTemplate) {
|
|
491
|
+
context.childrenTemplate[index - prevDynamics.length] = `<!>`;
|
|
492
|
+
prevDynamics[0].flags -= DynamicFlag.NON_TEMPLATE;
|
|
493
|
+
const anchor = prevDynamics[0].anchor = context.increaseId();
|
|
494
|
+
registerInsertion(prevDynamics, context, anchor);
|
|
495
|
+
} else registerInsertion(
|
|
496
|
+
prevDynamics,
|
|
497
|
+
context,
|
|
498
|
+
-1
|
|
499
|
+
/* prepend */
|
|
500
|
+
);
|
|
501
|
+
prevDynamics = [];
|
|
502
|
+
}
|
|
503
|
+
hasStaticTemplate = true;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
if (prevDynamics.length) registerInsertion(prevDynamics, context);
|
|
663
507
|
}
|
|
664
508
|
function registerInsertion(dynamics, context, anchor) {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
child.operation.anchor = anchor;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
509
|
+
for (const child of dynamics) if (child.template != null) context.registerOperation({
|
|
510
|
+
type: IRNodeTypes.INSERT_NODE,
|
|
511
|
+
elements: dynamics.map((child$1) => child$1.id),
|
|
512
|
+
parent: context.reference(),
|
|
513
|
+
anchor
|
|
514
|
+
});
|
|
515
|
+
else if (child.operation && isBlockOperation(child.operation)) {
|
|
516
|
+
child.operation.parent = context.reference();
|
|
517
|
+
child.operation.anchor = anchor;
|
|
518
|
+
}
|
|
678
519
|
}
|
|
679
520
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
var isReservedProp = /* @__PURE__ */ makeMap(
|
|
686
|
-
// the leading comma is intentional so empty string "" is also included
|
|
687
|
-
",key,ref,ref_for,ref_key,"
|
|
521
|
+
//#endregion
|
|
522
|
+
//#region src/transforms/transformElement.ts
|
|
523
|
+
const isReservedProp = /* @__PURE__ */ makeMap(
|
|
524
|
+
// the leading comma is intentional so empty string "" is also included
|
|
525
|
+
",key,ref,ref_for,ref_key,"
|
|
688
526
|
);
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
isComponent
|
|
705
|
-
);
|
|
706
|
-
let { parent } = context;
|
|
707
|
-
while (parent && parent.parent && parent.node.type === "JSXElement" && isTemplate(parent.node)) {
|
|
708
|
-
parent = parent.parent;
|
|
709
|
-
}
|
|
710
|
-
const singleRoot = context.root === parent && parent.node.children.filter((child) => !isJSXComponent(child)).length === 1;
|
|
711
|
-
(isComponent ? transformComponentElement : transformNativeElement)(
|
|
712
|
-
tag,
|
|
713
|
-
propsResult,
|
|
714
|
-
singleRoot,
|
|
715
|
-
context
|
|
716
|
-
);
|
|
717
|
-
};
|
|
527
|
+
const isEventRegex = /^on[A-Z]/;
|
|
528
|
+
const isDirectiveRegex = /^v-[a-z]/;
|
|
529
|
+
const transformElement = (node, context) => {
|
|
530
|
+
return function postTransformElement() {
|
|
531
|
+
({node} = context);
|
|
532
|
+
if (node.type !== "JSXElement" || isTemplate(node)) return;
|
|
533
|
+
const { openingElement: { name } } = node;
|
|
534
|
+
const tag = name.type === "JSXIdentifier" ? name.name : name.type === "JSXMemberExpression" ? context.ir.source.slice(name.start, name.end) : "";
|
|
535
|
+
const isComponent = isJSXComponent(node);
|
|
536
|
+
const propsResult = buildProps(node, context, isComponent);
|
|
537
|
+
let { parent } = context;
|
|
538
|
+
while (parent && parent.parent && parent.node.type === "JSXElement" && isTemplate(parent.node)) parent = parent.parent;
|
|
539
|
+
const singleRoot = context.root === parent && parent.node.children.filter((child) => !isJSXComponent(child)).length === 1;
|
|
540
|
+
(isComponent ? transformComponentElement : transformNativeElement)(tag, propsResult, singleRoot, context);
|
|
541
|
+
};
|
|
718
542
|
};
|
|
719
543
|
function transformComponentElement(tag, propsResult, singleRoot, context) {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
};
|
|
748
|
-
context.slots = [];
|
|
544
|
+
let asset = true;
|
|
545
|
+
const fromSetup = tag;
|
|
546
|
+
if (fromSetup) {
|
|
547
|
+
tag = fromSetup;
|
|
548
|
+
asset = false;
|
|
549
|
+
}
|
|
550
|
+
const dotIndex = tag.indexOf(".");
|
|
551
|
+
if (dotIndex > 0) {
|
|
552
|
+
const ns = tag.slice(0, dotIndex);
|
|
553
|
+
if (ns) {
|
|
554
|
+
tag = ns + tag.slice(dotIndex);
|
|
555
|
+
asset = false;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
if (asset) context.component.add(tag);
|
|
559
|
+
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE | DynamicFlag.INSERT;
|
|
560
|
+
context.dynamic.operation = {
|
|
561
|
+
type: IRNodeTypes.CREATE_COMPONENT_NODE,
|
|
562
|
+
id: context.reference(),
|
|
563
|
+
tag,
|
|
564
|
+
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
|
|
565
|
+
asset,
|
|
566
|
+
root: singleRoot,
|
|
567
|
+
slots: [...context.slots],
|
|
568
|
+
once: context.inVOnce
|
|
569
|
+
};
|
|
570
|
+
context.slots = [];
|
|
749
571
|
}
|
|
750
572
|
function transformNativeElement(tag, propsResult, singleRoot, context) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
}
|
|
789
|
-
if (context.parent && context.parent.node.type === "JSXElement" && context.parent.node.openingElement.name.type === "JSXIdentifier" && !isValidHTMLNesting(context.parent.node.openingElement.name.name, tag)) {
|
|
790
|
-
context.reference();
|
|
791
|
-
context.dynamic.template = context.pushTemplate(template);
|
|
792
|
-
context.dynamic.flags |= 4 /* INSERT */ | 2 /* NON_TEMPLATE */;
|
|
793
|
-
} else {
|
|
794
|
-
context.template += template;
|
|
795
|
-
}
|
|
573
|
+
const { scopeId } = context.options;
|
|
574
|
+
let template = "";
|
|
575
|
+
template += `<${tag}`;
|
|
576
|
+
if (scopeId) template += ` ${scopeId}`;
|
|
577
|
+
const dynamicProps = [];
|
|
578
|
+
if (propsResult[0]) {
|
|
579
|
+
const [, dynamicArgs, expressions] = propsResult;
|
|
580
|
+
context.registerEffect(expressions, {
|
|
581
|
+
type: IRNodeTypes.SET_DYNAMIC_PROPS,
|
|
582
|
+
element: context.reference(),
|
|
583
|
+
props: dynamicArgs,
|
|
584
|
+
root: singleRoot
|
|
585
|
+
});
|
|
586
|
+
} else for (const prop of propsResult[1]) {
|
|
587
|
+
const { key, values } = prop;
|
|
588
|
+
if (key.isStatic && values.length === 1 && values[0].isStatic) {
|
|
589
|
+
template += ` ${key.content}`;
|
|
590
|
+
if (values[0].content) template += `="${values[0].content}"`;
|
|
591
|
+
} else {
|
|
592
|
+
dynamicProps.push(key.content);
|
|
593
|
+
context.registerEffect(values, {
|
|
594
|
+
type: IRNodeTypes.SET_PROP,
|
|
595
|
+
element: context.reference(),
|
|
596
|
+
prop,
|
|
597
|
+
tag,
|
|
598
|
+
root: singleRoot
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
template += `>${context.childrenTemplate.join("")}`;
|
|
603
|
+
if (!isVoidTag(tag)) template += `</${tag}>`;
|
|
604
|
+
if (singleRoot) context.ir.rootTemplateIndex = context.ir.template.length;
|
|
605
|
+
if (context.parent && context.parent.node.type === "JSXElement" && context.parent.node.openingElement.name.type === "JSXIdentifier" && !isValidHTMLNesting(context.parent.node.openingElement.name.name, tag)) {
|
|
606
|
+
context.reference();
|
|
607
|
+
context.dynamic.template = context.pushTemplate(template);
|
|
608
|
+
context.dynamic.flags |= DynamicFlag.INSERT | DynamicFlag.NON_TEMPLATE;
|
|
609
|
+
} else context.template += template;
|
|
796
610
|
}
|
|
797
611
|
function buildProps(node, context, isComponent) {
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
const irProps = dedupeProperties(results);
|
|
840
|
-
return [false, irProps];
|
|
612
|
+
const props = node.openingElement.attributes;
|
|
613
|
+
if (props.length === 0) return [false, []];
|
|
614
|
+
const dynamicArgs = [];
|
|
615
|
+
const dynamicExpr = [];
|
|
616
|
+
let results = [];
|
|
617
|
+
function pushMergeArg() {
|
|
618
|
+
if (results.length) {
|
|
619
|
+
dynamicArgs.push(dedupeProperties(results));
|
|
620
|
+
results = [];
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
for (const prop of props) {
|
|
624
|
+
if (prop.type === "JSXSpreadAttribute" && prop.argument) {
|
|
625
|
+
const value = resolveExpression(prop.argument, context);
|
|
626
|
+
dynamicExpr.push(value);
|
|
627
|
+
pushMergeArg();
|
|
628
|
+
dynamicArgs.push({
|
|
629
|
+
kind: IRDynamicPropsKind.EXPRESSION,
|
|
630
|
+
value
|
|
631
|
+
});
|
|
632
|
+
continue;
|
|
633
|
+
}
|
|
634
|
+
const result = transformProp(prop, node, context);
|
|
635
|
+
if (result) {
|
|
636
|
+
dynamicExpr.push(result.key, result.value);
|
|
637
|
+
if (isComponent && !result.key.isStatic) {
|
|
638
|
+
pushMergeArg();
|
|
639
|
+
dynamicArgs.push(extend(resolveDirectiveResult(result), { kind: IRDynamicPropsKind.ATTRIBUTE }));
|
|
640
|
+
} else results.push(result);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
if (dynamicArgs.length || results.some(({ key }) => !key.isStatic)) {
|
|
644
|
+
pushMergeArg();
|
|
645
|
+
return [
|
|
646
|
+
true,
|
|
647
|
+
dynamicArgs,
|
|
648
|
+
dynamicExpr
|
|
649
|
+
];
|
|
650
|
+
}
|
|
651
|
+
const irProps = dedupeProperties(results);
|
|
652
|
+
return [false, irProps];
|
|
841
653
|
}
|
|
842
654
|
function transformProp(prop, node, context) {
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
name = fromSetup;
|
|
862
|
-
} else {
|
|
863
|
-
context.directive.add(name);
|
|
864
|
-
}
|
|
865
|
-
}
|
|
655
|
+
if (prop.type === "JSXSpreadAttribute") return;
|
|
656
|
+
let name = prop.name.type === "JSXIdentifier" ? prop.name.name : prop.name.type === "JSXNamespacedName" ? prop.name.namespace.name : "";
|
|
657
|
+
name = name.split("_")[0];
|
|
658
|
+
if (!isDirectiveRegex.test(name) && !isEventRegex.test(name) && (!prop.value || prop.value.type === "StringLiteral")) {
|
|
659
|
+
if (isReservedProp(name)) return;
|
|
660
|
+
return {
|
|
661
|
+
key: resolveSimpleExpression(name, true, prop.name.loc),
|
|
662
|
+
value: prop.value && prop.value.type === "StringLiteral" ? resolveSimpleExpression(prop.value.value, true, prop.value.loc) : EMPTY_EXPRESSION
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
name = isEventRegex.test(name) ? "on" : isDirectiveRegex.test(name) ? name.slice(2) : "bind";
|
|
666
|
+
const directiveTransform = context.options.directiveTransforms[name];
|
|
667
|
+
if (directiveTransform) return directiveTransform(prop, node, context);
|
|
668
|
+
if (!isBuiltInDirective(name)) {
|
|
669
|
+
const fromSetup = `v-${name}`;
|
|
670
|
+
if (fromSetup) name = fromSetup;
|
|
671
|
+
else context.directive.add(name);
|
|
672
|
+
}
|
|
866
673
|
}
|
|
867
674
|
function dedupeProperties(results) {
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
}
|
|
887
|
-
return deduped;
|
|
675
|
+
const knownProps = new Map();
|
|
676
|
+
const deduped = [];
|
|
677
|
+
for (const result of results) {
|
|
678
|
+
const prop = resolveDirectiveResult(result);
|
|
679
|
+
if (!prop.key.isStatic) {
|
|
680
|
+
deduped.push(prop);
|
|
681
|
+
continue;
|
|
682
|
+
}
|
|
683
|
+
const name = prop.key.content;
|
|
684
|
+
const existing = knownProps.get(name);
|
|
685
|
+
if (existing) {
|
|
686
|
+
if (name === "style" || name === "class") mergePropValues(existing, prop);
|
|
687
|
+
} else {
|
|
688
|
+
knownProps.set(name, prop);
|
|
689
|
+
deduped.push(prop);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return deduped;
|
|
888
693
|
}
|
|
889
694
|
function resolveDirectiveResult(prop) {
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
695
|
+
return extend({}, prop, {
|
|
696
|
+
value: void 0,
|
|
697
|
+
values: [prop.value]
|
|
698
|
+
});
|
|
894
699
|
}
|
|
895
700
|
function mergePropValues(existing, incoming) {
|
|
896
|
-
|
|
897
|
-
|
|
701
|
+
const newValues = incoming.values;
|
|
702
|
+
existing.values.push(...newValues);
|
|
898
703
|
}
|
|
899
704
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region src/transforms/transformTemplateRef.ts
|
|
707
|
+
const transformTemplateRef = (node, context) => {
|
|
708
|
+
if (node.type !== "JSXElement") return;
|
|
709
|
+
const dir = findProp(node, "ref");
|
|
710
|
+
if (!dir?.value) return;
|
|
711
|
+
context.ir.hasTemplateRef = true;
|
|
712
|
+
const value = resolveExpression(dir.value, context);
|
|
713
|
+
return () => {
|
|
714
|
+
const id = context.reference();
|
|
715
|
+
const effect = !isConstantExpression(value);
|
|
716
|
+
effect && context.registerOperation({
|
|
717
|
+
type: IRNodeTypes.DECLARE_OLD_REF,
|
|
718
|
+
id
|
|
719
|
+
});
|
|
720
|
+
context.registerEffect([value], {
|
|
721
|
+
type: IRNodeTypes.SET_TEMPLATE_REF,
|
|
722
|
+
element: id,
|
|
723
|
+
value,
|
|
724
|
+
refFor: !!context.inVFor,
|
|
725
|
+
effect
|
|
726
|
+
});
|
|
727
|
+
};
|
|
922
728
|
};
|
|
923
729
|
|
|
924
|
-
|
|
925
|
-
|
|
730
|
+
//#endregion
|
|
731
|
+
//#region src/transforms/expression.ts
|
|
926
732
|
function processConditionalExpression(node, context) {
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
onExit2();
|
|
949
|
-
}
|
|
950
|
-
];
|
|
733
|
+
const { test, consequent, alternate } = node;
|
|
734
|
+
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE | DynamicFlag.INSERT;
|
|
735
|
+
const id = context.reference();
|
|
736
|
+
const condition = resolveExpression(test, context);
|
|
737
|
+
const [branch, onExit] = createBranch(consequent, context);
|
|
738
|
+
const operation = {
|
|
739
|
+
type: IRNodeTypes.IF,
|
|
740
|
+
id,
|
|
741
|
+
condition,
|
|
742
|
+
positive: branch,
|
|
743
|
+
once: context.inVOnce || isStaticNode(test)
|
|
744
|
+
};
|
|
745
|
+
return [() => {
|
|
746
|
+
onExit();
|
|
747
|
+
context.dynamic.operation = operation;
|
|
748
|
+
}, () => {
|
|
749
|
+
const [branch$1, onExit$1] = createBranch(alternate, context);
|
|
750
|
+
operation.negative = branch$1;
|
|
751
|
+
transformNode(context);
|
|
752
|
+
onExit$1();
|
|
753
|
+
}];
|
|
951
754
|
}
|
|
952
755
|
function processLogicalExpression(node, context) {
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
const [branch2, onExit2] = createBranch(
|
|
976
|
-
operator === "&&" ? left : right,
|
|
977
|
-
context
|
|
978
|
-
);
|
|
979
|
-
operation.negative = branch2;
|
|
980
|
-
transformNode(context);
|
|
981
|
-
onExit2();
|
|
982
|
-
}
|
|
983
|
-
];
|
|
756
|
+
const { left, right, operator } = node;
|
|
757
|
+
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE;
|
|
758
|
+
context.dynamic.flags |= DynamicFlag.INSERT;
|
|
759
|
+
const id = context.reference();
|
|
760
|
+
const condition = resolveExpression(left, context);
|
|
761
|
+
const [branch, onExit] = createBranch(operator === "&&" ? right : left, context);
|
|
762
|
+
const operation = {
|
|
763
|
+
type: IRNodeTypes.IF,
|
|
764
|
+
id,
|
|
765
|
+
condition,
|
|
766
|
+
positive: branch,
|
|
767
|
+
once: context.inVOnce
|
|
768
|
+
};
|
|
769
|
+
return [() => {
|
|
770
|
+
onExit();
|
|
771
|
+
context.dynamic.operation = operation;
|
|
772
|
+
}, () => {
|
|
773
|
+
const [branch$1, onExit$1] = createBranch(operator === "&&" ? left : right, context);
|
|
774
|
+
operation.negative = branch$1;
|
|
775
|
+
transformNode(context);
|
|
776
|
+
onExit$1();
|
|
777
|
+
}];
|
|
984
778
|
}
|
|
985
779
|
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
}
|
|
1016
|
-
} else if (node.type === "JSXExpressionContainer") {
|
|
1017
|
-
if (node.expression.type === "ConditionalExpression") {
|
|
1018
|
-
return processConditionalExpression(node.expression, context);
|
|
1019
|
-
} else if (node.expression.type === "LogicalExpression") {
|
|
1020
|
-
return processLogicalExpression(node.expression, context);
|
|
1021
|
-
} else {
|
|
1022
|
-
processInterpolation(context);
|
|
1023
|
-
}
|
|
1024
|
-
} else if (node.type === "JSXText") {
|
|
1025
|
-
const value = resolveJSXText(node);
|
|
1026
|
-
if (value) {
|
|
1027
|
-
context.template += value;
|
|
1028
|
-
} else {
|
|
1029
|
-
context.dynamic.flags |= 2 /* NON_TEMPLATE */;
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
780
|
+
//#endregion
|
|
781
|
+
//#region src/transforms/transformText.ts
|
|
782
|
+
const seen = new WeakMap();
|
|
783
|
+
const transformText = (node, context) => {
|
|
784
|
+
if (!seen.has(context.root)) seen.set(context.root, new WeakSet());
|
|
785
|
+
if (seen.get(context.root).has(node)) {
|
|
786
|
+
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE;
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
const isFragment = isFragmentNode(node);
|
|
790
|
+
if ((node.type === "JSXElement" && !isTemplate(node) && !isJSXComponent(node) || isFragment) && node.children.length) {
|
|
791
|
+
let hasInterp = false;
|
|
792
|
+
let isAllTextLike = true;
|
|
793
|
+
for (const c of node.children) if (c.type === "JSXExpressionContainer" && c.expression.type !== "ConditionalExpression" && c.expression.type !== "LogicalExpression") hasInterp = true;
|
|
794
|
+
else if (c.type !== "JSXText") isAllTextLike = false;
|
|
795
|
+
if (!isFragment && isAllTextLike && hasInterp) processTextContainer(node.children, context);
|
|
796
|
+
else if (hasInterp) for (let i = 0; i < node.children.length; i++) {
|
|
797
|
+
const c = node.children[i];
|
|
798
|
+
const prev = node.children[i - 1];
|
|
799
|
+
if (c.type === "JSXExpressionContainer" && prev && prev.type === "JSXText") seen.get(context.root).add(prev);
|
|
800
|
+
}
|
|
801
|
+
} else if (node.type === "JSXExpressionContainer") if (node.expression.type === "ConditionalExpression") return processConditionalExpression(node.expression, context);
|
|
802
|
+
else if (node.expression.type === "LogicalExpression") return processLogicalExpression(node.expression, context);
|
|
803
|
+
else processInterpolation(context);
|
|
804
|
+
else if (node.type === "JSXText") {
|
|
805
|
+
const value = resolveJSXText(node);
|
|
806
|
+
if (value) context.template += value;
|
|
807
|
+
else context.dynamic.flags |= DynamicFlag.NON_TEMPLATE;
|
|
808
|
+
}
|
|
1032
809
|
};
|
|
1033
810
|
function processInterpolation(context) {
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
values
|
|
1061
|
-
});
|
|
1062
|
-
}
|
|
811
|
+
const parent = context.parent.node;
|
|
812
|
+
const children = parent.children;
|
|
813
|
+
const nexts = children.slice(context.index);
|
|
814
|
+
const idx = nexts.findIndex((n) => !isTextLike(n));
|
|
815
|
+
const nodes = idx !== -1 ? nexts.slice(0, idx) : nexts;
|
|
816
|
+
const prev = children[context.index - 1];
|
|
817
|
+
if (prev && prev.type === "JSXText") nodes.unshift(prev);
|
|
818
|
+
const values = createTextLikeExpressions(nodes, context);
|
|
819
|
+
if (!values.length) {
|
|
820
|
+
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE;
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
823
|
+
const id = context.reference();
|
|
824
|
+
if (isFragmentNode(parent)) context.registerOperation({
|
|
825
|
+
type: IRNodeTypes.CREATE_NODES,
|
|
826
|
+
id,
|
|
827
|
+
values
|
|
828
|
+
});
|
|
829
|
+
else {
|
|
830
|
+
context.template += " ";
|
|
831
|
+
context.registerOperation({
|
|
832
|
+
type: IRNodeTypes.SET_NODES,
|
|
833
|
+
element: id,
|
|
834
|
+
values
|
|
835
|
+
});
|
|
836
|
+
}
|
|
1063
837
|
}
|
|
1064
838
|
function processTextContainer(children, context) {
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
});
|
|
1082
|
-
}
|
|
839
|
+
const values = createTextLikeExpressions(children, context);
|
|
840
|
+
const literals = values.map(getLiteralExpressionValue);
|
|
841
|
+
if (literals.every((l) => l != null)) context.childrenTemplate = literals.map((l) => String(l));
|
|
842
|
+
else {
|
|
843
|
+
context.childrenTemplate = [" "];
|
|
844
|
+
context.registerOperation({
|
|
845
|
+
type: IRNodeTypes.GET_TEXT_CHILD,
|
|
846
|
+
parent: context.reference()
|
|
847
|
+
});
|
|
848
|
+
context.registerOperation({
|
|
849
|
+
type: IRNodeTypes.SET_NODES,
|
|
850
|
+
element: context.reference(),
|
|
851
|
+
values,
|
|
852
|
+
generated: true
|
|
853
|
+
});
|
|
854
|
+
}
|
|
1083
855
|
}
|
|
1084
856
|
function createTextLikeExpressions(nodes, context) {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
857
|
+
const values = [];
|
|
858
|
+
for (const node of nodes) {
|
|
859
|
+
seen.get(context.root).add(node);
|
|
860
|
+
if (isEmptyText(node)) continue;
|
|
861
|
+
values.push(resolveExpression(node, context, !context.inVOnce));
|
|
862
|
+
}
|
|
863
|
+
return values;
|
|
1092
864
|
}
|
|
1093
865
|
function isTextLike(node) {
|
|
1094
|
-
|
|
866
|
+
return node.type === "JSXExpressionContainer" && node.expression.type !== "ConditionalExpression" && node.expression.type !== "LogicalExpression" || node.type === "JSXText";
|
|
1095
867
|
}
|
|
1096
868
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
value: exp,
|
|
1117
|
-
loc,
|
|
1118
|
-
runtimeCamelize: camel,
|
|
1119
|
-
modifier: modifiers.includes("prop") ? "." : modifiers.includes("attr") ? "^" : void 0
|
|
1120
|
-
};
|
|
869
|
+
//#endregion
|
|
870
|
+
//#region src/transforms/vBind.ts
|
|
871
|
+
const transformVBind = (dir, node, context) => {
|
|
872
|
+
const { name, value, loc } = dir;
|
|
873
|
+
if (!loc || name.type === "JSXNamespacedName") return;
|
|
874
|
+
const [nameString, ...modifiers] = name.name.split("_");
|
|
875
|
+
const exp = resolveExpression(value, context);
|
|
876
|
+
let arg = resolveSimpleExpression(nameString, true, dir.name.loc);
|
|
877
|
+
if (arg.isStatic && isReservedProp(arg.content)) return;
|
|
878
|
+
let camel = false;
|
|
879
|
+
if (modifiers.includes("camel")) if (arg.isStatic) arg = extend({}, arg, { content: camelize(arg.content) });
|
|
880
|
+
else camel = true;
|
|
881
|
+
return {
|
|
882
|
+
key: arg,
|
|
883
|
+
value: exp,
|
|
884
|
+
loc,
|
|
885
|
+
runtimeCamelize: camel,
|
|
886
|
+
modifier: modifiers.includes("prop") ? "." : modifiers.includes("attr") ? "^" : void 0
|
|
887
|
+
};
|
|
1121
888
|
};
|
|
1122
889
|
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
ErrorCodes,
|
|
1127
|
-
isConstantNode
|
|
1128
|
-
} from "@vue/compiler-dom";
|
|
1129
|
-
var transformVFor = createStructuralDirectiveTransform(
|
|
1130
|
-
"for",
|
|
1131
|
-
processFor
|
|
1132
|
-
);
|
|
890
|
+
//#endregion
|
|
891
|
+
//#region src/transforms/vFor.ts
|
|
892
|
+
const transformVFor = createStructuralDirectiveTransform("for", processFor);
|
|
1133
893
|
function processFor(node, dir, context) {
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
once: context.inVOnce || !!(source.ast && isConstantNode(source.ast, {})),
|
|
1164
|
-
component: isComponent,
|
|
1165
|
-
onlyChild: !!isOnlyChild
|
|
1166
|
-
};
|
|
1167
|
-
};
|
|
894
|
+
const { value, index, key, source } = getForParseResult(dir, context);
|
|
895
|
+
if (!source) {
|
|
896
|
+
context.options.onError(createCompilerError(ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION, resolveLocation(dir.loc, context)));
|
|
897
|
+
return;
|
|
898
|
+
}
|
|
899
|
+
const keyProp = findProp(node, "key");
|
|
900
|
+
const keyProperty = keyProp && propToExpression(keyProp, context);
|
|
901
|
+
const isComponent = isJSXComponent(node);
|
|
902
|
+
const id = context.reference();
|
|
903
|
+
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE | DynamicFlag.INSERT;
|
|
904
|
+
const [render, exitBlock] = createBranch(node, context, true);
|
|
905
|
+
return () => {
|
|
906
|
+
exitBlock();
|
|
907
|
+
const { parent } = context;
|
|
908
|
+
const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
|
|
909
|
+
context.dynamic.operation = {
|
|
910
|
+
type: IRNodeTypes.FOR,
|
|
911
|
+
id,
|
|
912
|
+
source,
|
|
913
|
+
value,
|
|
914
|
+
key,
|
|
915
|
+
index,
|
|
916
|
+
keyProp: keyProperty,
|
|
917
|
+
render,
|
|
918
|
+
once: context.inVOnce || !!(source.ast && isConstantNode(source.ast, {})),
|
|
919
|
+
component: isComponent,
|
|
920
|
+
onlyChild: !!isOnlyChild
|
|
921
|
+
};
|
|
922
|
+
};
|
|
1168
923
|
}
|
|
1169
924
|
function getForParseResult(dir, context) {
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
)
|
|
1189
|
-
);
|
|
1190
|
-
}
|
|
1191
|
-
return {
|
|
1192
|
-
value,
|
|
1193
|
-
index,
|
|
1194
|
-
key,
|
|
1195
|
-
source
|
|
1196
|
-
};
|
|
925
|
+
let value, index, key, source;
|
|
926
|
+
if (dir.value) {
|
|
927
|
+
if (dir.value.type === "JSXExpressionContainer" && dir.value.expression.type === "BinaryExpression") {
|
|
928
|
+
if (dir.value.expression.left.type === "SequenceExpression") {
|
|
929
|
+
const expressions = dir.value.expression.left.expressions;
|
|
930
|
+
value = expressions[0] && resolveExpressionWithFn(expressions[0], context);
|
|
931
|
+
key = expressions[1] && resolveExpression(expressions[1], context);
|
|
932
|
+
index = expressions[2] && resolveExpression(expressions[2], context);
|
|
933
|
+
} else value = resolveExpressionWithFn(dir.value.expression.left, context);
|
|
934
|
+
source = resolveExpression(dir.value.expression.right, context);
|
|
935
|
+
}
|
|
936
|
+
} else context.options.onError(createCompilerError(ErrorCodes.X_V_FOR_NO_EXPRESSION, resolveLocation(dir.loc, context)));
|
|
937
|
+
return {
|
|
938
|
+
value,
|
|
939
|
+
index,
|
|
940
|
+
key,
|
|
941
|
+
source
|
|
942
|
+
};
|
|
1197
943
|
}
|
|
1198
944
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
945
|
+
//#endregion
|
|
946
|
+
//#region src/transforms/vHtml.ts
|
|
947
|
+
const transformVHtml = (dir, node, context) => {
|
|
948
|
+
let exp;
|
|
949
|
+
const loc = resolveLocation(dir.loc, context);
|
|
950
|
+
if (!dir.value) {
|
|
951
|
+
context.options.onError(createDOMCompilerError(DOMErrorCodes.X_V_HTML_NO_EXPRESSION, loc));
|
|
952
|
+
exp = EMPTY_EXPRESSION;
|
|
953
|
+
} else exp = resolveExpression(dir.value, context);
|
|
954
|
+
if (node.children.length) {
|
|
955
|
+
context.options.onError(createDOMCompilerError(DOMErrorCodes.X_V_HTML_WITH_CHILDREN, loc));
|
|
956
|
+
context.childrenTemplate.length = 0;
|
|
957
|
+
}
|
|
958
|
+
context.registerEffect([exp], {
|
|
959
|
+
type: IRNodeTypes.SET_HTML,
|
|
960
|
+
element: context.reference(),
|
|
961
|
+
value: exp
|
|
962
|
+
});
|
|
1207
963
|
};
|
|
1208
964
|
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
["if", "else", "else-if"],
|
|
1218
|
-
processIf
|
|
1219
|
-
);
|
|
1220
|
-
var transformedIfNode = /* @__PURE__ */ new WeakMap();
|
|
965
|
+
//#endregion
|
|
966
|
+
//#region src/transforms/vIf.ts
|
|
967
|
+
const transformVIf = createStructuralDirectiveTransform([
|
|
968
|
+
"if",
|
|
969
|
+
"else",
|
|
970
|
+
"else-if"
|
|
971
|
+
], processIf);
|
|
972
|
+
const transformedIfNode = new WeakMap();
|
|
1221
973
|
function processIf(node, attribute, context) {
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
lastIfNode = lastIfNode.negative;
|
|
1271
|
-
}
|
|
1272
|
-
if (dir.name === "else-if" && lastIfNode.negative) {
|
|
1273
|
-
context.options.onError(
|
|
1274
|
-
createCompilerError2(
|
|
1275
|
-
ErrorCodes2.X_V_ELSE_NO_ADJACENT_IF,
|
|
1276
|
-
resolveLocation(node.loc, context)
|
|
1277
|
-
)
|
|
1278
|
-
);
|
|
1279
|
-
}
|
|
1280
|
-
context.root.comment = [];
|
|
1281
|
-
const [branch, onExit] = createBranch(node, context);
|
|
1282
|
-
if (dir.name === "else") {
|
|
1283
|
-
lastIfNode.negative = branch;
|
|
1284
|
-
} else {
|
|
1285
|
-
lastIfNode.negative = {
|
|
1286
|
-
type: 15 /* IF */,
|
|
1287
|
-
id: -1,
|
|
1288
|
-
condition: dir.exp,
|
|
1289
|
-
positive: branch,
|
|
1290
|
-
once: context.inVOnce
|
|
1291
|
-
};
|
|
1292
|
-
}
|
|
1293
|
-
return () => onExit();
|
|
1294
|
-
}
|
|
974
|
+
const dir = resolveDirective(attribute, context);
|
|
975
|
+
if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
|
|
976
|
+
const loc = dir.exp ? dir.exp.loc : resolveLocation(node.loc, context);
|
|
977
|
+
context.options.onError(createCompilerError(ErrorCodes.X_V_IF_NO_EXPRESSION, dir.loc));
|
|
978
|
+
dir.exp = createSimpleExpression(`true`, false, loc);
|
|
979
|
+
}
|
|
980
|
+
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE;
|
|
981
|
+
transformedIfNode.set(node, dir);
|
|
982
|
+
if (dir.name === "if") {
|
|
983
|
+
const id = context.reference();
|
|
984
|
+
context.dynamic.flags |= DynamicFlag.INSERT;
|
|
985
|
+
const [branch, onExit] = createBranch(node, context);
|
|
986
|
+
return () => {
|
|
987
|
+
onExit();
|
|
988
|
+
context.dynamic.operation = {
|
|
989
|
+
type: IRNodeTypes.IF,
|
|
990
|
+
id,
|
|
991
|
+
condition: dir.exp,
|
|
992
|
+
positive: branch,
|
|
993
|
+
once: context.inVOnce || isConstantNode(attribute.value, context.options.bindingMetadata)
|
|
994
|
+
};
|
|
995
|
+
};
|
|
996
|
+
} else {
|
|
997
|
+
const siblingIf = getSiblingIf(context);
|
|
998
|
+
const siblings = context.parent && context.parent.dynamic.children;
|
|
999
|
+
let lastIfNode;
|
|
1000
|
+
if (siblings) {
|
|
1001
|
+
let i = siblings.length;
|
|
1002
|
+
while (i--) if (siblings[i].operation) lastIfNode = siblings[i].operation;
|
|
1003
|
+
}
|
|
1004
|
+
if (!siblingIf || !lastIfNode || lastIfNode.type !== IRNodeTypes.IF) {
|
|
1005
|
+
context.options.onError(createCompilerError(ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, resolveLocation(node.loc, context)));
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
while (lastIfNode.negative && lastIfNode.negative.type === IRNodeTypes.IF) lastIfNode = lastIfNode.negative;
|
|
1009
|
+
if (dir.name === "else-if" && lastIfNode.negative) context.options.onError(createCompilerError(ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, resolveLocation(node.loc, context)));
|
|
1010
|
+
context.root.comment = [];
|
|
1011
|
+
const [branch, onExit] = createBranch(node, context);
|
|
1012
|
+
if (dir.name === "else") lastIfNode.negative = branch;
|
|
1013
|
+
else lastIfNode.negative = {
|
|
1014
|
+
type: IRNodeTypes.IF,
|
|
1015
|
+
id: -1,
|
|
1016
|
+
condition: dir.exp,
|
|
1017
|
+
positive: branch,
|
|
1018
|
+
once: context.inVOnce
|
|
1019
|
+
};
|
|
1020
|
+
return () => onExit();
|
|
1021
|
+
}
|
|
1295
1022
|
}
|
|
1296
1023
|
function getSiblingIf(context) {
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
}
|
|
1308
|
-
if (sibling && sibling.type === "JSXElement" && transformedIfNode.has(sibling)) {
|
|
1309
|
-
return sibling;
|
|
1310
|
-
}
|
|
1024
|
+
const parent = context.parent;
|
|
1025
|
+
if (!parent) return;
|
|
1026
|
+
const siblings = parent.node.children;
|
|
1027
|
+
let sibling;
|
|
1028
|
+
let i = siblings.indexOf(context.node);
|
|
1029
|
+
while (--i >= 0) if (!isEmptyText(siblings[i])) {
|
|
1030
|
+
sibling = siblings[i];
|
|
1031
|
+
break;
|
|
1032
|
+
}
|
|
1033
|
+
if (sibling && sibling.type === "JSXElement" && transformedIfNode.has(sibling)) return sibling;
|
|
1311
1034
|
}
|
|
1312
1035
|
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1036
|
+
//#endregion
|
|
1037
|
+
//#region src/transforms/vModel.ts
|
|
1038
|
+
const transformVModel = (_dir, node, context) => {
|
|
1039
|
+
const dir = resolveDirective(_dir, context);
|
|
1040
|
+
const { exp, arg } = dir;
|
|
1041
|
+
if (!exp) {
|
|
1042
|
+
context.options.onError(createCompilerError(ErrorCodes.X_V_MODEL_NO_EXPRESSION, dir.loc));
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
const expString = exp.content;
|
|
1046
|
+
if (!expString.trim() || !isMemberExpression(exp, context.options)) {
|
|
1047
|
+
context.options.onError(createCompilerError(ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION, exp.loc));
|
|
1048
|
+
return;
|
|
1049
|
+
}
|
|
1050
|
+
const isComponent = isJSXComponent(node);
|
|
1051
|
+
if (isComponent) return {
|
|
1052
|
+
key: arg ? arg : createSimpleExpression("modelValue", true),
|
|
1053
|
+
value: exp,
|
|
1054
|
+
model: true,
|
|
1055
|
+
modelModifiers: dir.modifiers.map((m) => m.content)
|
|
1056
|
+
};
|
|
1057
|
+
if (dir.arg) context.options.onError(createDOMCompilerError(DOMErrorCodes.X_V_MODEL_ARG_ON_ELEMENT, dir.arg.loc));
|
|
1058
|
+
const tag = getText(node.openingElement.name, context);
|
|
1059
|
+
const isCustomElement = context.options.isCustomElement(tag);
|
|
1060
|
+
let modelType = "text";
|
|
1061
|
+
if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) if (tag === "input" || isCustomElement) {
|
|
1062
|
+
const type = findProp(node, "type");
|
|
1063
|
+
if (type?.value) {
|
|
1064
|
+
if (type.value.type === "JSXExpressionContainer") modelType = "dynamic";
|
|
1065
|
+
else if (type.value.type === "StringLiteral") switch (type.value.value) {
|
|
1066
|
+
case "radio":
|
|
1067
|
+
modelType = "radio";
|
|
1068
|
+
break;
|
|
1069
|
+
case "checkbox":
|
|
1070
|
+
modelType = "checkbox";
|
|
1071
|
+
break;
|
|
1072
|
+
case "file":
|
|
1073
|
+
modelType = void 0;
|
|
1074
|
+
context.options.onError(createDOMCompilerError(DOMErrorCodes.X_V_MODEL_ON_FILE_INPUT_ELEMENT, dir.loc));
|
|
1075
|
+
break;
|
|
1076
|
+
default:
|
|
1077
|
+
checkDuplicatedValue();
|
|
1078
|
+
break;
|
|
1079
|
+
}
|
|
1080
|
+
} else if (hasDynamicKeyVBind(node)) modelType = "dynamic";
|
|
1081
|
+
else checkDuplicatedValue();
|
|
1082
|
+
} else if (tag === "select") modelType = "select";
|
|
1083
|
+
else checkDuplicatedValue();
|
|
1084
|
+
else context.options.onError(createDOMCompilerError(DOMErrorCodes.X_V_MODEL_ON_INVALID_ELEMENT, dir.loc));
|
|
1085
|
+
if (modelType) context.registerOperation({
|
|
1086
|
+
type: IRNodeTypes.DIRECTIVE,
|
|
1087
|
+
element: context.reference(),
|
|
1088
|
+
dir,
|
|
1089
|
+
name: "model",
|
|
1090
|
+
modelType,
|
|
1091
|
+
builtin: true
|
|
1092
|
+
});
|
|
1093
|
+
function checkDuplicatedValue() {
|
|
1094
|
+
const value = findProp(node, "value");
|
|
1095
|
+
if (value && value.value?.type !== "StringLiteral") context.options.onError(createDOMCompilerError(DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE, resolveLocation(value.loc, context)));
|
|
1096
|
+
}
|
|
1321
1097
|
};
|
|
1098
|
+
function hasDynamicKeyVBind(node) {
|
|
1099
|
+
return node.openingElement.attributes.some((p) => p.type === "JSXSpreadAttribute" || p.type === "JSXAttribute" && p.name.type === "JSXNamespacedName" && !p.name.namespace.name.startsWith("v-"));
|
|
1100
|
+
}
|
|
1322
1101
|
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
);
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
return {
|
|
1376
|
-
key: arg,
|
|
1377
|
-
value: handler,
|
|
1378
|
-
handler: true,
|
|
1379
|
-
handlerModifiers: {
|
|
1380
|
-
keys: keyModifiers,
|
|
1381
|
-
nonKeys: nonKeyModifiers,
|
|
1382
|
-
options: eventOptionModifiers
|
|
1383
|
-
}
|
|
1384
|
-
};
|
|
1385
|
-
}
|
|
1386
|
-
const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
|
|
1387
|
-
const operation = {
|
|
1388
|
-
type: 5 /* SET_EVENT */,
|
|
1389
|
-
element: context.reference(),
|
|
1390
|
-
key: arg,
|
|
1391
|
-
value: exp,
|
|
1392
|
-
modifiers: {
|
|
1393
|
-
keys: keyModifiers,
|
|
1394
|
-
nonKeys: nonKeyModifiers,
|
|
1395
|
-
options: eventOptionModifiers
|
|
1396
|
-
},
|
|
1397
|
-
keyOverride,
|
|
1398
|
-
delegate,
|
|
1399
|
-
effect: !arg.isStatic
|
|
1400
|
-
};
|
|
1401
|
-
context.registerEffect([arg], operation);
|
|
1102
|
+
//#endregion
|
|
1103
|
+
//#region src/transforms/vOn.ts
|
|
1104
|
+
const delegatedEvents = /* @__PURE__ */ makeMap("beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart");
|
|
1105
|
+
const transformVOn = (dir, node, context) => {
|
|
1106
|
+
const { name, loc, value } = dir;
|
|
1107
|
+
if (name.type === "JSXNamespacedName") return;
|
|
1108
|
+
const isComponent = isJSXComponent(node);
|
|
1109
|
+
const [nameString, ...modifiers] = name.name.replace(/^on([A-Z])/, (_, $1) => $1.toLowerCase()).split("_");
|
|
1110
|
+
if (!value && !modifiers.length) context.options.onError(createCompilerError(ErrorCodes.X_V_ON_NO_EXPRESSION, resolveLocation(loc, context)));
|
|
1111
|
+
let arg = resolveSimpleExpression(nameString, true, dir.name.loc);
|
|
1112
|
+
const exp = resolveExpression(dir.value, context);
|
|
1113
|
+
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(arg.isStatic ? `on${nameString}` : arg, modifiers.map((modifier) => createSimpleExpression(modifier)), null, resolveLocation(loc, context));
|
|
1114
|
+
let keyOverride;
|
|
1115
|
+
const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
|
|
1116
|
+
if (nonKeyModifiers.includes("middle")) {
|
|
1117
|
+
if (keyOverride) {}
|
|
1118
|
+
if (isStaticClick) arg = extend({}, arg, { content: "mouseup" });
|
|
1119
|
+
else if (!arg.isStatic) keyOverride = ["click", "mouseup"];
|
|
1120
|
+
}
|
|
1121
|
+
if (nonKeyModifiers.includes("right")) {
|
|
1122
|
+
if (isStaticClick) arg = extend({}, arg, { content: "contextmenu" });
|
|
1123
|
+
else if (!arg.isStatic) keyOverride = ["click", "contextmenu"];
|
|
1124
|
+
}
|
|
1125
|
+
if (isComponent) {
|
|
1126
|
+
const handler = exp || EMPTY_EXPRESSION;
|
|
1127
|
+
return {
|
|
1128
|
+
key: arg,
|
|
1129
|
+
value: handler,
|
|
1130
|
+
handler: true,
|
|
1131
|
+
handlerModifiers: {
|
|
1132
|
+
keys: keyModifiers,
|
|
1133
|
+
nonKeys: nonKeyModifiers,
|
|
1134
|
+
options: eventOptionModifiers
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
}
|
|
1138
|
+
const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
|
|
1139
|
+
const operation = {
|
|
1140
|
+
type: IRNodeTypes.SET_EVENT,
|
|
1141
|
+
element: context.reference(),
|
|
1142
|
+
key: arg,
|
|
1143
|
+
value: exp,
|
|
1144
|
+
modifiers: {
|
|
1145
|
+
keys: keyModifiers,
|
|
1146
|
+
nonKeys: nonKeyModifiers,
|
|
1147
|
+
options: eventOptionModifiers
|
|
1148
|
+
},
|
|
1149
|
+
keyOverride,
|
|
1150
|
+
delegate,
|
|
1151
|
+
effect: !arg.isStatic
|
|
1152
|
+
};
|
|
1153
|
+
context.registerEffect([arg], operation);
|
|
1402
1154
|
};
|
|
1403
1155
|
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
node.type === "JSXElement" && findProp(node, "v-once")
|
|
1409
|
-
) {
|
|
1410
|
-
context.inVOnce = true;
|
|
1411
|
-
}
|
|
1156
|
+
//#endregion
|
|
1157
|
+
//#region src/transforms/vOnce.ts
|
|
1158
|
+
const transformVOnce = (node, context) => {
|
|
1159
|
+
if (node.type === "JSXElement" && findProp(node, "v-once")) context.inVOnce = true;
|
|
1412
1160
|
};
|
|
1413
1161
|
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1162
|
+
//#endregion
|
|
1163
|
+
//#region src/transforms/vShow.ts
|
|
1164
|
+
const transformVShow = (_dir, node, context) => {
|
|
1165
|
+
const dir = resolveDirective(_dir, context);
|
|
1166
|
+
const { exp, loc } = dir;
|
|
1167
|
+
if (!exp) {
|
|
1168
|
+
context.options.onError(createDOMCompilerError(DOMErrorCodes.X_V_SHOW_NO_EXPRESSION, loc));
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
context.registerOperation({
|
|
1172
|
+
type: IRNodeTypes.DIRECTIVE,
|
|
1173
|
+
element: context.reference(),
|
|
1174
|
+
dir,
|
|
1175
|
+
name: "show",
|
|
1176
|
+
builtin: true
|
|
1177
|
+
});
|
|
1422
1178
|
};
|
|
1423
1179
|
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
if (isComponent && children.length) {
|
|
1438
|
-
return transformComponentSlot(node, resolvedDirective, context);
|
|
1439
|
-
} else if (isSlotTemplate && resolvedDirective) {
|
|
1440
|
-
return transformTemplateSlot(node, resolvedDirective, context);
|
|
1441
|
-
} else if (!isComponent && dir) {
|
|
1442
|
-
context.options.onError(
|
|
1443
|
-
createCompilerError4(
|
|
1444
|
-
ErrorCodes4.X_V_SLOT_MISPLACED,
|
|
1445
|
-
resolveLocation(dir.loc, context)
|
|
1446
|
-
)
|
|
1447
|
-
);
|
|
1448
|
-
}
|
|
1180
|
+
//#endregion
|
|
1181
|
+
//#region src/transforms/vSlot.ts
|
|
1182
|
+
const transformVSlot = (node, context) => {
|
|
1183
|
+
if (node.type !== "JSXElement") return;
|
|
1184
|
+
const { children } = node;
|
|
1185
|
+
const dir = findProp(node, "v-slot");
|
|
1186
|
+
const resolvedDirective = dir ? resolveDirective(dir, context, true) : void 0;
|
|
1187
|
+
const { parent } = context;
|
|
1188
|
+
const isComponent = isJSXComponent(node);
|
|
1189
|
+
const isSlotTemplate = isTemplate(node) && parent && parent.node.type === "JSXElement" && isJSXComponent(parent.node);
|
|
1190
|
+
if (isComponent && children.length) return transformComponentSlot(node, resolvedDirective, context);
|
|
1191
|
+
else if (isSlotTemplate && resolvedDirective) return transformTemplateSlot(node, resolvedDirective, context);
|
|
1192
|
+
else if (!isComponent && dir) context.options.onError(createCompilerError(ErrorCodes.X_V_SLOT_MISPLACED, resolveLocation(dir.loc, context)));
|
|
1449
1193
|
};
|
|
1450
1194
|
function transformComponentSlot(node, dir, context) {
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
createCompilerError4(
|
|
1471
|
-
ErrorCodes4.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN,
|
|
1472
|
-
resolveLocation(nonSlotTemplateChildren[0].loc, context)
|
|
1473
|
-
)
|
|
1474
|
-
);
|
|
1475
|
-
} else {
|
|
1476
|
-
registerSlot(slots, arg, block);
|
|
1477
|
-
context.slots = slots;
|
|
1478
|
-
}
|
|
1479
|
-
} else if (hasOtherSlots) {
|
|
1480
|
-
context.slots = slots;
|
|
1481
|
-
}
|
|
1482
|
-
};
|
|
1195
|
+
const { children } = node;
|
|
1196
|
+
const arg = dir && dir.arg;
|
|
1197
|
+
const nonSlotTemplateChildren = children.filter((n) => !isEmptyText(n) && (n.type !== "JSXElement" || !findProp(n, "v-slot")));
|
|
1198
|
+
const [block, onExit] = createSlotBlock(node, dir, context);
|
|
1199
|
+
const { slots } = context;
|
|
1200
|
+
return () => {
|
|
1201
|
+
onExit();
|
|
1202
|
+
const hasOtherSlots = !!slots.length;
|
|
1203
|
+
if (dir && hasOtherSlots) {
|
|
1204
|
+
context.options.onError(createCompilerError(ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE, dir.loc));
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
if (nonSlotTemplateChildren.length) if (hasStaticSlot(slots, "default")) context.options.onError(createCompilerError(ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN, resolveLocation(nonSlotTemplateChildren[0].loc, context)));
|
|
1208
|
+
else {
|
|
1209
|
+
registerSlot(slots, arg, block);
|
|
1210
|
+
context.slots = slots;
|
|
1211
|
+
}
|
|
1212
|
+
else if (hasOtherSlots) context.slots = slots;
|
|
1213
|
+
};
|
|
1483
1214
|
}
|
|
1484
|
-
|
|
1215
|
+
const elseIfRE = /^v-else(-if)?$/;
|
|
1485
1216
|
function transformTemplateSlot(node, dir, context) {
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
} else if (vFor) {
|
|
1540
|
-
const forParseResult = getForParseResult(vFor, context);
|
|
1541
|
-
if (forParseResult.source) {
|
|
1542
|
-
registerDynamicSlot(slots, {
|
|
1543
|
-
slotType: 2 /* LOOP */,
|
|
1544
|
-
name: arg,
|
|
1545
|
-
fn: block,
|
|
1546
|
-
loop: forParseResult
|
|
1547
|
-
});
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
return onExit;
|
|
1217
|
+
context.dynamic.flags |= DynamicFlag.NON_TEMPLATE;
|
|
1218
|
+
const arg = dir.arg && resolveSimpleExpressionNode(dir.arg);
|
|
1219
|
+
const vFor = findProp(node, "v-for");
|
|
1220
|
+
const vIf = findProp(node, "v-if");
|
|
1221
|
+
const vElse = findProp(node, elseIfRE);
|
|
1222
|
+
const { slots } = context;
|
|
1223
|
+
const [block, onExit] = createSlotBlock(node, dir, context);
|
|
1224
|
+
if (!vFor && !vIf && !vElse) {
|
|
1225
|
+
const slotName = arg ? arg.isStatic && arg.content : "default";
|
|
1226
|
+
if (slotName && hasStaticSlot(slots, slotName)) context.options.onError(createCompilerError(ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES, dir.loc));
|
|
1227
|
+
else registerSlot(slots, arg, block);
|
|
1228
|
+
} else if (vIf) {
|
|
1229
|
+
const vIfDir = resolveDirective(vIf, context);
|
|
1230
|
+
registerDynamicSlot(slots, {
|
|
1231
|
+
slotType: IRSlotType.CONDITIONAL,
|
|
1232
|
+
condition: vIfDir.exp,
|
|
1233
|
+
positive: {
|
|
1234
|
+
slotType: IRSlotType.DYNAMIC,
|
|
1235
|
+
name: arg,
|
|
1236
|
+
fn: block
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
} else if (vElse) {
|
|
1240
|
+
const vElseDir = resolveDirective(vElse, context);
|
|
1241
|
+
const vIfSlot = slots.at(-1);
|
|
1242
|
+
if (vIfSlot.slotType === IRSlotType.CONDITIONAL) {
|
|
1243
|
+
let ifNode = vIfSlot;
|
|
1244
|
+
while (ifNode.negative && ifNode.negative.slotType === IRSlotType.CONDITIONAL) ifNode = ifNode.negative;
|
|
1245
|
+
const negative = vElseDir.exp ? {
|
|
1246
|
+
slotType: IRSlotType.CONDITIONAL,
|
|
1247
|
+
condition: vElseDir.exp,
|
|
1248
|
+
positive: {
|
|
1249
|
+
slotType: IRSlotType.DYNAMIC,
|
|
1250
|
+
name: arg,
|
|
1251
|
+
fn: block
|
|
1252
|
+
}
|
|
1253
|
+
} : {
|
|
1254
|
+
slotType: IRSlotType.DYNAMIC,
|
|
1255
|
+
name: arg,
|
|
1256
|
+
fn: block
|
|
1257
|
+
};
|
|
1258
|
+
ifNode.negative = negative;
|
|
1259
|
+
} else context.options.onError(createCompilerError(ErrorCodes.X_V_ELSE_NO_ADJACENT_IF, vElseDir.loc));
|
|
1260
|
+
} else if (vFor) {
|
|
1261
|
+
const forParseResult = getForParseResult(vFor, context);
|
|
1262
|
+
if (forParseResult.source) registerDynamicSlot(slots, {
|
|
1263
|
+
slotType: IRSlotType.LOOP,
|
|
1264
|
+
name: arg,
|
|
1265
|
+
fn: block,
|
|
1266
|
+
loop: forParseResult
|
|
1267
|
+
});
|
|
1268
|
+
}
|
|
1269
|
+
return onExit;
|
|
1551
1270
|
}
|
|
1552
1271
|
function ensureStaticSlots(slots) {
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
}
|
|
1560
|
-
);
|
|
1561
|
-
}
|
|
1562
|
-
return lastSlots.slots;
|
|
1272
|
+
let lastSlots = slots.at(-1);
|
|
1273
|
+
if (!slots.length || lastSlots.slotType !== IRSlotType.STATIC) slots.push(lastSlots = {
|
|
1274
|
+
slotType: IRSlotType.STATIC,
|
|
1275
|
+
slots: {}
|
|
1276
|
+
});
|
|
1277
|
+
return lastSlots.slots;
|
|
1563
1278
|
}
|
|
1564
1279
|
function registerSlot(slots, name, block) {
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
});
|
|
1575
|
-
}
|
|
1280
|
+
const isStatic = !name || name.isStatic;
|
|
1281
|
+
if (isStatic) {
|
|
1282
|
+
const staticSlots = ensureStaticSlots(slots);
|
|
1283
|
+
staticSlots[name ? name.content : "default"] = block;
|
|
1284
|
+
} else slots.push({
|
|
1285
|
+
slotType: IRSlotType.DYNAMIC,
|
|
1286
|
+
name,
|
|
1287
|
+
fn: block
|
|
1288
|
+
});
|
|
1576
1289
|
}
|
|
1577
1290
|
function registerDynamicSlot(allSlots, dynamic) {
|
|
1578
|
-
|
|
1291
|
+
allSlots.push(dynamic);
|
|
1579
1292
|
}
|
|
1580
1293
|
function hasStaticSlot(slots, name) {
|
|
1581
|
-
|
|
1582
|
-
(slot) => slot.slotType === 0 /* STATIC */ ? !!slot.slots[name] : false
|
|
1583
|
-
);
|
|
1294
|
+
return slots.some((slot) => slot.slotType === IRSlotType.STATIC ? !!slot.slots[name] : false);
|
|
1584
1295
|
}
|
|
1585
1296
|
function createSlotBlock(slotNode, dir, context) {
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1297
|
+
const block = newBlock(slotNode);
|
|
1298
|
+
block.props = dir && dir.exp;
|
|
1299
|
+
const exitBlock = context.enterBlock(block);
|
|
1300
|
+
return [block, exitBlock];
|
|
1590
1301
|
}
|
|
1591
1302
|
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
if (node.children.length) {
|
|
1604
|
-
context.options.onError(
|
|
1605
|
-
createCompilerError5(
|
|
1606
|
-
ErrorCodes5.X_V_SLOT_MIXED_SLOT_USAGE,
|
|
1607
|
-
resolveLocation(node.children[0].loc, context)
|
|
1608
|
-
)
|
|
1609
|
-
);
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1303
|
+
//#endregion
|
|
1304
|
+
//#region src/transforms/vSlots.ts
|
|
1305
|
+
const transformVSlots = (dir, node, context) => {
|
|
1306
|
+
if (!isJSXComponent(node)) return;
|
|
1307
|
+
if (dir.value?.type === "JSXExpressionContainer") {
|
|
1308
|
+
context.slots = [{
|
|
1309
|
+
slotType: IRSlotType.EXPRESSION,
|
|
1310
|
+
slots: resolveExpression(dir.value.expression, context)
|
|
1311
|
+
}];
|
|
1312
|
+
if (node.children.length) context.options.onError(createCompilerError(ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE, resolveLocation(node.children[0].loc, context)));
|
|
1313
|
+
}
|
|
1612
1314
|
};
|
|
1613
1315
|
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1316
|
+
//#endregion
|
|
1317
|
+
//#region src/transforms/vText.ts
|
|
1318
|
+
const transformVText = (dir, node, context) => {
|
|
1319
|
+
let exp;
|
|
1320
|
+
const loc = resolveLocation(dir.loc, context);
|
|
1321
|
+
if (!dir.value) {
|
|
1322
|
+
context.options.onError(createDOMCompilerError(DOMErrorCodes.X_V_TEXT_NO_EXPRESSION, loc));
|
|
1323
|
+
exp = EMPTY_EXPRESSION;
|
|
1324
|
+
} else exp = resolveExpression(dir.value, context);
|
|
1325
|
+
if (node.children.length) {
|
|
1326
|
+
context.options.onError(createDOMCompilerError(DOMErrorCodes.X_V_TEXT_WITH_CHILDREN, loc));
|
|
1327
|
+
context.childrenTemplate.length = 0;
|
|
1328
|
+
}
|
|
1329
|
+
if (isVoidTag(getText(node.openingElement.name, context))) return;
|
|
1330
|
+
const literal = getLiteralExpressionValue(exp);
|
|
1331
|
+
if (literal != null) context.childrenTemplate = [String(literal)];
|
|
1332
|
+
else {
|
|
1333
|
+
context.childrenTemplate = [" "];
|
|
1334
|
+
context.registerOperation({
|
|
1335
|
+
type: IRNodeTypes.GET_TEXT_CHILD,
|
|
1336
|
+
parent: context.reference()
|
|
1337
|
+
});
|
|
1338
|
+
context.registerEffect([exp], {
|
|
1339
|
+
type: IRNodeTypes.SET_TEXT,
|
|
1340
|
+
element: context.reference(),
|
|
1341
|
+
values: [exp],
|
|
1342
|
+
generated: true
|
|
1343
|
+
});
|
|
1344
|
+
}
|
|
1622
1345
|
};
|
|
1623
1346
|
|
|
1624
|
-
|
|
1347
|
+
//#endregion
|
|
1348
|
+
//#region src/compile.ts
|
|
1625
1349
|
function compile(source, options = {}) {
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
ast,
|
|
1656
|
-
extend5({}, resolvedOptions, {
|
|
1657
|
-
nodeTransforms: [
|
|
1658
|
-
...nodeTransforms,
|
|
1659
|
-
...resolvedOptions.nodeTransforms || []
|
|
1660
|
-
// user transforms
|
|
1661
|
-
],
|
|
1662
|
-
directiveTransforms: extend5(
|
|
1663
|
-
{},
|
|
1664
|
-
directiveTransforms,
|
|
1665
|
-
resolvedOptions.directiveTransforms || {}
|
|
1666
|
-
// user transforms
|
|
1667
|
-
)
|
|
1668
|
-
})
|
|
1669
|
-
);
|
|
1670
|
-
return generate(ir, {
|
|
1671
|
-
...resolvedOptions,
|
|
1672
|
-
customGenOperation
|
|
1673
|
-
});
|
|
1350
|
+
const resolvedOptions = extend({}, options, {
|
|
1351
|
+
inline: true,
|
|
1352
|
+
prefixIdentifiers: false,
|
|
1353
|
+
expressionPlugins: options.expressionPlugins || ["jsx"]
|
|
1354
|
+
});
|
|
1355
|
+
if (!resolvedOptions.source && isString(source)) resolvedOptions.source = source;
|
|
1356
|
+
if (resolvedOptions.isTS) {
|
|
1357
|
+
const { expressionPlugins } = resolvedOptions;
|
|
1358
|
+
if (!expressionPlugins.includes("typescript")) resolvedOptions.expressionPlugins = [...expressionPlugins || [], "typescript"];
|
|
1359
|
+
}
|
|
1360
|
+
const root = isString(source) ? parse(source, {
|
|
1361
|
+
sourceType: "module",
|
|
1362
|
+
plugins: resolvedOptions.expressionPlugins
|
|
1363
|
+
}).program.body[0].expression : source;
|
|
1364
|
+
const children = root.type === "JSXFragment" ? root.children : root.type === "JSXElement" ? [root] : [];
|
|
1365
|
+
const ast = {
|
|
1366
|
+
type: IRNodeTypes.ROOT,
|
|
1367
|
+
children,
|
|
1368
|
+
source: resolvedOptions.source || ""
|
|
1369
|
+
};
|
|
1370
|
+
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
|
|
1371
|
+
const ir = transform(ast, extend({}, resolvedOptions, {
|
|
1372
|
+
nodeTransforms: [...nodeTransforms, ...resolvedOptions.nodeTransforms || []],
|
|
1373
|
+
directiveTransforms: extend({}, directiveTransforms, resolvedOptions.directiveTransforms || {})
|
|
1374
|
+
}));
|
|
1375
|
+
return generate(ir, {
|
|
1376
|
+
...resolvedOptions,
|
|
1377
|
+
customGenOperation
|
|
1378
|
+
});
|
|
1674
1379
|
}
|
|
1675
1380
|
function getBaseTransformPreset() {
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
slots: transformVSlots
|
|
1695
|
-
}
|
|
1696
|
-
];
|
|
1381
|
+
return [[
|
|
1382
|
+
transformVOnce,
|
|
1383
|
+
transformVIf,
|
|
1384
|
+
transformVFor,
|
|
1385
|
+
transformTemplateRef,
|
|
1386
|
+
transformText,
|
|
1387
|
+
transformElement,
|
|
1388
|
+
transformVSlot,
|
|
1389
|
+
transformChildren
|
|
1390
|
+
], {
|
|
1391
|
+
bind: transformVBind,
|
|
1392
|
+
on: transformVOn,
|
|
1393
|
+
model: transformVModel,
|
|
1394
|
+
show: transformVShow,
|
|
1395
|
+
html: transformVHtml,
|
|
1396
|
+
text: transformVText,
|
|
1397
|
+
slots: transformVSlots
|
|
1398
|
+
}];
|
|
1697
1399
|
}
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
IRNodeTypes,
|
|
1702
|
-
IRSlotType,
|
|
1703
|
-
TransformContext,
|
|
1704
|
-
compile,
|
|
1705
|
-
createStructuralDirectiveTransform,
|
|
1706
|
-
generate,
|
|
1707
|
-
isBlockOperation,
|
|
1708
|
-
resolveDirectiveNode,
|
|
1709
|
-
resolveNode,
|
|
1710
|
-
transform,
|
|
1711
|
-
transformChildren,
|
|
1712
|
-
transformElement,
|
|
1713
|
-
transformNode,
|
|
1714
|
-
transformTemplateRef,
|
|
1715
|
-
transformText,
|
|
1716
|
-
transformVBind,
|
|
1717
|
-
transformVFor,
|
|
1718
|
-
transformVHtml,
|
|
1719
|
-
transformVIf,
|
|
1720
|
-
transformVModel,
|
|
1721
|
-
transformVOn,
|
|
1722
|
-
transformVOnce,
|
|
1723
|
-
transformVShow,
|
|
1724
|
-
transformVSlot,
|
|
1725
|
-
transformVSlots,
|
|
1726
|
-
transformVText
|
|
1727
|
-
};
|
|
1400
|
+
|
|
1401
|
+
//#endregion
|
|
1402
|
+
export { DynamicFlag, IRDynamicPropsKind, IRNodeTypes, IRSlotType, TransformContext, compile, createStructuralDirectiveTransform, generate, isBlockOperation, transform, transformChildren, transformElement, transformNode, transformTemplateRef, transformText, transformVBind, transformVFor, transformVHtml, transformVIf, transformVModel, transformVOn, transformVOnce, transformVShow, transformVSlot, transformVSlots, transformVText };
|