@dcloudio/uni-cli-shared 3.0.0-5020320260806002 → 3.0.0-5020420260811002
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/resolve.d.ts +8 -0
- package/dist/resolve.js +78 -2
- package/lib/dom2/@intlify/core-base/LICENSE +20 -0
- package/lib/dom2/@intlify/core-base/dist/core-base.mjs +1903 -0
- package/lib/dom2/@intlify/core-base/package.json +11 -0
- package/lib/dom2/@intlify/message-compiler/LICENSE +20 -0
- package/lib/dom2/@intlify/message-compiler/dist/message-compiler.mjs +1550 -0
- package/lib/dom2/@intlify/message-compiler/package.json +11 -0
- package/lib/dom2/@intlify/shared/LICENSE +20 -0
- package/lib/dom2/@intlify/shared/dist/shared.mjs +333 -0
- package/lib/dom2/@intlify/shared/package.json +11 -0
- package/lib/dom2/@vue/devtools-api/LICENSE +21 -0
- package/lib/dom2/@vue/devtools-api/dist/index.js +26 -0
- package/lib/dom2/@vue/devtools-api/package.json +12 -0
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +71 -68
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +71 -68
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +2 -20
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +53 -29
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +23 -12
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +22 -12
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +80 -30
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +5 -5
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +20 -3
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +369 -317
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +5 -5
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +2032 -5522
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.d.ts +11114 -33
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +2825 -4668
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +905 -2413
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +378 -544
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +998 -2549
- package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -1
- package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +26 -92
- package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +26 -92
- package/lib/dom2/app/@vue/shared/dist/shared.d.ts +2 -94
- package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +24 -83
- package/lib/dom2/pinia/LICENSE +21 -0
- package/lib/dom2/pinia/dist/pinia.mjs +1941 -0
- package/lib/dom2/pinia/package.json +11 -0
- package/lib/dom2/vue-i18n/LICENSE +20 -0
- package/lib/dom2/vue-i18n/dist/vue-i18n.esm-bundler.js +1 -0
- package/lib/dom2/vue-i18n/dist/vue-i18n.mjs +2501 -0
- package/lib/dom2/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js +1 -0
- package/lib/dom2/vue-i18n/dist/vue-i18n.runtime.mjs +2501 -0
- package/lib/dom2/vue-i18n/package.json +12 -0
- package/package.json +5 -5
|
@@ -1,105 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-vapor v3.6.0-beta.
|
|
2
|
+
* @vue/compiler-vapor v3.6.0-beta.5
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
6
|
-
Object.defineProperties(exports, {
|
|
7
|
-
__esModule: { value: true },
|
|
8
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
9
|
-
});
|
|
6
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
10
7
|
let _vue_compiler_dom = require("@vue/compiler-dom");
|
|
11
8
|
let _vue_shared = require("@vue/shared");
|
|
12
9
|
let source_map_js = require("source-map-js");
|
|
13
10
|
let _babel_parser = require("@babel/parser");
|
|
14
11
|
let estree_walker = require("estree-walker");
|
|
15
|
-
|
|
16
|
-
const IRDynamicPropsKind = {
|
|
17
|
-
"EXPRESSION": 0,
|
|
18
|
-
"0": "EXPRESSION",
|
|
19
|
-
"ATTRIBUTE": 1,
|
|
20
|
-
"1": "ATTRIBUTE"
|
|
21
|
-
};
|
|
22
|
-
const IRSlotType = {
|
|
23
|
-
"STATIC": 0,
|
|
24
|
-
"0": "STATIC",
|
|
25
|
-
"DYNAMIC": 1,
|
|
26
|
-
"1": "DYNAMIC",
|
|
27
|
-
"LOOP": 2,
|
|
28
|
-
"2": "LOOP",
|
|
29
|
-
"CONDITIONAL": 3,
|
|
30
|
-
"3": "CONDITIONAL",
|
|
31
|
-
"EXPRESSION": 4,
|
|
32
|
-
"4": "EXPRESSION"
|
|
33
|
-
};
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region packages/compiler-vapor/src/ir/index.ts
|
|
36
|
-
const IRNodeTypes = {
|
|
37
|
-
"ROOT": 0,
|
|
38
|
-
"0": "ROOT",
|
|
39
|
-
"BLOCK": 1,
|
|
40
|
-
"1": "BLOCK",
|
|
41
|
-
"SET_BLOCK_KEY": 2,
|
|
42
|
-
"2": "SET_BLOCK_KEY",
|
|
43
|
-
"SET_PROP": 3,
|
|
44
|
-
"3": "SET_PROP",
|
|
45
|
-
"SET_DYNAMIC_PROPS": 4,
|
|
46
|
-
"4": "SET_DYNAMIC_PROPS",
|
|
47
|
-
"SET_TEXT": 5,
|
|
48
|
-
"5": "SET_TEXT",
|
|
49
|
-
"SET_EVENT": 6,
|
|
50
|
-
"6": "SET_EVENT",
|
|
51
|
-
"SET_DYNAMIC_EVENTS": 7,
|
|
52
|
-
"7": "SET_DYNAMIC_EVENTS",
|
|
53
|
-
"SET_HTML": 8,
|
|
54
|
-
"8": "SET_HTML",
|
|
55
|
-
"SET_TEMPLATE_REF": 9,
|
|
56
|
-
"9": "SET_TEMPLATE_REF",
|
|
57
|
-
"INSERT_NODE": 10,
|
|
58
|
-
"10": "INSERT_NODE",
|
|
59
|
-
"PREPEND_NODE": 11,
|
|
60
|
-
"11": "PREPEND_NODE",
|
|
61
|
-
"CREATE_COMPONENT_NODE": 12,
|
|
62
|
-
"12": "CREATE_COMPONENT_NODE",
|
|
63
|
-
"SLOT_OUTLET_NODE": 13,
|
|
64
|
-
"13": "SLOT_OUTLET_NODE",
|
|
65
|
-
"DIRECTIVE": 14,
|
|
66
|
-
"14": "DIRECTIVE",
|
|
67
|
-
"IF": 15,
|
|
68
|
-
"15": "IF",
|
|
69
|
-
"FOR": 16,
|
|
70
|
-
"16": "FOR",
|
|
71
|
-
"KEY": 17,
|
|
72
|
-
"17": "KEY",
|
|
73
|
-
"GET_TEXT_CHILD": 18,
|
|
74
|
-
"18": "GET_TEXT_CHILD",
|
|
75
|
-
"GET_INSERTION_PARENT": 19,
|
|
76
|
-
"19": "GET_INSERTION_PARENT",
|
|
77
|
-
"SET_CHANGE_PROP": 20,
|
|
78
|
-
"20": "SET_CHANGE_PROP"
|
|
79
|
-
};
|
|
80
|
-
var TemplateRegistry = class {
|
|
81
|
-
constructor() {
|
|
82
|
-
this.entries = [];
|
|
83
|
-
}
|
|
84
|
-
keys() {
|
|
85
|
-
return this.entries.map(({ content }) => content);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const DynamicFlag = {
|
|
89
|
-
"NONE": 0,
|
|
90
|
-
"0": "NONE",
|
|
91
|
-
"REFERENCED": 1,
|
|
92
|
-
"1": "REFERENCED",
|
|
93
|
-
"NON_TEMPLATE": 2,
|
|
94
|
-
"2": "NON_TEMPLATE",
|
|
95
|
-
"INSERT": 4,
|
|
96
|
-
"4": "INSERT"
|
|
97
|
-
};
|
|
98
|
-
function isBlockOperation(op) {
|
|
99
|
-
const type = op.type;
|
|
100
|
-
return type === 12 || type === 13 || type === 15 || type === 17 || type === 16;
|
|
101
|
-
}
|
|
102
|
-
//#endregion
|
|
12
|
+
|
|
103
13
|
//#region packages/compiler-vapor/src/transforms/utils.ts
|
|
104
14
|
const newDynamic = () => ({
|
|
105
15
|
flags: 1,
|
|
@@ -140,7 +50,7 @@ function wrapTemplate(node, dirs) {
|
|
|
140
50
|
const reserved = [];
|
|
141
51
|
const pass = [];
|
|
142
52
|
node.props.forEach((prop) => {
|
|
143
|
-
if (prop.type === 7 &&
|
|
53
|
+
if (prop.type === 7 && dirs.includes(prop.name)) reserved.push(prop);
|
|
144
54
|
else pass.push(prop);
|
|
145
55
|
});
|
|
146
56
|
return (0, _vue_shared.extend)({}, node, {
|
|
@@ -154,11 +64,12 @@ function wrapTemplate(node, dirs) {
|
|
|
154
64
|
const EMPTY_EXPRESSION = (0, _vue_compiler_dom.createSimpleExpression)("", true);
|
|
155
65
|
const TEXT_PLACEHOLDER = "__vapor_dom2_text_placeholder__";
|
|
156
66
|
const TEXT_NODE_PLACEHOLDER = "__vapor_dom2_text_node_placeholder__";
|
|
67
|
+
|
|
157
68
|
//#endregion
|
|
158
69
|
//#region packages/compiler-vapor/src/utils.ts
|
|
159
70
|
const findProp$1 = _vue_compiler_dom.findProp;
|
|
160
71
|
/** find directive */
|
|
161
|
-
const findDir$
|
|
72
|
+
const findDir$2 = _vue_compiler_dom.findDir;
|
|
162
73
|
function propToExpression(prop) {
|
|
163
74
|
return prop.type === 6 ? prop.value ? (0, _vue_compiler_dom.createSimpleExpression)(prop.value.content, true, prop.value.loc) : EMPTY_EXPRESSION : prop.exp;
|
|
164
75
|
}
|
|
@@ -168,7 +79,7 @@ function isConstantExpression(exp) {
|
|
|
168
79
|
function isStaticExpression(node, bindings) {
|
|
169
80
|
if (node.ast) return (0, _vue_compiler_dom.isConstantNode)(node.ast, bindings);
|
|
170
81
|
else if (node.ast === null) {
|
|
171
|
-
if (!node.isStatic && (node.content === "true" || node.content === "false"
|
|
82
|
+
if (!node.isStatic && (node.content === "true" || node.content === "false")) return true;
|
|
172
83
|
return bindings[node.content] === "literal-const";
|
|
173
84
|
}
|
|
174
85
|
return false;
|
|
@@ -180,12 +91,6 @@ function resolveExpression(exp, isComponent) {
|
|
|
180
91
|
}
|
|
181
92
|
return exp;
|
|
182
93
|
}
|
|
183
|
-
function parseStaticAttrBooleanExpression(exp) {
|
|
184
|
-
try {
|
|
185
|
-
return (0, _vue_shared.includeBooleanAttr)(exp.isStatic ? exp.content : new Function(`return ${exp.content}`)());
|
|
186
|
-
} catch (e) {}
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
94
|
function getLiteralExpressionValue(exp, excludeNumber) {
|
|
190
95
|
if (exp.ast) {
|
|
191
96
|
if (exp.ast.type === "StringLiteral") return exp.ast.value;
|
|
@@ -230,19 +135,14 @@ function isTeleportTag(tag) {
|
|
|
230
135
|
}
|
|
231
136
|
function isBuiltInComponent(tag) {
|
|
232
137
|
if (isTeleportTag(tag)) return "VaporTeleport";
|
|
233
|
-
else if (tag === "Suspense" || tag === "suspense") return "Suspense";
|
|
234
138
|
else if (isKeepAliveTag(tag)) return "VaporKeepAlive";
|
|
235
139
|
else if (isTransitionTag(tag)) return "VaporTransition";
|
|
236
140
|
else if (isTransitionGroupTag(tag)) return "VaporTransitionGroup";
|
|
237
141
|
}
|
|
238
|
-
|
|
239
|
-
if (block.returns.length === 0) return 0;
|
|
240
|
-
return block.returns.length === 1 ? 1 : 2;
|
|
241
|
-
}
|
|
142
|
+
|
|
242
143
|
//#endregion
|
|
243
144
|
//#region packages/compiler-vapor/src/transform.ts
|
|
244
145
|
const generatedVarRE = /^[nxr](\d+)$/;
|
|
245
|
-
const childContextInfoCache = /* @__PURE__ */ new WeakMap();
|
|
246
146
|
var TransformContext = class TransformContext {
|
|
247
147
|
constructor(ir, node, options = {}) {
|
|
248
148
|
this.ir = ir;
|
|
@@ -253,8 +153,6 @@ var TransformContext = class TransformContext {
|
|
|
253
153
|
this.index = 0;
|
|
254
154
|
this.block = this.ir.block;
|
|
255
155
|
this.template = "";
|
|
256
|
-
this.templateRoot = false;
|
|
257
|
-
this.templateIndexMap = /* @__PURE__ */ new Map();
|
|
258
156
|
this.childrenTemplate = [];
|
|
259
157
|
this.dynamic = this.ir.block.dynamic;
|
|
260
158
|
this.imports = [];
|
|
@@ -264,13 +162,9 @@ var TransformContext = class TransformContext {
|
|
|
264
162
|
this.component = this.ir.component;
|
|
265
163
|
this.directive = this.ir.directive;
|
|
266
164
|
this.slots = [];
|
|
267
|
-
this.effectIndex = this.block.effect.length;
|
|
268
|
-
this.operationIndex = this.block.operation.length;
|
|
269
165
|
this.isLastEffectiveChild = true;
|
|
270
166
|
this.isOnRightmostPath = true;
|
|
271
|
-
this.
|
|
272
|
-
this.templateCloseTags = void 0;
|
|
273
|
-
this.templateCloseBlocks = false;
|
|
167
|
+
this.hasInlineAncestorNeedingClose = false;
|
|
274
168
|
this.globalId = 0;
|
|
275
169
|
this.nextIdMap = null;
|
|
276
170
|
this.ifIndex = 0;
|
|
@@ -285,28 +179,20 @@ var TransformContext = class TransformContext {
|
|
|
285
179
|
this.initNextIdMap();
|
|
286
180
|
}
|
|
287
181
|
enterBlock(ir, isVFor = false) {
|
|
288
|
-
const { block, template,
|
|
182
|
+
const { block, template, dynamic, childrenTemplate, slots } = this;
|
|
289
183
|
this.block = ir;
|
|
290
184
|
this.dynamic = ir.dynamic;
|
|
291
185
|
this.template = "";
|
|
292
|
-
this.templateRoot = false;
|
|
293
|
-
this.templateIndexMap = templateIndexMap;
|
|
294
186
|
this.childrenTemplate = [];
|
|
295
187
|
this.slots = [];
|
|
296
|
-
this.effectIndex = ir.effect.length;
|
|
297
|
-
this.operationIndex = ir.operation.length;
|
|
298
188
|
isVFor && this.inVFor++;
|
|
299
189
|
return () => {
|
|
300
190
|
this.registerTemplate();
|
|
301
191
|
this.block = block;
|
|
302
192
|
this.template = template;
|
|
303
|
-
this.templateRoot = templateRoot;
|
|
304
|
-
this.templateIndexMap = templateIndexMap;
|
|
305
193
|
this.dynamic = dynamic;
|
|
306
194
|
this.childrenTemplate = childrenTemplate;
|
|
307
195
|
this.slots = slots;
|
|
308
|
-
this.effectIndex = effectIndex;
|
|
309
|
-
this.operationIndex = operationIndex;
|
|
310
196
|
isVFor && this.inVFor--;
|
|
311
197
|
};
|
|
312
198
|
}
|
|
@@ -331,163 +217,66 @@ var TransformContext = class TransformContext {
|
|
|
331
217
|
nextIfIndex() {
|
|
332
218
|
return this.ifIndex++;
|
|
333
219
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
canUseStaticTemplate() {
|
|
338
|
-
if (!this.template) return false;
|
|
339
|
-
if (this.inVFor) return false;
|
|
340
|
-
if (this.dynamic.hasDynamicChild) return false;
|
|
341
|
-
if (this.block.effect.length !== this.effectIndex) return false;
|
|
342
|
-
if (this.block.operation.length !== this.operationIndex) return false;
|
|
343
|
-
if (this.node.type === 2 || this.node.type === 3) return true;
|
|
344
|
-
return this.node.type === 1 && this.node.tagType === 0 && !(this.options.isCustomElement(this.node.tag) || this.node.tag === "template");
|
|
345
|
-
}
|
|
346
|
-
pushTemplate(content, { root = false, static: isStatic = false } = {}) {
|
|
347
|
-
const templateKey = JSON.stringify([
|
|
348
|
-
this.getTemplateNamespace(),
|
|
349
|
-
root,
|
|
350
|
-
isStatic,
|
|
351
|
-
content
|
|
352
|
-
]);
|
|
353
|
-
const existingIndex = this.templateIndexMap.get(templateKey);
|
|
220
|
+
pushTemplate(content) {
|
|
221
|
+
const existingIndex = this.ir.templateIndexMap.get(content);
|
|
354
222
|
if (existingIndex !== void 0) return existingIndex;
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
this.ir.
|
|
358
|
-
content,
|
|
359
|
-
ns,
|
|
360
|
-
root,
|
|
361
|
-
static: isStatic
|
|
362
|
-
});
|
|
363
|
-
this.templateIndexMap.set(templateKey, newIndex);
|
|
223
|
+
const newIndex = this.ir.template.size;
|
|
224
|
+
this.ir.template.set(content, this.node.ns);
|
|
225
|
+
this.ir.templateIndexMap.set(content, newIndex);
|
|
364
226
|
return newIndex;
|
|
365
227
|
}
|
|
366
228
|
registerTemplate() {
|
|
367
229
|
if (!this.template) return -1;
|
|
368
|
-
const id = this.pushTemplate(this.template
|
|
369
|
-
root: this.templateRoot,
|
|
370
|
-
static: this.canUseStaticTemplate()
|
|
371
|
-
});
|
|
230
|
+
const id = this.pushTemplate(this.template);
|
|
372
231
|
return this.dynamic.template = id;
|
|
373
232
|
}
|
|
374
|
-
registerEffect(expressions, operation, getIndex, getOperationIndex) {
|
|
233
|
+
registerEffect(expressions, operation, getIndex = () => this.block.effect.length, getOperationIndex) {
|
|
375
234
|
const operations = [operation].flat();
|
|
376
235
|
expressions = expressions.filter((exp) => !isConstantExpression(exp));
|
|
377
236
|
if (this.inVOnce || expressions.length === 0 || expressions.every((e) => isStaticExpression(e, this.root.options.bindingMetadata))) {
|
|
378
237
|
if (getOperationIndex) {
|
|
379
|
-
|
|
380
|
-
this.block.operation.splice(index, 0, ...operations);
|
|
381
|
-
this.shiftOperationBoundaries(index, operations.length);
|
|
238
|
+
this.block.operation.splice(getOperationIndex(), 0, ...operations);
|
|
382
239
|
return;
|
|
383
240
|
}
|
|
384
241
|
return this.registerOperation(...operations);
|
|
385
242
|
}
|
|
386
|
-
|
|
387
|
-
this.block.effect.splice(index, 0, {
|
|
243
|
+
this.block.effect.splice(getIndex(), 0, {
|
|
388
244
|
expressions,
|
|
389
245
|
operations
|
|
390
246
|
});
|
|
391
|
-
if (getIndex) this.shiftEffectBoundaries(index);
|
|
392
247
|
}
|
|
393
248
|
registerOperation(...node) {
|
|
394
249
|
this.block.operation.push(...node);
|
|
395
250
|
}
|
|
396
|
-
effectBoundary() {
|
|
397
|
-
return {
|
|
398
|
-
operationIndex: this.operationIndex,
|
|
399
|
-
effectIndex: this.effectIndex
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
251
|
create(node, index) {
|
|
403
252
|
let effectiveParent = this;
|
|
404
253
|
while (effectiveParent && effectiveParent.node.type === 1 && effectiveParent.node.tagType === 3) effectiveParent = effectiveParent.parent;
|
|
405
|
-
const
|
|
406
|
-
const isLastEffectiveChild = childInfo.isLastEffectiveChild[index];
|
|
254
|
+
const isLastEffectiveChild = this.isEffectivelyLastChild(index);
|
|
407
255
|
const isOnRightmostPath = this.isOnRightmostPath && isLastEffectiveChild;
|
|
408
|
-
|
|
256
|
+
let hasInlineAncestorNeedingClose = this.hasInlineAncestorNeedingClose;
|
|
257
|
+
if (this.node.type === 1) {
|
|
258
|
+
if (this.node.tag === "template") hasInlineAncestorNeedingClose = false;
|
|
259
|
+
else if (!hasInlineAncestorNeedingClose && !this.isOnRightmostPath && (0, _vue_shared.isInlineTag)(this.node.tag)) hasInlineAncestorNeedingClose = true;
|
|
260
|
+
}
|
|
409
261
|
return Object.assign(Object.create(TransformContext.prototype), this, {
|
|
410
262
|
node,
|
|
411
263
|
parent: this,
|
|
412
264
|
index,
|
|
413
265
|
template: "",
|
|
414
|
-
templateRoot: false,
|
|
415
266
|
childrenTemplate: [],
|
|
416
|
-
templateIndexMap: this.templateIndexMap,
|
|
417
267
|
dynamic: newDynamic(),
|
|
418
|
-
effectIndex: this.block.effect.length,
|
|
419
|
-
operationIndex: this.block.operation.length,
|
|
420
268
|
effectiveParent,
|
|
421
269
|
isLastEffectiveChild,
|
|
422
270
|
isOnRightmostPath,
|
|
423
|
-
|
|
424
|
-
templateCloseTags: this.templateCloseTags,
|
|
425
|
-
templateCloseBlocks: this.templateCloseBlocks
|
|
271
|
+
hasInlineAncestorNeedingClose
|
|
426
272
|
});
|
|
427
273
|
}
|
|
428
|
-
|
|
429
|
-
const
|
|
430
|
-
if (
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
shiftOperationBoundaries(index, offset, dynamic = this.dynamic) {
|
|
434
|
-
const operation = dynamic.operation;
|
|
435
|
-
if (operation && isBlockOperation(operation) && operation.operationIndex !== void 0 && operation.operationIndex >= index) operation.operationIndex += offset;
|
|
436
|
-
for (const child of dynamic.children) this.shiftOperationBoundaries(index, offset, child);
|
|
437
|
-
}
|
|
438
|
-
getChildContextInfo() {
|
|
439
|
-
const node = this.node;
|
|
440
|
-
if (node.type !== 0 && node.type !== 1) return {
|
|
441
|
-
node,
|
|
442
|
-
hasSingleRootChild: true,
|
|
443
|
-
isLastEffectiveChild: []
|
|
444
|
-
};
|
|
445
|
-
const cached = childContextInfoCache.get(this);
|
|
446
|
-
if (cached && cached.node === node) return cached;
|
|
447
|
-
const { children } = node;
|
|
448
|
-
const isLastEffectiveChild = new Array(children.length);
|
|
449
|
-
let hasFollowingEffectiveChild = false;
|
|
450
|
-
for (let i = children.length - 1; i >= 0; i--) {
|
|
451
|
-
isLastEffectiveChild[i] = !hasFollowingEffectiveChild;
|
|
452
|
-
if (!isComponentChild(children[i])) hasFollowingEffectiveChild = true;
|
|
453
|
-
}
|
|
454
|
-
const childInfo = {
|
|
455
|
-
node,
|
|
456
|
-
hasSingleRootChild: hasSingleRootChild(children),
|
|
457
|
-
isLastEffectiveChild
|
|
458
|
-
};
|
|
459
|
-
childContextInfoCache.set(this, childInfo);
|
|
460
|
-
return childInfo;
|
|
461
|
-
}
|
|
462
|
-
isSingleRootChild(childInfo) {
|
|
463
|
-
if (this.inVFor || !childInfo.hasSingleRootChild) return false;
|
|
464
|
-
if (this.node.type === 0) return true;
|
|
465
|
-
return this.node.type === 1 && this.node.tagType === 3 && !!this.parent && this.isSingleRoot;
|
|
274
|
+
isEffectivelyLastChild(index) {
|
|
275
|
+
const children = this.node.children;
|
|
276
|
+
if (!children) return true;
|
|
277
|
+
return children.every((c, i) => i <= index || c.type === 1 && c.tagType === 1);
|
|
466
278
|
}
|
|
467
279
|
};
|
|
468
|
-
function hasSingleRootChild(children) {
|
|
469
|
-
let nonCommentChildren = 0;
|
|
470
|
-
let hasEncounteredIf = false;
|
|
471
|
-
let isSingleIfBlock = true;
|
|
472
|
-
for (const child of children) {
|
|
473
|
-
if ((0, _vue_compiler_dom.isCommentOrWhitespace)(child)) continue;
|
|
474
|
-
nonCommentChildren++;
|
|
475
|
-
if (isIfChild(child)) {
|
|
476
|
-
if (hasEncounteredIf) isSingleIfBlock = false;
|
|
477
|
-
hasEncounteredIf = true;
|
|
478
|
-
} else if (!hasEncounteredIf || !isElseChild(child)) isSingleIfBlock = false;
|
|
479
|
-
}
|
|
480
|
-
return nonCommentChildren === 1 || isSingleIfBlock;
|
|
481
|
-
}
|
|
482
|
-
function isComponentChild(child) {
|
|
483
|
-
return child.type === 1 && child.tagType === 1;
|
|
484
|
-
}
|
|
485
|
-
function isIfChild(child) {
|
|
486
|
-
return child.type === 9 || child.type === 1 && !!(0, _vue_compiler_dom.findDir)(child, "if");
|
|
487
|
-
}
|
|
488
|
-
function isElseChild(child) {
|
|
489
|
-
return child.type === 1 && !!(0, _vue_compiler_dom.findDir)(child, /^else(-if)?$/, true);
|
|
490
|
-
}
|
|
491
280
|
const defaultOptions = {
|
|
492
281
|
filename: "",
|
|
493
282
|
prefixIdentifiers: true,
|
|
@@ -511,7 +300,6 @@ const defaultOptions = {
|
|
|
511
300
|
bindingMetadata: _vue_shared.EMPTY_OBJ,
|
|
512
301
|
inline: false,
|
|
513
302
|
isTS: false,
|
|
514
|
-
eventDelegation: true,
|
|
515
303
|
onError: _vue_compiler_dom.defaultOnError,
|
|
516
304
|
onWarn: _vue_compiler_dom.defaultOnWarn
|
|
517
305
|
};
|
|
@@ -520,11 +308,14 @@ function transform(node, options = {}) {
|
|
|
520
308
|
type: 0,
|
|
521
309
|
node,
|
|
522
310
|
source: node.source,
|
|
523
|
-
template: new
|
|
311
|
+
template: /* @__PURE__ */ new Map(),
|
|
312
|
+
templateIndexMap: /* @__PURE__ */ new Map(),
|
|
313
|
+
rootTemplateIndexes: /* @__PURE__ */ new Set(),
|
|
524
314
|
component: /* @__PURE__ */ new Set(),
|
|
525
315
|
directive: /* @__PURE__ */ new Set(),
|
|
526
316
|
block: newBlock(node),
|
|
527
|
-
hasTemplateRef: false
|
|
317
|
+
hasTemplateRef: false,
|
|
318
|
+
hasDeferredVShow: false
|
|
528
319
|
};
|
|
529
320
|
const context = new TransformContext(ir, node, options);
|
|
530
321
|
transformNode(context);
|
|
@@ -591,6 +382,7 @@ function getNextId(map, n) {
|
|
|
591
382
|
if (map && map.has(n)) return map.get(n);
|
|
592
383
|
return n;
|
|
593
384
|
}
|
|
385
|
+
|
|
594
386
|
//#endregion
|
|
595
387
|
//#region packages/compiler-vapor/src/generators/utils.ts
|
|
596
388
|
const IMPORT_EXP_START = "__IMPORT_EXP_START__";
|
|
@@ -671,9 +463,6 @@ function genCall(name, ...frags) {
|
|
|
671
463
|
hasPlaceholder ? name[1] : "null"
|
|
672
464
|
], ...frags)];
|
|
673
465
|
}
|
|
674
|
-
function getParserOptions(plugins) {
|
|
675
|
-
return { plugins: plugins ? plugins.some((plugin) => plugin === "typescript") ? plugins : [...plugins, "typescript"] : ["typescript"] };
|
|
676
|
-
}
|
|
677
466
|
function codeFragmentToString(code, context) {
|
|
678
467
|
const { options: { sourceMap } } = context;
|
|
679
468
|
const filename = context.options.relativeFilename || context.options.filename;
|
|
@@ -737,6 +526,85 @@ function codeFragmentToString(code, context) {
|
|
|
737
526
|
});
|
|
738
527
|
}
|
|
739
528
|
}
|
|
529
|
+
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region packages/compiler-vapor/src/ir/component.ts
|
|
532
|
+
const IRDynamicPropsKind = {
|
|
533
|
+
"EXPRESSION": 0,
|
|
534
|
+
"0": "EXPRESSION",
|
|
535
|
+
"ATTRIBUTE": 1,
|
|
536
|
+
"1": "ATTRIBUTE"
|
|
537
|
+
};
|
|
538
|
+
const IRSlotType = {
|
|
539
|
+
"STATIC": 0,
|
|
540
|
+
"0": "STATIC",
|
|
541
|
+
"DYNAMIC": 1,
|
|
542
|
+
"1": "DYNAMIC",
|
|
543
|
+
"LOOP": 2,
|
|
544
|
+
"2": "LOOP",
|
|
545
|
+
"CONDITIONAL": 3,
|
|
546
|
+
"3": "CONDITIONAL",
|
|
547
|
+
"EXPRESSION": 4,
|
|
548
|
+
"4": "EXPRESSION"
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region packages/compiler-vapor/src/ir/index.ts
|
|
553
|
+
const IRNodeTypes = {
|
|
554
|
+
"ROOT": 0,
|
|
555
|
+
"0": "ROOT",
|
|
556
|
+
"BLOCK": 1,
|
|
557
|
+
"1": "BLOCK",
|
|
558
|
+
"SET_PROP": 2,
|
|
559
|
+
"2": "SET_PROP",
|
|
560
|
+
"SET_DYNAMIC_PROPS": 3,
|
|
561
|
+
"3": "SET_DYNAMIC_PROPS",
|
|
562
|
+
"SET_TEXT": 4,
|
|
563
|
+
"4": "SET_TEXT",
|
|
564
|
+
"SET_EVENT": 5,
|
|
565
|
+
"5": "SET_EVENT",
|
|
566
|
+
"SET_DYNAMIC_EVENTS": 6,
|
|
567
|
+
"6": "SET_DYNAMIC_EVENTS",
|
|
568
|
+
"SET_HTML": 7,
|
|
569
|
+
"7": "SET_HTML",
|
|
570
|
+
"SET_TEMPLATE_REF": 8,
|
|
571
|
+
"8": "SET_TEMPLATE_REF",
|
|
572
|
+
"INSERT_NODE": 9,
|
|
573
|
+
"9": "INSERT_NODE",
|
|
574
|
+
"PREPEND_NODE": 10,
|
|
575
|
+
"10": "PREPEND_NODE",
|
|
576
|
+
"CREATE_COMPONENT_NODE": 11,
|
|
577
|
+
"11": "CREATE_COMPONENT_NODE",
|
|
578
|
+
"SLOT_OUTLET_NODE": 12,
|
|
579
|
+
"12": "SLOT_OUTLET_NODE",
|
|
580
|
+
"DIRECTIVE": 13,
|
|
581
|
+
"13": "DIRECTIVE",
|
|
582
|
+
"IF": 14,
|
|
583
|
+
"14": "IF",
|
|
584
|
+
"FOR": 15,
|
|
585
|
+
"15": "FOR",
|
|
586
|
+
"GET_TEXT_CHILD": 16,
|
|
587
|
+
"16": "GET_TEXT_CHILD",
|
|
588
|
+
"GET_INSERTION_PARENT": 17,
|
|
589
|
+
"17": "GET_INSERTION_PARENT",
|
|
590
|
+
"SET_CHANGE_PROP": 18,
|
|
591
|
+
"18": "SET_CHANGE_PROP"
|
|
592
|
+
};
|
|
593
|
+
const DynamicFlag = {
|
|
594
|
+
"NONE": 0,
|
|
595
|
+
"0": "NONE",
|
|
596
|
+
"REFERENCED": 1,
|
|
597
|
+
"1": "REFERENCED",
|
|
598
|
+
"NON_TEMPLATE": 2,
|
|
599
|
+
"2": "NON_TEMPLATE",
|
|
600
|
+
"INSERT": 4,
|
|
601
|
+
"4": "INSERT"
|
|
602
|
+
};
|
|
603
|
+
function isBlockOperation(op) {
|
|
604
|
+
const type = op.type;
|
|
605
|
+
return type === 11 || type === 12 || type === 14 || type === 15;
|
|
606
|
+
}
|
|
607
|
+
|
|
740
608
|
//#endregion
|
|
741
609
|
//#region packages/compiler-vapor/src/generators/dom.ts
|
|
742
610
|
function genInsertNode({ parent, elements, anchor }, { helper }) {
|
|
@@ -747,13 +615,11 @@ function genInsertNode({ parent, elements, anchor }, { helper }) {
|
|
|
747
615
|
function genPrependNode(oper, { helper }) {
|
|
748
616
|
return [NEWLINE, ...genCall(helper("prepend"), `n${oper.parent}`, ...oper.elements.map((el) => `n${el}`))];
|
|
749
617
|
}
|
|
618
|
+
|
|
750
619
|
//#endregion
|
|
751
620
|
//#region packages/compiler-vapor/src/generators/expression.ts
|
|
752
621
|
function genExpression(node, context, assignment) {
|
|
753
|
-
node = context.getExpressionReplacement(node);
|
|
754
622
|
const { content, ast, isStatic, loc } = node;
|
|
755
|
-
const { options } = context;
|
|
756
|
-
const { inline } = options;
|
|
757
623
|
if (isStatic) return [[
|
|
758
624
|
JSON.stringify(content),
|
|
759
625
|
-2,
|
|
@@ -775,31 +641,23 @@ function genExpression(node, context, assignment) {
|
|
|
775
641
|
let hasMemberExpression = false;
|
|
776
642
|
if (ids.length) {
|
|
777
643
|
const [frag, push] = buildCodeFragment();
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
const
|
|
781
|
-
const
|
|
782
|
-
const
|
|
644
|
+
ids.sort((a, b) => a.start - b.start).forEach((id, i) => {
|
|
645
|
+
const start = id.start - 1;
|
|
646
|
+
const end = id.end - 1;
|
|
647
|
+
const last = ids[i - 1];
|
|
648
|
+
const leadingText = content.slice(last ? last.end - 1 : 0, start);
|
|
649
|
+
if (leadingText.length) push([leadingText, -3]);
|
|
650
|
+
const source = content.slice(start, end);
|
|
783
651
|
const parentStack = parentStackMap.get(id);
|
|
784
652
|
const parent = parentStack[parentStack.length - 1];
|
|
785
|
-
let start = idStart;
|
|
786
|
-
let end = idEnd;
|
|
787
|
-
if (inline && options.bindingMetadata && options.bindingMetadata[source] === "setup-let" && parent && parent.type === "UpdateExpression" && parent.argument === id) {
|
|
788
|
-
start = parent.start - 1;
|
|
789
|
-
end = parent.end - 1;
|
|
790
|
-
}
|
|
791
|
-
if (start < lastEnd) return;
|
|
792
|
-
const leadingText = content.slice(lastEnd, start);
|
|
793
|
-
if (leadingText.length) push([leadingText, -3]);
|
|
794
653
|
hasMemberExpression || (hasMemberExpression = parent && (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression"));
|
|
795
654
|
push(...genIdentifier(source, context, {
|
|
796
655
|
start: (0, _vue_compiler_dom.advancePositionWithClone)(node.loc.start, source, start),
|
|
797
656
|
end: (0, _vue_compiler_dom.advancePositionWithClone)(node.loc.start, source, end),
|
|
798
657
|
source
|
|
799
|
-
}, hasMemberExpression ? void 0 : assignment, id, parent, parentStack
|
|
800
|
-
|
|
658
|
+
}, hasMemberExpression ? void 0 : assignment, id, parent, parentStack));
|
|
659
|
+
if (i === ids.length - 1 && end < content.length) push([content.slice(end), -3]);
|
|
801
660
|
});
|
|
802
|
-
if (lastEnd < content.length) push([content.slice(lastEnd), -3]);
|
|
803
661
|
if (assignment && hasMemberExpression) push(` = ${assignment}`);
|
|
804
662
|
return frag;
|
|
805
663
|
} else return [[
|
|
@@ -808,7 +666,7 @@ function genExpression(node, context, assignment) {
|
|
|
808
666
|
loc
|
|
809
667
|
]];
|
|
810
668
|
}
|
|
811
|
-
function genIdentifier(raw, context, loc, assignment, id, parent, parentStack
|
|
669
|
+
function genIdentifier(raw, context, loc, assignment, id, parent, parentStack) {
|
|
812
670
|
const { options, helper, identifiers } = context;
|
|
813
671
|
const { inline, bindingMetadata } = options;
|
|
814
672
|
let name = raw;
|
|
@@ -828,49 +686,19 @@ function genIdentifier(raw, context, loc, assignment, id, parent, parentStack, s
|
|
|
828
686
|
else return genExpression(replacement, context, assignment);
|
|
829
687
|
}
|
|
830
688
|
let prefix;
|
|
689
|
+
if ((0, _vue_compiler_dom.isStaticProperty)(parent) && parent.shorthand) prefix = `${raw}: `;
|
|
831
690
|
const type = bindingMetadata && bindingMetadata[raw];
|
|
832
|
-
const isDestructureAssignment = parent && (0, _vue_compiler_dom.isInDestructureAssignment)(parent, parentStack || []);
|
|
833
|
-
const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
|
|
834
|
-
const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
|
|
835
|
-
if ((0, _vue_compiler_dom.isStaticProperty)(parent) && parent.shorthand && !(inline && type === "setup-let" && isDestructureAssignment)) prefix = `${raw}: `;
|
|
836
691
|
if (inline) switch (type) {
|
|
837
692
|
case "setup-let":
|
|
838
|
-
|
|
839
|
-
const { right, operator } = parent;
|
|
840
|
-
const source = sourceNode;
|
|
841
|
-
const sourceContent = source.content;
|
|
842
|
-
const rightStart = right.start - 1;
|
|
843
|
-
const rightEnd = right.end - 1;
|
|
844
|
-
const rightContent = sourceContent.slice(rightStart, rightEnd);
|
|
845
|
-
const rightExp = (0, _vue_compiler_dom.createSimpleExpression)(rightContent, false, {
|
|
846
|
-
start: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, sourceContent, rightStart),
|
|
847
|
-
end: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, sourceContent, rightEnd),
|
|
848
|
-
source: rightContent
|
|
849
|
-
});
|
|
850
|
-
rightExp.ast = parseExp(context, rightContent);
|
|
851
|
-
return [
|
|
852
|
-
prefix,
|
|
853
|
-
`${helper("isRef")}(${raw}) ? ${raw}.value ${operator} `,
|
|
854
|
-
...genExpression(rightExp, context),
|
|
855
|
-
` : `,
|
|
856
|
-
[
|
|
857
|
-
raw,
|
|
858
|
-
-2,
|
|
859
|
-
loc,
|
|
860
|
-
name
|
|
861
|
-
]
|
|
862
|
-
];
|
|
863
|
-
} else if (isUpdateArg) {
|
|
864
|
-
const { prefix: isPrefix, operator } = parent;
|
|
865
|
-
const updatePrefix = isPrefix ? operator : ``;
|
|
866
|
-
const updatePostfix = isPrefix ? `` : operator;
|
|
867
|
-
raw = `${helper("isRef")}(${raw}) ? ${updatePrefix}${raw}.value${updatePostfix} : ${updatePrefix}${raw}${updatePostfix}`;
|
|
868
|
-
} else if (!isDestructureAssignment) name = raw = assignment ? `${helper("isRef")}(${raw}) ? (${raw}.value = ${assignment}) : (${raw} = ${assignment})` : unref();
|
|
693
|
+
name = raw = assignment ? `_isRef(${raw}) ? (${raw}.value = ${assignment}) : (${raw} = ${assignment})` : unref();
|
|
869
694
|
break;
|
|
870
695
|
case "setup-ref":
|
|
871
696
|
name = raw = withAssignment(`${raw}.value`);
|
|
872
697
|
break;
|
|
873
698
|
case "setup-maybe-ref":
|
|
699
|
+
const isDestructureAssignment = parent && (0, _vue_compiler_dom.isInDestructureAssignment)(parent, parentStack || []);
|
|
700
|
+
const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
|
|
701
|
+
const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
|
|
874
702
|
raw = isAssignmentLVal || isUpdateArg || isDestructureAssignment ? name = `${raw}.value` : assignment ? `${helper("isRef")}(${raw}) ? (${raw}.value = ${assignment}) : null` : unref();
|
|
875
703
|
break;
|
|
876
704
|
case "props":
|
|
@@ -905,35 +733,27 @@ function canPrefix(name) {
|
|
|
905
733
|
return true;
|
|
906
734
|
}
|
|
907
735
|
function processExpressions(context, expressions, shouldDeclare) {
|
|
908
|
-
const
|
|
909
|
-
const
|
|
910
|
-
const
|
|
911
|
-
|
|
912
|
-
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expressionRecords, reservedNames, expressionReplacements);
|
|
913
|
-
return {
|
|
914
|
-
...genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare),
|
|
915
|
-
expressionReplacements
|
|
916
|
-
};
|
|
736
|
+
const { seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
|
|
737
|
+
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable);
|
|
738
|
+
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap);
|
|
739
|
+
return genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare);
|
|
917
740
|
}
|
|
918
741
|
function analyzeExpressions(expressions) {
|
|
919
742
|
const seenVariable = Object.create(null);
|
|
920
743
|
const variableToExpMap = /* @__PURE__ */ new Map();
|
|
921
|
-
const
|
|
744
|
+
const expToVariableMap = /* @__PURE__ */ new Map();
|
|
922
745
|
const seenIdentifier = /* @__PURE__ */ new Set();
|
|
923
746
|
const updatedVariable = /* @__PURE__ */ new Set();
|
|
924
|
-
const getRecord = (exp) => {
|
|
925
|
-
let record = expressionRecords.get(exp);
|
|
926
|
-
if (!record) expressionRecords.set(exp, record = { variables: [] });
|
|
927
|
-
return record;
|
|
928
|
-
};
|
|
929
747
|
const registerVariable = (name, exp, isIdentifier, loc, parentStack = []) => {
|
|
930
748
|
if (isIdentifier) seenIdentifier.add(name);
|
|
931
749
|
seenVariable[name] = (seenVariable[name] || 0) + 1;
|
|
932
750
|
variableToExpMap.set(name, (variableToExpMap.get(name) || /* @__PURE__ */ new Set()).add(exp));
|
|
933
|
-
|
|
751
|
+
const variables = expToVariableMap.get(exp) || [];
|
|
752
|
+
variables.push({
|
|
934
753
|
name,
|
|
935
754
|
loc
|
|
936
755
|
});
|
|
756
|
+
expToVariableMap.set(exp, variables);
|
|
937
757
|
if (parentStack.some((p) => p.type === "UpdateExpression" || p.type === "AssignmentExpression")) updatedVariable.add(name);
|
|
938
758
|
};
|
|
939
759
|
for (const exp of expressions) {
|
|
@@ -945,17 +765,14 @@ function analyzeExpressions(expressions) {
|
|
|
945
765
|
(0, _vue_compiler_dom.walkIdentifiers)(exp.ast, (currentNode, parent, parentStack) => {
|
|
946
766
|
if (parent && isMemberExpression$3(parent) && !seenParents.has(parent)) {
|
|
947
767
|
seenParents.add(parent);
|
|
948
|
-
let hasGlobalIdentifier = false;
|
|
949
768
|
const memberExp = extractMemberExpression(parent, (id) => {
|
|
950
769
|
registerVariable(id.name, exp, true, {
|
|
951
770
|
start: id.start,
|
|
952
771
|
end: id.end
|
|
953
772
|
});
|
|
954
|
-
if ((0, _vue_shared.isGloballyAllowed)(id.name)) hasGlobalIdentifier = true;
|
|
955
773
|
});
|
|
956
774
|
const parentOfMemberExp = parentStack[parentStack.length - 2];
|
|
957
775
|
if (parentOfMemberExp && isCallExpression(parentOfMemberExp)) return;
|
|
958
|
-
if (hasGlobalIdentifier) return;
|
|
959
776
|
registerVariable(memberExp, exp, false, {
|
|
960
777
|
start: parent.start,
|
|
961
778
|
end: parent.end
|
|
@@ -970,222 +787,109 @@ function analyzeExpressions(expressions) {
|
|
|
970
787
|
seenVariable,
|
|
971
788
|
seenIdentifier,
|
|
972
789
|
variableToExpMap,
|
|
973
|
-
|
|
790
|
+
expToVariableMap,
|
|
974
791
|
updatedVariable
|
|
975
792
|
};
|
|
976
793
|
}
|
|
977
|
-
function
|
|
978
|
-
return expressionReplacements.get(exp) || exp;
|
|
979
|
-
}
|
|
980
|
-
function setExpressionReplacement(expressionReplacements, exp, content, ast) {
|
|
981
|
-
expressionReplacements.set(exp, (0, _vue_shared.extend)({ ast }, (0, _vue_compiler_dom.createSimpleExpression)(content, exp.isStatic, exp.loc, exp.constType)));
|
|
982
|
-
}
|
|
983
|
-
function processRepeatedVariables(context, seenVariable, variableToExpMap, expressionRecords, seenIdentifier, updatedVariable, reservedNames, expressionReplacements) {
|
|
794
|
+
function processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable) {
|
|
984
795
|
const declarations = [];
|
|
985
|
-
const
|
|
986
|
-
const replacementPlan = /* @__PURE__ */ new Map();
|
|
796
|
+
const expToReplacementMap = /* @__PURE__ */ new Map();
|
|
987
797
|
for (const [name, exps] of variableToExpMap) {
|
|
988
798
|
if (updatedVariable.has(name)) continue;
|
|
989
|
-
if ((0, _vue_shared.isGloballyAllowed)(name)) continue;
|
|
990
799
|
if (seenVariable[name] > 1 && exps.size > 0) {
|
|
991
800
|
const isIdentifier = seenIdentifier.has(name);
|
|
992
|
-
const varName = isIdentifier ? name :
|
|
801
|
+
const varName = isIdentifier ? name : genVarName(name);
|
|
993
802
|
exps.forEach((node) => {
|
|
994
803
|
if (node.ast && varName !== name) {
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
804
|
+
const replacements = expToReplacementMap.get(node) || [];
|
|
805
|
+
replacements.push({
|
|
806
|
+
name: varName,
|
|
807
|
+
locs: expToVariableMap.get(node).reduce((locs, v) => {
|
|
808
|
+
if (v.name === name && v.loc) locs.push(v.loc);
|
|
809
|
+
return locs;
|
|
810
|
+
}, [])
|
|
999
811
|
});
|
|
812
|
+
expToReplacementMap.set(node, replacements);
|
|
1000
813
|
}
|
|
1001
814
|
});
|
|
1002
|
-
if (!
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
seenCount: seenVariable[name]
|
|
1011
|
-
});
|
|
1012
|
-
}
|
|
815
|
+
if (!declarations.some((d) => d.name === varName) && (!isIdentifier || shouldDeclareVariable(name, expToVariableMap, exps))) declarations.push({
|
|
816
|
+
name: varName,
|
|
817
|
+
isIdentifier,
|
|
818
|
+
value: (0, _vue_shared.extend)({ ast: isIdentifier ? null : parseExp(context, name) }, (0, _vue_compiler_dom.createSimpleExpression)(name)),
|
|
819
|
+
rawName: name,
|
|
820
|
+
exps,
|
|
821
|
+
seenCount: seenVariable[name]
|
|
822
|
+
});
|
|
1013
823
|
}
|
|
1014
824
|
}
|
|
1015
|
-
|
|
825
|
+
for (const [exp, replacements] of expToReplacementMap) {
|
|
826
|
+
replacements.flatMap(({ name, locs }) => locs.map(({ start, end }) => ({
|
|
827
|
+
start,
|
|
828
|
+
end,
|
|
829
|
+
name
|
|
830
|
+
}))).sort((a, b) => b.end - a.end).forEach(({ start, end, name }) => {
|
|
831
|
+
exp.content = exp.content.slice(0, start - 1) + name + exp.content.slice(end - 1);
|
|
832
|
+
});
|
|
833
|
+
exp.ast = parseExp(context, exp.content, exp.loc);
|
|
834
|
+
}
|
|
1016
835
|
return declarations;
|
|
1017
836
|
}
|
|
1018
|
-
function shouldDeclareVariable(name,
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
if (allSingleVariable && variables.length !== 1) allSingleVariable = false;
|
|
1026
|
-
if (!hasDifferentLength && variableUsages.length > 0 && variables.length !== variableUsages[0].length) hasDifferentLength = true;
|
|
1027
|
-
let nameCount = 0;
|
|
1028
|
-
for (const variable of variables) if (variable.name === name && ++nameCount > 1) {
|
|
1029
|
-
hasRepeatedName = true;
|
|
1030
|
-
break outer;
|
|
1031
|
-
}
|
|
1032
|
-
variableUsages.push(variables);
|
|
1033
|
-
}
|
|
1034
|
-
if (allSingleVariable) return true;
|
|
1035
|
-
if (hasRepeatedName) return true;
|
|
1036
|
-
const first = variableUsages[0];
|
|
1037
|
-
if (hasDifferentLength) {
|
|
1038
|
-
for (const variables of variableUsages) {
|
|
1039
|
-
if (variables.length === first.length) continue;
|
|
1040
|
-
const longer = variables.length > first.length ? variables : first;
|
|
1041
|
-
const shorter = variables.length > first.length ? first : variables;
|
|
1042
|
-
const shorterNames = /* @__PURE__ */ new Set();
|
|
1043
|
-
for (const variable of shorter) shorterNames.add(variable.name);
|
|
1044
|
-
let isSubset = true;
|
|
1045
|
-
for (const variable of longer) if (!shorterNames.has(variable.name)) {
|
|
1046
|
-
isSubset = false;
|
|
1047
|
-
break;
|
|
1048
|
-
}
|
|
1049
|
-
if (isSubset) return false;
|
|
1050
|
-
}
|
|
837
|
+
function shouldDeclareVariable(name, expToVariableMap, exps) {
|
|
838
|
+
const vars = Array.from(exps, (exp) => expToVariableMap.get(exp).map((v) => v.name));
|
|
839
|
+
if (vars.every((v) => v.length === 1)) return true;
|
|
840
|
+
if (vars.some((v) => v.filter((e) => e === name).length > 1)) return true;
|
|
841
|
+
const first = vars[0];
|
|
842
|
+
if (vars.some((v) => v.length !== first.length)) {
|
|
843
|
+
if (vars.some((v) => v.length > first.length && v.every((e) => first.includes(e))) || vars.some((v) => first.length > v.length && first.every((e) => v.includes(e)))) return false;
|
|
1051
844
|
return true;
|
|
1052
845
|
}
|
|
1053
|
-
|
|
1054
|
-
return
|
|
846
|
+
if (vars.every((v) => v.every((e, idx) => e === first[idx]))) return false;
|
|
847
|
+
return true;
|
|
1055
848
|
}
|
|
1056
|
-
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable,
|
|
849
|
+
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap) {
|
|
1057
850
|
const declarations = [];
|
|
1058
|
-
const seenExp =
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
const
|
|
1062
|
-
if (!
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
851
|
+
const seenExp = expressions.reduce((acc, exp) => {
|
|
852
|
+
const vars = expToVariableMap.get(exp);
|
|
853
|
+
if (!vars) return acc;
|
|
854
|
+
const variables = vars.map((v) => v.name);
|
|
855
|
+
if (exp.ast && exp.ast.type !== "Identifier" && !(variables && variables.some((v) => updatedVariable.has(v)))) acc[exp.content] = (acc[exp.content] || 0) + 1;
|
|
856
|
+
return acc;
|
|
857
|
+
}, Object.create(null));
|
|
858
|
+
Object.entries(seenExp).forEach(([content, count]) => {
|
|
859
|
+
if (count > 1) {
|
|
860
|
+
const varName = genVarName(content);
|
|
861
|
+
if (!declarations.some((d) => d.name === varName)) {
|
|
862
|
+
const delVars = {};
|
|
863
|
+
for (let i = varDeclarations.length - 1; i >= 0; i--) {
|
|
864
|
+
const item = varDeclarations[i];
|
|
865
|
+
if (!item.exps || !item.seenCount) continue;
|
|
866
|
+
if ([...item.exps].every((node) => node.content === content && item.seenCount === count)) {
|
|
867
|
+
delVars[item.name] = item.rawName;
|
|
868
|
+
varDeclarations.splice(i, 1);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
const value = (0, _vue_shared.extend)({}, expressions.find((exp) => exp.content === content));
|
|
872
|
+
Object.keys(delVars).forEach((name) => {
|
|
873
|
+
value.content = value.content.replace(name, delVars[name]);
|
|
874
|
+
if (value.ast) value.ast = parseExp(context, value.content, value.loc);
|
|
875
|
+
});
|
|
876
|
+
declarations.push({
|
|
877
|
+
name: varName,
|
|
878
|
+
value
|
|
1083
879
|
});
|
|
1084
|
-
reservedNames.delete(item.name);
|
|
1085
|
-
varDeclarations.splice(i, 1);
|
|
1086
880
|
}
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
}
|
|
1095
|
-
const varName = getUniqueDeclarationName(genVarName(content), reservedNames);
|
|
1096
|
-
declarations.push({
|
|
1097
|
-
name: varName,
|
|
1098
|
-
value
|
|
1099
|
-
});
|
|
1100
|
-
for (const exp of expressions) {
|
|
1101
|
-
const processed = getProcessedExpression(exp, expressionReplacements);
|
|
1102
|
-
if (processed.content === content) setExpressionReplacement(expressionReplacements, exp, varName, null);
|
|
1103
|
-
else if (processed.content.includes(content)) {
|
|
1104
|
-
const replacements = findContentReplacements(processed, content, varName);
|
|
1105
|
-
if (replacements.length) {
|
|
1106
|
-
const replacedContent = applyContentReplacements(processed.content, replacements);
|
|
1107
|
-
setExpressionReplacement(expressionReplacements, exp, replacedContent, parseExp(context, replacedContent));
|
|
881
|
+
expressions.forEach((exp) => {
|
|
882
|
+
if (exp.content === content) {
|
|
883
|
+
exp.content = varName;
|
|
884
|
+
exp.ast = null;
|
|
885
|
+
} else if (exp.content.includes(content)) {
|
|
886
|
+
exp.content = exp.content.replace(new RegExp(escapeRegExp(content), "g"), varName);
|
|
887
|
+
exp.ast = parseExp(context, exp.content, exp.loc);
|
|
1108
888
|
}
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
return declarations;
|
|
1113
|
-
}
|
|
1114
|
-
function canCacheExpression(processed, vars, updatedVariable) {
|
|
1115
|
-
if (!processed.ast || processed.ast.type === "Identifier") return false;
|
|
1116
|
-
for (const { name } of vars) if (updatedVariable.has(name) || (0, _vue_shared.isGloballyAllowed)(name)) return false;
|
|
1117
|
-
return true;
|
|
1118
|
-
}
|
|
1119
|
-
function getExpressionVariables(expressionRecords, exp) {
|
|
1120
|
-
var _expressionRecords$ge2;
|
|
1121
|
-
return ((_expressionRecords$ge2 = expressionRecords.get(exp)) === null || _expressionRecords$ge2 === void 0 ? void 0 : _expressionRecords$ge2.variables) || [];
|
|
1122
|
-
}
|
|
1123
|
-
function queueContentReplacement(replacementPlan, exp, replacement) {
|
|
1124
|
-
const replacements = replacementPlan.get(exp);
|
|
1125
|
-
if (replacements) replacements.push(replacement);
|
|
1126
|
-
else replacementPlan.set(exp, [replacement]);
|
|
1127
|
-
}
|
|
1128
|
-
function applyReplacementPlan(context, expressionReplacements, replacementPlan) {
|
|
1129
|
-
for (const [exp, replacements] of replacementPlan) {
|
|
1130
|
-
if (!replacements.length) continue;
|
|
1131
|
-
const content = applyContentReplacements(getProcessedExpression(exp, expressionReplacements).content, replacements);
|
|
1132
|
-
setExpressionReplacement(expressionReplacements, exp, content, parseExp(context, content));
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
function findContentReplacements(exp, content, replacement) {
|
|
1136
|
-
const identifiers = getIdentifierRanges(exp);
|
|
1137
|
-
if (!identifiers.length) return [];
|
|
1138
|
-
const replacements = [];
|
|
1139
|
-
let searchStart = 0;
|
|
1140
|
-
let start = exp.content.indexOf(content, searchStart);
|
|
1141
|
-
while (start !== -1) {
|
|
1142
|
-
const end = start + content.length;
|
|
1143
|
-
let canReplace = false;
|
|
1144
|
-
for (const identifier of identifiers) {
|
|
1145
|
-
if (start >= identifier.end || end <= identifier.start) continue;
|
|
1146
|
-
if (start > identifier.start || end < identifier.end) {
|
|
1147
|
-
canReplace = false;
|
|
1148
|
-
break;
|
|
1149
|
-
}
|
|
1150
|
-
canReplace = true;
|
|
1151
|
-
}
|
|
1152
|
-
if (canReplace) {
|
|
1153
|
-
replacements.push({
|
|
1154
|
-
start,
|
|
1155
|
-
end,
|
|
1156
|
-
content: replacement
|
|
1157
889
|
});
|
|
1158
|
-
|
|
1159
|
-
} else searchStart = start + 1;
|
|
1160
|
-
start = exp.content.indexOf(content, searchStart);
|
|
1161
|
-
}
|
|
1162
|
-
return replacements;
|
|
1163
|
-
}
|
|
1164
|
-
function findIdentifierReplacements(exp, name, replacement) {
|
|
1165
|
-
const replacements = [];
|
|
1166
|
-
for (const { start, end } of getIdentifierRanges(exp)) if (exp.content.slice(start, end) === name) replacements.push({
|
|
1167
|
-
start,
|
|
1168
|
-
end,
|
|
1169
|
-
content: replacement
|
|
1170
|
-
});
|
|
1171
|
-
return replacements;
|
|
1172
|
-
}
|
|
1173
|
-
function getIdentifierRanges(exp) {
|
|
1174
|
-
if (!exp.ast || typeof exp.ast !== "object") return [];
|
|
1175
|
-
const identifiers = [];
|
|
1176
|
-
(0, _vue_compiler_dom.walkIdentifiers)(exp.ast, (id) => {
|
|
1177
|
-
identifiers.push({
|
|
1178
|
-
start: id.start - 1,
|
|
1179
|
-
end: id.end - 1
|
|
1180
|
-
});
|
|
1181
|
-
}, false);
|
|
1182
|
-
return identifiers;
|
|
1183
|
-
}
|
|
1184
|
-
function applyContentReplacements(content, replacements) {
|
|
1185
|
-
replacements.sort((a, b) => b.start - a.start).forEach(({ start, end, content: replacement }) => {
|
|
1186
|
-
content = content.slice(0, start) + replacement + content.slice(end);
|
|
890
|
+
}
|
|
1187
891
|
});
|
|
1188
|
-
return
|
|
892
|
+
return declarations;
|
|
1189
893
|
}
|
|
1190
894
|
function genDeclarations(declarations, context, shouldDeclare) {
|
|
1191
895
|
const [frag, push] = buildCodeFragment();
|
|
@@ -1201,11 +905,10 @@ function genDeclarations(declarations, context, shouldDeclare) {
|
|
|
1201
905
|
});
|
|
1202
906
|
declarations.forEach(({ name, isIdentifier, value }) => {
|
|
1203
907
|
if (!isIdentifier) {
|
|
1204
|
-
const varName = `_${name}`;
|
|
908
|
+
const varName = ids[name] = `_${name}`;
|
|
1205
909
|
varNames.add(varName);
|
|
1206
910
|
if (shouldDeclare) push(`const `);
|
|
1207
911
|
push(`${varName} = `, ...context.withId(() => genExpression(value, context), ids), NEWLINE);
|
|
1208
|
-
ids[name] = varName;
|
|
1209
912
|
}
|
|
1210
913
|
});
|
|
1211
914
|
return {
|
|
@@ -1214,9 +917,14 @@ function genDeclarations(declarations, context, shouldDeclare) {
|
|
|
1214
917
|
varNames: [...varNames]
|
|
1215
918
|
};
|
|
1216
919
|
}
|
|
920
|
+
function escapeRegExp(string) {
|
|
921
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
922
|
+
}
|
|
1217
923
|
function parseExp(context, content, loc) {
|
|
924
|
+
const plugins = context.options.expressionPlugins;
|
|
925
|
+
const options = { plugins: plugins ? [...plugins, "typescript"] : ["typescript"] };
|
|
1218
926
|
try {
|
|
1219
|
-
return (0, _babel_parser.parseExpression)(`(${content})`,
|
|
927
|
+
return (0, _babel_parser.parseExpression)(`(${content})`, options);
|
|
1220
928
|
} catch (e) {
|
|
1221
929
|
if (loc) {
|
|
1222
930
|
const error = new SyntaxError(e.message);
|
|
@@ -1230,14 +938,6 @@ function parseExp(context, content, loc) {
|
|
|
1230
938
|
function genVarName(exp) {
|
|
1231
939
|
return `${exp.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/_+$/, "")}`;
|
|
1232
940
|
}
|
|
1233
|
-
function getUniqueDeclarationName(baseName, reservedNames) {
|
|
1234
|
-
const normalizedBase = baseName || "exp";
|
|
1235
|
-
let name = normalizedBase;
|
|
1236
|
-
let i = 1;
|
|
1237
|
-
while (reservedNames.has(name)) name = `${normalizedBase}_${i++}`;
|
|
1238
|
-
reservedNames.add(name);
|
|
1239
|
-
return name;
|
|
1240
|
-
}
|
|
1241
941
|
function extractMemberExpression(exp, onIdentifier) {
|
|
1242
942
|
if (!exp) return "";
|
|
1243
943
|
switch (exp.type) {
|
|
@@ -1261,36 +961,28 @@ const isCallExpression = (node) => {
|
|
|
1261
961
|
const isMemberExpression$3 = (node) => {
|
|
1262
962
|
return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "TSNonNullExpression";
|
|
1263
963
|
};
|
|
964
|
+
|
|
1264
965
|
//#endregion
|
|
1265
966
|
//#region packages/compiler-vapor/src/generators/event.ts
|
|
1266
967
|
function genSetEvent(oper, context) {
|
|
1267
968
|
const { helper } = context;
|
|
1268
969
|
const { element, key, keyOverride, value, modifiers, delegate, effect } = oper;
|
|
1269
|
-
|
|
970
|
+
const name = genName();
|
|
971
|
+
const handler = [
|
|
972
|
+
`${context.helper("createInvoker")}(`,
|
|
973
|
+
...genEventHandler(context, [value], modifiers),
|
|
974
|
+
`)`
|
|
975
|
+
];
|
|
976
|
+
const eventOptions = genEventOptions();
|
|
1270
977
|
if (delegate) {
|
|
1271
978
|
context.delegates.add(key.content);
|
|
1272
979
|
if (!context.block.operation.some(isSameDelegateEvent)) return [
|
|
1273
980
|
NEWLINE,
|
|
1274
981
|
`n${element}.$evt${key.content} = `,
|
|
1275
|
-
...
|
|
1276
|
-
];
|
|
1277
|
-
}
|
|
1278
|
-
const name = genName();
|
|
1279
|
-
const eventOptions = genEventOptions();
|
|
1280
|
-
return [NEWLINE, ...genCall(helper(effect ? "onBinding" : delegate ? "delegate" : "on"), `n${element}`, name, genHandler(), eventOptions)];
|
|
1281
|
-
function genHandler() {
|
|
1282
|
-
return handler || (handler = genEventHandler(context, [value], modifiers));
|
|
1283
|
-
}
|
|
1284
|
-
function genInvoker() {
|
|
1285
|
-
return [
|
|
1286
|
-
`${helper("createInvoker")}(`,
|
|
1287
|
-
...genHandler(),
|
|
1288
|
-
`)`
|
|
982
|
+
...handler
|
|
1289
983
|
];
|
|
1290
984
|
}
|
|
1291
|
-
|
|
1292
|
-
return modifiers.keys.length || modifiers.nonKeys.length ? genEventHandler(context, [value], modifiers, { modifierHelper: "vapor" }) : genInvoker();
|
|
1293
|
-
}
|
|
985
|
+
return [NEWLINE, ...genCall(helper(delegate ? "delegate" : "on"), `n${element}`, name, handler, eventOptions)];
|
|
1294
986
|
function genName() {
|
|
1295
987
|
const expr = genExpression(key, context);
|
|
1296
988
|
if (keyOverride) {
|
|
@@ -1310,11 +1002,11 @@ function genSetEvent(oper, context) {
|
|
|
1310
1002
|
}
|
|
1311
1003
|
function genEventOptions() {
|
|
1312
1004
|
let { options } = modifiers;
|
|
1313
|
-
if (!options.length) return;
|
|
1314
|
-
return genMulti(DELIMITERS_OBJECT_NEWLINE, ...options.map((option) => [`${option}: true`]));
|
|
1005
|
+
if (!options.length && !effect) return;
|
|
1006
|
+
return genMulti(DELIMITERS_OBJECT_NEWLINE, effect && ["effect: true"], ...options.map((option) => [`${option}: true`]));
|
|
1315
1007
|
}
|
|
1316
1008
|
function isSameDelegateEvent(op) {
|
|
1317
|
-
if (op.type ===
|
|
1009
|
+
if (op.type === 5 && op !== oper && op.delegate && op.element === oper.element && op.key.content === key.content) return true;
|
|
1318
1010
|
}
|
|
1319
1011
|
}
|
|
1320
1012
|
function genSetDynamicEvents(oper, context) {
|
|
@@ -1324,9 +1016,7 @@ function genSetDynamicEvents(oper, context) {
|
|
|
1324
1016
|
function genEventHandler(context, values, modifiers = {
|
|
1325
1017
|
nonKeys: [],
|
|
1326
1018
|
keys: []
|
|
1327
|
-
},
|
|
1328
|
-
const { asComponentProp = false, extraWrap = false, modifierHelper = "runtime" } = options;
|
|
1329
|
-
const useVaporModifierHelper = modifierHelper === "vapor";
|
|
1019
|
+
}, asComponentProp = false, extraWrap = false) {
|
|
1330
1020
|
let handlerExp = [];
|
|
1331
1021
|
if (values) {
|
|
1332
1022
|
values.forEach((value, index) => {
|
|
@@ -1367,27 +1057,28 @@ function genEventHandler(context, values, modifiers = {
|
|
|
1367
1057
|
}
|
|
1368
1058
|
if (handlerExp.length === 0) handlerExp = ["() => {}"];
|
|
1369
1059
|
const { keys, nonKeys } = modifiers;
|
|
1370
|
-
if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys
|
|
1371
|
-
if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys
|
|
1060
|
+
if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys);
|
|
1061
|
+
if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys);
|
|
1372
1062
|
if (extraWrap) handlerExp.unshift(`() => `);
|
|
1373
1063
|
return handlerExp;
|
|
1374
1064
|
}
|
|
1375
|
-
function genWithModifiers(context, handler, nonKeys
|
|
1376
|
-
return genCall(context.helper(
|
|
1065
|
+
function genWithModifiers(context, handler, nonKeys) {
|
|
1066
|
+
return genCall(context.helper("withModifiers"), handler, JSON.stringify(nonKeys));
|
|
1377
1067
|
}
|
|
1378
|
-
function genWithKeys(context, handler, keys
|
|
1379
|
-
return genCall(context.helper(
|
|
1068
|
+
function genWithKeys(context, handler, keys) {
|
|
1069
|
+
return genCall(context.helper("withKeys"), handler, JSON.stringify(keys));
|
|
1380
1070
|
}
|
|
1381
1071
|
function isConstantBinding(value, context) {
|
|
1382
1072
|
if (value.ast === null) {
|
|
1383
1073
|
if (context.options.bindingMetadata[value.content] === "setup-const") return true;
|
|
1384
1074
|
}
|
|
1385
1075
|
}
|
|
1076
|
+
|
|
1386
1077
|
//#endregion
|
|
1387
1078
|
//#region packages/compiler-vapor/src/generators/for.ts
|
|
1388
1079
|
function genFor(oper, context) {
|
|
1389
1080
|
const { helper } = context;
|
|
1390
|
-
const { source, value, key, index, render, keyProp, once, id, component, onlyChild
|
|
1081
|
+
const { source, value, key, index, render, keyProp, once, id, component, onlyChild } = oper;
|
|
1391
1082
|
const rawValue = value && value.content;
|
|
1392
1083
|
const rawKey = key && key.content;
|
|
1393
1084
|
const rawIndex = index && index.content;
|
|
@@ -1414,12 +1105,16 @@ function genFor(oper, context) {
|
|
|
1414
1105
|
idMap[rawIndex] = `${indexVar}.value`;
|
|
1415
1106
|
idMap[indexVar] = null;
|
|
1416
1107
|
}
|
|
1417
|
-
const { selectorPatterns, keyOnlyBindingPatterns
|
|
1108
|
+
const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap);
|
|
1418
1109
|
const selectorDeclarations = [];
|
|
1419
|
-
const
|
|
1110
|
+
const selectorSetup = [];
|
|
1420
1111
|
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
1421
1112
|
const { selector } = selectorPatterns[i];
|
|
1422
|
-
|
|
1113
|
+
const selectorName = `_selector${id}_${i}`;
|
|
1114
|
+
selectorDeclarations.push(`let ${selectorName}`, NEWLINE);
|
|
1115
|
+
if (i === 0) selectorSetup.push(`({ createSelector }) => {`, INDENT_START);
|
|
1116
|
+
selectorSetup.push(NEWLINE, `${selectorName} = `, ...genCall(`createSelector`, [`() => `, ...genExpression(selector, context)]));
|
|
1117
|
+
if (i === selectorPatterns.length - 1) selectorSetup.push(INDENT_END, NEWLINE, "}");
|
|
1423
1118
|
}
|
|
1424
1119
|
const blockFn = context.withId(() => {
|
|
1425
1120
|
const frag = [];
|
|
@@ -1428,27 +1123,27 @@ function genFor(oper, context) {
|
|
|
1428
1123
|
const patternFrag = [];
|
|
1429
1124
|
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
1430
1125
|
const { effect } = selectorPatterns[i];
|
|
1431
|
-
patternFrag.push(NEWLINE,
|
|
1126
|
+
patternFrag.push(NEWLINE, `_selector${id}_${i}(() => {`, INDENT_START);
|
|
1432
1127
|
for (const oper of effect.operations) patternFrag.push(...genOperation(oper, context));
|
|
1433
1128
|
patternFrag.push(INDENT_END, NEWLINE, `})`);
|
|
1434
1129
|
}
|
|
1435
1130
|
for (const { effect } of keyOnlyBindingPatterns) for (const oper of effect.operations) patternFrag.push(...genOperation(oper, context));
|
|
1436
1131
|
return patternFrag;
|
|
1437
|
-
}
|
|
1132
|
+
}));
|
|
1438
1133
|
else frag.push(...genBlockContent(render, context));
|
|
1439
1134
|
frag.push(INDENT_END, NEWLINE, "}");
|
|
1440
1135
|
return frag;
|
|
1441
1136
|
}, idMap);
|
|
1442
1137
|
exitScope();
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1138
|
+
let flags = 0;
|
|
1139
|
+
if (onlyChild) flags |= 1;
|
|
1140
|
+
if (component) flags |= 2;
|
|
1141
|
+
if (once) flags |= 4;
|
|
1446
1142
|
return [
|
|
1447
1143
|
NEWLINE,
|
|
1448
1144
|
...selectorDeclarations,
|
|
1449
1145
|
`const n${id} = `,
|
|
1450
|
-
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags),
|
|
1451
|
-
...onResetCalls
|
|
1146
|
+
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags ? String(flags) : void 0, selectorSetup.length ? selectorSetup : void 0)
|
|
1452
1147
|
];
|
|
1453
1148
|
function genCallback(expr) {
|
|
1454
1149
|
if (!expr) return false;
|
|
@@ -1472,51 +1167,6 @@ function genFor(oper, context) {
|
|
|
1472
1167
|
return idMap;
|
|
1473
1168
|
}
|
|
1474
1169
|
}
|
|
1475
|
-
function genForFlags(onlyChild, component, isFragment, isSingleNode, once, slotRoot) {
|
|
1476
|
-
let flags = 0;
|
|
1477
|
-
const names = [];
|
|
1478
|
-
if (onlyChild) {
|
|
1479
|
-
flags |= 1;
|
|
1480
|
-
names.push("FAST_REMOVE");
|
|
1481
|
-
}
|
|
1482
|
-
if (component) {
|
|
1483
|
-
flags |= 2;
|
|
1484
|
-
names.push("IS_COMPONENT");
|
|
1485
|
-
}
|
|
1486
|
-
if (isFragment) {
|
|
1487
|
-
flags |= 16;
|
|
1488
|
-
names.push("IS_FRAGMENT");
|
|
1489
|
-
}
|
|
1490
|
-
if (isSingleNode) {
|
|
1491
|
-
flags |= 8;
|
|
1492
|
-
names.push("IS_SINGLE_NODE");
|
|
1493
|
-
}
|
|
1494
|
-
if (once) {
|
|
1495
|
-
flags |= 4;
|
|
1496
|
-
names.push("ONCE");
|
|
1497
|
-
}
|
|
1498
|
-
if (slotRoot) {
|
|
1499
|
-
flags |= 32;
|
|
1500
|
-
names.push("SLOT_ROOT");
|
|
1501
|
-
}
|
|
1502
|
-
if (!flags) return;
|
|
1503
|
-
return `${flags} /* ${names.join(", ")} */`;
|
|
1504
|
-
}
|
|
1505
|
-
function isSingleNodeBlock(block) {
|
|
1506
|
-
const child = getSingleReturnedChild(block);
|
|
1507
|
-
return !!child && child.template != null;
|
|
1508
|
-
}
|
|
1509
|
-
function isFragmentBlock(block) {
|
|
1510
|
-
const child = getSingleReturnedChild(block);
|
|
1511
|
-
const operation = child && child.operation;
|
|
1512
|
-
if (!operation) return false;
|
|
1513
|
-
return operation.type === 13 || operation.type === 16 || operation.type === 17 || operation.type === 15 && !operation.once || operation.type === 12 && !!operation.dynamic && !operation.dynamic.isStatic;
|
|
1514
|
-
}
|
|
1515
|
-
function getSingleReturnedChild(block) {
|
|
1516
|
-
if (block.returns.length !== 1) return;
|
|
1517
|
-
const id = block.returns[0];
|
|
1518
|
-
for (const child of block.dynamic.children) if (child.id === id) return child;
|
|
1519
|
-
}
|
|
1520
1170
|
function parseValueDestructure(value, context) {
|
|
1521
1171
|
const map = /* @__PURE__ */ new Map();
|
|
1522
1172
|
if (value) {
|
|
@@ -1554,8 +1204,7 @@ function parseValueDestructure(value, context) {
|
|
|
1554
1204
|
if (child.type === "AssignmentPattern" && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
|
|
1555
1205
|
isDynamic = true;
|
|
1556
1206
|
helper = isDom2 ? context.helper("getSharedDataDefaultValue") : context.helper("getDefaultValue");
|
|
1557
|
-
|
|
1558
|
-
helperArgs = isDom2 ? rawDefault : `() => (${rawDefault})`;
|
|
1207
|
+
helperArgs = rawValue.slice(child.right.start - 1, child.right.end - 1);
|
|
1559
1208
|
}
|
|
1560
1209
|
}
|
|
1561
1210
|
map.set(id.name, {
|
|
@@ -1582,44 +1231,34 @@ function buildDestructureIdMap(idToPathMap, baseAccessor, plugins) {
|
|
|
1582
1231
|
}
|
|
1583
1232
|
if (pathInfo.dynamic) {
|
|
1584
1233
|
const node = idMap[id] = (0, _vue_compiler_dom.createSimpleExpression)(path);
|
|
1585
|
-
node.ast = (0, _babel_parser.parseExpression)(`(${path})`,
|
|
1234
|
+
node.ast = (0, _babel_parser.parseExpression)(`(${path})`, { plugins: plugins ? [...plugins, "typescript"] : ["typescript"] });
|
|
1586
1235
|
} else idMap[id] = path;
|
|
1587
1236
|
} else idMap[id] = path;
|
|
1588
1237
|
});
|
|
1589
1238
|
return idMap;
|
|
1590
1239
|
}
|
|
1591
|
-
function matchPatterns(render, keyProp, idMap
|
|
1240
|
+
function matchPatterns(render, keyProp, idMap) {
|
|
1592
1241
|
const selectorPatterns = [];
|
|
1593
1242
|
const keyOnlyBindingPatterns = [];
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
continue;
|
|
1607
|
-
}
|
|
1608
|
-
const keyOnly = matchKeyOnlyBindingPattern(effect, keyProp.content);
|
|
1609
|
-
if (keyOnly) {
|
|
1610
|
-
keyOnlyBindingPatterns.push(keyOnly);
|
|
1611
|
-
skipEffect(index);
|
|
1243
|
+
render.effect = render.effect.filter((effect) => {
|
|
1244
|
+
if (keyProp !== void 0) {
|
|
1245
|
+
const selector = matchSelectorPattern(effect, keyProp.content, idMap);
|
|
1246
|
+
if (selector) {
|
|
1247
|
+
selectorPatterns.push(selector);
|
|
1248
|
+
return false;
|
|
1249
|
+
}
|
|
1250
|
+
const keyOnly = matchKeyOnlyBindingPattern(effect, keyProp.content);
|
|
1251
|
+
if (keyOnly) {
|
|
1252
|
+
keyOnlyBindingPatterns.push(keyOnly);
|
|
1253
|
+
return false;
|
|
1254
|
+
}
|
|
1612
1255
|
}
|
|
1613
|
-
|
|
1256
|
+
return true;
|
|
1257
|
+
});
|
|
1614
1258
|
return {
|
|
1615
1259
|
keyOnlyBindingPatterns,
|
|
1616
|
-
selectorPatterns
|
|
1617
|
-
skippedEffectIndexes
|
|
1260
|
+
selectorPatterns
|
|
1618
1261
|
};
|
|
1619
|
-
function skipEffect(index) {
|
|
1620
|
-
if (!skippedEffectIndexes) skippedEffectIndexes = /* @__PURE__ */ new Set();
|
|
1621
|
-
skippedEffectIndexes.add(index);
|
|
1622
|
-
}
|
|
1623
1262
|
}
|
|
1624
1263
|
function matchKeyOnlyBindingPattern(effect, key) {
|
|
1625
1264
|
if (effect.expressions.length === 1) {
|
|
@@ -1629,7 +1268,7 @@ function matchKeyOnlyBindingPattern(effect, key) {
|
|
|
1629
1268
|
}
|
|
1630
1269
|
}
|
|
1631
1270
|
}
|
|
1632
|
-
function matchSelectorPattern(effect, key, idMap
|
|
1271
|
+
function matchSelectorPattern(effect, key, idMap) {
|
|
1633
1272
|
if (effect.expressions.length === 1) {
|
|
1634
1273
|
const { ast, content } = effect.expressions[0];
|
|
1635
1274
|
if (typeof ast === "object" && ast) {
|
|
@@ -1654,11 +1293,17 @@ function matchSelectorPattern(effect, key, idMap, context) {
|
|
|
1654
1293
|
}, false);
|
|
1655
1294
|
if (!hasExtraId) {
|
|
1656
1295
|
const name = content.slice(selector.start - 1, selector.end - 1);
|
|
1657
|
-
const selectorExpression = (0, _vue_compiler_dom.createSimpleExpression)(name, false, selector.loc);
|
|
1658
|
-
selectorExpression.ast = (0, _babel_parser.parseExpression)(`(${name})`, getParserOptions(context.options.expressionPlugins));
|
|
1659
1296
|
return {
|
|
1660
1297
|
effect,
|
|
1661
|
-
selector:
|
|
1298
|
+
selector: {
|
|
1299
|
+
content: name,
|
|
1300
|
+
ast: (0, _vue_shared.extend)({}, selector, {
|
|
1301
|
+
start: 1,
|
|
1302
|
+
end: name.length + 1
|
|
1303
|
+
}),
|
|
1304
|
+
loc: selector.loc,
|
|
1305
|
+
isStatic: false
|
|
1306
|
+
}
|
|
1662
1307
|
};
|
|
1663
1308
|
}
|
|
1664
1309
|
}
|
|
@@ -1688,6 +1333,7 @@ function isKeyOnlyBinding(expr, key, source) {
|
|
|
1688
1333
|
} });
|
|
1689
1334
|
return only;
|
|
1690
1335
|
}
|
|
1336
|
+
|
|
1691
1337
|
//#endregion
|
|
1692
1338
|
//#region packages/compiler-vapor/src/generators/html.ts
|
|
1693
1339
|
function genSetHtml(oper, context) {
|
|
@@ -1695,13 +1341,13 @@ function genSetHtml(oper, context) {
|
|
|
1695
1341
|
const { value, element, isComponent } = oper;
|
|
1696
1342
|
return [NEWLINE, ...genCall(isComponent ? helper("setBlockHtml") : helper("setHtml"), `n${element}`, genExpression(value, context))];
|
|
1697
1343
|
}
|
|
1344
|
+
|
|
1698
1345
|
//#endregion
|
|
1699
1346
|
//#region packages/compiler-vapor/src/generators/if.ts
|
|
1700
1347
|
function genIf(oper, context, isNested = false) {
|
|
1701
1348
|
const { helper } = context;
|
|
1702
|
-
const { condition, positive, negative, once,
|
|
1349
|
+
const { condition, positive, negative, once, index } = oper;
|
|
1703
1350
|
const [frag, push] = buildCodeFragment();
|
|
1704
|
-
const flags = genIfFlags(blockShape, once, slotRoot, negative ? index : void 0);
|
|
1705
1351
|
const conditionExpr = [
|
|
1706
1352
|
"() => (",
|
|
1707
1353
|
...genExpression(condition, context),
|
|
@@ -1712,44 +1358,16 @@ function genIf(oper, context, isNested = false) {
|
|
|
1712
1358
|
if (negative) if (negative.type === 1) negativeArg = genBlock(negative, context);
|
|
1713
1359
|
else negativeArg = ["() => ", ...genIf(negative, context, true)];
|
|
1714
1360
|
if (!isNested) push(NEWLINE, `const n${oper.id} = `);
|
|
1715
|
-
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg,
|
|
1361
|
+
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, once && "true", index !== void 0 && negative && String(index)));
|
|
1716
1362
|
return frag;
|
|
1717
1363
|
}
|
|
1718
|
-
|
|
1719
|
-
let flags = blockShape;
|
|
1720
|
-
if (slotRoot) flags |= 128;
|
|
1721
|
-
if (once) flags |= 16;
|
|
1722
|
-
else if (index !== void 0) flags |= index + 1 << 8;
|
|
1723
|
-
if (flags === 1) return false;
|
|
1724
|
-
return `${flags} /* ${genIfFlagNames(once, slotRoot, index, blockShape)} */`;
|
|
1725
|
-
}
|
|
1726
|
-
function genIfFlagNames(once, slotRoot, index, blockShape) {
|
|
1727
|
-
const names = [`TRUE_${genBlockShapeName(blockShape)}`];
|
|
1728
|
-
const falseShape = blockShape >> 2;
|
|
1729
|
-
const hasFalseBranch = (falseShape & 3) !== 0;
|
|
1730
|
-
if (hasFalseBranch) names.push(`FALSE_${genBlockShapeName(falseShape)}`);
|
|
1731
|
-
if (blockShape & 32) names.push("TRUE_NO_SCOPE");
|
|
1732
|
-
if (hasFalseBranch && blockShape & 64) names.push("FALSE_NO_SCOPE");
|
|
1733
|
-
if (once) names.push("ONCE");
|
|
1734
|
-
if (slotRoot) names.push("SLOT_ROOT");
|
|
1735
|
-
if (!once && index !== void 0) names.push(`KEYED_INDEX_${index}`);
|
|
1736
|
-
return names.join(", ");
|
|
1737
|
-
}
|
|
1738
|
-
function genBlockShapeName(flags) {
|
|
1739
|
-
switch (flags & 3) {
|
|
1740
|
-
case 0: return "EMPTY";
|
|
1741
|
-
case 1: return "SINGLE_ROOT";
|
|
1742
|
-
case 2: return "MULTI_ROOT";
|
|
1743
|
-
}
|
|
1744
|
-
return "UNKNOWN";
|
|
1745
|
-
}
|
|
1364
|
+
|
|
1746
1365
|
//#endregion
|
|
1747
1366
|
//#region packages/compiler-vapor/src/generators/prop.ts
|
|
1748
1367
|
const helpers = {
|
|
1749
1368
|
setText: { name: "setText" },
|
|
1750
1369
|
setHtml: { name: "setHtml" },
|
|
1751
1370
|
setClass: { name: "setClass" },
|
|
1752
|
-
setClassName: { name: "setClassName" },
|
|
1753
1371
|
setStyle: { name: "setStyle" },
|
|
1754
1372
|
setValue: { name: "setValue" },
|
|
1755
1373
|
setAttr: {
|
|
@@ -1769,133 +1387,9 @@ function genSetProp(oper, context) {
|
|
|
1769
1387
|
const { helper } = context;
|
|
1770
1388
|
const { prop: { key, values, modifier }, tag } = oper;
|
|
1771
1389
|
const resolvedHelper = getRuntimeHelper(tag, key.content, modifier);
|
|
1772
|
-
if (key.content === "class" && !resolvedHelper.isSVG && resolvedHelper.name === "setClass") {
|
|
1773
|
-
const className = genSetClassName(oper, context);
|
|
1774
|
-
if (className) return className;
|
|
1775
|
-
}
|
|
1776
1390
|
const propValue = genPropValue(values, context);
|
|
1777
1391
|
return [NEWLINE, ...genCall([helper(resolvedHelper.name), null], `n${oper.element}`, resolvedHelper.needKey ? genExpression(key, context) : false, propValue, resolvedHelper.isSVG && "true")];
|
|
1778
1392
|
}
|
|
1779
|
-
const MAX_CLASS_NAME_ENTRIES = 31;
|
|
1780
|
-
function genSetClassName(oper, context) {
|
|
1781
|
-
const info = resolveClassName(oper.prop.values, context);
|
|
1782
|
-
if (!info) return;
|
|
1783
|
-
const { helper } = context;
|
|
1784
|
-
const flags = genClassFlags(info.entries, context);
|
|
1785
|
-
const classFragments = info.entries.map((entry) => JSON.stringify(!info.prefix && info.entries.length === 1 ? entry.className : ` ${entry.className}`));
|
|
1786
|
-
const fragments = classFragments.length === 1 ? classFragments[0] : genMulti(DELIMITERS_ARRAY, ...classFragments);
|
|
1787
|
-
return [NEWLINE, ...genCall([helper("setClassName"), "\"\""], `n${oper.element}`, flags, fragments, info.prefix && JSON.stringify(info.prefix), info.suffix && JSON.stringify(info.suffix))];
|
|
1788
|
-
}
|
|
1789
|
-
function resolveClassName(values, context) {
|
|
1790
|
-
let prefix = "";
|
|
1791
|
-
let suffix = "";
|
|
1792
|
-
const entries = [];
|
|
1793
|
-
let sawDynamic = false;
|
|
1794
|
-
let sawSuffix = false;
|
|
1795
|
-
for (const rawValue of values) {
|
|
1796
|
-
const value = context.getExpressionReplacement(rawValue);
|
|
1797
|
-
const staticValue = getLiteralExpressionValue(value, true);
|
|
1798
|
-
if (staticValue != null) {
|
|
1799
|
-
const normalized = (0, _vue_shared.normalizeClass)(staticValue);
|
|
1800
|
-
if (normalized) if (sawSuffix) suffix = appendClass$1(suffix, normalized);
|
|
1801
|
-
else if (sawDynamic) {
|
|
1802
|
-
sawSuffix = true;
|
|
1803
|
-
suffix = appendClass$1(suffix, normalized);
|
|
1804
|
-
} else prefix = appendClass$1(prefix, normalized);
|
|
1805
|
-
continue;
|
|
1806
|
-
}
|
|
1807
|
-
const ast = value.ast;
|
|
1808
|
-
if (!ast || sawSuffix) return;
|
|
1809
|
-
sawDynamic = true;
|
|
1810
|
-
if (ast.type === "ObjectExpression") {
|
|
1811
|
-
if (!resolveObjectClassName(value, ast, entries, context)) return;
|
|
1812
|
-
} else if (ast.type === "ConditionalExpression") {
|
|
1813
|
-
if (!resolveConditionalClassName(value, ast, entries, context)) return;
|
|
1814
|
-
} else return;
|
|
1815
|
-
}
|
|
1816
|
-
return entries.length && entries.length <= MAX_CLASS_NAME_ENTRIES ? {
|
|
1817
|
-
prefix,
|
|
1818
|
-
suffix,
|
|
1819
|
-
entries
|
|
1820
|
-
} : void 0;
|
|
1821
|
-
}
|
|
1822
|
-
function resolveObjectClassName(source, ast, entries, context) {
|
|
1823
|
-
for (const prop of ast.properties) {
|
|
1824
|
-
if (prop.type !== "ObjectProperty" || prop.computed) return false;
|
|
1825
|
-
const rawClassName = getObjectPropertyName$1(prop);
|
|
1826
|
-
if (rawClassName == null) return false;
|
|
1827
|
-
const className = (0, _vue_shared.normalizeClass)(rawClassName);
|
|
1828
|
-
if (!className) continue;
|
|
1829
|
-
const value = getBooleanValue(prop.value);
|
|
1830
|
-
entries.push({
|
|
1831
|
-
className,
|
|
1832
|
-
value,
|
|
1833
|
-
condition: value == null ? createSubExpression(source, prop.value, context) : void 0
|
|
1834
|
-
});
|
|
1835
|
-
}
|
|
1836
|
-
return true;
|
|
1837
|
-
}
|
|
1838
|
-
function resolveConditionalClassName(source, ast, entries, context) {
|
|
1839
|
-
const consequent = getStringClassValue(ast.consequent);
|
|
1840
|
-
const alternate = getStringClassValue(ast.alternate);
|
|
1841
|
-
if (consequent && alternate === "") {
|
|
1842
|
-
entries.push({
|
|
1843
|
-
className: consequent,
|
|
1844
|
-
condition: createSubExpression(source, ast.test, context)
|
|
1845
|
-
});
|
|
1846
|
-
return true;
|
|
1847
|
-
} else if (alternate && consequent === "") {
|
|
1848
|
-
entries.push({
|
|
1849
|
-
className: alternate,
|
|
1850
|
-
condition: createSubExpression(source, ast.test, context),
|
|
1851
|
-
negate: true
|
|
1852
|
-
});
|
|
1853
|
-
return true;
|
|
1854
|
-
}
|
|
1855
|
-
return false;
|
|
1856
|
-
}
|
|
1857
|
-
function genClassFlags(entries, context) {
|
|
1858
|
-
const values = [];
|
|
1859
|
-
entries.forEach((entry, index) => {
|
|
1860
|
-
if (index) values.push(" | ");
|
|
1861
|
-
const bit = 1 << index;
|
|
1862
|
-
if (entry.value != null) {
|
|
1863
|
-
values.push(entry.value ? String(bit) : "0");
|
|
1864
|
-
return;
|
|
1865
|
-
}
|
|
1866
|
-
values.push("(", ...genExpression(entry.condition, context), entry.negate ? ` ? 0 : ${bit}` : ` ? ${bit} : 0`, ")");
|
|
1867
|
-
});
|
|
1868
|
-
return values;
|
|
1869
|
-
}
|
|
1870
|
-
function appendClass$1(base, value) {
|
|
1871
|
-
return base ? value ? `${base} ${value}` : base : value;
|
|
1872
|
-
}
|
|
1873
|
-
function getObjectPropertyName$1(prop) {
|
|
1874
|
-
const key = prop.key;
|
|
1875
|
-
if (key.type === "Identifier") return key.name;
|
|
1876
|
-
else if (key.type === "StringLiteral") return key.value;
|
|
1877
|
-
else if (key.type === "NumericLiteral") return String(key.value);
|
|
1878
|
-
}
|
|
1879
|
-
function getStringClassValue(node) {
|
|
1880
|
-
if (node.type === "StringLiteral") return (0, _vue_shared.normalizeClass)(node.value);
|
|
1881
|
-
else if (node.type === "TemplateLiteral" && node.expressions.length === 0) return (0, _vue_shared.normalizeClass)(node.quasis[0].value.cooked || "");
|
|
1882
|
-
else if (node.type === "NullLiteral" || node.type === "BooleanLiteral" && !node.value) return "";
|
|
1883
|
-
}
|
|
1884
|
-
function getBooleanValue(node) {
|
|
1885
|
-
if (node.type === "BooleanLiteral") return node.value;
|
|
1886
|
-
}
|
|
1887
|
-
function createSubExpression(source, node, context) {
|
|
1888
|
-
const start = node.start == null ? 0 : node.start - 1;
|
|
1889
|
-
const end = node.end == null ? source.content.length : node.end - 1;
|
|
1890
|
-
const content = source.content.slice(start, end);
|
|
1891
|
-
const expression = (0, _vue_compiler_dom.createSimpleExpression)(content, false, {
|
|
1892
|
-
start: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, source.content, start),
|
|
1893
|
-
end: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, source.content, end),
|
|
1894
|
-
source: content
|
|
1895
|
-
});
|
|
1896
|
-
expression.ast = (0, _vue_compiler_dom.isSimpleIdentifier)(content) ? null : (0, _babel_parser.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
1897
|
-
return expression;
|
|
1898
|
-
}
|
|
1899
1393
|
function genDynamicProps$1(oper, context) {
|
|
1900
1394
|
const { helper } = context;
|
|
1901
1395
|
const isSVG = (0, _vue_shared.isSVGTag)(oper.tag);
|
|
@@ -1924,12 +1418,7 @@ function genPropKey({ key: node, modifier, runtimeCamelize, handler, handlerModi
|
|
|
1924
1418
|
if (runtimeCamelize) {
|
|
1925
1419
|
key.push(" || \"\"");
|
|
1926
1420
|
key = genCall(helper("camelize"), key);
|
|
1927
|
-
}
|
|
1928
|
-
"(",
|
|
1929
|
-
...key,
|
|
1930
|
-
" || \"\"",
|
|
1931
|
-
")"
|
|
1932
|
-
];
|
|
1421
|
+
}
|
|
1933
1422
|
if (handler) key = genCall(helper("toHandlerKey"), key);
|
|
1934
1423
|
return [
|
|
1935
1424
|
"[",
|
|
@@ -1962,28 +1451,14 @@ function getSpecialHelper(keyName, tagName, isSVG) {
|
|
|
1962
1451
|
else if (keyName === "innerHTML") return helpers.setHtml;
|
|
1963
1452
|
else if (keyName === "textContent") return helpers.setText;
|
|
1964
1453
|
}
|
|
1454
|
+
|
|
1965
1455
|
//#endregion
|
|
1966
1456
|
//#region packages/compiler-vapor/src/generators/templateRef.ts
|
|
1967
1457
|
const setTemplateRefIdent = `_setTemplateRef`;
|
|
1968
1458
|
function genSetTemplateRef(oper, context) {
|
|
1969
1459
|
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
1970
|
-
if (context.staticTemplateRefHelperCandidate === oper) return genSetStaticTemplateRef(oper, refValue, refKey, context);
|
|
1971
|
-
context.needsTemplateRefSetter = true;
|
|
1972
1460
|
return [NEWLINE, ...genCall(setTemplateRefIdent, `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
1973
1461
|
}
|
|
1974
|
-
function genSetStaticTemplateRef(oper, refValue, refKey, context) {
|
|
1975
|
-
return [NEWLINE, ...genCall(context.helper("setStaticTemplateRef"), `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
1976
|
-
}
|
|
1977
|
-
function genSetTemplateRefBinding(oper, context) {
|
|
1978
|
-
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
1979
|
-
const setter = context.inSlotBlock && setTemplateRefIdent;
|
|
1980
|
-
if (context.inSlotBlock) context.needsTemplateRefSetter = true;
|
|
1981
|
-
return [NEWLINE, ...genCall([context.helper("setTemplateRefBinding"), "undefined"], `n${oper.element}`, ["() => ", ...refValue], ...setter || oper.refFor || refKey ? [
|
|
1982
|
-
setter,
|
|
1983
|
-
oper.refFor && "true",
|
|
1984
|
-
refKey
|
|
1985
|
-
] : [])];
|
|
1986
|
-
}
|
|
1987
1462
|
function genRefValue(value, context) {
|
|
1988
1463
|
if (value && context.options.inline) {
|
|
1989
1464
|
const binding = context.options.bindingMetadata[value.content];
|
|
@@ -1991,6 +1466,7 @@ function genRefValue(value, context) {
|
|
|
1991
1466
|
}
|
|
1992
1467
|
return [genExpression(value, context)];
|
|
1993
1468
|
}
|
|
1469
|
+
|
|
1994
1470
|
//#endregion
|
|
1995
1471
|
//#region packages/compiler-vapor/src/generators/text.ts
|
|
1996
1472
|
function genSetText(oper, context) {
|
|
@@ -2010,21 +1486,23 @@ function combineValues(values, context) {
|
|
|
2010
1486
|
function genGetTextChild(oper, context) {
|
|
2011
1487
|
return [NEWLINE, `const x${oper.parent} = ${context.helper("txt")}(n${oper.parent})`];
|
|
2012
1488
|
}
|
|
1489
|
+
|
|
2013
1490
|
//#endregion
|
|
2014
1491
|
//#region packages/compiler-vapor/src/generators/vShow.ts
|
|
2015
1492
|
function genVShow(oper, context) {
|
|
2016
|
-
const { element } = oper;
|
|
2017
|
-
return [
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
1493
|
+
const { deferred, element } = oper;
|
|
1494
|
+
return [
|
|
1495
|
+
NEWLINE,
|
|
1496
|
+
deferred ? `deferredApplyVShows.push(() => ` : void 0,
|
|
1497
|
+
...genCall(context.helper("applyVShow"), `n${element}`, [
|
|
1498
|
+
`() => (`,
|
|
1499
|
+
...genExpression(oper.dir.exp, context),
|
|
1500
|
+
`)`
|
|
1501
|
+
]),
|
|
1502
|
+
deferred ? `)` : void 0
|
|
1503
|
+
];
|
|
2027
1504
|
}
|
|
1505
|
+
|
|
2028
1506
|
//#endregion
|
|
2029
1507
|
//#region packages/compiler-vapor/src/generators/vModel.ts
|
|
2030
1508
|
const helperMap = {
|
|
@@ -2040,7 +1518,7 @@ function genVModel(oper, context) {
|
|
|
2040
1518
|
`() => (`,
|
|
2041
1519
|
...genExpression(exp, context),
|
|
2042
1520
|
`)`
|
|
2043
|
-
], genModelHandler(exp, context), modifiers.length ? `{ ${
|
|
1521
|
+
], genModelHandler(exp, context), modifiers.length ? `{ ${modifiers.map((e) => e.content + ": true").join(",")} }` : void 0)];
|
|
2044
1522
|
}
|
|
2045
1523
|
function genModelHandler(exp, context) {
|
|
2046
1524
|
return [
|
|
@@ -2049,6 +1527,7 @@ function genModelHandler(exp, context) {
|
|
|
2049
1527
|
")"
|
|
2050
1528
|
];
|
|
2051
1529
|
}
|
|
1530
|
+
|
|
2052
1531
|
//#endregion
|
|
2053
1532
|
//#region packages/compiler-vapor/src/generators/directive.ts
|
|
2054
1533
|
function genBuiltinDirective(oper, context) {
|
|
@@ -2082,31 +1561,26 @@ function genCustomDirectives(opers, context) {
|
|
|
2082
1561
|
return genMulti(DELIMITERS_ARRAY.concat("void 0"), directiveVar, value, argument, modifiers);
|
|
2083
1562
|
}
|
|
2084
1563
|
}
|
|
1564
|
+
function genDirectiveModifiers(modifiers) {
|
|
1565
|
+
return modifiers.map((value) => `${(0, _vue_compiler_dom.isSimpleIdentifier)(value) ? value : JSON.stringify(value)}: true`).join(", ");
|
|
1566
|
+
}
|
|
2085
1567
|
function filterCustomDirectives(id, operations) {
|
|
2086
|
-
return operations.filter((oper) => oper.type ===
|
|
1568
|
+
return operations.filter((oper) => oper.type === 13 && oper.element === id && !oper.builtin);
|
|
2087
1569
|
}
|
|
1570
|
+
|
|
2088
1571
|
//#endregion
|
|
2089
1572
|
//#region packages/compiler-vapor/src/generators/component.ts
|
|
2090
|
-
function genStaticModifierPropKey(name) {
|
|
2091
|
-
const key = (0, _vue_shared.getModifierPropName)(name);
|
|
2092
|
-
return [(0, _vue_compiler_dom.isSimpleIdentifier)(key) ? key : JSON.stringify(key)];
|
|
2093
|
-
}
|
|
2094
1573
|
function genCreateComponent(operation, context) {
|
|
2095
1574
|
const { helper } = context;
|
|
2096
|
-
const singleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
2097
|
-
const useAssetComponentHelper = operation.asset && !operation.dynamic && context.block === context.ir.block && !!singleUseAssetComponentNames && singleUseAssetComponentNames.has(operation.tag);
|
|
2098
|
-
const maybeSelfReference = useAssetComponentHelper && operation.tag.endsWith("__self");
|
|
2099
1575
|
const tag = genTag();
|
|
2100
|
-
const { root, props, slots, once
|
|
2101
|
-
const isRuntimeDynamicComponent = !!(operation.dynamic && !operation.dynamic.isStatic);
|
|
2102
|
-
const dynamicComponentFlags = isRuntimeDynamicComponent ? genDynamicComponentFlags(root, once, slotRoot) : false;
|
|
1576
|
+
const { root, props, slots, once } = operation;
|
|
2103
1577
|
const rawSlots = genRawSlots(slots, context);
|
|
2104
1578
|
const [ids, handlers] = processInlineHandlers(props, context);
|
|
2105
|
-
const rawProps = context.withId(() => genRawProps(props, context
|
|
1579
|
+
const rawProps = context.withId(() => genRawProps(props, context), ids);
|
|
2106
1580
|
return [
|
|
2107
1581
|
NEWLINE,
|
|
2108
1582
|
...handlers.reduce((acc, { name, value }) => {
|
|
2109
|
-
const handler = genEventHandler(context, [value]);
|
|
1583
|
+
const handler = genEventHandler(context, [value], void 0, false, false);
|
|
2110
1584
|
return [
|
|
2111
1585
|
...acc,
|
|
2112
1586
|
`const ${name} = `,
|
|
@@ -2115,21 +1589,18 @@ function genCreateComponent(operation, context) {
|
|
|
2115
1589
|
];
|
|
2116
1590
|
}, []),
|
|
2117
1591
|
`const n${operation.id} = `,
|
|
2118
|
-
...genCall(
|
|
1592
|
+
...genCall(operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.isCustomElement ? helper("createPlainElement") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, root ? "true" : false, once && "true"),
|
|
2119
1593
|
...genDirectivesForElement(operation.id, context)
|
|
2120
1594
|
];
|
|
2121
1595
|
function genTag() {
|
|
2122
|
-
if (operation.
|
|
1596
|
+
if (operation.isCustomElement) return JSON.stringify(operation.tag);
|
|
2123
1597
|
else if (operation.dynamic) if (operation.dynamic.isStatic) return genCall(helper("resolveDynamicComponent"), genExpression(operation.dynamic, context));
|
|
2124
1598
|
else return [
|
|
2125
1599
|
"() => (",
|
|
2126
1600
|
...genExpression(operation.dynamic, context),
|
|
2127
1601
|
")"
|
|
2128
1602
|
];
|
|
2129
|
-
else if (
|
|
2130
|
-
const name = maybeSelfReference ? operation.tag.slice(0, -6) : operation.tag;
|
|
2131
|
-
return JSON.stringify(name);
|
|
2132
|
-
} else if (operation.asset) return (0, _vue_compiler_dom.toValidAssetId)(operation.tag, "component");
|
|
1603
|
+
else if (operation.asset) return (0, _vue_compiler_dom.toValidAssetId)(operation.tag, "component");
|
|
2133
1604
|
else {
|
|
2134
1605
|
const { tag } = operation;
|
|
2135
1606
|
const builtInTag = isBuiltInComponent(tag);
|
|
@@ -2141,28 +1612,6 @@ function genCreateComponent(operation, context) {
|
|
|
2141
1612
|
}
|
|
2142
1613
|
}
|
|
2143
1614
|
}
|
|
2144
|
-
function genDynamicComponentFlags(root, once, slotRoot, extraFlags) {
|
|
2145
|
-
let flags = 0;
|
|
2146
|
-
const names = [];
|
|
2147
|
-
if (root) {
|
|
2148
|
-
flags |= 1;
|
|
2149
|
-
names.push("SINGLE_ROOT");
|
|
2150
|
-
}
|
|
2151
|
-
if (once) {
|
|
2152
|
-
flags |= 2;
|
|
2153
|
-
names.push("ONCE");
|
|
2154
|
-
}
|
|
2155
|
-
if (slotRoot) {
|
|
2156
|
-
flags |= 4;
|
|
2157
|
-
names.push("SLOT_ROOT");
|
|
2158
|
-
}
|
|
2159
|
-
if (extraFlags) for (const [flag, name] of extraFlags) {
|
|
2160
|
-
flags |= flag;
|
|
2161
|
-
names.push(name);
|
|
2162
|
-
}
|
|
2163
|
-
if (!flags) return false;
|
|
2164
|
-
return `${flags} /* ${names.join(", ")} */`;
|
|
2165
|
-
}
|
|
2166
1615
|
function getUniqueHandlerName(context, name) {
|
|
2167
1616
|
const { seenInlineHandlerNames } = context;
|
|
2168
1617
|
name = genVarName(name);
|
|
@@ -2191,14 +1640,14 @@ function processInlineHandlers(props, context) {
|
|
|
2191
1640
|
}
|
|
2192
1641
|
return [ids, handlers];
|
|
2193
1642
|
}
|
|
2194
|
-
function genRawProps(props, context
|
|
1643
|
+
function genRawProps(props, context) {
|
|
2195
1644
|
const staticProps = props[0];
|
|
2196
1645
|
if ((0, _vue_shared.isArray)(staticProps)) {
|
|
2197
1646
|
if (!staticProps.length && props.length === 1) return;
|
|
2198
|
-
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context
|
|
2199
|
-
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context
|
|
1647
|
+
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context));
|
|
1648
|
+
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context));
|
|
2200
1649
|
}
|
|
2201
|
-
function genStaticProps(props, context, dynamicProps
|
|
1650
|
+
function genStaticProps(props, context, dynamicProps) {
|
|
2202
1651
|
const args = [];
|
|
2203
1652
|
const handlerGroups = /* @__PURE__ */ new Map();
|
|
2204
1653
|
const ensureHandlerGroup = (keyName, keyFrag) => {
|
|
@@ -2231,11 +1680,11 @@ function genStaticProps(props, context, dynamicProps, directStaticLiteralProps =
|
|
|
2231
1680
|
continue;
|
|
2232
1681
|
}
|
|
2233
1682
|
const keyFrag = genPropKey(prop, context);
|
|
2234
|
-
if (!!prop.handlerModifiers && (prop.handlerModifiers.keys.length > 0 || prop.handlerModifiers.nonKeys.length > 0) || prop.values.length <= 1) addHandler(keyName, keyFrag, genEventHandler(context, prop.values, prop.handlerModifiers,
|
|
2235
|
-
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers,
|
|
1683
|
+
if (!!prop.handlerModifiers && (prop.handlerModifiers.keys.length > 0 || prop.handlerModifiers.nonKeys.length > 0) || prop.values.length <= 1) addHandler(keyName, keyFrag, genEventHandler(context, prop.values, prop.handlerModifiers, true, false));
|
|
1684
|
+
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, true, false));
|
|
2236
1685
|
continue;
|
|
2237
1686
|
}
|
|
2238
|
-
args.push(genProp(prop, context, true
|
|
1687
|
+
args.push(genProp(prop, context, true));
|
|
2239
1688
|
if (prop.model) {
|
|
2240
1689
|
if (prop.key.isStatic) {
|
|
2241
1690
|
const keyName = `onUpdate:${(0, _vue_shared.camelize)(prop.key.content)}`;
|
|
@@ -2254,13 +1703,13 @@ function genStaticProps(props, context, dynamicProps, directStaticLiteralProps =
|
|
|
2254
1703
|
}
|
|
2255
1704
|
const { key, modelModifiers } = prop;
|
|
2256
1705
|
if (modelModifiers && modelModifiers.length) {
|
|
2257
|
-
const modifiersKey = key.isStatic ?
|
|
1706
|
+
const modifiersKey = key.isStatic ? [(0, _vue_shared.getModifierPropName)(key.content)] : [
|
|
2258
1707
|
"[",
|
|
2259
1708
|
...genExpression(key, context),
|
|
2260
1709
|
" + \"Modifiers\"]"
|
|
2261
1710
|
];
|
|
2262
1711
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
2263
|
-
args.push([...modifiersKey,
|
|
1712
|
+
args.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
|
|
2264
1713
|
}
|
|
2265
1714
|
}
|
|
2266
1715
|
}
|
|
@@ -2275,13 +1724,13 @@ function genStaticProps(props, context, dynamicProps, directStaticLiteralProps =
|
|
|
2275
1724
|
if (dynamicProps) args.push([`$: `, ...dynamicProps]);
|
|
2276
1725
|
return genMulti(args.length > 1 ? DELIMITERS_OBJECT_NEWLINE : DELIMITERS_OBJECT, ...args);
|
|
2277
1726
|
}
|
|
2278
|
-
function genDynamicProps(props, context
|
|
1727
|
+
function genDynamicProps(props, context) {
|
|
2279
1728
|
const { helper } = context;
|
|
2280
1729
|
const frags = [];
|
|
2281
1730
|
for (const p of props) {
|
|
2282
1731
|
let expr;
|
|
2283
1732
|
if ((0, _vue_shared.isArray)(p)) {
|
|
2284
|
-
if (p.length) frags.push(genStaticProps(p, context
|
|
1733
|
+
if (p.length) frags.push(genStaticProps(p, context));
|
|
2285
1734
|
continue;
|
|
2286
1735
|
} else if (p.kind === 1) if (p.model) {
|
|
2287
1736
|
const entries = [genProp(p, context)];
|
|
@@ -2292,21 +1741,21 @@ function genDynamicProps(props, context, directStaticLiteralProps = false) {
|
|
|
2292
1741
|
];
|
|
2293
1742
|
entries.push([
|
|
2294
1743
|
...updateKey,
|
|
2295
|
-
": ",
|
|
1744
|
+
": () => ",
|
|
2296
1745
|
...genModelHandler(p.values[0], context)
|
|
2297
1746
|
]);
|
|
2298
1747
|
const { modelModifiers } = p;
|
|
2299
1748
|
if (modelModifiers && modelModifiers.length) {
|
|
2300
|
-
const modifiersKey = p.key.isStatic ?
|
|
1749
|
+
const modifiersKey = p.key.isStatic ? [(0, _vue_shared.getModifierPropName)(p.key.content)] : [
|
|
2301
1750
|
"[",
|
|
2302
1751
|
...genExpression(p.key, context),
|
|
2303
1752
|
" + \"Modifiers\"]"
|
|
2304
1753
|
];
|
|
2305
1754
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
2306
|
-
entries.push([...modifiersKey, `: { ${modifiersVal} }`]);
|
|
1755
|
+
entries.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
|
|
2307
1756
|
}
|
|
2308
1757
|
expr = genMulti(DELIMITERS_OBJECT_NEWLINE, ...entries);
|
|
2309
|
-
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context
|
|
1758
|
+
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context));
|
|
2310
1759
|
else {
|
|
2311
1760
|
expr = genExpression(p.value, context);
|
|
2312
1761
|
if (p.handler) expr = genCall(helper("toHandlers"), expr);
|
|
@@ -2319,79 +1768,27 @@ function genDynamicProps(props, context, directStaticLiteralProps = false) {
|
|
|
2319
1768
|
}
|
|
2320
1769
|
if (frags.length) return genMulti(DELIMITERS_ARRAY_NEWLINE, ...frags);
|
|
2321
1770
|
}
|
|
2322
|
-
function genProp(prop, context, isStatic
|
|
1771
|
+
function genProp(prop, context, isStatic) {
|
|
2323
1772
|
const values = genPropValue(prop.values, context);
|
|
2324
1773
|
return [
|
|
2325
1774
|
...genPropKey(prop, context),
|
|
2326
1775
|
": ",
|
|
2327
|
-
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers,
|
|
2328
|
-
asComponentProp: true,
|
|
2329
|
-
extraWrap: wrapHandler
|
|
2330
|
-
}) : isStatic ? directStaticLiteral ? values : [
|
|
1776
|
+
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, true, true) : isStatic ? [
|
|
2331
1777
|
"() => (",
|
|
2332
1778
|
...values,
|
|
2333
1779
|
")"
|
|
2334
1780
|
] : values
|
|
2335
1781
|
];
|
|
2336
1782
|
}
|
|
2337
|
-
/**
|
|
2338
|
-
* Static literal values are safe to emit directly because reading them cannot
|
|
2339
|
-
* touch reactive state. Keep handlers, v-model values, and dynamic expressions
|
|
2340
|
-
* as getter sources to preserve lazy access and merge semantics.
|
|
2341
|
-
*/
|
|
2342
|
-
function isDirectStaticLiteralProp(prop, context) {
|
|
2343
|
-
return prop.key.isStatic && prop.values.length === 1 && !prop.handler && !prop.model && isDirectConstantValue(prop.values[0], context);
|
|
2344
|
-
}
|
|
2345
|
-
function isDirectConstantValue(value, context) {
|
|
2346
|
-
value = context.getExpressionReplacement(value);
|
|
2347
|
-
if (value.isStatic) return true;
|
|
2348
|
-
const ast = value.ast;
|
|
2349
|
-
if (ast === null) return value.content === "true" || value.content === "false" || value.content === "null" || value.content === "undefined";
|
|
2350
|
-
if (!ast) return false;
|
|
2351
|
-
return isDirectConstantAst(ast);
|
|
2352
|
-
}
|
|
2353
|
-
function isDirectConstantAst(node) {
|
|
2354
|
-
switch (node.type) {
|
|
2355
|
-
case "StringLiteral":
|
|
2356
|
-
case "NumericLiteral":
|
|
2357
|
-
case "BooleanLiteral":
|
|
2358
|
-
case "NullLiteral":
|
|
2359
|
-
case "BigIntLiteral": return true;
|
|
2360
|
-
case "Identifier": return node.name === "undefined";
|
|
2361
|
-
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
2362
|
-
case "ArrayExpression": return node.elements.every((element) => element === null || element.type !== "SpreadElement" && isDirectConstantAst(element));
|
|
2363
|
-
case "ObjectExpression": return node.properties.every((prop) => prop.type === "ObjectProperty" && !prop.computed && isDirectConstantAst(prop.value));
|
|
2364
|
-
}
|
|
2365
|
-
return false;
|
|
2366
|
-
}
|
|
2367
|
-
function isDirectTemplateConstantAst(node) {
|
|
2368
|
-
switch (node.type) {
|
|
2369
|
-
case "StringLiteral":
|
|
2370
|
-
case "NumericLiteral":
|
|
2371
|
-
case "BooleanLiteral":
|
|
2372
|
-
case "NullLiteral":
|
|
2373
|
-
case "BigIntLiteral": return true;
|
|
2374
|
-
case "Identifier": return node.name === "undefined";
|
|
2375
|
-
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
2376
|
-
}
|
|
2377
|
-
return false;
|
|
2378
|
-
}
|
|
2379
1783
|
function genRawSlots(slots, context) {
|
|
2380
1784
|
if (!slots.length) return;
|
|
2381
1785
|
const staticSlots = slots[0];
|
|
2382
|
-
if (staticSlots.slotType === 0)
|
|
2383
|
-
|
|
2384
|
-
if (defaultSlot && slots.length === 1) return genSlotBlockWithProps(defaultSlot, context);
|
|
2385
|
-
return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
|
|
2386
|
-
} else return genStaticSlots({
|
|
1786
|
+
if (staticSlots.slotType === 0) return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
|
|
1787
|
+
else return genStaticSlots({
|
|
2387
1788
|
slotType: 0,
|
|
2388
1789
|
slots: {}
|
|
2389
1790
|
}, context, slots);
|
|
2390
1791
|
}
|
|
2391
|
-
function getSingleDefaultSlot({ slots }) {
|
|
2392
|
-
const names = Object.keys(slots);
|
|
2393
|
-
return names.length === 1 && names[0] === "default" ? slots.default : void 0;
|
|
2394
|
-
}
|
|
2395
1792
|
function genStaticSlots({ slots }, context, dynamicSlots) {
|
|
2396
1793
|
const args = Object.keys(slots).map((name) => [`${JSON.stringify(name)}: `, ...genSlotBlockWithProps(slots[name], context)]);
|
|
2397
1794
|
if (dynamicSlots) args.push([`$: `, ...genDynamicSlots(dynamicSlots, context)]);
|
|
@@ -2413,16 +1810,15 @@ function genDynamicSlot(slot, context, withFunction = false) {
|
|
|
2413
1810
|
frag = genConditionalSlot(slot, context);
|
|
2414
1811
|
break;
|
|
2415
1812
|
}
|
|
2416
|
-
|
|
2417
|
-
return [
|
|
1813
|
+
return withFunction ? [
|
|
2418
1814
|
"() => (",
|
|
2419
1815
|
...frag,
|
|
2420
1816
|
")"
|
|
2421
|
-
];
|
|
1817
|
+
] : frag;
|
|
2422
1818
|
}
|
|
2423
1819
|
function genBasicDynamicSlot(slot, context) {
|
|
2424
1820
|
const { name, fn } = slot;
|
|
2425
|
-
return genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...genExpression(name, context)], ["fn: ", ...genSlotBlockWithProps(fn, context
|
|
1821
|
+
return genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...genExpression(name, context)], ["fn: ", ...genSlotBlockWithProps(fn, context)]);
|
|
2426
1822
|
}
|
|
2427
1823
|
function genLoopSlot(slot, context) {
|
|
2428
1824
|
const { name, fn, loop } = slot;
|
|
@@ -2434,7 +1830,7 @@ function genLoopSlot(slot, context) {
|
|
|
2434
1830
|
if (rawValue) idMap[rawValue] = rawValue;
|
|
2435
1831
|
if (rawKey) idMap[rawKey] = rawKey;
|
|
2436
1832
|
if (rawIndex) idMap[rawIndex] = rawIndex;
|
|
2437
|
-
const slotExpr = genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...context.withId(() => genExpression(name, context), idMap)], ["fn: ", ...context.withId(() => genSlotBlockWithProps(fn, context
|
|
1833
|
+
const slotExpr = genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...context.withId(() => genExpression(name, context), idMap)], ["fn: ", ...context.withId(() => genSlotBlockWithProps(fn, context), idMap)]);
|
|
2438
1834
|
return [...genCall(context.helper("createForSlots"), genExpression(source, context), [
|
|
2439
1835
|
...genMulti([
|
|
2440
1836
|
"(",
|
|
@@ -2460,11 +1856,11 @@ function genConditionalSlot(slot, context) {
|
|
|
2460
1856
|
INDENT_END
|
|
2461
1857
|
];
|
|
2462
1858
|
}
|
|
2463
|
-
function genSlotBlockWithProps(oper, context
|
|
1859
|
+
function genSlotBlockWithProps(oper, context) {
|
|
2464
1860
|
let propsName;
|
|
2465
1861
|
let exitScope;
|
|
2466
1862
|
let depth;
|
|
2467
|
-
const { props } = oper;
|
|
1863
|
+
const { props, key, node } = oper;
|
|
2468
1864
|
const idToPathMap = props ? parseValueDestructure(props, context) : /* @__PURE__ */ new Map();
|
|
2469
1865
|
if (props) if (props.ast) {
|
|
2470
1866
|
[depth, exitScope] = context.enterScope();
|
|
@@ -2472,57 +1868,33 @@ function genSlotBlockWithProps(oper, context, emitNonStableFlag = true) {
|
|
|
2472
1868
|
} else propsName = props.content;
|
|
2473
1869
|
const idMap = idToPathMap.size ? buildDestructureIdMap(idToPathMap, propsName || "", context.options.expressionPlugins) : {};
|
|
2474
1870
|
if (propsName) idMap[propsName] = null;
|
|
2475
|
-
const exitSlotBlock = context.enterSlotBlock();
|
|
2476
|
-
const hasStableRoot = hasStableSlotRoot(oper, context);
|
|
2477
|
-
if (!hasStableRoot) markSlotRootOperations(oper);
|
|
2478
1871
|
let blockFn = context.withId(() => genBlock(oper, context, propsName ? [propsName] : []), idMap);
|
|
2479
|
-
if (emitNonStableFlag && !hasStableRoot) blockFn = genCall(context.helper("extend"), blockFn, [`{ _: ${genSlotFlags$1(8)} }`]);
|
|
2480
|
-
exitSlotBlock();
|
|
2481
1872
|
exitScope && exitScope();
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
const operation = child && child.operation;
|
|
2499
|
-
if (!operation) {
|
|
2500
|
-
if (child && isStableTemplateSlotRoot(child, context)) hasValidRoot = true;
|
|
2501
|
-
continue;
|
|
2502
|
-
}
|
|
2503
|
-
switch (operation.type) {
|
|
2504
|
-
case 12:
|
|
2505
|
-
if (!operation.dynamic || operation.dynamic.isStatic) {
|
|
2506
|
-
hasValidRoot = true;
|
|
2507
|
-
continue;
|
|
2508
|
-
}
|
|
2509
|
-
continue;
|
|
2510
|
-
case 17:
|
|
2511
|
-
if (hasStableSlotRoot(operation.block, context)) {
|
|
2512
|
-
hasValidRoot = true;
|
|
2513
|
-
continue;
|
|
2514
|
-
}
|
|
2515
|
-
continue;
|
|
2516
|
-
default: continue;
|
|
2517
|
-
}
|
|
1873
|
+
if (key) blockFn = [
|
|
1874
|
+
`() => {`,
|
|
1875
|
+
INDENT_START,
|
|
1876
|
+
NEWLINE,
|
|
1877
|
+
`return `,
|
|
1878
|
+
...genCall(context.helper("createKeyedFragment"), [`() => `, ...genExpression(key, context)], blockFn),
|
|
1879
|
+
INDENT_END,
|
|
1880
|
+
NEWLINE,
|
|
1881
|
+
`}`
|
|
1882
|
+
];
|
|
1883
|
+
if (node.type === 1) {
|
|
1884
|
+
if (needsVaporCtx(oper)) blockFn = [
|
|
1885
|
+
`${context.helper("withVaporCtx")}(`,
|
|
1886
|
+
...blockFn,
|
|
1887
|
+
`)`
|
|
1888
|
+
];
|
|
2518
1889
|
}
|
|
2519
|
-
return
|
|
2520
|
-
}
|
|
2521
|
-
function isStableTemplateSlotRoot(child, context) {
|
|
2522
|
-
if (child.template == null) return false;
|
|
2523
|
-
const content = context.ir.template.entries[child.template].content;
|
|
2524
|
-
return content !== "" && !commentOnlyTemplateRE.test(content.trim());
|
|
1890
|
+
return blockFn;
|
|
2525
1891
|
}
|
|
1892
|
+
/**
|
|
1893
|
+
* Check if a slot block needs withVaporCtx wrapper.
|
|
1894
|
+
* Returns true if the block contains:
|
|
1895
|
+
* - Component creation (needs scopeId inheritance)
|
|
1896
|
+
* - Slot outlet (needs rawSlots from slot owner)
|
|
1897
|
+
*/
|
|
2526
1898
|
function needsVaporCtx(block) {
|
|
2527
1899
|
return hasComponentOrSlotInBlock(block);
|
|
2528
1900
|
}
|
|
@@ -2533,11 +1905,11 @@ function hasComponentOrSlotInBlock(block) {
|
|
|
2533
1905
|
function hasComponentOrSlotInDynamic(dynamic) {
|
|
2534
1906
|
if (dynamic.operation) {
|
|
2535
1907
|
const type = dynamic.operation.type;
|
|
2536
|
-
if (type ===
|
|
2537
|
-
if (type ===
|
|
1908
|
+
if (type === 11 || type === 12) return true;
|
|
1909
|
+
if (type === 14) {
|
|
2538
1910
|
if (hasComponentOrSlotInIf(dynamic.operation)) return true;
|
|
2539
1911
|
}
|
|
2540
|
-
if (type ===
|
|
1912
|
+
if (type === 15) {
|
|
2541
1913
|
if (hasComponentOrSlotInBlock(dynamic.operation.render)) return true;
|
|
2542
1914
|
}
|
|
2543
1915
|
}
|
|
@@ -2546,12 +1918,12 @@ function hasComponentOrSlotInDynamic(dynamic) {
|
|
|
2546
1918
|
}
|
|
2547
1919
|
function hasComponentOrSlotInOperations(operations) {
|
|
2548
1920
|
for (const op of operations) switch (op.type) {
|
|
2549
|
-
case
|
|
2550
|
-
case
|
|
2551
|
-
case
|
|
1921
|
+
case 11:
|
|
1922
|
+
case 12: return true;
|
|
1923
|
+
case 14:
|
|
2552
1924
|
if (hasComponentOrSlotInIf(op)) return true;
|
|
2553
1925
|
break;
|
|
2554
|
-
case
|
|
1926
|
+
case 15:
|
|
2555
1927
|
if (hasComponentOrSlotInBlock(op.render)) return true;
|
|
2556
1928
|
break;
|
|
2557
1929
|
}
|
|
@@ -2563,51 +1935,24 @@ function hasComponentOrSlotInIf(node) {
|
|
|
2563
1935
|
else return hasComponentOrSlotInBlock(node.negative);
|
|
2564
1936
|
return false;
|
|
2565
1937
|
}
|
|
1938
|
+
|
|
2566
1939
|
//#endregion
|
|
2567
1940
|
//#region packages/compiler-vapor/src/generators/slotOutlet.ts
|
|
2568
1941
|
function genSlotOutlet(oper, context) {
|
|
2569
1942
|
const { helper } = context;
|
|
2570
|
-
const { id, name, fallback,
|
|
1943
|
+
const { id, name, fallback, noSlotted, once } = oper;
|
|
2571
1944
|
const [frag, push] = buildCodeFragment();
|
|
2572
|
-
|
|
2573
|
-
if (fallback) {
|
|
2574
|
-
if (context.inSlotBlock) markSlotRootOperations(fallback);
|
|
2575
|
-
fallbackArg = genBlock(fallback, context);
|
|
2576
|
-
}
|
|
2577
|
-
const createSlot = helper("createSlot");
|
|
2578
|
-
const rawPropsArg = genRawProps(oper.props, context, true);
|
|
2579
|
-
const nameArg = name.isStatic && name.content === "default" && !rawPropsArg && !fallbackArg && !flags ? void 0 : name.isStatic ? genExpression(name, context) : [
|
|
1945
|
+
const nameExpr = name.isStatic ? genExpression(name, context) : [
|
|
2580
1946
|
"() => (",
|
|
2581
1947
|
...genExpression(name, context),
|
|
2582
1948
|
")"
|
|
2583
1949
|
];
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
}
|
|
2587
|
-
function genSlotFlags(flags) {
|
|
2588
|
-
if (!flags) return;
|
|
2589
|
-
const names = [];
|
|
2590
|
-
if (flags & 1) names.push("NO_SLOTTED");
|
|
2591
|
-
if (flags & 2) names.push("ONCE");
|
|
2592
|
-
if (flags & 4) names.push("SLOT_ROOT");
|
|
2593
|
-
return `${flags} /* ${names.join(", ")} */`;
|
|
2594
|
-
}
|
|
2595
|
-
//#endregion
|
|
2596
|
-
//#region packages/compiler-vapor/src/generators/key.ts
|
|
2597
|
-
function genKey(oper, context) {
|
|
2598
|
-
const { id, value, block } = oper;
|
|
2599
|
-
const [frag, push] = buildCodeFragment();
|
|
2600
|
-
const blockFn = genBlock(block, context);
|
|
2601
|
-
push(NEWLINE, `const n${id} = `, ...genCall(context.helper("createKeyedFragment"), [
|
|
2602
|
-
`() => (`,
|
|
2603
|
-
...genExpression(value, context),
|
|
2604
|
-
")"
|
|
2605
|
-
], blockFn));
|
|
1950
|
+
let fallbackArg;
|
|
1951
|
+
if (fallback) fallbackArg = genBlock(fallback, context);
|
|
1952
|
+
push(NEWLINE, `const n${id} = `, ...genCall(helper("createSlot"), nameExpr, genRawProps(oper.props, context) || "null", fallbackArg, noSlotted && "true", once && "true"));
|
|
2606
1953
|
return frag;
|
|
2607
1954
|
}
|
|
2608
|
-
|
|
2609
|
-
return [NEWLINE, ...genCall(context.helper("setBlockKey"), `n${oper.element}`, genExpression(oper.value, context))];
|
|
2610
|
-
}
|
|
1955
|
+
|
|
2611
1956
|
//#endregion
|
|
2612
1957
|
//#region packages/compiler-vapor/src/generators/operation.ts
|
|
2613
1958
|
function genOperations(opers, context) {
|
|
@@ -2623,26 +1968,26 @@ function genOperationWithInsertionState(oper, context) {
|
|
|
2623
1968
|
}
|
|
2624
1969
|
function genOperation(oper, context) {
|
|
2625
1970
|
switch (oper.type) {
|
|
2626
|
-
case 2: return
|
|
2627
|
-
case 3: return
|
|
2628
|
-
case 4: return
|
|
2629
|
-
case 5: return
|
|
2630
|
-
case 6: return
|
|
2631
|
-
case 7: return
|
|
2632
|
-
case 8: return
|
|
2633
|
-
case 9: return
|
|
2634
|
-
case 10: return
|
|
2635
|
-
case
|
|
2636
|
-
case 15: return
|
|
2637
|
-
case
|
|
2638
|
-
case
|
|
2639
|
-
case
|
|
2640
|
-
case
|
|
2641
|
-
case
|
|
2642
|
-
case 18: return
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
1971
|
+
case 2: return genSetProp(oper, context);
|
|
1972
|
+
case 3: return genDynamicProps$1(oper, context);
|
|
1973
|
+
case 4: return genSetText(oper, context);
|
|
1974
|
+
case 5: return genSetEvent(oper, context);
|
|
1975
|
+
case 6: return genSetDynamicEvents(oper, context);
|
|
1976
|
+
case 7: return genSetHtml(oper, context);
|
|
1977
|
+
case 8: return genSetTemplateRef(oper, context);
|
|
1978
|
+
case 9: return genInsertNode(oper, context);
|
|
1979
|
+
case 10: return genPrependNode(oper, context);
|
|
1980
|
+
case 14: return genIf(oper, context);
|
|
1981
|
+
case 15: return genFor(oper, context);
|
|
1982
|
+
case 11: return genCreateComponent(oper, context);
|
|
1983
|
+
case 12: return genSlotOutlet(oper, context);
|
|
1984
|
+
case 13: return genBuiltinDirective(oper, context);
|
|
1985
|
+
case 16: return genGetTextChild(oper, context);
|
|
1986
|
+
case 17: return [];
|
|
1987
|
+
case 18: return [];
|
|
1988
|
+
default:
|
|
1989
|
+
const exhaustiveCheck = oper;
|
|
1990
|
+
throw new Error(`Unhandled operation type in genOperation: ${exhaustiveCheck}`);
|
|
2646
1991
|
}
|
|
2647
1992
|
}
|
|
2648
1993
|
function genEffects(effects, context, genExtraFrag) {
|
|
@@ -2651,35 +1996,28 @@ function genEffects(effects, context, genExtraFrag) {
|
|
|
2651
1996
|
const [frag, push, unshift] = buildCodeFragment();
|
|
2652
1997
|
const shouldDeclare = genExtraFrag === void 0;
|
|
2653
1998
|
let operationsCount = 0;
|
|
2654
|
-
const { ids, frag: declarationFrags, varNames
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
const
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
push(
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
unshift(NEWLINE, `${helper("renderEffect")}(() => `);
|
|
2677
|
-
push(`)`);
|
|
2678
|
-
}
|
|
2679
|
-
if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
|
|
2680
|
-
if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
|
|
2681
|
-
return frag;
|
|
2682
|
-
});
|
|
1999
|
+
const { ids, frag: declarationFrags, varNames } = processExpressions(context, expressions, shouldDeclare);
|
|
2000
|
+
push(...declarationFrags);
|
|
2001
|
+
for (let i = 0; i < effects.length; i++) {
|
|
2002
|
+
const effect = effects[i];
|
|
2003
|
+
operationsCount += effect.operations.length;
|
|
2004
|
+
const frags = context.withId(() => genEffect(effect, context), ids);
|
|
2005
|
+
i > 0 && push(NEWLINE);
|
|
2006
|
+
if (frag[frag.length - 1] === ")" && frags[0] === "(") push(";");
|
|
2007
|
+
push(...frags);
|
|
2008
|
+
}
|
|
2009
|
+
if (frag.filter((frag) => frag === NEWLINE).length > 1 || operationsCount > 1 || declarationFrags.length > 0) {
|
|
2010
|
+
unshift(`{`, INDENT_START, NEWLINE);
|
|
2011
|
+
push(INDENT_END, NEWLINE, "}");
|
|
2012
|
+
if (!effects.length) unshift(NEWLINE);
|
|
2013
|
+
}
|
|
2014
|
+
if (effects.length) {
|
|
2015
|
+
unshift(NEWLINE, `${helper("renderEffect")}(() => `);
|
|
2016
|
+
push(`)`);
|
|
2017
|
+
}
|
|
2018
|
+
if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
|
|
2019
|
+
if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
|
|
2020
|
+
return frag;
|
|
2683
2021
|
}
|
|
2684
2022
|
function genEffect({ operations }, context) {
|
|
2685
2023
|
const [frag, push] = buildCodeFragment();
|
|
@@ -2689,23 +2027,22 @@ function genEffect({ operations }, context) {
|
|
|
2689
2027
|
return frag;
|
|
2690
2028
|
}
|
|
2691
2029
|
function genInsertionState(operation, context) {
|
|
2692
|
-
const { parent, anchor, logicalIndex, append } = operation;
|
|
2693
|
-
return [NEWLINE, ...genCall(context.helper("setInsertionState"), `n${parent}`, anchor == null ? void 0 : anchor === -1 ? `0` : append ? "null" : `n${anchor}`, logicalIndex !== void 0 ? String(logicalIndex) : void 0)];
|
|
2030
|
+
const { parent, anchor, logicalIndex, append, last } = operation;
|
|
2031
|
+
return [NEWLINE, ...genCall(context.helper("setInsertionState"), `n${parent}`, anchor == null ? void 0 : anchor === -1 ? `0` : append ? "null" : `n${anchor}`, logicalIndex !== void 0 ? String(logicalIndex) : void 0, last && "true")];
|
|
2694
2032
|
}
|
|
2033
|
+
|
|
2695
2034
|
//#endregion
|
|
2696
2035
|
//#region packages/compiler-vapor/src/generators/template.ts
|
|
2697
|
-
function genTemplates(templates, context) {
|
|
2036
|
+
function genTemplates(templates, rootIndexes, context) {
|
|
2698
2037
|
const result = [];
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
const
|
|
2702
|
-
|
|
2703
|
-
if (ns) args += `, ${ns}`;
|
|
2704
|
-
result.push(`const ${context.tName(i)} = ${context.helper("template")}(${args})\n`);
|
|
2038
|
+
let i = 0;
|
|
2039
|
+
templates.forEach((ns, template) => {
|
|
2040
|
+
result.push(`const ${context.tName(i)} = ${context.helper("template")}(${JSON.stringify(template).replace(IMPORT_EXPR_RE, `" + $1 + "`)}${rootIndexes.has(i) ? ", true" : ns ? ", false" : ""}${ns ? `, ${ns}` : ""})\n`);
|
|
2041
|
+
i++;
|
|
2705
2042
|
});
|
|
2706
2043
|
return result.join("");
|
|
2707
2044
|
}
|
|
2708
|
-
function genSelf(dynamic, context
|
|
2045
|
+
function genSelf(dynamic, context) {
|
|
2709
2046
|
const [frag, push] = buildCodeFragment();
|
|
2710
2047
|
const { id, template, operation, hasDynamicChild } = dynamic;
|
|
2711
2048
|
if (id !== void 0 && template !== void 0) {
|
|
@@ -2713,145 +2050,47 @@ function genSelf(dynamic, context, flushBeforeDynamic) {
|
|
|
2713
2050
|
push(...genDirectivesForElement(id, context));
|
|
2714
2051
|
}
|
|
2715
2052
|
if (operation) push(...genOperationWithInsertionState(operation, context));
|
|
2716
|
-
if (hasDynamicChild) push(...genChildren(dynamic, context, push, `n${id}
|
|
2053
|
+
if (hasDynamicChild) push(...genChildren(dynamic, context, push, `n${id}`));
|
|
2717
2054
|
return frag;
|
|
2718
2055
|
}
|
|
2719
|
-
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}
|
|
2056
|
+
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`) {
|
|
2057
|
+
const { helper } = context;
|
|
2720
2058
|
const [frag, push] = buildCodeFragment();
|
|
2721
2059
|
const { children } = dynamic;
|
|
2722
2060
|
let offset = 0;
|
|
2723
|
-
/**
|
|
2724
|
-
* `reusable` means the previous access target is a p* cursor that can be
|
|
2725
|
-
* reassigned by the next lookup. Referenced n* variables must stay stable.
|
|
2726
|
-
*/
|
|
2727
2061
|
let prev;
|
|
2728
2062
|
for (const [index, child] of children.entries()) {
|
|
2729
2063
|
if (child.flags & 2) offset--;
|
|
2730
2064
|
if (child.flags & 4 && child.template != null) {
|
|
2731
|
-
|
|
2732
|
-
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2065
|
+
push(...genSelf(child, context));
|
|
2733
2066
|
continue;
|
|
2734
2067
|
}
|
|
2735
2068
|
const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
|
|
2736
2069
|
if (id === void 0 && !child.hasDynamicChild) {
|
|
2737
|
-
|
|
2738
|
-
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2070
|
+
push(...genSelf(child, context));
|
|
2739
2071
|
continue;
|
|
2740
2072
|
}
|
|
2741
2073
|
const elementIndex = index + offset;
|
|
2742
2074
|
const logicalIndex = child.logicalIndex !== void 0 ? String(child.logicalIndex) : void 0;
|
|
2743
|
-
const
|
|
2744
|
-
|
|
2745
|
-
if (
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
], flushBeforeDynamic));
|
|
2754
|
-
prev = [
|
|
2755
|
-
prev[0],
|
|
2756
|
-
elementIndex,
|
|
2757
|
-
true
|
|
2758
|
-
];
|
|
2759
|
-
continue;
|
|
2760
|
-
}
|
|
2761
|
-
if (!hasAdjacentFollowingAccessChild(children, index, elementIndex, offset)) {
|
|
2762
|
-
push(...genChildren(child, context, pushBlock, accessPath, flushBeforeDynamic));
|
|
2763
|
-
continue;
|
|
2764
|
-
}
|
|
2765
|
-
}
|
|
2766
|
-
let variable;
|
|
2767
|
-
if (id === void 0 && prev && prev[2]) {
|
|
2768
|
-
variable = prev[0];
|
|
2769
|
-
pushBlock(NEWLINE, `${variable} = `, ...accessPath);
|
|
2770
|
-
} else {
|
|
2771
|
-
variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
|
|
2772
|
-
pushBlock(NEWLINE, id === void 0 ? `let ${variable} = ` : `const ${variable} = `, ...accessPath);
|
|
2773
|
-
}
|
|
2774
|
-
if (id === child.anchor && !child.hasDynamicChild) {
|
|
2775
|
-
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
2776
|
-
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2075
|
+
const variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
|
|
2076
|
+
pushBlock(NEWLINE, `const ${variable} = `);
|
|
2077
|
+
if (prev) if (elementIndex - prev[1] === 1) pushBlock(...genCall(helper("next"), prev[0], logicalIndex));
|
|
2078
|
+
else pushBlock(...genCall(helper("nthChild"), from, String(elementIndex), logicalIndex));
|
|
2079
|
+
else if (elementIndex === 0) pushBlock(...genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0));
|
|
2080
|
+
else {
|
|
2081
|
+
let init = genCall(helper("child"), from);
|
|
2082
|
+
if (elementIndex === 1) init = genCall(helper("next"), init, logicalIndex);
|
|
2083
|
+
else if (elementIndex > 1) init = genCall(helper("nthChild"), from, String(elementIndex), logicalIndex);
|
|
2084
|
+
pushBlock(...init);
|
|
2777
2085
|
}
|
|
2086
|
+
if (id === child.anchor && !child.hasDynamicChild) push(...genSelf(child, context));
|
|
2778
2087
|
if (id !== void 0) push(...genDirectivesForElement(id, context));
|
|
2779
|
-
prev = [
|
|
2780
|
-
|
|
2781
|
-
elementIndex,
|
|
2782
|
-
id === void 0
|
|
2783
|
-
];
|
|
2784
|
-
push(...genChildren(child, context, pushBlock, variable, flushBeforeDynamic));
|
|
2088
|
+
prev = [variable, elementIndex];
|
|
2089
|
+
push(...genChildren(child, context, pushBlock, variable));
|
|
2785
2090
|
}
|
|
2786
2091
|
return frag;
|
|
2787
2092
|
}
|
|
2788
|
-
|
|
2789
|
-
* Build one DOM lookup path while preserving the fast sibling walk:
|
|
2790
|
-
* adjacent nodes use _next(prev), otherwise fall back to _nthChild(parent).
|
|
2791
|
-
*/
|
|
2792
|
-
function genAccessPath({ helper }, from, child, elementIndex, logicalIndex, prev) {
|
|
2793
|
-
if (prev) return elementIndex - prev[1] === 1 ? genCall(helper("next"), prev[0], logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
2794
|
-
if (elementIndex === 0) return genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0);
|
|
2795
|
-
const firstChild = genCall(helper("child"), from);
|
|
2796
|
-
return elementIndex === 1 ? genCall(helper("next"), firstChild, logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
2797
|
-
}
|
|
2798
|
-
/**
|
|
2799
|
-
* Only inline a placeholder when materializing it would not save a parent
|
|
2800
|
-
* lookup. If its child tree needs the parent more than once, keep p* so the
|
|
2801
|
-
* generated code does not duplicate _child/_nthChild work.
|
|
2802
|
-
*/
|
|
2803
|
-
function canInlinePlaceholder(dynamic) {
|
|
2804
|
-
return dynamic.hasDynamicChild === true && countParentAccessUsages(dynamic) === 1;
|
|
2805
|
-
}
|
|
2806
|
-
/**
|
|
2807
|
-
* A following access can reuse the current placeholder cursor only when it is
|
|
2808
|
-
* the next DOM sibling. Gapped siblings need _nthChild(parent, index) instead.
|
|
2809
|
-
*/
|
|
2810
|
-
function hasAdjacentFollowingAccessChild(children, index, elementIndex, offset) {
|
|
2811
|
-
let futureOffset = offset;
|
|
2812
|
-
for (let i = index + 1; i < children.length; i++) {
|
|
2813
|
-
const child = children[i];
|
|
2814
|
-
if (child.flags & 2) futureOffset--;
|
|
2815
|
-
if (!(child.flags & 4 && child.template != null) && (!!(child.flags & 1) || child.hasDynamicChild)) return i + futureOffset - elementIndex === 1;
|
|
2816
|
-
}
|
|
2817
|
-
return false;
|
|
2818
|
-
}
|
|
2819
|
-
/**
|
|
2820
|
-
* Mirrors genChildren's traversal closely enough to count how many emitted
|
|
2821
|
-
* access paths would start from this placeholder's parent. This is the guard
|
|
2822
|
-
* that keeps inline placeholders from duplicating parent lookups.
|
|
2823
|
-
*/
|
|
2824
|
-
function countParentAccessUsages(dynamic) {
|
|
2825
|
-
let usages = 0;
|
|
2826
|
-
let offset = 0;
|
|
2827
|
-
let prev;
|
|
2828
|
-
for (const [index, child] of dynamic.children.entries()) {
|
|
2829
|
-
if (child.flags & 2) offset--;
|
|
2830
|
-
if (child.flags & 4 && child.template != null) continue;
|
|
2831
|
-
const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
|
|
2832
|
-
if (id === void 0 && !child.hasDynamicChild) continue;
|
|
2833
|
-
const elementIndex = index + offset;
|
|
2834
|
-
const usesParent = !prev || elementIndex - prev[0] !== 1;
|
|
2835
|
-
if (id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6)) {
|
|
2836
|
-
if (prev && prev[1]) {
|
|
2837
|
-
if (usesParent) usages++;
|
|
2838
|
-
prev = [elementIndex, true];
|
|
2839
|
-
continue;
|
|
2840
|
-
}
|
|
2841
|
-
if (!hasAdjacentFollowingAccessChild(dynamic.children, index, elementIndex, offset)) {
|
|
2842
|
-
if (usesParent) usages++;
|
|
2843
|
-
continue;
|
|
2844
|
-
}
|
|
2845
|
-
}
|
|
2846
|
-
if (usesParent) usages++;
|
|
2847
|
-
prev = [elementIndex, id === void 0];
|
|
2848
|
-
}
|
|
2849
|
-
return usages;
|
|
2850
|
-
}
|
|
2851
|
-
function genNthChild(nthChild, from, elementIndex, logicalIndex) {
|
|
2852
|
-
const index = String(elementIndex);
|
|
2853
|
-
return genCall(nthChild, from, index, logicalIndex === index ? void 0 : logicalIndex);
|
|
2854
|
-
}
|
|
2093
|
+
|
|
2855
2094
|
//#endregion
|
|
2856
2095
|
//#region packages/compiler-vapor/src/generators/block.ts
|
|
2857
2096
|
function genBlock(oper, context, args = [], root) {
|
|
@@ -2866,16 +2105,12 @@ function genBlock(oper, context, args = [], root) {
|
|
|
2866
2105
|
"}"
|
|
2867
2106
|
];
|
|
2868
2107
|
}
|
|
2869
|
-
function genBlockContent(block, context, root, genEffectsExtraFrag
|
|
2108
|
+
function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
2870
2109
|
const [frag, push] = buildCodeFragment();
|
|
2871
2110
|
const { dynamic, effect, operation, returns } = block;
|
|
2872
2111
|
const resetBlock = context.enterBlock(block);
|
|
2873
|
-
const singleUseAssetComponentNames = root ? collectSingleUseAssetComponents(block) : void 0;
|
|
2874
|
-
const prevSingleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
2875
|
-
if (singleUseAssetComponentNames) context.singleUseAssetComponentNames = singleUseAssetComponentNames;
|
|
2876
2112
|
if (root) {
|
|
2877
2113
|
for (let name of context.ir.component) {
|
|
2878
|
-
if (singleUseAssetComponentNames && singleUseAssetComponentNames.has(name)) continue;
|
|
2879
2114
|
const id = (0, _vue_compiler_dom.toValidAssetId)(name, "component");
|
|
2880
2115
|
const maybeSelfReference = name.endsWith("__self");
|
|
2881
2116
|
if (maybeSelfReference) name = name.slice(0, -6);
|
|
@@ -2883,167 +2118,25 @@ function genBlockContent(block, context, root, genEffectsExtraFrag, skippedEffec
|
|
|
2883
2118
|
}
|
|
2884
2119
|
genResolveAssets("directive", "resolveDirective");
|
|
2885
2120
|
}
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
operationIndex++;
|
|
2892
|
-
}
|
|
2893
|
-
if (effectIndex < effectEnd) {
|
|
2894
|
-
push(...genEffectRange(effectIndex, effectEnd));
|
|
2895
|
-
effectIndex = effectEnd;
|
|
2896
|
-
}
|
|
2897
|
-
};
|
|
2898
|
-
const flushBeforeDynamic = (dynamic, push) => {
|
|
2899
|
-
const operation = dynamic.operation;
|
|
2900
|
-
if (operation && isBlockOperation(operation) && operation.operationIndex !== void 0 && operation.effectIndex !== void 0) flushPendingOperations(operation.operationIndex, operation.effectIndex, push);
|
|
2901
|
-
};
|
|
2902
|
-
for (const child of dynamic.children) {
|
|
2903
|
-
flushBeforeDynamic(child, push);
|
|
2904
|
-
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2905
|
-
}
|
|
2906
|
-
for (const child of dynamic.children) if (!child.hasDynamicChild) push(...genChildren(child, context, push, `n${child.id}`, flushBeforeDynamic));
|
|
2907
|
-
if (operationIndex < operation.length) push(...genOperations(operation.slice(operationIndex), context));
|
|
2908
|
-
if (effectIndex < effect.length) push(...genEffectRange(effectIndex, effect.length, genEffectsExtraFrag));
|
|
2909
|
-
else if (genEffectsExtraFrag) push(...genEffects([], context, genEffectsExtraFrag));
|
|
2121
|
+
for (const child of dynamic.children) push(...genSelf(child, context));
|
|
2122
|
+
for (const child of dynamic.children) if (!child.hasDynamicChild) push(...genChildren(child, context, push, `n${child.id}`));
|
|
2123
|
+
push(...genOperations(operation, context));
|
|
2124
|
+
push(...genEffects(effect, context, genEffectsExtraFrag));
|
|
2125
|
+
if (root && context.ir.hasDeferredVShow) push(NEWLINE, `deferredApplyVShows.forEach(fn => fn())`);
|
|
2910
2126
|
push(NEWLINE, `return `);
|
|
2911
2127
|
const returnNodes = returns.map((n) => `n${n}`);
|
|
2912
|
-
push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "
|
|
2128
|
+
push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"]);
|
|
2913
2129
|
resetBlock();
|
|
2914
|
-
context.singleUseAssetComponentNames = prevSingleUseAssetComponentNames;
|
|
2915
2130
|
return frag;
|
|
2916
|
-
function genEffectRange(start, end, genExtraFrag) {
|
|
2917
|
-
if (!skippedEffectIndexes) return genEffects(effect.slice(start, end), context, genExtraFrag);
|
|
2918
|
-
const effects = [];
|
|
2919
|
-
for (let i = start; i < end; i++) if (!skippedEffectIndexes.has(i)) effects.push(effect[i]);
|
|
2920
|
-
if (effects.length || genExtraFrag) return genEffects(effects, context, genExtraFrag);
|
|
2921
|
-
return [];
|
|
2922
|
-
}
|
|
2923
2131
|
function genResolveAssets(kind, helper) {
|
|
2924
2132
|
for (const name of context.ir[kind]) push(NEWLINE, `const ${(0, _vue_compiler_dom.toValidAssetId)(name, kind)} = `, ...genCall(context.helper(helper), JSON.stringify(name)));
|
|
2925
2133
|
}
|
|
2926
2134
|
}
|
|
2927
|
-
|
|
2928
|
-
for (let i = 0; i < block.returns.length; i++) {
|
|
2929
|
-
const child = findReturnedDynamic$1(block, block.returns[i]);
|
|
2930
|
-
const operation = child && child.operation;
|
|
2931
|
-
if (!operation) continue;
|
|
2932
|
-
if (operation.type === 15) markSlotRootIf(operation);
|
|
2933
|
-
else if (operation.type === 16) markSlotRootFor(operation);
|
|
2934
|
-
else if (operation.type === 12) markSlotRootComponent(operation);
|
|
2935
|
-
}
|
|
2936
|
-
}
|
|
2937
|
-
function markSlotRootIf(operation) {
|
|
2938
|
-
if (!operation.once) operation.slotRoot = true;
|
|
2939
|
-
markSlotRootOperations(operation.positive);
|
|
2940
|
-
const negative = operation.negative;
|
|
2941
|
-
if (!negative) return;
|
|
2942
|
-
if (negative.type === 15) markSlotRootIf(negative);
|
|
2943
|
-
else markSlotRootOperations(negative);
|
|
2944
|
-
}
|
|
2945
|
-
function markSlotRootFor(operation) {
|
|
2946
|
-
if (!operation.once) operation.slotRoot = true;
|
|
2947
|
-
markSlotRootOperations(operation.render);
|
|
2948
|
-
}
|
|
2949
|
-
function markSlotRootComponent(operation) {
|
|
2950
|
-
if (!operation.once && operation.dynamic && !operation.dynamic.isStatic) operation.slotRoot = true;
|
|
2951
|
-
}
|
|
2952
|
-
function findReturnedDynamic$1(block, id) {
|
|
2953
|
-
for (let i = 0; i < block.dynamic.children.length; i++) {
|
|
2954
|
-
const child = block.dynamic.children[i];
|
|
2955
|
-
if (child.id === id) return child;
|
|
2956
|
-
}
|
|
2957
|
-
}
|
|
2958
|
-
function collectSingleUseAssetComponents(block) {
|
|
2959
|
-
const usageMap = /* @__PURE__ */ new Map();
|
|
2960
|
-
const seenOperations = /* @__PURE__ */ new Set();
|
|
2961
|
-
visitBlock(block, true);
|
|
2962
|
-
const names = /* @__PURE__ */ new Set();
|
|
2963
|
-
for (const [name, usage] of usageMap) if (usage.count === 1 && usage.root) names.add(name);
|
|
2964
|
-
return names;
|
|
2965
|
-
function visitBlock(block, rootCandidate) {
|
|
2966
|
-
visitDynamic(block.dynamic, rootCandidate);
|
|
2967
|
-
for (const operation of block.operation) visitOperation(operation, rootCandidate);
|
|
2968
|
-
for (const effect of block.effect) for (const operation of effect.operations) visitOperation(operation, false);
|
|
2969
|
-
}
|
|
2970
|
-
function visitDynamic(dynamic, rootCandidate) {
|
|
2971
|
-
if (dynamic.operation) visitOperation(dynamic.operation, rootCandidate);
|
|
2972
|
-
for (const child of dynamic.children) visitDynamic(child, rootCandidate);
|
|
2973
|
-
}
|
|
2974
|
-
function visitOperation(operation, rootCandidate) {
|
|
2975
|
-
if (seenOperations.has(operation)) return;
|
|
2976
|
-
seenOperations.add(operation);
|
|
2977
|
-
if (operation.type === 12) {
|
|
2978
|
-
if (operation.asset) {
|
|
2979
|
-
const usage = usageMap.get(operation.tag) || {
|
|
2980
|
-
count: 0,
|
|
2981
|
-
root: false
|
|
2982
|
-
};
|
|
2983
|
-
usage.count++;
|
|
2984
|
-
if (rootCandidate) usage.root = true;
|
|
2985
|
-
usageMap.set(operation.tag, usage);
|
|
2986
|
-
}
|
|
2987
|
-
visitSlots(operation.slots);
|
|
2988
|
-
return;
|
|
2989
|
-
}
|
|
2990
|
-
switch (operation.type) {
|
|
2991
|
-
case 15:
|
|
2992
|
-
visitBlock(operation.positive, false);
|
|
2993
|
-
if (operation.negative) if (operation.negative.type === 15) visitOperation(operation.negative, false);
|
|
2994
|
-
else visitBlock(operation.negative, false);
|
|
2995
|
-
break;
|
|
2996
|
-
case 16:
|
|
2997
|
-
visitBlock(operation.render, false);
|
|
2998
|
-
break;
|
|
2999
|
-
case 17:
|
|
3000
|
-
visitBlock(operation.block, false);
|
|
3001
|
-
break;
|
|
3002
|
-
case 13:
|
|
3003
|
-
if (operation.fallback) visitBlock(operation.fallback, false);
|
|
3004
|
-
break;
|
|
3005
|
-
}
|
|
3006
|
-
}
|
|
3007
|
-
function visitSlots(slots) {
|
|
3008
|
-
for (const slot of slots) switch (slot.slotType) {
|
|
3009
|
-
case 0:
|
|
3010
|
-
for (const name in slot.slots) visitBlock(slot.slots[name], false);
|
|
3011
|
-
break;
|
|
3012
|
-
case 1:
|
|
3013
|
-
case 2:
|
|
3014
|
-
visitBlock(slot.fn, false);
|
|
3015
|
-
break;
|
|
3016
|
-
case 3:
|
|
3017
|
-
visitSlots([slot.positive]);
|
|
3018
|
-
if (slot.negative) visitSlots([slot.negative]);
|
|
3019
|
-
break;
|
|
3020
|
-
}
|
|
3021
|
-
}
|
|
3022
|
-
}
|
|
2135
|
+
|
|
3023
2136
|
//#endregion
|
|
3024
2137
|
//#region packages/compiler-vapor/src/generate.ts
|
|
3025
2138
|
const idWithTrailingDigitsRE = /^([A-Za-z_$][\w$]*)(\d+)$/;
|
|
3026
|
-
const helperNameAliases = {
|
|
3027
|
-
withVaporKeys: "withKeys",
|
|
3028
|
-
withVaporModifiers: "withModifiers"
|
|
3029
|
-
};
|
|
3030
2139
|
var CodegenContext = class {
|
|
3031
|
-
withExpressionReplacements(map, fn) {
|
|
3032
|
-
if (map.size === 0) return fn();
|
|
3033
|
-
this.expressionReplacements.unshift(map);
|
|
3034
|
-
try {
|
|
3035
|
-
return fn();
|
|
3036
|
-
} finally {
|
|
3037
|
-
(0, _vue_shared.remove)(this.expressionReplacements, map);
|
|
3038
|
-
}
|
|
3039
|
-
}
|
|
3040
|
-
getExpressionReplacement(node) {
|
|
3041
|
-
for (const map of this.expressionReplacements) {
|
|
3042
|
-
const replacement = map.get(node);
|
|
3043
|
-
if (replacement) return replacement;
|
|
3044
|
-
}
|
|
3045
|
-
return node;
|
|
3046
|
-
}
|
|
3047
2140
|
withId(fn, map) {
|
|
3048
2141
|
const { identifiers } = this;
|
|
3049
2142
|
const ids = Object.keys(map);
|
|
@@ -3060,19 +2153,9 @@ var CodegenContext = class {
|
|
|
3060
2153
|
this.block = block;
|
|
3061
2154
|
return () => this.block = parent;
|
|
3062
2155
|
}
|
|
3063
|
-
enterSlotBlock() {
|
|
3064
|
-
const parent = this.inSlotBlock;
|
|
3065
|
-
this.inSlotBlock = true;
|
|
3066
|
-
return () => this.inSlotBlock = parent;
|
|
3067
|
-
}
|
|
3068
2156
|
enterScope() {
|
|
3069
2157
|
return [this.scopeLevel++, () => this.scopeLevel--];
|
|
3070
2158
|
}
|
|
3071
|
-
isHelperNameAvailable(name) {
|
|
3072
|
-
if (this.bindingNames.has(name)) return false;
|
|
3073
|
-
for (const alias of this.helpers.values()) if (alias === name) return false;
|
|
3074
|
-
return true;
|
|
3075
|
-
}
|
|
3076
2159
|
initNextIdMap() {
|
|
3077
2160
|
if (this.bindingNames.size === 0) return;
|
|
3078
2161
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -3107,36 +2190,26 @@ var CodegenContext = class {
|
|
|
3107
2190
|
this.ir = ir;
|
|
3108
2191
|
this.bindingNames = /* @__PURE__ */ new Set();
|
|
3109
2192
|
this.helpers = /* @__PURE__ */ new Map();
|
|
3110
|
-
this.needsTemplateRefSetter = false;
|
|
3111
|
-
this.inSlotBlock = false;
|
|
3112
2193
|
this.helper = (name) => {
|
|
3113
2194
|
if (this.helpers.has(name)) return this.helpers.get(name);
|
|
3114
|
-
const base = `_${
|
|
3115
|
-
if (this.
|
|
2195
|
+
const base = `_${name}`;
|
|
2196
|
+
if (this.bindingNames.size === 0 || !this.bindingNames.has(base)) {
|
|
3116
2197
|
this.helpers.set(name, base);
|
|
3117
2198
|
return base;
|
|
3118
2199
|
}
|
|
3119
|
-
const
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
const alias = `${base}${getNextId(map, next)}`;
|
|
3123
|
-
if (this.isHelperNameAvailable(alias)) {
|
|
3124
|
-
this.helpers.set(name, alias);
|
|
3125
|
-
return alias;
|
|
3126
|
-
}
|
|
3127
|
-
next++;
|
|
3128
|
-
}
|
|
2200
|
+
const alias = `${base}${getNextId(this.nextIdMap.get(base), 1)}`;
|
|
2201
|
+
this.helpers.set(name, alias);
|
|
2202
|
+
return alias;
|
|
3129
2203
|
};
|
|
3130
2204
|
this.delegates = /* @__PURE__ */ new Set();
|
|
3131
2205
|
this.identifiers = Object.create(null);
|
|
3132
|
-
this.expressionReplacements = [];
|
|
3133
2206
|
this.seenInlineHandlerNames = Object.create(null);
|
|
3134
2207
|
this.scopeLevel = 0;
|
|
3135
2208
|
this.templateVars = /* @__PURE__ */ new Map();
|
|
3136
2209
|
this.nextIdMap = /* @__PURE__ */ new Map();
|
|
3137
2210
|
this.lastIdMap = /* @__PURE__ */ new Map();
|
|
3138
2211
|
this.lastTIndex = -1;
|
|
3139
|
-
|
|
2212
|
+
this.options = (0, _vue_shared.extend)({
|
|
3140
2213
|
mode: "module",
|
|
3141
2214
|
prefixIdentifiers: true,
|
|
3142
2215
|
sourceMap: false,
|
|
@@ -3151,12 +2224,10 @@ var CodegenContext = class {
|
|
|
3151
2224
|
inline: false,
|
|
3152
2225
|
bindingMetadata: {},
|
|
3153
2226
|
expressionPlugins: []
|
|
3154
|
-
};
|
|
3155
|
-
this.options = (0, _vue_shared.extend)(defaultOptions, options);
|
|
2227
|
+
}, options);
|
|
3156
2228
|
this.block = ir.block;
|
|
3157
2229
|
this.bindingNames = new Set(this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []);
|
|
3158
2230
|
this.initNextIdMap();
|
|
3159
|
-
this.staticTemplateRefHelperCandidate = getStaticTemplateRefHelperCandidate(ir.block);
|
|
3160
2231
|
}
|
|
3161
2232
|
};
|
|
3162
2233
|
function generate(ir, options = {}) {
|
|
@@ -3169,15 +2240,13 @@ function generate(ir, options = {}) {
|
|
|
3169
2240
|
const signature = (options.isTS ? args.map((arg) => `${arg}: any`) : args).join(", ");
|
|
3170
2241
|
if (!inline) push(NEWLINE, `export function ${functionName}(${signature}) {`);
|
|
3171
2242
|
push(INDENT_START);
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
else if (templateRefSetterHelper) context.helpers.delete("createTemplateRefSetter");
|
|
3176
|
-
push(...body);
|
|
2243
|
+
if (ir.hasTemplateRef) push(NEWLINE, `const ${setTemplateRefIdent} = ${context.helper("createTemplateRefSetter")}()`);
|
|
2244
|
+
if (ir.hasDeferredVShow) push(NEWLINE, `const deferredApplyVShows = []`);
|
|
2245
|
+
push(...genBlockContent(ir.block, context, true));
|
|
3177
2246
|
push(INDENT_END, NEWLINE);
|
|
3178
2247
|
if (!inline) push("}");
|
|
3179
2248
|
const delegates = genDelegates(context);
|
|
3180
|
-
const templates = genTemplates(ir.template.
|
|
2249
|
+
const templates = genTemplates(ir.template, ir.rootTemplateIndexes, context);
|
|
3181
2250
|
const preamble = genHelperImports(context) + genAssetImports(context) + templates + delegates;
|
|
3182
2251
|
const newlineCount = [...preamble].filter((c) => c === "\n").length;
|
|
3183
2252
|
if (newlineCount && !inline) frag.unshift(...new Array(newlineCount).fill(LF));
|
|
@@ -3208,100 +2277,93 @@ function genAssetImports({ ir }) {
|
|
|
3208
2277
|
}
|
|
3209
2278
|
return imports;
|
|
3210
2279
|
}
|
|
3211
|
-
|
|
3212
|
-
if (block.operation.length !== 1) return;
|
|
3213
|
-
const operation = block.operation[0];
|
|
3214
|
-
if (operation.type === 9 && !operation.effect && !operation.refFor && operation.value.isStatic) return operation;
|
|
3215
|
-
}
|
|
2280
|
+
|
|
3216
2281
|
//#endregion
|
|
3217
|
-
//#region packages/compiler-vapor/src/transforms/
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
context.options.onError((0, _vue_compiler_dom.createCompilerError)(34, loc));
|
|
3235
|
-
exp = (0, _vue_compiler_dom.createSimpleExpression)("", true, loc);
|
|
2282
|
+
//#region packages/compiler-vapor/src/transforms/transformChildren.ts
|
|
2283
|
+
const transformChildren = (node, context) => {
|
|
2284
|
+
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
2285
|
+
if (!isFragment && node.type !== 1) return;
|
|
2286
|
+
for (const [i, child] of node.children.entries()) {
|
|
2287
|
+
const childContext = context.create(child, i);
|
|
2288
|
+
transformNode(childContext);
|
|
2289
|
+
const childDynamic = childContext.dynamic;
|
|
2290
|
+
if (isFragment) {
|
|
2291
|
+
childContext.reference();
|
|
2292
|
+
childContext.registerTemplate();
|
|
2293
|
+
if (!(childDynamic.flags & 2) || childDynamic.flags & 4) context.block.returns.push(childContext.dynamic.id);
|
|
2294
|
+
} else context.childrenTemplate.push(childContext.template);
|
|
2295
|
+
if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & 2 || childDynamic.flags & 4) context.dynamic.hasDynamicChild = true;
|
|
2296
|
+
childDynamic.type = child.type;
|
|
2297
|
+
if (child.type === 1) childDynamic.tag = child.tag;
|
|
2298
|
+
context.dynamic.children[i] = childDynamic;
|
|
3236
2299
|
}
|
|
3237
|
-
|
|
3238
|
-
const isDom2DataAttr = context.options.platform && arg.isStatic && arg.content.length > 5 && arg.content.startsWith("data-");
|
|
3239
|
-
exp = resolveExpression(exp, isComponent || isDom2DataAttr);
|
|
3240
|
-
arg = resolveExpression(arg);
|
|
3241
|
-
if (arg.isStatic && isReservedProp(arg.content)) return;
|
|
3242
|
-
let camel = false;
|
|
3243
|
-
if (modifiersString.includes("camel")) if (arg.isStatic) arg = (0, _vue_shared.extend)({}, arg, { content: (0, _vue_shared.camelize)(arg.content) });
|
|
3244
|
-
else camel = true;
|
|
3245
|
-
return {
|
|
3246
|
-
key: arg,
|
|
3247
|
-
value: exp,
|
|
3248
|
-
loc,
|
|
3249
|
-
runtimeCamelize: camel,
|
|
3250
|
-
modifier: modifiersString.includes("prop") ? "." : modifiersString.includes("attr") ? "^" : void 0
|
|
3251
|
-
};
|
|
2300
|
+
if (!isFragment) processDynamicChildren(context);
|
|
3252
2301
|
};
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
2302
|
+
function processDynamicChildren(context) {
|
|
2303
|
+
let prevDynamics = [];
|
|
2304
|
+
let staticCount = 0;
|
|
2305
|
+
let dynamicCount = 0;
|
|
2306
|
+
let lastInsertionChild;
|
|
2307
|
+
const children = context.dynamic.children;
|
|
2308
|
+
let logicalIndex = 0;
|
|
2309
|
+
for (const [index, child] of children.entries()) {
|
|
2310
|
+
if (child.flags & 4) {
|
|
2311
|
+
child.logicalIndex = logicalIndex;
|
|
2312
|
+
prevDynamics.push(lastInsertionChild = child);
|
|
2313
|
+
logicalIndex++;
|
|
2314
|
+
}
|
|
2315
|
+
if (!(child.flags & 2)) {
|
|
2316
|
+
child.logicalIndex = logicalIndex;
|
|
2317
|
+
if (prevDynamics.length) {
|
|
2318
|
+
if (staticCount) {
|
|
2319
|
+
context.childrenTemplate[index - prevDynamics.length] = `<!>`;
|
|
2320
|
+
prevDynamics[0].flags -= 2;
|
|
2321
|
+
const anchor = prevDynamics[0].anchor = context.increaseId();
|
|
2322
|
+
registerInsertion(prevDynamics, context, anchor);
|
|
2323
|
+
} else registerInsertion(prevDynamics, context, -1);
|
|
2324
|
+
dynamicCount += prevDynamics.length;
|
|
2325
|
+
prevDynamics = [];
|
|
2326
|
+
}
|
|
2327
|
+
staticCount++;
|
|
2328
|
+
logicalIndex++;
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
if (prevDynamics.length) registerInsertion(prevDynamics, context, dynamicCount + staticCount, true);
|
|
2332
|
+
if (lastInsertionChild && lastInsertionChild.operation) lastInsertionChild.operation.last = true;
|
|
3262
2333
|
}
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
2334
|
+
function registerInsertion(dynamics, context, anchor, append) {
|
|
2335
|
+
for (const child of dynamics) {
|
|
2336
|
+
const logicalIndex = child.logicalIndex;
|
|
2337
|
+
if (child.template != null) context.registerOperation({
|
|
2338
|
+
type: 9,
|
|
2339
|
+
node: context.node,
|
|
2340
|
+
elements: dynamics.map((child) => child.id),
|
|
2341
|
+
parent: context.reference(),
|
|
2342
|
+
anchor: append ? void 0 : anchor
|
|
2343
|
+
});
|
|
2344
|
+
else if (child.operation && isBlockOperation(child.operation)) {
|
|
2345
|
+
child.operation.parent = context.reference();
|
|
2346
|
+
child.operation.anchor = anchor;
|
|
2347
|
+
child.operation.logicalIndex = logicalIndex;
|
|
2348
|
+
child.operation.append = append;
|
|
2349
|
+
}
|
|
3268
2350
|
}
|
|
3269
|
-
ignoreVHtmlChildren(node, context, "template");
|
|
3270
|
-
context.registerEffect([exp], {
|
|
3271
|
-
type: 8,
|
|
3272
|
-
node,
|
|
3273
|
-
element: context.reference(),
|
|
3274
|
-
value: exp,
|
|
3275
|
-
isComponent: node.tagType === 1
|
|
3276
|
-
});
|
|
3277
|
-
};
|
|
3278
|
-
//#endregion
|
|
3279
|
-
//#region packages/compiler-vapor/src/errors.ts
|
|
3280
|
-
function createVaporCompilerError(code, loc) {
|
|
3281
|
-
return (0, _vue_compiler_dom.createCompilerError)(code, loc, VaporErrorMessages);
|
|
3282
2351
|
}
|
|
3283
|
-
|
|
3284
|
-
"X_V_PLACEHOLDER": 100,
|
|
3285
|
-
"100": "X_V_PLACEHOLDER",
|
|
3286
|
-
"X_DYNAMIC_FLATTEN_NOT_SUPPORTED": 101,
|
|
3287
|
-
"101": "X_DYNAMIC_FLATTEN_NOT_SUPPORTED",
|
|
3288
|
-
"__EXTEND_POINT__": 102,
|
|
3289
|
-
"102": "__EXTEND_POINT__"
|
|
3290
|
-
};
|
|
3291
|
-
const VaporErrorMessages = {
|
|
3292
|
-
[100]: `[placeholder]`,
|
|
3293
|
-
[101]: "The value of flatten attribute must be a static boolean value.",
|
|
3294
|
-
[102]: ``
|
|
3295
|
-
};
|
|
2352
|
+
|
|
3296
2353
|
//#endregion
|
|
3297
|
-
//#region packages/compiler-vapor/src/transforms/
|
|
2354
|
+
//#region packages/compiler-vapor/src/transforms/vOnce.ts
|
|
2355
|
+
const transformVOnce = (node, context) => {
|
|
2356
|
+
if (node.type === 1 && (0, _vue_compiler_dom.findDir)(node, "once", true)) context.inVOnce = true;
|
|
2357
|
+
};
|
|
2358
|
+
|
|
2359
|
+
//#endregion
|
|
2360
|
+
//#region packages/compiler-vapor/src/transforms/transformElement.ts
|
|
3298
2361
|
const isReservedProp = /* @__PURE__ */ (0, _vue_shared.makeMap)(",key,ref,ref_for,ref_key,");
|
|
3299
2362
|
const transformElement = (node, context) => {
|
|
3300
2363
|
let effectIndex = context.block.effect.length;
|
|
3301
2364
|
const getEffectIndex = () => effectIndex++;
|
|
3302
2365
|
let operationIndex = context.block.operation.length;
|
|
3303
2366
|
const getOperationIndex = () => operationIndex++;
|
|
3304
|
-
if (node.type === 1 && node.children.length) ignoreVHtmlChildren(node, context, "node");
|
|
3305
2367
|
let parentSlots;
|
|
3306
2368
|
if (node.type === 1 && (node.tagType === 1 || context.options.isCustomElement(node.tag))) {
|
|
3307
2369
|
parentSlots = context.slots;
|
|
@@ -3310,14 +2372,13 @@ const transformElement = (node, context) => {
|
|
|
3310
2372
|
return function postTransformElement() {
|
|
3311
2373
|
({node} = context);
|
|
3312
2374
|
if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) return;
|
|
3313
|
-
const
|
|
3314
|
-
const isComponent = node.tagType === 1 ||
|
|
2375
|
+
const isCustomElement = !!context.options.isCustomElement(node.tag);
|
|
2376
|
+
const isComponent = node.tagType === 1 || isCustomElement;
|
|
3315
2377
|
const isDynamicComponent = isComponentTag(node.tag);
|
|
3316
|
-
const staticKey = resolveStaticKey(node, context, isComponent);
|
|
3317
2378
|
const propsResult = buildProps(node, context, isComponent, isDynamicComponent, getEffectIndex);
|
|
3318
|
-
const singleRoot = context
|
|
3319
|
-
if (isComponent) transformComponentElement(node, propsResult,
|
|
3320
|
-
else transformNativeElement(node, propsResult,
|
|
2379
|
+
const singleRoot = isSingleRoot(context);
|
|
2380
|
+
if (isComponent) transformComponentElement(node, propsResult, singleRoot, context, isDynamicComponent, isCustomElement);
|
|
2381
|
+
else transformNativeElement(node, propsResult, singleRoot, context, getEffectIndex, context.root === context.effectiveParent || canOmitEndTag(node, context), getOperationIndex);
|
|
3321
2382
|
if (parentSlots) context.slots = parentSlots;
|
|
3322
2383
|
};
|
|
3323
2384
|
};
|
|
@@ -3325,40 +2386,26 @@ function canOmitEndTag(node, context) {
|
|
|
3325
2386
|
const { block, parent } = context;
|
|
3326
2387
|
if (!parent) return false;
|
|
3327
2388
|
if (block !== parent.block) return true;
|
|
3328
|
-
if (context.templateCloseTags && (context.templateCloseTags.has(node.tag) || (0, _vue_shared.isAlwaysCloseTag)(node.tag) || (0, _vue_shared.isFormattingTag)(node.tag)) || context.templateCloseBlocks && (0, _vue_shared.isBlockTag)(node.tag)) return false;
|
|
3329
2389
|
if ((0, _vue_shared.isAlwaysCloseTag)(node.tag) && !context.isOnRightmostPath) return false;
|
|
3330
2390
|
if ((0, _vue_shared.isFormattingTag)(node.tag) || parent.node.type === 1 && node.tag === parent.node.tag) return context.isOnRightmostPath;
|
|
2391
|
+
if ((0, _vue_shared.isBlockTag)(node.tag) && context.hasInlineAncestorNeedingClose) return false;
|
|
3331
2392
|
return context.isLastEffectiveChild;
|
|
3332
2393
|
}
|
|
3333
|
-
function
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
} : void 0;
|
|
3343
|
-
const tags = new Set(inheritedTags);
|
|
3344
|
-
tags.add(node.tag);
|
|
3345
|
-
return {
|
|
3346
|
-
tags,
|
|
3347
|
-
blocks: inheritedBlocks || (0, _vue_shared.isInlineTag)(node.tag)
|
|
3348
|
-
};
|
|
3349
|
-
}
|
|
3350
|
-
function isInSameTemplateAsParent(context) {
|
|
3351
|
-
const { parent, node, block } = context;
|
|
3352
|
-
if (!parent || block !== parent.block) return false;
|
|
3353
|
-
const parentNode = parent.node;
|
|
3354
|
-
if (parentNode.type !== 1 || parentNode.tagType !== 0) return false;
|
|
3355
|
-
return !shouldUseCreateElement(parentNode, parent) && (0, _vue_compiler_dom.isValidHTMLNesting)(parentNode.tag, node.tag);
|
|
2394
|
+
function isSingleRoot(context) {
|
|
2395
|
+
if (context.inVFor) return false;
|
|
2396
|
+
let { parent } = context;
|
|
2397
|
+
if (parent && !((0, _vue_compiler_dom.hasSingleChild)(parent.node) || (0, _vue_compiler_dom.isSingleIfBlock)(parent.node))) return false;
|
|
2398
|
+
while (parent && parent.parent && parent.node.type === 1 && parent.node.tagType === 3) {
|
|
2399
|
+
parent = parent.parent;
|
|
2400
|
+
if (!((0, _vue_compiler_dom.hasSingleChild)(parent.node) || (0, _vue_compiler_dom.isSingleIfBlock)(parent.node))) return false;
|
|
2401
|
+
}
|
|
2402
|
+
return context.root === parent;
|
|
3356
2403
|
}
|
|
3357
|
-
function transformComponentElement(node, propsResult,
|
|
2404
|
+
function transformComponentElement(node, propsResult, singleRoot, context, isDynamicComponent, isCustomElement) {
|
|
3358
2405
|
const dynamicComponent = isDynamicComponent ? resolveDynamicComponent(node) : void 0;
|
|
3359
2406
|
let { tag } = node;
|
|
3360
2407
|
let asset = true;
|
|
3361
|
-
if (!dynamicComponent && !
|
|
2408
|
+
if (!dynamicComponent && !isCustomElement) {
|
|
3362
2409
|
const { isEasyComponent } = context.options;
|
|
3363
2410
|
const isEasyCom = isEasyComponent && isEasyComponent(tag);
|
|
3364
2411
|
if (!isEasyCom) {
|
|
@@ -3387,13 +2434,10 @@ function transformComponentElement(node, propsResult, staticKey, singleRoot, con
|
|
|
3387
2434
|
}
|
|
3388
2435
|
}
|
|
3389
2436
|
context.dynamic.flags |= 6;
|
|
3390
|
-
const id = context.reference();
|
|
3391
|
-
const flatten = extractElementFlatten(node, propsResult, context);
|
|
3392
2437
|
context.dynamic.operation = {
|
|
3393
|
-
type:
|
|
2438
|
+
type: 11,
|
|
3394
2439
|
node,
|
|
3395
|
-
id,
|
|
3396
|
-
...context.effectBoundary(),
|
|
2440
|
+
id: context.reference(),
|
|
3397
2441
|
tag,
|
|
3398
2442
|
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
|
|
3399
2443
|
asset,
|
|
@@ -3401,38 +2445,10 @@ function transformComponentElement(node, propsResult, staticKey, singleRoot, con
|
|
|
3401
2445
|
slots: [...context.slots],
|
|
3402
2446
|
once: context.inVOnce,
|
|
3403
2447
|
dynamic: dynamicComponent,
|
|
3404
|
-
|
|
3405
|
-
flatten
|
|
2448
|
+
isCustomElement
|
|
3406
2449
|
};
|
|
3407
|
-
if (staticKey) context.registerOperation(createSetBlockKey(id, staticKey, node));
|
|
3408
2450
|
context.slots = [];
|
|
3409
2451
|
}
|
|
3410
|
-
function extractElementFlatten(node, propsResult, context) {
|
|
3411
|
-
if (!context.options.platform) return;
|
|
3412
|
-
const flatten = extractStaticBooleanProp(propsResult, "flatten", (loc) => {
|
|
3413
|
-
context.options.onError(createVaporCompilerError(101, loc));
|
|
3414
|
-
});
|
|
3415
|
-
if (flatten != null) node.flatten = flatten;
|
|
3416
|
-
return flatten;
|
|
3417
|
-
}
|
|
3418
|
-
function extractStaticBooleanProp(propsResult, name, onInvalid) {
|
|
3419
|
-
const groups = propsResult[0] ? propsResult[1] : [propsResult[1]];
|
|
3420
|
-
for (const props of groups) {
|
|
3421
|
-
if (!Array.isArray(props)) continue;
|
|
3422
|
-
for (let i = 0; i < props.length; i++) {
|
|
3423
|
-
const prop = props[i];
|
|
3424
|
-
if (prop.key.isStatic && prop.key.content === name && !prop.handler && !prop.model) {
|
|
3425
|
-
const value = parseStaticAttrBooleanExpression(prop.values[0]);
|
|
3426
|
-
props.splice(i, 1);
|
|
3427
|
-
if (value == null) {
|
|
3428
|
-
onInvalid && onInvalid(prop.values[0].loc);
|
|
3429
|
-
return;
|
|
3430
|
-
}
|
|
3431
|
-
return value;
|
|
3432
|
-
}
|
|
3433
|
-
}
|
|
3434
|
-
}
|
|
3435
|
-
}
|
|
3436
2452
|
function resolveDynamicComponent(node) {
|
|
3437
2453
|
const isProp = findProp$1(node, "is", false, true);
|
|
3438
2454
|
if (!isProp) return;
|
|
@@ -3448,42 +2464,29 @@ function resolveSetupReference(name, context) {
|
|
|
3448
2464
|
}
|
|
3449
2465
|
const dynamicKeys = ["indeterminate"];
|
|
3450
2466
|
const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
|
|
3451
|
-
|
|
3452
|
-
function isDataProp(prop) {
|
|
3453
|
-
const name = prop.key.content;
|
|
3454
|
-
return prop.key.isStatic && name.length > 5 && name.startsWith("data-");
|
|
3455
|
-
}
|
|
3456
|
-
function transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, omitEndTag, getOperationIndex) {
|
|
2467
|
+
function transformNativeElement(node, propsResult, singleRoot, context, getEffectIndex, omitEndTag, getOperationIndex) {
|
|
3457
2468
|
const isDom2 = !!context.options.platform;
|
|
3458
2469
|
if (isDom2) omitEndTag = false;
|
|
3459
|
-
if (isDom2) extractElementFlatten(node, propsResult, context);
|
|
3460
2470
|
const { tag } = node;
|
|
3461
2471
|
const { scopeId } = context.options;
|
|
3462
2472
|
let template = "";
|
|
3463
2473
|
template += `<${tag}`;
|
|
3464
2474
|
if (scopeId) template += ` ${scopeId}`;
|
|
3465
|
-
if (isDom2) {
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
if (rootElementTagName) {
|
|
3471
|
-
template += ` custom-tag-name="${rootElementTagName}"`;
|
|
3472
|
-
if (context.options.rootElementFromUniModule) template += ` gen-root-custom-native="${rootElementTagName}"`;
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
|
-
if (node.flatten) template += ` flatten`;
|
|
2475
|
+
if (isDom2 && singleRoot) {
|
|
2476
|
+
template += ` gen-flag-flatten=""`;
|
|
2477
|
+
const rootElementTagName = context.options.rootElementTagName;
|
|
2478
|
+
if (rootElementTagName || context.options.genVueId) template += ` gen-vue-id=""`;
|
|
2479
|
+
if (rootElementTagName) template += ` custom-tag-name="${rootElementTagName}"`;
|
|
3476
2480
|
}
|
|
3477
2481
|
const dynamicProps = [];
|
|
3478
2482
|
if (propsResult[0]) {
|
|
3479
2483
|
const [, dynamicArgs, expressions] = propsResult;
|
|
3480
2484
|
context.registerEffect(expressions, {
|
|
3481
|
-
type:
|
|
2485
|
+
type: 3,
|
|
3482
2486
|
node,
|
|
3483
2487
|
element: context.reference(),
|
|
3484
2488
|
props: dynamicArgs,
|
|
3485
|
-
tag
|
|
3486
|
-
root: singleRoot && context.effectiveParent === context.root && context.options.componentType === "component"
|
|
2489
|
+
tag
|
|
3487
2490
|
}, getEffectIndex);
|
|
3488
2491
|
} else {
|
|
3489
2492
|
const changeProps = [];
|
|
@@ -3495,9 +2498,8 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
3495
2498
|
const props = propsResult[1];
|
|
3496
2499
|
const indicesToRemove = [];
|
|
3497
2500
|
for (let i = 0; i < props.length; i++) {
|
|
3498
|
-
const
|
|
3499
|
-
|
|
3500
|
-
if (isDataProp(prop) || key.content.startsWith("change:") || changeProps.includes(key.content)) continue;
|
|
2501
|
+
const { key, values } = props[i];
|
|
2502
|
+
if (key.content.startsWith("change:") || changeProps.includes(key.content)) continue;
|
|
3501
2503
|
if (key.isStatic && values.length === 1 && !["class", "style"].includes(key.content)) {
|
|
3502
2504
|
let endLoc = values[0].loc;
|
|
3503
2505
|
if (endLoc === _vue_compiler_dom.locStub) endLoc = key.loc;
|
|
@@ -3512,30 +2514,15 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
3512
2514
|
}
|
|
3513
2515
|
let hasStaticStyle = false;
|
|
3514
2516
|
let hasClass = false;
|
|
3515
|
-
const datasetProps = [];
|
|
3516
2517
|
let prevWasQuoted = false;
|
|
3517
|
-
const appendTemplateProp = (key, value = "", generated = false) => {
|
|
3518
|
-
if (!prevWasQuoted) template += ` `;
|
|
3519
|
-
template += key;
|
|
3520
|
-
if (value) {
|
|
3521
|
-
const escapedValue = generated ? escapeGeneratedAttrValue(value) : value.replace(/"/g, """);
|
|
3522
|
-
template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${escapedValue}"` : `=${escapedValue}`;
|
|
3523
|
-
} else prevWasQuoted = false;
|
|
3524
|
-
};
|
|
3525
2518
|
for (const prop of propsResult[1]) {
|
|
3526
2519
|
const { key, values } = prop;
|
|
3527
|
-
const canStringifyAttrName = key.isStatic && !UNSAFE_ATTR_NAME_RE.test(key.content);
|
|
3528
|
-
let foldedValue;
|
|
3529
2520
|
if (isDom2) {
|
|
3530
|
-
if (isDataProp(prop)) {
|
|
3531
|
-
datasetProps.push(prop);
|
|
3532
|
-
continue;
|
|
3533
|
-
}
|
|
3534
2521
|
if (key.content.startsWith("change:")) {
|
|
3535
2522
|
dynamicProps.push(key.content);
|
|
3536
2523
|
values[0].isStatic = false;
|
|
3537
2524
|
context.registerEffect(values, {
|
|
3538
|
-
type:
|
|
2525
|
+
type: 18,
|
|
3539
2526
|
node,
|
|
3540
2527
|
prop
|
|
3541
2528
|
}, getEffectIndex);
|
|
@@ -3543,11 +2530,11 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
3543
2530
|
}
|
|
3544
2531
|
if (key.content === "class") hasClass = true;
|
|
3545
2532
|
}
|
|
3546
|
-
if (
|
|
2533
|
+
if (context.imports.some((imported) => values[0].content.includes(imported.exp.content))) {
|
|
3547
2534
|
if (!prevWasQuoted) template += ` `;
|
|
3548
2535
|
template += `${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
|
|
3549
2536
|
prevWasQuoted = true;
|
|
3550
|
-
} else if (
|
|
2537
|
+
} else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
3551
2538
|
if (isDom2 && key.content === "style") {
|
|
3552
2539
|
hasStaticStyle = true;
|
|
3553
2540
|
const checkStaticStyle = context.options.checkStaticStyle;
|
|
@@ -3559,7 +2546,7 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
3559
2546
|
if (isDom2 && (key.content === "class" || key.content === "hover-class" || key.content === "style" && context.options.disableStaticStyle)) {
|
|
3560
2547
|
dynamicProps.push(key.content);
|
|
3561
2548
|
context.registerEffect(values, {
|
|
3562
|
-
type:
|
|
2549
|
+
type: 2,
|
|
3563
2550
|
node,
|
|
3564
2551
|
element: context.reference(),
|
|
3565
2552
|
prop,
|
|
@@ -3567,178 +2554,33 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
3567
2554
|
}, getEffectIndex, getOperationIndex);
|
|
3568
2555
|
continue;
|
|
3569
2556
|
}
|
|
2557
|
+
if (!prevWasQuoted) template += ` `;
|
|
3570
2558
|
const value = values[0].content === "''" ? "" : values[0].content;
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
} else
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
2559
|
+
template += key.content;
|
|
2560
|
+
if (value) template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${value.replace(/"/g, """)}"` : `=${value}`;
|
|
2561
|
+
else prevWasQuoted = false;
|
|
2562
|
+
} else {
|
|
2563
|
+
dynamicProps.push(key.content);
|
|
2564
|
+
context.registerEffect(values, {
|
|
2565
|
+
type: 2,
|
|
2566
|
+
node,
|
|
2567
|
+
isChangeProp: changeProps.includes(key.content),
|
|
2568
|
+
element: context.reference(),
|
|
2569
|
+
prop,
|
|
2570
|
+
tag
|
|
2571
|
+
}, getEffectIndex);
|
|
2572
|
+
}
|
|
3584
2573
|
}
|
|
3585
2574
|
if (hasStaticStyle && hasClass) template += ` ext:style`;
|
|
3586
|
-
if (datasetProps.length) {
|
|
3587
|
-
const expressions = datasetProps.flatMap((prop) => prop.values);
|
|
3588
|
-
context.registerEffect(expressions, {
|
|
3589
|
-
type: 3,
|
|
3590
|
-
node,
|
|
3591
|
-
element: context.reference(),
|
|
3592
|
-
prop: {
|
|
3593
|
-
...datasetProps[0],
|
|
3594
|
-
datasetProps
|
|
3595
|
-
},
|
|
3596
|
-
tag,
|
|
3597
|
-
root: singleRoot && context.effectiveParent === context.root && context.options.componentType === "component"
|
|
3598
|
-
}, getEffectIndex);
|
|
3599
|
-
}
|
|
3600
2575
|
}
|
|
3601
2576
|
template += `>` + context.childrenTemplate.join("");
|
|
3602
2577
|
if (!(0, _vue_shared.isVoidTag)(tag) && !omitEndTag) template += `</${tag}>`;
|
|
3603
|
-
context.
|
|
2578
|
+
if (singleRoot) context.ir.rootTemplateIndexes.add(context.ir.template.size);
|
|
3604
2579
|
if (context.parent && context.parent.node.type === 1 && !(0, _vue_compiler_dom.isValidHTMLNesting)(context.parent.node.tag, tag)) {
|
|
3605
2580
|
context.reference();
|
|
3606
2581
|
context.dynamic.template = context.pushTemplate(template);
|
|
3607
2582
|
context.dynamic.flags |= 6;
|
|
3608
2583
|
} else context.template += template;
|
|
3609
|
-
if (staticKey) context.registerOperation(createSetBlockKey(context.reference(), staticKey, node));
|
|
3610
|
-
}
|
|
3611
|
-
function escapeGeneratedAttrValue(value) {
|
|
3612
|
-
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
3613
|
-
}
|
|
3614
|
-
function foldBooleanAttrValue(values) {
|
|
3615
|
-
if (values.length !== 1) return;
|
|
3616
|
-
const evaluated = evaluateConstantExpression(values[0]);
|
|
3617
|
-
if (!evaluated) return;
|
|
3618
|
-
const value = evaluated.value;
|
|
3619
|
-
if (value === true || value === false || value == null) return (0, _vue_shared.includeBooleanAttr)(value);
|
|
3620
|
-
}
|
|
3621
|
-
function foldStyleValues(values) {
|
|
3622
|
-
const evaluatedValues = [];
|
|
3623
|
-
for (const value of values) {
|
|
3624
|
-
const evaluated = evaluateConstantExpression(value);
|
|
3625
|
-
if (!evaluated || !isStaticStyleValue(evaluated.value)) return;
|
|
3626
|
-
evaluatedValues.push(evaluated.value);
|
|
3627
|
-
}
|
|
3628
|
-
return (0, _vue_shared.stringifyStyle)((0, _vue_shared.normalizeStyle)(evaluatedValues.length === 1 ? evaluatedValues[0] : evaluatedValues));
|
|
3629
|
-
}
|
|
3630
|
-
function isStaticStyleValue(value) {
|
|
3631
|
-
if (typeof value === "string") return true;
|
|
3632
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
3633
|
-
for (const key in value) {
|
|
3634
|
-
const propValue = value[key];
|
|
3635
|
-
if (!isSafeStylePropertyName(key) || !isSafeStylePropertyValue(propValue)) return false;
|
|
3636
|
-
}
|
|
3637
|
-
return true;
|
|
3638
|
-
}
|
|
3639
|
-
function isSafeStylePropertyName(key) {
|
|
3640
|
-
return !!key && !/[;:]/.test(key);
|
|
3641
|
-
}
|
|
3642
|
-
function isSafeStylePropertyValue(value) {
|
|
3643
|
-
return typeof value === "number" || typeof value === "string" && !value.includes(";");
|
|
3644
|
-
}
|
|
3645
|
-
function hasBoundValue(values) {
|
|
3646
|
-
return values.some((value) => !value.isStatic && value.content !== "''");
|
|
3647
|
-
}
|
|
3648
|
-
function foldClassValues(values) {
|
|
3649
|
-
let templateValue = "";
|
|
3650
|
-
let changed = false;
|
|
3651
|
-
for (const value of values) {
|
|
3652
|
-
const evaluated = evaluateConstantExpression(value);
|
|
3653
|
-
if (evaluated) {
|
|
3654
|
-
const normalized = (0, _vue_shared.normalizeClass)(evaluated.value);
|
|
3655
|
-
if (normalized) templateValue = appendClass(templateValue, normalized);
|
|
3656
|
-
else changed = true;
|
|
3657
|
-
continue;
|
|
3658
|
-
}
|
|
3659
|
-
return;
|
|
3660
|
-
}
|
|
3661
|
-
return changed || templateValue ? templateValue : void 0;
|
|
3662
|
-
}
|
|
3663
|
-
function appendClass(base, value) {
|
|
3664
|
-
return base ? value ? `${base} ${value}` : base : value;
|
|
3665
|
-
}
|
|
3666
|
-
function getObjectPropertyName(prop) {
|
|
3667
|
-
const key = prop.key;
|
|
3668
|
-
if (key.type === "Identifier") return key.name;
|
|
3669
|
-
else if (key.type === "StringLiteral") return key.value;
|
|
3670
|
-
else if (key.type === "NumericLiteral") return String(key.value);
|
|
3671
|
-
}
|
|
3672
|
-
function evaluateConstantExpression(node) {
|
|
3673
|
-
if (node.isStatic) return { value: node.content };
|
|
3674
|
-
const ast = node.ast;
|
|
3675
|
-
if (ast === null) {
|
|
3676
|
-
if (node.content === "true") return { value: true };
|
|
3677
|
-
else if (node.content === "false") return { value: false };
|
|
3678
|
-
else if (node.content === "null") return { value: null };
|
|
3679
|
-
else if (node.content === "undefined") return { value: void 0 };
|
|
3680
|
-
}
|
|
3681
|
-
if (!ast) return;
|
|
3682
|
-
return evaluateConstantAst(ast);
|
|
3683
|
-
}
|
|
3684
|
-
function evaluateConstantAst(node) {
|
|
3685
|
-
switch (node.type) {
|
|
3686
|
-
case "StringLiteral": return { value: node.value };
|
|
3687
|
-
case "NumericLiteral": return { value: node.value };
|
|
3688
|
-
case "BooleanLiteral": return { value: node.value };
|
|
3689
|
-
case "NullLiteral": return { value: null };
|
|
3690
|
-
case "Identifier": return node.name === "undefined" ? { value: void 0 } : void 0;
|
|
3691
|
-
case "UnaryExpression":
|
|
3692
|
-
if (node.operator === "void") return { value: void 0 };
|
|
3693
|
-
else if (node.operator === "-") {
|
|
3694
|
-
const value = evaluateConstantAst(node.argument);
|
|
3695
|
-
return value && typeof value.value === "number" ? { value: -value.value } : void 0;
|
|
3696
|
-
}
|
|
3697
|
-
return;
|
|
3698
|
-
case "TemplateLiteral": return evaluateTemplateLiteral(node);
|
|
3699
|
-
case "ObjectExpression": return evaluateObjectExpression(node);
|
|
3700
|
-
}
|
|
3701
|
-
}
|
|
3702
|
-
function evaluateTemplateLiteral(node) {
|
|
3703
|
-
if (node.type !== "TemplateLiteral") return;
|
|
3704
|
-
let value = "";
|
|
3705
|
-
for (const [index, quasi] of node.quasis.entries()) {
|
|
3706
|
-
value += quasi.value.cooked || "";
|
|
3707
|
-
const expression = node.expressions[index];
|
|
3708
|
-
if (expression) {
|
|
3709
|
-
const evaluated = evaluateConstantAst(expression);
|
|
3710
|
-
if (!evaluated) return;
|
|
3711
|
-
value += evaluated.value;
|
|
3712
|
-
}
|
|
3713
|
-
}
|
|
3714
|
-
return { value };
|
|
3715
|
-
}
|
|
3716
|
-
function evaluateObjectExpression(node) {
|
|
3717
|
-
const value = {};
|
|
3718
|
-
for (const prop of node.properties) {
|
|
3719
|
-
if (prop.type !== "ObjectProperty" || prop.computed) return;
|
|
3720
|
-
const key = getObjectPropertyName(prop);
|
|
3721
|
-
if (key == null) return;
|
|
3722
|
-
const evaluated = evaluateConstantAst(prop.value);
|
|
3723
|
-
if (!evaluated) return;
|
|
3724
|
-
value[key] = evaluated.value;
|
|
3725
|
-
}
|
|
3726
|
-
return { value };
|
|
3727
|
-
}
|
|
3728
|
-
function resolveStaticKey(node, context, isComponent) {
|
|
3729
|
-
const keyProp = findProp$1(node, "key", false, true);
|
|
3730
|
-
if (!keyProp) return;
|
|
3731
|
-
if (keyProp.type === 6) return keyProp.value ? (0, _vue_compiler_dom.createSimpleExpression)(keyProp.value.content, true, keyProp.value.loc) : EMPTY_EXPRESSION;
|
|
3732
|
-
const value = keyProp.exp || normalizeBindShorthand(keyProp.arg, context);
|
|
3733
|
-
if (isStaticExpression(value, context.options.bindingMetadata)) return resolveExpression(value, isComponent);
|
|
3734
|
-
}
|
|
3735
|
-
function createSetBlockKey(element, value, node) {
|
|
3736
|
-
return {
|
|
3737
|
-
type: 2,
|
|
3738
|
-
node,
|
|
3739
|
-
element,
|
|
3740
|
-
value
|
|
3741
|
-
};
|
|
3742
2584
|
}
|
|
3743
2585
|
function buildProps(node, context, isComponent, isDynamicComponent, getEffectIndex) {
|
|
3744
2586
|
const props = node.props;
|
|
@@ -3752,44 +2594,29 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
3752
2594
|
results = [];
|
|
3753
2595
|
}
|
|
3754
2596
|
}
|
|
3755
|
-
function pushStaticObjectLiteralProps(props) {
|
|
3756
|
-
if (dynamicArgs.length) {
|
|
3757
|
-
pushMergeArg();
|
|
3758
|
-
dynamicArgs.push(props);
|
|
3759
|
-
} else results.push(...props.map(toDirectiveResult));
|
|
3760
|
-
}
|
|
3761
2597
|
for (const prop of props) {
|
|
3762
2598
|
if (prop.type === 7 && !prop.arg) {
|
|
3763
2599
|
if (prop.name === "bind") {
|
|
3764
2600
|
if (prop.exp) {
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
dynamicArgs.push({
|
|
3772
|
-
kind: 0,
|
|
3773
|
-
value: prop.exp
|
|
3774
|
-
});
|
|
3775
|
-
}
|
|
2601
|
+
dynamicExpr.push(prop.exp);
|
|
2602
|
+
pushMergeArg();
|
|
2603
|
+
dynamicArgs.push({
|
|
2604
|
+
kind: 0,
|
|
2605
|
+
value: prop.exp
|
|
2606
|
+
});
|
|
3776
2607
|
} else context.options.onError((0, _vue_compiler_dom.createCompilerError)(34, prop.loc));
|
|
3777
2608
|
continue;
|
|
3778
2609
|
} else if (prop.name === "on") {
|
|
3779
2610
|
if (prop.exp) if (isComponent) {
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
value: prop.exp,
|
|
3788
|
-
handler: true
|
|
3789
|
-
});
|
|
3790
|
-
}
|
|
2611
|
+
dynamicExpr.push(prop.exp);
|
|
2612
|
+
pushMergeArg();
|
|
2613
|
+
dynamicArgs.push({
|
|
2614
|
+
kind: 0,
|
|
2615
|
+
value: prop.exp,
|
|
2616
|
+
handler: true
|
|
2617
|
+
});
|
|
3791
2618
|
} else context.registerEffect([prop.exp], {
|
|
3792
|
-
type:
|
|
2619
|
+
type: 6,
|
|
3793
2620
|
node,
|
|
3794
2621
|
element: context.reference(),
|
|
3795
2622
|
event: prop.exp
|
|
@@ -3798,7 +2625,7 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
3798
2625
|
continue;
|
|
3799
2626
|
}
|
|
3800
2627
|
}
|
|
3801
|
-
if (isDynamicComponent &&
|
|
2628
|
+
if (isDynamicComponent && prop.type === 6 && prop.name === "is" || prop.type === 7 && prop.name === "bind" && (0, _vue_compiler_dom.isStaticArgOf)(prop.arg, "is")) continue;
|
|
3802
2629
|
const result = transformProp(prop, node, context);
|
|
3803
2630
|
if (result) {
|
|
3804
2631
|
dynamicExpr.push(result.key, result.value);
|
|
@@ -3818,151 +2645,6 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
3818
2645
|
}
|
|
3819
2646
|
return [false, dedupeProperties(results)];
|
|
3820
2647
|
}
|
|
3821
|
-
function resolveObjectLiteralProps(exp, context, keyTransform, isValidKey) {
|
|
3822
|
-
const ast = exp.ast;
|
|
3823
|
-
if (!ast || ast.type !== "ObjectExpression") return;
|
|
3824
|
-
const props = [];
|
|
3825
|
-
const knownKeys = /* @__PURE__ */ new Set();
|
|
3826
|
-
for (const property of ast.properties) {
|
|
3827
|
-
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
3828
|
-
let key = getObjectPropertyName(property);
|
|
3829
|
-
if (key == null || key === "__proto__") return;
|
|
3830
|
-
if (isValidKey && !isValidKey(key)) return;
|
|
3831
|
-
if (keyTransform) key = keyTransform(key);
|
|
3832
|
-
if (knownKeys.has(key)) return;
|
|
3833
|
-
knownKeys.add(key);
|
|
3834
|
-
props.push({
|
|
3835
|
-
key: (0, _vue_compiler_dom.createSimpleExpression)(key, true),
|
|
3836
|
-
values: [resolveExpression(createObjectBindSubExpression(exp, property.value, context), true)]
|
|
3837
|
-
});
|
|
3838
|
-
}
|
|
3839
|
-
return props;
|
|
3840
|
-
}
|
|
3841
|
-
function resolveComponentObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
3842
|
-
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeObjectLiteralBindKey);
|
|
3843
|
-
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
3844
|
-
return props;
|
|
3845
|
-
}
|
|
3846
|
-
function resolveNativeObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
3847
|
-
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeNativeObjectLiteralBindKey);
|
|
3848
|
-
if (!props || hasNativeObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
3849
|
-
return props;
|
|
3850
|
-
}
|
|
3851
|
-
function resolveComponentObjectLiteralOnProps(exp, context, nodeProps, currentProp) {
|
|
3852
|
-
const props = resolveObjectLiteralProps(exp, context, _vue_shared.toHandlerKey);
|
|
3853
|
-
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
3854
|
-
return props;
|
|
3855
|
-
}
|
|
3856
|
-
function isSafeNativeObjectLiteralBindKey(key) {
|
|
3857
|
-
return key !== "" && !UNSAFE_ATTR_NAME_RE.test(key) && isSafeObjectLiteralBindKey(key) && !(0, _vue_shared.isOn)(key) && key.charCodeAt(0) !== 46 && key.charCodeAt(0) !== 94;
|
|
3858
|
-
}
|
|
3859
|
-
function isSafeObjectLiteralBindKey(key) {
|
|
3860
|
-
return !isReservedProp(key);
|
|
3861
|
-
}
|
|
3862
|
-
function hasComponentObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
3863
|
-
const keys = createComponentConflictKeySet(objectLiteralProps.map((prop) => prop.key.content));
|
|
3864
|
-
for (const prop of props) {
|
|
3865
|
-
if (prop === currentProp) continue;
|
|
3866
|
-
let key;
|
|
3867
|
-
if (prop.type === 6) key = prop.name;
|
|
3868
|
-
else if (prop.name === "bind") {
|
|
3869
|
-
if (!prop.arg) {
|
|
3870
|
-
const bindKeys = getObjectLiteralKeys(prop.exp);
|
|
3871
|
-
if (bindKeys && hasComponentKeyOverlap(keys, bindKeys)) return true;
|
|
3872
|
-
continue;
|
|
3873
|
-
}
|
|
3874
|
-
key = getStaticBindKey(prop);
|
|
3875
|
-
} else if (prop.name === "on") key = getStaticHandlerKey(prop);
|
|
3876
|
-
else if (prop.name === "model") {
|
|
3877
|
-
if (hasComponentModelKey(keys, prop)) return true;
|
|
3878
|
-
}
|
|
3879
|
-
if (key && hasComponentKey(keys, key)) return true;
|
|
3880
|
-
}
|
|
3881
|
-
return false;
|
|
3882
|
-
}
|
|
3883
|
-
function hasComponentModelKey(keys, prop) {
|
|
3884
|
-
const { arg } = prop;
|
|
3885
|
-
if (arg && (arg.type !== 4 || !arg.isStatic)) return true;
|
|
3886
|
-
const key = arg ? arg.content : "modelValue";
|
|
3887
|
-
return hasComponentKey(keys, key) || hasComponentKey(keys, `onUpdate:${(0, _vue_shared.camelize)(key)}`) || prop.modifiers.length > 0 && hasComponentKey(keys, (0, _vue_shared.getModifierPropName)(key));
|
|
3888
|
-
}
|
|
3889
|
-
function hasNativeObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
3890
|
-
const keys = new Set(objectLiteralProps.map((prop) => prop.key.content));
|
|
3891
|
-
for (const prop of props) {
|
|
3892
|
-
if (prop === currentProp) continue;
|
|
3893
|
-
let key;
|
|
3894
|
-
if (prop.type === 6) key = prop.name;
|
|
3895
|
-
else if (prop.name === "bind") {
|
|
3896
|
-
if (!prop.arg) return true;
|
|
3897
|
-
key = getStaticBindKey(prop);
|
|
3898
|
-
if (!key) return true;
|
|
3899
|
-
}
|
|
3900
|
-
if (key && keys.has(key)) return true;
|
|
3901
|
-
}
|
|
3902
|
-
return false;
|
|
3903
|
-
}
|
|
3904
|
-
function getStaticBindKey(prop) {
|
|
3905
|
-
const { arg } = prop;
|
|
3906
|
-
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
3907
|
-
let key = arg.content;
|
|
3908
|
-
if (isReservedProp(key)) return;
|
|
3909
|
-
if (prop.modifiers.some((modifier) => modifier.content === "camel")) key = (0, _vue_shared.camelize)(key);
|
|
3910
|
-
return key;
|
|
3911
|
-
}
|
|
3912
|
-
function getStaticHandlerKey(prop) {
|
|
3913
|
-
const { arg } = prop;
|
|
3914
|
-
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
3915
|
-
let key = arg.content;
|
|
3916
|
-
if (key.startsWith("vue:")) key = `vnode-${key.slice(4)}`;
|
|
3917
|
-
const { nonKeyModifiers, eventOptionModifiers } = (0, _vue_compiler_dom.resolveModifiers)(`on${key}`, prop.modifiers, null, prop.loc);
|
|
3918
|
-
if (key.toLowerCase() === "click") {
|
|
3919
|
-
if (nonKeyModifiers.includes("middle")) key = "mouseup";
|
|
3920
|
-
if (nonKeyModifiers.includes("right")) key = "contextmenu";
|
|
3921
|
-
}
|
|
3922
|
-
key = (0, _vue_shared.toHandlerKey)((0, _vue_shared.camelize)(key));
|
|
3923
|
-
const optionPostfix = eventOptionModifiers.map(_vue_shared.capitalize).join("");
|
|
3924
|
-
if (optionPostfix) key += optionPostfix;
|
|
3925
|
-
return key;
|
|
3926
|
-
}
|
|
3927
|
-
function getObjectLiteralKeys(exp) {
|
|
3928
|
-
const ast = exp && exp.ast;
|
|
3929
|
-
if (!ast || ast.type !== "ObjectExpression") return;
|
|
3930
|
-
const keys = /* @__PURE__ */ new Set();
|
|
3931
|
-
for (const property of ast.properties) {
|
|
3932
|
-
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
3933
|
-
const key = getObjectPropertyName(property);
|
|
3934
|
-
if (key == null) return;
|
|
3935
|
-
keys.add(key);
|
|
3936
|
-
}
|
|
3937
|
-
return keys;
|
|
3938
|
-
}
|
|
3939
|
-
function createComponentConflictKeySet(keys) {
|
|
3940
|
-
const normalized = /* @__PURE__ */ new Set();
|
|
3941
|
-
for (const key of keys) {
|
|
3942
|
-
normalized.add(key);
|
|
3943
|
-
normalized.add((0, _vue_shared.camelize)(key));
|
|
3944
|
-
}
|
|
3945
|
-
return normalized;
|
|
3946
|
-
}
|
|
3947
|
-
function hasComponentKey(keys, key) {
|
|
3948
|
-
return keys.has(key) || keys.has((0, _vue_shared.camelize)(key));
|
|
3949
|
-
}
|
|
3950
|
-
function hasComponentKeyOverlap(left, right) {
|
|
3951
|
-
for (const key of right) if (hasComponentKey(left, key)) return true;
|
|
3952
|
-
return false;
|
|
3953
|
-
}
|
|
3954
|
-
function createObjectBindSubExpression(source, node, context) {
|
|
3955
|
-
const start = node.start == null ? 0 : node.start - 1;
|
|
3956
|
-
const end = node.end == null ? source.content.length : node.end - 1;
|
|
3957
|
-
const content = source.content.slice(start, end);
|
|
3958
|
-
const expression = (0, _vue_compiler_dom.createSimpleExpression)(content, false, {
|
|
3959
|
-
start: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, source.content, start),
|
|
3960
|
-
end: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, source.content, end),
|
|
3961
|
-
source: content
|
|
3962
|
-
});
|
|
3963
|
-
expression.ast = (0, _vue_compiler_dom.isSimpleIdentifier)(content) ? null : (0, _babel_parser.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
3964
|
-
return expression;
|
|
3965
|
-
}
|
|
3966
2648
|
function transformProp(prop, node, context) {
|
|
3967
2649
|
let { name } = prop;
|
|
3968
2650
|
if (prop.type === 6) {
|
|
@@ -3979,7 +2661,7 @@ function transformProp(prop, node, context) {
|
|
|
3979
2661
|
if (fromSetup) name = fromSetup;
|
|
3980
2662
|
else context.directive.add(name);
|
|
3981
2663
|
context.registerOperation({
|
|
3982
|
-
type:
|
|
2664
|
+
type: 13,
|
|
3983
2665
|
node,
|
|
3984
2666
|
element: context.reference(),
|
|
3985
2667
|
dir: prop,
|
|
@@ -4014,284 +2696,60 @@ function resolveDirectiveResult(prop) {
|
|
|
4014
2696
|
values: [prop.value]
|
|
4015
2697
|
});
|
|
4016
2698
|
}
|
|
4017
|
-
function
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
value: prop.values[0]
|
|
4021
|
-
});
|
|
4022
|
-
}
|
|
4023
|
-
function mergePropValues(existing, incoming) {
|
|
4024
|
-
const newValues = incoming.values;
|
|
4025
|
-
existing.values.push(...newValues);
|
|
4026
|
-
}
|
|
4027
|
-
function isComponentTag(tag) {
|
|
4028
|
-
return tag === "component" || tag === "Component";
|
|
4029
|
-
}
|
|
4030
|
-
function shouldUseCreateElement(node, context) {
|
|
4031
|
-
return context.options.isCustomElement(node.tag) || node.tagType === 0 && node.tag === "template";
|
|
4032
|
-
}
|
|
4033
|
-
//#endregion
|
|
4034
|
-
//#region packages/compiler-vapor/src/transforms/transformChildren.ts
|
|
4035
|
-
const transformChildren = (node, context) => {
|
|
4036
|
-
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
4037
|
-
if (!isFragment && node.type !== 1) return;
|
|
4038
|
-
const useCreateElement = node.type === 1 && shouldUseCreateElement(node, context);
|
|
4039
|
-
const childTemplateCloseState = !isFragment && !useCreateElement ? getChildTemplateCloseState(context) : void 0;
|
|
4040
|
-
for (const [i, child] of node.children.entries()) {
|
|
4041
|
-
const childContext = context.create(child, i);
|
|
4042
|
-
const isInSameTemplate = childTemplateCloseState && child.type === 1 && child.tagType === 0 && isInSameTemplateAsParent(childContext);
|
|
4043
|
-
childContext.templateCloseTags = isInSameTemplate ? childTemplateCloseState.tags : void 0;
|
|
4044
|
-
childContext.templateCloseBlocks = isInSameTemplate ? childTemplateCloseState.blocks : false;
|
|
4045
|
-
transformNode(childContext);
|
|
4046
|
-
const childDynamic = childContext.dynamic;
|
|
4047
|
-
if (isFragment) {
|
|
4048
|
-
childContext.reference();
|
|
4049
|
-
childContext.registerTemplate();
|
|
4050
|
-
if (!(childDynamic.flags & 2) || childDynamic.flags & 4) context.block.returns.push(childContext.dynamic.id);
|
|
4051
|
-
} else if (useCreateElement) {
|
|
4052
|
-
if (childContext.template !== "" || childDynamic.template != null || childDynamic.id !== void 0 || childDynamic.operation !== void 0 || childDynamic.hasDynamicChild === true) {
|
|
4053
|
-
childContext.reference();
|
|
4054
|
-
childContext.registerTemplate();
|
|
4055
|
-
childDynamic.flags |= 6;
|
|
4056
|
-
}
|
|
4057
|
-
} else context.childrenTemplate.push(childContext.template);
|
|
4058
|
-
if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & 2 || childDynamic.flags & 4) context.dynamic.hasDynamicChild = true;
|
|
4059
|
-
childDynamic.type = child.type;
|
|
4060
|
-
if (child.type === 1) childDynamic.tag = child.tag;
|
|
4061
|
-
context.dynamic.children[i] = childDynamic;
|
|
4062
|
-
}
|
|
4063
|
-
if (!isFragment) processDynamicChildren(context);
|
|
4064
|
-
};
|
|
4065
|
-
function processDynamicChildren(context) {
|
|
4066
|
-
let prevDynamics = [];
|
|
4067
|
-
let staticCount = 0;
|
|
4068
|
-
const children = context.dynamic.children;
|
|
4069
|
-
let logicalIndex = 0;
|
|
4070
|
-
for (const [index, child] of children.entries()) {
|
|
4071
|
-
if (child.flags & 4) {
|
|
4072
|
-
child.logicalIndex = logicalIndex;
|
|
4073
|
-
prevDynamics.push(child);
|
|
4074
|
-
logicalIndex++;
|
|
4075
|
-
}
|
|
4076
|
-
if (!(child.flags & 2)) {
|
|
4077
|
-
child.logicalIndex = logicalIndex;
|
|
4078
|
-
if (prevDynamics.length) {
|
|
4079
|
-
if (staticCount) {
|
|
4080
|
-
context.childrenTemplate[index - prevDynamics.length] = `<!>`;
|
|
4081
|
-
prevDynamics[0].flags -= 2;
|
|
4082
|
-
const anchor = prevDynamics[0].anchor = context.increaseId();
|
|
4083
|
-
registerInsertion(prevDynamics, context, anchor);
|
|
4084
|
-
} else registerInsertion(prevDynamics, context, -1);
|
|
4085
|
-
prevDynamics = [];
|
|
4086
|
-
}
|
|
4087
|
-
staticCount++;
|
|
4088
|
-
logicalIndex++;
|
|
4089
|
-
}
|
|
4090
|
-
}
|
|
4091
|
-
if (prevDynamics.length) registerInsertion(prevDynamics, context, prevDynamics[0].logicalIndex, true);
|
|
4092
|
-
}
|
|
4093
|
-
function registerInsertion(dynamics, context, anchor, append) {
|
|
4094
|
-
for (const child of dynamics) {
|
|
4095
|
-
const logicalIndex = child.logicalIndex;
|
|
4096
|
-
if (child.template != null) context.registerOperation({
|
|
4097
|
-
type: 10,
|
|
4098
|
-
node: context.node,
|
|
4099
|
-
elements: dynamics.map((child) => child.id),
|
|
4100
|
-
parent: context.reference(),
|
|
4101
|
-
anchor: append ? void 0 : anchor
|
|
4102
|
-
});
|
|
4103
|
-
else if (child.operation && isBlockOperation(child.operation)) {
|
|
4104
|
-
child.operation.parent = context.reference();
|
|
4105
|
-
child.operation.anchor = anchor;
|
|
4106
|
-
child.operation.logicalIndex = logicalIndex;
|
|
4107
|
-
child.operation.append = append;
|
|
4108
|
-
}
|
|
4109
|
-
}
|
|
4110
|
-
}
|
|
4111
|
-
//#endregion
|
|
4112
|
-
//#region packages/compiler-vapor/src/transforms/vOnce.ts
|
|
4113
|
-
const transformVOnce = (node, context) => {
|
|
4114
|
-
if (node.type === 1 && (0, _vue_compiler_dom.findDir)(node, "once", true)) context.inVOnce = true;
|
|
4115
|
-
};
|
|
4116
|
-
//#endregion
|
|
4117
|
-
//#region packages/shared/src/makeMap.ts
|
|
4118
|
-
/**
|
|
4119
|
-
* Make a map and return a function for checking if a key
|
|
4120
|
-
* is in that map.
|
|
4121
|
-
* IMPORTANT: all calls of this function must be prefixed with
|
|
4122
|
-
* \/\*#\_\_PURE\_\_\*\/
|
|
4123
|
-
* So that they can be tree-shaken if necessary.
|
|
4124
|
-
*/
|
|
4125
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
4126
|
-
function makeMap$1(str) {
|
|
4127
|
-
const map = Object.create(null);
|
|
4128
|
-
for (const key of str.split(",")) map[key] = 1;
|
|
4129
|
-
return (val) => val in map;
|
|
4130
|
-
}
|
|
4131
|
-
/**
|
|
4132
|
-
* Compiler only.
|
|
4133
|
-
* Do NOT use in runtime code paths unless behind `__DEV__` flag.
|
|
4134
|
-
*/
|
|
4135
|
-
const isVoidTag = /* @__PURE__ */ makeMap$1("area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr");
|
|
4136
|
-
//#endregion
|
|
4137
|
-
//#region packages/compiler-vapor/src/transforms/transformText.ts
|
|
4138
|
-
const seen = /* @__PURE__ */ new WeakMap();
|
|
4139
|
-
function markNonTemplate(node, context) {
|
|
4140
|
-
let seenNodes = seen.get(context.root);
|
|
4141
|
-
if (!seenNodes) {
|
|
4142
|
-
seenNodes = /* @__PURE__ */ new WeakSet();
|
|
4143
|
-
seen.set(context.root, seenNodes);
|
|
4144
|
-
}
|
|
4145
|
-
seenNodes.add(node);
|
|
4146
|
-
}
|
|
4147
|
-
const transformText = (node, context) => {
|
|
4148
|
-
if (!seen.has(context.root)) seen.set(context.root, /* @__PURE__ */ new WeakSet());
|
|
4149
|
-
if (seen.get(context.root).has(node)) {
|
|
4150
|
-
context.dynamic.flags |= 2;
|
|
4151
|
-
return;
|
|
4152
|
-
}
|
|
4153
|
-
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
4154
|
-
if ((isFragment || node.type === 1 && node.tagType === 0) && node.children.length) {
|
|
4155
|
-
let hasInterp = false;
|
|
4156
|
-
let isAllTextLike = true;
|
|
4157
|
-
for (const c of node.children) if (c.type === 5) hasInterp = true;
|
|
4158
|
-
else if (c.type !== 2) isAllTextLike = false;
|
|
4159
|
-
if (!isFragment && isAllTextLike && hasInterp) {
|
|
4160
|
-
const elementContext = context;
|
|
4161
|
-
if (shouldUseCreateElement(node, elementContext)) processCreateElementTextContainer(node.children, elementContext);
|
|
4162
|
-
else processTextContainer(node.children, elementContext);
|
|
4163
|
-
} else if (hasInterp) for (let i = 0; i < node.children.length; i++) {
|
|
4164
|
-
const c = node.children[i];
|
|
4165
|
-
const prev = node.children[i - 1];
|
|
4166
|
-
if (c.type === 5 && prev && prev.type === 2) markNonTemplate(prev, context);
|
|
4167
|
-
}
|
|
4168
|
-
} else if (node.type === 5) processInterpolation(context);
|
|
4169
|
-
else if (node.type === 2) {
|
|
4170
|
-
var _context$parent;
|
|
4171
|
-
const parent = (_context$parent = context.parent) === null || _context$parent === void 0 ? void 0 : _context$parent.node;
|
|
4172
|
-
if (parent && parent.type === 1 && shouldUseCreateElement(parent, context.parent) && node.content[0] === "<") {
|
|
4173
|
-
materializeLiteralTextNode((0, _vue_compiler_dom.createSimpleExpression)(node.content, true, node.loc), context);
|
|
4174
|
-
return;
|
|
4175
|
-
}
|
|
4176
|
-
const isRootText = !parent || parent.type === 0 || parent.type === 1 && (parent.tagType === 3 || parent.tagType === 1);
|
|
4177
|
-
context.template += isRootText ? node.content : (0, _vue_shared.escapeHtml)(node.content);
|
|
4178
|
-
}
|
|
4179
|
-
};
|
|
4180
|
-
function processInterpolation(context) {
|
|
4181
|
-
const parentNode = context.parent.node;
|
|
4182
|
-
const values = processTextLikeChildren(collectAdjacentText(context), context);
|
|
4183
|
-
if (values.length === 0 && parentNode.type !== 0) return;
|
|
4184
|
-
const literalValues = values.map((v) => getLiteralExpressionValue(v));
|
|
4185
|
-
if (literalValues.every((v) => v != null) && parentNode.type !== 0) {
|
|
4186
|
-
const text = literalValues.join("");
|
|
4187
|
-
if (parentNode.type === 1 && shouldUseCreateElement(parentNode, context.parent) && text[0] === "<") {
|
|
4188
|
-
materializeLiteralTextNode((0, _vue_compiler_dom.createSimpleExpression)(text, true, context.node.loc), context);
|
|
4189
|
-
return;
|
|
4190
|
-
}
|
|
4191
|
-
const isElementChild = parentNode.type === 1 && parentNode.tagType === 0;
|
|
4192
|
-
context.template += isElementChild ? (0, _vue_shared.escapeHtml)(text) : text;
|
|
4193
|
-
return;
|
|
4194
|
-
}
|
|
4195
|
-
const isDom2 = !!context.options.platform;
|
|
4196
|
-
let isTextNode = false;
|
|
4197
|
-
let isInComponentSlot = false;
|
|
4198
|
-
let shouldReuseParentText = false;
|
|
4199
|
-
if (isDom2) {
|
|
4200
|
-
const grandNode = context.parent.parent && context.parent.parent.node;
|
|
4201
|
-
function isComponent(node) {
|
|
4202
|
-
return !!(node && node.type === 1 && node.tagType === 1);
|
|
4203
|
-
}
|
|
4204
|
-
isInComponentSlot = parentNode.type === 1 && (parentNode.tagType === 1 || (0, _vue_compiler_dom.isTemplateNode)(parentNode) && isComponent(grandNode));
|
|
4205
|
-
shouldReuseParentText = !!(!isInComponentSlot && parentNode.loc.source.startsWith("<slot") && parentNode.type === 1 && parentNode.tag === "template" && grandNode && grandNode.tag === "text" && parentNode.children.every((child) => isTextLike(child)));
|
|
4206
|
-
isTextNode = isInComponentSlot || shouldReuseParentText;
|
|
4207
|
-
}
|
|
4208
|
-
context.template += isDom2 ? isTextNode ? TEXT_NODE_PLACEHOLDER : TEXT_PLACEHOLDER : " ";
|
|
4209
|
-
const id = context.reference();
|
|
4210
|
-
if (values.length === 0) return;
|
|
4211
|
-
context.registerEffect(values, {
|
|
4212
|
-
type: 5,
|
|
4213
|
-
node: context.node,
|
|
4214
|
-
element: id,
|
|
4215
|
-
values
|
|
4216
|
-
});
|
|
4217
|
-
}
|
|
4218
|
-
function collectAdjacentText(context) {
|
|
4219
|
-
const children = context.parent.node.children;
|
|
4220
|
-
const nodes = [];
|
|
4221
|
-
const prev = children[context.index - 1];
|
|
4222
|
-
let index = prev && prev.type === 2 ? context.index - 1 : context.index;
|
|
4223
|
-
for (; index < children.length; index++) {
|
|
4224
|
-
const child = children[index];
|
|
4225
|
-
if (!isTextLike(child)) break;
|
|
4226
|
-
nodes.push(child);
|
|
4227
|
-
}
|
|
4228
|
-
return nodes;
|
|
4229
|
-
}
|
|
4230
|
-
function processTextContainer(children, context) {
|
|
4231
|
-
const values = processTextLikeChildren(children, context);
|
|
4232
|
-
const literals = values.map((value) => getLiteralExpressionValue(value));
|
|
4233
|
-
if (literals.every((l) => l != null)) context.childrenTemplate = literals.map((l) => (0, _vue_shared.escapeHtml)(String(l)));
|
|
4234
|
-
else {
|
|
4235
|
-
context.childrenTemplate = [context.options.platform ? TEXT_PLACEHOLDER : " "];
|
|
4236
|
-
context.registerOperation({
|
|
4237
|
-
type: 18,
|
|
4238
|
-
node: context.node,
|
|
4239
|
-
parent: context.reference()
|
|
4240
|
-
});
|
|
4241
|
-
context.registerEffect(values, {
|
|
4242
|
-
type: 5,
|
|
4243
|
-
node: context.node,
|
|
4244
|
-
element: context.reference(),
|
|
4245
|
-
values,
|
|
4246
|
-
generated: true
|
|
4247
|
-
});
|
|
4248
|
-
}
|
|
4249
|
-
}
|
|
4250
|
-
function registerSyntheticTextChild(context, template, values) {
|
|
4251
|
-
const id = context.increaseId();
|
|
4252
|
-
context.dynamic.children[context.node.children.length] = {
|
|
4253
|
-
id,
|
|
4254
|
-
flags: 6,
|
|
4255
|
-
children: [],
|
|
4256
|
-
template: context.pushTemplate(template)
|
|
4257
|
-
};
|
|
4258
|
-
context.dynamic.hasDynamicChild = true;
|
|
4259
|
-
if (values && values.length) context.registerEffect(values, {
|
|
4260
|
-
type: 5,
|
|
4261
|
-
node: context.node,
|
|
4262
|
-
element: id,
|
|
4263
|
-
values
|
|
4264
|
-
});
|
|
4265
|
-
return id;
|
|
4266
|
-
}
|
|
4267
|
-
function processCreateElementTextContainer(children, context) {
|
|
4268
|
-
registerSyntheticTextChild(context, "", processTextLikeChildren(children, context));
|
|
4269
|
-
}
|
|
4270
|
-
function materializeLiteralTextNode(value, context) {
|
|
4271
|
-
const id = context.reference();
|
|
4272
|
-
context.dynamic.flags |= 6;
|
|
4273
|
-
context.dynamic.template = context.pushTemplate("");
|
|
4274
|
-
context.registerEffect([value], {
|
|
4275
|
-
type: 5,
|
|
4276
|
-
node: context.node,
|
|
4277
|
-
element: id,
|
|
4278
|
-
values: [value]
|
|
4279
|
-
});
|
|
4280
|
-
}
|
|
4281
|
-
function processTextLikeChildren(nodes, context) {
|
|
4282
|
-
const exps = [];
|
|
4283
|
-
for (const node of nodes) {
|
|
4284
|
-
let exp;
|
|
4285
|
-
markNonTemplate(node, context);
|
|
4286
|
-
if (node.type === 2) exp = (0, _vue_compiler_dom.createSimpleExpression)(node.content, true, node.loc);
|
|
4287
|
-
else exp = node.content;
|
|
4288
|
-
if (exp.content) exps.push(exp);
|
|
4289
|
-
}
|
|
4290
|
-
return exps;
|
|
2699
|
+
function mergePropValues(existing, incoming) {
|
|
2700
|
+
const newValues = incoming.values;
|
|
2701
|
+
existing.values.push(...newValues);
|
|
4291
2702
|
}
|
|
4292
|
-
function
|
|
4293
|
-
return
|
|
2703
|
+
function isComponentTag(tag) {
|
|
2704
|
+
return tag === "component" || tag === "Component";
|
|
2705
|
+
}
|
|
2706
|
+
|
|
2707
|
+
//#endregion
|
|
2708
|
+
//#region packages/compiler-vapor/src/transforms/vHtml.ts
|
|
2709
|
+
const transformVHtml = (dir, node, context) => {
|
|
2710
|
+
let { exp, loc } = dir;
|
|
2711
|
+
if (!exp) {
|
|
2712
|
+
context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(54, loc));
|
|
2713
|
+
exp = EMPTY_EXPRESSION;
|
|
2714
|
+
}
|
|
2715
|
+
if (node.children.length) {
|
|
2716
|
+
context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(55, loc));
|
|
2717
|
+
context.childrenTemplate.length = 0;
|
|
2718
|
+
}
|
|
2719
|
+
context.registerEffect([exp], {
|
|
2720
|
+
type: 7,
|
|
2721
|
+
node,
|
|
2722
|
+
element: context.reference(),
|
|
2723
|
+
value: exp,
|
|
2724
|
+
isComponent: node.tagType === 1
|
|
2725
|
+
});
|
|
2726
|
+
};
|
|
2727
|
+
|
|
2728
|
+
//#endregion
|
|
2729
|
+
//#region packages/shared/src/makeMap.ts
|
|
2730
|
+
/**
|
|
2731
|
+
* Make a map and return a function for checking if a key
|
|
2732
|
+
* is in that map.
|
|
2733
|
+
* IMPORTANT: all calls of this function must be prefixed with
|
|
2734
|
+
* \/\*#\_\_PURE\_\_\*\/
|
|
2735
|
+
* So that they can be tree-shaken if necessary.
|
|
2736
|
+
*/
|
|
2737
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
2738
|
+
function makeMap$1(str) {
|
|
2739
|
+
const map = Object.create(null);
|
|
2740
|
+
for (const key of str.split(",")) map[key] = 1;
|
|
2741
|
+
return (val) => val in map;
|
|
4294
2742
|
}
|
|
2743
|
+
|
|
2744
|
+
//#endregion
|
|
2745
|
+
//#region packages/shared/src/domTagConfig.ts
|
|
2746
|
+
const VOID_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
|
|
2747
|
+
/**
|
|
2748
|
+
* Compiler only.
|
|
2749
|
+
* Do NOT use in runtime code paths unless behind `__DEV__` flag.
|
|
2750
|
+
*/
|
|
2751
|
+
const isVoidTag = /* @__PURE__ */ makeMap$1(VOID_TAGS);
|
|
2752
|
+
|
|
4295
2753
|
//#endregion
|
|
4296
2754
|
//#region packages/compiler-vapor/src/transforms/vText.ts
|
|
4297
2755
|
const transformVText = (dir, node, context) => {
|
|
@@ -4303,49 +2761,66 @@ const transformVText = (dir, node, context) => {
|
|
|
4303
2761
|
if (node.children.length) {
|
|
4304
2762
|
context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(57, loc));
|
|
4305
2763
|
context.childrenTemplate.length = 0;
|
|
4306
|
-
for (const child of node.children) markNonTemplate(child, context);
|
|
4307
2764
|
}
|
|
4308
2765
|
if (isVoidTag(context.node.tag)) return;
|
|
4309
2766
|
const literal = getLiteralExpressionValue(exp);
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
2767
|
+
if (literal != null) context.childrenTemplate = [String(literal)];
|
|
2768
|
+
else {
|
|
2769
|
+
context.childrenTemplate = [context.options.platform ? TEXT_PLACEHOLDER : " "];
|
|
2770
|
+
const isComponent = node.tagType === 1;
|
|
2771
|
+
if (!isComponent) context.registerOperation({
|
|
2772
|
+
type: 16,
|
|
4315
2773
|
node,
|
|
4316
|
-
elements: [id],
|
|
4317
2774
|
parent: context.reference()
|
|
4318
2775
|
});
|
|
4319
|
-
} else context.childrenTemplate = [String(literal)];
|
|
4320
|
-
else {
|
|
4321
|
-
const isComponent = node.tagType === 1;
|
|
4322
|
-
let id;
|
|
4323
|
-
if (useCreateElement) {
|
|
4324
|
-
id = registerSyntheticTextChild(context, "");
|
|
4325
|
-
context.registerOperation({
|
|
4326
|
-
type: 10,
|
|
4327
|
-
node,
|
|
4328
|
-
elements: [id],
|
|
4329
|
-
parent: context.reference()
|
|
4330
|
-
});
|
|
4331
|
-
} else {
|
|
4332
|
-
context.childrenTemplate = [context.options.platform ? TEXT_PLACEHOLDER : " "];
|
|
4333
|
-
if (!isComponent) context.registerOperation({
|
|
4334
|
-
type: 18,
|
|
4335
|
-
node,
|
|
4336
|
-
parent: context.reference()
|
|
4337
|
-
});
|
|
4338
|
-
}
|
|
4339
2776
|
context.registerEffect([exp], {
|
|
4340
|
-
type:
|
|
2777
|
+
type: 4,
|
|
4341
2778
|
node,
|
|
4342
|
-
element:
|
|
2779
|
+
element: context.reference(),
|
|
4343
2780
|
values: [exp],
|
|
4344
|
-
generated:
|
|
2781
|
+
generated: true,
|
|
4345
2782
|
isComponent
|
|
4346
2783
|
});
|
|
4347
2784
|
}
|
|
4348
2785
|
};
|
|
2786
|
+
|
|
2787
|
+
//#endregion
|
|
2788
|
+
//#region packages/compiler-vapor/src/transforms/vBind.ts
|
|
2789
|
+
function normalizeBindShorthand(arg, context) {
|
|
2790
|
+
if (arg.type !== 4 || !arg.isStatic) {
|
|
2791
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(53, arg.loc));
|
|
2792
|
+
return (0, _vue_compiler_dom.createSimpleExpression)("", true, arg.loc);
|
|
2793
|
+
}
|
|
2794
|
+
const exp = (0, _vue_compiler_dom.createSimpleExpression)((0, _vue_shared.camelize)(arg.content), false, arg.loc);
|
|
2795
|
+
exp.ast = null;
|
|
2796
|
+
return exp;
|
|
2797
|
+
}
|
|
2798
|
+
const transformVBind = (dir, node, context) => {
|
|
2799
|
+
const { loc, modifiers } = dir;
|
|
2800
|
+
let { exp } = dir;
|
|
2801
|
+
let arg = dir.arg;
|
|
2802
|
+
const modifiersString = modifiers.map((s) => s.content);
|
|
2803
|
+
if (!exp) exp = normalizeBindShorthand(arg, context);
|
|
2804
|
+
if (!exp.content.trim()) {
|
|
2805
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(34, loc));
|
|
2806
|
+
exp = (0, _vue_compiler_dom.createSimpleExpression)("", true, loc);
|
|
2807
|
+
}
|
|
2808
|
+
const isComponent = node.tagType === 1;
|
|
2809
|
+
exp = resolveExpression(exp, isComponent);
|
|
2810
|
+
arg = resolveExpression(arg);
|
|
2811
|
+
if (arg.isStatic && isReservedProp(arg.content)) return;
|
|
2812
|
+
let camel = false;
|
|
2813
|
+
if (modifiersString.includes("camel")) if (arg.isStatic) arg = (0, _vue_shared.extend)({}, arg, { content: (0, _vue_shared.camelize)(arg.content) });
|
|
2814
|
+
else camel = true;
|
|
2815
|
+
return {
|
|
2816
|
+
key: arg,
|
|
2817
|
+
value: exp,
|
|
2818
|
+
loc,
|
|
2819
|
+
runtimeCamelize: camel,
|
|
2820
|
+
modifier: modifiersString.includes("prop") ? "." : modifiersString.includes("attr") ? "^" : void 0
|
|
2821
|
+
};
|
|
2822
|
+
};
|
|
2823
|
+
|
|
4349
2824
|
//#endregion
|
|
4350
2825
|
//#region packages/compiler-vapor/src/transforms/vOn.ts
|
|
4351
2826
|
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");
|
|
@@ -4355,16 +2830,18 @@ const transformVOn = (dir, node, context) => {
|
|
|
4355
2830
|
const isSlotOutlet = node.tag === "slot";
|
|
4356
2831
|
if (!exp && !modifiers.length) context.options.onError((0, _vue_compiler_dom.createCompilerError)(35, loc));
|
|
4357
2832
|
arg = resolveExpression(arg);
|
|
4358
|
-
if (arg.isStatic && arg.content.startsWith("vue:")) arg = (0, _vue_shared.extend)({}, arg, { content: `vnode-${arg.content.slice(4)}` });
|
|
4359
2833
|
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = (0, _vue_compiler_dom.resolveModifiers)(arg.isStatic ? `on${arg.content}` : arg, modifiers, null, loc);
|
|
4360
2834
|
let keyOverride;
|
|
4361
2835
|
const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
|
|
2836
|
+
if (nonKeyModifiers.includes("middle")) {
|
|
2837
|
+
if (keyOverride) {}
|
|
2838
|
+
if (isStaticClick) arg = (0, _vue_shared.extend)({}, arg, { content: "mouseup" });
|
|
2839
|
+
else if (!arg.isStatic) keyOverride = ["click", "mouseup"];
|
|
2840
|
+
}
|
|
4362
2841
|
if (nonKeyModifiers.includes("right")) {
|
|
4363
|
-
if (
|
|
4364
|
-
|
|
4365
|
-
if (!isStaticClick && !arg.isStatic) keyOverride = ["click", "mouseup"];
|
|
2842
|
+
if (isStaticClick) arg = (0, _vue_shared.extend)({}, arg, { content: "contextmenu" });
|
|
2843
|
+
else if (!arg.isStatic) keyOverride = ["click", "contextmenu"];
|
|
4366
2844
|
}
|
|
4367
|
-
arg = normalizeStaticEventArg(arg, nonKeyModifiers);
|
|
4368
2845
|
if (keyModifiers.length && (0, _vue_compiler_dom.isStaticExp)(arg) && !(0, _vue_compiler_dom.isKeyboardEvent)(`on${arg.content.toLowerCase()}`)) keyModifiers.length = 0;
|
|
4369
2846
|
if (isComponent || isSlotOutlet) return {
|
|
4370
2847
|
key: arg,
|
|
@@ -4376,9 +2853,9 @@ const transformVOn = (dir, node, context) => {
|
|
|
4376
2853
|
options: eventOptionModifiers
|
|
4377
2854
|
}
|
|
4378
2855
|
};
|
|
4379
|
-
const delegate =
|
|
2856
|
+
const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
|
|
4380
2857
|
const operation = {
|
|
4381
|
-
type:
|
|
2858
|
+
type: 5,
|
|
4382
2859
|
node,
|
|
4383
2860
|
element: context.reference(),
|
|
4384
2861
|
key: arg,
|
|
@@ -4394,23 +2871,7 @@ const transformVOn = (dir, node, context) => {
|
|
|
4394
2871
|
};
|
|
4395
2872
|
context.registerEffect([arg], operation);
|
|
4396
2873
|
};
|
|
4397
|
-
|
|
4398
|
-
if (!arg.isStatic) return arg;
|
|
4399
|
-
let normalized = arg;
|
|
4400
|
-
const isStaticClick = arg.content.toLowerCase() === "click";
|
|
4401
|
-
if (nonKeyModifiers.includes("right") && isStaticClick) normalized = (0, _vue_shared.extend)({}, normalized, { content: "contextmenu" });
|
|
4402
|
-
else if (nonKeyModifiers.includes("middle") && isStaticClick) normalized = (0, _vue_shared.extend)({}, normalized, { content: "mouseup" });
|
|
4403
|
-
return normalized;
|
|
4404
|
-
}
|
|
4405
|
-
function hasStopHandlerForStaticEvent(node, eventName) {
|
|
4406
|
-
return node.props.some((prop) => {
|
|
4407
|
-
if (prop.type !== 7 || prop.name !== "on" || !prop.arg || prop.arg.type !== 4) return false;
|
|
4408
|
-
const arg = resolveExpression(prop.arg);
|
|
4409
|
-
if (!arg.isStatic) return false;
|
|
4410
|
-
const { nonKeyModifiers } = (0, _vue_compiler_dom.resolveModifiers)(`on${arg.content}`, prop.modifiers, null, prop.loc);
|
|
4411
|
-
return nonKeyModifiers.includes("stop") && normalizeStaticEventArg(arg, nonKeyModifiers).content === eventName;
|
|
4412
|
-
});
|
|
4413
|
-
}
|
|
2874
|
+
|
|
4414
2875
|
//#endregion
|
|
4415
2876
|
//#region packages/compiler-vapor/src/transforms/vShow.ts
|
|
4416
2877
|
const transformVShow = (dir, node, context) => {
|
|
@@ -4423,15 +2884,23 @@ const transformVShow = (dir, node, context) => {
|
|
|
4423
2884
|
context.options.onError((0, _vue_compiler_dom.createCompilerError)(36, loc));
|
|
4424
2885
|
return;
|
|
4425
2886
|
}
|
|
2887
|
+
let shouldDeferred = false;
|
|
2888
|
+
const parentNode = context.parent && context.parent.node;
|
|
2889
|
+
if (parentNode && parentNode.type === 1) {
|
|
2890
|
+
shouldDeferred = !!(isTransitionTag(parentNode.tag) && findProp$1(parentNode, "appear", false, true));
|
|
2891
|
+
if (shouldDeferred) context.ir.hasDeferredVShow = true;
|
|
2892
|
+
}
|
|
4426
2893
|
context.registerOperation({
|
|
4427
|
-
type:
|
|
2894
|
+
type: 13,
|
|
4428
2895
|
node,
|
|
4429
2896
|
element: context.reference(),
|
|
4430
2897
|
dir,
|
|
4431
2898
|
name: "show",
|
|
4432
|
-
builtin: true
|
|
2899
|
+
builtin: true,
|
|
2900
|
+
deferred: shouldDeferred
|
|
4433
2901
|
});
|
|
4434
2902
|
};
|
|
2903
|
+
|
|
4435
2904
|
//#endregion
|
|
4436
2905
|
//#region packages/compiler-vapor/src/transforms/transformTemplateRef.ts
|
|
4437
2906
|
const transformTemplateRef = (node, context) => {
|
|
@@ -4446,7 +2915,7 @@ const transformTemplateRef = (node, context) => {
|
|
|
4446
2915
|
const id = context.reference();
|
|
4447
2916
|
const effect = !isConstantExpression(value);
|
|
4448
2917
|
context.registerEffect([value], {
|
|
4449
|
-
type:
|
|
2918
|
+
type: 8,
|
|
4450
2919
|
node,
|
|
4451
2920
|
element: id,
|
|
4452
2921
|
value,
|
|
@@ -4455,6 +2924,114 @@ const transformTemplateRef = (node, context) => {
|
|
|
4455
2924
|
});
|
|
4456
2925
|
};
|
|
4457
2926
|
};
|
|
2927
|
+
|
|
2928
|
+
//#endregion
|
|
2929
|
+
//#region packages/compiler-vapor/src/transforms/transformText.ts
|
|
2930
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
2931
|
+
function markNonTemplate(node, context) {
|
|
2932
|
+
seen.get(context.root).add(node);
|
|
2933
|
+
}
|
|
2934
|
+
const transformText = (node, context) => {
|
|
2935
|
+
if (!seen.has(context.root)) seen.set(context.root, /* @__PURE__ */ new WeakSet());
|
|
2936
|
+
if (seen.get(context.root).has(node)) {
|
|
2937
|
+
context.dynamic.flags |= 2;
|
|
2938
|
+
return;
|
|
2939
|
+
}
|
|
2940
|
+
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
2941
|
+
if ((isFragment || node.type === 1 && node.tagType === 0) && node.children.length) {
|
|
2942
|
+
let hasInterp = false;
|
|
2943
|
+
let isAllTextLike = true;
|
|
2944
|
+
for (const c of node.children) if (c.type === 5) hasInterp = true;
|
|
2945
|
+
else if (c.type !== 2) isAllTextLike = false;
|
|
2946
|
+
if (!isFragment && isAllTextLike && hasInterp) processTextContainer(node.children, context);
|
|
2947
|
+
else if (hasInterp) for (let i = 0; i < node.children.length; i++) {
|
|
2948
|
+
const c = node.children[i];
|
|
2949
|
+
const prev = node.children[i - 1];
|
|
2950
|
+
if (c.type === 5 && prev && prev.type === 2) markNonTemplate(prev, context);
|
|
2951
|
+
}
|
|
2952
|
+
} else if (node.type === 5) processInterpolation(context);
|
|
2953
|
+
else if (node.type === 2) {
|
|
2954
|
+
var _context$parent;
|
|
2955
|
+
const parent = (_context$parent = context.parent) === null || _context$parent === void 0 ? void 0 : _context$parent.node;
|
|
2956
|
+
const isRootText = !parent || parent.type === 0 || parent.type === 1 && (parent.tagType === 3 || parent.tagType === 1);
|
|
2957
|
+
context.template += isRootText ? node.content : (0, _vue_shared.escapeHtml)(node.content);
|
|
2958
|
+
}
|
|
2959
|
+
};
|
|
2960
|
+
function processInterpolation(context) {
|
|
2961
|
+
const parentNode = context.parent.node;
|
|
2962
|
+
const children = parentNode.children;
|
|
2963
|
+
const nexts = children.slice(context.index);
|
|
2964
|
+
const idx = nexts.findIndex((n) => !isTextLike(n));
|
|
2965
|
+
const nodes = idx > -1 ? nexts.slice(0, idx) : nexts;
|
|
2966
|
+
const prev = children[context.index - 1];
|
|
2967
|
+
if (prev && prev.type === 2) nodes.unshift(prev);
|
|
2968
|
+
const values = processTextLikeChildren(nodes, context);
|
|
2969
|
+
if (values.length === 0 && parentNode.type !== 0) return;
|
|
2970
|
+
const literalValues = values.map((v) => getLiteralExpressionValue(v));
|
|
2971
|
+
if (literalValues.every((v) => v != null) && parentNode.type !== 0) {
|
|
2972
|
+
const text = literalValues.join("");
|
|
2973
|
+
const isElementChild = parentNode.type === 1 && parentNode.tagType === 0;
|
|
2974
|
+
context.template += isElementChild ? (0, _vue_shared.escapeHtml)(text) : text;
|
|
2975
|
+
return;
|
|
2976
|
+
}
|
|
2977
|
+
const isDom2 = !!context.options.platform;
|
|
2978
|
+
let isTextNode = false;
|
|
2979
|
+
let isInComponentSlot = false;
|
|
2980
|
+
let shouldReuseParentText = false;
|
|
2981
|
+
if (isDom2) {
|
|
2982
|
+
const grandNode = context.parent.parent && context.parent.parent.node;
|
|
2983
|
+
function isComponent(node) {
|
|
2984
|
+
return !!(node && node.type === 1 && node.tagType === 1);
|
|
2985
|
+
}
|
|
2986
|
+
isInComponentSlot = parentNode.type === 1 && (parentNode.tagType === 1 || (0, _vue_compiler_dom.isTemplateNode)(parentNode) && isComponent(grandNode));
|
|
2987
|
+
shouldReuseParentText = !!(!isInComponentSlot && parentNode.loc.source.startsWith("<slot") && parentNode.type === 1 && parentNode.tag === "template" && grandNode && grandNode.tag === "text" && parentNode.children.every((child) => isTextLike(child)));
|
|
2988
|
+
isTextNode = isInComponentSlot || shouldReuseParentText;
|
|
2989
|
+
}
|
|
2990
|
+
context.template += isDom2 ? isTextNode ? TEXT_NODE_PLACEHOLDER : TEXT_PLACEHOLDER : " ";
|
|
2991
|
+
const id = context.reference();
|
|
2992
|
+
if (values.length === 0) return;
|
|
2993
|
+
context.registerEffect(values, {
|
|
2994
|
+
type: 4,
|
|
2995
|
+
node: context.node,
|
|
2996
|
+
element: id,
|
|
2997
|
+
values
|
|
2998
|
+
});
|
|
2999
|
+
}
|
|
3000
|
+
function processTextContainer(children, context) {
|
|
3001
|
+
const values = processTextLikeChildren(children, context);
|
|
3002
|
+
const literals = values.map((value) => getLiteralExpressionValue(value));
|
|
3003
|
+
if (literals.every((l) => l != null)) context.childrenTemplate = literals.map((l) => (0, _vue_shared.escapeHtml)(String(l)));
|
|
3004
|
+
else {
|
|
3005
|
+
context.childrenTemplate = [context.options.platform ? TEXT_PLACEHOLDER : " "];
|
|
3006
|
+
context.registerOperation({
|
|
3007
|
+
type: 16,
|
|
3008
|
+
node: context.node,
|
|
3009
|
+
parent: context.reference()
|
|
3010
|
+
});
|
|
3011
|
+
context.registerEffect(values, {
|
|
3012
|
+
type: 4,
|
|
3013
|
+
node: context.node,
|
|
3014
|
+
element: context.reference(),
|
|
3015
|
+
values,
|
|
3016
|
+
generated: true
|
|
3017
|
+
});
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
function processTextLikeChildren(nodes, context) {
|
|
3021
|
+
const exps = [];
|
|
3022
|
+
for (const node of nodes) {
|
|
3023
|
+
let exp;
|
|
3024
|
+
markNonTemplate(node, context);
|
|
3025
|
+
if (node.type === 2) exp = (0, _vue_compiler_dom.createSimpleExpression)(node.content, true, node.loc);
|
|
3026
|
+
else exp = node.content;
|
|
3027
|
+
if (exp.content) exps.push(exp);
|
|
3028
|
+
}
|
|
3029
|
+
return exps;
|
|
3030
|
+
}
|
|
3031
|
+
function isTextLike(node) {
|
|
3032
|
+
return node.type === 5 || node.type === 2;
|
|
3033
|
+
}
|
|
3034
|
+
|
|
4458
3035
|
//#endregion
|
|
4459
3036
|
//#region packages/compiler-vapor/src/transforms/vModel.ts
|
|
4460
3037
|
const transformVModel = (dir, node, context) => {
|
|
@@ -4510,7 +3087,7 @@ const transformVModel = (dir, node, context) => {
|
|
|
4510
3087
|
else checkDuplicatedValue();
|
|
4511
3088
|
else context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(58, dir.loc));
|
|
4512
3089
|
if (modelType) context.registerOperation({
|
|
4513
|
-
type:
|
|
3090
|
+
type: 13,
|
|
4514
3091
|
node,
|
|
4515
3092
|
element: context.reference(),
|
|
4516
3093
|
dir,
|
|
@@ -4523,19 +3100,12 @@ const transformVModel = (dir, node, context) => {
|
|
|
4523
3100
|
if (value && (0, _vue_compiler_dom.isStaticArgOf)(value.arg, "value")) context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(61, value.loc));
|
|
4524
3101
|
}
|
|
4525
3102
|
};
|
|
3103
|
+
|
|
4526
3104
|
//#endregion
|
|
4527
3105
|
//#region packages/compiler-vapor/src/transforms/transformComment.ts
|
|
4528
|
-
const ignoredComments = /* @__PURE__ */ new WeakMap();
|
|
4529
|
-
function ignoreComment(node, context) {
|
|
4530
|
-
let ignored = ignoredComments.get(context.root);
|
|
4531
|
-
if (!ignored) ignoredComments.set(context.root, ignored = /* @__PURE__ */ new WeakSet());
|
|
4532
|
-
ignored.add(node);
|
|
4533
|
-
}
|
|
4534
3106
|
const transformComment = (node, context) => {
|
|
4535
|
-
var _ignoredComments$get;
|
|
4536
3107
|
if (node.type !== 3) return;
|
|
4537
|
-
if ((
|
|
4538
|
-
else if (getSiblingIf(context)) {
|
|
3108
|
+
if (getSiblingIf(context)) {
|
|
4539
3109
|
context.comment.push(node);
|
|
4540
3110
|
context.dynamic.flags |= 2;
|
|
4541
3111
|
} else context.template += `<!--${(0, _vue_shared.escapeHtml)(node.content)}-->`;
|
|
@@ -4552,6 +3122,7 @@ function getSiblingIf(context, reverse) {
|
|
|
4552
3122
|
}
|
|
4553
3123
|
if (sibling && sibling.type === 1 && sibling.props.some(({ type, name }) => type === 7 && ["else-if", reverse ? "if" : "else"].includes(name))) return sibling;
|
|
4554
3124
|
}
|
|
3125
|
+
|
|
4555
3126
|
//#endregion
|
|
4556
3127
|
//#region packages/compiler-vapor/src/transforms/vIf.ts
|
|
4557
3128
|
const transformVIf = createStructuralDirectiveTransform([
|
|
@@ -4566,8 +3137,6 @@ function processIf(node, dir, context) {
|
|
|
4566
3137
|
dir.exp = (0, _vue_compiler_dom.createSimpleExpression)(`true`, false, loc);
|
|
4567
3138
|
}
|
|
4568
3139
|
context.dynamic.flags |= 2;
|
|
4569
|
-
const forceMultiRoot = shouldForceMultiRoot(context);
|
|
4570
|
-
const allowNoScope = context.block === context.root.block;
|
|
4571
3140
|
if (dir.name === "if") {
|
|
4572
3141
|
const id = context.reference();
|
|
4573
3142
|
context.dynamic.flags |= 4;
|
|
@@ -4575,14 +3144,12 @@ function processIf(node, dir, context) {
|
|
|
4575
3144
|
return () => {
|
|
4576
3145
|
onExit();
|
|
4577
3146
|
context.dynamic.operation = {
|
|
4578
|
-
type:
|
|
3147
|
+
type: 14,
|
|
4579
3148
|
node,
|
|
4580
3149
|
id,
|
|
4581
|
-
...context.effectBoundary(),
|
|
4582
|
-
blockShape: encodeIfBlockShape(branch, forceMultiRoot, void 0, allowNoScope),
|
|
4583
3150
|
condition: dir.exp,
|
|
4584
3151
|
positive: branch,
|
|
4585
|
-
index: context.root.nextIfIndex(),
|
|
3152
|
+
index: isInTransition(context) ? context.root.nextIfIndex() : void 0,
|
|
4586
3153
|
once: context.inVOnce || isStaticExpression(dir.exp, context.options.bindingMetadata)
|
|
4587
3154
|
};
|
|
4588
3155
|
};
|
|
@@ -4592,42 +3159,34 @@ function processIf(node, dir, context) {
|
|
|
4592
3159
|
let lastIfNode;
|
|
4593
3160
|
if (siblings) {
|
|
4594
3161
|
let i = siblings.length;
|
|
4595
|
-
while (i--) if (siblings[i].operation && siblings[i].operation.type ===
|
|
3162
|
+
while (i--) if (siblings[i].operation && siblings[i].operation.type === 14) {
|
|
4596
3163
|
lastIfNode = siblings[i].operation;
|
|
4597
3164
|
break;
|
|
4598
3165
|
}
|
|
4599
3166
|
}
|
|
4600
|
-
if (!siblingIf || !lastIfNode || lastIfNode.type !==
|
|
3167
|
+
if (!siblingIf || !lastIfNode || lastIfNode.type !== 14) {
|
|
4601
3168
|
context.options.onError((0, _vue_compiler_dom.createCompilerError)(30, node.loc));
|
|
4602
3169
|
return;
|
|
4603
3170
|
}
|
|
4604
|
-
while (lastIfNode.negative && lastIfNode.negative.type ===
|
|
3171
|
+
while (lastIfNode.negative && lastIfNode.negative.type === 14) lastIfNode = lastIfNode.negative;
|
|
4605
3172
|
if (dir.name === "else-if" && lastIfNode.negative) context.options.onError((0, _vue_compiler_dom.createCompilerError)(30, node.loc));
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
node = wrapTemplate(node, ["else-if", "else"]);
|
|
4610
|
-
context.node = node = (0, _vue_shared.extend)({}, node, { children: [...comments, ...node.children] });
|
|
4611
|
-
}
|
|
4612
|
-
comments.length = 0;
|
|
3173
|
+
if (context.root.comment.length) {
|
|
3174
|
+
node = wrapTemplate(node, ["else-if", "else"]);
|
|
3175
|
+
context.node = node = (0, _vue_shared.extend)({}, node, { children: [...context.comment, ...node.children] });
|
|
4613
3176
|
}
|
|
3177
|
+
context.root.comment = [];
|
|
4614
3178
|
const [branch, onExit] = createIfBranch(node, context);
|
|
4615
3179
|
if (dir.name === "else") lastIfNode.negative = branch;
|
|
4616
3180
|
else lastIfNode.negative = {
|
|
4617
|
-
type:
|
|
3181
|
+
type: 14,
|
|
4618
3182
|
node,
|
|
4619
3183
|
id: -1,
|
|
4620
3184
|
condition: dir.exp,
|
|
4621
3185
|
positive: branch,
|
|
4622
|
-
index: context.root.nextIfIndex(),
|
|
4623
|
-
blockShape: 0,
|
|
3186
|
+
index: isInTransition(context) ? context.root.nextIfIndex() : void 0,
|
|
4624
3187
|
once: context.inVOnce || isStaticExpression(dir.exp, context.options.bindingMetadata)
|
|
4625
3188
|
};
|
|
4626
|
-
return () =>
|
|
4627
|
-
onExit();
|
|
4628
|
-
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot, void 0, allowNoScope);
|
|
4629
|
-
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative, allowNoScope);
|
|
4630
|
-
};
|
|
3189
|
+
return () => onExit();
|
|
4631
3190
|
}
|
|
4632
3191
|
}
|
|
4633
3192
|
function createIfBranch(node, context) {
|
|
@@ -4641,42 +3200,7 @@ function createIfBranch(node, context) {
|
|
|
4641
3200
|
context.reference();
|
|
4642
3201
|
return [branch, exitBlock];
|
|
4643
3202
|
}
|
|
4644
|
-
|
|
4645
|
-
if (forceMultiRoot) return 10;
|
|
4646
|
-
const positiveNoScope = allowNoScope && canSkipIfBranchScope(positive);
|
|
4647
|
-
const negativeNoScope = allowNoScope && negative && negative.type !== 15 && canSkipIfBranchScope(negative);
|
|
4648
|
-
return getBlockShape(positive) | getNegativeIfBranchShape(negative) << 2 | (positiveNoScope ? 32 : 0) | (negativeNoScope ? 64 : 0);
|
|
4649
|
-
}
|
|
4650
|
-
function getNegativeIfBranchShape(negative) {
|
|
4651
|
-
if (!negative) return 0;
|
|
4652
|
-
return negative.type === 15 ? 1 : getBlockShape(negative);
|
|
4653
|
-
}
|
|
4654
|
-
function canSkipIfBranchScope(block) {
|
|
4655
|
-
if (block.effect.length || block.operation.length) return false;
|
|
4656
|
-
if (!isStaticBranch(block.node)) return false;
|
|
4657
|
-
if (block.returns.length === 0 || block.dynamic.children.length !== block.returns.length) return false;
|
|
4658
|
-
return block.returns.every((id) => {
|
|
4659
|
-
const returned = findReturnedDynamic(block, id);
|
|
4660
|
-
return !!(returned && returned.template != null && !returned.operation && !returned.hasDynamicChild && !(returned.flags & 6));
|
|
4661
|
-
});
|
|
4662
|
-
}
|
|
4663
|
-
function findReturnedDynamic(block, id) {
|
|
4664
|
-
return block.dynamic.children.find((child) => child.id === id);
|
|
4665
|
-
}
|
|
4666
|
-
function isStaticBranch(node) {
|
|
4667
|
-
if (node.type !== 1 || node.tagType !== 3 || node.children.length === 0) return false;
|
|
4668
|
-
return node.children.every((child) => isStaticTemplateNode(child));
|
|
4669
|
-
}
|
|
4670
|
-
function isStaticTemplateNode(node) {
|
|
4671
|
-
if (node.type === 2 || node.type === 3) return true;
|
|
4672
|
-
if (node.type !== 1 || node.tagType !== 0) return false;
|
|
4673
|
-
for (const prop of node.props) if (prop.type === 7 || prop.name === "ref") return false;
|
|
4674
|
-
return node.children.every((child) => isStaticTemplateNode(child));
|
|
4675
|
-
}
|
|
4676
|
-
function shouldForceMultiRoot(context) {
|
|
4677
|
-
const parent = context.parent && context.parent.node;
|
|
4678
|
-
return !!parent && parent.type === 1 && parent.tagType === 3 && parent.props.some((prop) => prop.type === 7 && prop.name === "for");
|
|
4679
|
-
}
|
|
3203
|
+
|
|
4680
3204
|
//#endregion
|
|
4681
3205
|
//#region packages/compiler-vapor/src/transforms/vFor.ts
|
|
4682
3206
|
const transformVFor = createStructuralDirectiveTransform("for", processFor);
|
|
@@ -4696,7 +3220,7 @@ function processFor(node, dir, context) {
|
|
|
4696
3220
|
const typeProp = findProp$1(node, "type");
|
|
4697
3221
|
const typeProperty = typeProp && propToExpression(typeProp);
|
|
4698
3222
|
const isComponent = node.tagType === 1 || isTemplateWithSingleComponent(node);
|
|
4699
|
-
context.node = node = wrapTemplate(node, ["for"
|
|
3223
|
+
context.node = node = wrapTemplate(node, ["for"]);
|
|
4700
3224
|
context.dynamic.flags |= 6;
|
|
4701
3225
|
const id = context.reference();
|
|
4702
3226
|
const render = newBlock(node);
|
|
@@ -4707,10 +3231,9 @@ function processFor(node, dir, context) {
|
|
|
4707
3231
|
const { parent } = context;
|
|
4708
3232
|
const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
|
|
4709
3233
|
context.dynamic.operation = {
|
|
4710
|
-
type:
|
|
3234
|
+
type: 15,
|
|
4711
3235
|
node,
|
|
4712
3236
|
id,
|
|
4713
|
-
...context.effectBoundary(),
|
|
4714
3237
|
source,
|
|
4715
3238
|
value,
|
|
4716
3239
|
key,
|
|
@@ -4729,6 +3252,7 @@ function isTemplateWithSingleComponent(node) {
|
|
|
4729
3252
|
const nonCommentChildren = node.children.filter((c) => c.type !== 3);
|
|
4730
3253
|
return nonCommentChildren.length === 1 && nonCommentChildren[0].type === 1 && nonCommentChildren[0].tagType === 1;
|
|
4731
3254
|
}
|
|
3255
|
+
|
|
4732
3256
|
//#endregion
|
|
4733
3257
|
//#region packages/compiler-vapor/src/transforms/transformSlotOutlet.ts
|
|
4734
3258
|
const transformSlotOutlet = (node, context) => {
|
|
@@ -4756,23 +3280,20 @@ const transformSlotOutlet = (node, context) => {
|
|
|
4756
3280
|
if (slotProps.length) {
|
|
4757
3281
|
const [isDynamic, props] = buildProps((0, _vue_shared.extend)({}, node, { props: slotProps }), context, true);
|
|
4758
3282
|
irProps = isDynamic ? props : [props];
|
|
4759
|
-
const runtimeDirective = context.block.operation.find((oper) => oper.type ===
|
|
3283
|
+
const runtimeDirective = context.block.operation.find((oper) => oper.type === 13 && oper.element === id);
|
|
4760
3284
|
if (runtimeDirective) context.options.onError((0, _vue_compiler_dom.createCompilerError)(36, runtimeDirective.dir.loc));
|
|
4761
3285
|
}
|
|
4762
3286
|
return () => {
|
|
4763
3287
|
exitBlock && exitBlock();
|
|
4764
|
-
let flags = 0;
|
|
4765
|
-
if (context.options.scopeId && !context.options.slotted) flags |= 1;
|
|
4766
|
-
if (context.inVOnce) flags |= 2;
|
|
4767
3288
|
context.dynamic.operation = {
|
|
4768
|
-
type:
|
|
3289
|
+
type: 12,
|
|
4769
3290
|
node,
|
|
4770
3291
|
id,
|
|
4771
|
-
...context.effectBoundary(),
|
|
4772
3292
|
name: slotName,
|
|
4773
3293
|
props: irProps,
|
|
4774
3294
|
fallback,
|
|
4775
|
-
|
|
3295
|
+
noSlotted: !!(context.options.scopeId && !context.options.slotted),
|
|
3296
|
+
once: context.inVOnce
|
|
4776
3297
|
};
|
|
4777
3298
|
};
|
|
4778
3299
|
};
|
|
@@ -4790,11 +3311,12 @@ function createFallback(node, context) {
|
|
|
4790
3311
|
context.reference();
|
|
4791
3312
|
return [fallback, exitBlock];
|
|
4792
3313
|
}
|
|
3314
|
+
|
|
4793
3315
|
//#endregion
|
|
4794
3316
|
//#region packages/compiler-vapor/src/transforms/vSlot.ts
|
|
4795
3317
|
const transformVSlot = (node, context) => {
|
|
4796
3318
|
if (node.type !== 1) return;
|
|
4797
|
-
const dir = findDir$
|
|
3319
|
+
const dir = findDir$2(node, "slot", true);
|
|
4798
3320
|
const { tagType, children } = node;
|
|
4799
3321
|
const { parent } = context;
|
|
4800
3322
|
const isComponent = tagType === 1;
|
|
@@ -4806,24 +3328,22 @@ const transformVSlot = (node, context) => {
|
|
|
4806
3328
|
function transformComponentSlot(node, dir, context) {
|
|
4807
3329
|
const { children } = node;
|
|
4808
3330
|
const arg = dir && dir.arg;
|
|
4809
|
-
const hasTemplateSlots = children.some(isSlotTemplateChild);
|
|
4810
3331
|
const emptyTextNodes = [];
|
|
4811
3332
|
const nonSlotTemplateChildren = children.filter((n) => {
|
|
4812
|
-
if (
|
|
4813
|
-
|
|
4814
|
-
ignoreComment(n, context);
|
|
4815
|
-
return false;
|
|
4816
|
-
}
|
|
4817
|
-
if (isNonWhitespaceContent(n)) return true;
|
|
4818
|
-
else {
|
|
4819
|
-
emptyTextNodes.push(n);
|
|
4820
|
-
return false;
|
|
4821
|
-
}
|
|
3333
|
+
if (isNonWhitespaceContent(n)) return !(n.type === 1 && n.props.some(_vue_compiler_dom.isVSlot));
|
|
3334
|
+
else emptyTextNodes.push(n);
|
|
4822
3335
|
});
|
|
4823
3336
|
if (!nonSlotTemplateChildren.length) emptyTextNodes.forEach((n) => {
|
|
4824
3337
|
markNonTemplate(n, context);
|
|
4825
3338
|
});
|
|
4826
3339
|
const [block, onExit] = createSlotBlock(node, dir, context);
|
|
3340
|
+
if (isTransitionNode(node) && nonSlotTemplateChildren.length) {
|
|
3341
|
+
const nonCommentChild = nonSlotTemplateChildren.find((n) => !(0, _vue_compiler_dom.isCommentOrWhitespace)(n));
|
|
3342
|
+
if (nonCommentChild) {
|
|
3343
|
+
const keyProp = findProp$1(nonCommentChild, "key");
|
|
3344
|
+
if (keyProp) block.key = keyProp.exp;
|
|
3345
|
+
}
|
|
3346
|
+
}
|
|
4827
3347
|
const { slots } = context;
|
|
4828
3348
|
return () => {
|
|
4829
3349
|
onExit();
|
|
@@ -4842,16 +3362,14 @@ function transformComponentSlot(node, dir, context) {
|
|
|
4842
3362
|
}
|
|
4843
3363
|
function transformTemplateSlot(node, dir, context) {
|
|
4844
3364
|
context.dynamic.flags |= 2;
|
|
4845
|
-
const
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
const
|
|
4849
|
-
const vIf = findDir$4(node, "if");
|
|
4850
|
-
const vElse = findDir$4(node, /^else(-if)?$/, true);
|
|
3365
|
+
const arg = dir.arg && resolveExpression(dir.arg);
|
|
3366
|
+
const vFor = findDir$2(node, "for");
|
|
3367
|
+
const vIf = findDir$2(node, "if");
|
|
3368
|
+
const vElse = findDir$2(node, /^else(-if)?$/, true);
|
|
4851
3369
|
const { slots } = context;
|
|
4852
3370
|
const [block, onExit] = createSlotBlock(node, dir, context);
|
|
4853
3371
|
if (!vFor && !vIf && !vElse) {
|
|
4854
|
-
const slotName =
|
|
3372
|
+
const slotName = arg ? arg.isStatic && arg.content : "default";
|
|
4855
3373
|
if (slotName && hasStaticSlot(slots, slotName)) context.options.onError((0, _vue_compiler_dom.createCompilerError)(38, dir.loc));
|
|
4856
3374
|
else registerSlot(slots, arg, block);
|
|
4857
3375
|
} else if (vIf) registerDynamicSlot(slots, {
|
|
@@ -4865,7 +3383,7 @@ function transformTemplateSlot(node, dir, context) {
|
|
|
4865
3383
|
});
|
|
4866
3384
|
else if (vElse) {
|
|
4867
3385
|
const vIfSlot = slots[slots.length - 1];
|
|
4868
|
-
if (vIfSlot
|
|
3386
|
+
if (vIfSlot.slotType === 3) {
|
|
4869
3387
|
let ifNode = vIfSlot;
|
|
4870
3388
|
while (ifNode.negative && ifNode.negative.slotType === 3) ifNode = ifNode.negative;
|
|
4871
3389
|
const negative = vElse.exp ? {
|
|
@@ -4927,9 +3445,7 @@ function isNonWhitespaceContent(node) {
|
|
|
4927
3445
|
if (node.type !== 2) return true;
|
|
4928
3446
|
return !!node.content.trim();
|
|
4929
3447
|
}
|
|
4930
|
-
|
|
4931
|
-
return node.type === 1 && (0, _vue_compiler_dom.isTemplateNode)(node) && !!findDir$4(node, "slot", true);
|
|
4932
|
-
}
|
|
3448
|
+
|
|
4933
3449
|
//#endregion
|
|
4934
3450
|
//#region packages/compiler-vapor/src/transforms/transformTransition.ts
|
|
4935
3451
|
const transformTransition = (node, context) => {
|
|
@@ -4940,40 +3456,12 @@ const transformTransition = (node, context) => {
|
|
|
4940
3456
|
function hasMultipleChildren(node) {
|
|
4941
3457
|
const children = node.children = node.children.filter((c) => c.type !== 3 && !(c.type === 2 && !c.content.trim()));
|
|
4942
3458
|
const first = children[0];
|
|
4943
|
-
if (children.length === 1 && first.type === 1)
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
const hasElse = (node) => findDir$4(node, "else-if") || findDir$4(node, "else", true);
|
|
4948
|
-
if (children.length > 0 && children.every((c, index) => c.type === 1 && (!(0, _vue_compiler_dom.isTemplateNode)(c) || !hasMultipleChildren(c)) && !findDir$4(c, "for") && (index === 0 ? findDir$4(c, "if") : hasElse(c)))) return false;
|
|
4949
|
-
return children.length !== 1;
|
|
3459
|
+
if (children.length === 1 && first.type === 1 && (findDir$2(first, "for") || (0, _vue_compiler_dom.isTemplateNode)(first))) return true;
|
|
3460
|
+
const hasElse = (node) => findDir$2(node, "else-if") || findDir$2(node, "else", true);
|
|
3461
|
+
if (children.every((c, index) => c.type === 1 && !(0, _vue_compiler_dom.isTemplateNode)(c) && !findDir$2(c, "for") && (index === 0 ? findDir$2(c, "if") : hasElse(c)))) return false;
|
|
3462
|
+
return children.length > 1;
|
|
4950
3463
|
}
|
|
4951
|
-
|
|
4952
|
-
//#region packages/compiler-vapor/src/transforms/transformKey.ts
|
|
4953
|
-
const transformKey = (node, context) => {
|
|
4954
|
-
if (node.type !== 1 || context.inVOnce || findDir$4(node, "for")) return;
|
|
4955
|
-
const dir = findProp$1(node, "key", true, true);
|
|
4956
|
-
if (!dir || dir.type === 6) return;
|
|
4957
|
-
let value;
|
|
4958
|
-
value = dir.exp || normalizeBindShorthand(dir.arg, context);
|
|
4959
|
-
if (isStaticExpression(value, context.options.bindingMetadata)) return;
|
|
4960
|
-
let id = context.reference();
|
|
4961
|
-
context.dynamic.flags |= 6;
|
|
4962
|
-
context.node = node = wrapTemplate(node, ["key"]);
|
|
4963
|
-
const block = newBlock(node);
|
|
4964
|
-
const exitBlock = context.enterBlock(block);
|
|
4965
|
-
return () => {
|
|
4966
|
-
exitBlock();
|
|
4967
|
-
context.dynamic.operation = {
|
|
4968
|
-
type: 17,
|
|
4969
|
-
node,
|
|
4970
|
-
id,
|
|
4971
|
-
...context.effectBoundary(),
|
|
4972
|
-
value,
|
|
4973
|
-
block
|
|
4974
|
-
};
|
|
4975
|
-
};
|
|
4976
|
-
};
|
|
3464
|
+
|
|
4977
3465
|
//#endregion
|
|
4978
3466
|
//#region packages/compiler-vapor/src/compile.ts
|
|
4979
3467
|
function compile(source, options = {}) {
|
|
@@ -4998,7 +3486,6 @@ function getBaseTransformPreset() {
|
|
|
4998
3486
|
transformVOnce,
|
|
4999
3487
|
transformVIf,
|
|
5000
3488
|
transformVFor,
|
|
5001
|
-
transformKey,
|
|
5002
3489
|
transformSlotOutlet,
|
|
5003
3490
|
transformTemplateRef,
|
|
5004
3491
|
transformElement,
|
|
@@ -5015,6 +3502,23 @@ function getBaseTransformPreset() {
|
|
|
5015
3502
|
model: transformVModel
|
|
5016
3503
|
}];
|
|
5017
3504
|
}
|
|
3505
|
+
|
|
3506
|
+
//#endregion
|
|
3507
|
+
//#region packages/compiler-vapor/src/errors.ts
|
|
3508
|
+
function createVaporCompilerError(code, loc) {
|
|
3509
|
+
return (0, _vue_compiler_dom.createCompilerError)(code, loc, VaporErrorMessages);
|
|
3510
|
+
}
|
|
3511
|
+
const VaporErrorCodes = {
|
|
3512
|
+
"X_V_PLACEHOLDER": 100,
|
|
3513
|
+
"100": "X_V_PLACEHOLDER",
|
|
3514
|
+
"__EXTEND_POINT__": 101,
|
|
3515
|
+
"101": "__EXTEND_POINT__"
|
|
3516
|
+
};
|
|
3517
|
+
const VaporErrorMessages = {
|
|
3518
|
+
[100]: `[placeholder]`,
|
|
3519
|
+
[101]: ``
|
|
3520
|
+
};
|
|
3521
|
+
|
|
5018
3522
|
//#endregion
|
|
5019
3523
|
exports.CodegenContext = CodegenContext;
|
|
5020
3524
|
exports.DELIMITERS_ARRAY = DELIMITERS_ARRAY;
|
|
@@ -5034,7 +3538,6 @@ exports.LF = LF;
|
|
|
5034
3538
|
exports.NEWLINE = NEWLINE;
|
|
5035
3539
|
exports.TEXT_NODE_PLACEHOLDER = TEXT_NODE_PLACEHOLDER;
|
|
5036
3540
|
exports.TEXT_PLACEHOLDER = TEXT_PLACEHOLDER;
|
|
5037
|
-
exports.TemplateRegistry = TemplateRegistry;
|
|
5038
3541
|
exports.VaporErrorCodes = VaporErrorCodes;
|
|
5039
3542
|
exports.VaporErrorMessages = VaporErrorMessages;
|
|
5040
3543
|
exports.analyzeExpressions = analyzeExpressions;
|
|
@@ -5045,37 +3548,26 @@ exports.compile = compile;
|
|
|
5045
3548
|
exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
|
|
5046
3549
|
exports.createVaporCompilerError = createVaporCompilerError;
|
|
5047
3550
|
exports.genCall = genCall;
|
|
5048
|
-
exports.genDirectiveModifiers = genDirectiveModifiers;
|
|
5049
|
-
exports.genDynamicComponentFlags = genDynamicComponentFlags;
|
|
5050
3551
|
exports.genMulti = genMulti;
|
|
5051
|
-
exports.genSlotFlags = genSlotFlags;
|
|
5052
3552
|
exports.generate = generate;
|
|
5053
3553
|
exports.getBaseTransformPreset = getBaseTransformPreset;
|
|
5054
3554
|
exports.getLiteralExpressionValue = getLiteralExpressionValue;
|
|
5055
|
-
exports.getParserOptions = getParserOptions;
|
|
5056
|
-
exports.hasStableSlotRoot = hasStableSlotRoot;
|
|
5057
3555
|
exports.isBlockOperation = isBlockOperation;
|
|
5058
3556
|
exports.isBuiltInComponent = isBuiltInComponent;
|
|
5059
3557
|
exports.isConstantExpression = isConstantExpression;
|
|
5060
|
-
exports.isDirectStaticLiteralProp = isDirectStaticLiteralProp;
|
|
5061
3558
|
exports.isKeepAliveTag = isKeepAliveTag;
|
|
5062
3559
|
exports.isStaticExpression = isStaticExpression;
|
|
5063
3560
|
exports.isTeleportTag = isTeleportTag;
|
|
5064
3561
|
exports.isTransitionGroupTag = isTransitionGroupTag;
|
|
5065
3562
|
exports.isTransitionTag = isTransitionTag;
|
|
5066
|
-
exports.markSlotRootOperations = markSlotRootOperations;
|
|
5067
|
-
exports.matchKeyOnlyBindingPattern = matchKeyOnlyBindingPattern;
|
|
5068
|
-
exports.matchSelectorPattern = matchSelectorPattern;
|
|
5069
3563
|
exports.needsVaporCtx = needsVaporCtx;
|
|
5070
3564
|
exports.parse = _vue_compiler_dom.parse;
|
|
5071
|
-
exports.parseStaticAttrBooleanExpression = parseStaticAttrBooleanExpression;
|
|
5072
3565
|
exports.parseValueDestructure = parseValueDestructure;
|
|
5073
3566
|
exports.propToExpression = propToExpression;
|
|
5074
3567
|
exports.transform = transform;
|
|
5075
3568
|
exports.transformChildren = transformChildren;
|
|
5076
3569
|
exports.transformComment = transformComment;
|
|
5077
3570
|
exports.transformElement = transformElement;
|
|
5078
|
-
exports.transformKey = transformKey;
|
|
5079
3571
|
exports.transformSlotOutlet = transformSlotOutlet;
|
|
5080
3572
|
exports.transformTemplateRef = transformTemplateRef;
|
|
5081
3573
|
exports.transformText = transformText;
|
|
@@ -5089,4 +3581,4 @@ exports.transformVOnce = transformVOnce;
|
|
|
5089
3581
|
exports.transformVShow = transformVShow;
|
|
5090
3582
|
exports.transformVSlot = transformVSlot;
|
|
5091
3583
|
exports.transformVText = transformVText;
|
|
5092
|
-
exports.wrapTemplate = wrapTemplate;
|
|
3584
|
+
exports.wrapTemplate = wrapTemplate;
|