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