@vue/compiler-vapor 3.6.0-beta.10 → 3.6.0-beta.11
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/compiler-vapor.cjs.js +474 -291
- package/dist/compiler-vapor.d.ts +149 -99
- package/dist/compiler-vapor.esm-browser.js +583 -326
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-vapor v3.6.0-beta.
|
|
2
|
+
* @vue/compiler-vapor v3.6.0-beta.11
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -12,6 +12,90 @@ let _vue_shared = require("@vue/shared");
|
|
|
12
12
|
let source_map_js = require("source-map-js");
|
|
13
13
|
let _babel_parser = require("@babel/parser");
|
|
14
14
|
let estree_walker = require("estree-walker");
|
|
15
|
+
//#region packages/compiler-vapor/src/ir/component.ts
|
|
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
|
+
};
|
|
76
|
+
var TemplateRegistry = class {
|
|
77
|
+
constructor() {
|
|
78
|
+
this.entries = [];
|
|
79
|
+
}
|
|
80
|
+
keys() {
|
|
81
|
+
return this.entries.map(({ content }) => content);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const DynamicFlag = {
|
|
85
|
+
"NONE": 0,
|
|
86
|
+
"0": "NONE",
|
|
87
|
+
"REFERENCED": 1,
|
|
88
|
+
"1": "REFERENCED",
|
|
89
|
+
"NON_TEMPLATE": 2,
|
|
90
|
+
"2": "NON_TEMPLATE",
|
|
91
|
+
"INSERT": 4,
|
|
92
|
+
"4": "INSERT"
|
|
93
|
+
};
|
|
94
|
+
function isBlockOperation(op) {
|
|
95
|
+
const type = op.type;
|
|
96
|
+
return type === 12 || type === 13 || type === 15 || type === 17 || type === 16;
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
15
99
|
//#region packages/compiler-vapor/src/transforms/utils.ts
|
|
16
100
|
const newDynamic = () => ({
|
|
17
101
|
flags: 1,
|
|
@@ -127,6 +211,7 @@ function isTeleportTag(tag) {
|
|
|
127
211
|
}
|
|
128
212
|
function isBuiltInComponent(tag) {
|
|
129
213
|
if (isTeleportTag(tag)) return "VaporTeleport";
|
|
214
|
+
else if (tag === "Suspense" || tag === "suspense") return "Suspense";
|
|
130
215
|
else if (isKeepAliveTag(tag)) return "VaporKeepAlive";
|
|
131
216
|
else if (isTransitionTag(tag)) return "VaporTransition";
|
|
132
217
|
else if (isTransitionGroupTag(tag)) return "VaporTransitionGroup";
|
|
@@ -148,6 +233,8 @@ var TransformContext = class TransformContext {
|
|
|
148
233
|
this.index = 0;
|
|
149
234
|
this.block = this.ir.block;
|
|
150
235
|
this.template = "";
|
|
236
|
+
this.templateRoot = false;
|
|
237
|
+
this.templateIndexMap = /* @__PURE__ */ new Map();
|
|
151
238
|
this.childrenTemplate = [];
|
|
152
239
|
this.dynamic = this.ir.block.dynamic;
|
|
153
240
|
this.imports = [];
|
|
@@ -157,6 +244,8 @@ var TransformContext = class TransformContext {
|
|
|
157
244
|
this.component = this.ir.component;
|
|
158
245
|
this.directive = this.ir.directive;
|
|
159
246
|
this.slots = [];
|
|
247
|
+
this.effectIndex = this.block.effect.length;
|
|
248
|
+
this.operationIndex = this.block.operation.length;
|
|
160
249
|
this.isLastEffectiveChild = true;
|
|
161
250
|
this.isOnRightmostPath = true;
|
|
162
251
|
this.hasInlineAncestorNeedingClose = false;
|
|
@@ -174,20 +263,28 @@ var TransformContext = class TransformContext {
|
|
|
174
263
|
this.initNextIdMap();
|
|
175
264
|
}
|
|
176
265
|
enterBlock(ir, isVFor = false) {
|
|
177
|
-
const { block, template, dynamic, childrenTemplate, slots } = this;
|
|
266
|
+
const { block, template, templateRoot, templateIndexMap, dynamic, childrenTemplate, slots, effectIndex, operationIndex } = this;
|
|
178
267
|
this.block = ir;
|
|
179
268
|
this.dynamic = ir.dynamic;
|
|
180
269
|
this.template = "";
|
|
270
|
+
this.templateRoot = false;
|
|
271
|
+
this.templateIndexMap = templateIndexMap;
|
|
181
272
|
this.childrenTemplate = [];
|
|
182
273
|
this.slots = [];
|
|
274
|
+
this.effectIndex = ir.effect.length;
|
|
275
|
+
this.operationIndex = ir.operation.length;
|
|
183
276
|
isVFor && this.inVFor++;
|
|
184
277
|
return () => {
|
|
185
278
|
this.registerTemplate();
|
|
186
279
|
this.block = block;
|
|
187
280
|
this.template = template;
|
|
281
|
+
this.templateRoot = templateRoot;
|
|
282
|
+
this.templateIndexMap = templateIndexMap;
|
|
188
283
|
this.dynamic = dynamic;
|
|
189
284
|
this.childrenTemplate = childrenTemplate;
|
|
190
285
|
this.slots = slots;
|
|
286
|
+
this.effectIndex = effectIndex;
|
|
287
|
+
this.operationIndex = operationIndex;
|
|
191
288
|
isVFor && this.inVFor--;
|
|
192
289
|
};
|
|
193
290
|
}
|
|
@@ -212,31 +309,66 @@ var TransformContext = class TransformContext {
|
|
|
212
309
|
nextIfIndex() {
|
|
213
310
|
return this.ifIndex++;
|
|
214
311
|
}
|
|
215
|
-
|
|
216
|
-
|
|
312
|
+
getTemplateNamespace() {
|
|
313
|
+
return this.node.type === 1 ? this.node.ns : 0;
|
|
314
|
+
}
|
|
315
|
+
canUseStaticTemplate() {
|
|
316
|
+
if (!this.template) return false;
|
|
317
|
+
if (this.inVFor) return false;
|
|
318
|
+
if (this.dynamic.hasDynamicChild) return false;
|
|
319
|
+
if (this.block.effect.length !== this.effectIndex) return false;
|
|
320
|
+
if (this.block.operation.length !== this.operationIndex) return false;
|
|
321
|
+
if (this.node.type === 2 || this.node.type === 3) return true;
|
|
322
|
+
return this.node.type === 1 && this.node.tagType === 0 && !(this.options.isCustomElement(this.node.tag) || this.node.tag === "template");
|
|
323
|
+
}
|
|
324
|
+
pushTemplate(content, { root = false, static: isStatic = false } = {}) {
|
|
325
|
+
const templateKey = JSON.stringify([
|
|
326
|
+
this.getTemplateNamespace(),
|
|
327
|
+
root,
|
|
328
|
+
isStatic,
|
|
329
|
+
content
|
|
330
|
+
]);
|
|
331
|
+
const existingIndex = this.templateIndexMap.get(templateKey);
|
|
217
332
|
if (existingIndex !== void 0) return existingIndex;
|
|
218
|
-
const
|
|
219
|
-
this.ir.template.
|
|
220
|
-
this.ir.
|
|
333
|
+
const ns = this.getTemplateNamespace();
|
|
334
|
+
const newIndex = this.ir.template.entries.length;
|
|
335
|
+
this.ir.template.entries.push({
|
|
336
|
+
content,
|
|
337
|
+
ns,
|
|
338
|
+
root,
|
|
339
|
+
static: isStatic
|
|
340
|
+
});
|
|
341
|
+
this.templateIndexMap.set(templateKey, newIndex);
|
|
221
342
|
return newIndex;
|
|
222
343
|
}
|
|
223
344
|
registerTemplate() {
|
|
224
345
|
if (!this.template) return -1;
|
|
225
|
-
const id = this.pushTemplate(this.template
|
|
346
|
+
const id = this.pushTemplate(this.template, {
|
|
347
|
+
root: this.templateRoot,
|
|
348
|
+
static: this.canUseStaticTemplate()
|
|
349
|
+
});
|
|
226
350
|
return this.dynamic.template = id;
|
|
227
351
|
}
|
|
228
|
-
registerEffect(expressions, operation, getIndex
|
|
352
|
+
registerEffect(expressions, operation, getIndex) {
|
|
229
353
|
const operations = [operation].flat();
|
|
230
354
|
expressions = expressions.filter((exp) => !isConstantExpression(exp));
|
|
231
355
|
if (this.inVOnce || expressions.length === 0 || expressions.every((e) => isStaticExpression(e, this.root.options.bindingMetadata))) return this.registerOperation(...operations);
|
|
232
|
-
this.block.effect.
|
|
356
|
+
const index = getIndex ? getIndex() : this.block.effect.length;
|
|
357
|
+
this.block.effect.splice(index, 0, {
|
|
233
358
|
expressions,
|
|
234
359
|
operations
|
|
235
360
|
});
|
|
361
|
+
if (getIndex) this.shiftEffectBoundaries(index);
|
|
236
362
|
}
|
|
237
363
|
registerOperation(...node) {
|
|
238
364
|
this.block.operation.push(...node);
|
|
239
365
|
}
|
|
366
|
+
effectBoundary() {
|
|
367
|
+
return {
|
|
368
|
+
operationIndex: this.operationIndex,
|
|
369
|
+
effectIndex: this.effectIndex
|
|
370
|
+
};
|
|
371
|
+
}
|
|
240
372
|
create(node, index) {
|
|
241
373
|
let effectiveParent = this;
|
|
242
374
|
while (effectiveParent && effectiveParent.node.type === 1 && effectiveParent.node.tagType === 3) effectiveParent = effectiveParent.parent;
|
|
@@ -252,14 +384,23 @@ var TransformContext = class TransformContext {
|
|
|
252
384
|
parent: this,
|
|
253
385
|
index,
|
|
254
386
|
template: "",
|
|
387
|
+
templateRoot: false,
|
|
255
388
|
childrenTemplate: [],
|
|
389
|
+
templateIndexMap: this.templateIndexMap,
|
|
256
390
|
dynamic: newDynamic(),
|
|
391
|
+
effectIndex: this.block.effect.length,
|
|
392
|
+
operationIndex: this.block.operation.length,
|
|
257
393
|
effectiveParent,
|
|
258
394
|
isLastEffectiveChild,
|
|
259
395
|
isOnRightmostPath,
|
|
260
396
|
hasInlineAncestorNeedingClose
|
|
261
397
|
});
|
|
262
398
|
}
|
|
399
|
+
shiftEffectBoundaries(index, dynamic = this.dynamic) {
|
|
400
|
+
const operation = dynamic.operation;
|
|
401
|
+
if (operation && isBlockOperation(operation) && operation.effectIndex !== void 0 && operation.effectIndex >= index) operation.effectIndex++;
|
|
402
|
+
for (const child of dynamic.children) this.shiftEffectBoundaries(index, child);
|
|
403
|
+
}
|
|
263
404
|
isEffectivelyLastChild(index) {
|
|
264
405
|
const children = this.node.children;
|
|
265
406
|
if (!children) return true;
|
|
@@ -294,9 +435,7 @@ function transform(node, options = {}) {
|
|
|
294
435
|
type: 0,
|
|
295
436
|
node,
|
|
296
437
|
source: node.source,
|
|
297
|
-
template:
|
|
298
|
-
templateIndexMap: /* @__PURE__ */ new Map(),
|
|
299
|
-
rootTemplateIndexes: /* @__PURE__ */ new Set(),
|
|
438
|
+
template: new TemplateRegistry(),
|
|
300
439
|
component: /* @__PURE__ */ new Set(),
|
|
301
440
|
directive: /* @__PURE__ */ new Set(),
|
|
302
441
|
block: newBlock(node),
|
|
@@ -510,82 +649,6 @@ function codeFragmentToString(code, context) {
|
|
|
510
649
|
}
|
|
511
650
|
}
|
|
512
651
|
//#endregion
|
|
513
|
-
//#region packages/compiler-vapor/src/ir/component.ts
|
|
514
|
-
const IRDynamicPropsKind = {
|
|
515
|
-
"EXPRESSION": 0,
|
|
516
|
-
"0": "EXPRESSION",
|
|
517
|
-
"ATTRIBUTE": 1,
|
|
518
|
-
"1": "ATTRIBUTE"
|
|
519
|
-
};
|
|
520
|
-
const IRSlotType = {
|
|
521
|
-
"STATIC": 0,
|
|
522
|
-
"0": "STATIC",
|
|
523
|
-
"DYNAMIC": 1,
|
|
524
|
-
"1": "DYNAMIC",
|
|
525
|
-
"LOOP": 2,
|
|
526
|
-
"2": "LOOP",
|
|
527
|
-
"CONDITIONAL": 3,
|
|
528
|
-
"3": "CONDITIONAL",
|
|
529
|
-
"EXPRESSION": 4,
|
|
530
|
-
"4": "EXPRESSION"
|
|
531
|
-
};
|
|
532
|
-
//#endregion
|
|
533
|
-
//#region packages/compiler-vapor/src/ir/index.ts
|
|
534
|
-
const IRNodeTypes = {
|
|
535
|
-
"ROOT": 0,
|
|
536
|
-
"0": "ROOT",
|
|
537
|
-
"BLOCK": 1,
|
|
538
|
-
"1": "BLOCK",
|
|
539
|
-
"SET_BLOCK_KEY": 2,
|
|
540
|
-
"2": "SET_BLOCK_KEY",
|
|
541
|
-
"SET_PROP": 3,
|
|
542
|
-
"3": "SET_PROP",
|
|
543
|
-
"SET_DYNAMIC_PROPS": 4,
|
|
544
|
-
"4": "SET_DYNAMIC_PROPS",
|
|
545
|
-
"SET_TEXT": 5,
|
|
546
|
-
"5": "SET_TEXT",
|
|
547
|
-
"SET_EVENT": 6,
|
|
548
|
-
"6": "SET_EVENT",
|
|
549
|
-
"SET_DYNAMIC_EVENTS": 7,
|
|
550
|
-
"7": "SET_DYNAMIC_EVENTS",
|
|
551
|
-
"SET_HTML": 8,
|
|
552
|
-
"8": "SET_HTML",
|
|
553
|
-
"SET_TEMPLATE_REF": 9,
|
|
554
|
-
"9": "SET_TEMPLATE_REF",
|
|
555
|
-
"INSERT_NODE": 10,
|
|
556
|
-
"10": "INSERT_NODE",
|
|
557
|
-
"PREPEND_NODE": 11,
|
|
558
|
-
"11": "PREPEND_NODE",
|
|
559
|
-
"CREATE_COMPONENT_NODE": 12,
|
|
560
|
-
"12": "CREATE_COMPONENT_NODE",
|
|
561
|
-
"SLOT_OUTLET_NODE": 13,
|
|
562
|
-
"13": "SLOT_OUTLET_NODE",
|
|
563
|
-
"DIRECTIVE": 14,
|
|
564
|
-
"14": "DIRECTIVE",
|
|
565
|
-
"IF": 15,
|
|
566
|
-
"15": "IF",
|
|
567
|
-
"FOR": 16,
|
|
568
|
-
"16": "FOR",
|
|
569
|
-
"KEY": 17,
|
|
570
|
-
"17": "KEY",
|
|
571
|
-
"GET_TEXT_CHILD": 18,
|
|
572
|
-
"18": "GET_TEXT_CHILD"
|
|
573
|
-
};
|
|
574
|
-
const DynamicFlag = {
|
|
575
|
-
"NONE": 0,
|
|
576
|
-
"0": "NONE",
|
|
577
|
-
"REFERENCED": 1,
|
|
578
|
-
"1": "REFERENCED",
|
|
579
|
-
"NON_TEMPLATE": 2,
|
|
580
|
-
"2": "NON_TEMPLATE",
|
|
581
|
-
"INSERT": 4,
|
|
582
|
-
"4": "INSERT"
|
|
583
|
-
};
|
|
584
|
-
function isBlockOperation(op) {
|
|
585
|
-
const type = op.type;
|
|
586
|
-
return type === 12 || type === 13 || type === 15 || type === 17 || type === 16;
|
|
587
|
-
}
|
|
588
|
-
//#endregion
|
|
589
652
|
//#region packages/compiler-vapor/src/generators/dom.ts
|
|
590
653
|
function genInsertNode({ parent, elements, anchor }, { helper }) {
|
|
591
654
|
let element = elements.map((el) => `n${el}`).join(", ");
|
|
@@ -1218,26 +1281,40 @@ function buildDestructureIdMap(idToPathMap, baseAccessor, plugins) {
|
|
|
1218
1281
|
function matchPatterns(render, keyProp, idMap) {
|
|
1219
1282
|
const selectorPatterns = [];
|
|
1220
1283
|
const keyOnlyBindingPatterns = [];
|
|
1221
|
-
|
|
1284
|
+
const removedEffectIndexes = [];
|
|
1285
|
+
render.effect = render.effect.filter((effect, index) => {
|
|
1222
1286
|
if (keyProp !== void 0) {
|
|
1223
1287
|
const selector = matchSelectorPattern(effect, keyProp.content, idMap);
|
|
1224
1288
|
if (selector) {
|
|
1225
1289
|
selectorPatterns.push(selector);
|
|
1290
|
+
removedEffectIndexes.push(index);
|
|
1226
1291
|
return false;
|
|
1227
1292
|
}
|
|
1228
1293
|
const keyOnly = matchKeyOnlyBindingPattern(effect, keyProp.content);
|
|
1229
1294
|
if (keyOnly) {
|
|
1230
1295
|
keyOnlyBindingPatterns.push(keyOnly);
|
|
1296
|
+
removedEffectIndexes.push(index);
|
|
1231
1297
|
return false;
|
|
1232
1298
|
}
|
|
1233
1299
|
}
|
|
1234
1300
|
return true;
|
|
1235
1301
|
});
|
|
1302
|
+
if (removedEffectIndexes.length) shiftEffectBoundaries(render.dynamic, removedEffectIndexes);
|
|
1236
1303
|
return {
|
|
1237
1304
|
keyOnlyBindingPatterns,
|
|
1238
1305
|
selectorPatterns
|
|
1239
1306
|
};
|
|
1240
1307
|
}
|
|
1308
|
+
function shiftEffectBoundaries(dynamic, removedEffectIndexes) {
|
|
1309
|
+
const operation = dynamic.operation;
|
|
1310
|
+
if (operation && isBlockOperation(operation) && operation.effectIndex !== void 0) {
|
|
1311
|
+
let offset = 0;
|
|
1312
|
+
for (const removedIndex of removedEffectIndexes) if (removedIndex < operation.effectIndex) offset++;
|
|
1313
|
+
else break;
|
|
1314
|
+
operation.effectIndex -= offset;
|
|
1315
|
+
}
|
|
1316
|
+
for (const child of dynamic.children) shiftEffectBoundaries(child, removedEffectIndexes);
|
|
1317
|
+
}
|
|
1241
1318
|
function matchKeyOnlyBindingPattern(effect, key) {
|
|
1242
1319
|
if (effect.expressions.length === 1) {
|
|
1243
1320
|
const { ast, content } = effect.expressions[0];
|
|
@@ -1553,11 +1630,11 @@ function genCreateComponent(operation, context) {
|
|
|
1553
1630
|
];
|
|
1554
1631
|
}, []),
|
|
1555
1632
|
`const n${operation.id} = `,
|
|
1556
|
-
...genCall(operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.
|
|
1633
|
+
...genCall(operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.useCreateElement ? helper("createPlainElement") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, root ? "true" : false, once && "true"),
|
|
1557
1634
|
...genDirectivesForElement(operation.id, context)
|
|
1558
1635
|
];
|
|
1559
1636
|
function genTag() {
|
|
1560
|
-
if (operation.
|
|
1637
|
+
if (operation.useCreateElement) return JSON.stringify(operation.tag);
|
|
1561
1638
|
else if (operation.dynamic) if (operation.dynamic.isStatic) return genCall(helper("resolveDynamicComponent"), genExpression(operation.dynamic, context));
|
|
1562
1639
|
else return [
|
|
1563
1640
|
"() => (",
|
|
@@ -1993,21 +2070,24 @@ function genEffect({ operations }, context) {
|
|
|
1993
2070
|
return frag;
|
|
1994
2071
|
}
|
|
1995
2072
|
function genInsertionState(operation, context) {
|
|
1996
|
-
const { parent, anchor, logicalIndex, append
|
|
1997
|
-
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
|
|
2073
|
+
const { parent, anchor, logicalIndex, append } = operation;
|
|
2074
|
+
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)];
|
|
1998
2075
|
}
|
|
1999
2076
|
//#endregion
|
|
2000
2077
|
//#region packages/compiler-vapor/src/generators/template.ts
|
|
2001
|
-
function genTemplates(templates,
|
|
2078
|
+
function genTemplates(templates, context) {
|
|
2002
2079
|
const result = [];
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2080
|
+
templates.forEach(({ content, ns, root, static: isStatic }, i) => {
|
|
2081
|
+
let args = JSON.stringify(content).replace(IMPORT_EXPR_RE, `" + $1 + "`);
|
|
2082
|
+
if (root) args += ", true";
|
|
2083
|
+
else if (isStatic || ns) args += ", false";
|
|
2084
|
+
if (isStatic || ns) args += `, ${isStatic ? "true" : "false"}`;
|
|
2085
|
+
if (ns) args += `, ${ns}`;
|
|
2086
|
+
result.push(`const ${context.tName(i)} = ${context.helper("template")}(${args})\n`);
|
|
2007
2087
|
});
|
|
2008
2088
|
return result.join("");
|
|
2009
2089
|
}
|
|
2010
|
-
function genSelf(dynamic, context) {
|
|
2090
|
+
function genSelf(dynamic, context, flushBeforeDynamic) {
|
|
2011
2091
|
const [frag, push] = buildCodeFragment();
|
|
2012
2092
|
const { id, template, operation, hasDynamicChild } = dynamic;
|
|
2013
2093
|
if (id !== void 0 && template !== void 0) {
|
|
@@ -2015,10 +2095,10 @@ function genSelf(dynamic, context) {
|
|
|
2015
2095
|
push(...genDirectivesForElement(id, context));
|
|
2016
2096
|
}
|
|
2017
2097
|
if (operation) push(...genOperationWithInsertionState(operation, context));
|
|
2018
|
-
if (hasDynamicChild) push(...genChildren(dynamic, context, push, `n${id}
|
|
2098
|
+
if (hasDynamicChild) push(...genChildren(dynamic, context, push, `n${id}`, flushBeforeDynamic));
|
|
2019
2099
|
return frag;
|
|
2020
2100
|
}
|
|
2021
|
-
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}
|
|
2101
|
+
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flushBeforeDynamic) {
|
|
2022
2102
|
const { helper } = context;
|
|
2023
2103
|
const [frag, push] = buildCodeFragment();
|
|
2024
2104
|
const { children } = dynamic;
|
|
@@ -2027,12 +2107,14 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`) {
|
|
|
2027
2107
|
for (const [index, child] of children.entries()) {
|
|
2028
2108
|
if (child.flags & 2) offset--;
|
|
2029
2109
|
if (child.flags & 4 && child.template != null) {
|
|
2030
|
-
|
|
2110
|
+
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
2111
|
+
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2031
2112
|
continue;
|
|
2032
2113
|
}
|
|
2033
2114
|
const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
|
|
2034
2115
|
if (id === void 0 && !child.hasDynamicChild) {
|
|
2035
|
-
|
|
2116
|
+
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
2117
|
+
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2036
2118
|
continue;
|
|
2037
2119
|
}
|
|
2038
2120
|
const elementIndex = index + offset;
|
|
@@ -2048,10 +2130,13 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`) {
|
|
|
2048
2130
|
else if (elementIndex > 1) init = genCall(helper("nthChild"), from, String(elementIndex), logicalIndex);
|
|
2049
2131
|
pushBlock(...init);
|
|
2050
2132
|
}
|
|
2051
|
-
if (id === child.anchor && !child.hasDynamicChild)
|
|
2133
|
+
if (id === child.anchor && !child.hasDynamicChild) {
|
|
2134
|
+
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
2135
|
+
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2136
|
+
}
|
|
2052
2137
|
if (id !== void 0) push(...genDirectivesForElement(id, context));
|
|
2053
2138
|
prev = [variable, elementIndex];
|
|
2054
|
-
push(...genChildren(child, context, pushBlock, variable));
|
|
2139
|
+
push(...genChildren(child, context, pushBlock, variable, flushBeforeDynamic));
|
|
2055
2140
|
}
|
|
2056
2141
|
return frag;
|
|
2057
2142
|
}
|
|
@@ -2082,10 +2167,30 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
2082
2167
|
}
|
|
2083
2168
|
genResolveAssets("directive", "resolveDirective");
|
|
2084
2169
|
}
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2170
|
+
let operationIndex = 0;
|
|
2171
|
+
let effectIndex = 0;
|
|
2172
|
+
const flushPendingOperations = (operationEnd, effectEnd, push) => {
|
|
2173
|
+
while (operationIndex < operationEnd) {
|
|
2174
|
+
push(...genOperationWithInsertionState(operation[operationIndex], context));
|
|
2175
|
+
operationIndex++;
|
|
2176
|
+
}
|
|
2177
|
+
if (effectIndex < effectEnd) {
|
|
2178
|
+
push(...genEffects(effect.slice(effectIndex, effectEnd), context));
|
|
2179
|
+
effectIndex = effectEnd;
|
|
2180
|
+
}
|
|
2181
|
+
};
|
|
2182
|
+
const flushBeforeDynamic = (dynamic, push) => {
|
|
2183
|
+
const operation = dynamic.operation;
|
|
2184
|
+
if (operation && isBlockOperation(operation) && operation.operationIndex !== void 0 && operation.effectIndex !== void 0) flushPendingOperations(operation.operationIndex, operation.effectIndex, push);
|
|
2185
|
+
};
|
|
2186
|
+
for (const child of dynamic.children) {
|
|
2187
|
+
flushBeforeDynamic(child, push);
|
|
2188
|
+
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2189
|
+
}
|
|
2190
|
+
for (const child of dynamic.children) if (!child.hasDynamicChild) push(...genChildren(child, context, push, `n${child.id}`, flushBeforeDynamic));
|
|
2191
|
+
if (operationIndex < operation.length) push(...genOperations(operation.slice(operationIndex), context));
|
|
2192
|
+
if (effectIndex < effect.length) push(...genEffects(effect.slice(effectIndex), context, genEffectsExtraFrag));
|
|
2193
|
+
else if (genEffectsExtraFrag) push(...genEffects([], context, genEffectsExtraFrag));
|
|
2089
2194
|
push(NEWLINE, `return `);
|
|
2090
2195
|
const returnNodes = returns.map((n) => `n${n}`);
|
|
2091
2196
|
push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"]);
|
|
@@ -2171,7 +2276,7 @@ var CodegenContext = class {
|
|
|
2171
2276
|
this.nextIdMap = /* @__PURE__ */ new Map();
|
|
2172
2277
|
this.lastIdMap = /* @__PURE__ */ new Map();
|
|
2173
2278
|
this.lastTIndex = -1;
|
|
2174
|
-
|
|
2279
|
+
const defaultOptions = {
|
|
2175
2280
|
mode: "module",
|
|
2176
2281
|
prefixIdentifiers: true,
|
|
2177
2282
|
sourceMap: false,
|
|
@@ -2186,7 +2291,8 @@ var CodegenContext = class {
|
|
|
2186
2291
|
inline: false,
|
|
2187
2292
|
bindingMetadata: {},
|
|
2188
2293
|
expressionPlugins: []
|
|
2189
|
-
}
|
|
2294
|
+
};
|
|
2295
|
+
this.options = (0, _vue_shared.extend)(defaultOptions, options);
|
|
2190
2296
|
this.block = ir.block;
|
|
2191
2297
|
this.bindingNames = new Set(this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []);
|
|
2192
2298
|
this.initNextIdMap();
|
|
@@ -2207,7 +2313,7 @@ function generate(ir, options = {}) {
|
|
|
2207
2313
|
push(INDENT_END, NEWLINE);
|
|
2208
2314
|
if (!inline) push("}");
|
|
2209
2315
|
const delegates = genDelegates(context);
|
|
2210
|
-
const templates = genTemplates(ir.template
|
|
2316
|
+
const templates = genTemplates(ir.template.entries, context);
|
|
2211
2317
|
const preamble = genHelperImports(context) + genAssetImports(context) + templates + delegates;
|
|
2212
2318
|
const newlineCount = [...preamble].filter((c) => c === "\n").length;
|
|
2213
2319
|
if (newlineCount && !inline) frag.unshift(...new Array(newlineCount).fill(LF));
|
|
@@ -2239,79 +2345,6 @@ function genAssetImports({ ir }) {
|
|
|
2239
2345
|
return imports;
|
|
2240
2346
|
}
|
|
2241
2347
|
//#endregion
|
|
2242
|
-
//#region packages/compiler-vapor/src/transforms/transformChildren.ts
|
|
2243
|
-
const transformChildren = (node, context) => {
|
|
2244
|
-
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
2245
|
-
if (!isFragment && node.type !== 1) return;
|
|
2246
|
-
for (const [i, child] of node.children.entries()) {
|
|
2247
|
-
const childContext = context.create(child, i);
|
|
2248
|
-
transformNode(childContext);
|
|
2249
|
-
const childDynamic = childContext.dynamic;
|
|
2250
|
-
if (isFragment) {
|
|
2251
|
-
childContext.reference();
|
|
2252
|
-
childContext.registerTemplate();
|
|
2253
|
-
if (!(childDynamic.flags & 2) || childDynamic.flags & 4) context.block.returns.push(childContext.dynamic.id);
|
|
2254
|
-
} else context.childrenTemplate.push(childContext.template);
|
|
2255
|
-
if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & 2 || childDynamic.flags & 4) context.dynamic.hasDynamicChild = true;
|
|
2256
|
-
context.dynamic.children[i] = childDynamic;
|
|
2257
|
-
}
|
|
2258
|
-
if (!isFragment) processDynamicChildren(context);
|
|
2259
|
-
};
|
|
2260
|
-
function processDynamicChildren(context) {
|
|
2261
|
-
let prevDynamics = [];
|
|
2262
|
-
let staticCount = 0;
|
|
2263
|
-
let dynamicCount = 0;
|
|
2264
|
-
let lastInsertionChild;
|
|
2265
|
-
const children = context.dynamic.children;
|
|
2266
|
-
let logicalIndex = 0;
|
|
2267
|
-
for (const [index, child] of children.entries()) {
|
|
2268
|
-
if (child.flags & 4) {
|
|
2269
|
-
child.logicalIndex = logicalIndex;
|
|
2270
|
-
prevDynamics.push(lastInsertionChild = child);
|
|
2271
|
-
logicalIndex++;
|
|
2272
|
-
}
|
|
2273
|
-
if (!(child.flags & 2)) {
|
|
2274
|
-
child.logicalIndex = logicalIndex;
|
|
2275
|
-
if (prevDynamics.length) {
|
|
2276
|
-
if (staticCount) {
|
|
2277
|
-
context.childrenTemplate[index - prevDynamics.length] = `<!>`;
|
|
2278
|
-
prevDynamics[0].flags -= 2;
|
|
2279
|
-
const anchor = prevDynamics[0].anchor = context.increaseId();
|
|
2280
|
-
registerInsertion(prevDynamics, context, anchor);
|
|
2281
|
-
} else registerInsertion(prevDynamics, context, -1);
|
|
2282
|
-
dynamicCount += prevDynamics.length;
|
|
2283
|
-
prevDynamics = [];
|
|
2284
|
-
}
|
|
2285
|
-
staticCount++;
|
|
2286
|
-
logicalIndex++;
|
|
2287
|
-
}
|
|
2288
|
-
}
|
|
2289
|
-
if (prevDynamics.length) registerInsertion(prevDynamics, context, dynamicCount + staticCount, true);
|
|
2290
|
-
if (lastInsertionChild && lastInsertionChild.operation) lastInsertionChild.operation.last = true;
|
|
2291
|
-
}
|
|
2292
|
-
function registerInsertion(dynamics, context, anchor, append) {
|
|
2293
|
-
for (const child of dynamics) {
|
|
2294
|
-
const logicalIndex = child.logicalIndex;
|
|
2295
|
-
if (child.template != null) context.registerOperation({
|
|
2296
|
-
type: 10,
|
|
2297
|
-
elements: dynamics.map((child) => child.id),
|
|
2298
|
-
parent: context.reference(),
|
|
2299
|
-
anchor: append ? void 0 : anchor
|
|
2300
|
-
});
|
|
2301
|
-
else if (child.operation && isBlockOperation(child.operation)) {
|
|
2302
|
-
child.operation.parent = context.reference();
|
|
2303
|
-
child.operation.anchor = anchor;
|
|
2304
|
-
child.operation.logicalIndex = logicalIndex;
|
|
2305
|
-
child.operation.append = append;
|
|
2306
|
-
}
|
|
2307
|
-
}
|
|
2308
|
-
}
|
|
2309
|
-
//#endregion
|
|
2310
|
-
//#region packages/compiler-vapor/src/transforms/vOnce.ts
|
|
2311
|
-
const transformVOnce = (node, context) => {
|
|
2312
|
-
if (node.type === 1 && (0, _vue_compiler_dom.findDir)(node, "once", true)) context.inVOnce = true;
|
|
2313
|
-
};
|
|
2314
|
-
//#endregion
|
|
2315
2348
|
//#region packages/compiler-vapor/src/transforms/vBind.ts
|
|
2316
2349
|
function normalizeBindShorthand(arg, context) {
|
|
2317
2350
|
if (arg.type !== 4 || !arg.isStatic) {
|
|
@@ -2361,13 +2394,13 @@ const transformElement = (node, context) => {
|
|
|
2361
2394
|
return function postTransformElement() {
|
|
2362
2395
|
({node} = context);
|
|
2363
2396
|
if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) return;
|
|
2364
|
-
const
|
|
2365
|
-
const isComponent = node.tagType === 1 ||
|
|
2397
|
+
const useCreateElement = shouldUseCreateElement(node, context);
|
|
2398
|
+
const isComponent = node.tagType === 1 || useCreateElement;
|
|
2366
2399
|
const isDynamicComponent = isComponentTag(node.tag);
|
|
2367
2400
|
const staticKey = resolveStaticKey(node, context, isComponent);
|
|
2368
2401
|
const propsResult = buildProps(node, context, isComponent, isDynamicComponent, getEffectIndex);
|
|
2369
2402
|
const singleRoot = isSingleRoot(context);
|
|
2370
|
-
if (isComponent) transformComponentElement(node, propsResult, staticKey, singleRoot, context, isDynamicComponent,
|
|
2403
|
+
if (isComponent) transformComponentElement(node, propsResult, staticKey, singleRoot, context, isDynamicComponent, useCreateElement);
|
|
2371
2404
|
else transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, context.root === context.effectiveParent || canOmitEndTag(node, context));
|
|
2372
2405
|
if (parentSlots) context.slots = parentSlots;
|
|
2373
2406
|
};
|
|
@@ -2391,11 +2424,11 @@ function isSingleRoot(context) {
|
|
|
2391
2424
|
}
|
|
2392
2425
|
return context.root === parent;
|
|
2393
2426
|
}
|
|
2394
|
-
function transformComponentElement(node, propsResult, staticKey, singleRoot, context, isDynamicComponent,
|
|
2427
|
+
function transformComponentElement(node, propsResult, staticKey, singleRoot, context, isDynamicComponent, useCreateElement) {
|
|
2395
2428
|
const dynamicComponent = isDynamicComponent ? resolveDynamicComponent(node) : void 0;
|
|
2396
2429
|
let { tag } = node;
|
|
2397
2430
|
let asset = true;
|
|
2398
|
-
if (!dynamicComponent && !
|
|
2431
|
+
if (!dynamicComponent && !useCreateElement) {
|
|
2399
2432
|
const fromSetup = resolveSetupReference(tag, context);
|
|
2400
2433
|
if (fromSetup) {
|
|
2401
2434
|
tag = fromSetup;
|
|
@@ -2424,6 +2457,7 @@ function transformComponentElement(node, propsResult, staticKey, singleRoot, con
|
|
|
2424
2457
|
context.dynamic.operation = {
|
|
2425
2458
|
type: 12,
|
|
2426
2459
|
id,
|
|
2460
|
+
...context.effectBoundary(),
|
|
2427
2461
|
tag,
|
|
2428
2462
|
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
|
|
2429
2463
|
asset,
|
|
@@ -2431,7 +2465,7 @@ function transformComponentElement(node, propsResult, staticKey, singleRoot, con
|
|
|
2431
2465
|
slots: [...context.slots],
|
|
2432
2466
|
once: context.inVOnce,
|
|
2433
2467
|
dynamic: dynamicComponent,
|
|
2434
|
-
|
|
2468
|
+
useCreateElement
|
|
2435
2469
|
};
|
|
2436
2470
|
if (staticKey) context.registerOperation(createSetBlockKey(id, staticKey));
|
|
2437
2471
|
context.slots = [];
|
|
@@ -2493,7 +2527,7 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
2493
2527
|
}
|
|
2494
2528
|
template += `>` + context.childrenTemplate.join("");
|
|
2495
2529
|
if (!(0, _vue_shared.isVoidTag)(tag) && !omitEndTag) template += `</${tag}>`;
|
|
2496
|
-
|
|
2530
|
+
context.templateRoot = singleRoot;
|
|
2497
2531
|
if (context.parent && context.parent.node.type === 1 && !(0, _vue_compiler_dom.isValidHTMLNesting)(context.parent.node.tag, tag)) {
|
|
2498
2532
|
context.reference();
|
|
2499
2533
|
context.dynamic.template = context.pushTemplate(template);
|
|
@@ -2634,6 +2668,85 @@ function mergePropValues(existing, incoming) {
|
|
|
2634
2668
|
function isComponentTag(tag) {
|
|
2635
2669
|
return tag === "component" || tag === "Component";
|
|
2636
2670
|
}
|
|
2671
|
+
function shouldUseCreateElement(node, context) {
|
|
2672
|
+
return context.options.isCustomElement(node.tag) || node.tagType === 0 && node.tag === "template";
|
|
2673
|
+
}
|
|
2674
|
+
//#endregion
|
|
2675
|
+
//#region packages/compiler-vapor/src/transforms/transformChildren.ts
|
|
2676
|
+
const transformChildren = (node, context) => {
|
|
2677
|
+
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
2678
|
+
if (!isFragment && node.type !== 1) return;
|
|
2679
|
+
const useCreateElement = node.type === 1 && shouldUseCreateElement(node, context);
|
|
2680
|
+
for (const [i, child] of node.children.entries()) {
|
|
2681
|
+
const childContext = context.create(child, i);
|
|
2682
|
+
transformNode(childContext);
|
|
2683
|
+
const childDynamic = childContext.dynamic;
|
|
2684
|
+
if (isFragment) {
|
|
2685
|
+
childContext.reference();
|
|
2686
|
+
childContext.registerTemplate();
|
|
2687
|
+
if (!(childDynamic.flags & 2) || childDynamic.flags & 4) context.block.returns.push(childContext.dynamic.id);
|
|
2688
|
+
} else if (useCreateElement) {
|
|
2689
|
+
if (childContext.template !== "" || childDynamic.template != null || childDynamic.id !== void 0 || childDynamic.operation !== void 0 || childDynamic.hasDynamicChild === true) {
|
|
2690
|
+
childContext.reference();
|
|
2691
|
+
childContext.registerTemplate();
|
|
2692
|
+
childDynamic.flags |= 6;
|
|
2693
|
+
}
|
|
2694
|
+
} else context.childrenTemplate.push(childContext.template);
|
|
2695
|
+
if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & 2 || childDynamic.flags & 4) context.dynamic.hasDynamicChild = true;
|
|
2696
|
+
context.dynamic.children[i] = childDynamic;
|
|
2697
|
+
}
|
|
2698
|
+
if (!isFragment) processDynamicChildren(context);
|
|
2699
|
+
};
|
|
2700
|
+
function processDynamicChildren(context) {
|
|
2701
|
+
let prevDynamics = [];
|
|
2702
|
+
let staticCount = 0;
|
|
2703
|
+
const children = context.dynamic.children;
|
|
2704
|
+
let logicalIndex = 0;
|
|
2705
|
+
for (const [index, child] of children.entries()) {
|
|
2706
|
+
if (child.flags & 4) {
|
|
2707
|
+
child.logicalIndex = logicalIndex;
|
|
2708
|
+
prevDynamics.push(child);
|
|
2709
|
+
logicalIndex++;
|
|
2710
|
+
}
|
|
2711
|
+
if (!(child.flags & 2)) {
|
|
2712
|
+
child.logicalIndex = logicalIndex;
|
|
2713
|
+
if (prevDynamics.length) {
|
|
2714
|
+
if (staticCount) {
|
|
2715
|
+
context.childrenTemplate[index - prevDynamics.length] = `<!>`;
|
|
2716
|
+
prevDynamics[0].flags -= 2;
|
|
2717
|
+
const anchor = prevDynamics[0].anchor = context.increaseId();
|
|
2718
|
+
registerInsertion(prevDynamics, context, anchor);
|
|
2719
|
+
} else registerInsertion(prevDynamics, context, -1);
|
|
2720
|
+
prevDynamics = [];
|
|
2721
|
+
}
|
|
2722
|
+
staticCount++;
|
|
2723
|
+
logicalIndex++;
|
|
2724
|
+
}
|
|
2725
|
+
}
|
|
2726
|
+
if (prevDynamics.length) registerInsertion(prevDynamics, context, prevDynamics[0].logicalIndex, true);
|
|
2727
|
+
}
|
|
2728
|
+
function registerInsertion(dynamics, context, anchor, append) {
|
|
2729
|
+
for (const child of dynamics) {
|
|
2730
|
+
const logicalIndex = child.logicalIndex;
|
|
2731
|
+
if (child.template != null) context.registerOperation({
|
|
2732
|
+
type: 10,
|
|
2733
|
+
elements: dynamics.map((child) => child.id),
|
|
2734
|
+
parent: context.reference(),
|
|
2735
|
+
anchor: append ? void 0 : anchor
|
|
2736
|
+
});
|
|
2737
|
+
else if (child.operation && isBlockOperation(child.operation)) {
|
|
2738
|
+
child.operation.parent = context.reference();
|
|
2739
|
+
child.operation.anchor = anchor;
|
|
2740
|
+
child.operation.logicalIndex = logicalIndex;
|
|
2741
|
+
child.operation.append = append;
|
|
2742
|
+
}
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
//#endregion
|
|
2746
|
+
//#region packages/compiler-vapor/src/transforms/vOnce.ts
|
|
2747
|
+
const transformVOnce = (node, context) => {
|
|
2748
|
+
if (node.type === 1 && (0, _vue_compiler_dom.findDir)(node, "once", true)) context.inVOnce = true;
|
|
2749
|
+
};
|
|
2637
2750
|
//#endregion
|
|
2638
2751
|
//#region packages/compiler-vapor/src/transforms/vHtml.ts
|
|
2639
2752
|
const transformVHtml = (dir, node, context) => {
|
|
@@ -2674,6 +2787,141 @@ function makeMap$1(str) {
|
|
|
2674
2787
|
*/
|
|
2675
2788
|
const isVoidTag = /* @__PURE__ */ makeMap$1("area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr");
|
|
2676
2789
|
//#endregion
|
|
2790
|
+
//#region packages/compiler-vapor/src/transforms/transformText.ts
|
|
2791
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
2792
|
+
function markNonTemplate(node, context) {
|
|
2793
|
+
let seenNodes = seen.get(context.root);
|
|
2794
|
+
if (!seenNodes) {
|
|
2795
|
+
seenNodes = /* @__PURE__ */ new WeakSet();
|
|
2796
|
+
seen.set(context.root, seenNodes);
|
|
2797
|
+
}
|
|
2798
|
+
seenNodes.add(node);
|
|
2799
|
+
}
|
|
2800
|
+
const transformText = (node, context) => {
|
|
2801
|
+
if (!seen.has(context.root)) seen.set(context.root, /* @__PURE__ */ new WeakSet());
|
|
2802
|
+
if (seen.get(context.root).has(node)) {
|
|
2803
|
+
context.dynamic.flags |= 2;
|
|
2804
|
+
return;
|
|
2805
|
+
}
|
|
2806
|
+
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
2807
|
+
if ((isFragment || node.type === 1 && node.tagType === 0) && node.children.length) {
|
|
2808
|
+
let hasInterp = false;
|
|
2809
|
+
let isAllTextLike = true;
|
|
2810
|
+
for (const c of node.children) if (c.type === 5) hasInterp = true;
|
|
2811
|
+
else if (c.type !== 2) isAllTextLike = false;
|
|
2812
|
+
if (!isFragment && isAllTextLike && hasInterp) {
|
|
2813
|
+
const elementContext = context;
|
|
2814
|
+
if (shouldUseCreateElement(node, elementContext)) processCreateElementTextContainer(node.children, elementContext);
|
|
2815
|
+
else processTextContainer(node.children, elementContext);
|
|
2816
|
+
} else if (hasInterp) for (let i = 0; i < node.children.length; i++) {
|
|
2817
|
+
const c = node.children[i];
|
|
2818
|
+
const prev = node.children[i - 1];
|
|
2819
|
+
if (c.type === 5 && prev && prev.type === 2) markNonTemplate(prev, context);
|
|
2820
|
+
}
|
|
2821
|
+
} else if (node.type === 5) processInterpolation(context);
|
|
2822
|
+
else if (node.type === 2) {
|
|
2823
|
+
var _context$parent;
|
|
2824
|
+
const parent = (_context$parent = context.parent) === null || _context$parent === void 0 ? void 0 : _context$parent.node;
|
|
2825
|
+
if (parent && parent.type === 1 && shouldUseCreateElement(parent, context.parent) && node.content[0] === "<") {
|
|
2826
|
+
materializeLiteralTextNode((0, _vue_compiler_dom.createSimpleExpression)(node.content, true, node.loc), context);
|
|
2827
|
+
return;
|
|
2828
|
+
}
|
|
2829
|
+
const isRootText = !parent || parent.type === 0 || parent.type === 1 && (parent.tagType === 3 || parent.tagType === 1);
|
|
2830
|
+
context.template += isRootText ? node.content : (0, _vue_shared.escapeHtml)(node.content);
|
|
2831
|
+
}
|
|
2832
|
+
};
|
|
2833
|
+
function processInterpolation(context) {
|
|
2834
|
+
const parentNode = context.parent.node;
|
|
2835
|
+
const children = parentNode.children;
|
|
2836
|
+
const nexts = children.slice(context.index);
|
|
2837
|
+
const idx = nexts.findIndex((n) => !isTextLike(n));
|
|
2838
|
+
const nodes = idx > -1 ? nexts.slice(0, idx) : nexts;
|
|
2839
|
+
const prev = children[context.index - 1];
|
|
2840
|
+
if (prev && prev.type === 2) nodes.unshift(prev);
|
|
2841
|
+
const values = processTextLikeChildren(nodes, context);
|
|
2842
|
+
if (values.length === 0 && parentNode.type !== 0) return;
|
|
2843
|
+
const literalValues = values.map((v) => getLiteralExpressionValue(v));
|
|
2844
|
+
if (literalValues.every((v) => v != null) && parentNode.type !== 0) {
|
|
2845
|
+
const text = literalValues.join("");
|
|
2846
|
+
if (parentNode.type === 1 && shouldUseCreateElement(parentNode, context.parent) && text[0] === "<") {
|
|
2847
|
+
materializeLiteralTextNode((0, _vue_compiler_dom.createSimpleExpression)(text, true, context.node.loc), context);
|
|
2848
|
+
return;
|
|
2849
|
+
}
|
|
2850
|
+
const isElementChild = parentNode.type === 1 && parentNode.tagType === 0;
|
|
2851
|
+
context.template += isElementChild ? (0, _vue_shared.escapeHtml)(text) : text;
|
|
2852
|
+
return;
|
|
2853
|
+
}
|
|
2854
|
+
context.template += " ";
|
|
2855
|
+
const id = context.reference();
|
|
2856
|
+
if (values.length === 0) return;
|
|
2857
|
+
context.registerEffect(values, {
|
|
2858
|
+
type: 5,
|
|
2859
|
+
element: id,
|
|
2860
|
+
values
|
|
2861
|
+
});
|
|
2862
|
+
}
|
|
2863
|
+
function processTextContainer(children, context) {
|
|
2864
|
+
const values = processTextLikeChildren(children, context);
|
|
2865
|
+
const literals = values.map((value) => getLiteralExpressionValue(value));
|
|
2866
|
+
if (literals.every((l) => l != null)) context.childrenTemplate = literals.map((l) => (0, _vue_shared.escapeHtml)(String(l)));
|
|
2867
|
+
else {
|
|
2868
|
+
context.childrenTemplate = [" "];
|
|
2869
|
+
context.registerOperation({
|
|
2870
|
+
type: 18,
|
|
2871
|
+
parent: context.reference()
|
|
2872
|
+
});
|
|
2873
|
+
context.registerEffect(values, {
|
|
2874
|
+
type: 5,
|
|
2875
|
+
element: context.reference(),
|
|
2876
|
+
values,
|
|
2877
|
+
generated: true
|
|
2878
|
+
});
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
function registerSyntheticTextChild(context, template, values) {
|
|
2882
|
+
const id = context.increaseId();
|
|
2883
|
+
context.dynamic.children[context.node.children.length] = {
|
|
2884
|
+
id,
|
|
2885
|
+
flags: 6,
|
|
2886
|
+
children: [],
|
|
2887
|
+
template: context.pushTemplate(template)
|
|
2888
|
+
};
|
|
2889
|
+
context.dynamic.hasDynamicChild = true;
|
|
2890
|
+
if (values && values.length) context.registerEffect(values, {
|
|
2891
|
+
type: 5,
|
|
2892
|
+
element: id,
|
|
2893
|
+
values
|
|
2894
|
+
});
|
|
2895
|
+
return id;
|
|
2896
|
+
}
|
|
2897
|
+
function processCreateElementTextContainer(children, context) {
|
|
2898
|
+
registerSyntheticTextChild(context, "", processTextLikeChildren(children, context));
|
|
2899
|
+
}
|
|
2900
|
+
function materializeLiteralTextNode(value, context) {
|
|
2901
|
+
const id = context.reference();
|
|
2902
|
+
context.dynamic.flags |= 6;
|
|
2903
|
+
context.dynamic.template = context.pushTemplate("");
|
|
2904
|
+
context.registerEffect([value], {
|
|
2905
|
+
type: 5,
|
|
2906
|
+
element: id,
|
|
2907
|
+
values: [value]
|
|
2908
|
+
});
|
|
2909
|
+
}
|
|
2910
|
+
function processTextLikeChildren(nodes, context) {
|
|
2911
|
+
const exps = [];
|
|
2912
|
+
for (const node of nodes) {
|
|
2913
|
+
let exp;
|
|
2914
|
+
markNonTemplate(node, context);
|
|
2915
|
+
if (node.type === 2) exp = (0, _vue_compiler_dom.createSimpleExpression)(node.content, true, node.loc);
|
|
2916
|
+
else exp = node.content;
|
|
2917
|
+
if (exp.content) exps.push(exp);
|
|
2918
|
+
}
|
|
2919
|
+
return exps;
|
|
2920
|
+
}
|
|
2921
|
+
function isTextLike(node) {
|
|
2922
|
+
return node.type === 5 || node.type === 2;
|
|
2923
|
+
}
|
|
2924
|
+
//#endregion
|
|
2677
2925
|
//#region packages/compiler-vapor/src/transforms/vText.ts
|
|
2678
2926
|
const transformVText = (dir, node, context) => {
|
|
2679
2927
|
let { exp, loc } = dir;
|
|
@@ -2684,22 +2932,41 @@ const transformVText = (dir, node, context) => {
|
|
|
2684
2932
|
if (node.children.length) {
|
|
2685
2933
|
context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(57, loc));
|
|
2686
2934
|
context.childrenTemplate.length = 0;
|
|
2935
|
+
for (const child of node.children) markNonTemplate(child, context);
|
|
2687
2936
|
}
|
|
2688
2937
|
if (isVoidTag(context.node.tag)) return;
|
|
2689
2938
|
const literal = getLiteralExpressionValue(exp);
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2939
|
+
const useCreateElement = shouldUseCreateElement(context.node, context);
|
|
2940
|
+
if (literal != null) if (useCreateElement) {
|
|
2941
|
+
const id = registerSyntheticTextChild(context, "", [exp]);
|
|
2942
|
+
context.registerOperation({
|
|
2943
|
+
type: 10,
|
|
2944
|
+
elements: [id],
|
|
2696
2945
|
parent: context.reference()
|
|
2697
2946
|
});
|
|
2947
|
+
} else context.childrenTemplate = [String(literal)];
|
|
2948
|
+
else {
|
|
2949
|
+
const isComponent = node.tagType === 1;
|
|
2950
|
+
let id;
|
|
2951
|
+
if (useCreateElement) {
|
|
2952
|
+
id = registerSyntheticTextChild(context, "");
|
|
2953
|
+
context.registerOperation({
|
|
2954
|
+
type: 10,
|
|
2955
|
+
elements: [id],
|
|
2956
|
+
parent: context.reference()
|
|
2957
|
+
});
|
|
2958
|
+
} else if (!isComponent) {
|
|
2959
|
+
context.childrenTemplate = [" "];
|
|
2960
|
+
context.registerOperation({
|
|
2961
|
+
type: 18,
|
|
2962
|
+
parent: context.reference()
|
|
2963
|
+
});
|
|
2964
|
+
}
|
|
2698
2965
|
context.registerEffect([exp], {
|
|
2699
2966
|
type: 5,
|
|
2700
|
-
element: context.reference(),
|
|
2967
|
+
element: useCreateElement ? id : context.reference(),
|
|
2701
2968
|
values: [exp],
|
|
2702
|
-
generated:
|
|
2969
|
+
generated: !useCreateElement,
|
|
2703
2970
|
isComponent
|
|
2704
2971
|
});
|
|
2705
2972
|
}
|
|
@@ -2713,6 +2980,7 @@ const transformVOn = (dir, node, context) => {
|
|
|
2713
2980
|
const isSlotOutlet = node.tag === "slot";
|
|
2714
2981
|
if (!exp && !modifiers.length) context.options.onError((0, _vue_compiler_dom.createCompilerError)(35, loc));
|
|
2715
2982
|
arg = resolveExpression(arg);
|
|
2983
|
+
if (arg.isStatic && arg.content.startsWith("vue:")) arg = (0, _vue_shared.extend)({}, arg, { content: `vnode-${arg.content.slice(4)}` });
|
|
2716
2984
|
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = (0, _vue_compiler_dom.resolveModifiers)(arg.isStatic ? `on${arg.content}` : arg, modifiers, null, loc);
|
|
2717
2985
|
let keyOverride;
|
|
2718
2986
|
const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
|
|
@@ -2812,96 +3080,6 @@ const transformTemplateRef = (node, context) => {
|
|
|
2812
3080
|
};
|
|
2813
3081
|
};
|
|
2814
3082
|
//#endregion
|
|
2815
|
-
//#region packages/compiler-vapor/src/transforms/transformText.ts
|
|
2816
|
-
const seen = /* @__PURE__ */ new WeakMap();
|
|
2817
|
-
function markNonTemplate(node, context) {
|
|
2818
|
-
seen.get(context.root).add(node);
|
|
2819
|
-
}
|
|
2820
|
-
const transformText = (node, context) => {
|
|
2821
|
-
if (!seen.has(context.root)) seen.set(context.root, /* @__PURE__ */ new WeakSet());
|
|
2822
|
-
if (seen.get(context.root).has(node)) {
|
|
2823
|
-
context.dynamic.flags |= 2;
|
|
2824
|
-
return;
|
|
2825
|
-
}
|
|
2826
|
-
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
2827
|
-
if ((isFragment || node.type === 1 && node.tagType === 0) && node.children.length) {
|
|
2828
|
-
let hasInterp = false;
|
|
2829
|
-
let isAllTextLike = true;
|
|
2830
|
-
for (const c of node.children) if (c.type === 5) hasInterp = true;
|
|
2831
|
-
else if (c.type !== 2) isAllTextLike = false;
|
|
2832
|
-
if (!isFragment && isAllTextLike && hasInterp) processTextContainer(node.children, context);
|
|
2833
|
-
else if (hasInterp) for (let i = 0; i < node.children.length; i++) {
|
|
2834
|
-
const c = node.children[i];
|
|
2835
|
-
const prev = node.children[i - 1];
|
|
2836
|
-
if (c.type === 5 && prev && prev.type === 2) markNonTemplate(prev, context);
|
|
2837
|
-
}
|
|
2838
|
-
} else if (node.type === 5) processInterpolation(context);
|
|
2839
|
-
else if (node.type === 2) {
|
|
2840
|
-
var _context$parent;
|
|
2841
|
-
const parent = (_context$parent = context.parent) === null || _context$parent === void 0 ? void 0 : _context$parent.node;
|
|
2842
|
-
const isRootText = !parent || parent.type === 0 || parent.type === 1 && (parent.tagType === 3 || parent.tagType === 1);
|
|
2843
|
-
context.template += isRootText ? node.content : (0, _vue_shared.escapeHtml)(node.content);
|
|
2844
|
-
}
|
|
2845
|
-
};
|
|
2846
|
-
function processInterpolation(context) {
|
|
2847
|
-
const parentNode = context.parent.node;
|
|
2848
|
-
const children = parentNode.children;
|
|
2849
|
-
const nexts = children.slice(context.index);
|
|
2850
|
-
const idx = nexts.findIndex((n) => !isTextLike(n));
|
|
2851
|
-
const nodes = idx > -1 ? nexts.slice(0, idx) : nexts;
|
|
2852
|
-
const prev = children[context.index - 1];
|
|
2853
|
-
if (prev && prev.type === 2) nodes.unshift(prev);
|
|
2854
|
-
const values = processTextLikeChildren(nodes, context);
|
|
2855
|
-
if (values.length === 0 && parentNode.type !== 0) return;
|
|
2856
|
-
const literalValues = values.map((v) => getLiteralExpressionValue(v));
|
|
2857
|
-
if (literalValues.every((v) => v != null) && parentNode.type !== 0) {
|
|
2858
|
-
const text = literalValues.join("");
|
|
2859
|
-
const isElementChild = parentNode.type === 1 && parentNode.tagType === 0;
|
|
2860
|
-
context.template += isElementChild ? (0, _vue_shared.escapeHtml)(text) : text;
|
|
2861
|
-
return;
|
|
2862
|
-
}
|
|
2863
|
-
context.template += " ";
|
|
2864
|
-
const id = context.reference();
|
|
2865
|
-
if (values.length === 0) return;
|
|
2866
|
-
context.registerEffect(values, {
|
|
2867
|
-
type: 5,
|
|
2868
|
-
element: id,
|
|
2869
|
-
values
|
|
2870
|
-
});
|
|
2871
|
-
}
|
|
2872
|
-
function processTextContainer(children, context) {
|
|
2873
|
-
const values = processTextLikeChildren(children, context);
|
|
2874
|
-
const literals = values.map((value) => getLiteralExpressionValue(value));
|
|
2875
|
-
if (literals.every((l) => l != null)) context.childrenTemplate = literals.map((l) => (0, _vue_shared.escapeHtml)(String(l)));
|
|
2876
|
-
else {
|
|
2877
|
-
context.childrenTemplate = [" "];
|
|
2878
|
-
context.registerOperation({
|
|
2879
|
-
type: 18,
|
|
2880
|
-
parent: context.reference()
|
|
2881
|
-
});
|
|
2882
|
-
context.registerEffect(values, {
|
|
2883
|
-
type: 5,
|
|
2884
|
-
element: context.reference(),
|
|
2885
|
-
values,
|
|
2886
|
-
generated: true
|
|
2887
|
-
});
|
|
2888
|
-
}
|
|
2889
|
-
}
|
|
2890
|
-
function processTextLikeChildren(nodes, context) {
|
|
2891
|
-
const exps = [];
|
|
2892
|
-
for (const node of nodes) {
|
|
2893
|
-
let exp;
|
|
2894
|
-
markNonTemplate(node, context);
|
|
2895
|
-
if (node.type === 2) exp = (0, _vue_compiler_dom.createSimpleExpression)(node.content, true, node.loc);
|
|
2896
|
-
else exp = node.content;
|
|
2897
|
-
if (exp.content) exps.push(exp);
|
|
2898
|
-
}
|
|
2899
|
-
return exps;
|
|
2900
|
-
}
|
|
2901
|
-
function isTextLike(node) {
|
|
2902
|
-
return node.type === 5 || node.type === 2;
|
|
2903
|
-
}
|
|
2904
|
-
//#endregion
|
|
2905
3083
|
//#region packages/compiler-vapor/src/transforms/vModel.ts
|
|
2906
3084
|
const transformVModel = (dir, node, context) => {
|
|
2907
3085
|
const { exp, arg } = dir;
|
|
@@ -3021,6 +3199,7 @@ function processIf(node, dir, context) {
|
|
|
3021
3199
|
context.dynamic.operation = {
|
|
3022
3200
|
type: 15,
|
|
3023
3201
|
id,
|
|
3202
|
+
...context.effectBoundary(),
|
|
3024
3203
|
blockShape: encodeIfBlockShape(branch, forceMultiRoot),
|
|
3025
3204
|
condition: dir.exp,
|
|
3026
3205
|
positive: branch,
|
|
@@ -3121,6 +3300,7 @@ function processFor(node, dir, context) {
|
|
|
3121
3300
|
context.dynamic.operation = {
|
|
3122
3301
|
type: 16,
|
|
3123
3302
|
id,
|
|
3303
|
+
...context.effectBoundary(),
|
|
3124
3304
|
source,
|
|
3125
3305
|
value,
|
|
3126
3306
|
key,
|
|
@@ -3173,6 +3353,7 @@ const transformSlotOutlet = (node, context) => {
|
|
|
3173
3353
|
context.dynamic.operation = {
|
|
3174
3354
|
type: 13,
|
|
3175
3355
|
id,
|
|
3356
|
+
...context.effectBoundary(),
|
|
3176
3357
|
name: slotName,
|
|
3177
3358
|
props: irProps,
|
|
3178
3359
|
fallback,
|
|
@@ -3372,6 +3553,7 @@ const transformKey = (node, context) => {
|
|
|
3372
3553
|
context.dynamic.operation = {
|
|
3373
3554
|
type: 17,
|
|
3374
3555
|
id,
|
|
3556
|
+
...context.effectBoundary(),
|
|
3375
3557
|
value,
|
|
3376
3558
|
block
|
|
3377
3559
|
};
|
|
@@ -3439,6 +3621,7 @@ exports.DynamicFlag = DynamicFlag;
|
|
|
3439
3621
|
exports.IRDynamicPropsKind = IRDynamicPropsKind;
|
|
3440
3622
|
exports.IRNodeTypes = IRNodeTypes;
|
|
3441
3623
|
exports.IRSlotType = IRSlotType;
|
|
3624
|
+
exports.TemplateRegistry = TemplateRegistry;
|
|
3442
3625
|
exports.VaporErrorCodes = VaporErrorCodes;
|
|
3443
3626
|
exports.VaporErrorMessages = VaporErrorMessages;
|
|
3444
3627
|
exports.buildCodeFragment = buildCodeFragment;
|