@dcloudio/uni-cli-shared 3.0.0-5000720260410001 → 3.0.0-5010420260703001
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/constants.d.ts +1 -3
- package/dist/constants.js +2 -6
- package/dist/deps.d.ts +1 -0
- package/dist/deps.js +22 -13
- package/dist/dom2/fontFamily.d.ts +4 -0
- package/dist/dom2/fontFamily.js +21 -0
- package/dist/dom2/index.d.ts +3 -0
- package/dist/dom2/index.js +3 -0
- package/dist/dom2/rootScrollView.d.ts +47 -0
- package/dist/dom2/rootScrollView.js +283 -0
- package/dist/dom2/sharedData.d.ts +4 -0
- package/dist/dom2/sharedData.js +40 -5
- package/dist/dom2/vue.d.ts +17 -0
- package/dist/dom2/vue.js +50 -0
- package/dist/easycom.d.ts +1 -0
- package/dist/easycom.js +23 -9
- package/dist/env/define.d.ts +0 -1
- package/dist/env/define.js +3 -11
- package/dist/hbx/alias.js +66 -10
- package/dist/hbx/log.js +9 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/json/app/manifest/plus.js +9 -1
- package/dist/json/index.d.ts +1 -1
- package/dist/json/index.js +2 -1
- package/dist/json/uni-x/index.d.ts +6 -0
- package/dist/json/uni-x/index.js +54 -1
- package/dist/json/uni-x/manifest.d.ts +1 -1
- package/dist/json/uni-x/manifest.js +2 -1
- package/dist/json/utils.js +24 -0
- package/dist/messages/en.d.ts +10 -2
- package/dist/messages/en.js +10 -2
- package/dist/messages/index.d.ts +20 -4
- package/dist/messages/zh_CN.d.ts +10 -2
- package/dist/messages/zh_CN.js +10 -2
- package/dist/mp/style.js +6 -2
- package/dist/postcss/plugins/stylePluginExternal.d.ts +9 -10
- package/dist/postcss/plugins/stylePluginExternal.js +51 -45
- package/dist/uni_modules.cloud.d.ts +7 -1
- package/dist/uni_modules.cloud.js +131 -14
- package/dist/uni_modules.js +3 -2
- package/dist/utils.js +5 -0
- package/dist/uts.d.ts +1 -0
- package/dist/uts.js +90 -6
- package/dist/vite/autoImport.js +7 -4
- package/dist/vite/cloud.js +13 -6
- package/dist/vite/extApi.js +4 -1
- package/dist/vite/plugins/inject.js +4 -1
- package/dist/vite/plugins/json.js +2 -69
- package/dist/vite/plugins/pre.js +2 -0
- package/dist/vite/plugins/stats.d.ts +5 -1
- package/dist/vite/plugins/stats.js +74 -3
- package/dist/vite/plugins/uts/uni_modules.d.ts +1 -1
- package/dist/vite/plugins/uts/uni_modules.js +30 -12
- package/dist/vite/plugins/vitejs/plugins/css.d.ts +2 -2
- package/dist/vite/plugins/vitejs/plugins/css.js +10 -5
- package/dist/vue/transforms/index.d.ts +1 -0
- package/dist/vue/transforms/index.js +1 -0
- package/dist/vue/transforms/transformTeleport.d.ts +2 -0
- package/dist/vue/transforms/transformTeleport.js +68 -0
- package/dist/vue/transforms/x/transformDirection.js +33 -4
- package/dist/workers.d.ts +1 -0
- package/dist/workers.js +12 -5
- package/dist/x.d.ts +10 -0
- package/dist/x.js +39 -0
- package/lib/dom2/app/@vitejs/plugin-vue/dist/index.cjs +0 -7
- package/lib/dom2/app/@vitejs/plugin-vue/dist/index.mjs +0 -7
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +58 -63
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +58 -63
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +7 -1
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +22 -47
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +12 -23
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +12 -22
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +23 -74
- 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 +3 -20
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +310 -363
- 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 +810 -579
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.d.ts +33 -11114
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +1638 -1250
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +1031 -599
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +470 -328
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +1154 -709
- 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 +16 -25
- package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +16 -25
- package/lib/dom2/app/@vue/shared/dist/shared.d.ts +5 -0
- package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +11 -23
- package/package.json +6 -6
|
@@ -1,15 +1,105 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-vapor v3.6.0-beta.
|
|
2
|
+
* @vue/compiler-vapor v3.6.0-beta.12
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
6
|
-
Object.defineProperties(exports, {
|
|
6
|
+
Object.defineProperties(exports, {
|
|
7
|
+
__esModule: { value: true },
|
|
8
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
9
|
+
});
|
|
7
10
|
let _vue_compiler_dom = require("@vue/compiler-dom");
|
|
8
11
|
let _vue_shared = require("@vue/shared");
|
|
9
12
|
let source_map_js = require("source-map-js");
|
|
10
13
|
let _babel_parser = require("@babel/parser");
|
|
11
14
|
let estree_walker = require("estree-walker");
|
|
12
|
-
|
|
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
|
+
"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
|
|
13
103
|
//#region packages/compiler-vapor/src/transforms/utils.ts
|
|
14
104
|
const newDynamic = () => ({
|
|
15
105
|
flags: 1,
|
|
@@ -50,7 +140,7 @@ function wrapTemplate(node, dirs) {
|
|
|
50
140
|
const reserved = [];
|
|
51
141
|
const pass = [];
|
|
52
142
|
node.props.forEach((prop) => {
|
|
53
|
-
if (prop.type === 7 && dirs.includes(prop.name)) reserved.push(prop);
|
|
143
|
+
if (prop.type === 7 && (dirs.includes(prop.name) || prop.name === "bind" && prop.arg && prop.arg.type === 4 && prop.arg.content === "key" && dirs.includes("key"))) reserved.push(prop);
|
|
54
144
|
else pass.push(prop);
|
|
55
145
|
});
|
|
56
146
|
return (0, _vue_shared.extend)({}, node, {
|
|
@@ -64,7 +154,6 @@ function wrapTemplate(node, dirs) {
|
|
|
64
154
|
const EMPTY_EXPRESSION = (0, _vue_compiler_dom.createSimpleExpression)("", true);
|
|
65
155
|
const TEXT_PLACEHOLDER = "__vapor_dom2_text_placeholder__";
|
|
66
156
|
const TEXT_NODE_PLACEHOLDER = "__vapor_dom2_text_node_placeholder__";
|
|
67
|
-
|
|
68
157
|
//#endregion
|
|
69
158
|
//#region packages/compiler-vapor/src/utils.ts
|
|
70
159
|
const findProp$1 = _vue_compiler_dom.findProp;
|
|
@@ -79,7 +168,7 @@ function isConstantExpression(exp) {
|
|
|
79
168
|
function isStaticExpression(node, bindings) {
|
|
80
169
|
if (node.ast) return (0, _vue_compiler_dom.isConstantNode)(node.ast, bindings);
|
|
81
170
|
else if (node.ast === null) {
|
|
82
|
-
if (!node.isStatic && (node.content === "true" || node.content === "false")) return true;
|
|
171
|
+
if (!node.isStatic && (node.content === "true" || node.content === "false" || node.content === "null")) return true;
|
|
83
172
|
return bindings[node.content] === "literal-const";
|
|
84
173
|
}
|
|
85
174
|
return false;
|
|
@@ -110,13 +199,6 @@ function getLiteralExpressionValue(exp, excludeNumber) {
|
|
|
110
199
|
}
|
|
111
200
|
return exp.isStatic ? exp.content : null;
|
|
112
201
|
}
|
|
113
|
-
function isInTransition(context) {
|
|
114
|
-
const parentNode = context.parent && context.parent.node;
|
|
115
|
-
return !!(parentNode && isTransitionNode(parentNode));
|
|
116
|
-
}
|
|
117
|
-
function isTransitionNode(node) {
|
|
118
|
-
return node.type === 1 && isTransitionTag(node.tag);
|
|
119
|
-
}
|
|
120
202
|
function isTransitionTag(tag) {
|
|
121
203
|
tag = tag.toLowerCase();
|
|
122
204
|
return tag === "transition" || tag === "vaportransition";
|
|
@@ -135,11 +217,15 @@ function isTeleportTag(tag) {
|
|
|
135
217
|
}
|
|
136
218
|
function isBuiltInComponent(tag) {
|
|
137
219
|
if (isTeleportTag(tag)) return "VaporTeleport";
|
|
220
|
+
else if (tag === "Suspense" || tag === "suspense") return "Suspense";
|
|
138
221
|
else if (isKeepAliveTag(tag)) return "VaporKeepAlive";
|
|
139
222
|
else if (isTransitionTag(tag)) return "VaporTransition";
|
|
140
223
|
else if (isTransitionGroupTag(tag)) return "VaporTransitionGroup";
|
|
141
224
|
}
|
|
142
|
-
|
|
225
|
+
function getBlockShape(block) {
|
|
226
|
+
if (block.returns.length === 0) return 0;
|
|
227
|
+
return block.returns.length === 1 ? 1 : 2;
|
|
228
|
+
}
|
|
143
229
|
//#endregion
|
|
144
230
|
//#region packages/compiler-vapor/src/transform.ts
|
|
145
231
|
const generatedVarRE = /^[nxr](\d+)$/;
|
|
@@ -153,6 +239,8 @@ var TransformContext = class TransformContext {
|
|
|
153
239
|
this.index = 0;
|
|
154
240
|
this.block = this.ir.block;
|
|
155
241
|
this.template = "";
|
|
242
|
+
this.templateRoot = false;
|
|
243
|
+
this.templateIndexMap = /* @__PURE__ */ new Map();
|
|
156
244
|
this.childrenTemplate = [];
|
|
157
245
|
this.dynamic = this.ir.block.dynamic;
|
|
158
246
|
this.imports = [];
|
|
@@ -162,9 +250,12 @@ var TransformContext = class TransformContext {
|
|
|
162
250
|
this.component = this.ir.component;
|
|
163
251
|
this.directive = this.ir.directive;
|
|
164
252
|
this.slots = [];
|
|
253
|
+
this.effectIndex = this.block.effect.length;
|
|
254
|
+
this.operationIndex = this.block.operation.length;
|
|
165
255
|
this.isLastEffectiveChild = true;
|
|
166
256
|
this.isOnRightmostPath = true;
|
|
167
|
-
this.
|
|
257
|
+
this.templateCloseTags = void 0;
|
|
258
|
+
this.templateCloseBlocks = false;
|
|
168
259
|
this.globalId = 0;
|
|
169
260
|
this.nextIdMap = null;
|
|
170
261
|
this.ifIndex = 0;
|
|
@@ -179,20 +270,28 @@ var TransformContext = class TransformContext {
|
|
|
179
270
|
this.initNextIdMap();
|
|
180
271
|
}
|
|
181
272
|
enterBlock(ir, isVFor = false) {
|
|
182
|
-
const { block, template, dynamic, childrenTemplate, slots } = this;
|
|
273
|
+
const { block, template, templateRoot, templateIndexMap, dynamic, childrenTemplate, slots, effectIndex, operationIndex } = this;
|
|
183
274
|
this.block = ir;
|
|
184
275
|
this.dynamic = ir.dynamic;
|
|
185
276
|
this.template = "";
|
|
277
|
+
this.templateRoot = false;
|
|
278
|
+
this.templateIndexMap = templateIndexMap;
|
|
186
279
|
this.childrenTemplate = [];
|
|
187
280
|
this.slots = [];
|
|
281
|
+
this.effectIndex = ir.effect.length;
|
|
282
|
+
this.operationIndex = ir.operation.length;
|
|
188
283
|
isVFor && this.inVFor++;
|
|
189
284
|
return () => {
|
|
190
285
|
this.registerTemplate();
|
|
191
286
|
this.block = block;
|
|
192
287
|
this.template = template;
|
|
288
|
+
this.templateRoot = templateRoot;
|
|
289
|
+
this.templateIndexMap = templateIndexMap;
|
|
193
290
|
this.dynamic = dynamic;
|
|
194
291
|
this.childrenTemplate = childrenTemplate;
|
|
195
292
|
this.slots = slots;
|
|
293
|
+
this.effectIndex = effectIndex;
|
|
294
|
+
this.operationIndex = operationIndex;
|
|
196
295
|
isVFor && this.inVFor--;
|
|
197
296
|
};
|
|
198
297
|
}
|
|
@@ -217,60 +316,107 @@ var TransformContext = class TransformContext {
|
|
|
217
316
|
nextIfIndex() {
|
|
218
317
|
return this.ifIndex++;
|
|
219
318
|
}
|
|
220
|
-
|
|
221
|
-
|
|
319
|
+
getTemplateNamespace() {
|
|
320
|
+
return this.node.type === 1 ? this.node.ns : 0;
|
|
321
|
+
}
|
|
322
|
+
canUseStaticTemplate() {
|
|
323
|
+
if (!this.template) return false;
|
|
324
|
+
if (this.inVFor) return false;
|
|
325
|
+
if (this.dynamic.hasDynamicChild) return false;
|
|
326
|
+
if (this.block.effect.length !== this.effectIndex) return false;
|
|
327
|
+
if (this.block.operation.length !== this.operationIndex) return false;
|
|
328
|
+
if (this.node.type === 2 || this.node.type === 3) return true;
|
|
329
|
+
return this.node.type === 1 && this.node.tagType === 0 && !(this.options.isCustomElement(this.node.tag) || this.node.tag === "template");
|
|
330
|
+
}
|
|
331
|
+
pushTemplate(content, { root = false, static: isStatic = false } = {}) {
|
|
332
|
+
const templateKey = JSON.stringify([
|
|
333
|
+
this.getTemplateNamespace(),
|
|
334
|
+
root,
|
|
335
|
+
isStatic,
|
|
336
|
+
content
|
|
337
|
+
]);
|
|
338
|
+
const existingIndex = this.templateIndexMap.get(templateKey);
|
|
222
339
|
if (existingIndex !== void 0) return existingIndex;
|
|
223
|
-
const
|
|
224
|
-
this.ir.template.
|
|
225
|
-
this.ir.
|
|
340
|
+
const ns = this.getTemplateNamespace();
|
|
341
|
+
const newIndex = this.ir.template.entries.length;
|
|
342
|
+
this.ir.template.entries.push({
|
|
343
|
+
content,
|
|
344
|
+
ns,
|
|
345
|
+
root,
|
|
346
|
+
static: isStatic
|
|
347
|
+
});
|
|
348
|
+
this.templateIndexMap.set(templateKey, newIndex);
|
|
226
349
|
return newIndex;
|
|
227
350
|
}
|
|
228
351
|
registerTemplate() {
|
|
229
352
|
if (!this.template) return -1;
|
|
230
|
-
const id = this.pushTemplate(this.template
|
|
353
|
+
const id = this.pushTemplate(this.template, {
|
|
354
|
+
root: this.templateRoot,
|
|
355
|
+
static: this.canUseStaticTemplate()
|
|
356
|
+
});
|
|
231
357
|
return this.dynamic.template = id;
|
|
232
358
|
}
|
|
233
|
-
registerEffect(expressions, operation, getIndex
|
|
359
|
+
registerEffect(expressions, operation, getIndex, getOperationIndex) {
|
|
234
360
|
const operations = [operation].flat();
|
|
235
361
|
expressions = expressions.filter((exp) => !isConstantExpression(exp));
|
|
236
362
|
if (this.inVOnce || expressions.length === 0 || expressions.every((e) => isStaticExpression(e, this.root.options.bindingMetadata))) {
|
|
237
363
|
if (getOperationIndex) {
|
|
238
|
-
|
|
364
|
+
const index = getOperationIndex();
|
|
365
|
+
this.block.operation.splice(index, 0, ...operations);
|
|
366
|
+
this.shiftOperationBoundaries(index, operations.length);
|
|
239
367
|
return;
|
|
240
368
|
}
|
|
241
369
|
return this.registerOperation(...operations);
|
|
242
370
|
}
|
|
243
|
-
this.block.effect.
|
|
371
|
+
const index = getIndex ? getIndex() : this.block.effect.length;
|
|
372
|
+
this.block.effect.splice(index, 0, {
|
|
244
373
|
expressions,
|
|
245
374
|
operations
|
|
246
375
|
});
|
|
376
|
+
if (getIndex) this.shiftEffectBoundaries(index);
|
|
247
377
|
}
|
|
248
378
|
registerOperation(...node) {
|
|
249
379
|
this.block.operation.push(...node);
|
|
250
380
|
}
|
|
381
|
+
effectBoundary() {
|
|
382
|
+
return {
|
|
383
|
+
operationIndex: this.operationIndex,
|
|
384
|
+
effectIndex: this.effectIndex
|
|
385
|
+
};
|
|
386
|
+
}
|
|
251
387
|
create(node, index) {
|
|
252
388
|
let effectiveParent = this;
|
|
253
389
|
while (effectiveParent && effectiveParent.node.type === 1 && effectiveParent.node.tagType === 3) effectiveParent = effectiveParent.parent;
|
|
254
390
|
const isLastEffectiveChild = this.isEffectivelyLastChild(index);
|
|
255
391
|
const isOnRightmostPath = this.isOnRightmostPath && isLastEffectiveChild;
|
|
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
|
-
}
|
|
261
392
|
return Object.assign(Object.create(TransformContext.prototype), this, {
|
|
262
393
|
node,
|
|
263
394
|
parent: this,
|
|
264
395
|
index,
|
|
265
396
|
template: "",
|
|
397
|
+
templateRoot: false,
|
|
266
398
|
childrenTemplate: [],
|
|
399
|
+
templateIndexMap: this.templateIndexMap,
|
|
267
400
|
dynamic: newDynamic(),
|
|
401
|
+
effectIndex: this.block.effect.length,
|
|
402
|
+
operationIndex: this.block.operation.length,
|
|
268
403
|
effectiveParent,
|
|
269
404
|
isLastEffectiveChild,
|
|
270
405
|
isOnRightmostPath,
|
|
271
|
-
|
|
406
|
+
templateCloseTags: this.templateCloseTags,
|
|
407
|
+
templateCloseBlocks: this.templateCloseBlocks
|
|
272
408
|
});
|
|
273
409
|
}
|
|
410
|
+
shiftEffectBoundaries(index, dynamic = this.dynamic) {
|
|
411
|
+
const operation = dynamic.operation;
|
|
412
|
+
if (operation && isBlockOperation(operation) && operation.effectIndex !== void 0 && operation.effectIndex >= index) operation.effectIndex++;
|
|
413
|
+
for (const child of dynamic.children) this.shiftEffectBoundaries(index, child);
|
|
414
|
+
}
|
|
415
|
+
shiftOperationBoundaries(index, offset, dynamic = this.dynamic) {
|
|
416
|
+
const operation = dynamic.operation;
|
|
417
|
+
if (operation && isBlockOperation(operation) && operation.operationIndex !== void 0 && operation.operationIndex >= index) operation.operationIndex += offset;
|
|
418
|
+
for (const child of dynamic.children) this.shiftOperationBoundaries(index, offset, child);
|
|
419
|
+
}
|
|
274
420
|
isEffectivelyLastChild(index) {
|
|
275
421
|
const children = this.node.children;
|
|
276
422
|
if (!children) return true;
|
|
@@ -308,14 +454,11 @@ function transform(node, options = {}) {
|
|
|
308
454
|
type: 0,
|
|
309
455
|
node,
|
|
310
456
|
source: node.source,
|
|
311
|
-
template:
|
|
312
|
-
templateIndexMap: /* @__PURE__ */ new Map(),
|
|
313
|
-
rootTemplateIndexes: /* @__PURE__ */ new Set(),
|
|
457
|
+
template: new TemplateRegistry(),
|
|
314
458
|
component: /* @__PURE__ */ new Set(),
|
|
315
459
|
directive: /* @__PURE__ */ new Set(),
|
|
316
460
|
block: newBlock(node),
|
|
317
|
-
hasTemplateRef: false
|
|
318
|
-
hasDeferredVShow: false
|
|
461
|
+
hasTemplateRef: false
|
|
319
462
|
};
|
|
320
463
|
const context = new TransformContext(ir, node, options);
|
|
321
464
|
transformNode(context);
|
|
@@ -382,7 +525,6 @@ function getNextId(map, n) {
|
|
|
382
525
|
if (map && map.has(n)) return map.get(n);
|
|
383
526
|
return n;
|
|
384
527
|
}
|
|
385
|
-
|
|
386
528
|
//#endregion
|
|
387
529
|
//#region packages/compiler-vapor/src/generators/utils.ts
|
|
388
530
|
const IMPORT_EXP_START = "__IMPORT_EXP_START__";
|
|
@@ -463,6 +605,9 @@ function genCall(name, ...frags) {
|
|
|
463
605
|
hasPlaceholder ? name[1] : "null"
|
|
464
606
|
], ...frags)];
|
|
465
607
|
}
|
|
608
|
+
function getParserOptions(plugins) {
|
|
609
|
+
return { plugins: plugins ? plugins.some((plugin) => plugin === "typescript") ? plugins : [...plugins, "typescript"] : ["typescript"] };
|
|
610
|
+
}
|
|
466
611
|
function codeFragmentToString(code, context) {
|
|
467
612
|
const { options: { sourceMap } } = context;
|
|
468
613
|
const filename = context.options.relativeFilename || context.options.filename;
|
|
@@ -526,85 +671,6 @@ function codeFragmentToString(code, context) {
|
|
|
526
671
|
});
|
|
527
672
|
}
|
|
528
673
|
}
|
|
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
|
-
|
|
608
674
|
//#endregion
|
|
609
675
|
//#region packages/compiler-vapor/src/generators/dom.ts
|
|
610
676
|
function genInsertNode({ parent, elements, anchor }, { helper }) {
|
|
@@ -615,7 +681,6 @@ function genInsertNode({ parent, elements, anchor }, { helper }) {
|
|
|
615
681
|
function genPrependNode(oper, { helper }) {
|
|
616
682
|
return [NEWLINE, ...genCall(helper("prepend"), `n${oper.parent}`, ...oper.elements.map((el) => `n${el}`))];
|
|
617
683
|
}
|
|
618
|
-
|
|
619
684
|
//#endregion
|
|
620
685
|
//#region packages/compiler-vapor/src/generators/expression.ts
|
|
621
686
|
function genExpression(node, context, assignment) {
|
|
@@ -734,8 +799,9 @@ function canPrefix(name) {
|
|
|
734
799
|
}
|
|
735
800
|
function processExpressions(context, expressions, shouldDeclare) {
|
|
736
801
|
const { seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
|
|
737
|
-
const
|
|
738
|
-
const
|
|
802
|
+
const reservedNames = new Set(seenIdentifier);
|
|
803
|
+
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames);
|
|
804
|
+
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames);
|
|
739
805
|
return genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare);
|
|
740
806
|
}
|
|
741
807
|
function analyzeExpressions(expressions) {
|
|
@@ -765,14 +831,17 @@ function analyzeExpressions(expressions) {
|
|
|
765
831
|
(0, _vue_compiler_dom.walkIdentifiers)(exp.ast, (currentNode, parent, parentStack) => {
|
|
766
832
|
if (parent && isMemberExpression$3(parent) && !seenParents.has(parent)) {
|
|
767
833
|
seenParents.add(parent);
|
|
834
|
+
let hasGlobalIdentifier = false;
|
|
768
835
|
const memberExp = extractMemberExpression(parent, (id) => {
|
|
769
836
|
registerVariable(id.name, exp, true, {
|
|
770
837
|
start: id.start,
|
|
771
838
|
end: id.end
|
|
772
839
|
});
|
|
840
|
+
if ((0, _vue_shared.isGloballyAllowed)(id.name)) hasGlobalIdentifier = true;
|
|
773
841
|
});
|
|
774
842
|
const parentOfMemberExp = parentStack[parentStack.length - 2];
|
|
775
843
|
if (parentOfMemberExp && isCallExpression(parentOfMemberExp)) return;
|
|
844
|
+
if (hasGlobalIdentifier) return;
|
|
776
845
|
registerVariable(memberExp, exp, false, {
|
|
777
846
|
start: parent.start,
|
|
778
847
|
end: parent.end
|
|
@@ -791,14 +860,15 @@ function analyzeExpressions(expressions) {
|
|
|
791
860
|
updatedVariable
|
|
792
861
|
};
|
|
793
862
|
}
|
|
794
|
-
function processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable) {
|
|
863
|
+
function processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames) {
|
|
795
864
|
const declarations = [];
|
|
796
865
|
const expToReplacementMap = /* @__PURE__ */ new Map();
|
|
797
866
|
for (const [name, exps] of variableToExpMap) {
|
|
798
867
|
if (updatedVariable.has(name)) continue;
|
|
868
|
+
if ((0, _vue_shared.isGloballyAllowed)(name)) continue;
|
|
799
869
|
if (seenVariable[name] > 1 && exps.size > 0) {
|
|
800
870
|
const isIdentifier = seenIdentifier.has(name);
|
|
801
|
-
const varName = isIdentifier ? name : genVarName(name);
|
|
871
|
+
const varName = isIdentifier ? name : getUniqueDeclarationName(genVarName(name), reservedNames);
|
|
802
872
|
exps.forEach((node) => {
|
|
803
873
|
if (node.ast && varName !== name) {
|
|
804
874
|
const replacements = expToReplacementMap.get(node) || [];
|
|
@@ -830,7 +900,7 @@ function processRepeatedVariables(context, seenVariable, variableToExpMap, expTo
|
|
|
830
900
|
}))).sort((a, b) => b.end - a.end).forEach(({ start, end, name }) => {
|
|
831
901
|
exp.content = exp.content.slice(0, start - 1) + name + exp.content.slice(end - 1);
|
|
832
902
|
});
|
|
833
|
-
exp.ast = parseExp(context, exp.content
|
|
903
|
+
exp.ast = parseExp(context, exp.content);
|
|
834
904
|
}
|
|
835
905
|
return declarations;
|
|
836
906
|
}
|
|
@@ -846,45 +916,44 @@ function shouldDeclareVariable(name, expToVariableMap, exps) {
|
|
|
846
916
|
if (vars.every((v) => v.every((e, idx) => e === first[idx]))) return false;
|
|
847
917
|
return true;
|
|
848
918
|
}
|
|
849
|
-
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap) {
|
|
919
|
+
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames) {
|
|
850
920
|
const declarations = [];
|
|
851
921
|
const seenExp = expressions.reduce((acc, exp) => {
|
|
852
922
|
const vars = expToVariableMap.get(exp);
|
|
853
923
|
if (!vars) return acc;
|
|
854
924
|
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;
|
|
925
|
+
if (exp.ast && exp.ast.type !== "Identifier" && !(variables && variables.some((v) => updatedVariable.has(v))) && !variables.some((v) => (0, _vue_shared.isGloballyAllowed)(v))) acc[exp.content] = (acc[exp.content] || 0) + 1;
|
|
856
926
|
return acc;
|
|
857
927
|
}, Object.create(null));
|
|
858
928
|
Object.entries(seenExp).forEach(([content, count]) => {
|
|
859
929
|
if (count > 1) {
|
|
860
|
-
const
|
|
861
|
-
|
|
862
|
-
const
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
varDeclarations.splice(i, 1);
|
|
869
|
-
}
|
|
930
|
+
const delVars = {};
|
|
931
|
+
for (let i = varDeclarations.length - 1; i >= 0; i--) {
|
|
932
|
+
const item = varDeclarations[i];
|
|
933
|
+
if (!item.exps || !item.seenCount) continue;
|
|
934
|
+
if ([...item.exps].every((node) => node.content === content && item.seenCount === count)) {
|
|
935
|
+
delVars[item.name] = item.rawName;
|
|
936
|
+
reservedNames.delete(item.name);
|
|
937
|
+
varDeclarations.splice(i, 1);
|
|
870
938
|
}
|
|
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
|
|
879
|
-
});
|
|
880
939
|
}
|
|
940
|
+
const value = (0, _vue_shared.extend)({}, expressions.find((exp) => exp.content === content));
|
|
941
|
+
Object.keys(delVars).forEach((name) => {
|
|
942
|
+
value.content = value.content.replace(name, delVars[name]);
|
|
943
|
+
if (value.ast) value.ast = parseExp(context, value.content);
|
|
944
|
+
});
|
|
945
|
+
const varName = getUniqueDeclarationName(genVarName(content), reservedNames);
|
|
946
|
+
declarations.push({
|
|
947
|
+
name: varName,
|
|
948
|
+
value
|
|
949
|
+
});
|
|
881
950
|
expressions.forEach((exp) => {
|
|
882
951
|
if (exp.content === content) {
|
|
883
952
|
exp.content = varName;
|
|
884
953
|
exp.ast = null;
|
|
885
954
|
} else if (exp.content.includes(content)) {
|
|
886
955
|
exp.content = exp.content.replace(new RegExp(escapeRegExp(content), "g"), varName);
|
|
887
|
-
exp.ast = parseExp(context, exp.content
|
|
956
|
+
exp.ast = parseExp(context, exp.content);
|
|
888
957
|
}
|
|
889
958
|
});
|
|
890
959
|
}
|
|
@@ -905,10 +974,11 @@ function genDeclarations(declarations, context, shouldDeclare) {
|
|
|
905
974
|
});
|
|
906
975
|
declarations.forEach(({ name, isIdentifier, value }) => {
|
|
907
976
|
if (!isIdentifier) {
|
|
908
|
-
const varName =
|
|
977
|
+
const varName = `_${name}`;
|
|
909
978
|
varNames.add(varName);
|
|
910
979
|
if (shouldDeclare) push(`const `);
|
|
911
980
|
push(`${varName} = `, ...context.withId(() => genExpression(value, context), ids), NEWLINE);
|
|
981
|
+
ids[name] = varName;
|
|
912
982
|
}
|
|
913
983
|
});
|
|
914
984
|
return {
|
|
@@ -921,10 +991,8 @@ function escapeRegExp(string) {
|
|
|
921
991
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
922
992
|
}
|
|
923
993
|
function parseExp(context, content, loc) {
|
|
924
|
-
const plugins = context.options.expressionPlugins;
|
|
925
|
-
const options = { plugins: plugins ? [...plugins, "typescript"] : ["typescript"] };
|
|
926
994
|
try {
|
|
927
|
-
return (0, _babel_parser.parseExpression)(`(${content})`, options);
|
|
995
|
+
return (0, _babel_parser.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
928
996
|
} catch (e) {
|
|
929
997
|
if (loc) {
|
|
930
998
|
const error = new SyntaxError(e.message);
|
|
@@ -938,6 +1006,14 @@ function parseExp(context, content, loc) {
|
|
|
938
1006
|
function genVarName(exp) {
|
|
939
1007
|
return `${exp.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/_+$/, "")}`;
|
|
940
1008
|
}
|
|
1009
|
+
function getUniqueDeclarationName(baseName, reservedNames) {
|
|
1010
|
+
const normalizedBase = baseName || "exp";
|
|
1011
|
+
let name = normalizedBase;
|
|
1012
|
+
let i = 1;
|
|
1013
|
+
while (reservedNames.has(name)) name = `${normalizedBase}_${i++}`;
|
|
1014
|
+
reservedNames.add(name);
|
|
1015
|
+
return name;
|
|
1016
|
+
}
|
|
941
1017
|
function extractMemberExpression(exp, onIdentifier) {
|
|
942
1018
|
if (!exp) return "";
|
|
943
1019
|
switch (exp.type) {
|
|
@@ -961,7 +1037,6 @@ const isCallExpression = (node) => {
|
|
|
961
1037
|
const isMemberExpression$3 = (node) => {
|
|
962
1038
|
return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "TSNonNullExpression";
|
|
963
1039
|
};
|
|
964
|
-
|
|
965
1040
|
//#endregion
|
|
966
1041
|
//#region packages/compiler-vapor/src/generators/event.ts
|
|
967
1042
|
function genSetEvent(oper, context) {
|
|
@@ -1006,7 +1081,7 @@ function genSetEvent(oper, context) {
|
|
|
1006
1081
|
return genMulti(DELIMITERS_OBJECT_NEWLINE, effect && ["effect: true"], ...options.map((option) => [`${option}: true`]));
|
|
1007
1082
|
}
|
|
1008
1083
|
function isSameDelegateEvent(op) {
|
|
1009
|
-
if (op.type ===
|
|
1084
|
+
if (op.type === 6 && op !== oper && op.delegate && op.element === oper.element && op.key.content === key.content) return true;
|
|
1010
1085
|
}
|
|
1011
1086
|
}
|
|
1012
1087
|
function genSetDynamicEvents(oper, context) {
|
|
@@ -1073,7 +1148,6 @@ function isConstantBinding(value, context) {
|
|
|
1073
1148
|
if (context.options.bindingMetadata[value.content] === "setup-const") return true;
|
|
1074
1149
|
}
|
|
1075
1150
|
}
|
|
1076
|
-
|
|
1077
1151
|
//#endregion
|
|
1078
1152
|
//#region packages/compiler-vapor/src/generators/for.ts
|
|
1079
1153
|
function genFor(oper, context) {
|
|
@@ -1105,16 +1179,12 @@ function genFor(oper, context) {
|
|
|
1105
1179
|
idMap[rawIndex] = `${indexVar}.value`;
|
|
1106
1180
|
idMap[indexVar] = null;
|
|
1107
1181
|
}
|
|
1108
|
-
const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap);
|
|
1182
|
+
const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap, context);
|
|
1109
1183
|
const selectorDeclarations = [];
|
|
1110
|
-
const
|
|
1184
|
+
const selectorName = (i) => selectorPatterns.length > 1 ? `_selector${id}_${i}` : `_selector${id}`;
|
|
1111
1185
|
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
1112
1186
|
const { selector } = selectorPatterns[i];
|
|
1113
|
-
const selectorName = `
|
|
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, "}");
|
|
1187
|
+
selectorDeclarations.push(`const ${selectorName(i)} = `, ...genCall(helper("createSelector"), [`() => `, ...genExpression(selector, context)]), NEWLINE);
|
|
1118
1188
|
}
|
|
1119
1189
|
const blockFn = context.withId(() => {
|
|
1120
1190
|
const frag = [];
|
|
@@ -1123,7 +1193,7 @@ function genFor(oper, context) {
|
|
|
1123
1193
|
const patternFrag = [];
|
|
1124
1194
|
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
1125
1195
|
const { effect } = selectorPatterns[i];
|
|
1126
|
-
patternFrag.push(NEWLINE,
|
|
1196
|
+
patternFrag.push(NEWLINE, `${selectorName(i)}(`, ...genExpression(keyProp, context), `, () => {`, INDENT_START);
|
|
1127
1197
|
for (const oper of effect.operations) patternFrag.push(...genOperation(oper, context));
|
|
1128
1198
|
patternFrag.push(INDENT_END, NEWLINE, `})`);
|
|
1129
1199
|
}
|
|
@@ -1139,11 +1209,14 @@ function genFor(oper, context) {
|
|
|
1139
1209
|
if (onlyChild) flags |= 1;
|
|
1140
1210
|
if (component) flags |= 2;
|
|
1141
1211
|
if (once) flags |= 4;
|
|
1212
|
+
const onResetCalls = [];
|
|
1213
|
+
for (let i = 0; i < selectorPatterns.length; i++) onResetCalls.push(NEWLINE, `n${id}.onReset(${selectorName(i)}.reset)`);
|
|
1142
1214
|
return [
|
|
1143
1215
|
NEWLINE,
|
|
1144
1216
|
...selectorDeclarations,
|
|
1145
1217
|
`const n${id} = `,
|
|
1146
|
-
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags ? String(flags) : void 0,
|
|
1218
|
+
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags ? String(flags) : void 0),
|
|
1219
|
+
...onResetCalls
|
|
1147
1220
|
];
|
|
1148
1221
|
function genCallback(expr) {
|
|
1149
1222
|
if (!expr) return false;
|
|
@@ -1231,35 +1304,49 @@ function buildDestructureIdMap(idToPathMap, baseAccessor, plugins) {
|
|
|
1231
1304
|
}
|
|
1232
1305
|
if (pathInfo.dynamic) {
|
|
1233
1306
|
const node = idMap[id] = (0, _vue_compiler_dom.createSimpleExpression)(path);
|
|
1234
|
-
node.ast = (0, _babel_parser.parseExpression)(`(${path})`,
|
|
1307
|
+
node.ast = (0, _babel_parser.parseExpression)(`(${path})`, getParserOptions(plugins));
|
|
1235
1308
|
} else idMap[id] = path;
|
|
1236
1309
|
} else idMap[id] = path;
|
|
1237
1310
|
});
|
|
1238
1311
|
return idMap;
|
|
1239
1312
|
}
|
|
1240
|
-
function matchPatterns(render, keyProp, idMap) {
|
|
1313
|
+
function matchPatterns(render, keyProp, idMap, context) {
|
|
1241
1314
|
const selectorPatterns = [];
|
|
1242
1315
|
const keyOnlyBindingPatterns = [];
|
|
1243
|
-
|
|
1316
|
+
const removedEffectIndexes = [];
|
|
1317
|
+
render.effect = render.effect.filter((effect, index) => {
|
|
1244
1318
|
if (keyProp !== void 0) {
|
|
1245
|
-
const selector = matchSelectorPattern(effect, keyProp.content, idMap);
|
|
1319
|
+
const selector = matchSelectorPattern(effect, keyProp.content, idMap, context);
|
|
1246
1320
|
if (selector) {
|
|
1247
1321
|
selectorPatterns.push(selector);
|
|
1322
|
+
removedEffectIndexes.push(index);
|
|
1248
1323
|
return false;
|
|
1249
1324
|
}
|
|
1250
1325
|
const keyOnly = matchKeyOnlyBindingPattern(effect, keyProp.content);
|
|
1251
1326
|
if (keyOnly) {
|
|
1252
1327
|
keyOnlyBindingPatterns.push(keyOnly);
|
|
1328
|
+
removedEffectIndexes.push(index);
|
|
1253
1329
|
return false;
|
|
1254
1330
|
}
|
|
1255
1331
|
}
|
|
1256
1332
|
return true;
|
|
1257
1333
|
});
|
|
1334
|
+
if (removedEffectIndexes.length) shiftEffectBoundaries(render.dynamic, removedEffectIndexes);
|
|
1258
1335
|
return {
|
|
1259
1336
|
keyOnlyBindingPatterns,
|
|
1260
1337
|
selectorPatterns
|
|
1261
1338
|
};
|
|
1262
1339
|
}
|
|
1340
|
+
function shiftEffectBoundaries(dynamic, removedEffectIndexes) {
|
|
1341
|
+
const operation = dynamic.operation;
|
|
1342
|
+
if (operation && isBlockOperation(operation) && operation.effectIndex !== void 0) {
|
|
1343
|
+
let offset = 0;
|
|
1344
|
+
for (const removedIndex of removedEffectIndexes) if (removedIndex < operation.effectIndex) offset++;
|
|
1345
|
+
else break;
|
|
1346
|
+
operation.effectIndex -= offset;
|
|
1347
|
+
}
|
|
1348
|
+
for (const child of dynamic.children) shiftEffectBoundaries(child, removedEffectIndexes);
|
|
1349
|
+
}
|
|
1263
1350
|
function matchKeyOnlyBindingPattern(effect, key) {
|
|
1264
1351
|
if (effect.expressions.length === 1) {
|
|
1265
1352
|
const { ast, content } = effect.expressions[0];
|
|
@@ -1268,7 +1355,7 @@ function matchKeyOnlyBindingPattern(effect, key) {
|
|
|
1268
1355
|
}
|
|
1269
1356
|
}
|
|
1270
1357
|
}
|
|
1271
|
-
function matchSelectorPattern(effect, key, idMap) {
|
|
1358
|
+
function matchSelectorPattern(effect, key, idMap, context) {
|
|
1272
1359
|
if (effect.expressions.length === 1) {
|
|
1273
1360
|
const { ast, content } = effect.expressions[0];
|
|
1274
1361
|
if (typeof ast === "object" && ast) {
|
|
@@ -1293,17 +1380,11 @@ function matchSelectorPattern(effect, key, idMap) {
|
|
|
1293
1380
|
}, false);
|
|
1294
1381
|
if (!hasExtraId) {
|
|
1295
1382
|
const name = content.slice(selector.start - 1, selector.end - 1);
|
|
1383
|
+
const selectorExpression = (0, _vue_compiler_dom.createSimpleExpression)(name, false, selector.loc);
|
|
1384
|
+
selectorExpression.ast = (0, _babel_parser.parseExpression)(`(${name})`, getParserOptions(context.options.expressionPlugins));
|
|
1296
1385
|
return {
|
|
1297
1386
|
effect,
|
|
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
|
-
}
|
|
1387
|
+
selector: selectorExpression
|
|
1307
1388
|
};
|
|
1308
1389
|
}
|
|
1309
1390
|
}
|
|
@@ -1333,7 +1414,6 @@ function isKeyOnlyBinding(expr, key, source) {
|
|
|
1333
1414
|
} });
|
|
1334
1415
|
return only;
|
|
1335
1416
|
}
|
|
1336
|
-
|
|
1337
1417
|
//#endregion
|
|
1338
1418
|
//#region packages/compiler-vapor/src/generators/html.ts
|
|
1339
1419
|
function genSetHtml(oper, context) {
|
|
@@ -1341,12 +1421,11 @@ function genSetHtml(oper, context) {
|
|
|
1341
1421
|
const { value, element, isComponent } = oper;
|
|
1342
1422
|
return [NEWLINE, ...genCall(isComponent ? helper("setBlockHtml") : helper("setHtml"), `n${element}`, genExpression(value, context))];
|
|
1343
1423
|
}
|
|
1344
|
-
|
|
1345
1424
|
//#endregion
|
|
1346
1425
|
//#region packages/compiler-vapor/src/generators/if.ts
|
|
1347
1426
|
function genIf(oper, context, isNested = false) {
|
|
1348
1427
|
const { helper } = context;
|
|
1349
|
-
const { condition, positive, negative, once, index } = oper;
|
|
1428
|
+
const { condition, positive, negative, once, index, blockShape } = oper;
|
|
1350
1429
|
const [frag, push] = buildCodeFragment();
|
|
1351
1430
|
const conditionExpr = [
|
|
1352
1431
|
"() => (",
|
|
@@ -1358,16 +1437,16 @@ function genIf(oper, context, isNested = false) {
|
|
|
1358
1437
|
if (negative) if (negative.type === 1) negativeArg = genBlock(negative, context);
|
|
1359
1438
|
else negativeArg = ["() => ", ...genIf(negative, context, true)];
|
|
1360
1439
|
if (!isNested) push(NEWLINE, `const n${oper.id} = `);
|
|
1361
|
-
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, once && "true", index !== void 0 && negative && String(index)));
|
|
1440
|
+
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, String(blockShape), once && "true", index !== void 0 && negative && String(index)));
|
|
1362
1441
|
return frag;
|
|
1363
1442
|
}
|
|
1364
|
-
|
|
1365
1443
|
//#endregion
|
|
1366
1444
|
//#region packages/compiler-vapor/src/generators/prop.ts
|
|
1367
1445
|
const helpers = {
|
|
1368
1446
|
setText: { name: "setText" },
|
|
1369
1447
|
setHtml: { name: "setHtml" },
|
|
1370
1448
|
setClass: { name: "setClass" },
|
|
1449
|
+
setClassName: { name: "setClassName" },
|
|
1371
1450
|
setStyle: { name: "setStyle" },
|
|
1372
1451
|
setValue: { name: "setValue" },
|
|
1373
1452
|
setAttr: {
|
|
@@ -1387,9 +1466,132 @@ function genSetProp(oper, context) {
|
|
|
1387
1466
|
const { helper } = context;
|
|
1388
1467
|
const { prop: { key, values, modifier }, tag } = oper;
|
|
1389
1468
|
const resolvedHelper = getRuntimeHelper(tag, key.content, modifier);
|
|
1469
|
+
if (key.content === "class" && !resolvedHelper.isSVG && resolvedHelper.name === "setClass") {
|
|
1470
|
+
const className = genSetClassName(oper, context);
|
|
1471
|
+
if (className) return className;
|
|
1472
|
+
}
|
|
1390
1473
|
const propValue = genPropValue(values, context);
|
|
1391
1474
|
return [NEWLINE, ...genCall([helper(resolvedHelper.name), null], `n${oper.element}`, resolvedHelper.needKey ? genExpression(key, context) : false, propValue, resolvedHelper.isSVG && "true")];
|
|
1392
1475
|
}
|
|
1476
|
+
const MAX_CLASS_NAME_ENTRIES = 31;
|
|
1477
|
+
function genSetClassName(oper, context) {
|
|
1478
|
+
const info = resolveClassName(oper.prop.values, context);
|
|
1479
|
+
if (!info) return;
|
|
1480
|
+
const { helper } = context;
|
|
1481
|
+
const flags = genClassFlags(info.entries, context);
|
|
1482
|
+
const classFragments = info.entries.map((entry) => JSON.stringify(!info.prefix && info.entries.length === 1 ? entry.className : ` ${entry.className}`));
|
|
1483
|
+
const fragments = classFragments.length === 1 ? classFragments[0] : genMulti(DELIMITERS_ARRAY, ...classFragments);
|
|
1484
|
+
return [NEWLINE, ...genCall([helper("setClassName"), "\"\""], `n${oper.element}`, flags, fragments, info.prefix && JSON.stringify(info.prefix), info.suffix && JSON.stringify(info.suffix))];
|
|
1485
|
+
}
|
|
1486
|
+
function resolveClassName(values, context) {
|
|
1487
|
+
let prefix = "";
|
|
1488
|
+
let suffix = "";
|
|
1489
|
+
const entries = [];
|
|
1490
|
+
let sawDynamic = false;
|
|
1491
|
+
let sawSuffix = false;
|
|
1492
|
+
for (const value of values) {
|
|
1493
|
+
const staticValue = getLiteralExpressionValue(value, true);
|
|
1494
|
+
if (staticValue != null) {
|
|
1495
|
+
const normalized = (0, _vue_shared.normalizeClass)(staticValue);
|
|
1496
|
+
if (normalized) if (sawSuffix) suffix = appendClass(suffix, normalized);
|
|
1497
|
+
else if (sawDynamic) {
|
|
1498
|
+
sawSuffix = true;
|
|
1499
|
+
suffix = appendClass(suffix, normalized);
|
|
1500
|
+
} else prefix = appendClass(prefix, normalized);
|
|
1501
|
+
continue;
|
|
1502
|
+
}
|
|
1503
|
+
const ast = value.ast;
|
|
1504
|
+
if (!ast || sawSuffix) return;
|
|
1505
|
+
sawDynamic = true;
|
|
1506
|
+
if (ast.type === "ObjectExpression") {
|
|
1507
|
+
if (!resolveObjectClassName(value, ast, entries, context)) return;
|
|
1508
|
+
} else if (ast.type === "ConditionalExpression") {
|
|
1509
|
+
if (!resolveConditionalClassName(value, ast, entries, context)) return;
|
|
1510
|
+
} else return;
|
|
1511
|
+
}
|
|
1512
|
+
return entries.length && entries.length <= MAX_CLASS_NAME_ENTRIES ? {
|
|
1513
|
+
prefix,
|
|
1514
|
+
suffix,
|
|
1515
|
+
entries
|
|
1516
|
+
} : void 0;
|
|
1517
|
+
}
|
|
1518
|
+
function resolveObjectClassName(source, ast, entries, context) {
|
|
1519
|
+
for (const prop of ast.properties) {
|
|
1520
|
+
if (prop.type !== "ObjectProperty" || prop.computed) return false;
|
|
1521
|
+
const rawClassName = getObjectPropertyName(prop);
|
|
1522
|
+
if (rawClassName == null) return false;
|
|
1523
|
+
const className = (0, _vue_shared.normalizeClass)(rawClassName);
|
|
1524
|
+
if (!className) continue;
|
|
1525
|
+
const value = getBooleanValue(prop.value);
|
|
1526
|
+
entries.push({
|
|
1527
|
+
className,
|
|
1528
|
+
value,
|
|
1529
|
+
condition: value == null ? createSubExpression(source, prop.value, context) : void 0
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
return true;
|
|
1533
|
+
}
|
|
1534
|
+
function resolveConditionalClassName(source, ast, entries, context) {
|
|
1535
|
+
const consequent = getStringClassValue(ast.consequent);
|
|
1536
|
+
const alternate = getStringClassValue(ast.alternate);
|
|
1537
|
+
if (consequent && alternate === "") {
|
|
1538
|
+
entries.push({
|
|
1539
|
+
className: consequent,
|
|
1540
|
+
condition: createSubExpression(source, ast.test, context)
|
|
1541
|
+
});
|
|
1542
|
+
return true;
|
|
1543
|
+
} else if (alternate && consequent === "") {
|
|
1544
|
+
entries.push({
|
|
1545
|
+
className: alternate,
|
|
1546
|
+
condition: createSubExpression(source, ast.test, context),
|
|
1547
|
+
negate: true
|
|
1548
|
+
});
|
|
1549
|
+
return true;
|
|
1550
|
+
}
|
|
1551
|
+
return false;
|
|
1552
|
+
}
|
|
1553
|
+
function genClassFlags(entries, context) {
|
|
1554
|
+
const values = [];
|
|
1555
|
+
entries.forEach((entry, index) => {
|
|
1556
|
+
if (index) values.push(" | ");
|
|
1557
|
+
const bit = 1 << index;
|
|
1558
|
+
if (entry.value != null) {
|
|
1559
|
+
values.push(entry.value ? String(bit) : "0");
|
|
1560
|
+
return;
|
|
1561
|
+
}
|
|
1562
|
+
values.push("(", ...genExpression(entry.condition, context), entry.negate ? ` ? 0 : ${bit}` : ` ? ${bit} : 0`, ")");
|
|
1563
|
+
});
|
|
1564
|
+
return values;
|
|
1565
|
+
}
|
|
1566
|
+
function appendClass(base, value) {
|
|
1567
|
+
return base ? value ? `${base} ${value}` : base : value;
|
|
1568
|
+
}
|
|
1569
|
+
function getObjectPropertyName(prop) {
|
|
1570
|
+
const key = prop.key;
|
|
1571
|
+
if (key.type === "Identifier") return key.name;
|
|
1572
|
+
else if (key.type === "StringLiteral") return key.value;
|
|
1573
|
+
else if (key.type === "NumericLiteral") return String(key.value);
|
|
1574
|
+
}
|
|
1575
|
+
function getStringClassValue(node) {
|
|
1576
|
+
if (node.type === "StringLiteral") return (0, _vue_shared.normalizeClass)(node.value);
|
|
1577
|
+
else if (node.type === "TemplateLiteral" && node.expressions.length === 0) return (0, _vue_shared.normalizeClass)(node.quasis[0].value.cooked || "");
|
|
1578
|
+
else if (node.type === "NullLiteral" || node.type === "BooleanLiteral" && !node.value) return "";
|
|
1579
|
+
}
|
|
1580
|
+
function getBooleanValue(node) {
|
|
1581
|
+
if (node.type === "BooleanLiteral") return node.value;
|
|
1582
|
+
}
|
|
1583
|
+
function createSubExpression(source, node, context) {
|
|
1584
|
+
const start = node.start == null ? 0 : node.start - 1;
|
|
1585
|
+
const end = node.end == null ? source.content.length : node.end - 1;
|
|
1586
|
+
const content = source.content.slice(start, end);
|
|
1587
|
+
const expression = (0, _vue_compiler_dom.createSimpleExpression)(content, false, {
|
|
1588
|
+
start: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, source.content, start),
|
|
1589
|
+
end: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, source.content, end),
|
|
1590
|
+
source: content
|
|
1591
|
+
});
|
|
1592
|
+
expression.ast = (0, _vue_compiler_dom.isSimpleIdentifier)(content) ? null : (0, _babel_parser.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
1593
|
+
return expression;
|
|
1594
|
+
}
|
|
1393
1595
|
function genDynamicProps$1(oper, context) {
|
|
1394
1596
|
const { helper } = context;
|
|
1395
1597
|
const isSVG = (0, _vue_shared.isSVGTag)(oper.tag);
|
|
@@ -1451,7 +1653,6 @@ function getSpecialHelper(keyName, tagName, isSVG) {
|
|
|
1451
1653
|
else if (keyName === "innerHTML") return helpers.setHtml;
|
|
1452
1654
|
else if (keyName === "textContent") return helpers.setText;
|
|
1453
1655
|
}
|
|
1454
|
-
|
|
1455
1656
|
//#endregion
|
|
1456
1657
|
//#region packages/compiler-vapor/src/generators/templateRef.ts
|
|
1457
1658
|
const setTemplateRefIdent = `_setTemplateRef`;
|
|
@@ -1466,7 +1667,6 @@ function genRefValue(value, context) {
|
|
|
1466
1667
|
}
|
|
1467
1668
|
return [genExpression(value, context)];
|
|
1468
1669
|
}
|
|
1469
|
-
|
|
1470
1670
|
//#endregion
|
|
1471
1671
|
//#region packages/compiler-vapor/src/generators/text.ts
|
|
1472
1672
|
function genSetText(oper, context) {
|
|
@@ -1486,23 +1686,16 @@ function combineValues(values, context) {
|
|
|
1486
1686
|
function genGetTextChild(oper, context) {
|
|
1487
1687
|
return [NEWLINE, `const x${oper.parent} = ${context.helper("txt")}(n${oper.parent})`];
|
|
1488
1688
|
}
|
|
1489
|
-
|
|
1490
1689
|
//#endregion
|
|
1491
1690
|
//#region packages/compiler-vapor/src/generators/vShow.ts
|
|
1492
1691
|
function genVShow(oper, context) {
|
|
1493
|
-
const {
|
|
1494
|
-
return [
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
...genExpression(oper.dir.exp, context),
|
|
1500
|
-
`)`
|
|
1501
|
-
]),
|
|
1502
|
-
deferred ? `)` : void 0
|
|
1503
|
-
];
|
|
1692
|
+
const { element } = oper;
|
|
1693
|
+
return [NEWLINE, ...genCall(context.helper("applyVShow"), `n${element}`, [
|
|
1694
|
+
`() => (`,
|
|
1695
|
+
...genExpression(oper.dir.exp, context),
|
|
1696
|
+
`)`
|
|
1697
|
+
])];
|
|
1504
1698
|
}
|
|
1505
|
-
|
|
1506
1699
|
//#endregion
|
|
1507
1700
|
//#region packages/compiler-vapor/src/generators/vModel.ts
|
|
1508
1701
|
const helperMap = {
|
|
@@ -1527,7 +1720,6 @@ function genModelHandler(exp, context) {
|
|
|
1527
1720
|
")"
|
|
1528
1721
|
];
|
|
1529
1722
|
}
|
|
1530
|
-
|
|
1531
1723
|
//#endregion
|
|
1532
1724
|
//#region packages/compiler-vapor/src/generators/directive.ts
|
|
1533
1725
|
function genBuiltinDirective(oper, context) {
|
|
@@ -1565,9 +1757,8 @@ function genDirectiveModifiers(modifiers) {
|
|
|
1565
1757
|
return modifiers.map((value) => `${(0, _vue_compiler_dom.isSimpleIdentifier)(value) ? value : JSON.stringify(value)}: true`).join(", ");
|
|
1566
1758
|
}
|
|
1567
1759
|
function filterCustomDirectives(id, operations) {
|
|
1568
|
-
return operations.filter((oper) => oper.type ===
|
|
1760
|
+
return operations.filter((oper) => oper.type === 14 && oper.element === id && !oper.builtin);
|
|
1569
1761
|
}
|
|
1570
|
-
|
|
1571
1762
|
//#endregion
|
|
1572
1763
|
//#region packages/compiler-vapor/src/generators/component.ts
|
|
1573
1764
|
function genCreateComponent(operation, context) {
|
|
@@ -1589,11 +1780,11 @@ function genCreateComponent(operation, context) {
|
|
|
1589
1780
|
];
|
|
1590
1781
|
}, []),
|
|
1591
1782
|
`const n${operation.id} = `,
|
|
1592
|
-
...genCall(operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.
|
|
1783
|
+
...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"),
|
|
1593
1784
|
...genDirectivesForElement(operation.id, context)
|
|
1594
1785
|
];
|
|
1595
1786
|
function genTag() {
|
|
1596
|
-
if (operation.
|
|
1787
|
+
if (operation.useCreateElement) return JSON.stringify(operation.tag);
|
|
1597
1788
|
else if (operation.dynamic) if (operation.dynamic.isStatic) return genCall(helper("resolveDynamicComponent"), genExpression(operation.dynamic, context));
|
|
1598
1789
|
else return [
|
|
1599
1790
|
"() => (",
|
|
@@ -1741,7 +1932,7 @@ function genDynamicProps(props, context) {
|
|
|
1741
1932
|
];
|
|
1742
1933
|
entries.push([
|
|
1743
1934
|
...updateKey,
|
|
1744
|
-
":
|
|
1935
|
+
": ",
|
|
1745
1936
|
...genModelHandler(p.values[0], context)
|
|
1746
1937
|
]);
|
|
1747
1938
|
const { modelModifiers } = p;
|
|
@@ -1752,10 +1943,10 @@ function genDynamicProps(props, context) {
|
|
|
1752
1943
|
" + \"Modifiers\"]"
|
|
1753
1944
|
];
|
|
1754
1945
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
1755
|
-
entries.push([...modifiersKey, `:
|
|
1946
|
+
entries.push([...modifiersKey, `: { ${modifiersVal} }`]);
|
|
1756
1947
|
}
|
|
1757
1948
|
expr = genMulti(DELIMITERS_OBJECT_NEWLINE, ...entries);
|
|
1758
|
-
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context));
|
|
1949
|
+
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context, false, false));
|
|
1759
1950
|
else {
|
|
1760
1951
|
expr = genExpression(p.value, context);
|
|
1761
1952
|
if (p.handler) expr = genCall(helper("toHandlers"), expr);
|
|
@@ -1768,12 +1959,12 @@ function genDynamicProps(props, context) {
|
|
|
1768
1959
|
}
|
|
1769
1960
|
if (frags.length) return genMulti(DELIMITERS_ARRAY_NEWLINE, ...frags);
|
|
1770
1961
|
}
|
|
1771
|
-
function genProp(prop, context, isStatic) {
|
|
1962
|
+
function genProp(prop, context, isStatic, wrapHandler = true) {
|
|
1772
1963
|
const values = genPropValue(prop.values, context);
|
|
1773
1964
|
return [
|
|
1774
1965
|
...genPropKey(prop, context),
|
|
1775
1966
|
": ",
|
|
1776
|
-
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, true,
|
|
1967
|
+
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, true, wrapHandler) : isStatic ? [
|
|
1777
1968
|
"() => (",
|
|
1778
1969
|
...values,
|
|
1779
1970
|
")"
|
|
@@ -1810,11 +2001,23 @@ function genDynamicSlot(slot, context, withFunction = false) {
|
|
|
1810
2001
|
frag = genConditionalSlot(slot, context);
|
|
1811
2002
|
break;
|
|
1812
2003
|
}
|
|
1813
|
-
|
|
2004
|
+
if (!withFunction) return frag;
|
|
2005
|
+
return needsDynamicSlotSourceCtx(slot) ? [
|
|
2006
|
+
`${context.helper("withVaporCtx")}(() => (`,
|
|
2007
|
+
...frag,
|
|
2008
|
+
"))"
|
|
2009
|
+
] : [
|
|
1814
2010
|
"() => (",
|
|
1815
2011
|
...frag,
|
|
1816
2012
|
")"
|
|
1817
|
-
]
|
|
2013
|
+
];
|
|
2014
|
+
}
|
|
2015
|
+
function needsDynamicSlotSourceCtx(slot) {
|
|
2016
|
+
switch (slot.slotType) {
|
|
2017
|
+
case 1: return needsVaporCtx(slot.fn);
|
|
2018
|
+
case 2: return needsVaporCtx(slot.fn);
|
|
2019
|
+
case 3: return needsDynamicSlotSourceCtx(slot.positive) || (slot.negative ? needsDynamicSlotSourceCtx(slot.negative) : false);
|
|
2020
|
+
}
|
|
1818
2021
|
}
|
|
1819
2022
|
function genBasicDynamicSlot(slot, context) {
|
|
1820
2023
|
const { name, fn } = slot;
|
|
@@ -1860,7 +2063,7 @@ function genSlotBlockWithProps(oper, context) {
|
|
|
1860
2063
|
let propsName;
|
|
1861
2064
|
let exitScope;
|
|
1862
2065
|
let depth;
|
|
1863
|
-
const { props,
|
|
2066
|
+
const { props, node } = oper;
|
|
1864
2067
|
const idToPathMap = props ? parseValueDestructure(props, context) : /* @__PURE__ */ new Map();
|
|
1865
2068
|
if (props) if (props.ast) {
|
|
1866
2069
|
[depth, exitScope] = context.enterScope();
|
|
@@ -1870,16 +2073,6 @@ function genSlotBlockWithProps(oper, context) {
|
|
|
1870
2073
|
if (propsName) idMap[propsName] = null;
|
|
1871
2074
|
let blockFn = context.withId(() => genBlock(oper, context, propsName ? [propsName] : []), idMap);
|
|
1872
2075
|
exitScope && exitScope();
|
|
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
2076
|
if (node.type === 1) {
|
|
1884
2077
|
if (needsVaporCtx(oper)) blockFn = [
|
|
1885
2078
|
`${context.helper("withVaporCtx")}(`,
|
|
@@ -1905,11 +2098,11 @@ function hasComponentOrSlotInBlock(block) {
|
|
|
1905
2098
|
function hasComponentOrSlotInDynamic(dynamic) {
|
|
1906
2099
|
if (dynamic.operation) {
|
|
1907
2100
|
const type = dynamic.operation.type;
|
|
1908
|
-
if (type ===
|
|
1909
|
-
if (type ===
|
|
2101
|
+
if (type === 12 || type === 13) return true;
|
|
2102
|
+
if (type === 15) {
|
|
1910
2103
|
if (hasComponentOrSlotInIf(dynamic.operation)) return true;
|
|
1911
2104
|
}
|
|
1912
|
-
if (type ===
|
|
2105
|
+
if (type === 16) {
|
|
1913
2106
|
if (hasComponentOrSlotInBlock(dynamic.operation.render)) return true;
|
|
1914
2107
|
}
|
|
1915
2108
|
}
|
|
@@ -1918,12 +2111,12 @@ function hasComponentOrSlotInDynamic(dynamic) {
|
|
|
1918
2111
|
}
|
|
1919
2112
|
function hasComponentOrSlotInOperations(operations) {
|
|
1920
2113
|
for (const op of operations) switch (op.type) {
|
|
1921
|
-
case
|
|
1922
|
-
case
|
|
1923
|
-
case
|
|
2114
|
+
case 12:
|
|
2115
|
+
case 13: return true;
|
|
2116
|
+
case 15:
|
|
1924
2117
|
if (hasComponentOrSlotInIf(op)) return true;
|
|
1925
2118
|
break;
|
|
1926
|
-
case
|
|
2119
|
+
case 16:
|
|
1927
2120
|
if (hasComponentOrSlotInBlock(op.render)) return true;
|
|
1928
2121
|
break;
|
|
1929
2122
|
}
|
|
@@ -1935,7 +2128,6 @@ function hasComponentOrSlotInIf(node) {
|
|
|
1935
2128
|
else return hasComponentOrSlotInBlock(node.negative);
|
|
1936
2129
|
return false;
|
|
1937
2130
|
}
|
|
1938
|
-
|
|
1939
2131
|
//#endregion
|
|
1940
2132
|
//#region packages/compiler-vapor/src/generators/slotOutlet.ts
|
|
1941
2133
|
function genSlotOutlet(oper, context) {
|
|
@@ -1952,7 +2144,22 @@ function genSlotOutlet(oper, context) {
|
|
|
1952
2144
|
push(NEWLINE, `const n${id} = `, ...genCall(helper("createSlot"), nameExpr, genRawProps(oper.props, context) || "null", fallbackArg, noSlotted && "true", once && "true"));
|
|
1953
2145
|
return frag;
|
|
1954
2146
|
}
|
|
1955
|
-
|
|
2147
|
+
//#endregion
|
|
2148
|
+
//#region packages/compiler-vapor/src/generators/key.ts
|
|
2149
|
+
function genKey(oper, context) {
|
|
2150
|
+
const { id, value, block } = oper;
|
|
2151
|
+
const [frag, push] = buildCodeFragment();
|
|
2152
|
+
const blockFn = genBlock(block, context);
|
|
2153
|
+
push(NEWLINE, `const n${id} = `, ...genCall(context.helper("createKeyedFragment"), [
|
|
2154
|
+
`() => (`,
|
|
2155
|
+
...genExpression(value, context),
|
|
2156
|
+
")"
|
|
2157
|
+
], blockFn));
|
|
2158
|
+
return frag;
|
|
2159
|
+
}
|
|
2160
|
+
function genSetBlockKey(oper, context) {
|
|
2161
|
+
return [NEWLINE, ...genCall(context.helper("setBlockKey"), `n${oper.element}`, genExpression(oper.value, context))];
|
|
2162
|
+
}
|
|
1956
2163
|
//#endregion
|
|
1957
2164
|
//#region packages/compiler-vapor/src/generators/operation.ts
|
|
1958
2165
|
function genOperations(opers, context) {
|
|
@@ -1968,26 +2175,26 @@ function genOperationWithInsertionState(oper, context) {
|
|
|
1968
2175
|
}
|
|
1969
2176
|
function genOperation(oper, context) {
|
|
1970
2177
|
switch (oper.type) {
|
|
1971
|
-
case 2: return
|
|
1972
|
-
case 3: return
|
|
1973
|
-
case 4: return
|
|
1974
|
-
case 5: return
|
|
1975
|
-
case 6: return
|
|
1976
|
-
case 7: return
|
|
1977
|
-
case 8: return
|
|
1978
|
-
case 9: return
|
|
1979
|
-
case 10: return
|
|
1980
|
-
case
|
|
1981
|
-
case 15: return
|
|
1982
|
-
case
|
|
1983
|
-
case
|
|
1984
|
-
case
|
|
1985
|
-
case
|
|
1986
|
-
case
|
|
1987
|
-
case 18: return
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
2178
|
+
case 2: return genSetBlockKey(oper, context);
|
|
2179
|
+
case 3: return genSetProp(oper, context);
|
|
2180
|
+
case 4: return genDynamicProps$1(oper, context);
|
|
2181
|
+
case 5: return genSetText(oper, context);
|
|
2182
|
+
case 6: return genSetEvent(oper, context);
|
|
2183
|
+
case 7: return genSetDynamicEvents(oper, context);
|
|
2184
|
+
case 8: return genSetHtml(oper, context);
|
|
2185
|
+
case 9: return genSetTemplateRef(oper, context);
|
|
2186
|
+
case 10: return genInsertNode(oper, context);
|
|
2187
|
+
case 11: return genPrependNode(oper, context);
|
|
2188
|
+
case 15: return genIf(oper, context);
|
|
2189
|
+
case 16: return genFor(oper, context);
|
|
2190
|
+
case 17: return genKey(oper, context);
|
|
2191
|
+
case 12: return genCreateComponent(oper, context);
|
|
2192
|
+
case 13: return genSlotOutlet(oper, context);
|
|
2193
|
+
case 14: return genBuiltinDirective(oper, context);
|
|
2194
|
+
case 18: return genGetTextChild(oper, context);
|
|
2195
|
+
case 19: return [];
|
|
2196
|
+
case 20: return [];
|
|
2197
|
+
default: throw new Error(`Unhandled operation type in genOperation: ${oper}`);
|
|
1991
2198
|
}
|
|
1992
2199
|
}
|
|
1993
2200
|
function genEffects(effects, context, genExtraFrag) {
|
|
@@ -2027,22 +2234,24 @@ function genEffect({ operations }, context) {
|
|
|
2027
2234
|
return frag;
|
|
2028
2235
|
}
|
|
2029
2236
|
function genInsertionState(operation, context) {
|
|
2030
|
-
const { parent, anchor, logicalIndex, append
|
|
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
|
|
2237
|
+
const { parent, anchor, logicalIndex, append } = operation;
|
|
2238
|
+
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)];
|
|
2032
2239
|
}
|
|
2033
|
-
|
|
2034
2240
|
//#endregion
|
|
2035
2241
|
//#region packages/compiler-vapor/src/generators/template.ts
|
|
2036
|
-
function genTemplates(templates,
|
|
2242
|
+
function genTemplates(templates, context) {
|
|
2037
2243
|
const result = [];
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2244
|
+
templates.forEach(({ content, ns, root, static: isStatic }, i) => {
|
|
2245
|
+
let args = JSON.stringify(content).replace(IMPORT_EXPR_RE, `" + $1 + "`);
|
|
2246
|
+
if (root) args += ", true";
|
|
2247
|
+
else if (isStatic || ns) args += ", false";
|
|
2248
|
+
if (isStatic || ns) args += `, ${isStatic ? "true" : "false"}`;
|
|
2249
|
+
if (ns) args += `, ${ns}`;
|
|
2250
|
+
result.push(`const ${context.tName(i)} = ${context.helper("template")}(${args})\n`);
|
|
2042
2251
|
});
|
|
2043
2252
|
return result.join("");
|
|
2044
2253
|
}
|
|
2045
|
-
function genSelf(dynamic, context) {
|
|
2254
|
+
function genSelf(dynamic, context, flushBeforeDynamic) {
|
|
2046
2255
|
const [frag, push] = buildCodeFragment();
|
|
2047
2256
|
const { id, template, operation, hasDynamicChild } = dynamic;
|
|
2048
2257
|
if (id !== void 0 && template !== void 0) {
|
|
@@ -2050,10 +2259,10 @@ function genSelf(dynamic, context) {
|
|
|
2050
2259
|
push(...genDirectivesForElement(id, context));
|
|
2051
2260
|
}
|
|
2052
2261
|
if (operation) push(...genOperationWithInsertionState(operation, context));
|
|
2053
|
-
if (hasDynamicChild) push(...genChildren(dynamic, context, push, `n${id}
|
|
2262
|
+
if (hasDynamicChild) push(...genChildren(dynamic, context, push, `n${id}`, flushBeforeDynamic));
|
|
2054
2263
|
return frag;
|
|
2055
2264
|
}
|
|
2056
|
-
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}
|
|
2265
|
+
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flushBeforeDynamic) {
|
|
2057
2266
|
const { helper } = context;
|
|
2058
2267
|
const [frag, push] = buildCodeFragment();
|
|
2059
2268
|
const { children } = dynamic;
|
|
@@ -2062,12 +2271,14 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`) {
|
|
|
2062
2271
|
for (const [index, child] of children.entries()) {
|
|
2063
2272
|
if (child.flags & 2) offset--;
|
|
2064
2273
|
if (child.flags & 4 && child.template != null) {
|
|
2065
|
-
|
|
2274
|
+
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
2275
|
+
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2066
2276
|
continue;
|
|
2067
2277
|
}
|
|
2068
2278
|
const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
|
|
2069
2279
|
if (id === void 0 && !child.hasDynamicChild) {
|
|
2070
|
-
|
|
2280
|
+
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
2281
|
+
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2071
2282
|
continue;
|
|
2072
2283
|
}
|
|
2073
2284
|
const elementIndex = index + offset;
|
|
@@ -2083,14 +2294,16 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`) {
|
|
|
2083
2294
|
else if (elementIndex > 1) init = genCall(helper("nthChild"), from, String(elementIndex), logicalIndex);
|
|
2084
2295
|
pushBlock(...init);
|
|
2085
2296
|
}
|
|
2086
|
-
if (id === child.anchor && !child.hasDynamicChild)
|
|
2297
|
+
if (id === child.anchor && !child.hasDynamicChild) {
|
|
2298
|
+
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
2299
|
+
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2300
|
+
}
|
|
2087
2301
|
if (id !== void 0) push(...genDirectivesForElement(id, context));
|
|
2088
2302
|
prev = [variable, elementIndex];
|
|
2089
|
-
push(...genChildren(child, context, pushBlock, variable));
|
|
2303
|
+
push(...genChildren(child, context, pushBlock, variable, flushBeforeDynamic));
|
|
2090
2304
|
}
|
|
2091
2305
|
return frag;
|
|
2092
2306
|
}
|
|
2093
|
-
|
|
2094
2307
|
//#endregion
|
|
2095
2308
|
//#region packages/compiler-vapor/src/generators/block.ts
|
|
2096
2309
|
function genBlock(oper, context, args = [], root) {
|
|
@@ -2118,11 +2331,30 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
2118
2331
|
}
|
|
2119
2332
|
genResolveAssets("directive", "resolveDirective");
|
|
2120
2333
|
}
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2334
|
+
let operationIndex = 0;
|
|
2335
|
+
let effectIndex = 0;
|
|
2336
|
+
const flushPendingOperations = (operationEnd, effectEnd, push) => {
|
|
2337
|
+
while (operationIndex < operationEnd) {
|
|
2338
|
+
push(...genOperationWithInsertionState(operation[operationIndex], context));
|
|
2339
|
+
operationIndex++;
|
|
2340
|
+
}
|
|
2341
|
+
if (effectIndex < effectEnd) {
|
|
2342
|
+
push(...genEffects(effect.slice(effectIndex, effectEnd), context));
|
|
2343
|
+
effectIndex = effectEnd;
|
|
2344
|
+
}
|
|
2345
|
+
};
|
|
2346
|
+
const flushBeforeDynamic = (dynamic, push) => {
|
|
2347
|
+
const operation = dynamic.operation;
|
|
2348
|
+
if (operation && isBlockOperation(operation) && operation.operationIndex !== void 0 && operation.effectIndex !== void 0) flushPendingOperations(operation.operationIndex, operation.effectIndex, push);
|
|
2349
|
+
};
|
|
2350
|
+
for (const child of dynamic.children) {
|
|
2351
|
+
flushBeforeDynamic(child, push);
|
|
2352
|
+
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2353
|
+
}
|
|
2354
|
+
for (const child of dynamic.children) if (!child.hasDynamicChild) push(...genChildren(child, context, push, `n${child.id}`, flushBeforeDynamic));
|
|
2355
|
+
if (operationIndex < operation.length) push(...genOperations(operation.slice(operationIndex), context));
|
|
2356
|
+
if (effectIndex < effect.length) push(...genEffects(effect.slice(effectIndex), context, genEffectsExtraFrag));
|
|
2357
|
+
else if (genEffectsExtraFrag) push(...genEffects([], context, genEffectsExtraFrag));
|
|
2126
2358
|
push(NEWLINE, `return `);
|
|
2127
2359
|
const returnNodes = returns.map((n) => `n${n}`);
|
|
2128
2360
|
push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"]);
|
|
@@ -2132,7 +2364,6 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
2132
2364
|
for (const name of context.ir[kind]) push(NEWLINE, `const ${(0, _vue_compiler_dom.toValidAssetId)(name, kind)} = `, ...genCall(context.helper(helper), JSON.stringify(name)));
|
|
2133
2365
|
}
|
|
2134
2366
|
}
|
|
2135
|
-
|
|
2136
2367
|
//#endregion
|
|
2137
2368
|
//#region packages/compiler-vapor/src/generate.ts
|
|
2138
2369
|
const idWithTrailingDigitsRE = /^([A-Za-z_$][\w$]*)(\d+)$/;
|
|
@@ -2209,7 +2440,7 @@ var CodegenContext = class {
|
|
|
2209
2440
|
this.nextIdMap = /* @__PURE__ */ new Map();
|
|
2210
2441
|
this.lastIdMap = /* @__PURE__ */ new Map();
|
|
2211
2442
|
this.lastTIndex = -1;
|
|
2212
|
-
|
|
2443
|
+
const defaultOptions = {
|
|
2213
2444
|
mode: "module",
|
|
2214
2445
|
prefixIdentifiers: true,
|
|
2215
2446
|
sourceMap: false,
|
|
@@ -2224,7 +2455,8 @@ var CodegenContext = class {
|
|
|
2224
2455
|
inline: false,
|
|
2225
2456
|
bindingMetadata: {},
|
|
2226
2457
|
expressionPlugins: []
|
|
2227
|
-
}
|
|
2458
|
+
};
|
|
2459
|
+
this.options = (0, _vue_shared.extend)(defaultOptions, options);
|
|
2228
2460
|
this.block = ir.block;
|
|
2229
2461
|
this.bindingNames = new Set(this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []);
|
|
2230
2462
|
this.initNextIdMap();
|
|
@@ -2241,12 +2473,11 @@ function generate(ir, options = {}) {
|
|
|
2241
2473
|
if (!inline) push(NEWLINE, `export function ${functionName}(${signature}) {`);
|
|
2242
2474
|
push(INDENT_START);
|
|
2243
2475
|
if (ir.hasTemplateRef) push(NEWLINE, `const ${setTemplateRefIdent} = ${context.helper("createTemplateRefSetter")}()`);
|
|
2244
|
-
if (ir.hasDeferredVShow) push(NEWLINE, `const deferredApplyVShows = []`);
|
|
2245
2476
|
push(...genBlockContent(ir.block, context, true));
|
|
2246
2477
|
push(INDENT_END, NEWLINE);
|
|
2247
2478
|
if (!inline) push("}");
|
|
2248
2479
|
const delegates = genDelegates(context);
|
|
2249
|
-
const templates = genTemplates(ir.template
|
|
2480
|
+
const templates = genTemplates(ir.template.entries, context);
|
|
2250
2481
|
const preamble = genHelperImports(context) + genAssetImports(context) + templates + delegates;
|
|
2251
2482
|
const newlineCount = [...preamble].filter((c) => c === "\n").length;
|
|
2252
2483
|
if (newlineCount && !inline) frag.unshift(...new Array(newlineCount).fill(LF));
|
|
@@ -2277,92 +2508,50 @@ function genAssetImports({ ir }) {
|
|
|
2277
2508
|
}
|
|
2278
2509
|
return imports;
|
|
2279
2510
|
}
|
|
2280
|
-
|
|
2281
2511
|
//#endregion
|
|
2282
|
-
//#region packages/compiler-vapor/src/transforms/
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
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;
|
|
2299
|
-
}
|
|
2300
|
-
if (!isFragment) processDynamicChildren(context);
|
|
2301
|
-
};
|
|
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
|
-
}
|
|
2512
|
+
//#region packages/compiler-vapor/src/transforms/vBind.ts
|
|
2513
|
+
function normalizeBindShorthand(arg, context) {
|
|
2514
|
+
if (arg.type !== 4 || !arg.isStatic) {
|
|
2515
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(53, arg.loc));
|
|
2516
|
+
return (0, _vue_compiler_dom.createSimpleExpression)("", true, arg.loc);
|
|
2330
2517
|
}
|
|
2331
|
-
|
|
2332
|
-
|
|
2518
|
+
const exp = (0, _vue_compiler_dom.createSimpleExpression)((0, _vue_shared.camelize)(arg.content), false, arg.loc);
|
|
2519
|
+
exp.ast = null;
|
|
2520
|
+
return exp;
|
|
2333
2521
|
}
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
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
|
-
}
|
|
2522
|
+
const transformVBind = (dir, node, context) => {
|
|
2523
|
+
const { loc, modifiers } = dir;
|
|
2524
|
+
let { exp } = dir;
|
|
2525
|
+
let arg = dir.arg;
|
|
2526
|
+
const modifiersString = modifiers.map((s) => s.content);
|
|
2527
|
+
if (!exp) exp = normalizeBindShorthand(arg, context);
|
|
2528
|
+
if (!exp.content.trim()) {
|
|
2529
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(34, loc));
|
|
2530
|
+
exp = (0, _vue_compiler_dom.createSimpleExpression)("", true, loc);
|
|
2350
2531
|
}
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
};
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2532
|
+
const isComponent = node.tagType === 1;
|
|
2533
|
+
const isDom2DataAttr = context.options.platform && arg.isStatic && arg.content.length > 5 && arg.content.startsWith("data-");
|
|
2534
|
+
exp = resolveExpression(exp, isComponent || isDom2DataAttr);
|
|
2535
|
+
arg = resolveExpression(arg);
|
|
2536
|
+
if (arg.isStatic && isReservedProp(arg.content)) return;
|
|
2537
|
+
let camel = false;
|
|
2538
|
+
if (modifiersString.includes("camel")) if (arg.isStatic) arg = (0, _vue_shared.extend)({}, arg, { content: (0, _vue_shared.camelize)(arg.content) });
|
|
2539
|
+
else camel = true;
|
|
2540
|
+
return {
|
|
2541
|
+
key: arg,
|
|
2542
|
+
value: exp,
|
|
2543
|
+
loc,
|
|
2544
|
+
runtimeCamelize: camel,
|
|
2545
|
+
modifier: modifiersString.includes("prop") ? "." : modifiersString.includes("attr") ? "^" : void 0
|
|
2546
|
+
};
|
|
2547
|
+
};
|
|
2548
|
+
//#endregion
|
|
2549
|
+
//#region packages/compiler-vapor/src/transforms/transformElement.ts
|
|
2550
|
+
const isReservedProp = /* @__PURE__ */ (0, _vue_shared.makeMap)(",key,ref,ref_for,ref_key,");
|
|
2551
|
+
const transformElement = (node, context) => {
|
|
2552
|
+
let effectIndex = context.block.effect.length;
|
|
2553
|
+
const getEffectIndex = () => effectIndex++;
|
|
2554
|
+
let operationIndex = context.block.operation.length;
|
|
2366
2555
|
const getOperationIndex = () => operationIndex++;
|
|
2367
2556
|
let parentSlots;
|
|
2368
2557
|
if (node.type === 1 && (node.tagType === 1 || context.options.isCustomElement(node.tag))) {
|
|
@@ -2372,13 +2561,14 @@ const transformElement = (node, context) => {
|
|
|
2372
2561
|
return function postTransformElement() {
|
|
2373
2562
|
({node} = context);
|
|
2374
2563
|
if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) return;
|
|
2375
|
-
const
|
|
2376
|
-
const isComponent = node.tagType === 1 ||
|
|
2564
|
+
const useCreateElement = shouldUseCreateElement(node, context);
|
|
2565
|
+
const isComponent = node.tagType === 1 || useCreateElement;
|
|
2377
2566
|
const isDynamicComponent = isComponentTag(node.tag);
|
|
2567
|
+
const staticKey = resolveStaticKey(node, context, isComponent);
|
|
2378
2568
|
const propsResult = buildProps(node, context, isComponent, isDynamicComponent, getEffectIndex);
|
|
2379
2569
|
const singleRoot = isSingleRoot(context);
|
|
2380
|
-
if (isComponent) transformComponentElement(node, propsResult, singleRoot, context, isDynamicComponent,
|
|
2381
|
-
else transformNativeElement(node, propsResult, singleRoot, context, getEffectIndex, context.root === context.effectiveParent || canOmitEndTag(node, context), getOperationIndex);
|
|
2570
|
+
if (isComponent) transformComponentElement(node, propsResult, staticKey, singleRoot, context, isDynamicComponent, useCreateElement);
|
|
2571
|
+
else transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, context.root === context.effectiveParent || canOmitEndTag(node, context), getOperationIndex);
|
|
2382
2572
|
if (parentSlots) context.slots = parentSlots;
|
|
2383
2573
|
};
|
|
2384
2574
|
};
|
|
@@ -2386,11 +2576,35 @@ function canOmitEndTag(node, context) {
|
|
|
2386
2576
|
const { block, parent } = context;
|
|
2387
2577
|
if (!parent) return false;
|
|
2388
2578
|
if (block !== parent.block) return true;
|
|
2579
|
+
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;
|
|
2389
2580
|
if ((0, _vue_shared.isAlwaysCloseTag)(node.tag) && !context.isOnRightmostPath) return false;
|
|
2390
2581
|
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;
|
|
2392
2582
|
return context.isLastEffectiveChild;
|
|
2393
2583
|
}
|
|
2584
|
+
function getChildTemplateCloseState(context) {
|
|
2585
|
+
const { node } = context;
|
|
2586
|
+
if (node.type !== 1 || node.tagType !== 0 || shouldUseCreateElement(node, context)) return;
|
|
2587
|
+
const inSameTemplateAsParent = isInSameTemplateAsParent(context);
|
|
2588
|
+
const inheritedTags = inSameTemplateAsParent ? context.templateCloseTags : void 0;
|
|
2589
|
+
const inheritedBlocks = inSameTemplateAsParent && context.templateCloseBlocks;
|
|
2590
|
+
if (context.root === context.effectiveParent || canOmitEndTag(node, context) || (0, _vue_shared.isVoidTag)(node.tag)) return inheritedTags || inheritedBlocks ? {
|
|
2591
|
+
tags: inheritedTags,
|
|
2592
|
+
blocks: inheritedBlocks
|
|
2593
|
+
} : void 0;
|
|
2594
|
+
const tags = new Set(inheritedTags);
|
|
2595
|
+
tags.add(node.tag);
|
|
2596
|
+
return {
|
|
2597
|
+
tags,
|
|
2598
|
+
blocks: inheritedBlocks || (0, _vue_shared.isInlineTag)(node.tag)
|
|
2599
|
+
};
|
|
2600
|
+
}
|
|
2601
|
+
function isInSameTemplateAsParent(context) {
|
|
2602
|
+
const { parent, node, block } = context;
|
|
2603
|
+
if (!parent || block !== parent.block) return false;
|
|
2604
|
+
const parentNode = parent.node;
|
|
2605
|
+
if (parentNode.type !== 1 || parentNode.tagType !== 0) return false;
|
|
2606
|
+
return !shouldUseCreateElement(parentNode, parent) && (0, _vue_compiler_dom.isValidHTMLNesting)(parentNode.tag, node.tag);
|
|
2607
|
+
}
|
|
2394
2608
|
function isSingleRoot(context) {
|
|
2395
2609
|
if (context.inVFor) return false;
|
|
2396
2610
|
let { parent } = context;
|
|
@@ -2401,11 +2615,11 @@ function isSingleRoot(context) {
|
|
|
2401
2615
|
}
|
|
2402
2616
|
return context.root === parent;
|
|
2403
2617
|
}
|
|
2404
|
-
function transformComponentElement(node, propsResult, singleRoot, context, isDynamicComponent,
|
|
2618
|
+
function transformComponentElement(node, propsResult, staticKey, singleRoot, context, isDynamicComponent, useCreateElement) {
|
|
2405
2619
|
const dynamicComponent = isDynamicComponent ? resolveDynamicComponent(node) : void 0;
|
|
2406
2620
|
let { tag } = node;
|
|
2407
2621
|
let asset = true;
|
|
2408
|
-
if (!dynamicComponent && !
|
|
2622
|
+
if (!dynamicComponent && !useCreateElement) {
|
|
2409
2623
|
const { isEasyComponent } = context.options;
|
|
2410
2624
|
const isEasyCom = isEasyComponent && isEasyComponent(tag);
|
|
2411
2625
|
if (!isEasyCom) {
|
|
@@ -2434,10 +2648,12 @@ function transformComponentElement(node, propsResult, singleRoot, context, isDyn
|
|
|
2434
2648
|
}
|
|
2435
2649
|
}
|
|
2436
2650
|
context.dynamic.flags |= 6;
|
|
2651
|
+
const id = context.reference();
|
|
2437
2652
|
context.dynamic.operation = {
|
|
2438
|
-
type:
|
|
2653
|
+
type: 12,
|
|
2439
2654
|
node,
|
|
2440
|
-
id
|
|
2655
|
+
id,
|
|
2656
|
+
...context.effectBoundary(),
|
|
2441
2657
|
tag,
|
|
2442
2658
|
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
|
|
2443
2659
|
asset,
|
|
@@ -2445,8 +2661,9 @@ function transformComponentElement(node, propsResult, singleRoot, context, isDyn
|
|
|
2445
2661
|
slots: [...context.slots],
|
|
2446
2662
|
once: context.inVOnce,
|
|
2447
2663
|
dynamic: dynamicComponent,
|
|
2448
|
-
|
|
2664
|
+
useCreateElement
|
|
2449
2665
|
};
|
|
2666
|
+
if (staticKey) context.registerOperation(createSetBlockKey(id, staticKey, node));
|
|
2450
2667
|
context.slots = [];
|
|
2451
2668
|
}
|
|
2452
2669
|
function resolveDynamicComponent(node) {
|
|
@@ -2464,7 +2681,7 @@ function resolveSetupReference(name, context) {
|
|
|
2464
2681
|
}
|
|
2465
2682
|
const dynamicKeys = ["indeterminate"];
|
|
2466
2683
|
const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
|
|
2467
|
-
function transformNativeElement(node, propsResult, singleRoot, context, getEffectIndex, omitEndTag, getOperationIndex) {
|
|
2684
|
+
function transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, omitEndTag, getOperationIndex) {
|
|
2468
2685
|
const isDom2 = !!context.options.platform;
|
|
2469
2686
|
if (isDom2) omitEndTag = false;
|
|
2470
2687
|
const { tag } = node;
|
|
@@ -2472,21 +2689,27 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
2472
2689
|
let template = "";
|
|
2473
2690
|
template += `<${tag}`;
|
|
2474
2691
|
if (scopeId) template += ` ${scopeId}`;
|
|
2475
|
-
if (isDom2
|
|
2476
|
-
template += ` gen-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2692
|
+
if (isDom2) {
|
|
2693
|
+
if (context.effectiveParent === context.root) template += ` gen-vue-id=""`;
|
|
2694
|
+
if (singleRoot) {
|
|
2695
|
+
template += ` gen-flag-flatten=""`;
|
|
2696
|
+
const rootElementTagName = context.options.rootElementTagName;
|
|
2697
|
+
if (rootElementTagName) {
|
|
2698
|
+
template += ` custom-tag-name="${rootElementTagName}"`;
|
|
2699
|
+
if (context.options.rootElementFromUniModule) template += ` gen-root-custom-native="${rootElementTagName}"`;
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2480
2702
|
}
|
|
2481
2703
|
const dynamicProps = [];
|
|
2482
2704
|
if (propsResult[0]) {
|
|
2483
2705
|
const [, dynamicArgs, expressions] = propsResult;
|
|
2484
2706
|
context.registerEffect(expressions, {
|
|
2485
|
-
type:
|
|
2707
|
+
type: 4,
|
|
2486
2708
|
node,
|
|
2487
2709
|
element: context.reference(),
|
|
2488
2710
|
props: dynamicArgs,
|
|
2489
|
-
tag
|
|
2711
|
+
tag,
|
|
2712
|
+
root: singleRoot && context.effectiveParent === context.root && context.options.componentType === "component"
|
|
2490
2713
|
}, getEffectIndex);
|
|
2491
2714
|
} else {
|
|
2492
2715
|
const changeProps = [];
|
|
@@ -2514,6 +2737,7 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
2514
2737
|
}
|
|
2515
2738
|
let hasStaticStyle = false;
|
|
2516
2739
|
let hasClass = false;
|
|
2740
|
+
const datasetProps = [];
|
|
2517
2741
|
let prevWasQuoted = false;
|
|
2518
2742
|
for (const prop of propsResult[1]) {
|
|
2519
2743
|
const { key, values } = prop;
|
|
@@ -2522,7 +2746,7 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
2522
2746
|
dynamicProps.push(key.content);
|
|
2523
2747
|
values[0].isStatic = false;
|
|
2524
2748
|
context.registerEffect(values, {
|
|
2525
|
-
type:
|
|
2749
|
+
type: 20,
|
|
2526
2750
|
node,
|
|
2527
2751
|
prop
|
|
2528
2752
|
}, getEffectIndex);
|
|
@@ -2546,7 +2770,7 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
2546
2770
|
if (isDom2 && (key.content === "class" || key.content === "hover-class" || key.content === "style" && context.options.disableStaticStyle)) {
|
|
2547
2771
|
dynamicProps.push(key.content);
|
|
2548
2772
|
context.registerEffect(values, {
|
|
2549
|
-
type:
|
|
2773
|
+
type: 3,
|
|
2550
2774
|
node,
|
|
2551
2775
|
element: context.reference(),
|
|
2552
2776
|
prop,
|
|
@@ -2562,7 +2786,7 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
2562
2786
|
} else {
|
|
2563
2787
|
dynamicProps.push(key.content);
|
|
2564
2788
|
context.registerEffect(values, {
|
|
2565
|
-
type:
|
|
2789
|
+
type: 3,
|
|
2566
2790
|
node,
|
|
2567
2791
|
isChangeProp: changeProps.includes(key.content),
|
|
2568
2792
|
element: context.reference(),
|
|
@@ -2572,15 +2796,45 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
2572
2796
|
}
|
|
2573
2797
|
}
|
|
2574
2798
|
if (hasStaticStyle && hasClass) template += ` ext:style`;
|
|
2799
|
+
if (datasetProps.length) {
|
|
2800
|
+
const expressions = datasetProps.flatMap((prop) => prop.values);
|
|
2801
|
+
context.registerEffect(expressions, {
|
|
2802
|
+
type: 3,
|
|
2803
|
+
node,
|
|
2804
|
+
element: context.reference(),
|
|
2805
|
+
prop: {
|
|
2806
|
+
...datasetProps[0],
|
|
2807
|
+
datasetProps
|
|
2808
|
+
},
|
|
2809
|
+
tag,
|
|
2810
|
+
root: singleRoot && context.effectiveParent === context.root && context.options.componentType === "component"
|
|
2811
|
+
}, getEffectIndex);
|
|
2812
|
+
}
|
|
2575
2813
|
}
|
|
2576
2814
|
template += `>` + context.childrenTemplate.join("");
|
|
2577
2815
|
if (!(0, _vue_shared.isVoidTag)(tag) && !omitEndTag) template += `</${tag}>`;
|
|
2578
|
-
|
|
2816
|
+
context.templateRoot = singleRoot;
|
|
2579
2817
|
if (context.parent && context.parent.node.type === 1 && !(0, _vue_compiler_dom.isValidHTMLNesting)(context.parent.node.tag, tag)) {
|
|
2580
2818
|
context.reference();
|
|
2581
2819
|
context.dynamic.template = context.pushTemplate(template);
|
|
2582
2820
|
context.dynamic.flags |= 6;
|
|
2583
2821
|
} else context.template += template;
|
|
2822
|
+
if (staticKey) context.registerOperation(createSetBlockKey(context.reference(), staticKey, node));
|
|
2823
|
+
}
|
|
2824
|
+
function resolveStaticKey(node, context, isComponent) {
|
|
2825
|
+
const keyProp = findProp$1(node, "key", false, true);
|
|
2826
|
+
if (!keyProp) return;
|
|
2827
|
+
if (keyProp.type === 6) return keyProp.value ? (0, _vue_compiler_dom.createSimpleExpression)(keyProp.value.content, true, keyProp.value.loc) : EMPTY_EXPRESSION;
|
|
2828
|
+
const value = keyProp.exp || normalizeBindShorthand(keyProp.arg, context);
|
|
2829
|
+
if (isStaticExpression(value, context.options.bindingMetadata)) return resolveExpression(value, isComponent);
|
|
2830
|
+
}
|
|
2831
|
+
function createSetBlockKey(element, value, node) {
|
|
2832
|
+
return {
|
|
2833
|
+
type: 2,
|
|
2834
|
+
node,
|
|
2835
|
+
element,
|
|
2836
|
+
value
|
|
2837
|
+
};
|
|
2584
2838
|
}
|
|
2585
2839
|
function buildProps(node, context, isComponent, isDynamicComponent, getEffectIndex) {
|
|
2586
2840
|
const props = node.props;
|
|
@@ -2616,7 +2870,7 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
2616
2870
|
handler: true
|
|
2617
2871
|
});
|
|
2618
2872
|
} else context.registerEffect([prop.exp], {
|
|
2619
|
-
type:
|
|
2873
|
+
type: 7,
|
|
2620
2874
|
node,
|
|
2621
2875
|
element: context.reference(),
|
|
2622
2876
|
event: prop.exp
|
|
@@ -2625,7 +2879,7 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
2625
2879
|
continue;
|
|
2626
2880
|
}
|
|
2627
2881
|
}
|
|
2628
|
-
if (isDynamicComponent && prop.type === 6 && prop.name === "is" || prop.type === 7 && prop.name === "bind" && (0, _vue_compiler_dom.isStaticArgOf)(prop.arg, "is")) continue;
|
|
2882
|
+
if (isDynamicComponent && (prop.type === 6 && prop.name === "is" || prop.type === 7 && prop.name === "bind" && (0, _vue_compiler_dom.isStaticArgOf)(prop.arg, "is"))) continue;
|
|
2629
2883
|
const result = transformProp(prop, node, context);
|
|
2630
2884
|
if (result) {
|
|
2631
2885
|
dynamicExpr.push(result.key, result.value);
|
|
@@ -2661,7 +2915,7 @@ function transformProp(prop, node, context) {
|
|
|
2661
2915
|
if (fromSetup) name = fromSetup;
|
|
2662
2916
|
else context.directive.add(name);
|
|
2663
2917
|
context.registerOperation({
|
|
2664
|
-
type:
|
|
2918
|
+
type: 14,
|
|
2665
2919
|
node,
|
|
2666
2920
|
element: context.reference(),
|
|
2667
2921
|
dir: prop,
|
|
@@ -2703,7 +2957,92 @@ function mergePropValues(existing, incoming) {
|
|
|
2703
2957
|
function isComponentTag(tag) {
|
|
2704
2958
|
return tag === "component" || tag === "Component";
|
|
2705
2959
|
}
|
|
2706
|
-
|
|
2960
|
+
function shouldUseCreateElement(node, context) {
|
|
2961
|
+
return context.options.isCustomElement(node.tag) || node.tagType === 0 && node.tag === "template";
|
|
2962
|
+
}
|
|
2963
|
+
//#endregion
|
|
2964
|
+
//#region packages/compiler-vapor/src/transforms/transformChildren.ts
|
|
2965
|
+
const transformChildren = (node, context) => {
|
|
2966
|
+
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
2967
|
+
if (!isFragment && node.type !== 1) return;
|
|
2968
|
+
const useCreateElement = node.type === 1 && shouldUseCreateElement(node, context);
|
|
2969
|
+
const childTemplateCloseState = !isFragment && !useCreateElement ? getChildTemplateCloseState(context) : void 0;
|
|
2970
|
+
for (const [i, child] of node.children.entries()) {
|
|
2971
|
+
const childContext = context.create(child, i);
|
|
2972
|
+
const isInSameTemplate = childTemplateCloseState && child.type === 1 && child.tagType === 0 && isInSameTemplateAsParent(childContext);
|
|
2973
|
+
childContext.templateCloseTags = isInSameTemplate ? childTemplateCloseState.tags : void 0;
|
|
2974
|
+
childContext.templateCloseBlocks = isInSameTemplate ? childTemplateCloseState.blocks : false;
|
|
2975
|
+
transformNode(childContext);
|
|
2976
|
+
const childDynamic = childContext.dynamic;
|
|
2977
|
+
if (isFragment) {
|
|
2978
|
+
childContext.reference();
|
|
2979
|
+
childContext.registerTemplate();
|
|
2980
|
+
if (!(childDynamic.flags & 2) || childDynamic.flags & 4) context.block.returns.push(childContext.dynamic.id);
|
|
2981
|
+
} else if (useCreateElement) {
|
|
2982
|
+
if (childContext.template !== "" || childDynamic.template != null || childDynamic.id !== void 0 || childDynamic.operation !== void 0 || childDynamic.hasDynamicChild === true) {
|
|
2983
|
+
childContext.reference();
|
|
2984
|
+
childContext.registerTemplate();
|
|
2985
|
+
childDynamic.flags |= 6;
|
|
2986
|
+
}
|
|
2987
|
+
} else context.childrenTemplate.push(childContext.template);
|
|
2988
|
+
if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & 2 || childDynamic.flags & 4) context.dynamic.hasDynamicChild = true;
|
|
2989
|
+
childDynamic.type = child.type;
|
|
2990
|
+
if (child.type === 1) childDynamic.tag = child.tag;
|
|
2991
|
+
context.dynamic.children[i] = childDynamic;
|
|
2992
|
+
}
|
|
2993
|
+
if (!isFragment) processDynamicChildren(context);
|
|
2994
|
+
};
|
|
2995
|
+
function processDynamicChildren(context) {
|
|
2996
|
+
let prevDynamics = [];
|
|
2997
|
+
let staticCount = 0;
|
|
2998
|
+
const children = context.dynamic.children;
|
|
2999
|
+
let logicalIndex = 0;
|
|
3000
|
+
for (const [index, child] of children.entries()) {
|
|
3001
|
+
if (child.flags & 4) {
|
|
3002
|
+
child.logicalIndex = logicalIndex;
|
|
3003
|
+
prevDynamics.push(child);
|
|
3004
|
+
logicalIndex++;
|
|
3005
|
+
}
|
|
3006
|
+
if (!(child.flags & 2)) {
|
|
3007
|
+
child.logicalIndex = logicalIndex;
|
|
3008
|
+
if (prevDynamics.length) {
|
|
3009
|
+
if (staticCount) {
|
|
3010
|
+
context.childrenTemplate[index - prevDynamics.length] = `<!>`;
|
|
3011
|
+
prevDynamics[0].flags -= 2;
|
|
3012
|
+
const anchor = prevDynamics[0].anchor = context.increaseId();
|
|
3013
|
+
registerInsertion(prevDynamics, context, anchor);
|
|
3014
|
+
} else registerInsertion(prevDynamics, context, -1);
|
|
3015
|
+
prevDynamics = [];
|
|
3016
|
+
}
|
|
3017
|
+
staticCount++;
|
|
3018
|
+
logicalIndex++;
|
|
3019
|
+
}
|
|
3020
|
+
}
|
|
3021
|
+
if (prevDynamics.length) registerInsertion(prevDynamics, context, prevDynamics[0].logicalIndex, true);
|
|
3022
|
+
}
|
|
3023
|
+
function registerInsertion(dynamics, context, anchor, append) {
|
|
3024
|
+
for (const child of dynamics) {
|
|
3025
|
+
const logicalIndex = child.logicalIndex;
|
|
3026
|
+
if (child.template != null) context.registerOperation({
|
|
3027
|
+
type: 10,
|
|
3028
|
+
node: context.node,
|
|
3029
|
+
elements: dynamics.map((child) => child.id),
|
|
3030
|
+
parent: context.reference(),
|
|
3031
|
+
anchor: append ? void 0 : anchor
|
|
3032
|
+
});
|
|
3033
|
+
else if (child.operation && isBlockOperation(child.operation)) {
|
|
3034
|
+
child.operation.parent = context.reference();
|
|
3035
|
+
child.operation.anchor = anchor;
|
|
3036
|
+
child.operation.logicalIndex = logicalIndex;
|
|
3037
|
+
child.operation.append = append;
|
|
3038
|
+
}
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
//#endregion
|
|
3042
|
+
//#region packages/compiler-vapor/src/transforms/vOnce.ts
|
|
3043
|
+
const transformVOnce = (node, context) => {
|
|
3044
|
+
if (node.type === 1 && (0, _vue_compiler_dom.findDir)(node, "once", true)) context.inVOnce = true;
|
|
3045
|
+
};
|
|
2707
3046
|
//#endregion
|
|
2708
3047
|
//#region packages/compiler-vapor/src/transforms/vHtml.ts
|
|
2709
3048
|
const transformVHtml = (dir, node, context) => {
|
|
@@ -2717,14 +3056,13 @@ const transformVHtml = (dir, node, context) => {
|
|
|
2717
3056
|
context.childrenTemplate.length = 0;
|
|
2718
3057
|
}
|
|
2719
3058
|
context.registerEffect([exp], {
|
|
2720
|
-
type:
|
|
3059
|
+
type: 8,
|
|
2721
3060
|
node,
|
|
2722
3061
|
element: context.reference(),
|
|
2723
3062
|
value: exp,
|
|
2724
3063
|
isComponent: node.tagType === 1
|
|
2725
3064
|
});
|
|
2726
3065
|
};
|
|
2727
|
-
|
|
2728
3066
|
//#endregion
|
|
2729
3067
|
//#region packages/shared/src/makeMap.ts
|
|
2730
3068
|
/**
|
|
@@ -2740,16 +3078,164 @@ function makeMap$1(str) {
|
|
|
2740
3078
|
for (const key of str.split(",")) map[key] = 1;
|
|
2741
3079
|
return (val) => val in map;
|
|
2742
3080
|
}
|
|
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
3081
|
/**
|
|
2748
3082
|
* Compiler only.
|
|
2749
3083
|
* Do NOT use in runtime code paths unless behind `__DEV__` flag.
|
|
2750
3084
|
*/
|
|
2751
|
-
const isVoidTag = /* @__PURE__ */ makeMap$1(
|
|
2752
|
-
|
|
3085
|
+
const isVoidTag = /* @__PURE__ */ makeMap$1("area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr");
|
|
3086
|
+
//#endregion
|
|
3087
|
+
//#region packages/compiler-vapor/src/transforms/transformText.ts
|
|
3088
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
3089
|
+
function markNonTemplate(node, context) {
|
|
3090
|
+
let seenNodes = seen.get(context.root);
|
|
3091
|
+
if (!seenNodes) {
|
|
3092
|
+
seenNodes = /* @__PURE__ */ new WeakSet();
|
|
3093
|
+
seen.set(context.root, seenNodes);
|
|
3094
|
+
}
|
|
3095
|
+
seenNodes.add(node);
|
|
3096
|
+
}
|
|
3097
|
+
const transformText = (node, context) => {
|
|
3098
|
+
if (!seen.has(context.root)) seen.set(context.root, /* @__PURE__ */ new WeakSet());
|
|
3099
|
+
if (seen.get(context.root).has(node)) {
|
|
3100
|
+
context.dynamic.flags |= 2;
|
|
3101
|
+
return;
|
|
3102
|
+
}
|
|
3103
|
+
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
3104
|
+
if ((isFragment || node.type === 1 && node.tagType === 0) && node.children.length) {
|
|
3105
|
+
let hasInterp = false;
|
|
3106
|
+
let isAllTextLike = true;
|
|
3107
|
+
for (const c of node.children) if (c.type === 5) hasInterp = true;
|
|
3108
|
+
else if (c.type !== 2) isAllTextLike = false;
|
|
3109
|
+
if (!isFragment && isAllTextLike && hasInterp) {
|
|
3110
|
+
const elementContext = context;
|
|
3111
|
+
if (shouldUseCreateElement(node, elementContext)) processCreateElementTextContainer(node.children, elementContext);
|
|
3112
|
+
else processTextContainer(node.children, elementContext);
|
|
3113
|
+
} else if (hasInterp) for (let i = 0; i < node.children.length; i++) {
|
|
3114
|
+
const c = node.children[i];
|
|
3115
|
+
const prev = node.children[i - 1];
|
|
3116
|
+
if (c.type === 5 && prev && prev.type === 2) markNonTemplate(prev, context);
|
|
3117
|
+
}
|
|
3118
|
+
} else if (node.type === 5) processInterpolation(context);
|
|
3119
|
+
else if (node.type === 2) {
|
|
3120
|
+
var _context$parent;
|
|
3121
|
+
const parent = (_context$parent = context.parent) === null || _context$parent === void 0 ? void 0 : _context$parent.node;
|
|
3122
|
+
if (parent && parent.type === 1 && shouldUseCreateElement(parent, context.parent) && node.content[0] === "<") {
|
|
3123
|
+
materializeLiteralTextNode((0, _vue_compiler_dom.createSimpleExpression)(node.content, true, node.loc), context);
|
|
3124
|
+
return;
|
|
3125
|
+
}
|
|
3126
|
+
const isRootText = !parent || parent.type === 0 || parent.type === 1 && (parent.tagType === 3 || parent.tagType === 1);
|
|
3127
|
+
context.template += isRootText ? node.content : (0, _vue_shared.escapeHtml)(node.content);
|
|
3128
|
+
}
|
|
3129
|
+
};
|
|
3130
|
+
function processInterpolation(context) {
|
|
3131
|
+
const parentNode = context.parent.node;
|
|
3132
|
+
const children = parentNode.children;
|
|
3133
|
+
const nexts = children.slice(context.index);
|
|
3134
|
+
const idx = nexts.findIndex((n) => !isTextLike(n));
|
|
3135
|
+
const nodes = idx > -1 ? nexts.slice(0, idx) : nexts;
|
|
3136
|
+
const prev = children[context.index - 1];
|
|
3137
|
+
if (prev && prev.type === 2) nodes.unshift(prev);
|
|
3138
|
+
const values = processTextLikeChildren(nodes, context);
|
|
3139
|
+
if (values.length === 0 && parentNode.type !== 0) return;
|
|
3140
|
+
const literalValues = values.map((v) => getLiteralExpressionValue(v));
|
|
3141
|
+
if (literalValues.every((v) => v != null) && parentNode.type !== 0) {
|
|
3142
|
+
const text = literalValues.join("");
|
|
3143
|
+
if (parentNode.type === 1 && shouldUseCreateElement(parentNode, context.parent) && text[0] === "<") {
|
|
3144
|
+
materializeLiteralTextNode((0, _vue_compiler_dom.createSimpleExpression)(text, true, context.node.loc), context);
|
|
3145
|
+
return;
|
|
3146
|
+
}
|
|
3147
|
+
const isElementChild = parentNode.type === 1 && parentNode.tagType === 0;
|
|
3148
|
+
context.template += isElementChild ? (0, _vue_shared.escapeHtml)(text) : text;
|
|
3149
|
+
return;
|
|
3150
|
+
}
|
|
3151
|
+
const isDom2 = !!context.options.platform;
|
|
3152
|
+
let isTextNode = false;
|
|
3153
|
+
let isInComponentSlot = false;
|
|
3154
|
+
let shouldReuseParentText = false;
|
|
3155
|
+
if (isDom2) {
|
|
3156
|
+
const grandNode = context.parent.parent && context.parent.parent.node;
|
|
3157
|
+
function isComponent(node) {
|
|
3158
|
+
return !!(node && node.type === 1 && node.tagType === 1);
|
|
3159
|
+
}
|
|
3160
|
+
isInComponentSlot = parentNode.type === 1 && (parentNode.tagType === 1 || (0, _vue_compiler_dom.isTemplateNode)(parentNode) && isComponent(grandNode));
|
|
3161
|
+
shouldReuseParentText = !!(!isInComponentSlot && parentNode.loc.source.startsWith("<slot") && parentNode.type === 1 && parentNode.tag === "template" && grandNode && grandNode.tag === "text" && parentNode.children.every((child) => isTextLike(child)));
|
|
3162
|
+
isTextNode = isInComponentSlot || shouldReuseParentText;
|
|
3163
|
+
}
|
|
3164
|
+
context.template += isDom2 ? isTextNode ? TEXT_NODE_PLACEHOLDER : TEXT_PLACEHOLDER : " ";
|
|
3165
|
+
const id = context.reference();
|
|
3166
|
+
if (values.length === 0) return;
|
|
3167
|
+
context.registerEffect(values, {
|
|
3168
|
+
type: 5,
|
|
3169
|
+
node: context.node,
|
|
3170
|
+
element: id,
|
|
3171
|
+
values
|
|
3172
|
+
});
|
|
3173
|
+
}
|
|
3174
|
+
function processTextContainer(children, context) {
|
|
3175
|
+
const values = processTextLikeChildren(children, context);
|
|
3176
|
+
const literals = values.map((value) => getLiteralExpressionValue(value));
|
|
3177
|
+
if (literals.every((l) => l != null)) context.childrenTemplate = literals.map((l) => (0, _vue_shared.escapeHtml)(String(l)));
|
|
3178
|
+
else {
|
|
3179
|
+
context.childrenTemplate = [context.options.platform ? TEXT_PLACEHOLDER : " "];
|
|
3180
|
+
context.registerOperation({
|
|
3181
|
+
type: 18,
|
|
3182
|
+
node: context.node,
|
|
3183
|
+
parent: context.reference()
|
|
3184
|
+
});
|
|
3185
|
+
context.registerEffect(values, {
|
|
3186
|
+
type: 5,
|
|
3187
|
+
node: context.node,
|
|
3188
|
+
element: context.reference(),
|
|
3189
|
+
values,
|
|
3190
|
+
generated: true
|
|
3191
|
+
});
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
function registerSyntheticTextChild(context, template, values) {
|
|
3195
|
+
const id = context.increaseId();
|
|
3196
|
+
context.dynamic.children[context.node.children.length] = {
|
|
3197
|
+
id,
|
|
3198
|
+
flags: 6,
|
|
3199
|
+
children: [],
|
|
3200
|
+
template: context.pushTemplate(template)
|
|
3201
|
+
};
|
|
3202
|
+
context.dynamic.hasDynamicChild = true;
|
|
3203
|
+
if (values && values.length) context.registerEffect(values, {
|
|
3204
|
+
type: 5,
|
|
3205
|
+
node: context.node,
|
|
3206
|
+
element: id,
|
|
3207
|
+
values
|
|
3208
|
+
});
|
|
3209
|
+
return id;
|
|
3210
|
+
}
|
|
3211
|
+
function processCreateElementTextContainer(children, context) {
|
|
3212
|
+
registerSyntheticTextChild(context, "", processTextLikeChildren(children, context));
|
|
3213
|
+
}
|
|
3214
|
+
function materializeLiteralTextNode(value, context) {
|
|
3215
|
+
const id = context.reference();
|
|
3216
|
+
context.dynamic.flags |= 6;
|
|
3217
|
+
context.dynamic.template = context.pushTemplate("");
|
|
3218
|
+
context.registerEffect([value], {
|
|
3219
|
+
type: 5,
|
|
3220
|
+
node: context.node,
|
|
3221
|
+
element: id,
|
|
3222
|
+
values: [value]
|
|
3223
|
+
});
|
|
3224
|
+
}
|
|
3225
|
+
function processTextLikeChildren(nodes, context) {
|
|
3226
|
+
const exps = [];
|
|
3227
|
+
for (const node of nodes) {
|
|
3228
|
+
let exp;
|
|
3229
|
+
markNonTemplate(node, context);
|
|
3230
|
+
if (node.type === 2) exp = (0, _vue_compiler_dom.createSimpleExpression)(node.content, true, node.loc);
|
|
3231
|
+
else exp = node.content;
|
|
3232
|
+
if (exp.content) exps.push(exp);
|
|
3233
|
+
}
|
|
3234
|
+
return exps;
|
|
3235
|
+
}
|
|
3236
|
+
function isTextLike(node) {
|
|
3237
|
+
return node.type === 5 || node.type === 2;
|
|
3238
|
+
}
|
|
2753
3239
|
//#endregion
|
|
2754
3240
|
//#region packages/compiler-vapor/src/transforms/vText.ts
|
|
2755
3241
|
const transformVText = (dir, node, context) => {
|
|
@@ -2761,66 +3247,49 @@ const transformVText = (dir, node, context) => {
|
|
|
2761
3247
|
if (node.children.length) {
|
|
2762
3248
|
context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(57, loc));
|
|
2763
3249
|
context.childrenTemplate.length = 0;
|
|
3250
|
+
for (const child of node.children) markNonTemplate(child, context);
|
|
2764
3251
|
}
|
|
2765
3252
|
if (isVoidTag(context.node.tag)) return;
|
|
2766
3253
|
const literal = getLiteralExpressionValue(exp);
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
type: 16,
|
|
3254
|
+
const useCreateElement = shouldUseCreateElement(context.node, context);
|
|
3255
|
+
if (literal != null) if (useCreateElement) {
|
|
3256
|
+
const id = registerSyntheticTextChild(context, "", [exp]);
|
|
3257
|
+
context.registerOperation({
|
|
3258
|
+
type: 10,
|
|
2773
3259
|
node,
|
|
3260
|
+
elements: [id],
|
|
2774
3261
|
parent: context.reference()
|
|
2775
3262
|
});
|
|
3263
|
+
} else context.childrenTemplate = [String(literal)];
|
|
3264
|
+
else {
|
|
3265
|
+
const isComponent = node.tagType === 1;
|
|
3266
|
+
let id;
|
|
3267
|
+
if (useCreateElement) {
|
|
3268
|
+
id = registerSyntheticTextChild(context, "");
|
|
3269
|
+
context.registerOperation({
|
|
3270
|
+
type: 10,
|
|
3271
|
+
node,
|
|
3272
|
+
elements: [id],
|
|
3273
|
+
parent: context.reference()
|
|
3274
|
+
});
|
|
3275
|
+
} else {
|
|
3276
|
+
context.childrenTemplate = [context.options.platform ? TEXT_PLACEHOLDER : " "];
|
|
3277
|
+
if (!isComponent) context.registerOperation({
|
|
3278
|
+
type: 18,
|
|
3279
|
+
node,
|
|
3280
|
+
parent: context.reference()
|
|
3281
|
+
});
|
|
3282
|
+
}
|
|
2776
3283
|
context.registerEffect([exp], {
|
|
2777
|
-
type:
|
|
3284
|
+
type: 5,
|
|
2778
3285
|
node,
|
|
2779
|
-
element: context.reference(),
|
|
3286
|
+
element: useCreateElement ? id : context.reference(),
|
|
2780
3287
|
values: [exp],
|
|
2781
|
-
generated:
|
|
3288
|
+
generated: !useCreateElement,
|
|
2782
3289
|
isComponent
|
|
2783
3290
|
});
|
|
2784
3291
|
}
|
|
2785
3292
|
};
|
|
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
|
-
|
|
2824
3293
|
//#endregion
|
|
2825
3294
|
//#region packages/compiler-vapor/src/transforms/vOn.ts
|
|
2826
3295
|
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");
|
|
@@ -2830,18 +3299,18 @@ const transformVOn = (dir, node, context) => {
|
|
|
2830
3299
|
const isSlotOutlet = node.tag === "slot";
|
|
2831
3300
|
if (!exp && !modifiers.length) context.options.onError((0, _vue_compiler_dom.createCompilerError)(35, loc));
|
|
2832
3301
|
arg = resolveExpression(arg);
|
|
3302
|
+
if (arg.isStatic && arg.content.startsWith("vue:")) arg = (0, _vue_shared.extend)({}, arg, { content: `vnode-${arg.content.slice(4)}` });
|
|
2833
3303
|
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = (0, _vue_compiler_dom.resolveModifiers)(arg.isStatic ? `on${arg.content}` : arg, modifiers, null, loc);
|
|
2834
3304
|
let keyOverride;
|
|
2835
3305
|
const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
|
|
2836
3306
|
if (nonKeyModifiers.includes("middle")) {
|
|
2837
3307
|
if (keyOverride) {}
|
|
2838
|
-
if (isStaticClick
|
|
2839
|
-
else if (!arg.isStatic) keyOverride = ["click", "mouseup"];
|
|
3308
|
+
if (!isStaticClick && !arg.isStatic) keyOverride = ["click", "mouseup"];
|
|
2840
3309
|
}
|
|
2841
3310
|
if (nonKeyModifiers.includes("right")) {
|
|
2842
|
-
if (isStaticClick
|
|
2843
|
-
else if (!arg.isStatic) keyOverride = ["click", "contextmenu"];
|
|
3311
|
+
if (!isStaticClick && !arg.isStatic) keyOverride = ["click", "contextmenu"];
|
|
2844
3312
|
}
|
|
3313
|
+
arg = normalizeStaticEventArg(arg, nonKeyModifiers);
|
|
2845
3314
|
if (keyModifiers.length && (0, _vue_compiler_dom.isStaticExp)(arg) && !(0, _vue_compiler_dom.isKeyboardEvent)(`on${arg.content.toLowerCase()}`)) keyModifiers.length = 0;
|
|
2846
3315
|
if (isComponent || isSlotOutlet) return {
|
|
2847
3316
|
key: arg,
|
|
@@ -2853,9 +3322,9 @@ const transformVOn = (dir, node, context) => {
|
|
|
2853
3322
|
options: eventOptionModifiers
|
|
2854
3323
|
}
|
|
2855
3324
|
};
|
|
2856
|
-
const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
|
|
3325
|
+
const delegate = arg.isStatic && !eventOptionModifiers.length && !hasStopHandlerForStaticEvent(node, arg.content) && delegatedEvents(arg.content);
|
|
2857
3326
|
const operation = {
|
|
2858
|
-
type:
|
|
3327
|
+
type: 6,
|
|
2859
3328
|
node,
|
|
2860
3329
|
element: context.reference(),
|
|
2861
3330
|
key: arg,
|
|
@@ -2871,7 +3340,23 @@ const transformVOn = (dir, node, context) => {
|
|
|
2871
3340
|
};
|
|
2872
3341
|
context.registerEffect([arg], operation);
|
|
2873
3342
|
};
|
|
2874
|
-
|
|
3343
|
+
function normalizeStaticEventArg(arg, nonKeyModifiers) {
|
|
3344
|
+
if (!arg.isStatic) return arg;
|
|
3345
|
+
let normalized = arg;
|
|
3346
|
+
const isStaticClick = arg.content.toLowerCase() === "click";
|
|
3347
|
+
if (nonKeyModifiers.includes("middle") && isStaticClick) normalized = (0, _vue_shared.extend)({}, normalized, { content: "mouseup" });
|
|
3348
|
+
if (nonKeyModifiers.includes("right") && isStaticClick) normalized = (0, _vue_shared.extend)({}, normalized, { content: "contextmenu" });
|
|
3349
|
+
return normalized;
|
|
3350
|
+
}
|
|
3351
|
+
function hasStopHandlerForStaticEvent(node, eventName) {
|
|
3352
|
+
return node.props.some((prop) => {
|
|
3353
|
+
if (prop.type !== 7 || prop.name !== "on" || !prop.arg || prop.arg.type !== 4) return false;
|
|
3354
|
+
const arg = resolveExpression(prop.arg);
|
|
3355
|
+
if (!arg.isStatic) return false;
|
|
3356
|
+
const { nonKeyModifiers } = (0, _vue_compiler_dom.resolveModifiers)(`on${arg.content}`, prop.modifiers, null, prop.loc);
|
|
3357
|
+
return nonKeyModifiers.includes("stop") && normalizeStaticEventArg(arg, nonKeyModifiers).content === eventName;
|
|
3358
|
+
});
|
|
3359
|
+
}
|
|
2875
3360
|
//#endregion
|
|
2876
3361
|
//#region packages/compiler-vapor/src/transforms/vShow.ts
|
|
2877
3362
|
const transformVShow = (dir, node, context) => {
|
|
@@ -2884,23 +3369,15 @@ const transformVShow = (dir, node, context) => {
|
|
|
2884
3369
|
context.options.onError((0, _vue_compiler_dom.createCompilerError)(36, loc));
|
|
2885
3370
|
return;
|
|
2886
3371
|
}
|
|
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
|
-
}
|
|
2893
3372
|
context.registerOperation({
|
|
2894
|
-
type:
|
|
3373
|
+
type: 14,
|
|
2895
3374
|
node,
|
|
2896
3375
|
element: context.reference(),
|
|
2897
3376
|
dir,
|
|
2898
3377
|
name: "show",
|
|
2899
|
-
builtin: true
|
|
2900
|
-
deferred: shouldDeferred
|
|
3378
|
+
builtin: true
|
|
2901
3379
|
});
|
|
2902
3380
|
};
|
|
2903
|
-
|
|
2904
3381
|
//#endregion
|
|
2905
3382
|
//#region packages/compiler-vapor/src/transforms/transformTemplateRef.ts
|
|
2906
3383
|
const transformTemplateRef = (node, context) => {
|
|
@@ -2915,7 +3392,7 @@ const transformTemplateRef = (node, context) => {
|
|
|
2915
3392
|
const id = context.reference();
|
|
2916
3393
|
const effect = !isConstantExpression(value);
|
|
2917
3394
|
context.registerEffect([value], {
|
|
2918
|
-
type:
|
|
3395
|
+
type: 9,
|
|
2919
3396
|
node,
|
|
2920
3397
|
element: id,
|
|
2921
3398
|
value,
|
|
@@ -2924,114 +3401,6 @@ const transformTemplateRef = (node, context) => {
|
|
|
2924
3401
|
});
|
|
2925
3402
|
};
|
|
2926
3403
|
};
|
|
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
|
-
|
|
3035
3404
|
//#endregion
|
|
3036
3405
|
//#region packages/compiler-vapor/src/transforms/vModel.ts
|
|
3037
3406
|
const transformVModel = (dir, node, context) => {
|
|
@@ -3087,7 +3456,7 @@ const transformVModel = (dir, node, context) => {
|
|
|
3087
3456
|
else checkDuplicatedValue();
|
|
3088
3457
|
else context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(58, dir.loc));
|
|
3089
3458
|
if (modelType) context.registerOperation({
|
|
3090
|
-
type:
|
|
3459
|
+
type: 14,
|
|
3091
3460
|
node,
|
|
3092
3461
|
element: context.reference(),
|
|
3093
3462
|
dir,
|
|
@@ -3100,12 +3469,19 @@ const transformVModel = (dir, node, context) => {
|
|
|
3100
3469
|
if (value && (0, _vue_compiler_dom.isStaticArgOf)(value.arg, "value")) context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(61, value.loc));
|
|
3101
3470
|
}
|
|
3102
3471
|
};
|
|
3103
|
-
|
|
3104
3472
|
//#endregion
|
|
3105
3473
|
//#region packages/compiler-vapor/src/transforms/transformComment.ts
|
|
3474
|
+
const ignoredComments = /* @__PURE__ */ new WeakMap();
|
|
3475
|
+
function ignoreComment(node, context) {
|
|
3476
|
+
let ignored = ignoredComments.get(context.root);
|
|
3477
|
+
if (!ignored) ignoredComments.set(context.root, ignored = /* @__PURE__ */ new WeakSet());
|
|
3478
|
+
ignored.add(node);
|
|
3479
|
+
}
|
|
3106
3480
|
const transformComment = (node, context) => {
|
|
3481
|
+
var _ignoredComments$get;
|
|
3107
3482
|
if (node.type !== 3) return;
|
|
3108
|
-
if (
|
|
3483
|
+
if ((_ignoredComments$get = ignoredComments.get(context.root)) === null || _ignoredComments$get === void 0 ? void 0 : _ignoredComments$get.has(node)) context.dynamic.flags |= 2;
|
|
3484
|
+
else if (getSiblingIf(context)) {
|
|
3109
3485
|
context.comment.push(node);
|
|
3110
3486
|
context.dynamic.flags |= 2;
|
|
3111
3487
|
} else context.template += `<!--${(0, _vue_shared.escapeHtml)(node.content)}-->`;
|
|
@@ -3122,7 +3498,6 @@ function getSiblingIf(context, reverse) {
|
|
|
3122
3498
|
}
|
|
3123
3499
|
if (sibling && sibling.type === 1 && sibling.props.some(({ type, name }) => type === 7 && ["else-if", reverse ? "if" : "else"].includes(name))) return sibling;
|
|
3124
3500
|
}
|
|
3125
|
-
|
|
3126
3501
|
//#endregion
|
|
3127
3502
|
//#region packages/compiler-vapor/src/transforms/vIf.ts
|
|
3128
3503
|
const transformVIf = createStructuralDirectiveTransform([
|
|
@@ -3137,6 +3512,7 @@ function processIf(node, dir, context) {
|
|
|
3137
3512
|
dir.exp = (0, _vue_compiler_dom.createSimpleExpression)(`true`, false, loc);
|
|
3138
3513
|
}
|
|
3139
3514
|
context.dynamic.flags |= 2;
|
|
3515
|
+
const forceMultiRoot = shouldForceMultiRoot(context);
|
|
3140
3516
|
if (dir.name === "if") {
|
|
3141
3517
|
const id = context.reference();
|
|
3142
3518
|
context.dynamic.flags |= 4;
|
|
@@ -3144,12 +3520,14 @@ function processIf(node, dir, context) {
|
|
|
3144
3520
|
return () => {
|
|
3145
3521
|
onExit();
|
|
3146
3522
|
context.dynamic.operation = {
|
|
3147
|
-
type:
|
|
3523
|
+
type: 15,
|
|
3148
3524
|
node,
|
|
3149
3525
|
id,
|
|
3526
|
+
...context.effectBoundary(),
|
|
3527
|
+
blockShape: encodeIfBlockShape(branch, forceMultiRoot),
|
|
3150
3528
|
condition: dir.exp,
|
|
3151
3529
|
positive: branch,
|
|
3152
|
-
index:
|
|
3530
|
+
index: context.root.nextIfIndex(),
|
|
3153
3531
|
once: context.inVOnce || isStaticExpression(dir.exp, context.options.bindingMetadata)
|
|
3154
3532
|
};
|
|
3155
3533
|
};
|
|
@@ -3159,16 +3537,16 @@ function processIf(node, dir, context) {
|
|
|
3159
3537
|
let lastIfNode;
|
|
3160
3538
|
if (siblings) {
|
|
3161
3539
|
let i = siblings.length;
|
|
3162
|
-
while (i--) if (siblings[i].operation && siblings[i].operation.type ===
|
|
3540
|
+
while (i--) if (siblings[i].operation && siblings[i].operation.type === 15) {
|
|
3163
3541
|
lastIfNode = siblings[i].operation;
|
|
3164
3542
|
break;
|
|
3165
3543
|
}
|
|
3166
3544
|
}
|
|
3167
|
-
if (!siblingIf || !lastIfNode || lastIfNode.type !==
|
|
3545
|
+
if (!siblingIf || !lastIfNode || lastIfNode.type !== 15) {
|
|
3168
3546
|
context.options.onError((0, _vue_compiler_dom.createCompilerError)(30, node.loc));
|
|
3169
3547
|
return;
|
|
3170
3548
|
}
|
|
3171
|
-
while (lastIfNode.negative && lastIfNode.negative.type ===
|
|
3549
|
+
while (lastIfNode.negative && lastIfNode.negative.type === 15) lastIfNode = lastIfNode.negative;
|
|
3172
3550
|
if (dir.name === "else-if" && lastIfNode.negative) context.options.onError((0, _vue_compiler_dom.createCompilerError)(30, node.loc));
|
|
3173
3551
|
if (context.root.comment.length) {
|
|
3174
3552
|
node = wrapTemplate(node, ["else-if", "else"]);
|
|
@@ -3178,15 +3556,20 @@ function processIf(node, dir, context) {
|
|
|
3178
3556
|
const [branch, onExit] = createIfBranch(node, context);
|
|
3179
3557
|
if (dir.name === "else") lastIfNode.negative = branch;
|
|
3180
3558
|
else lastIfNode.negative = {
|
|
3181
|
-
type:
|
|
3559
|
+
type: 15,
|
|
3182
3560
|
node,
|
|
3183
3561
|
id: -1,
|
|
3184
3562
|
condition: dir.exp,
|
|
3185
3563
|
positive: branch,
|
|
3186
|
-
index:
|
|
3564
|
+
index: context.root.nextIfIndex(),
|
|
3565
|
+
blockShape: 0,
|
|
3187
3566
|
once: context.inVOnce || isStaticExpression(dir.exp, context.options.bindingMetadata)
|
|
3188
3567
|
};
|
|
3189
|
-
return () =>
|
|
3568
|
+
return () => {
|
|
3569
|
+
onExit();
|
|
3570
|
+
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot);
|
|
3571
|
+
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative);
|
|
3572
|
+
};
|
|
3190
3573
|
}
|
|
3191
3574
|
}
|
|
3192
3575
|
function createIfBranch(node, context) {
|
|
@@ -3200,7 +3583,18 @@ function createIfBranch(node, context) {
|
|
|
3200
3583
|
context.reference();
|
|
3201
3584
|
return [branch, exitBlock];
|
|
3202
3585
|
}
|
|
3203
|
-
|
|
3586
|
+
function encodeIfBlockShape(positive, forceMultiRoot = false, negative) {
|
|
3587
|
+
if (forceMultiRoot) return 10;
|
|
3588
|
+
return getBlockShape(positive) | getNegativeBlockShape(negative) << 2;
|
|
3589
|
+
}
|
|
3590
|
+
function getNegativeBlockShape(negative) {
|
|
3591
|
+
if (!negative) return 0;
|
|
3592
|
+
return negative.type === 15 ? 1 : getBlockShape(negative);
|
|
3593
|
+
}
|
|
3594
|
+
function shouldForceMultiRoot(context) {
|
|
3595
|
+
const parent = context.parent && context.parent.node;
|
|
3596
|
+
return !!parent && parent.type === 1 && parent.tagType === 3 && parent.props.some((prop) => prop.type === 7 && prop.name === "for");
|
|
3597
|
+
}
|
|
3204
3598
|
//#endregion
|
|
3205
3599
|
//#region packages/compiler-vapor/src/transforms/vFor.ts
|
|
3206
3600
|
const transformVFor = createStructuralDirectiveTransform("for", processFor);
|
|
@@ -3220,7 +3614,7 @@ function processFor(node, dir, context) {
|
|
|
3220
3614
|
const typeProp = findProp$1(node, "type");
|
|
3221
3615
|
const typeProperty = typeProp && propToExpression(typeProp);
|
|
3222
3616
|
const isComponent = node.tagType === 1 || isTemplateWithSingleComponent(node);
|
|
3223
|
-
context.node = node = wrapTemplate(node, ["for"]);
|
|
3617
|
+
context.node = node = wrapTemplate(node, ["for", "key"]);
|
|
3224
3618
|
context.dynamic.flags |= 6;
|
|
3225
3619
|
const id = context.reference();
|
|
3226
3620
|
const render = newBlock(node);
|
|
@@ -3231,9 +3625,10 @@ function processFor(node, dir, context) {
|
|
|
3231
3625
|
const { parent } = context;
|
|
3232
3626
|
const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
|
|
3233
3627
|
context.dynamic.operation = {
|
|
3234
|
-
type:
|
|
3628
|
+
type: 16,
|
|
3235
3629
|
node,
|
|
3236
3630
|
id,
|
|
3631
|
+
...context.effectBoundary(),
|
|
3237
3632
|
source,
|
|
3238
3633
|
value,
|
|
3239
3634
|
key,
|
|
@@ -3252,7 +3647,6 @@ function isTemplateWithSingleComponent(node) {
|
|
|
3252
3647
|
const nonCommentChildren = node.children.filter((c) => c.type !== 3);
|
|
3253
3648
|
return nonCommentChildren.length === 1 && nonCommentChildren[0].type === 1 && nonCommentChildren[0].tagType === 1;
|
|
3254
3649
|
}
|
|
3255
|
-
|
|
3256
3650
|
//#endregion
|
|
3257
3651
|
//#region packages/compiler-vapor/src/transforms/transformSlotOutlet.ts
|
|
3258
3652
|
const transformSlotOutlet = (node, context) => {
|
|
@@ -3280,15 +3674,16 @@ const transformSlotOutlet = (node, context) => {
|
|
|
3280
3674
|
if (slotProps.length) {
|
|
3281
3675
|
const [isDynamic, props] = buildProps((0, _vue_shared.extend)({}, node, { props: slotProps }), context, true);
|
|
3282
3676
|
irProps = isDynamic ? props : [props];
|
|
3283
|
-
const runtimeDirective = context.block.operation.find((oper) => oper.type ===
|
|
3677
|
+
const runtimeDirective = context.block.operation.find((oper) => oper.type === 14 && oper.element === id);
|
|
3284
3678
|
if (runtimeDirective) context.options.onError((0, _vue_compiler_dom.createCompilerError)(36, runtimeDirective.dir.loc));
|
|
3285
3679
|
}
|
|
3286
3680
|
return () => {
|
|
3287
3681
|
exitBlock && exitBlock();
|
|
3288
3682
|
context.dynamic.operation = {
|
|
3289
|
-
type:
|
|
3683
|
+
type: 13,
|
|
3290
3684
|
node,
|
|
3291
3685
|
id,
|
|
3686
|
+
...context.effectBoundary(),
|
|
3292
3687
|
name: slotName,
|
|
3293
3688
|
props: irProps,
|
|
3294
3689
|
fallback,
|
|
@@ -3311,7 +3706,6 @@ function createFallback(node, context) {
|
|
|
3311
3706
|
context.reference();
|
|
3312
3707
|
return [fallback, exitBlock];
|
|
3313
3708
|
}
|
|
3314
|
-
|
|
3315
3709
|
//#endregion
|
|
3316
3710
|
//#region packages/compiler-vapor/src/transforms/vSlot.ts
|
|
3317
3711
|
const transformVSlot = (node, context) => {
|
|
@@ -3328,22 +3722,24 @@ const transformVSlot = (node, context) => {
|
|
|
3328
3722
|
function transformComponentSlot(node, dir, context) {
|
|
3329
3723
|
const { children } = node;
|
|
3330
3724
|
const arg = dir && dir.arg;
|
|
3725
|
+
const hasTemplateSlots = children.some(isSlotTemplateChild);
|
|
3331
3726
|
const emptyTextNodes = [];
|
|
3332
3727
|
const nonSlotTemplateChildren = children.filter((n) => {
|
|
3333
|
-
if (
|
|
3334
|
-
|
|
3728
|
+
if (isSlotTemplateChild(n)) return false;
|
|
3729
|
+
if (n.type === 3 && hasTemplateSlots) {
|
|
3730
|
+
ignoreComment(n, context);
|
|
3731
|
+
return false;
|
|
3732
|
+
}
|
|
3733
|
+
if (isNonWhitespaceContent(n)) return true;
|
|
3734
|
+
else {
|
|
3735
|
+
emptyTextNodes.push(n);
|
|
3736
|
+
return false;
|
|
3737
|
+
}
|
|
3335
3738
|
});
|
|
3336
3739
|
if (!nonSlotTemplateChildren.length) emptyTextNodes.forEach((n) => {
|
|
3337
3740
|
markNonTemplate(n, context);
|
|
3338
3741
|
});
|
|
3339
3742
|
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
|
-
}
|
|
3347
3743
|
const { slots } = context;
|
|
3348
3744
|
return () => {
|
|
3349
3745
|
onExit();
|
|
@@ -3362,14 +3758,16 @@ function transformComponentSlot(node, dir, context) {
|
|
|
3362
3758
|
}
|
|
3363
3759
|
function transformTemplateSlot(node, dir, context) {
|
|
3364
3760
|
context.dynamic.flags |= 2;
|
|
3365
|
-
const
|
|
3761
|
+
const resolvedArg = dir.arg && resolveExpression(dir.arg);
|
|
3762
|
+
let arg = resolvedArg;
|
|
3763
|
+
if (!arg) arg = (0, _vue_compiler_dom.createSimpleExpression)("default", true);
|
|
3366
3764
|
const vFor = findDir$2(node, "for");
|
|
3367
3765
|
const vIf = findDir$2(node, "if");
|
|
3368
3766
|
const vElse = findDir$2(node, /^else(-if)?$/, true);
|
|
3369
3767
|
const { slots } = context;
|
|
3370
3768
|
const [block, onExit] = createSlotBlock(node, dir, context);
|
|
3371
3769
|
if (!vFor && !vIf && !vElse) {
|
|
3372
|
-
const slotName =
|
|
3770
|
+
const slotName = resolvedArg ? resolvedArg.isStatic && resolvedArg.content : "default";
|
|
3373
3771
|
if (slotName && hasStaticSlot(slots, slotName)) context.options.onError((0, _vue_compiler_dom.createCompilerError)(38, dir.loc));
|
|
3374
3772
|
else registerSlot(slots, arg, block);
|
|
3375
3773
|
} else if (vIf) registerDynamicSlot(slots, {
|
|
@@ -3445,7 +3843,9 @@ function isNonWhitespaceContent(node) {
|
|
|
3445
3843
|
if (node.type !== 2) return true;
|
|
3446
3844
|
return !!node.content.trim();
|
|
3447
3845
|
}
|
|
3448
|
-
|
|
3846
|
+
function isSlotTemplateChild(node) {
|
|
3847
|
+
return node.type === 1 && (0, _vue_compiler_dom.isTemplateNode)(node) && !!findDir$2(node, "slot", true);
|
|
3848
|
+
}
|
|
3449
3849
|
//#endregion
|
|
3450
3850
|
//#region packages/compiler-vapor/src/transforms/transformTransition.ts
|
|
3451
3851
|
const transformTransition = (node, context) => {
|
|
@@ -3456,12 +3856,40 @@ const transformTransition = (node, context) => {
|
|
|
3456
3856
|
function hasMultipleChildren(node) {
|
|
3457
3857
|
const children = node.children = node.children.filter((c) => c.type !== 3 && !(c.type === 2 && !c.content.trim()));
|
|
3458
3858
|
const first = children[0];
|
|
3459
|
-
if (children.length === 1 && first.type === 1
|
|
3859
|
+
if (children.length === 1 && first.type === 1) {
|
|
3860
|
+
if (findDir$2(first, "for")) return true;
|
|
3861
|
+
if ((0, _vue_compiler_dom.isTemplateNode)(first)) return hasMultipleChildren(first);
|
|
3862
|
+
}
|
|
3460
3863
|
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
|
|
3864
|
+
if (children.length > 0 && children.every((c, index) => c.type === 1 && (!(0, _vue_compiler_dom.isTemplateNode)(c) || !hasMultipleChildren(c)) && !findDir$2(c, "for") && (index === 0 ? findDir$2(c, "if") : hasElse(c)))) return false;
|
|
3865
|
+
return children.length !== 1;
|
|
3463
3866
|
}
|
|
3464
|
-
|
|
3867
|
+
//#endregion
|
|
3868
|
+
//#region packages/compiler-vapor/src/transforms/transformKey.ts
|
|
3869
|
+
const transformKey = (node, context) => {
|
|
3870
|
+
if (node.type !== 1 || context.inVOnce || findDir$2(node, "for")) return;
|
|
3871
|
+
const dir = findProp$1(node, "key", true, true);
|
|
3872
|
+
if (!dir || dir.type === 6) return;
|
|
3873
|
+
let value;
|
|
3874
|
+
value = dir.exp || normalizeBindShorthand(dir.arg, context);
|
|
3875
|
+
if (isStaticExpression(value, context.options.bindingMetadata)) return;
|
|
3876
|
+
let id = context.reference();
|
|
3877
|
+
context.dynamic.flags |= 6;
|
|
3878
|
+
context.node = node = wrapTemplate(node, ["key"]);
|
|
3879
|
+
const block = newBlock(node);
|
|
3880
|
+
const exitBlock = context.enterBlock(block);
|
|
3881
|
+
return () => {
|
|
3882
|
+
exitBlock();
|
|
3883
|
+
context.dynamic.operation = {
|
|
3884
|
+
type: 17,
|
|
3885
|
+
node,
|
|
3886
|
+
id,
|
|
3887
|
+
...context.effectBoundary(),
|
|
3888
|
+
value,
|
|
3889
|
+
block
|
|
3890
|
+
};
|
|
3891
|
+
};
|
|
3892
|
+
};
|
|
3465
3893
|
//#endregion
|
|
3466
3894
|
//#region packages/compiler-vapor/src/compile.ts
|
|
3467
3895
|
function compile(source, options = {}) {
|
|
@@ -3486,6 +3914,7 @@ function getBaseTransformPreset() {
|
|
|
3486
3914
|
transformVOnce,
|
|
3487
3915
|
transformVIf,
|
|
3488
3916
|
transformVFor,
|
|
3917
|
+
transformKey,
|
|
3489
3918
|
transformSlotOutlet,
|
|
3490
3919
|
transformTemplateRef,
|
|
3491
3920
|
transformElement,
|
|
@@ -3502,7 +3931,6 @@ function getBaseTransformPreset() {
|
|
|
3502
3931
|
model: transformVModel
|
|
3503
3932
|
}];
|
|
3504
3933
|
}
|
|
3505
|
-
|
|
3506
3934
|
//#endregion
|
|
3507
3935
|
//#region packages/compiler-vapor/src/errors.ts
|
|
3508
3936
|
function createVaporCompilerError(code, loc) {
|
|
@@ -3518,7 +3946,6 @@ const VaporErrorMessages = {
|
|
|
3518
3946
|
[100]: `[placeholder]`,
|
|
3519
3947
|
[101]: ``
|
|
3520
3948
|
};
|
|
3521
|
-
|
|
3522
3949
|
//#endregion
|
|
3523
3950
|
exports.CodegenContext = CodegenContext;
|
|
3524
3951
|
exports.DELIMITERS_ARRAY = DELIMITERS_ARRAY;
|
|
@@ -3538,6 +3965,7 @@ exports.LF = LF;
|
|
|
3538
3965
|
exports.NEWLINE = NEWLINE;
|
|
3539
3966
|
exports.TEXT_NODE_PLACEHOLDER = TEXT_NODE_PLACEHOLDER;
|
|
3540
3967
|
exports.TEXT_PLACEHOLDER = TEXT_PLACEHOLDER;
|
|
3968
|
+
exports.TemplateRegistry = TemplateRegistry;
|
|
3541
3969
|
exports.VaporErrorCodes = VaporErrorCodes;
|
|
3542
3970
|
exports.VaporErrorMessages = VaporErrorMessages;
|
|
3543
3971
|
exports.analyzeExpressions = analyzeExpressions;
|
|
@@ -3552,6 +3980,7 @@ exports.genMulti = genMulti;
|
|
|
3552
3980
|
exports.generate = generate;
|
|
3553
3981
|
exports.getBaseTransformPreset = getBaseTransformPreset;
|
|
3554
3982
|
exports.getLiteralExpressionValue = getLiteralExpressionValue;
|
|
3983
|
+
exports.getParserOptions = getParserOptions;
|
|
3555
3984
|
exports.isBlockOperation = isBlockOperation;
|
|
3556
3985
|
exports.isBuiltInComponent = isBuiltInComponent;
|
|
3557
3986
|
exports.isConstantExpression = isConstantExpression;
|
|
@@ -3560,6 +3989,8 @@ exports.isStaticExpression = isStaticExpression;
|
|
|
3560
3989
|
exports.isTeleportTag = isTeleportTag;
|
|
3561
3990
|
exports.isTransitionGroupTag = isTransitionGroupTag;
|
|
3562
3991
|
exports.isTransitionTag = isTransitionTag;
|
|
3992
|
+
exports.matchKeyOnlyBindingPattern = matchKeyOnlyBindingPattern;
|
|
3993
|
+
exports.matchSelectorPattern = matchSelectorPattern;
|
|
3563
3994
|
exports.needsVaporCtx = needsVaporCtx;
|
|
3564
3995
|
exports.parse = _vue_compiler_dom.parse;
|
|
3565
3996
|
exports.parseValueDestructure = parseValueDestructure;
|
|
@@ -3568,6 +3999,7 @@ exports.transform = transform;
|
|
|
3568
3999
|
exports.transformChildren = transformChildren;
|
|
3569
4000
|
exports.transformComment = transformComment;
|
|
3570
4001
|
exports.transformElement = transformElement;
|
|
4002
|
+
exports.transformKey = transformKey;
|
|
3571
4003
|
exports.transformSlotOutlet = transformSlotOutlet;
|
|
3572
4004
|
exports.transformTemplateRef = transformTemplateRef;
|
|
3573
4005
|
exports.transformText = transformText;
|
|
@@ -3581,4 +4013,4 @@ exports.transformVOnce = transformVOnce;
|
|
|
3581
4013
|
exports.transformVShow = transformVShow;
|
|
3582
4014
|
exports.transformVSlot = transformVSlot;
|
|
3583
4015
|
exports.transformVText = transformVText;
|
|
3584
|
-
exports.wrapTemplate = wrapTemplate;
|
|
4016
|
+
exports.wrapTemplate = wrapTemplate;
|