@dcloudio/uni-cli-shared 3.0.0-4080720251210001 → 3.0.0-5000320260312001
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 +3 -0
- package/dist/constants.js +6 -1
- package/dist/deps.js +6 -1
- package/dist/dom2/index.d.ts +1 -0
- package/dist/dom2/index.js +17 -0
- package/dist/dom2/sharedData.d.ts +2 -0
- package/dist/dom2/sharedData.js +19 -0
- package/dist/easycom.js +34 -5
- package/dist/env/define.d.ts +3 -0
- package/dist/env/define.js +12 -0
- package/dist/hbx/alias.js +15 -17
- package/dist/hbx/index.d.ts +1 -1
- package/dist/hbx/index.js +4 -2
- package/dist/hbx/log.d.ts +5 -0
- package/dist/hbx/log.js +44 -1
- package/dist/i18n.js +4 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/json/app/manifest/index.d.ts +1 -0
- package/dist/json/app/manifest/index.js +3 -1
- package/dist/json/mp/pages.js +0 -5
- package/dist/json/pages.d.ts +2 -2
- package/dist/json/pages.js +4 -1
- package/dist/json/uni-x/index.d.ts +1 -1
- package/dist/json/utils.js +31 -22
- package/dist/logs/console.js +1 -1
- package/dist/logs/index.d.ts +11 -0
- package/dist/logs/index.js +34 -1
- package/dist/messages/en.d.ts +6 -3
- package/dist/messages/en.js +6 -3
- package/dist/messages/index.d.ts +11 -5
- package/dist/messages/zh_CN.d.ts +5 -2
- package/dist/messages/zh_CN.js +5 -2
- package/dist/mp/assets.d.ts +1 -0
- package/dist/mp/assets.js +27 -1
- package/dist/mp/externalClasses.d.ts +38 -2
- package/dist/mp/externalClasses.js +90 -4
- package/dist/mp/index.d.ts +4 -3
- package/dist/mp/index.js +11 -1
- package/dist/mp/plugin.d.ts +1 -0
- package/dist/mp/plugin.js +14 -1
- package/dist/mp/style.d.ts +1 -0
- package/dist/mp/style.js +8 -1
- package/dist/mp/usingComponents.d.ts +1 -0
- package/dist/mp/usingComponents.js +17 -1
- package/dist/postcss/index.d.ts +2 -0
- package/dist/postcss/index.js +3 -1
- package/dist/postcss/plugins/stylePluginExternal.d.ts +17 -0
- package/dist/postcss/plugins/stylePluginExternal.js +127 -0
- package/dist/postcss/plugins/stylePluginScoped.js +30 -0
- package/dist/preprocess/context.js +2 -0
- package/dist/preprocess/index.d.ts +9 -6
- package/dist/preprocess/index.js +33 -8
- package/dist/resolve.js +5 -1
- package/dist/uni_modules.js +20 -4
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +9 -6
- package/dist/utsUtils.d.ts +1 -0
- package/dist/utsUtils.js +2 -1
- package/dist/vite/autoImport.js +91 -6
- package/dist/vite/plugins/console.js +1 -1
- package/dist/vite/plugins/cssScoped.js +2 -1
- package/dist/vite/plugins/easycom.js +7 -0
- package/dist/vite/plugins/json.js +69 -2
- package/dist/vite/plugins/pre.js +4 -2
- package/dist/vite/plugins/sfc.js +1 -1
- package/dist/vite/plugins/stats.js +32 -0
- package/dist/vite/plugins/uts/ext-api.js +1 -1
- package/dist/vite/plugins/uts/uni_modules.js +12 -0
- package/dist/vite/plugins/uts/uvue.js +7 -2
- package/dist/vite/plugins/vitejs/plugins/asset.d.ts +1 -0
- package/dist/vite/plugins/vitejs/plugins/asset.js +19 -1
- package/dist/vite/plugins/vitejs/plugins/css.d.ts +2 -1
- package/dist/vite/plugins/vitejs/plugins/css.js +27 -10
- package/dist/vite/utils/ast.d.ts +2 -1
- package/dist/vite/utils/ast.js +5 -1
- package/dist/vue/parse.d.ts +2 -0
- package/dist/vue/parse.js +3 -1
- package/dist/vue/transforms/index.d.ts +1 -0
- package/dist/vue/transforms/index.js +1 -0
- package/dist/vue/transforms/transformLineBreak.d.ts +2 -0
- package/dist/vue/transforms/transformLineBreak.js +15 -0
- package/dist/vue/transforms/transformTag.d.ts +1 -1
- package/dist/vue/transforms/transformTag.js +5 -0
- package/dist/vue/transforms/x/transformMPBuiltInTag.js +2 -2
- package/dist/vue/utils.js +8 -1
- package/lib/@vue/compiler-core/dist/compiler-core.cjs.js +42 -23
- package/lib/@vue/compiler-core/dist/compiler-core.cjs.prod.js +42 -23
- package/lib/@vue/compiler-core/dist/compiler-core.esm-bundler.js +39 -19
- package/lib/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +4635 -1024
- package/lib/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +8762 -7849
- package/lib/dom2/app/@vitejs/plugin-vue/LICENSE +21 -0
- package/lib/dom2/app/@vitejs/plugin-vue/README.md +278 -0
- package/lib/dom2/app/@vitejs/plugin-vue/dist/index.cjs +3353 -0
- package/lib/dom2/app/@vitejs/plugin-vue/dist/index.d.cts +113 -0
- package/lib/dom2/app/@vitejs/plugin-vue/dist/index.d.mts +111 -0
- package/lib/dom2/app/@vitejs/plugin-vue/dist/index.d.ts +113 -0
- package/lib/dom2/app/@vitejs/plugin-vue/dist/index.mjs +3338 -0
- package/lib/dom2/app/@vitejs/plugin-vue/package.json +50 -0
- package/lib/dom2/app/@vue/compiler-core/LICENSE +21 -0
- package/lib/dom2/app/@vue/compiler-core/README.md +1 -0
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +5492 -0
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +5436 -0
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +1187 -0
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +4335 -0
- package/lib/dom2/app/@vue/compiler-core/index.js +7 -0
- package/lib/dom2/app/@vue/compiler-core/package.json +58 -0
- package/lib/dom2/app/@vue/compiler-dom/LICENSE +21 -0
- package/lib/dom2/app/@vue/compiler-dom/README.md +1 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +762 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +736 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.d.ts +73 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +5051 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +11 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +557 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +5234 -0
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +11 -0
- package/lib/dom2/app/@vue/compiler-dom/index.js +7 -0
- package/lib/dom2/app/@vue/compiler-dom/package.json +57 -0
- package/lib/dom2/app/@vue/compiler-sfc/LICENSE +21 -0
- package/lib/dom2/app/@vue/compiler-sfc/README.md +80 -0
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +15528 -0
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.d.ts +11595 -0
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +41525 -0
- package/lib/dom2/app/@vue/compiler-sfc/package.json +68 -0
- package/lib/dom2/app/@vue/compiler-vapor/LICENSE +21 -0
- package/lib/dom2/app/@vue/compiler-vapor/README.md +1 -0
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +3584 -0
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +22858 -0
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +22438 -0
- package/lib/dom2/app/@vue/compiler-vapor/package.json +51 -0
- package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -0
- package/lib/dom2/app/@vue/compiler-vapor-dom2/package.json +56 -0
- package/lib/dom2/app/@vue/shared/LICENSE +21 -0
- package/lib/dom2/app/@vue/shared/README.md +3 -0
- package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +773 -0
- package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +773 -0
- package/lib/dom2/app/@vue/shared/dist/shared.d.ts +412 -0
- package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +688 -0
- package/lib/dom2/app/@vue/shared/index.js +7 -0
- package/lib/dom2/app/@vue/shared/package.json +47 -0
- package/lib/preprocess/lib/preprocess.js +9 -3
- package/lib/vapor/@vue/compiler-core/dist/compiler-core.cjs.js +1 -1
- package/lib/vapor/@vue/compiler-core/dist/compiler-core.cjs.prod.js +1 -1
- package/package.json +8 -6
|
@@ -0,0 +1,3584 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vue/compiler-vapor v3.6.0-beta.5
|
|
3
|
+
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
|
+
* @license MIT
|
|
5
|
+
**/
|
|
6
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
7
|
+
let _vue_compiler_dom = require("@vue/compiler-dom");
|
|
8
|
+
let _vue_shared = require("@vue/shared");
|
|
9
|
+
let source_map_js = require("source-map-js");
|
|
10
|
+
let _babel_parser = require("@babel/parser");
|
|
11
|
+
let estree_walker = require("estree-walker");
|
|
12
|
+
|
|
13
|
+
//#region packages/compiler-vapor/src/transforms/utils.ts
|
|
14
|
+
const newDynamic = () => ({
|
|
15
|
+
flags: 1,
|
|
16
|
+
children: []
|
|
17
|
+
});
|
|
18
|
+
const newBlock = (node) => ({
|
|
19
|
+
type: 1,
|
|
20
|
+
node,
|
|
21
|
+
dynamic: newDynamic(),
|
|
22
|
+
effect: [],
|
|
23
|
+
operation: [],
|
|
24
|
+
returns: [],
|
|
25
|
+
tempId: 0
|
|
26
|
+
});
|
|
27
|
+
function wrapTemplate(node, dirs) {
|
|
28
|
+
if (node.tagType === 3) {
|
|
29
|
+
const otherStructuralDirs = [
|
|
30
|
+
"if",
|
|
31
|
+
"else-if",
|
|
32
|
+
"else",
|
|
33
|
+
"for"
|
|
34
|
+
];
|
|
35
|
+
if (!node.props.some((prop) => prop.type === 7 && otherStructuralDirs.includes(prop.name) && !dirs.includes(prop.name))) return node;
|
|
36
|
+
const reserved = [];
|
|
37
|
+
const pass = [];
|
|
38
|
+
node.props.forEach((prop) => {
|
|
39
|
+
if (prop.type === 7 && dirs.includes(prop.name)) reserved.push(prop);
|
|
40
|
+
else pass.push(prop);
|
|
41
|
+
});
|
|
42
|
+
return (0, _vue_shared.extend)({}, node, {
|
|
43
|
+
type: 1,
|
|
44
|
+
tag: "template",
|
|
45
|
+
props: reserved,
|
|
46
|
+
tagType: 3,
|
|
47
|
+
children: [(0, _vue_shared.extend)({}, node, { props: pass })]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const reserved = [];
|
|
51
|
+
const pass = [];
|
|
52
|
+
node.props.forEach((prop) => {
|
|
53
|
+
if (prop.type === 7 && dirs.includes(prop.name)) reserved.push(prop);
|
|
54
|
+
else pass.push(prop);
|
|
55
|
+
});
|
|
56
|
+
return (0, _vue_shared.extend)({}, node, {
|
|
57
|
+
type: 1,
|
|
58
|
+
tag: "template",
|
|
59
|
+
props: reserved,
|
|
60
|
+
tagType: 3,
|
|
61
|
+
children: [(0, _vue_shared.extend)({}, node, { props: pass })]
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const EMPTY_EXPRESSION = (0, _vue_compiler_dom.createSimpleExpression)("", true);
|
|
65
|
+
const TEXT_PLACEHOLDER = "__vapor_dom2_text_placeholder__";
|
|
66
|
+
const TEXT_NODE_PLACEHOLDER = "__vapor_dom2_text_node_placeholder__";
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region packages/compiler-vapor/src/utils.ts
|
|
70
|
+
const findProp$1 = _vue_compiler_dom.findProp;
|
|
71
|
+
/** find directive */
|
|
72
|
+
const findDir$2 = _vue_compiler_dom.findDir;
|
|
73
|
+
function propToExpression(prop) {
|
|
74
|
+
return prop.type === 6 ? prop.value ? (0, _vue_compiler_dom.createSimpleExpression)(prop.value.content, true, prop.value.loc) : EMPTY_EXPRESSION : prop.exp;
|
|
75
|
+
}
|
|
76
|
+
function isConstantExpression(exp) {
|
|
77
|
+
return (0, _vue_compiler_dom.isLiteralWhitelisted)(exp.content) || (0, _vue_shared.isGloballyAllowed)(exp.content) || getLiteralExpressionValue(exp) !== null;
|
|
78
|
+
}
|
|
79
|
+
function isStaticExpression(node, bindings) {
|
|
80
|
+
if (node.ast) return (0, _vue_compiler_dom.isConstantNode)(node.ast, bindings);
|
|
81
|
+
else if (node.ast === null) {
|
|
82
|
+
if (!node.isStatic && (node.content === "true" || node.content === "false")) return true;
|
|
83
|
+
return bindings[node.content] === "literal-const";
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
function resolveExpression(exp, isComponent) {
|
|
88
|
+
if (!exp.isStatic) {
|
|
89
|
+
const value = getLiteralExpressionValue(exp, isComponent);
|
|
90
|
+
if (value !== null) return (0, _vue_compiler_dom.createSimpleExpression)(value, true, exp.loc);
|
|
91
|
+
}
|
|
92
|
+
return exp;
|
|
93
|
+
}
|
|
94
|
+
function getLiteralExpressionValue(exp, excludeNumber) {
|
|
95
|
+
if (exp.ast) {
|
|
96
|
+
if (exp.ast.type === "StringLiteral") return exp.ast.value;
|
|
97
|
+
else if (!excludeNumber && (exp.ast.type === "NumericLiteral" || exp.ast.type === "BigIntLiteral")) return String(exp.ast.value);
|
|
98
|
+
else if (exp.ast.type === "TemplateLiteral") {
|
|
99
|
+
let result = "";
|
|
100
|
+
for (const [index, quasi] of exp.ast.quasis.entries()) {
|
|
101
|
+
result += quasi.value.cooked;
|
|
102
|
+
if (exp.ast.expressions[index]) {
|
|
103
|
+
let expressionValue = getLiteralExpressionValue({ ast: exp.ast.expressions[index] });
|
|
104
|
+
if (expressionValue == null) return null;
|
|
105
|
+
else result += expressionValue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return exp.isStatic ? exp.content : null;
|
|
112
|
+
}
|
|
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
|
+
function isTransitionTag(tag) {
|
|
121
|
+
tag = tag.toLowerCase();
|
|
122
|
+
return tag === "transition" || tag === "vaportransition";
|
|
123
|
+
}
|
|
124
|
+
function isTransitionGroupTag(tag) {
|
|
125
|
+
tag = tag.toLowerCase().replace(/-/g, "");
|
|
126
|
+
return tag === "transitiongroup" || tag === "vaportransitiongroup";
|
|
127
|
+
}
|
|
128
|
+
function isKeepAliveTag(tag) {
|
|
129
|
+
tag = tag.toLowerCase();
|
|
130
|
+
return tag === "keepalive" || tag === "vaporkeepalive";
|
|
131
|
+
}
|
|
132
|
+
function isTeleportTag(tag) {
|
|
133
|
+
tag = tag.toLowerCase();
|
|
134
|
+
return tag === "teleport" || tag === "vaporteleport";
|
|
135
|
+
}
|
|
136
|
+
function isBuiltInComponent(tag) {
|
|
137
|
+
if (isTeleportTag(tag)) return "VaporTeleport";
|
|
138
|
+
else if (isKeepAliveTag(tag)) return "VaporKeepAlive";
|
|
139
|
+
else if (isTransitionTag(tag)) return "VaporTransition";
|
|
140
|
+
else if (isTransitionGroupTag(tag)) return "VaporTransitionGroup";
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
//#region packages/compiler-vapor/src/transform.ts
|
|
145
|
+
const generatedVarRE = /^[nxr](\d+)$/;
|
|
146
|
+
var TransformContext = class TransformContext {
|
|
147
|
+
constructor(ir, node, options = {}) {
|
|
148
|
+
this.ir = ir;
|
|
149
|
+
this.node = node;
|
|
150
|
+
this.selfName = null;
|
|
151
|
+
this.parent = null;
|
|
152
|
+
this.effectiveParent = null;
|
|
153
|
+
this.index = 0;
|
|
154
|
+
this.block = this.ir.block;
|
|
155
|
+
this.template = "";
|
|
156
|
+
this.childrenTemplate = [];
|
|
157
|
+
this.dynamic = this.ir.block.dynamic;
|
|
158
|
+
this.imports = [];
|
|
159
|
+
this.inVOnce = false;
|
|
160
|
+
this.inVFor = 0;
|
|
161
|
+
this.comment = [];
|
|
162
|
+
this.component = this.ir.component;
|
|
163
|
+
this.directive = this.ir.directive;
|
|
164
|
+
this.slots = [];
|
|
165
|
+
this.isLastEffectiveChild = true;
|
|
166
|
+
this.isOnRightmostPath = true;
|
|
167
|
+
this.hasInlineAncestorNeedingClose = false;
|
|
168
|
+
this.globalId = 0;
|
|
169
|
+
this.nextIdMap = null;
|
|
170
|
+
this.ifIndex = 0;
|
|
171
|
+
this.increaseId = () => {
|
|
172
|
+
const id = getNextId(this.nextIdMap, this.globalId);
|
|
173
|
+
this.globalId = getNextId(this.nextIdMap, id + 1);
|
|
174
|
+
return id;
|
|
175
|
+
};
|
|
176
|
+
this.options = (0, _vue_shared.extend)({}, defaultOptions, options);
|
|
177
|
+
this.root = this;
|
|
178
|
+
if (options.filename) this.selfName = (0, _vue_compiler_dom.getSelfName)(options.filename);
|
|
179
|
+
this.initNextIdMap();
|
|
180
|
+
}
|
|
181
|
+
enterBlock(ir, isVFor = false) {
|
|
182
|
+
const { block, template, dynamic, childrenTemplate, slots } = this;
|
|
183
|
+
this.block = ir;
|
|
184
|
+
this.dynamic = ir.dynamic;
|
|
185
|
+
this.template = "";
|
|
186
|
+
this.childrenTemplate = [];
|
|
187
|
+
this.slots = [];
|
|
188
|
+
isVFor && this.inVFor++;
|
|
189
|
+
return () => {
|
|
190
|
+
this.registerTemplate();
|
|
191
|
+
this.block = block;
|
|
192
|
+
this.template = template;
|
|
193
|
+
this.dynamic = dynamic;
|
|
194
|
+
this.childrenTemplate = childrenTemplate;
|
|
195
|
+
this.slots = slots;
|
|
196
|
+
isVFor && this.inVFor--;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
initNextIdMap() {
|
|
200
|
+
const binding = this.root.options.bindingMetadata;
|
|
201
|
+
if (!binding) return;
|
|
202
|
+
const keys = Object.keys(binding);
|
|
203
|
+
if (keys.length === 0) return;
|
|
204
|
+
const numbers = /* @__PURE__ */ new Set();
|
|
205
|
+
for (const name of keys) {
|
|
206
|
+
const m = generatedVarRE.exec(name);
|
|
207
|
+
if (m) numbers.add(Number(m[1]));
|
|
208
|
+
}
|
|
209
|
+
if (numbers.size === 0) return;
|
|
210
|
+
this.globalId = getNextId(this.nextIdMap = buildNextIdMap(numbers), 0);
|
|
211
|
+
}
|
|
212
|
+
reference() {
|
|
213
|
+
if (this.dynamic.id !== void 0) return this.dynamic.id;
|
|
214
|
+
this.dynamic.flags |= 1;
|
|
215
|
+
return this.dynamic.id = this.increaseId();
|
|
216
|
+
}
|
|
217
|
+
nextIfIndex() {
|
|
218
|
+
return this.ifIndex++;
|
|
219
|
+
}
|
|
220
|
+
pushTemplate(content) {
|
|
221
|
+
const existingIndex = this.ir.templateIndexMap.get(content);
|
|
222
|
+
if (existingIndex !== void 0) return existingIndex;
|
|
223
|
+
const newIndex = this.ir.template.size;
|
|
224
|
+
this.ir.template.set(content, this.node.ns);
|
|
225
|
+
this.ir.templateIndexMap.set(content, newIndex);
|
|
226
|
+
return newIndex;
|
|
227
|
+
}
|
|
228
|
+
registerTemplate() {
|
|
229
|
+
if (!this.template) return -1;
|
|
230
|
+
const id = this.pushTemplate(this.template);
|
|
231
|
+
return this.dynamic.template = id;
|
|
232
|
+
}
|
|
233
|
+
registerEffect(expressions, operation, getIndex = () => this.block.effect.length, getOperationIndex) {
|
|
234
|
+
const operations = [operation].flat();
|
|
235
|
+
expressions = expressions.filter((exp) => !isConstantExpression(exp));
|
|
236
|
+
if (this.inVOnce || expressions.length === 0 || expressions.every((e) => isStaticExpression(e, this.root.options.bindingMetadata))) {
|
|
237
|
+
if (getOperationIndex) {
|
|
238
|
+
this.block.operation.splice(getOperationIndex(), 0, ...operations);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
return this.registerOperation(...operations);
|
|
242
|
+
}
|
|
243
|
+
this.block.effect.splice(getIndex(), 0, {
|
|
244
|
+
expressions,
|
|
245
|
+
operations
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
registerOperation(...node) {
|
|
249
|
+
this.block.operation.push(...node);
|
|
250
|
+
}
|
|
251
|
+
create(node, index) {
|
|
252
|
+
let effectiveParent = this;
|
|
253
|
+
while (effectiveParent && effectiveParent.node.type === 1 && effectiveParent.node.tagType === 3) effectiveParent = effectiveParent.parent;
|
|
254
|
+
const isLastEffectiveChild = this.isEffectivelyLastChild(index);
|
|
255
|
+
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
|
+
return Object.assign(Object.create(TransformContext.prototype), this, {
|
|
262
|
+
node,
|
|
263
|
+
parent: this,
|
|
264
|
+
index,
|
|
265
|
+
template: "",
|
|
266
|
+
childrenTemplate: [],
|
|
267
|
+
dynamic: newDynamic(),
|
|
268
|
+
effectiveParent,
|
|
269
|
+
isLastEffectiveChild,
|
|
270
|
+
isOnRightmostPath,
|
|
271
|
+
hasInlineAncestorNeedingClose
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
isEffectivelyLastChild(index) {
|
|
275
|
+
const children = this.node.children;
|
|
276
|
+
if (!children) return true;
|
|
277
|
+
return children.every((c, i) => i <= index || c.type === 1 && c.tagType === 1);
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
const defaultOptions = {
|
|
281
|
+
filename: "",
|
|
282
|
+
prefixIdentifiers: true,
|
|
283
|
+
hoistStatic: false,
|
|
284
|
+
hmr: false,
|
|
285
|
+
cacheHandlers: false,
|
|
286
|
+
nodeTransforms: [],
|
|
287
|
+
directiveTransforms: {},
|
|
288
|
+
transformHoist: null,
|
|
289
|
+
isBuiltInComponent: _vue_shared.NOOP,
|
|
290
|
+
isCustomElement: _vue_shared.NOOP,
|
|
291
|
+
isUserComponent(element) {
|
|
292
|
+
return element.tagType === 1;
|
|
293
|
+
},
|
|
294
|
+
expressionPlugins: [],
|
|
295
|
+
scopeId: null,
|
|
296
|
+
slotted: true,
|
|
297
|
+
ssr: false,
|
|
298
|
+
inSSR: false,
|
|
299
|
+
ssrCssVars: ``,
|
|
300
|
+
bindingMetadata: _vue_shared.EMPTY_OBJ,
|
|
301
|
+
inline: false,
|
|
302
|
+
isTS: false,
|
|
303
|
+
onError: _vue_compiler_dom.defaultOnError,
|
|
304
|
+
onWarn: _vue_compiler_dom.defaultOnWarn
|
|
305
|
+
};
|
|
306
|
+
function transform(node, options = {}) {
|
|
307
|
+
const ir = {
|
|
308
|
+
type: 0,
|
|
309
|
+
node,
|
|
310
|
+
source: node.source,
|
|
311
|
+
template: /* @__PURE__ */ new Map(),
|
|
312
|
+
templateIndexMap: /* @__PURE__ */ new Map(),
|
|
313
|
+
rootTemplateIndexes: /* @__PURE__ */ new Set(),
|
|
314
|
+
component: /* @__PURE__ */ new Set(),
|
|
315
|
+
directive: /* @__PURE__ */ new Set(),
|
|
316
|
+
block: newBlock(node),
|
|
317
|
+
hasTemplateRef: false,
|
|
318
|
+
hasDeferredVShow: false
|
|
319
|
+
};
|
|
320
|
+
const context = new TransformContext(ir, node, options);
|
|
321
|
+
transformNode(context);
|
|
322
|
+
ir.node.imports = context.imports;
|
|
323
|
+
return ir;
|
|
324
|
+
}
|
|
325
|
+
function transformNode(context) {
|
|
326
|
+
let { node } = context;
|
|
327
|
+
const { nodeTransforms } = context.options;
|
|
328
|
+
const exitFns = [];
|
|
329
|
+
for (const nodeTransform of nodeTransforms) {
|
|
330
|
+
const onExit = nodeTransform(node, context);
|
|
331
|
+
if (onExit) if ((0, _vue_shared.isArray)(onExit)) exitFns.push(...onExit);
|
|
332
|
+
else exitFns.push(onExit);
|
|
333
|
+
if (!context.node) return;
|
|
334
|
+
else node = context.node;
|
|
335
|
+
}
|
|
336
|
+
context.node = node;
|
|
337
|
+
let i = exitFns.length;
|
|
338
|
+
while (i--) exitFns[i]();
|
|
339
|
+
if (context.node.type === 0) context.registerTemplate();
|
|
340
|
+
}
|
|
341
|
+
function createStructuralDirectiveTransform(name, fn) {
|
|
342
|
+
const matches = (n) => (0, _vue_shared.isString)(name) ? n === name : name.includes(n);
|
|
343
|
+
return (node, context) => {
|
|
344
|
+
if (node.type === 1) {
|
|
345
|
+
const { props } = node;
|
|
346
|
+
if (node.tagType === 3 && props.some(_vue_compiler_dom.isVSlot)) return;
|
|
347
|
+
const exitFns = [];
|
|
348
|
+
for (const prop of props) if (prop.type === 7 && matches(prop.name)) {
|
|
349
|
+
const onExit = fn(node, prop, context);
|
|
350
|
+
if (onExit) exitFns.push(onExit);
|
|
351
|
+
}
|
|
352
|
+
return exitFns;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Build a "next-id" map from an occupied number set.
|
|
358
|
+
* For each consecutive range [start..end], map every v in the range to end + 1.
|
|
359
|
+
* Example: input [0, 1, 2, 4] => { 0: 3, 1: 3, 2: 3, 4: 5 }.
|
|
360
|
+
*/
|
|
361
|
+
function buildNextIdMap(nums) {
|
|
362
|
+
const map = /* @__PURE__ */ new Map();
|
|
363
|
+
const arr = Array.from(new Set(nums)).sort((a, b) => a - b);
|
|
364
|
+
if (arr.length === 0) return map;
|
|
365
|
+
for (let i = 0; i < arr.length; i++) {
|
|
366
|
+
let start = arr[i];
|
|
367
|
+
let end = start;
|
|
368
|
+
while (i + 1 < arr.length && arr[i + 1] === end + 1) {
|
|
369
|
+
i++;
|
|
370
|
+
end = arr[i];
|
|
371
|
+
}
|
|
372
|
+
for (let v = start; v <= end; v++) map.set(v, end + 1);
|
|
373
|
+
}
|
|
374
|
+
return map;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Return the available id for n using a map built by buildNextIdMap:
|
|
378
|
+
* - If n is not occupied, return n.
|
|
379
|
+
* - If n is occupied, return the mapped value
|
|
380
|
+
*/
|
|
381
|
+
function getNextId(map, n) {
|
|
382
|
+
if (map && map.has(n)) return map.get(n);
|
|
383
|
+
return n;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
//#endregion
|
|
387
|
+
//#region packages/compiler-vapor/src/generators/utils.ts
|
|
388
|
+
const IMPORT_EXP_START = "__IMPORT_EXP_START__";
|
|
389
|
+
const IMPORT_EXP_END = "__IMPORT_EXP_END__";
|
|
390
|
+
const IMPORT_EXPR_RE = new RegExp(`${IMPORT_EXP_START}(.*?)${IMPORT_EXP_END}`, "g");
|
|
391
|
+
const NEWLINE = Symbol(`newline`);
|
|
392
|
+
/** increase offset but don't push actual code */
|
|
393
|
+
const LF = Symbol(`line feed`);
|
|
394
|
+
const INDENT_START = Symbol(`indent start`);
|
|
395
|
+
const INDENT_END = Symbol(`indent end`);
|
|
396
|
+
function buildCodeFragment(...frag) {
|
|
397
|
+
return [
|
|
398
|
+
frag,
|
|
399
|
+
frag.push.bind(frag),
|
|
400
|
+
frag.unshift.bind(frag)
|
|
401
|
+
];
|
|
402
|
+
}
|
|
403
|
+
function genMulti([left, right, seg, placeholder], ...frags) {
|
|
404
|
+
if (placeholder) {
|
|
405
|
+
while (frags.length > 0 && !frags[frags.length - 1]) frags.pop();
|
|
406
|
+
frags = frags.map((frag) => frag || placeholder);
|
|
407
|
+
} else frags = frags.filter(Boolean);
|
|
408
|
+
const frag = [];
|
|
409
|
+
push(left);
|
|
410
|
+
for (let [i, fn] of frags.entries()) {
|
|
411
|
+
push(fn);
|
|
412
|
+
if (i < frags.length - 1) push(seg);
|
|
413
|
+
}
|
|
414
|
+
push(right);
|
|
415
|
+
return frag;
|
|
416
|
+
function push(fn) {
|
|
417
|
+
if (!(0, _vue_shared.isArray)(fn)) fn = [fn];
|
|
418
|
+
frag.push(...fn);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
const DELIMITERS_ARRAY = [
|
|
422
|
+
"[",
|
|
423
|
+
"]",
|
|
424
|
+
", "
|
|
425
|
+
];
|
|
426
|
+
const DELIMITERS_ARRAY_NEWLINE = [
|
|
427
|
+
[
|
|
428
|
+
"[",
|
|
429
|
+
INDENT_START,
|
|
430
|
+
NEWLINE
|
|
431
|
+
],
|
|
432
|
+
[
|
|
433
|
+
INDENT_END,
|
|
434
|
+
NEWLINE,
|
|
435
|
+
"]"
|
|
436
|
+
],
|
|
437
|
+
[",", NEWLINE]
|
|
438
|
+
];
|
|
439
|
+
const DELIMITERS_OBJECT = [
|
|
440
|
+
"{ ",
|
|
441
|
+
" }",
|
|
442
|
+
", "
|
|
443
|
+
];
|
|
444
|
+
const DELIMITERS_OBJECT_NEWLINE = [
|
|
445
|
+
[
|
|
446
|
+
"{",
|
|
447
|
+
INDENT_START,
|
|
448
|
+
NEWLINE
|
|
449
|
+
],
|
|
450
|
+
[
|
|
451
|
+
INDENT_END,
|
|
452
|
+
NEWLINE,
|
|
453
|
+
"}"
|
|
454
|
+
],
|
|
455
|
+
[",", NEWLINE]
|
|
456
|
+
];
|
|
457
|
+
function genCall(name, ...frags) {
|
|
458
|
+
const hasPlaceholder = (0, _vue_shared.isArray)(name);
|
|
459
|
+
return [hasPlaceholder ? name[0] : name, ...genMulti([
|
|
460
|
+
"(",
|
|
461
|
+
")",
|
|
462
|
+
", ",
|
|
463
|
+
hasPlaceholder ? name[1] : "null"
|
|
464
|
+
], ...frags)];
|
|
465
|
+
}
|
|
466
|
+
function codeFragmentToString(code, context) {
|
|
467
|
+
const { options: { sourceMap } } = context;
|
|
468
|
+
const filename = context.options.relativeFilename || context.options.filename;
|
|
469
|
+
let map;
|
|
470
|
+
if (sourceMap) {
|
|
471
|
+
map = new source_map_js.SourceMapGenerator();
|
|
472
|
+
map.setSourceContent(filename, context.ir.source);
|
|
473
|
+
map._sources.add(filename);
|
|
474
|
+
}
|
|
475
|
+
let codegen = "";
|
|
476
|
+
const pos = {
|
|
477
|
+
line: 1,
|
|
478
|
+
column: 1,
|
|
479
|
+
offset: 0
|
|
480
|
+
};
|
|
481
|
+
let indentLevel = 0;
|
|
482
|
+
for (let frag of code) {
|
|
483
|
+
if (!frag) continue;
|
|
484
|
+
if (frag === NEWLINE) frag = [`\n${` `.repeat(indentLevel)}`, 0];
|
|
485
|
+
else if (frag === INDENT_START) {
|
|
486
|
+
indentLevel++;
|
|
487
|
+
continue;
|
|
488
|
+
} else if (frag === INDENT_END) {
|
|
489
|
+
indentLevel--;
|
|
490
|
+
continue;
|
|
491
|
+
} else if (frag === LF) {
|
|
492
|
+
pos.line++;
|
|
493
|
+
pos.column = 0;
|
|
494
|
+
pos.offset++;
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
if ((0, _vue_shared.isString)(frag)) frag = [frag];
|
|
498
|
+
let [code, newlineIndex = -2, loc, name] = frag;
|
|
499
|
+
codegen += code;
|
|
500
|
+
if (map) {
|
|
501
|
+
if (loc) addMapping(loc.start, name);
|
|
502
|
+
if (newlineIndex === -3) (0, _vue_compiler_dom.advancePositionWithMutation)(pos, code);
|
|
503
|
+
else {
|
|
504
|
+
pos.offset += code.length;
|
|
505
|
+
if (newlineIndex === -2) pos.column += code.length;
|
|
506
|
+
else {
|
|
507
|
+
if (newlineIndex === -1) newlineIndex = code.length - 1;
|
|
508
|
+
pos.line++;
|
|
509
|
+
pos.column = code.length - newlineIndex;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
if (loc && loc !== _vue_compiler_dom.locStub) addMapping(loc.end);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return [codegen, map];
|
|
516
|
+
function addMapping(loc, name = null) {
|
|
517
|
+
const { _names, _mappings } = map;
|
|
518
|
+
if (name !== null && !_names.has(name)) _names.add(name);
|
|
519
|
+
_mappings.add({
|
|
520
|
+
originalLine: loc.line,
|
|
521
|
+
originalColumn: loc.column - 1,
|
|
522
|
+
generatedLine: pos.line,
|
|
523
|
+
generatedColumn: pos.column - 1,
|
|
524
|
+
source: filename,
|
|
525
|
+
name
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region packages/compiler-vapor/src/ir/component.ts
|
|
532
|
+
const IRDynamicPropsKind = {
|
|
533
|
+
"EXPRESSION": 0,
|
|
534
|
+
"0": "EXPRESSION",
|
|
535
|
+
"ATTRIBUTE": 1,
|
|
536
|
+
"1": "ATTRIBUTE"
|
|
537
|
+
};
|
|
538
|
+
const IRSlotType = {
|
|
539
|
+
"STATIC": 0,
|
|
540
|
+
"0": "STATIC",
|
|
541
|
+
"DYNAMIC": 1,
|
|
542
|
+
"1": "DYNAMIC",
|
|
543
|
+
"LOOP": 2,
|
|
544
|
+
"2": "LOOP",
|
|
545
|
+
"CONDITIONAL": 3,
|
|
546
|
+
"3": "CONDITIONAL",
|
|
547
|
+
"EXPRESSION": 4,
|
|
548
|
+
"4": "EXPRESSION"
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region packages/compiler-vapor/src/ir/index.ts
|
|
553
|
+
const IRNodeTypes = {
|
|
554
|
+
"ROOT": 0,
|
|
555
|
+
"0": "ROOT",
|
|
556
|
+
"BLOCK": 1,
|
|
557
|
+
"1": "BLOCK",
|
|
558
|
+
"SET_PROP": 2,
|
|
559
|
+
"2": "SET_PROP",
|
|
560
|
+
"SET_DYNAMIC_PROPS": 3,
|
|
561
|
+
"3": "SET_DYNAMIC_PROPS",
|
|
562
|
+
"SET_TEXT": 4,
|
|
563
|
+
"4": "SET_TEXT",
|
|
564
|
+
"SET_EVENT": 5,
|
|
565
|
+
"5": "SET_EVENT",
|
|
566
|
+
"SET_DYNAMIC_EVENTS": 6,
|
|
567
|
+
"6": "SET_DYNAMIC_EVENTS",
|
|
568
|
+
"SET_HTML": 7,
|
|
569
|
+
"7": "SET_HTML",
|
|
570
|
+
"SET_TEMPLATE_REF": 8,
|
|
571
|
+
"8": "SET_TEMPLATE_REF",
|
|
572
|
+
"INSERT_NODE": 9,
|
|
573
|
+
"9": "INSERT_NODE",
|
|
574
|
+
"PREPEND_NODE": 10,
|
|
575
|
+
"10": "PREPEND_NODE",
|
|
576
|
+
"CREATE_COMPONENT_NODE": 11,
|
|
577
|
+
"11": "CREATE_COMPONENT_NODE",
|
|
578
|
+
"SLOT_OUTLET_NODE": 12,
|
|
579
|
+
"12": "SLOT_OUTLET_NODE",
|
|
580
|
+
"DIRECTIVE": 13,
|
|
581
|
+
"13": "DIRECTIVE",
|
|
582
|
+
"IF": 14,
|
|
583
|
+
"14": "IF",
|
|
584
|
+
"FOR": 15,
|
|
585
|
+
"15": "FOR",
|
|
586
|
+
"GET_TEXT_CHILD": 16,
|
|
587
|
+
"16": "GET_TEXT_CHILD",
|
|
588
|
+
"GET_INSERTION_PARENT": 17,
|
|
589
|
+
"17": "GET_INSERTION_PARENT",
|
|
590
|
+
"SET_CHANGE_PROP": 18,
|
|
591
|
+
"18": "SET_CHANGE_PROP"
|
|
592
|
+
};
|
|
593
|
+
const DynamicFlag = {
|
|
594
|
+
"NONE": 0,
|
|
595
|
+
"0": "NONE",
|
|
596
|
+
"REFERENCED": 1,
|
|
597
|
+
"1": "REFERENCED",
|
|
598
|
+
"NON_TEMPLATE": 2,
|
|
599
|
+
"2": "NON_TEMPLATE",
|
|
600
|
+
"INSERT": 4,
|
|
601
|
+
"4": "INSERT"
|
|
602
|
+
};
|
|
603
|
+
function isBlockOperation(op) {
|
|
604
|
+
const type = op.type;
|
|
605
|
+
return type === 11 || type === 12 || type === 14 || type === 15;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
//#endregion
|
|
609
|
+
//#region packages/compiler-vapor/src/generators/dom.ts
|
|
610
|
+
function genInsertNode({ parent, elements, anchor }, { helper }) {
|
|
611
|
+
let element = elements.map((el) => `n${el}`).join(", ");
|
|
612
|
+
if (elements.length > 1) element = `[${element}]`;
|
|
613
|
+
return [NEWLINE, ...genCall(helper("insert"), element, `n${parent}`, anchor === void 0 ? void 0 : `n${anchor}`)];
|
|
614
|
+
}
|
|
615
|
+
function genPrependNode(oper, { helper }) {
|
|
616
|
+
return [NEWLINE, ...genCall(helper("prepend"), `n${oper.parent}`, ...oper.elements.map((el) => `n${el}`))];
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
//#endregion
|
|
620
|
+
//#region packages/compiler-vapor/src/generators/expression.ts
|
|
621
|
+
function genExpression(node, context, assignment) {
|
|
622
|
+
const { content, ast, isStatic, loc } = node;
|
|
623
|
+
if (isStatic) return [[
|
|
624
|
+
JSON.stringify(content),
|
|
625
|
+
-2,
|
|
626
|
+
loc
|
|
627
|
+
]];
|
|
628
|
+
if (!node.content.trim() || ast === false || isConstantExpression(node)) return [[
|
|
629
|
+
content,
|
|
630
|
+
-2,
|
|
631
|
+
loc
|
|
632
|
+
], assignment && ` = ${assignment}`];
|
|
633
|
+
if (ast === null) return genIdentifier(content, context, loc, assignment);
|
|
634
|
+
const ids = [];
|
|
635
|
+
const parentStackMap = /* @__PURE__ */ new Map();
|
|
636
|
+
const parentStack = [];
|
|
637
|
+
(0, _vue_compiler_dom.walkIdentifiers)(ast, (id) => {
|
|
638
|
+
ids.push(id);
|
|
639
|
+
parentStackMap.set(id, parentStack.slice());
|
|
640
|
+
}, false, parentStack);
|
|
641
|
+
let hasMemberExpression = false;
|
|
642
|
+
if (ids.length) {
|
|
643
|
+
const [frag, push] = buildCodeFragment();
|
|
644
|
+
ids.sort((a, b) => a.start - b.start).forEach((id, i) => {
|
|
645
|
+
const start = id.start - 1;
|
|
646
|
+
const end = id.end - 1;
|
|
647
|
+
const last = ids[i - 1];
|
|
648
|
+
const leadingText = content.slice(last ? last.end - 1 : 0, start);
|
|
649
|
+
if (leadingText.length) push([leadingText, -3]);
|
|
650
|
+
const source = content.slice(start, end);
|
|
651
|
+
const parentStack = parentStackMap.get(id);
|
|
652
|
+
const parent = parentStack[parentStack.length - 1];
|
|
653
|
+
hasMemberExpression || (hasMemberExpression = parent && (parent.type === "MemberExpression" || parent.type === "OptionalMemberExpression"));
|
|
654
|
+
push(...genIdentifier(source, context, {
|
|
655
|
+
start: (0, _vue_compiler_dom.advancePositionWithClone)(node.loc.start, source, start),
|
|
656
|
+
end: (0, _vue_compiler_dom.advancePositionWithClone)(node.loc.start, source, end),
|
|
657
|
+
source
|
|
658
|
+
}, hasMemberExpression ? void 0 : assignment, id, parent, parentStack));
|
|
659
|
+
if (i === ids.length - 1 && end < content.length) push([content.slice(end), -3]);
|
|
660
|
+
});
|
|
661
|
+
if (assignment && hasMemberExpression) push(` = ${assignment}`);
|
|
662
|
+
return frag;
|
|
663
|
+
} else return [[
|
|
664
|
+
content,
|
|
665
|
+
-3,
|
|
666
|
+
loc
|
|
667
|
+
]];
|
|
668
|
+
}
|
|
669
|
+
function genIdentifier(raw, context, loc, assignment, id, parent, parentStack) {
|
|
670
|
+
const { options, helper, identifiers } = context;
|
|
671
|
+
const { inline, bindingMetadata } = options;
|
|
672
|
+
let name = raw;
|
|
673
|
+
const idMap = identifiers[raw];
|
|
674
|
+
if (idMap && idMap.length) {
|
|
675
|
+
const replacement = idMap[0];
|
|
676
|
+
if ((0, _vue_shared.isString)(replacement)) if (parent && parent.type === "ObjectProperty" && parent.shorthand) return [[
|
|
677
|
+
`${name}: ${replacement}`,
|
|
678
|
+
-2,
|
|
679
|
+
loc
|
|
680
|
+
]];
|
|
681
|
+
else return [[
|
|
682
|
+
replacement,
|
|
683
|
+
-2,
|
|
684
|
+
loc
|
|
685
|
+
]];
|
|
686
|
+
else return genExpression(replacement, context, assignment);
|
|
687
|
+
}
|
|
688
|
+
let prefix;
|
|
689
|
+
if ((0, _vue_compiler_dom.isStaticProperty)(parent) && parent.shorthand) prefix = `${raw}: `;
|
|
690
|
+
const type = bindingMetadata && bindingMetadata[raw];
|
|
691
|
+
if (inline) switch (type) {
|
|
692
|
+
case "setup-let":
|
|
693
|
+
name = raw = assignment ? `_isRef(${raw}) ? (${raw}.value = ${assignment}) : (${raw} = ${assignment})` : unref();
|
|
694
|
+
break;
|
|
695
|
+
case "setup-ref":
|
|
696
|
+
name = raw = withAssignment(`${raw}.value`);
|
|
697
|
+
break;
|
|
698
|
+
case "setup-maybe-ref":
|
|
699
|
+
const isDestructureAssignment = parent && (0, _vue_compiler_dom.isInDestructureAssignment)(parent, parentStack || []);
|
|
700
|
+
const isAssignmentLVal = parent && parent.type === "AssignmentExpression" && parent.left === id;
|
|
701
|
+
const isUpdateArg = parent && parent.type === "UpdateExpression" && parent.argument === id;
|
|
702
|
+
raw = isAssignmentLVal || isUpdateArg || isDestructureAssignment ? name = `${raw}.value` : assignment ? `${helper("isRef")}(${raw}) ? (${raw}.value = ${assignment}) : null` : unref();
|
|
703
|
+
break;
|
|
704
|
+
case "props":
|
|
705
|
+
raw = (0, _vue_shared.genPropsAccessExp)(raw);
|
|
706
|
+
break;
|
|
707
|
+
case "props-aliased":
|
|
708
|
+
raw = (0, _vue_shared.genPropsAccessExp)(bindingMetadata.__propsAliases[raw]);
|
|
709
|
+
break;
|
|
710
|
+
default: raw = withAssignment(raw);
|
|
711
|
+
}
|
|
712
|
+
else {
|
|
713
|
+
if (canPrefix(raw)) if (type === "props-aliased") raw = `$props['${bindingMetadata.__propsAliases[raw]}']`;
|
|
714
|
+
else raw = `${type === "props" ? "$props" : "_ctx"}.${raw}`;
|
|
715
|
+
raw = withAssignment(raw);
|
|
716
|
+
}
|
|
717
|
+
return [prefix, [
|
|
718
|
+
raw,
|
|
719
|
+
-2,
|
|
720
|
+
loc,
|
|
721
|
+
name
|
|
722
|
+
]];
|
|
723
|
+
function withAssignment(s) {
|
|
724
|
+
return assignment ? `${s} = ${assignment}` : s;
|
|
725
|
+
}
|
|
726
|
+
function unref() {
|
|
727
|
+
return `${helper("unref")}(${raw})`;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
function canPrefix(name) {
|
|
731
|
+
if ((0, _vue_shared.isGloballyAllowed)(name)) return false;
|
|
732
|
+
if (name === "require" || name === "$props" || name === "$emit" || name === "$attrs" || name === "$slots") return false;
|
|
733
|
+
return true;
|
|
734
|
+
}
|
|
735
|
+
function processExpressions(context, expressions, shouldDeclare) {
|
|
736
|
+
const { seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
|
|
737
|
+
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable);
|
|
738
|
+
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap);
|
|
739
|
+
return genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare);
|
|
740
|
+
}
|
|
741
|
+
function analyzeExpressions(expressions) {
|
|
742
|
+
const seenVariable = Object.create(null);
|
|
743
|
+
const variableToExpMap = /* @__PURE__ */ new Map();
|
|
744
|
+
const expToVariableMap = /* @__PURE__ */ new Map();
|
|
745
|
+
const seenIdentifier = /* @__PURE__ */ new Set();
|
|
746
|
+
const updatedVariable = /* @__PURE__ */ new Set();
|
|
747
|
+
const registerVariable = (name, exp, isIdentifier, loc, parentStack = []) => {
|
|
748
|
+
if (isIdentifier) seenIdentifier.add(name);
|
|
749
|
+
seenVariable[name] = (seenVariable[name] || 0) + 1;
|
|
750
|
+
variableToExpMap.set(name, (variableToExpMap.get(name) || /* @__PURE__ */ new Set()).add(exp));
|
|
751
|
+
const variables = expToVariableMap.get(exp) || [];
|
|
752
|
+
variables.push({
|
|
753
|
+
name,
|
|
754
|
+
loc
|
|
755
|
+
});
|
|
756
|
+
expToVariableMap.set(exp, variables);
|
|
757
|
+
if (parentStack.some((p) => p.type === "UpdateExpression" || p.type === "AssignmentExpression")) updatedVariable.add(name);
|
|
758
|
+
};
|
|
759
|
+
for (const exp of expressions) {
|
|
760
|
+
if (!exp.ast) {
|
|
761
|
+
exp.ast === null && registerVariable(exp.content, exp, true);
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
const seenParents = /* @__PURE__ */ new Set();
|
|
765
|
+
(0, _vue_compiler_dom.walkIdentifiers)(exp.ast, (currentNode, parent, parentStack) => {
|
|
766
|
+
if (parent && isMemberExpression$3(parent) && !seenParents.has(parent)) {
|
|
767
|
+
seenParents.add(parent);
|
|
768
|
+
const memberExp = extractMemberExpression(parent, (id) => {
|
|
769
|
+
registerVariable(id.name, exp, true, {
|
|
770
|
+
start: id.start,
|
|
771
|
+
end: id.end
|
|
772
|
+
});
|
|
773
|
+
});
|
|
774
|
+
const parentOfMemberExp = parentStack[parentStack.length - 2];
|
|
775
|
+
if (parentOfMemberExp && isCallExpression(parentOfMemberExp)) return;
|
|
776
|
+
registerVariable(memberExp, exp, false, {
|
|
777
|
+
start: parent.start,
|
|
778
|
+
end: parent.end
|
|
779
|
+
}, parentStack);
|
|
780
|
+
} else if (!parentStack.some(isMemberExpression$3)) registerVariable(currentNode.name, exp, true, {
|
|
781
|
+
start: currentNode.start,
|
|
782
|
+
end: currentNode.end
|
|
783
|
+
}, parentStack);
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
return {
|
|
787
|
+
seenVariable,
|
|
788
|
+
seenIdentifier,
|
|
789
|
+
variableToExpMap,
|
|
790
|
+
expToVariableMap,
|
|
791
|
+
updatedVariable
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
function processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable) {
|
|
795
|
+
const declarations = [];
|
|
796
|
+
const expToReplacementMap = /* @__PURE__ */ new Map();
|
|
797
|
+
for (const [name, exps] of variableToExpMap) {
|
|
798
|
+
if (updatedVariable.has(name)) continue;
|
|
799
|
+
if (seenVariable[name] > 1 && exps.size > 0) {
|
|
800
|
+
const isIdentifier = seenIdentifier.has(name);
|
|
801
|
+
const varName = isIdentifier ? name : genVarName(name);
|
|
802
|
+
exps.forEach((node) => {
|
|
803
|
+
if (node.ast && varName !== name) {
|
|
804
|
+
const replacements = expToReplacementMap.get(node) || [];
|
|
805
|
+
replacements.push({
|
|
806
|
+
name: varName,
|
|
807
|
+
locs: expToVariableMap.get(node).reduce((locs, v) => {
|
|
808
|
+
if (v.name === name && v.loc) locs.push(v.loc);
|
|
809
|
+
return locs;
|
|
810
|
+
}, [])
|
|
811
|
+
});
|
|
812
|
+
expToReplacementMap.set(node, replacements);
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
if (!declarations.some((d) => d.name === varName) && (!isIdentifier || shouldDeclareVariable(name, expToVariableMap, exps))) declarations.push({
|
|
816
|
+
name: varName,
|
|
817
|
+
isIdentifier,
|
|
818
|
+
value: (0, _vue_shared.extend)({ ast: isIdentifier ? null : parseExp(context, name) }, (0, _vue_compiler_dom.createSimpleExpression)(name)),
|
|
819
|
+
rawName: name,
|
|
820
|
+
exps,
|
|
821
|
+
seenCount: seenVariable[name]
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
for (const [exp, replacements] of expToReplacementMap) {
|
|
826
|
+
replacements.flatMap(({ name, locs }) => locs.map(({ start, end }) => ({
|
|
827
|
+
start,
|
|
828
|
+
end,
|
|
829
|
+
name
|
|
830
|
+
}))).sort((a, b) => b.end - a.end).forEach(({ start, end, name }) => {
|
|
831
|
+
exp.content = exp.content.slice(0, start - 1) + name + exp.content.slice(end - 1);
|
|
832
|
+
});
|
|
833
|
+
exp.ast = parseExp(context, exp.content, exp.loc);
|
|
834
|
+
}
|
|
835
|
+
return declarations;
|
|
836
|
+
}
|
|
837
|
+
function shouldDeclareVariable(name, expToVariableMap, exps) {
|
|
838
|
+
const vars = Array.from(exps, (exp) => expToVariableMap.get(exp).map((v) => v.name));
|
|
839
|
+
if (vars.every((v) => v.length === 1)) return true;
|
|
840
|
+
if (vars.some((v) => v.filter((e) => e === name).length > 1)) return true;
|
|
841
|
+
const first = vars[0];
|
|
842
|
+
if (vars.some((v) => v.length !== first.length)) {
|
|
843
|
+
if (vars.some((v) => v.length > first.length && v.every((e) => first.includes(e))) || vars.some((v) => first.length > v.length && first.every((e) => v.includes(e)))) return false;
|
|
844
|
+
return true;
|
|
845
|
+
}
|
|
846
|
+
if (vars.every((v) => v.every((e, idx) => e === first[idx]))) return false;
|
|
847
|
+
return true;
|
|
848
|
+
}
|
|
849
|
+
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap) {
|
|
850
|
+
const declarations = [];
|
|
851
|
+
const seenExp = expressions.reduce((acc, exp) => {
|
|
852
|
+
const vars = expToVariableMap.get(exp);
|
|
853
|
+
if (!vars) return acc;
|
|
854
|
+
const variables = vars.map((v) => v.name);
|
|
855
|
+
if (exp.ast && exp.ast.type !== "Identifier" && !(variables && variables.some((v) => updatedVariable.has(v)))) acc[exp.content] = (acc[exp.content] || 0) + 1;
|
|
856
|
+
return acc;
|
|
857
|
+
}, Object.create(null));
|
|
858
|
+
Object.entries(seenExp).forEach(([content, count]) => {
|
|
859
|
+
if (count > 1) {
|
|
860
|
+
const varName = genVarName(content);
|
|
861
|
+
if (!declarations.some((d) => d.name === varName)) {
|
|
862
|
+
const delVars = {};
|
|
863
|
+
for (let i = varDeclarations.length - 1; i >= 0; i--) {
|
|
864
|
+
const item = varDeclarations[i];
|
|
865
|
+
if (!item.exps || !item.seenCount) continue;
|
|
866
|
+
if ([...item.exps].every((node) => node.content === content && item.seenCount === count)) {
|
|
867
|
+
delVars[item.name] = item.rawName;
|
|
868
|
+
varDeclarations.splice(i, 1);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
const value = (0, _vue_shared.extend)({}, expressions.find((exp) => exp.content === content));
|
|
872
|
+
Object.keys(delVars).forEach((name) => {
|
|
873
|
+
value.content = value.content.replace(name, delVars[name]);
|
|
874
|
+
if (value.ast) value.ast = parseExp(context, value.content, value.loc);
|
|
875
|
+
});
|
|
876
|
+
declarations.push({
|
|
877
|
+
name: varName,
|
|
878
|
+
value
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
expressions.forEach((exp) => {
|
|
882
|
+
if (exp.content === content) {
|
|
883
|
+
exp.content = varName;
|
|
884
|
+
exp.ast = null;
|
|
885
|
+
} else if (exp.content.includes(content)) {
|
|
886
|
+
exp.content = exp.content.replace(new RegExp(escapeRegExp(content), "g"), varName);
|
|
887
|
+
exp.ast = parseExp(context, exp.content, exp.loc);
|
|
888
|
+
}
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
});
|
|
892
|
+
return declarations;
|
|
893
|
+
}
|
|
894
|
+
function genDeclarations(declarations, context, shouldDeclare) {
|
|
895
|
+
const [frag, push] = buildCodeFragment();
|
|
896
|
+
const ids = Object.create(null);
|
|
897
|
+
const varNames = /* @__PURE__ */ new Set();
|
|
898
|
+
declarations.forEach(({ name, isIdentifier, value }) => {
|
|
899
|
+
if (isIdentifier) {
|
|
900
|
+
const varName = ids[name] = `_${name}`;
|
|
901
|
+
varNames.add(varName);
|
|
902
|
+
if (shouldDeclare) push(`const `);
|
|
903
|
+
push(`${varName} = `, ...genExpression(value, context), NEWLINE);
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
declarations.forEach(({ name, isIdentifier, value }) => {
|
|
907
|
+
if (!isIdentifier) {
|
|
908
|
+
const varName = ids[name] = `_${name}`;
|
|
909
|
+
varNames.add(varName);
|
|
910
|
+
if (shouldDeclare) push(`const `);
|
|
911
|
+
push(`${varName} = `, ...context.withId(() => genExpression(value, context), ids), NEWLINE);
|
|
912
|
+
}
|
|
913
|
+
});
|
|
914
|
+
return {
|
|
915
|
+
ids,
|
|
916
|
+
frag,
|
|
917
|
+
varNames: [...varNames]
|
|
918
|
+
};
|
|
919
|
+
}
|
|
920
|
+
function escapeRegExp(string) {
|
|
921
|
+
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
922
|
+
}
|
|
923
|
+
function parseExp(context, content, loc) {
|
|
924
|
+
const plugins = context.options.expressionPlugins;
|
|
925
|
+
const options = { plugins: plugins ? [...plugins, "typescript"] : ["typescript"] };
|
|
926
|
+
try {
|
|
927
|
+
return (0, _babel_parser.parseExpression)(`(${content})`, options);
|
|
928
|
+
} catch (e) {
|
|
929
|
+
if (loc) {
|
|
930
|
+
const error = new SyntaxError(e.message);
|
|
931
|
+
error.loc = loc;
|
|
932
|
+
context.options.onError(error);
|
|
933
|
+
throw error;
|
|
934
|
+
}
|
|
935
|
+
throw e;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
function genVarName(exp) {
|
|
939
|
+
return `${exp.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/_+$/, "")}`;
|
|
940
|
+
}
|
|
941
|
+
function extractMemberExpression(exp, onIdentifier) {
|
|
942
|
+
if (!exp) return "";
|
|
943
|
+
switch (exp.type) {
|
|
944
|
+
case "Identifier":
|
|
945
|
+
onIdentifier(exp);
|
|
946
|
+
return exp.name;
|
|
947
|
+
case "StringLiteral": return exp.extra ? exp.extra.raw : exp.value;
|
|
948
|
+
case "NumericLiteral": return exp.value.toString();
|
|
949
|
+
case "BinaryExpression": return `${extractMemberExpression(exp.left, onIdentifier)} ${exp.operator} ${extractMemberExpression(exp.right, onIdentifier)}`;
|
|
950
|
+
case "CallExpression": return `${extractMemberExpression(exp.callee, onIdentifier)}(${exp.arguments.map((arg) => extractMemberExpression(arg, onIdentifier)).join(", ")})`;
|
|
951
|
+
case "OptionalCallExpression": return `${extractMemberExpression(exp.callee, onIdentifier)}?.(${exp.arguments.map((arg) => extractMemberExpression(arg, onIdentifier)).join(", ")})`;
|
|
952
|
+
case "MemberExpression":
|
|
953
|
+
case "OptionalMemberExpression": return `${extractMemberExpression(exp.object, onIdentifier)}${exp.computed ? `[${extractMemberExpression(exp.property, onIdentifier)}]` : `.${extractMemberExpression(exp.property, _vue_shared.NOOP)}`}`;
|
|
954
|
+
case "TSNonNullExpression": return `${extractMemberExpression(exp.expression, onIdentifier)}`;
|
|
955
|
+
default: return "";
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
const isCallExpression = (node) => {
|
|
959
|
+
return node.type === "CallExpression" || node.type === "OptionalCallExpression";
|
|
960
|
+
};
|
|
961
|
+
const isMemberExpression$3 = (node) => {
|
|
962
|
+
return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "TSNonNullExpression";
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
//#endregion
|
|
966
|
+
//#region packages/compiler-vapor/src/generators/event.ts
|
|
967
|
+
function genSetEvent(oper, context) {
|
|
968
|
+
const { helper } = context;
|
|
969
|
+
const { element, key, keyOverride, value, modifiers, delegate, effect } = oper;
|
|
970
|
+
const name = genName();
|
|
971
|
+
const handler = [
|
|
972
|
+
`${context.helper("createInvoker")}(`,
|
|
973
|
+
...genEventHandler(context, [value], modifiers),
|
|
974
|
+
`)`
|
|
975
|
+
];
|
|
976
|
+
const eventOptions = genEventOptions();
|
|
977
|
+
if (delegate) {
|
|
978
|
+
context.delegates.add(key.content);
|
|
979
|
+
if (!context.block.operation.some(isSameDelegateEvent)) return [
|
|
980
|
+
NEWLINE,
|
|
981
|
+
`n${element}.$evt${key.content} = `,
|
|
982
|
+
...handler
|
|
983
|
+
];
|
|
984
|
+
}
|
|
985
|
+
return [NEWLINE, ...genCall(helper(delegate ? "delegate" : "on"), `n${element}`, name, handler, eventOptions)];
|
|
986
|
+
function genName() {
|
|
987
|
+
const expr = genExpression(key, context);
|
|
988
|
+
if (keyOverride) {
|
|
989
|
+
const find = JSON.stringify(keyOverride[0]);
|
|
990
|
+
const replacement = JSON.stringify(keyOverride[1]);
|
|
991
|
+
const wrapped = [
|
|
992
|
+
"(",
|
|
993
|
+
...expr,
|
|
994
|
+
")"
|
|
995
|
+
];
|
|
996
|
+
return [
|
|
997
|
+
...wrapped,
|
|
998
|
+
` === ${find} ? ${replacement} : `,
|
|
999
|
+
...wrapped
|
|
1000
|
+
];
|
|
1001
|
+
} else return genExpression(key, context);
|
|
1002
|
+
}
|
|
1003
|
+
function genEventOptions() {
|
|
1004
|
+
let { options } = modifiers;
|
|
1005
|
+
if (!options.length && !effect) return;
|
|
1006
|
+
return genMulti(DELIMITERS_OBJECT_NEWLINE, effect && ["effect: true"], ...options.map((option) => [`${option}: true`]));
|
|
1007
|
+
}
|
|
1008
|
+
function isSameDelegateEvent(op) {
|
|
1009
|
+
if (op.type === 5 && op !== oper && op.delegate && op.element === oper.element && op.key.content === key.content) return true;
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
function genSetDynamicEvents(oper, context) {
|
|
1013
|
+
const { helper } = context;
|
|
1014
|
+
return [NEWLINE, ...genCall(helper("setDynamicEvents"), `n${oper.element}`, genExpression(oper.event, context))];
|
|
1015
|
+
}
|
|
1016
|
+
function genEventHandler(context, values, modifiers = {
|
|
1017
|
+
nonKeys: [],
|
|
1018
|
+
keys: []
|
|
1019
|
+
}, asComponentProp = false, extraWrap = false) {
|
|
1020
|
+
let handlerExp = [];
|
|
1021
|
+
if (values) {
|
|
1022
|
+
values.forEach((value, index) => {
|
|
1023
|
+
let exp = [];
|
|
1024
|
+
if (value && value.content.trim()) {
|
|
1025
|
+
if ((0, _vue_compiler_dom.isMemberExpression)(value, context.options)) {
|
|
1026
|
+
exp = genExpression(value, context);
|
|
1027
|
+
if (!isConstantBinding(value, context) && !asComponentProp) {
|
|
1028
|
+
const isTSNode = value.ast && _vue_compiler_dom.TS_NODE_TYPES.includes(value.ast.type);
|
|
1029
|
+
exp = [
|
|
1030
|
+
`e => `,
|
|
1031
|
+
isTSNode ? "(" : "",
|
|
1032
|
+
...exp,
|
|
1033
|
+
isTSNode ? ")" : "",
|
|
1034
|
+
`(e)`
|
|
1035
|
+
];
|
|
1036
|
+
}
|
|
1037
|
+
} else if ((0, _vue_compiler_dom.isFnExpression)(value, context.options)) exp = genExpression(value, context);
|
|
1038
|
+
else {
|
|
1039
|
+
const referencesEvent = value.content.includes("$event");
|
|
1040
|
+
const hasMultipleStatements = value.content.includes(`;`);
|
|
1041
|
+
const expr = referencesEvent ? context.withId(() => genExpression(value, context), { $event: null }) : genExpression(value, context);
|
|
1042
|
+
exp = [
|
|
1043
|
+
referencesEvent ? "$event => " : "() => ",
|
|
1044
|
+
hasMultipleStatements ? "{" : "(",
|
|
1045
|
+
...expr,
|
|
1046
|
+
hasMultipleStatements ? "}" : ")"
|
|
1047
|
+
];
|
|
1048
|
+
}
|
|
1049
|
+
handlerExp = handlerExp.concat([index !== 0 ? ", " : "", ...exp]);
|
|
1050
|
+
}
|
|
1051
|
+
});
|
|
1052
|
+
if (values.length > 1) handlerExp = [
|
|
1053
|
+
"[",
|
|
1054
|
+
...handlerExp,
|
|
1055
|
+
"]"
|
|
1056
|
+
];
|
|
1057
|
+
}
|
|
1058
|
+
if (handlerExp.length === 0) handlerExp = ["() => {}"];
|
|
1059
|
+
const { keys, nonKeys } = modifiers;
|
|
1060
|
+
if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys);
|
|
1061
|
+
if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys);
|
|
1062
|
+
if (extraWrap) handlerExp.unshift(`() => `);
|
|
1063
|
+
return handlerExp;
|
|
1064
|
+
}
|
|
1065
|
+
function genWithModifiers(context, handler, nonKeys) {
|
|
1066
|
+
return genCall(context.helper("withModifiers"), handler, JSON.stringify(nonKeys));
|
|
1067
|
+
}
|
|
1068
|
+
function genWithKeys(context, handler, keys) {
|
|
1069
|
+
return genCall(context.helper("withKeys"), handler, JSON.stringify(keys));
|
|
1070
|
+
}
|
|
1071
|
+
function isConstantBinding(value, context) {
|
|
1072
|
+
if (value.ast === null) {
|
|
1073
|
+
if (context.options.bindingMetadata[value.content] === "setup-const") return true;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
//#endregion
|
|
1078
|
+
//#region packages/compiler-vapor/src/generators/for.ts
|
|
1079
|
+
function genFor(oper, context) {
|
|
1080
|
+
const { helper } = context;
|
|
1081
|
+
const { source, value, key, index, render, keyProp, once, id, component, onlyChild } = oper;
|
|
1082
|
+
const rawValue = value && value.content;
|
|
1083
|
+
const rawKey = key && key.content;
|
|
1084
|
+
const rawIndex = index && index.content;
|
|
1085
|
+
const sourceExpr = [
|
|
1086
|
+
"() => (",
|
|
1087
|
+
...genExpression(source, context),
|
|
1088
|
+
")"
|
|
1089
|
+
];
|
|
1090
|
+
const idToPathMap = parseValueDestructure(value, context);
|
|
1091
|
+
const [depth, exitScope] = context.enterScope();
|
|
1092
|
+
const itemVar = `_for_item${depth}`;
|
|
1093
|
+
const idMap = buildDestructureIdMap(idToPathMap, `${itemVar}.value`, context.options.expressionPlugins);
|
|
1094
|
+
idMap[itemVar] = null;
|
|
1095
|
+
const args = [itemVar];
|
|
1096
|
+
if (rawKey) {
|
|
1097
|
+
const keyVar = `_for_key${depth}`;
|
|
1098
|
+
args.push(`, ${keyVar}`);
|
|
1099
|
+
idMap[rawKey] = `${keyVar}.value`;
|
|
1100
|
+
idMap[keyVar] = null;
|
|
1101
|
+
}
|
|
1102
|
+
if (rawIndex) {
|
|
1103
|
+
const indexVar = `_for_index${depth}`;
|
|
1104
|
+
args.push(`, ${indexVar}`);
|
|
1105
|
+
idMap[rawIndex] = `${indexVar}.value`;
|
|
1106
|
+
idMap[indexVar] = null;
|
|
1107
|
+
}
|
|
1108
|
+
const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap);
|
|
1109
|
+
const selectorDeclarations = [];
|
|
1110
|
+
const selectorSetup = [];
|
|
1111
|
+
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
1112
|
+
const { selector } = selectorPatterns[i];
|
|
1113
|
+
const selectorName = `_selector${id}_${i}`;
|
|
1114
|
+
selectorDeclarations.push(`let ${selectorName}`, NEWLINE);
|
|
1115
|
+
if (i === 0) selectorSetup.push(`({ createSelector }) => {`, INDENT_START);
|
|
1116
|
+
selectorSetup.push(NEWLINE, `${selectorName} = `, ...genCall(`createSelector`, [`() => `, ...genExpression(selector, context)]));
|
|
1117
|
+
if (i === selectorPatterns.length - 1) selectorSetup.push(INDENT_END, NEWLINE, "}");
|
|
1118
|
+
}
|
|
1119
|
+
const blockFn = context.withId(() => {
|
|
1120
|
+
const frag = [];
|
|
1121
|
+
frag.push("(", ...args, ") => {", INDENT_START);
|
|
1122
|
+
if (selectorPatterns.length || keyOnlyBindingPatterns.length) frag.push(...genBlockContent(render, context, false, () => {
|
|
1123
|
+
const patternFrag = [];
|
|
1124
|
+
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
1125
|
+
const { effect } = selectorPatterns[i];
|
|
1126
|
+
patternFrag.push(NEWLINE, `_selector${id}_${i}(() => {`, INDENT_START);
|
|
1127
|
+
for (const oper of effect.operations) patternFrag.push(...genOperation(oper, context));
|
|
1128
|
+
patternFrag.push(INDENT_END, NEWLINE, `})`);
|
|
1129
|
+
}
|
|
1130
|
+
for (const { effect } of keyOnlyBindingPatterns) for (const oper of effect.operations) patternFrag.push(...genOperation(oper, context));
|
|
1131
|
+
return patternFrag;
|
|
1132
|
+
}));
|
|
1133
|
+
else frag.push(...genBlockContent(render, context));
|
|
1134
|
+
frag.push(INDENT_END, NEWLINE, "}");
|
|
1135
|
+
return frag;
|
|
1136
|
+
}, idMap);
|
|
1137
|
+
exitScope();
|
|
1138
|
+
let flags = 0;
|
|
1139
|
+
if (onlyChild) flags |= 1;
|
|
1140
|
+
if (component) flags |= 2;
|
|
1141
|
+
if (once) flags |= 4;
|
|
1142
|
+
return [
|
|
1143
|
+
NEWLINE,
|
|
1144
|
+
...selectorDeclarations,
|
|
1145
|
+
`const n${id} = `,
|
|
1146
|
+
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags ? String(flags) : void 0, selectorSetup.length ? selectorSetup : void 0)
|
|
1147
|
+
];
|
|
1148
|
+
function genCallback(expr) {
|
|
1149
|
+
if (!expr) return false;
|
|
1150
|
+
const res = context.withId(() => genExpression(expr, context), genSimpleIdMap());
|
|
1151
|
+
return [
|
|
1152
|
+
...genMulti([
|
|
1153
|
+
"(",
|
|
1154
|
+
")",
|
|
1155
|
+
", "
|
|
1156
|
+
], rawValue ? rawValue : rawKey || rawIndex ? "_" : void 0, rawKey ? rawKey : rawIndex ? "__" : void 0, rawIndex),
|
|
1157
|
+
" => (",
|
|
1158
|
+
...res,
|
|
1159
|
+
")"
|
|
1160
|
+
];
|
|
1161
|
+
}
|
|
1162
|
+
function genSimpleIdMap() {
|
|
1163
|
+
const idMap = {};
|
|
1164
|
+
if (rawKey) idMap[rawKey] = null;
|
|
1165
|
+
if (rawIndex) idMap[rawIndex] = null;
|
|
1166
|
+
idToPathMap.forEach((_, id) => idMap[id] = null);
|
|
1167
|
+
return idMap;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
function parseValueDestructure(value, context) {
|
|
1171
|
+
const map = /* @__PURE__ */ new Map();
|
|
1172
|
+
if (value) {
|
|
1173
|
+
const rawValue = value.content;
|
|
1174
|
+
if (value.ast) {
|
|
1175
|
+
const isDom2 = !!context.options.platform;
|
|
1176
|
+
(0, _vue_compiler_dom.walkIdentifiers)(value.ast, (id, _, parentStack, ___, isLocal) => {
|
|
1177
|
+
if (isLocal) {
|
|
1178
|
+
let path = "";
|
|
1179
|
+
let isDynamic = false;
|
|
1180
|
+
let helper;
|
|
1181
|
+
let helperArgs;
|
|
1182
|
+
for (let i = 0; i < parentStack.length; i++) {
|
|
1183
|
+
const parent = parentStack[i];
|
|
1184
|
+
const child = parentStack[i + 1] || id;
|
|
1185
|
+
if (parent.type === "ObjectProperty" && parent.value === child) if (parent.key.type === "StringLiteral") path += `[${JSON.stringify(parent.key.value)}]`;
|
|
1186
|
+
else if (parent.computed) {
|
|
1187
|
+
isDynamic = true;
|
|
1188
|
+
path += `[${rawValue.slice(parent.key.start - 1, parent.key.end - 1)}]`;
|
|
1189
|
+
} else path += `.${parent.key.name}`;
|
|
1190
|
+
else if (parent.type === "ArrayPattern") {
|
|
1191
|
+
const index = parent.elements.indexOf(child);
|
|
1192
|
+
if (child.type === "RestElement") path += `.slice(${index})`;
|
|
1193
|
+
else path += `[${index}]`;
|
|
1194
|
+
} else if (parent.type === "ObjectPattern" && child.type === "RestElement") {
|
|
1195
|
+
helper = isDom2 ? context.helper("getSharedDataRestElement") : context.helper("getRestElement");
|
|
1196
|
+
helperArgs = "[" + parent.properties.filter((p) => p.type === "ObjectProperty").map((p) => {
|
|
1197
|
+
if (p.key.type === "StringLiteral") return JSON.stringify(p.key.value);
|
|
1198
|
+
else if (p.computed) {
|
|
1199
|
+
isDynamic = true;
|
|
1200
|
+
return rawValue.slice(p.key.start - 1, p.key.end - 1);
|
|
1201
|
+
} else return JSON.stringify(p.key.name);
|
|
1202
|
+
}).join(", ") + "]";
|
|
1203
|
+
}
|
|
1204
|
+
if (child.type === "AssignmentPattern" && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
|
|
1205
|
+
isDynamic = true;
|
|
1206
|
+
helper = isDom2 ? context.helper("getSharedDataDefaultValue") : context.helper("getDefaultValue");
|
|
1207
|
+
helperArgs = rawValue.slice(child.right.start - 1, child.right.end - 1);
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
map.set(id.name, {
|
|
1211
|
+
path,
|
|
1212
|
+
dynamic: isDynamic,
|
|
1213
|
+
helper,
|
|
1214
|
+
helperArgs
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
}, true);
|
|
1218
|
+
} else if (rawValue) map.set(rawValue, null);
|
|
1219
|
+
}
|
|
1220
|
+
return map;
|
|
1221
|
+
}
|
|
1222
|
+
function buildDestructureIdMap(idToPathMap, baseAccessor, plugins) {
|
|
1223
|
+
const idMap = {};
|
|
1224
|
+
idToPathMap.forEach((pathInfo, id) => {
|
|
1225
|
+
let path = baseAccessor;
|
|
1226
|
+
if (pathInfo) {
|
|
1227
|
+
path = `${baseAccessor}${pathInfo.path}`;
|
|
1228
|
+
if (pathInfo.helper) {
|
|
1229
|
+
idMap[pathInfo.helper] = null;
|
|
1230
|
+
path = pathInfo.helperArgs ? `${pathInfo.helper}(${path}, ${pathInfo.helperArgs})` : `${pathInfo.helper}(${path})`;
|
|
1231
|
+
}
|
|
1232
|
+
if (pathInfo.dynamic) {
|
|
1233
|
+
const node = idMap[id] = (0, _vue_compiler_dom.createSimpleExpression)(path);
|
|
1234
|
+
node.ast = (0, _babel_parser.parseExpression)(`(${path})`, { plugins: plugins ? [...plugins, "typescript"] : ["typescript"] });
|
|
1235
|
+
} else idMap[id] = path;
|
|
1236
|
+
} else idMap[id] = path;
|
|
1237
|
+
});
|
|
1238
|
+
return idMap;
|
|
1239
|
+
}
|
|
1240
|
+
function matchPatterns(render, keyProp, idMap) {
|
|
1241
|
+
const selectorPatterns = [];
|
|
1242
|
+
const keyOnlyBindingPatterns = [];
|
|
1243
|
+
render.effect = render.effect.filter((effect) => {
|
|
1244
|
+
if (keyProp !== void 0) {
|
|
1245
|
+
const selector = matchSelectorPattern(effect, keyProp.content, idMap);
|
|
1246
|
+
if (selector) {
|
|
1247
|
+
selectorPatterns.push(selector);
|
|
1248
|
+
return false;
|
|
1249
|
+
}
|
|
1250
|
+
const keyOnly = matchKeyOnlyBindingPattern(effect, keyProp.content);
|
|
1251
|
+
if (keyOnly) {
|
|
1252
|
+
keyOnlyBindingPatterns.push(keyOnly);
|
|
1253
|
+
return false;
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
return true;
|
|
1257
|
+
});
|
|
1258
|
+
return {
|
|
1259
|
+
keyOnlyBindingPatterns,
|
|
1260
|
+
selectorPatterns
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
function matchKeyOnlyBindingPattern(effect, key) {
|
|
1264
|
+
if (effect.expressions.length === 1) {
|
|
1265
|
+
const { ast, content } = effect.expressions[0];
|
|
1266
|
+
if (typeof ast === "object" && ast !== null) {
|
|
1267
|
+
if (isKeyOnlyBinding(ast, key, content)) return { effect };
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
function matchSelectorPattern(effect, key, idMap) {
|
|
1272
|
+
if (effect.expressions.length === 1) {
|
|
1273
|
+
const { ast, content } = effect.expressions[0];
|
|
1274
|
+
if (typeof ast === "object" && ast) {
|
|
1275
|
+
const matcheds = [];
|
|
1276
|
+
(0, estree_walker.walk)(ast, { enter(node) {
|
|
1277
|
+
if (typeof node === "object" && node && node.type === "BinaryExpression" && node.operator === "===" && node.left.type !== "PrivateName") {
|
|
1278
|
+
const { left, right } = node;
|
|
1279
|
+
for (const [a, b] of [[left, right], [right, left]]) {
|
|
1280
|
+
const aIsKey = isKeyOnlyBinding(a, key, content);
|
|
1281
|
+
const bIsKey = isKeyOnlyBinding(b, key, content);
|
|
1282
|
+
const bVars = analyzeVariableScopes(b, idMap);
|
|
1283
|
+
if (aIsKey && !bIsKey && !bVars.length) matcheds.push([a, b]);
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
} });
|
|
1287
|
+
if (matcheds.length === 1) {
|
|
1288
|
+
const [key, selector] = matcheds[0];
|
|
1289
|
+
const content = effect.expressions[0].content;
|
|
1290
|
+
let hasExtraId = false;
|
|
1291
|
+
(0, _vue_compiler_dom.walkIdentifiers)(ast, (id) => {
|
|
1292
|
+
if (id.start !== key.start && id.start !== selector.start) hasExtraId = true;
|
|
1293
|
+
}, false);
|
|
1294
|
+
if (!hasExtraId) {
|
|
1295
|
+
const name = content.slice(selector.start - 1, selector.end - 1);
|
|
1296
|
+
return {
|
|
1297
|
+
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
|
+
}
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
function analyzeVariableScopes(ast, idMap) {
|
|
1314
|
+
let locals = [];
|
|
1315
|
+
const ids = [];
|
|
1316
|
+
(0, _vue_compiler_dom.walkIdentifiers)(ast, (id) => {
|
|
1317
|
+
ids.push(id);
|
|
1318
|
+
}, false);
|
|
1319
|
+
for (const id of ids) {
|
|
1320
|
+
if ((0, _vue_shared.isGloballyAllowed)(id.name)) continue;
|
|
1321
|
+
if (idMap[id.name]) locals.push(id.name);
|
|
1322
|
+
}
|
|
1323
|
+
return locals;
|
|
1324
|
+
}
|
|
1325
|
+
function isKeyOnlyBinding(expr, key, source) {
|
|
1326
|
+
let only = true;
|
|
1327
|
+
(0, estree_walker.walk)(expr, { enter(node) {
|
|
1328
|
+
if (source.slice(node.start - 1, node.end - 1) === key) {
|
|
1329
|
+
this.skip();
|
|
1330
|
+
return;
|
|
1331
|
+
}
|
|
1332
|
+
if (node.type === "Identifier") only = false;
|
|
1333
|
+
} });
|
|
1334
|
+
return only;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
//#endregion
|
|
1338
|
+
//#region packages/compiler-vapor/src/generators/html.ts
|
|
1339
|
+
function genSetHtml(oper, context) {
|
|
1340
|
+
const { helper } = context;
|
|
1341
|
+
const { value, element, isComponent } = oper;
|
|
1342
|
+
return [NEWLINE, ...genCall(isComponent ? helper("setBlockHtml") : helper("setHtml"), `n${element}`, genExpression(value, context))];
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
//#endregion
|
|
1346
|
+
//#region packages/compiler-vapor/src/generators/if.ts
|
|
1347
|
+
function genIf(oper, context, isNested = false) {
|
|
1348
|
+
const { helper } = context;
|
|
1349
|
+
const { condition, positive, negative, once, index } = oper;
|
|
1350
|
+
const [frag, push] = buildCodeFragment();
|
|
1351
|
+
const conditionExpr = [
|
|
1352
|
+
"() => (",
|
|
1353
|
+
...genExpression(condition, context),
|
|
1354
|
+
")"
|
|
1355
|
+
];
|
|
1356
|
+
let positiveArg = genBlock(positive, context);
|
|
1357
|
+
let negativeArg = false;
|
|
1358
|
+
if (negative) if (negative.type === 1) negativeArg = genBlock(negative, context);
|
|
1359
|
+
else negativeArg = ["() => ", ...genIf(negative, context, true)];
|
|
1360
|
+
if (!isNested) push(NEWLINE, `const n${oper.id} = `);
|
|
1361
|
+
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, once && "true", index !== void 0 && negative && String(index)));
|
|
1362
|
+
return frag;
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
//#endregion
|
|
1366
|
+
//#region packages/compiler-vapor/src/generators/prop.ts
|
|
1367
|
+
const helpers = {
|
|
1368
|
+
setText: { name: "setText" },
|
|
1369
|
+
setHtml: { name: "setHtml" },
|
|
1370
|
+
setClass: { name: "setClass" },
|
|
1371
|
+
setStyle: { name: "setStyle" },
|
|
1372
|
+
setValue: { name: "setValue" },
|
|
1373
|
+
setAttr: {
|
|
1374
|
+
name: "setAttr",
|
|
1375
|
+
needKey: true
|
|
1376
|
+
},
|
|
1377
|
+
setProp: {
|
|
1378
|
+
name: "setProp",
|
|
1379
|
+
needKey: true
|
|
1380
|
+
},
|
|
1381
|
+
setDOMProp: {
|
|
1382
|
+
name: "setDOMProp",
|
|
1383
|
+
needKey: true
|
|
1384
|
+
}
|
|
1385
|
+
};
|
|
1386
|
+
function genSetProp(oper, context) {
|
|
1387
|
+
const { helper } = context;
|
|
1388
|
+
const { prop: { key, values, modifier }, tag } = oper;
|
|
1389
|
+
const resolvedHelper = getRuntimeHelper(tag, key.content, modifier);
|
|
1390
|
+
const propValue = genPropValue(values, context);
|
|
1391
|
+
return [NEWLINE, ...genCall([helper(resolvedHelper.name), null], `n${oper.element}`, resolvedHelper.needKey ? genExpression(key, context) : false, propValue, resolvedHelper.isSVG && "true")];
|
|
1392
|
+
}
|
|
1393
|
+
function genDynamicProps$1(oper, context) {
|
|
1394
|
+
const { helper } = context;
|
|
1395
|
+
const isSVG = (0, _vue_shared.isSVGTag)(oper.tag);
|
|
1396
|
+
const values = oper.props.map((props) => Array.isArray(props) ? genLiteralObjectProps(props, context) : props.kind === 1 ? genLiteralObjectProps([props], context) : genExpression(props.value, context));
|
|
1397
|
+
return [NEWLINE, ...genCall(helper("setDynamicProps"), `n${oper.element}`, genMulti(DELIMITERS_ARRAY, ...values), isSVG && "true")];
|
|
1398
|
+
}
|
|
1399
|
+
function genLiteralObjectProps(props, context) {
|
|
1400
|
+
return genMulti(DELIMITERS_OBJECT, ...props.map((prop) => [
|
|
1401
|
+
...genPropKey(prop, context),
|
|
1402
|
+
`: `,
|
|
1403
|
+
...genPropValue(prop.values, context)
|
|
1404
|
+
]));
|
|
1405
|
+
}
|
|
1406
|
+
function genPropKey({ key: node, modifier, runtimeCamelize, handler, handlerModifiers }, context) {
|
|
1407
|
+
const { helper } = context;
|
|
1408
|
+
const handlerModifierPostfix = handlerModifiers && handlerModifiers.options ? handlerModifiers.options.map(_vue_shared.capitalize).join("") : "";
|
|
1409
|
+
if (node.isStatic) {
|
|
1410
|
+
const keyName = (handler ? (0, _vue_shared.toHandlerKey)((0, _vue_shared.camelize)(node.content)) : node.content) + handlerModifierPostfix;
|
|
1411
|
+
return [[
|
|
1412
|
+
(0, _vue_compiler_dom.isSimpleIdentifier)(keyName) ? keyName : JSON.stringify(keyName),
|
|
1413
|
+
-2,
|
|
1414
|
+
node.loc
|
|
1415
|
+
]];
|
|
1416
|
+
}
|
|
1417
|
+
let key = genExpression(node, context);
|
|
1418
|
+
if (runtimeCamelize) {
|
|
1419
|
+
key.push(" || \"\"");
|
|
1420
|
+
key = genCall(helper("camelize"), key);
|
|
1421
|
+
}
|
|
1422
|
+
if (handler) key = genCall(helper("toHandlerKey"), key);
|
|
1423
|
+
return [
|
|
1424
|
+
"[",
|
|
1425
|
+
modifier && `${JSON.stringify(modifier)} + `,
|
|
1426
|
+
...key,
|
|
1427
|
+
handlerModifierPostfix ? ` + ${JSON.stringify(handlerModifierPostfix)}` : void 0,
|
|
1428
|
+
"]"
|
|
1429
|
+
];
|
|
1430
|
+
}
|
|
1431
|
+
function genPropValue(values, context) {
|
|
1432
|
+
if (values.length === 1) return genExpression(values[0], context);
|
|
1433
|
+
return genMulti(DELIMITERS_ARRAY, ...values.map((expr) => genExpression(expr, context)));
|
|
1434
|
+
}
|
|
1435
|
+
function getRuntimeHelper(tag, key, modifier) {
|
|
1436
|
+
const tagName = tag.toUpperCase();
|
|
1437
|
+
const isSVG = (0, _vue_shared.isSVGTag)(tag);
|
|
1438
|
+
if (modifier) if (modifier === ".") return getSpecialHelper(key, tagName, isSVG) || helpers.setDOMProp;
|
|
1439
|
+
else return isSVG ? (0, _vue_shared.extend)({ isSVG: true }, helpers.setAttr) : helpers.setAttr;
|
|
1440
|
+
const helper = getSpecialHelper(key, tagName, isSVG);
|
|
1441
|
+
if (helper) return helper;
|
|
1442
|
+
if (/aria[A-Z]/.test(key)) return helpers.setDOMProp;
|
|
1443
|
+
if (isSVG) return (0, _vue_shared.extend)({ isSVG: true }, helpers.setAttr);
|
|
1444
|
+
if ((0, _vue_shared.shouldSetAsAttr)(tagName, key) || key.includes("-")) return helpers.setAttr;
|
|
1445
|
+
return helpers.setProp;
|
|
1446
|
+
}
|
|
1447
|
+
function getSpecialHelper(keyName, tagName, isSVG) {
|
|
1448
|
+
if (keyName === "value" && (0, _vue_shared.canSetValueDirectly)(tagName)) return helpers.setValue;
|
|
1449
|
+
else if (keyName === "class") return (0, _vue_shared.extend)({ isSVG }, helpers.setClass);
|
|
1450
|
+
else if (keyName === "style") return helpers.setStyle;
|
|
1451
|
+
else if (keyName === "innerHTML") return helpers.setHtml;
|
|
1452
|
+
else if (keyName === "textContent") return helpers.setText;
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
//#endregion
|
|
1456
|
+
//#region packages/compiler-vapor/src/generators/templateRef.ts
|
|
1457
|
+
const setTemplateRefIdent = `_setTemplateRef`;
|
|
1458
|
+
function genSetTemplateRef(oper, context) {
|
|
1459
|
+
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
1460
|
+
return [NEWLINE, ...genCall(setTemplateRefIdent, `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
1461
|
+
}
|
|
1462
|
+
function genRefValue(value, context) {
|
|
1463
|
+
if (value && context.options.inline) {
|
|
1464
|
+
const binding = context.options.bindingMetadata[value.content];
|
|
1465
|
+
if (binding === "setup-let" || binding === "setup-ref" || binding === "setup-maybe-ref") return [[value.content], JSON.stringify(value.content)];
|
|
1466
|
+
}
|
|
1467
|
+
return [genExpression(value, context)];
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
//#endregion
|
|
1471
|
+
//#region packages/compiler-vapor/src/generators/text.ts
|
|
1472
|
+
function genSetText(oper, context) {
|
|
1473
|
+
const { helper } = context;
|
|
1474
|
+
const { element, values, generated, isComponent } = oper;
|
|
1475
|
+
const texts = combineValues(values, context);
|
|
1476
|
+
return [NEWLINE, ...genCall(isComponent ? helper("setBlockText") : helper("setText"), `${generated && !isComponent ? "x" : "n"}${element}`, texts)];
|
|
1477
|
+
}
|
|
1478
|
+
function combineValues(values, context) {
|
|
1479
|
+
return values.flatMap((value, i) => {
|
|
1480
|
+
let exp = genExpression(value, context);
|
|
1481
|
+
if (getLiteralExpressionValue(value, true) == null) exp = genCall(context.helper("toDisplayString"), exp);
|
|
1482
|
+
if (i > 0) exp.unshift(" + ");
|
|
1483
|
+
return exp;
|
|
1484
|
+
});
|
|
1485
|
+
}
|
|
1486
|
+
function genGetTextChild(oper, context) {
|
|
1487
|
+
return [NEWLINE, `const x${oper.parent} = ${context.helper("txt")}(n${oper.parent})`];
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1490
|
+
//#endregion
|
|
1491
|
+
//#region packages/compiler-vapor/src/generators/vShow.ts
|
|
1492
|
+
function genVShow(oper, context) {
|
|
1493
|
+
const { deferred, element } = oper;
|
|
1494
|
+
return [
|
|
1495
|
+
NEWLINE,
|
|
1496
|
+
deferred ? `deferredApplyVShows.push(() => ` : void 0,
|
|
1497
|
+
...genCall(context.helper("applyVShow"), `n${element}`, [
|
|
1498
|
+
`() => (`,
|
|
1499
|
+
...genExpression(oper.dir.exp, context),
|
|
1500
|
+
`)`
|
|
1501
|
+
]),
|
|
1502
|
+
deferred ? `)` : void 0
|
|
1503
|
+
];
|
|
1504
|
+
}
|
|
1505
|
+
|
|
1506
|
+
//#endregion
|
|
1507
|
+
//#region packages/compiler-vapor/src/generators/vModel.ts
|
|
1508
|
+
const helperMap = {
|
|
1509
|
+
text: "applyTextModel",
|
|
1510
|
+
radio: "applyRadioModel",
|
|
1511
|
+
checkbox: "applyCheckboxModel",
|
|
1512
|
+
select: "applySelectModel",
|
|
1513
|
+
dynamic: "applyDynamicModel"
|
|
1514
|
+
};
|
|
1515
|
+
function genVModel(oper, context) {
|
|
1516
|
+
const { modelType, element, dir: { exp, modifiers } } = oper;
|
|
1517
|
+
return [NEWLINE, ...genCall(context.helper(helperMap[modelType]), `n${element}`, [
|
|
1518
|
+
`() => (`,
|
|
1519
|
+
...genExpression(exp, context),
|
|
1520
|
+
`)`
|
|
1521
|
+
], genModelHandler(exp, context), modifiers.length ? `{ ${modifiers.map((e) => e.content + ": true").join(",")} }` : void 0)];
|
|
1522
|
+
}
|
|
1523
|
+
function genModelHandler(exp, context) {
|
|
1524
|
+
return [
|
|
1525
|
+
`${context.options.isTS ? `(_value: any)` : `_value`} => (`,
|
|
1526
|
+
...genExpression(exp, context, "_value"),
|
|
1527
|
+
")"
|
|
1528
|
+
];
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
//#endregion
|
|
1532
|
+
//#region packages/compiler-vapor/src/generators/directive.ts
|
|
1533
|
+
function genBuiltinDirective(oper, context) {
|
|
1534
|
+
switch (oper.name) {
|
|
1535
|
+
case "show": return genVShow(oper, context);
|
|
1536
|
+
case "model": return genVModel(oper, context);
|
|
1537
|
+
default: return [];
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
/**
|
|
1541
|
+
* user directives via `withVaporDirectives`
|
|
1542
|
+
*/
|
|
1543
|
+
function genDirectivesForElement(id, context) {
|
|
1544
|
+
const dirs = filterCustomDirectives(id, context.block.operation);
|
|
1545
|
+
return dirs.length ? genCustomDirectives(dirs, context) : [];
|
|
1546
|
+
}
|
|
1547
|
+
function genCustomDirectives(opers, context) {
|
|
1548
|
+
const { helper } = context;
|
|
1549
|
+
const element = `n${opers[0].element}`;
|
|
1550
|
+
const directives = genMulti(DELIMITERS_ARRAY, ...opers.map(genDirectiveItem));
|
|
1551
|
+
return [NEWLINE, ...genCall(helper("withVaporDirectives"), element, directives)];
|
|
1552
|
+
function genDirectiveItem({ dir, name, asset }) {
|
|
1553
|
+
const directiveVar = asset ? (0, _vue_compiler_dom.toValidAssetId)(name, "directive") : genExpression((0, _vue_shared.extend)((0, _vue_compiler_dom.createSimpleExpression)(name, false), { ast: null }), context);
|
|
1554
|
+
const value = dir.exp && ["() => ", ...genExpression(dir.exp, context)];
|
|
1555
|
+
const argument = dir.arg && genExpression(dir.arg, context);
|
|
1556
|
+
const modifiers = !!dir.modifiers.length && [
|
|
1557
|
+
"{ ",
|
|
1558
|
+
genDirectiveModifiers(dir.modifiers.map((m) => m.content)),
|
|
1559
|
+
" }"
|
|
1560
|
+
];
|
|
1561
|
+
return genMulti(DELIMITERS_ARRAY.concat("void 0"), directiveVar, value, argument, modifiers);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
function genDirectiveModifiers(modifiers) {
|
|
1565
|
+
return modifiers.map((value) => `${(0, _vue_compiler_dom.isSimpleIdentifier)(value) ? value : JSON.stringify(value)}: true`).join(", ");
|
|
1566
|
+
}
|
|
1567
|
+
function filterCustomDirectives(id, operations) {
|
|
1568
|
+
return operations.filter((oper) => oper.type === 13 && oper.element === id && !oper.builtin);
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
//#endregion
|
|
1572
|
+
//#region packages/compiler-vapor/src/generators/component.ts
|
|
1573
|
+
function genCreateComponent(operation, context) {
|
|
1574
|
+
const { helper } = context;
|
|
1575
|
+
const tag = genTag();
|
|
1576
|
+
const { root, props, slots, once } = operation;
|
|
1577
|
+
const rawSlots = genRawSlots(slots, context);
|
|
1578
|
+
const [ids, handlers] = processInlineHandlers(props, context);
|
|
1579
|
+
const rawProps = context.withId(() => genRawProps(props, context), ids);
|
|
1580
|
+
return [
|
|
1581
|
+
NEWLINE,
|
|
1582
|
+
...handlers.reduce((acc, { name, value }) => {
|
|
1583
|
+
const handler = genEventHandler(context, [value], void 0, false, false);
|
|
1584
|
+
return [
|
|
1585
|
+
...acc,
|
|
1586
|
+
`const ${name} = `,
|
|
1587
|
+
...handler,
|
|
1588
|
+
NEWLINE
|
|
1589
|
+
];
|
|
1590
|
+
}, []),
|
|
1591
|
+
`const n${operation.id} = `,
|
|
1592
|
+
...genCall(operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.isCustomElement ? helper("createPlainElement") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, root ? "true" : false, once && "true"),
|
|
1593
|
+
...genDirectivesForElement(operation.id, context)
|
|
1594
|
+
];
|
|
1595
|
+
function genTag() {
|
|
1596
|
+
if (operation.isCustomElement) return JSON.stringify(operation.tag);
|
|
1597
|
+
else if (operation.dynamic) if (operation.dynamic.isStatic) return genCall(helper("resolveDynamicComponent"), genExpression(operation.dynamic, context));
|
|
1598
|
+
else return [
|
|
1599
|
+
"() => (",
|
|
1600
|
+
...genExpression(operation.dynamic, context),
|
|
1601
|
+
")"
|
|
1602
|
+
];
|
|
1603
|
+
else if (operation.asset) return (0, _vue_compiler_dom.toValidAssetId)(operation.tag, "component");
|
|
1604
|
+
else {
|
|
1605
|
+
const { tag } = operation;
|
|
1606
|
+
const builtInTag = isBuiltInComponent(tag);
|
|
1607
|
+
if (builtInTag) {
|
|
1608
|
+
helper(builtInTag);
|
|
1609
|
+
return `_${builtInTag}`;
|
|
1610
|
+
}
|
|
1611
|
+
return genExpression((0, _vue_shared.extend)((0, _vue_compiler_dom.createSimpleExpression)(tag, false), { ast: null }), context);
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
function getUniqueHandlerName(context, name) {
|
|
1616
|
+
const { seenInlineHandlerNames } = context;
|
|
1617
|
+
name = genVarName(name);
|
|
1618
|
+
const count = seenInlineHandlerNames[name] || 0;
|
|
1619
|
+
seenInlineHandlerNames[name] = count + 1;
|
|
1620
|
+
return count === 0 ? name : `${name}${count}`;
|
|
1621
|
+
}
|
|
1622
|
+
function processInlineHandlers(props, context) {
|
|
1623
|
+
const ids = Object.create(null);
|
|
1624
|
+
const handlers = [];
|
|
1625
|
+
const staticProps = props[0];
|
|
1626
|
+
if ((0, _vue_shared.isArray)(staticProps)) for (let i = 0; i < staticProps.length; i++) {
|
|
1627
|
+
const prop = staticProps[i];
|
|
1628
|
+
if (!prop.handler) continue;
|
|
1629
|
+
prop.values.forEach((value, i) => {
|
|
1630
|
+
if (!(0, _vue_compiler_dom.isMemberExpression)(value, context.options)) {
|
|
1631
|
+
const name = getUniqueHandlerName(context, `_on_${prop.key.content.replace(/-/g, "_")}`);
|
|
1632
|
+
handlers.push({
|
|
1633
|
+
name,
|
|
1634
|
+
value
|
|
1635
|
+
});
|
|
1636
|
+
ids[name] = null;
|
|
1637
|
+
prop.values[i] = (0, _vue_shared.extend)({ ast: null }, (0, _vue_compiler_dom.createSimpleExpression)(name));
|
|
1638
|
+
}
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
return [ids, handlers];
|
|
1642
|
+
}
|
|
1643
|
+
function genRawProps(props, context) {
|
|
1644
|
+
const staticProps = props[0];
|
|
1645
|
+
if ((0, _vue_shared.isArray)(staticProps)) {
|
|
1646
|
+
if (!staticProps.length && props.length === 1) return;
|
|
1647
|
+
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context));
|
|
1648
|
+
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context));
|
|
1649
|
+
}
|
|
1650
|
+
function genStaticProps(props, context, dynamicProps) {
|
|
1651
|
+
const args = [];
|
|
1652
|
+
const handlerGroups = /* @__PURE__ */ new Map();
|
|
1653
|
+
const ensureHandlerGroup = (keyName, keyFrag) => {
|
|
1654
|
+
let group = handlerGroups.get(keyName);
|
|
1655
|
+
if (!group) {
|
|
1656
|
+
const index = args.length;
|
|
1657
|
+
args.push([]);
|
|
1658
|
+
group = {
|
|
1659
|
+
keyFrag,
|
|
1660
|
+
handlers: [],
|
|
1661
|
+
index
|
|
1662
|
+
};
|
|
1663
|
+
handlerGroups.set(keyName, group);
|
|
1664
|
+
}
|
|
1665
|
+
return group;
|
|
1666
|
+
};
|
|
1667
|
+
const addHandler = (keyName, keyFrag, handlerExp) => {
|
|
1668
|
+
ensureHandlerGroup(keyName, keyFrag).handlers.push(handlerExp);
|
|
1669
|
+
};
|
|
1670
|
+
const getStaticPropKeyName = (prop) => {
|
|
1671
|
+
if (!prop.key.isStatic) return;
|
|
1672
|
+
const handlerModifierPostfix = prop.handlerModifiers && prop.handlerModifiers.options ? prop.handlerModifiers.options.map((m) => m.charAt(0).toUpperCase() + m.slice(1)).join("") : "";
|
|
1673
|
+
return (prop.handler ? (0, _vue_shared.toHandlerKey)((0, _vue_shared.camelize)(prop.key.content)) : prop.key.content) + handlerModifierPostfix;
|
|
1674
|
+
};
|
|
1675
|
+
for (const prop of props) {
|
|
1676
|
+
if (prop.handler) {
|
|
1677
|
+
const keyName = getStaticPropKeyName(prop);
|
|
1678
|
+
if (!keyName) {
|
|
1679
|
+
args.push(genProp(prop, context, true));
|
|
1680
|
+
continue;
|
|
1681
|
+
}
|
|
1682
|
+
const keyFrag = genPropKey(prop, context);
|
|
1683
|
+
if (!!prop.handlerModifiers && (prop.handlerModifiers.keys.length > 0 || prop.handlerModifiers.nonKeys.length > 0) || prop.values.length <= 1) addHandler(keyName, keyFrag, genEventHandler(context, prop.values, prop.handlerModifiers, true, false));
|
|
1684
|
+
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, true, false));
|
|
1685
|
+
continue;
|
|
1686
|
+
}
|
|
1687
|
+
args.push(genProp(prop, context, true));
|
|
1688
|
+
if (prop.model) {
|
|
1689
|
+
if (prop.key.isStatic) {
|
|
1690
|
+
const keyName = `onUpdate:${(0, _vue_shared.camelize)(prop.key.content)}`;
|
|
1691
|
+
addHandler(keyName, [JSON.stringify(keyName)], genModelHandler(prop.values[0], context));
|
|
1692
|
+
} else {
|
|
1693
|
+
const keyFrag = [
|
|
1694
|
+
"[\"onUpdate:\" + ",
|
|
1695
|
+
...genExpression(prop.key, context),
|
|
1696
|
+
"]"
|
|
1697
|
+
];
|
|
1698
|
+
args.push([
|
|
1699
|
+
...keyFrag,
|
|
1700
|
+
": () => ",
|
|
1701
|
+
...genModelHandler(prop.values[0], context)
|
|
1702
|
+
]);
|
|
1703
|
+
}
|
|
1704
|
+
const { key, modelModifiers } = prop;
|
|
1705
|
+
if (modelModifiers && modelModifiers.length) {
|
|
1706
|
+
const modifiersKey = key.isStatic ? [(0, _vue_shared.getModifierPropName)(key.content)] : [
|
|
1707
|
+
"[",
|
|
1708
|
+
...genExpression(key, context),
|
|
1709
|
+
" + \"Modifiers\"]"
|
|
1710
|
+
];
|
|
1711
|
+
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
1712
|
+
args.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
for (const group of handlerGroups.values()) {
|
|
1717
|
+
const handlerValue = group.handlers.length > 1 ? genMulti(DELIMITERS_ARRAY_NEWLINE, ...group.handlers) : group.handlers[0];
|
|
1718
|
+
args[group.index] = [
|
|
1719
|
+
...group.keyFrag,
|
|
1720
|
+
": () => ",
|
|
1721
|
+
...handlerValue
|
|
1722
|
+
];
|
|
1723
|
+
}
|
|
1724
|
+
if (dynamicProps) args.push([`$: `, ...dynamicProps]);
|
|
1725
|
+
return genMulti(args.length > 1 ? DELIMITERS_OBJECT_NEWLINE : DELIMITERS_OBJECT, ...args);
|
|
1726
|
+
}
|
|
1727
|
+
function genDynamicProps(props, context) {
|
|
1728
|
+
const { helper } = context;
|
|
1729
|
+
const frags = [];
|
|
1730
|
+
for (const p of props) {
|
|
1731
|
+
let expr;
|
|
1732
|
+
if ((0, _vue_shared.isArray)(p)) {
|
|
1733
|
+
if (p.length) frags.push(genStaticProps(p, context));
|
|
1734
|
+
continue;
|
|
1735
|
+
} else if (p.kind === 1) if (p.model) {
|
|
1736
|
+
const entries = [genProp(p, context)];
|
|
1737
|
+
const updateKey = p.key.isStatic ? [JSON.stringify(`onUpdate:${(0, _vue_shared.camelize)(p.key.content)}`)] : [
|
|
1738
|
+
"[\"onUpdate:\" + ",
|
|
1739
|
+
...genExpression(p.key, context),
|
|
1740
|
+
"]"
|
|
1741
|
+
];
|
|
1742
|
+
entries.push([
|
|
1743
|
+
...updateKey,
|
|
1744
|
+
": () => ",
|
|
1745
|
+
...genModelHandler(p.values[0], context)
|
|
1746
|
+
]);
|
|
1747
|
+
const { modelModifiers } = p;
|
|
1748
|
+
if (modelModifiers && modelModifiers.length) {
|
|
1749
|
+
const modifiersKey = p.key.isStatic ? [(0, _vue_shared.getModifierPropName)(p.key.content)] : [
|
|
1750
|
+
"[",
|
|
1751
|
+
...genExpression(p.key, context),
|
|
1752
|
+
" + \"Modifiers\"]"
|
|
1753
|
+
];
|
|
1754
|
+
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
1755
|
+
entries.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
|
|
1756
|
+
}
|
|
1757
|
+
expr = genMulti(DELIMITERS_OBJECT_NEWLINE, ...entries);
|
|
1758
|
+
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context));
|
|
1759
|
+
else {
|
|
1760
|
+
expr = genExpression(p.value, context);
|
|
1761
|
+
if (p.handler) expr = genCall(helper("toHandlers"), expr);
|
|
1762
|
+
}
|
|
1763
|
+
frags.push([
|
|
1764
|
+
"() => (",
|
|
1765
|
+
...expr,
|
|
1766
|
+
")"
|
|
1767
|
+
]);
|
|
1768
|
+
}
|
|
1769
|
+
if (frags.length) return genMulti(DELIMITERS_ARRAY_NEWLINE, ...frags);
|
|
1770
|
+
}
|
|
1771
|
+
function genProp(prop, context, isStatic) {
|
|
1772
|
+
const values = genPropValue(prop.values, context);
|
|
1773
|
+
return [
|
|
1774
|
+
...genPropKey(prop, context),
|
|
1775
|
+
": ",
|
|
1776
|
+
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, true, true) : isStatic ? [
|
|
1777
|
+
"() => (",
|
|
1778
|
+
...values,
|
|
1779
|
+
")"
|
|
1780
|
+
] : values
|
|
1781
|
+
];
|
|
1782
|
+
}
|
|
1783
|
+
function genRawSlots(slots, context) {
|
|
1784
|
+
if (!slots.length) return;
|
|
1785
|
+
const staticSlots = slots[0];
|
|
1786
|
+
if (staticSlots.slotType === 0) return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
|
|
1787
|
+
else return genStaticSlots({
|
|
1788
|
+
slotType: 0,
|
|
1789
|
+
slots: {}
|
|
1790
|
+
}, context, slots);
|
|
1791
|
+
}
|
|
1792
|
+
function genStaticSlots({ slots }, context, dynamicSlots) {
|
|
1793
|
+
const args = Object.keys(slots).map((name) => [`${JSON.stringify(name)}: `, ...genSlotBlockWithProps(slots[name], context)]);
|
|
1794
|
+
if (dynamicSlots) args.push([`$: `, ...genDynamicSlots(dynamicSlots, context)]);
|
|
1795
|
+
return genMulti(DELIMITERS_OBJECT_NEWLINE, ...args);
|
|
1796
|
+
}
|
|
1797
|
+
function genDynamicSlots(slots, context) {
|
|
1798
|
+
return genMulti(DELIMITERS_ARRAY_NEWLINE, ...slots.map((slot) => slot.slotType === 0 ? genStaticSlots(slot, context) : slot.slotType === 4 ? slot.slots.content : genDynamicSlot(slot, context, true)));
|
|
1799
|
+
}
|
|
1800
|
+
function genDynamicSlot(slot, context, withFunction = false) {
|
|
1801
|
+
let frag;
|
|
1802
|
+
switch (slot.slotType) {
|
|
1803
|
+
case 1:
|
|
1804
|
+
frag = genBasicDynamicSlot(slot, context);
|
|
1805
|
+
break;
|
|
1806
|
+
case 2:
|
|
1807
|
+
frag = genLoopSlot(slot, context);
|
|
1808
|
+
break;
|
|
1809
|
+
case 3:
|
|
1810
|
+
frag = genConditionalSlot(slot, context);
|
|
1811
|
+
break;
|
|
1812
|
+
}
|
|
1813
|
+
return withFunction ? [
|
|
1814
|
+
"() => (",
|
|
1815
|
+
...frag,
|
|
1816
|
+
")"
|
|
1817
|
+
] : frag;
|
|
1818
|
+
}
|
|
1819
|
+
function genBasicDynamicSlot(slot, context) {
|
|
1820
|
+
const { name, fn } = slot;
|
|
1821
|
+
return genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...genExpression(name, context)], ["fn: ", ...genSlotBlockWithProps(fn, context)]);
|
|
1822
|
+
}
|
|
1823
|
+
function genLoopSlot(slot, context) {
|
|
1824
|
+
const { name, fn, loop } = slot;
|
|
1825
|
+
const { value, key, index, source } = loop;
|
|
1826
|
+
const rawValue = value && value.content;
|
|
1827
|
+
const rawKey = key && key.content;
|
|
1828
|
+
const rawIndex = index && index.content;
|
|
1829
|
+
const idMap = {};
|
|
1830
|
+
if (rawValue) idMap[rawValue] = rawValue;
|
|
1831
|
+
if (rawKey) idMap[rawKey] = rawKey;
|
|
1832
|
+
if (rawIndex) idMap[rawIndex] = rawIndex;
|
|
1833
|
+
const slotExpr = genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...context.withId(() => genExpression(name, context), idMap)], ["fn: ", ...context.withId(() => genSlotBlockWithProps(fn, context), idMap)]);
|
|
1834
|
+
return [...genCall(context.helper("createForSlots"), genExpression(source, context), [
|
|
1835
|
+
...genMulti([
|
|
1836
|
+
"(",
|
|
1837
|
+
")",
|
|
1838
|
+
", "
|
|
1839
|
+
], rawValue ? rawValue : rawKey || rawIndex ? "_" : void 0, rawKey ? rawKey : rawIndex ? "__" : void 0, rawIndex),
|
|
1840
|
+
" => (",
|
|
1841
|
+
...slotExpr,
|
|
1842
|
+
")"
|
|
1843
|
+
])];
|
|
1844
|
+
}
|
|
1845
|
+
function genConditionalSlot(slot, context) {
|
|
1846
|
+
const { condition, positive, negative } = slot;
|
|
1847
|
+
return [
|
|
1848
|
+
...genExpression(condition, context),
|
|
1849
|
+
INDENT_START,
|
|
1850
|
+
NEWLINE,
|
|
1851
|
+
"? ",
|
|
1852
|
+
...genDynamicSlot(positive, context),
|
|
1853
|
+
NEWLINE,
|
|
1854
|
+
": ",
|
|
1855
|
+
...negative ? [...genDynamicSlot(negative, context)] : ["void 0"],
|
|
1856
|
+
INDENT_END
|
|
1857
|
+
];
|
|
1858
|
+
}
|
|
1859
|
+
function genSlotBlockWithProps(oper, context) {
|
|
1860
|
+
let propsName;
|
|
1861
|
+
let exitScope;
|
|
1862
|
+
let depth;
|
|
1863
|
+
const { props, key, node } = oper;
|
|
1864
|
+
const idToPathMap = props ? parseValueDestructure(props, context) : /* @__PURE__ */ new Map();
|
|
1865
|
+
if (props) if (props.ast) {
|
|
1866
|
+
[depth, exitScope] = context.enterScope();
|
|
1867
|
+
propsName = `_slotProps${depth}`;
|
|
1868
|
+
} else propsName = props.content;
|
|
1869
|
+
const idMap = idToPathMap.size ? buildDestructureIdMap(idToPathMap, propsName || "", context.options.expressionPlugins) : {};
|
|
1870
|
+
if (propsName) idMap[propsName] = null;
|
|
1871
|
+
let blockFn = context.withId(() => genBlock(oper, context, propsName ? [propsName] : []), idMap);
|
|
1872
|
+
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
|
+
if (node.type === 1) {
|
|
1884
|
+
if (needsVaporCtx(oper)) blockFn = [
|
|
1885
|
+
`${context.helper("withVaporCtx")}(`,
|
|
1886
|
+
...blockFn,
|
|
1887
|
+
`)`
|
|
1888
|
+
];
|
|
1889
|
+
}
|
|
1890
|
+
return blockFn;
|
|
1891
|
+
}
|
|
1892
|
+
/**
|
|
1893
|
+
* Check if a slot block needs withVaporCtx wrapper.
|
|
1894
|
+
* Returns true if the block contains:
|
|
1895
|
+
* - Component creation (needs scopeId inheritance)
|
|
1896
|
+
* - Slot outlet (needs rawSlots from slot owner)
|
|
1897
|
+
*/
|
|
1898
|
+
function needsVaporCtx(block) {
|
|
1899
|
+
return hasComponentOrSlotInBlock(block);
|
|
1900
|
+
}
|
|
1901
|
+
function hasComponentOrSlotInBlock(block) {
|
|
1902
|
+
if (hasComponentOrSlotInOperations(block.operation)) return true;
|
|
1903
|
+
return hasComponentOrSlotInDynamic(block.dynamic);
|
|
1904
|
+
}
|
|
1905
|
+
function hasComponentOrSlotInDynamic(dynamic) {
|
|
1906
|
+
if (dynamic.operation) {
|
|
1907
|
+
const type = dynamic.operation.type;
|
|
1908
|
+
if (type === 11 || type === 12) return true;
|
|
1909
|
+
if (type === 14) {
|
|
1910
|
+
if (hasComponentOrSlotInIf(dynamic.operation)) return true;
|
|
1911
|
+
}
|
|
1912
|
+
if (type === 15) {
|
|
1913
|
+
if (hasComponentOrSlotInBlock(dynamic.operation.render)) return true;
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
for (const child of dynamic.children) if (hasComponentOrSlotInDynamic(child)) return true;
|
|
1917
|
+
return false;
|
|
1918
|
+
}
|
|
1919
|
+
function hasComponentOrSlotInOperations(operations) {
|
|
1920
|
+
for (const op of operations) switch (op.type) {
|
|
1921
|
+
case 11:
|
|
1922
|
+
case 12: return true;
|
|
1923
|
+
case 14:
|
|
1924
|
+
if (hasComponentOrSlotInIf(op)) return true;
|
|
1925
|
+
break;
|
|
1926
|
+
case 15:
|
|
1927
|
+
if (hasComponentOrSlotInBlock(op.render)) return true;
|
|
1928
|
+
break;
|
|
1929
|
+
}
|
|
1930
|
+
return false;
|
|
1931
|
+
}
|
|
1932
|
+
function hasComponentOrSlotInIf(node) {
|
|
1933
|
+
if (hasComponentOrSlotInBlock(node.positive)) return true;
|
|
1934
|
+
if (node.negative) if ("positive" in node.negative) return hasComponentOrSlotInIf(node.negative);
|
|
1935
|
+
else return hasComponentOrSlotInBlock(node.negative);
|
|
1936
|
+
return false;
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
//#endregion
|
|
1940
|
+
//#region packages/compiler-vapor/src/generators/slotOutlet.ts
|
|
1941
|
+
function genSlotOutlet(oper, context) {
|
|
1942
|
+
const { helper } = context;
|
|
1943
|
+
const { id, name, fallback, noSlotted, once } = oper;
|
|
1944
|
+
const [frag, push] = buildCodeFragment();
|
|
1945
|
+
const nameExpr = name.isStatic ? genExpression(name, context) : [
|
|
1946
|
+
"() => (",
|
|
1947
|
+
...genExpression(name, context),
|
|
1948
|
+
")"
|
|
1949
|
+
];
|
|
1950
|
+
let fallbackArg;
|
|
1951
|
+
if (fallback) fallbackArg = genBlock(fallback, context);
|
|
1952
|
+
push(NEWLINE, `const n${id} = `, ...genCall(helper("createSlot"), nameExpr, genRawProps(oper.props, context) || "null", fallbackArg, noSlotted && "true", once && "true"));
|
|
1953
|
+
return frag;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
//#endregion
|
|
1957
|
+
//#region packages/compiler-vapor/src/generators/operation.ts
|
|
1958
|
+
function genOperations(opers, context) {
|
|
1959
|
+
const [frag, push] = buildCodeFragment();
|
|
1960
|
+
for (const operation of opers) push(...genOperationWithInsertionState(operation, context));
|
|
1961
|
+
return frag;
|
|
1962
|
+
}
|
|
1963
|
+
function genOperationWithInsertionState(oper, context) {
|
|
1964
|
+
const [frag, push] = buildCodeFragment();
|
|
1965
|
+
if (isBlockOperation(oper) && oper.parent) push(...genInsertionState(oper, context));
|
|
1966
|
+
push(...genOperation(oper, context));
|
|
1967
|
+
return frag;
|
|
1968
|
+
}
|
|
1969
|
+
function genOperation(oper, context) {
|
|
1970
|
+
switch (oper.type) {
|
|
1971
|
+
case 2: return genSetProp(oper, context);
|
|
1972
|
+
case 3: return genDynamicProps$1(oper, context);
|
|
1973
|
+
case 4: return genSetText(oper, context);
|
|
1974
|
+
case 5: return genSetEvent(oper, context);
|
|
1975
|
+
case 6: return genSetDynamicEvents(oper, context);
|
|
1976
|
+
case 7: return genSetHtml(oper, context);
|
|
1977
|
+
case 8: return genSetTemplateRef(oper, context);
|
|
1978
|
+
case 9: return genInsertNode(oper, context);
|
|
1979
|
+
case 10: return genPrependNode(oper, context);
|
|
1980
|
+
case 14: return genIf(oper, context);
|
|
1981
|
+
case 15: return genFor(oper, context);
|
|
1982
|
+
case 11: return genCreateComponent(oper, context);
|
|
1983
|
+
case 12: return genSlotOutlet(oper, context);
|
|
1984
|
+
case 13: return genBuiltinDirective(oper, context);
|
|
1985
|
+
case 16: return genGetTextChild(oper, context);
|
|
1986
|
+
case 17: return [];
|
|
1987
|
+
case 18: return [];
|
|
1988
|
+
default:
|
|
1989
|
+
const exhaustiveCheck = oper;
|
|
1990
|
+
throw new Error(`Unhandled operation type in genOperation: ${exhaustiveCheck}`);
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
function genEffects(effects, context, genExtraFrag) {
|
|
1994
|
+
const { helper } = context;
|
|
1995
|
+
const expressions = effects.flatMap((effect) => effect.expressions);
|
|
1996
|
+
const [frag, push, unshift] = buildCodeFragment();
|
|
1997
|
+
const shouldDeclare = genExtraFrag === void 0;
|
|
1998
|
+
let operationsCount = 0;
|
|
1999
|
+
const { ids, frag: declarationFrags, varNames } = processExpressions(context, expressions, shouldDeclare);
|
|
2000
|
+
push(...declarationFrags);
|
|
2001
|
+
for (let i = 0; i < effects.length; i++) {
|
|
2002
|
+
const effect = effects[i];
|
|
2003
|
+
operationsCount += effect.operations.length;
|
|
2004
|
+
const frags = context.withId(() => genEffect(effect, context), ids);
|
|
2005
|
+
i > 0 && push(NEWLINE);
|
|
2006
|
+
if (frag[frag.length - 1] === ")" && frags[0] === "(") push(";");
|
|
2007
|
+
push(...frags);
|
|
2008
|
+
}
|
|
2009
|
+
if (frag.filter((frag) => frag === NEWLINE).length > 1 || operationsCount > 1 || declarationFrags.length > 0) {
|
|
2010
|
+
unshift(`{`, INDENT_START, NEWLINE);
|
|
2011
|
+
push(INDENT_END, NEWLINE, "}");
|
|
2012
|
+
if (!effects.length) unshift(NEWLINE);
|
|
2013
|
+
}
|
|
2014
|
+
if (effects.length) {
|
|
2015
|
+
unshift(NEWLINE, `${helper("renderEffect")}(() => `);
|
|
2016
|
+
push(`)`);
|
|
2017
|
+
}
|
|
2018
|
+
if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
|
|
2019
|
+
if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
|
|
2020
|
+
return frag;
|
|
2021
|
+
}
|
|
2022
|
+
function genEffect({ operations }, context) {
|
|
2023
|
+
const [frag, push] = buildCodeFragment();
|
|
2024
|
+
const operationsExps = genOperations(operations, context);
|
|
2025
|
+
if (operationsExps.filter((frag) => frag === NEWLINE).length > 1) push(...operationsExps);
|
|
2026
|
+
else push(...operationsExps.filter((frag) => frag !== NEWLINE));
|
|
2027
|
+
return frag;
|
|
2028
|
+
}
|
|
2029
|
+
function genInsertionState(operation, context) {
|
|
2030
|
+
const { parent, anchor, logicalIndex, append, last } = operation;
|
|
2031
|
+
return [NEWLINE, ...genCall(context.helper("setInsertionState"), `n${parent}`, anchor == null ? void 0 : anchor === -1 ? `0` : append ? "null" : `n${anchor}`, logicalIndex !== void 0 ? String(logicalIndex) : void 0, last && "true")];
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
//#endregion
|
|
2035
|
+
//#region packages/compiler-vapor/src/generators/template.ts
|
|
2036
|
+
function genTemplates(templates, rootIndexes, context) {
|
|
2037
|
+
const result = [];
|
|
2038
|
+
let i = 0;
|
|
2039
|
+
templates.forEach((ns, template) => {
|
|
2040
|
+
result.push(`const ${context.tName(i)} = ${context.helper("template")}(${JSON.stringify(template).replace(IMPORT_EXPR_RE, `" + $1 + "`)}${rootIndexes.has(i) ? ", true" : ns ? ", false" : ""}${ns ? `, ${ns}` : ""})\n`);
|
|
2041
|
+
i++;
|
|
2042
|
+
});
|
|
2043
|
+
return result.join("");
|
|
2044
|
+
}
|
|
2045
|
+
function genSelf(dynamic, context) {
|
|
2046
|
+
const [frag, push] = buildCodeFragment();
|
|
2047
|
+
const { id, template, operation, hasDynamicChild } = dynamic;
|
|
2048
|
+
if (id !== void 0 && template !== void 0) {
|
|
2049
|
+
push(NEWLINE, `const n${id} = ${context.tName(template)}()`);
|
|
2050
|
+
push(...genDirectivesForElement(id, context));
|
|
2051
|
+
}
|
|
2052
|
+
if (operation) push(...genOperationWithInsertionState(operation, context));
|
|
2053
|
+
if (hasDynamicChild) push(...genChildren(dynamic, context, push, `n${id}`));
|
|
2054
|
+
return frag;
|
|
2055
|
+
}
|
|
2056
|
+
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`) {
|
|
2057
|
+
const { helper } = context;
|
|
2058
|
+
const [frag, push] = buildCodeFragment();
|
|
2059
|
+
const { children } = dynamic;
|
|
2060
|
+
let offset = 0;
|
|
2061
|
+
let prev;
|
|
2062
|
+
for (const [index, child] of children.entries()) {
|
|
2063
|
+
if (child.flags & 2) offset--;
|
|
2064
|
+
if (child.flags & 4 && child.template != null) {
|
|
2065
|
+
push(...genSelf(child, context));
|
|
2066
|
+
continue;
|
|
2067
|
+
}
|
|
2068
|
+
const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
|
|
2069
|
+
if (id === void 0 && !child.hasDynamicChild) {
|
|
2070
|
+
push(...genSelf(child, context));
|
|
2071
|
+
continue;
|
|
2072
|
+
}
|
|
2073
|
+
const elementIndex = index + offset;
|
|
2074
|
+
const logicalIndex = child.logicalIndex !== void 0 ? String(child.logicalIndex) : void 0;
|
|
2075
|
+
const variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
|
|
2076
|
+
pushBlock(NEWLINE, `const ${variable} = `);
|
|
2077
|
+
if (prev) if (elementIndex - prev[1] === 1) pushBlock(...genCall(helper("next"), prev[0], logicalIndex));
|
|
2078
|
+
else pushBlock(...genCall(helper("nthChild"), from, String(elementIndex), logicalIndex));
|
|
2079
|
+
else if (elementIndex === 0) pushBlock(...genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0));
|
|
2080
|
+
else {
|
|
2081
|
+
let init = genCall(helper("child"), from);
|
|
2082
|
+
if (elementIndex === 1) init = genCall(helper("next"), init, logicalIndex);
|
|
2083
|
+
else if (elementIndex > 1) init = genCall(helper("nthChild"), from, String(elementIndex), logicalIndex);
|
|
2084
|
+
pushBlock(...init);
|
|
2085
|
+
}
|
|
2086
|
+
if (id === child.anchor && !child.hasDynamicChild) push(...genSelf(child, context));
|
|
2087
|
+
if (id !== void 0) push(...genDirectivesForElement(id, context));
|
|
2088
|
+
prev = [variable, elementIndex];
|
|
2089
|
+
push(...genChildren(child, context, pushBlock, variable));
|
|
2090
|
+
}
|
|
2091
|
+
return frag;
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
//#endregion
|
|
2095
|
+
//#region packages/compiler-vapor/src/generators/block.ts
|
|
2096
|
+
function genBlock(oper, context, args = [], root) {
|
|
2097
|
+
return [
|
|
2098
|
+
"(",
|
|
2099
|
+
...args,
|
|
2100
|
+
") => {",
|
|
2101
|
+
INDENT_START,
|
|
2102
|
+
...genBlockContent(oper, context, root),
|
|
2103
|
+
INDENT_END,
|
|
2104
|
+
NEWLINE,
|
|
2105
|
+
"}"
|
|
2106
|
+
];
|
|
2107
|
+
}
|
|
2108
|
+
function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
2109
|
+
const [frag, push] = buildCodeFragment();
|
|
2110
|
+
const { dynamic, effect, operation, returns } = block;
|
|
2111
|
+
const resetBlock = context.enterBlock(block);
|
|
2112
|
+
if (root) {
|
|
2113
|
+
for (let name of context.ir.component) {
|
|
2114
|
+
const id = (0, _vue_compiler_dom.toValidAssetId)(name, "component");
|
|
2115
|
+
const maybeSelfReference = name.endsWith("__self");
|
|
2116
|
+
if (maybeSelfReference) name = name.slice(0, -6);
|
|
2117
|
+
push(NEWLINE, `const ${id} = `, ...genCall(context.helper("resolveComponent"), JSON.stringify(name), maybeSelfReference ? "true" : void 0));
|
|
2118
|
+
}
|
|
2119
|
+
genResolveAssets("directive", "resolveDirective");
|
|
2120
|
+
}
|
|
2121
|
+
for (const child of dynamic.children) push(...genSelf(child, context));
|
|
2122
|
+
for (const child of dynamic.children) if (!child.hasDynamicChild) push(...genChildren(child, context, push, `n${child.id}`));
|
|
2123
|
+
push(...genOperations(operation, context));
|
|
2124
|
+
push(...genEffects(effect, context, genEffectsExtraFrag));
|
|
2125
|
+
if (root && context.ir.hasDeferredVShow) push(NEWLINE, `deferredApplyVShows.forEach(fn => fn())`);
|
|
2126
|
+
push(NEWLINE, `return `);
|
|
2127
|
+
const returnNodes = returns.map((n) => `n${n}`);
|
|
2128
|
+
push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"]);
|
|
2129
|
+
resetBlock();
|
|
2130
|
+
return frag;
|
|
2131
|
+
function genResolveAssets(kind, helper) {
|
|
2132
|
+
for (const name of context.ir[kind]) push(NEWLINE, `const ${(0, _vue_compiler_dom.toValidAssetId)(name, kind)} = `, ...genCall(context.helper(helper), JSON.stringify(name)));
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
//#endregion
|
|
2137
|
+
//#region packages/compiler-vapor/src/generate.ts
|
|
2138
|
+
const idWithTrailingDigitsRE = /^([A-Za-z_$][\w$]*)(\d+)$/;
|
|
2139
|
+
var CodegenContext = class {
|
|
2140
|
+
withId(fn, map) {
|
|
2141
|
+
const { identifiers } = this;
|
|
2142
|
+
const ids = Object.keys(map);
|
|
2143
|
+
for (const id of ids) {
|
|
2144
|
+
identifiers[id] || (identifiers[id] = []);
|
|
2145
|
+
identifiers[id].unshift(map[id] || id);
|
|
2146
|
+
}
|
|
2147
|
+
const ret = fn();
|
|
2148
|
+
ids.forEach((id) => (0, _vue_shared.remove)(identifiers[id], map[id] || id));
|
|
2149
|
+
return ret;
|
|
2150
|
+
}
|
|
2151
|
+
enterBlock(block) {
|
|
2152
|
+
const parent = this.block;
|
|
2153
|
+
this.block = block;
|
|
2154
|
+
return () => this.block = parent;
|
|
2155
|
+
}
|
|
2156
|
+
enterScope() {
|
|
2157
|
+
return [this.scopeLevel++, () => this.scopeLevel--];
|
|
2158
|
+
}
|
|
2159
|
+
initNextIdMap() {
|
|
2160
|
+
if (this.bindingNames.size === 0) return;
|
|
2161
|
+
const map = /* @__PURE__ */ new Map();
|
|
2162
|
+
for (const name of this.bindingNames) {
|
|
2163
|
+
const m = idWithTrailingDigitsRE.exec(name);
|
|
2164
|
+
if (!m) continue;
|
|
2165
|
+
const prefix = m[1];
|
|
2166
|
+
const num = Number(m[2]);
|
|
2167
|
+
let set = map.get(prefix);
|
|
2168
|
+
if (!set) map.set(prefix, set = /* @__PURE__ */ new Set());
|
|
2169
|
+
set.add(num);
|
|
2170
|
+
}
|
|
2171
|
+
for (const [prefix, nums] of map) this.nextIdMap.set(prefix, buildNextIdMap(nums));
|
|
2172
|
+
}
|
|
2173
|
+
tName(i) {
|
|
2174
|
+
let name = this.templateVars.get(i);
|
|
2175
|
+
if (name) return name;
|
|
2176
|
+
const map = this.nextIdMap.get("t");
|
|
2177
|
+
let lastId = this.lastIdMap.get("t") || -1;
|
|
2178
|
+
for (let j = this.lastTIndex + 1; j <= i; j++) this.templateVars.set(j, name = `t${lastId = getNextId(map, Math.max(j, lastId + 1))}`);
|
|
2179
|
+
this.lastIdMap.set("t", lastId);
|
|
2180
|
+
this.lastTIndex = i;
|
|
2181
|
+
return name;
|
|
2182
|
+
}
|
|
2183
|
+
pName(i) {
|
|
2184
|
+
const map = this.nextIdMap.get("p");
|
|
2185
|
+
let lastId = this.lastIdMap.get("p") || -1;
|
|
2186
|
+
this.lastIdMap.set("p", lastId = getNextId(map, Math.max(i, lastId + 1)));
|
|
2187
|
+
return `p${lastId}`;
|
|
2188
|
+
}
|
|
2189
|
+
constructor(ir, options) {
|
|
2190
|
+
this.ir = ir;
|
|
2191
|
+
this.bindingNames = /* @__PURE__ */ new Set();
|
|
2192
|
+
this.helpers = /* @__PURE__ */ new Map();
|
|
2193
|
+
this.helper = (name) => {
|
|
2194
|
+
if (this.helpers.has(name)) return this.helpers.get(name);
|
|
2195
|
+
const base = `_${name}`;
|
|
2196
|
+
if (this.bindingNames.size === 0 || !this.bindingNames.has(base)) {
|
|
2197
|
+
this.helpers.set(name, base);
|
|
2198
|
+
return base;
|
|
2199
|
+
}
|
|
2200
|
+
const alias = `${base}${getNextId(this.nextIdMap.get(base), 1)}`;
|
|
2201
|
+
this.helpers.set(name, alias);
|
|
2202
|
+
return alias;
|
|
2203
|
+
};
|
|
2204
|
+
this.delegates = /* @__PURE__ */ new Set();
|
|
2205
|
+
this.identifiers = Object.create(null);
|
|
2206
|
+
this.seenInlineHandlerNames = Object.create(null);
|
|
2207
|
+
this.scopeLevel = 0;
|
|
2208
|
+
this.templateVars = /* @__PURE__ */ new Map();
|
|
2209
|
+
this.nextIdMap = /* @__PURE__ */ new Map();
|
|
2210
|
+
this.lastIdMap = /* @__PURE__ */ new Map();
|
|
2211
|
+
this.lastTIndex = -1;
|
|
2212
|
+
this.options = (0, _vue_shared.extend)({
|
|
2213
|
+
mode: "module",
|
|
2214
|
+
prefixIdentifiers: true,
|
|
2215
|
+
sourceMap: false,
|
|
2216
|
+
filename: `template.vue.html`,
|
|
2217
|
+
scopeId: null,
|
|
2218
|
+
runtimeGlobalName: `Vue`,
|
|
2219
|
+
runtimeModuleName: `vue`,
|
|
2220
|
+
ssrRuntimeModuleName: "vue/server-renderer",
|
|
2221
|
+
ssr: false,
|
|
2222
|
+
isTS: false,
|
|
2223
|
+
inSSR: false,
|
|
2224
|
+
inline: false,
|
|
2225
|
+
bindingMetadata: {},
|
|
2226
|
+
expressionPlugins: []
|
|
2227
|
+
}, options);
|
|
2228
|
+
this.block = ir.block;
|
|
2229
|
+
this.bindingNames = new Set(this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []);
|
|
2230
|
+
this.initNextIdMap();
|
|
2231
|
+
}
|
|
2232
|
+
};
|
|
2233
|
+
function generate(ir, options = {}) {
|
|
2234
|
+
const [frag, push] = buildCodeFragment();
|
|
2235
|
+
const context = new CodegenContext(ir, options);
|
|
2236
|
+
const { inline, bindingMetadata } = options;
|
|
2237
|
+
const functionName = "render";
|
|
2238
|
+
const args = ["_ctx"];
|
|
2239
|
+
if (bindingMetadata && !inline) args.push("$props", "$emit", "$attrs", "$slots");
|
|
2240
|
+
const signature = (options.isTS ? args.map((arg) => `${arg}: any`) : args).join(", ");
|
|
2241
|
+
if (!inline) push(NEWLINE, `export function ${functionName}(${signature}) {`);
|
|
2242
|
+
push(INDENT_START);
|
|
2243
|
+
if (ir.hasTemplateRef) push(NEWLINE, `const ${setTemplateRefIdent} = ${context.helper("createTemplateRefSetter")}()`);
|
|
2244
|
+
if (ir.hasDeferredVShow) push(NEWLINE, `const deferredApplyVShows = []`);
|
|
2245
|
+
push(...genBlockContent(ir.block, context, true));
|
|
2246
|
+
push(INDENT_END, NEWLINE);
|
|
2247
|
+
if (!inline) push("}");
|
|
2248
|
+
const delegates = genDelegates(context);
|
|
2249
|
+
const templates = genTemplates(ir.template, ir.rootTemplateIndexes, context);
|
|
2250
|
+
const preamble = genHelperImports(context) + genAssetImports(context) + templates + delegates;
|
|
2251
|
+
const newlineCount = [...preamble].filter((c) => c === "\n").length;
|
|
2252
|
+
if (newlineCount && !inline) frag.unshift(...new Array(newlineCount).fill(LF));
|
|
2253
|
+
let [code, map] = codeFragmentToString(frag, context);
|
|
2254
|
+
if (!inline) code = preamble + code;
|
|
2255
|
+
return {
|
|
2256
|
+
code,
|
|
2257
|
+
ast: ir,
|
|
2258
|
+
preamble,
|
|
2259
|
+
map: map && map.toJSON(),
|
|
2260
|
+
helpers: new Set(Array.from(context.helpers.keys()))
|
|
2261
|
+
};
|
|
2262
|
+
}
|
|
2263
|
+
function genDelegates({ delegates, helper }) {
|
|
2264
|
+
return delegates.size ? genCall(helper("delegateEvents"), ...Array.from(delegates).map((v) => `"${v}"`)).join("") + "\n" : "";
|
|
2265
|
+
}
|
|
2266
|
+
function genHelperImports({ helpers, options }) {
|
|
2267
|
+
let imports = "";
|
|
2268
|
+
if (helpers.size) imports += `import { ${Array.from(helpers).map(([h, alias]) => `${h} as ${alias}`).join(", ")} } from '${options.runtimeModuleName}';\n`;
|
|
2269
|
+
return imports;
|
|
2270
|
+
}
|
|
2271
|
+
function genAssetImports({ ir }) {
|
|
2272
|
+
const assetImports = ir.node.imports;
|
|
2273
|
+
let imports = "";
|
|
2274
|
+
for (const assetImport of assetImports) {
|
|
2275
|
+
const name = assetImport.exp.content;
|
|
2276
|
+
imports += `import ${name} from '${assetImport.path}';\n`;
|
|
2277
|
+
}
|
|
2278
|
+
return imports;
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
//#endregion
|
|
2282
|
+
//#region packages/compiler-vapor/src/transforms/transformChildren.ts
|
|
2283
|
+
const transformChildren = (node, context) => {
|
|
2284
|
+
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
2285
|
+
if (!isFragment && node.type !== 1) return;
|
|
2286
|
+
for (const [i, child] of node.children.entries()) {
|
|
2287
|
+
const childContext = context.create(child, i);
|
|
2288
|
+
transformNode(childContext);
|
|
2289
|
+
const childDynamic = childContext.dynamic;
|
|
2290
|
+
if (isFragment) {
|
|
2291
|
+
childContext.reference();
|
|
2292
|
+
childContext.registerTemplate();
|
|
2293
|
+
if (!(childDynamic.flags & 2) || childDynamic.flags & 4) context.block.returns.push(childContext.dynamic.id);
|
|
2294
|
+
} else context.childrenTemplate.push(childContext.template);
|
|
2295
|
+
if (childDynamic.hasDynamicChild || childDynamic.id !== void 0 || childDynamic.flags & 2 || childDynamic.flags & 4) context.dynamic.hasDynamicChild = true;
|
|
2296
|
+
childDynamic.type = child.type;
|
|
2297
|
+
if (child.type === 1) childDynamic.tag = child.tag;
|
|
2298
|
+
context.dynamic.children[i] = childDynamic;
|
|
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
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
if (prevDynamics.length) registerInsertion(prevDynamics, context, dynamicCount + staticCount, true);
|
|
2332
|
+
if (lastInsertionChild && lastInsertionChild.operation) lastInsertionChild.operation.last = true;
|
|
2333
|
+
}
|
|
2334
|
+
function registerInsertion(dynamics, context, anchor, append) {
|
|
2335
|
+
for (const child of dynamics) {
|
|
2336
|
+
const logicalIndex = child.logicalIndex;
|
|
2337
|
+
if (child.template != null) context.registerOperation({
|
|
2338
|
+
type: 9,
|
|
2339
|
+
node: context.node,
|
|
2340
|
+
elements: dynamics.map((child) => child.id),
|
|
2341
|
+
parent: context.reference(),
|
|
2342
|
+
anchor: append ? void 0 : anchor
|
|
2343
|
+
});
|
|
2344
|
+
else if (child.operation && isBlockOperation(child.operation)) {
|
|
2345
|
+
child.operation.parent = context.reference();
|
|
2346
|
+
child.operation.anchor = anchor;
|
|
2347
|
+
child.operation.logicalIndex = logicalIndex;
|
|
2348
|
+
child.operation.append = append;
|
|
2349
|
+
}
|
|
2350
|
+
}
|
|
2351
|
+
}
|
|
2352
|
+
|
|
2353
|
+
//#endregion
|
|
2354
|
+
//#region packages/compiler-vapor/src/transforms/vOnce.ts
|
|
2355
|
+
const transformVOnce = (node, context) => {
|
|
2356
|
+
if (node.type === 1 && (0, _vue_compiler_dom.findDir)(node, "once", true)) context.inVOnce = true;
|
|
2357
|
+
};
|
|
2358
|
+
|
|
2359
|
+
//#endregion
|
|
2360
|
+
//#region packages/compiler-vapor/src/transforms/transformElement.ts
|
|
2361
|
+
const isReservedProp = /* @__PURE__ */ (0, _vue_shared.makeMap)(",key,ref,ref_for,ref_key,");
|
|
2362
|
+
const transformElement = (node, context) => {
|
|
2363
|
+
let effectIndex = context.block.effect.length;
|
|
2364
|
+
const getEffectIndex = () => effectIndex++;
|
|
2365
|
+
let operationIndex = context.block.operation.length;
|
|
2366
|
+
const getOperationIndex = () => operationIndex++;
|
|
2367
|
+
let parentSlots;
|
|
2368
|
+
if (node.type === 1 && (node.tagType === 1 || context.options.isCustomElement(node.tag))) {
|
|
2369
|
+
parentSlots = context.slots;
|
|
2370
|
+
context.slots = [];
|
|
2371
|
+
}
|
|
2372
|
+
return function postTransformElement() {
|
|
2373
|
+
({node} = context);
|
|
2374
|
+
if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1))) return;
|
|
2375
|
+
const isCustomElement = !!context.options.isCustomElement(node.tag);
|
|
2376
|
+
const isComponent = node.tagType === 1 || isCustomElement;
|
|
2377
|
+
const isDynamicComponent = isComponentTag(node.tag);
|
|
2378
|
+
const propsResult = buildProps(node, context, isComponent, isDynamicComponent, getEffectIndex);
|
|
2379
|
+
const singleRoot = isSingleRoot(context);
|
|
2380
|
+
if (isComponent) transformComponentElement(node, propsResult, singleRoot, context, isDynamicComponent, isCustomElement);
|
|
2381
|
+
else transformNativeElement(node, propsResult, singleRoot, context, getEffectIndex, context.root === context.effectiveParent || canOmitEndTag(node, context), getOperationIndex);
|
|
2382
|
+
if (parentSlots) context.slots = parentSlots;
|
|
2383
|
+
};
|
|
2384
|
+
};
|
|
2385
|
+
function canOmitEndTag(node, context) {
|
|
2386
|
+
const { block, parent } = context;
|
|
2387
|
+
if (!parent) return false;
|
|
2388
|
+
if (block !== parent.block) return true;
|
|
2389
|
+
if ((0, _vue_shared.isAlwaysCloseTag)(node.tag) && !context.isOnRightmostPath) return false;
|
|
2390
|
+
if ((0, _vue_shared.isFormattingTag)(node.tag) || parent.node.type === 1 && node.tag === parent.node.tag) return context.isOnRightmostPath;
|
|
2391
|
+
if ((0, _vue_shared.isBlockTag)(node.tag) && context.hasInlineAncestorNeedingClose) return false;
|
|
2392
|
+
return context.isLastEffectiveChild;
|
|
2393
|
+
}
|
|
2394
|
+
function isSingleRoot(context) {
|
|
2395
|
+
if (context.inVFor) return false;
|
|
2396
|
+
let { parent } = context;
|
|
2397
|
+
if (parent && !((0, _vue_compiler_dom.hasSingleChild)(parent.node) || (0, _vue_compiler_dom.isSingleIfBlock)(parent.node))) return false;
|
|
2398
|
+
while (parent && parent.parent && parent.node.type === 1 && parent.node.tagType === 3) {
|
|
2399
|
+
parent = parent.parent;
|
|
2400
|
+
if (!((0, _vue_compiler_dom.hasSingleChild)(parent.node) || (0, _vue_compiler_dom.isSingleIfBlock)(parent.node))) return false;
|
|
2401
|
+
}
|
|
2402
|
+
return context.root === parent;
|
|
2403
|
+
}
|
|
2404
|
+
function transformComponentElement(node, propsResult, singleRoot, context, isDynamicComponent, isCustomElement) {
|
|
2405
|
+
const dynamicComponent = isDynamicComponent ? resolveDynamicComponent(node) : void 0;
|
|
2406
|
+
let { tag } = node;
|
|
2407
|
+
let asset = true;
|
|
2408
|
+
if (!dynamicComponent && !isCustomElement) {
|
|
2409
|
+
const { isEasyComponent } = context.options;
|
|
2410
|
+
const isEasyCom = isEasyComponent && isEasyComponent(tag);
|
|
2411
|
+
if (!isEasyCom) {
|
|
2412
|
+
const fromSetup = resolveSetupReference(tag, context);
|
|
2413
|
+
if (fromSetup) {
|
|
2414
|
+
tag = fromSetup;
|
|
2415
|
+
asset = false;
|
|
2416
|
+
}
|
|
2417
|
+
const builtInTag = isBuiltInComponent(tag);
|
|
2418
|
+
if (builtInTag) {
|
|
2419
|
+
tag = builtInTag;
|
|
2420
|
+
asset = false;
|
|
2421
|
+
}
|
|
2422
|
+
const dotIndex = tag.indexOf(".");
|
|
2423
|
+
if (dotIndex > 0) {
|
|
2424
|
+
const ns = resolveSetupReference(tag.slice(0, dotIndex), context);
|
|
2425
|
+
if (ns) {
|
|
2426
|
+
tag = ns + tag.slice(dotIndex);
|
|
2427
|
+
asset = false;
|
|
2428
|
+
}
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
if (asset) {
|
|
2432
|
+
if (!isEasyCom && context.selfName && (0, _vue_shared.capitalize)((0, _vue_shared.camelize)(tag)) === context.selfName) tag += `__self`;
|
|
2433
|
+
context.component.add(tag);
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
context.dynamic.flags |= 6;
|
|
2437
|
+
context.dynamic.operation = {
|
|
2438
|
+
type: 11,
|
|
2439
|
+
node,
|
|
2440
|
+
id: context.reference(),
|
|
2441
|
+
tag,
|
|
2442
|
+
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
|
|
2443
|
+
asset,
|
|
2444
|
+
root: singleRoot,
|
|
2445
|
+
slots: [...context.slots],
|
|
2446
|
+
once: context.inVOnce,
|
|
2447
|
+
dynamic: dynamicComponent,
|
|
2448
|
+
isCustomElement
|
|
2449
|
+
};
|
|
2450
|
+
context.slots = [];
|
|
2451
|
+
}
|
|
2452
|
+
function resolveDynamicComponent(node) {
|
|
2453
|
+
const isProp = findProp$1(node, "is", false, true);
|
|
2454
|
+
if (!isProp) return;
|
|
2455
|
+
if (isProp.type === 6) return isProp.value && (0, _vue_compiler_dom.createSimpleExpression)(isProp.value.content, true);
|
|
2456
|
+
else return isProp.exp || (0, _vue_shared.extend)((0, _vue_compiler_dom.createSimpleExpression)(`is`, false, isProp.arg.loc), { ast: null });
|
|
2457
|
+
}
|
|
2458
|
+
function resolveSetupReference(name, context) {
|
|
2459
|
+
const bindings = context.options.bindingMetadata;
|
|
2460
|
+
if (!bindings || bindings.__isScriptSetup === false) return;
|
|
2461
|
+
const camelName = (0, _vue_shared.camelize)(name);
|
|
2462
|
+
const PascalName = (0, _vue_shared.capitalize)(camelName);
|
|
2463
|
+
return bindings[name] ? name : bindings[camelName] ? camelName : bindings[PascalName] ? PascalName : void 0;
|
|
2464
|
+
}
|
|
2465
|
+
const dynamicKeys = ["indeterminate"];
|
|
2466
|
+
const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
|
|
2467
|
+
function transformNativeElement(node, propsResult, singleRoot, context, getEffectIndex, omitEndTag, getOperationIndex) {
|
|
2468
|
+
const isDom2 = !!context.options.platform;
|
|
2469
|
+
if (isDom2) omitEndTag = false;
|
|
2470
|
+
const { tag } = node;
|
|
2471
|
+
const { scopeId } = context.options;
|
|
2472
|
+
let template = "";
|
|
2473
|
+
template += `<${tag}`;
|
|
2474
|
+
if (scopeId) template += ` ${scopeId}`;
|
|
2475
|
+
if (isDom2 && singleRoot) {
|
|
2476
|
+
template += ` gen-flag-flatten=""`;
|
|
2477
|
+
const rootElementTagName = context.options.rootElementTagName;
|
|
2478
|
+
if (rootElementTagName || context.options.genVueId) template += ` gen-vue-id=""`;
|
|
2479
|
+
if (rootElementTagName) template += ` custom-tag-name="${rootElementTagName}"`;
|
|
2480
|
+
}
|
|
2481
|
+
const dynamicProps = [];
|
|
2482
|
+
if (propsResult[0]) {
|
|
2483
|
+
const [, dynamicArgs, expressions] = propsResult;
|
|
2484
|
+
context.registerEffect(expressions, {
|
|
2485
|
+
type: 3,
|
|
2486
|
+
node,
|
|
2487
|
+
element: context.reference(),
|
|
2488
|
+
props: dynamicArgs,
|
|
2489
|
+
tag
|
|
2490
|
+
}, getEffectIndex);
|
|
2491
|
+
} else {
|
|
2492
|
+
const changeProps = [];
|
|
2493
|
+
if (isDom2) {
|
|
2494
|
+
const resolveChangeProp = context.options.resolveChangeProp;
|
|
2495
|
+
if (resolveChangeProp) changeProps.push(...resolveChangeProp(propsResult[1], context));
|
|
2496
|
+
const checkStaticProp = context.options.checkStaticProp;
|
|
2497
|
+
if (checkStaticProp) {
|
|
2498
|
+
const props = propsResult[1];
|
|
2499
|
+
const indicesToRemove = [];
|
|
2500
|
+
for (let i = 0; i < props.length; i++) {
|
|
2501
|
+
const { key, values } = props[i];
|
|
2502
|
+
if (key.content.startsWith("change:") || changeProps.includes(key.content)) continue;
|
|
2503
|
+
if (key.isStatic && values.length === 1 && !["class", "style"].includes(key.content)) {
|
|
2504
|
+
let endLoc = values[0].loc;
|
|
2505
|
+
if (endLoc === _vue_compiler_dom.locStub) endLoc = key.loc;
|
|
2506
|
+
if (!checkStaticProp(values.length === 1 && values[0].isStatic, key.content, values[0].content, {
|
|
2507
|
+
start: key.loc.start,
|
|
2508
|
+
end: endLoc.end
|
|
2509
|
+
}, node, context)) indicesToRemove.push(i);
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
for (let i = indicesToRemove.length - 1; i >= 0; i--) props.splice(indicesToRemove[i], 1);
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2515
|
+
let hasStaticStyle = false;
|
|
2516
|
+
let hasClass = false;
|
|
2517
|
+
let prevWasQuoted = false;
|
|
2518
|
+
for (const prop of propsResult[1]) {
|
|
2519
|
+
const { key, values } = prop;
|
|
2520
|
+
if (isDom2) {
|
|
2521
|
+
if (key.content.startsWith("change:")) {
|
|
2522
|
+
dynamicProps.push(key.content);
|
|
2523
|
+
values[0].isStatic = false;
|
|
2524
|
+
context.registerEffect(values, {
|
|
2525
|
+
type: 18,
|
|
2526
|
+
node,
|
|
2527
|
+
prop
|
|
2528
|
+
}, getEffectIndex);
|
|
2529
|
+
continue;
|
|
2530
|
+
}
|
|
2531
|
+
if (key.content === "class") hasClass = true;
|
|
2532
|
+
}
|
|
2533
|
+
if (context.imports.some((imported) => values[0].content.includes(imported.exp.content))) {
|
|
2534
|
+
if (!prevWasQuoted) template += ` `;
|
|
2535
|
+
template += `${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
|
|
2536
|
+
prevWasQuoted = true;
|
|
2537
|
+
} else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
2538
|
+
if (isDom2 && key.content === "style") {
|
|
2539
|
+
hasStaticStyle = true;
|
|
2540
|
+
const checkStaticStyle = context.options.checkStaticStyle;
|
|
2541
|
+
if (checkStaticStyle) checkStaticStyle(values[0].content, {
|
|
2542
|
+
start: key.loc.start,
|
|
2543
|
+
end: values[0].loc.end
|
|
2544
|
+
}, node, context);
|
|
2545
|
+
}
|
|
2546
|
+
if (isDom2 && (key.content === "class" || key.content === "hover-class" || key.content === "style" && context.options.disableStaticStyle)) {
|
|
2547
|
+
dynamicProps.push(key.content);
|
|
2548
|
+
context.registerEffect(values, {
|
|
2549
|
+
type: 2,
|
|
2550
|
+
node,
|
|
2551
|
+
element: context.reference(),
|
|
2552
|
+
prop,
|
|
2553
|
+
tag
|
|
2554
|
+
}, getEffectIndex, getOperationIndex);
|
|
2555
|
+
continue;
|
|
2556
|
+
}
|
|
2557
|
+
if (!prevWasQuoted) template += ` `;
|
|
2558
|
+
const value = values[0].content === "''" ? "" : values[0].content;
|
|
2559
|
+
template += key.content;
|
|
2560
|
+
if (value) template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${value.replace(/"/g, """)}"` : `=${value}`;
|
|
2561
|
+
else prevWasQuoted = false;
|
|
2562
|
+
} else {
|
|
2563
|
+
dynamicProps.push(key.content);
|
|
2564
|
+
context.registerEffect(values, {
|
|
2565
|
+
type: 2,
|
|
2566
|
+
node,
|
|
2567
|
+
isChangeProp: changeProps.includes(key.content),
|
|
2568
|
+
element: context.reference(),
|
|
2569
|
+
prop,
|
|
2570
|
+
tag
|
|
2571
|
+
}, getEffectIndex);
|
|
2572
|
+
}
|
|
2573
|
+
}
|
|
2574
|
+
if (hasStaticStyle && hasClass) template += ` ext:style`;
|
|
2575
|
+
}
|
|
2576
|
+
template += `>` + context.childrenTemplate.join("");
|
|
2577
|
+
if (!(0, _vue_shared.isVoidTag)(tag) && !omitEndTag) template += `</${tag}>`;
|
|
2578
|
+
if (singleRoot) context.ir.rootTemplateIndexes.add(context.ir.template.size);
|
|
2579
|
+
if (context.parent && context.parent.node.type === 1 && !(0, _vue_compiler_dom.isValidHTMLNesting)(context.parent.node.tag, tag)) {
|
|
2580
|
+
context.reference();
|
|
2581
|
+
context.dynamic.template = context.pushTemplate(template);
|
|
2582
|
+
context.dynamic.flags |= 6;
|
|
2583
|
+
} else context.template += template;
|
|
2584
|
+
}
|
|
2585
|
+
function buildProps(node, context, isComponent, isDynamicComponent, getEffectIndex) {
|
|
2586
|
+
const props = node.props;
|
|
2587
|
+
if (props.length === 0) return [false, []];
|
|
2588
|
+
const dynamicArgs = [];
|
|
2589
|
+
const dynamicExpr = [];
|
|
2590
|
+
let results = [];
|
|
2591
|
+
function pushMergeArg() {
|
|
2592
|
+
if (results.length) {
|
|
2593
|
+
dynamicArgs.push(dedupeProperties(results));
|
|
2594
|
+
results = [];
|
|
2595
|
+
}
|
|
2596
|
+
}
|
|
2597
|
+
for (const prop of props) {
|
|
2598
|
+
if (prop.type === 7 && !prop.arg) {
|
|
2599
|
+
if (prop.name === "bind") {
|
|
2600
|
+
if (prop.exp) {
|
|
2601
|
+
dynamicExpr.push(prop.exp);
|
|
2602
|
+
pushMergeArg();
|
|
2603
|
+
dynamicArgs.push({
|
|
2604
|
+
kind: 0,
|
|
2605
|
+
value: prop.exp
|
|
2606
|
+
});
|
|
2607
|
+
} else context.options.onError((0, _vue_compiler_dom.createCompilerError)(34, prop.loc));
|
|
2608
|
+
continue;
|
|
2609
|
+
} else if (prop.name === "on") {
|
|
2610
|
+
if (prop.exp) if (isComponent) {
|
|
2611
|
+
dynamicExpr.push(prop.exp);
|
|
2612
|
+
pushMergeArg();
|
|
2613
|
+
dynamicArgs.push({
|
|
2614
|
+
kind: 0,
|
|
2615
|
+
value: prop.exp,
|
|
2616
|
+
handler: true
|
|
2617
|
+
});
|
|
2618
|
+
} else context.registerEffect([prop.exp], {
|
|
2619
|
+
type: 6,
|
|
2620
|
+
node,
|
|
2621
|
+
element: context.reference(),
|
|
2622
|
+
event: prop.exp
|
|
2623
|
+
}, getEffectIndex);
|
|
2624
|
+
else context.options.onError((0, _vue_compiler_dom.createCompilerError)(35, prop.loc));
|
|
2625
|
+
continue;
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
if (isDynamicComponent && prop.type === 6 && prop.name === "is" || prop.type === 7 && prop.name === "bind" && (0, _vue_compiler_dom.isStaticArgOf)(prop.arg, "is")) continue;
|
|
2629
|
+
const result = transformProp(prop, node, context);
|
|
2630
|
+
if (result) {
|
|
2631
|
+
dynamicExpr.push(result.key, result.value);
|
|
2632
|
+
if (isComponent && !result.key.isStatic) {
|
|
2633
|
+
pushMergeArg();
|
|
2634
|
+
dynamicArgs.push((0, _vue_shared.extend)(resolveDirectiveResult(result), { kind: 1 }));
|
|
2635
|
+
} else results.push(result);
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
if (dynamicArgs.length || results.some(({ key }) => !key.isStatic)) {
|
|
2639
|
+
pushMergeArg();
|
|
2640
|
+
return [
|
|
2641
|
+
true,
|
|
2642
|
+
dynamicArgs,
|
|
2643
|
+
dynamicExpr
|
|
2644
|
+
];
|
|
2645
|
+
}
|
|
2646
|
+
return [false, dedupeProperties(results)];
|
|
2647
|
+
}
|
|
2648
|
+
function transformProp(prop, node, context) {
|
|
2649
|
+
let { name } = prop;
|
|
2650
|
+
if (prop.type === 6) {
|
|
2651
|
+
if (isReservedProp(name)) return;
|
|
2652
|
+
return {
|
|
2653
|
+
key: (0, _vue_compiler_dom.createSimpleExpression)(prop.name, true, prop.nameLoc),
|
|
2654
|
+
value: prop.value ? (0, _vue_compiler_dom.createSimpleExpression)(prop.value.content, true, prop.value.loc) : EMPTY_EXPRESSION
|
|
2655
|
+
};
|
|
2656
|
+
}
|
|
2657
|
+
const directiveTransform = context.options.directiveTransforms[name];
|
|
2658
|
+
if (directiveTransform) return directiveTransform(prop, node, context);
|
|
2659
|
+
if (!(0, _vue_shared.isBuiltInDirective)(name)) {
|
|
2660
|
+
const fromSetup = resolveSetupReference(`v-${name}`, context);
|
|
2661
|
+
if (fromSetup) name = fromSetup;
|
|
2662
|
+
else context.directive.add(name);
|
|
2663
|
+
context.registerOperation({
|
|
2664
|
+
type: 13,
|
|
2665
|
+
node,
|
|
2666
|
+
element: context.reference(),
|
|
2667
|
+
dir: prop,
|
|
2668
|
+
name,
|
|
2669
|
+
asset: !fromSetup
|
|
2670
|
+
});
|
|
2671
|
+
}
|
|
2672
|
+
}
|
|
2673
|
+
function dedupeProperties(results) {
|
|
2674
|
+
const knownProps = /* @__PURE__ */ new Map();
|
|
2675
|
+
const deduped = [];
|
|
2676
|
+
for (const result of results) {
|
|
2677
|
+
const prop = resolveDirectiveResult(result);
|
|
2678
|
+
if (!prop.key.isStatic) {
|
|
2679
|
+
deduped.push(prop);
|
|
2680
|
+
continue;
|
|
2681
|
+
}
|
|
2682
|
+
const name = prop.key.content;
|
|
2683
|
+
const existing = knownProps.get(name);
|
|
2684
|
+
if (existing && existing.handler === prop.handler) {
|
|
2685
|
+
if (name === "style" || name === "class" || prop.handler || name === "hover-class") mergePropValues(existing, prop);
|
|
2686
|
+
} else {
|
|
2687
|
+
knownProps.set(name, prop);
|
|
2688
|
+
deduped.push(prop);
|
|
2689
|
+
}
|
|
2690
|
+
}
|
|
2691
|
+
return deduped;
|
|
2692
|
+
}
|
|
2693
|
+
function resolveDirectiveResult(prop) {
|
|
2694
|
+
return (0, _vue_shared.extend)({}, prop, {
|
|
2695
|
+
value: void 0,
|
|
2696
|
+
values: [prop.value]
|
|
2697
|
+
});
|
|
2698
|
+
}
|
|
2699
|
+
function mergePropValues(existing, incoming) {
|
|
2700
|
+
const newValues = incoming.values;
|
|
2701
|
+
existing.values.push(...newValues);
|
|
2702
|
+
}
|
|
2703
|
+
function isComponentTag(tag) {
|
|
2704
|
+
return tag === "component" || tag === "Component";
|
|
2705
|
+
}
|
|
2706
|
+
|
|
2707
|
+
//#endregion
|
|
2708
|
+
//#region packages/compiler-vapor/src/transforms/vHtml.ts
|
|
2709
|
+
const transformVHtml = (dir, node, context) => {
|
|
2710
|
+
let { exp, loc } = dir;
|
|
2711
|
+
if (!exp) {
|
|
2712
|
+
context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(54, loc));
|
|
2713
|
+
exp = EMPTY_EXPRESSION;
|
|
2714
|
+
}
|
|
2715
|
+
if (node.children.length) {
|
|
2716
|
+
context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(55, loc));
|
|
2717
|
+
context.childrenTemplate.length = 0;
|
|
2718
|
+
}
|
|
2719
|
+
context.registerEffect([exp], {
|
|
2720
|
+
type: 7,
|
|
2721
|
+
node,
|
|
2722
|
+
element: context.reference(),
|
|
2723
|
+
value: exp,
|
|
2724
|
+
isComponent: node.tagType === 1
|
|
2725
|
+
});
|
|
2726
|
+
};
|
|
2727
|
+
|
|
2728
|
+
//#endregion
|
|
2729
|
+
//#region packages/shared/src/makeMap.ts
|
|
2730
|
+
/**
|
|
2731
|
+
* Make a map and return a function for checking if a key
|
|
2732
|
+
* is in that map.
|
|
2733
|
+
* IMPORTANT: all calls of this function must be prefixed with
|
|
2734
|
+
* \/\*#\_\_PURE\_\_\*\/
|
|
2735
|
+
* So that they can be tree-shaken if necessary.
|
|
2736
|
+
*/
|
|
2737
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
2738
|
+
function makeMap$1(str) {
|
|
2739
|
+
const map = Object.create(null);
|
|
2740
|
+
for (const key of str.split(",")) map[key] = 1;
|
|
2741
|
+
return (val) => val in map;
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2744
|
+
//#endregion
|
|
2745
|
+
//#region packages/shared/src/domTagConfig.ts
|
|
2746
|
+
const VOID_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
|
|
2747
|
+
/**
|
|
2748
|
+
* Compiler only.
|
|
2749
|
+
* Do NOT use in runtime code paths unless behind `__DEV__` flag.
|
|
2750
|
+
*/
|
|
2751
|
+
const isVoidTag = /* @__PURE__ */ makeMap$1(VOID_TAGS);
|
|
2752
|
+
|
|
2753
|
+
//#endregion
|
|
2754
|
+
//#region packages/compiler-vapor/src/transforms/vText.ts
|
|
2755
|
+
const transformVText = (dir, node, context) => {
|
|
2756
|
+
let { exp, loc } = dir;
|
|
2757
|
+
if (!exp) {
|
|
2758
|
+
context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(56, loc));
|
|
2759
|
+
exp = EMPTY_EXPRESSION;
|
|
2760
|
+
}
|
|
2761
|
+
if (node.children.length) {
|
|
2762
|
+
context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(57, loc));
|
|
2763
|
+
context.childrenTemplate.length = 0;
|
|
2764
|
+
}
|
|
2765
|
+
if (isVoidTag(context.node.tag)) return;
|
|
2766
|
+
const literal = getLiteralExpressionValue(exp);
|
|
2767
|
+
if (literal != null) context.childrenTemplate = [String(literal)];
|
|
2768
|
+
else {
|
|
2769
|
+
context.childrenTemplate = [context.options.platform ? TEXT_PLACEHOLDER : " "];
|
|
2770
|
+
const isComponent = node.tagType === 1;
|
|
2771
|
+
if (!isComponent) context.registerOperation({
|
|
2772
|
+
type: 16,
|
|
2773
|
+
node,
|
|
2774
|
+
parent: context.reference()
|
|
2775
|
+
});
|
|
2776
|
+
context.registerEffect([exp], {
|
|
2777
|
+
type: 4,
|
|
2778
|
+
node,
|
|
2779
|
+
element: context.reference(),
|
|
2780
|
+
values: [exp],
|
|
2781
|
+
generated: true,
|
|
2782
|
+
isComponent
|
|
2783
|
+
});
|
|
2784
|
+
}
|
|
2785
|
+
};
|
|
2786
|
+
|
|
2787
|
+
//#endregion
|
|
2788
|
+
//#region packages/compiler-vapor/src/transforms/vBind.ts
|
|
2789
|
+
function normalizeBindShorthand(arg, context) {
|
|
2790
|
+
if (arg.type !== 4 || !arg.isStatic) {
|
|
2791
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(53, arg.loc));
|
|
2792
|
+
return (0, _vue_compiler_dom.createSimpleExpression)("", true, arg.loc);
|
|
2793
|
+
}
|
|
2794
|
+
const exp = (0, _vue_compiler_dom.createSimpleExpression)((0, _vue_shared.camelize)(arg.content), false, arg.loc);
|
|
2795
|
+
exp.ast = null;
|
|
2796
|
+
return exp;
|
|
2797
|
+
}
|
|
2798
|
+
const transformVBind = (dir, node, context) => {
|
|
2799
|
+
const { loc, modifiers } = dir;
|
|
2800
|
+
let { exp } = dir;
|
|
2801
|
+
let arg = dir.arg;
|
|
2802
|
+
const modifiersString = modifiers.map((s) => s.content);
|
|
2803
|
+
if (!exp) exp = normalizeBindShorthand(arg, context);
|
|
2804
|
+
if (!exp.content.trim()) {
|
|
2805
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(34, loc));
|
|
2806
|
+
exp = (0, _vue_compiler_dom.createSimpleExpression)("", true, loc);
|
|
2807
|
+
}
|
|
2808
|
+
const isComponent = node.tagType === 1;
|
|
2809
|
+
exp = resolveExpression(exp, isComponent);
|
|
2810
|
+
arg = resolveExpression(arg);
|
|
2811
|
+
if (arg.isStatic && isReservedProp(arg.content)) return;
|
|
2812
|
+
let camel = false;
|
|
2813
|
+
if (modifiersString.includes("camel")) if (arg.isStatic) arg = (0, _vue_shared.extend)({}, arg, { content: (0, _vue_shared.camelize)(arg.content) });
|
|
2814
|
+
else camel = true;
|
|
2815
|
+
return {
|
|
2816
|
+
key: arg,
|
|
2817
|
+
value: exp,
|
|
2818
|
+
loc,
|
|
2819
|
+
runtimeCamelize: camel,
|
|
2820
|
+
modifier: modifiersString.includes("prop") ? "." : modifiersString.includes("attr") ? "^" : void 0
|
|
2821
|
+
};
|
|
2822
|
+
};
|
|
2823
|
+
|
|
2824
|
+
//#endregion
|
|
2825
|
+
//#region packages/compiler-vapor/src/transforms/vOn.ts
|
|
2826
|
+
const delegatedEvents = /* @__PURE__ */ (0, _vue_shared.makeMap)("beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,keyup,mousedown,mousemove,mouseout,mouseover,mouseup,pointerdown,pointermove,pointerout,pointerover,pointerup,touchend,touchmove,touchstart");
|
|
2827
|
+
const transformVOn = (dir, node, context) => {
|
|
2828
|
+
let { arg, exp, loc, modifiers } = dir;
|
|
2829
|
+
const isComponent = node.tagType === 1;
|
|
2830
|
+
const isSlotOutlet = node.tag === "slot";
|
|
2831
|
+
if (!exp && !modifiers.length) context.options.onError((0, _vue_compiler_dom.createCompilerError)(35, loc));
|
|
2832
|
+
arg = resolveExpression(arg);
|
|
2833
|
+
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = (0, _vue_compiler_dom.resolveModifiers)(arg.isStatic ? `on${arg.content}` : arg, modifiers, null, loc);
|
|
2834
|
+
let keyOverride;
|
|
2835
|
+
const isStaticClick = arg.isStatic && arg.content.toLowerCase() === "click";
|
|
2836
|
+
if (nonKeyModifiers.includes("middle")) {
|
|
2837
|
+
if (keyOverride) {}
|
|
2838
|
+
if (isStaticClick) arg = (0, _vue_shared.extend)({}, arg, { content: "mouseup" });
|
|
2839
|
+
else if (!arg.isStatic) keyOverride = ["click", "mouseup"];
|
|
2840
|
+
}
|
|
2841
|
+
if (nonKeyModifiers.includes("right")) {
|
|
2842
|
+
if (isStaticClick) arg = (0, _vue_shared.extend)({}, arg, { content: "contextmenu" });
|
|
2843
|
+
else if (!arg.isStatic) keyOverride = ["click", "contextmenu"];
|
|
2844
|
+
}
|
|
2845
|
+
if (keyModifiers.length && (0, _vue_compiler_dom.isStaticExp)(arg) && !(0, _vue_compiler_dom.isKeyboardEvent)(`on${arg.content.toLowerCase()}`)) keyModifiers.length = 0;
|
|
2846
|
+
if (isComponent || isSlotOutlet) return {
|
|
2847
|
+
key: arg,
|
|
2848
|
+
value: exp || EMPTY_EXPRESSION,
|
|
2849
|
+
handler: true,
|
|
2850
|
+
handlerModifiers: {
|
|
2851
|
+
keys: keyModifiers,
|
|
2852
|
+
nonKeys: nonKeyModifiers,
|
|
2853
|
+
options: eventOptionModifiers
|
|
2854
|
+
}
|
|
2855
|
+
};
|
|
2856
|
+
const delegate = arg.isStatic && !eventOptionModifiers.length && delegatedEvents(arg.content);
|
|
2857
|
+
const operation = {
|
|
2858
|
+
type: 5,
|
|
2859
|
+
node,
|
|
2860
|
+
element: context.reference(),
|
|
2861
|
+
key: arg,
|
|
2862
|
+
value: exp,
|
|
2863
|
+
modifiers: {
|
|
2864
|
+
keys: keyModifiers,
|
|
2865
|
+
nonKeys: nonKeyModifiers,
|
|
2866
|
+
options: eventOptionModifiers
|
|
2867
|
+
},
|
|
2868
|
+
keyOverride,
|
|
2869
|
+
delegate,
|
|
2870
|
+
effect: !arg.isStatic
|
|
2871
|
+
};
|
|
2872
|
+
context.registerEffect([arg], operation);
|
|
2873
|
+
};
|
|
2874
|
+
|
|
2875
|
+
//#endregion
|
|
2876
|
+
//#region packages/compiler-vapor/src/transforms/vShow.ts
|
|
2877
|
+
const transformVShow = (dir, node, context) => {
|
|
2878
|
+
const { exp, loc } = dir;
|
|
2879
|
+
if (!exp) {
|
|
2880
|
+
context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(62, loc));
|
|
2881
|
+
return;
|
|
2882
|
+
}
|
|
2883
|
+
if (node.tagType === 2) {
|
|
2884
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(36, loc));
|
|
2885
|
+
return;
|
|
2886
|
+
}
|
|
2887
|
+
let shouldDeferred = false;
|
|
2888
|
+
const parentNode = context.parent && context.parent.node;
|
|
2889
|
+
if (parentNode && parentNode.type === 1) {
|
|
2890
|
+
shouldDeferred = !!(isTransitionTag(parentNode.tag) && findProp$1(parentNode, "appear", false, true));
|
|
2891
|
+
if (shouldDeferred) context.ir.hasDeferredVShow = true;
|
|
2892
|
+
}
|
|
2893
|
+
context.registerOperation({
|
|
2894
|
+
type: 13,
|
|
2895
|
+
node,
|
|
2896
|
+
element: context.reference(),
|
|
2897
|
+
dir,
|
|
2898
|
+
name: "show",
|
|
2899
|
+
builtin: true,
|
|
2900
|
+
deferred: shouldDeferred
|
|
2901
|
+
});
|
|
2902
|
+
};
|
|
2903
|
+
|
|
2904
|
+
//#endregion
|
|
2905
|
+
//#region packages/compiler-vapor/src/transforms/transformTemplateRef.ts
|
|
2906
|
+
const transformTemplateRef = (node, context) => {
|
|
2907
|
+
if (node.type !== 1) return;
|
|
2908
|
+
const dir = findProp$1(node, "ref", false, true);
|
|
2909
|
+
if (!dir) return;
|
|
2910
|
+
context.ir.hasTemplateRef = true;
|
|
2911
|
+
let value;
|
|
2912
|
+
if (dir.type === 7) value = dir.exp || normalizeBindShorthand(dir.arg, context);
|
|
2913
|
+
else value = dir.value ? (0, _vue_compiler_dom.createSimpleExpression)(dir.value.content, true, dir.value.loc) : EMPTY_EXPRESSION;
|
|
2914
|
+
return () => {
|
|
2915
|
+
const id = context.reference();
|
|
2916
|
+
const effect = !isConstantExpression(value);
|
|
2917
|
+
context.registerEffect([value], {
|
|
2918
|
+
type: 8,
|
|
2919
|
+
node,
|
|
2920
|
+
element: id,
|
|
2921
|
+
value,
|
|
2922
|
+
refFor: !!context.inVFor,
|
|
2923
|
+
effect
|
|
2924
|
+
});
|
|
2925
|
+
};
|
|
2926
|
+
};
|
|
2927
|
+
|
|
2928
|
+
//#endregion
|
|
2929
|
+
//#region packages/compiler-vapor/src/transforms/transformText.ts
|
|
2930
|
+
const seen = /* @__PURE__ */ new WeakMap();
|
|
2931
|
+
function markNonTemplate(node, context) {
|
|
2932
|
+
seen.get(context.root).add(node);
|
|
2933
|
+
}
|
|
2934
|
+
const transformText = (node, context) => {
|
|
2935
|
+
if (!seen.has(context.root)) seen.set(context.root, /* @__PURE__ */ new WeakSet());
|
|
2936
|
+
if (seen.get(context.root).has(node)) {
|
|
2937
|
+
context.dynamic.flags |= 2;
|
|
2938
|
+
return;
|
|
2939
|
+
}
|
|
2940
|
+
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
2941
|
+
if ((isFragment || node.type === 1 && node.tagType === 0) && node.children.length) {
|
|
2942
|
+
let hasInterp = false;
|
|
2943
|
+
let isAllTextLike = true;
|
|
2944
|
+
for (const c of node.children) if (c.type === 5) hasInterp = true;
|
|
2945
|
+
else if (c.type !== 2) isAllTextLike = false;
|
|
2946
|
+
if (!isFragment && isAllTextLike && hasInterp) processTextContainer(node.children, context);
|
|
2947
|
+
else if (hasInterp) for (let i = 0; i < node.children.length; i++) {
|
|
2948
|
+
const c = node.children[i];
|
|
2949
|
+
const prev = node.children[i - 1];
|
|
2950
|
+
if (c.type === 5 && prev && prev.type === 2) markNonTemplate(prev, context);
|
|
2951
|
+
}
|
|
2952
|
+
} else if (node.type === 5) processInterpolation(context);
|
|
2953
|
+
else if (node.type === 2) {
|
|
2954
|
+
var _context$parent;
|
|
2955
|
+
const parent = (_context$parent = context.parent) === null || _context$parent === void 0 ? void 0 : _context$parent.node;
|
|
2956
|
+
const isRootText = !parent || parent.type === 0 || parent.type === 1 && (parent.tagType === 3 || parent.tagType === 1);
|
|
2957
|
+
context.template += isRootText ? node.content : (0, _vue_shared.escapeHtml)(node.content);
|
|
2958
|
+
}
|
|
2959
|
+
};
|
|
2960
|
+
function processInterpolation(context) {
|
|
2961
|
+
const parentNode = context.parent.node;
|
|
2962
|
+
const children = parentNode.children;
|
|
2963
|
+
const nexts = children.slice(context.index);
|
|
2964
|
+
const idx = nexts.findIndex((n) => !isTextLike(n));
|
|
2965
|
+
const nodes = idx > -1 ? nexts.slice(0, idx) : nexts;
|
|
2966
|
+
const prev = children[context.index - 1];
|
|
2967
|
+
if (prev && prev.type === 2) nodes.unshift(prev);
|
|
2968
|
+
const values = processTextLikeChildren(nodes, context);
|
|
2969
|
+
if (values.length === 0 && parentNode.type !== 0) return;
|
|
2970
|
+
const literalValues = values.map((v) => getLiteralExpressionValue(v));
|
|
2971
|
+
if (literalValues.every((v) => v != null) && parentNode.type !== 0) {
|
|
2972
|
+
const text = literalValues.join("");
|
|
2973
|
+
const isElementChild = parentNode.type === 1 && parentNode.tagType === 0;
|
|
2974
|
+
context.template += isElementChild ? (0, _vue_shared.escapeHtml)(text) : text;
|
|
2975
|
+
return;
|
|
2976
|
+
}
|
|
2977
|
+
const isDom2 = !!context.options.platform;
|
|
2978
|
+
let isTextNode = false;
|
|
2979
|
+
let isInComponentSlot = false;
|
|
2980
|
+
let shouldReuseParentText = false;
|
|
2981
|
+
if (isDom2) {
|
|
2982
|
+
const grandNode = context.parent.parent && context.parent.parent.node;
|
|
2983
|
+
function isComponent(node) {
|
|
2984
|
+
return !!(node && node.type === 1 && node.tagType === 1);
|
|
2985
|
+
}
|
|
2986
|
+
isInComponentSlot = parentNode.type === 1 && (parentNode.tagType === 1 || (0, _vue_compiler_dom.isTemplateNode)(parentNode) && isComponent(grandNode));
|
|
2987
|
+
shouldReuseParentText = !!(!isInComponentSlot && parentNode.loc.source.startsWith("<slot") && parentNode.type === 1 && parentNode.tag === "template" && grandNode && grandNode.tag === "text" && parentNode.children.every((child) => isTextLike(child)));
|
|
2988
|
+
isTextNode = isInComponentSlot || shouldReuseParentText;
|
|
2989
|
+
}
|
|
2990
|
+
context.template += isDom2 ? isTextNode ? TEXT_NODE_PLACEHOLDER : TEXT_PLACEHOLDER : " ";
|
|
2991
|
+
const id = context.reference();
|
|
2992
|
+
if (values.length === 0) return;
|
|
2993
|
+
context.registerEffect(values, {
|
|
2994
|
+
type: 4,
|
|
2995
|
+
node: context.node,
|
|
2996
|
+
element: id,
|
|
2997
|
+
values
|
|
2998
|
+
});
|
|
2999
|
+
}
|
|
3000
|
+
function processTextContainer(children, context) {
|
|
3001
|
+
const values = processTextLikeChildren(children, context);
|
|
3002
|
+
const literals = values.map((value) => getLiteralExpressionValue(value));
|
|
3003
|
+
if (literals.every((l) => l != null)) context.childrenTemplate = literals.map((l) => (0, _vue_shared.escapeHtml)(String(l)));
|
|
3004
|
+
else {
|
|
3005
|
+
context.childrenTemplate = [context.options.platform ? TEXT_PLACEHOLDER : " "];
|
|
3006
|
+
context.registerOperation({
|
|
3007
|
+
type: 16,
|
|
3008
|
+
node: context.node,
|
|
3009
|
+
parent: context.reference()
|
|
3010
|
+
});
|
|
3011
|
+
context.registerEffect(values, {
|
|
3012
|
+
type: 4,
|
|
3013
|
+
node: context.node,
|
|
3014
|
+
element: context.reference(),
|
|
3015
|
+
values,
|
|
3016
|
+
generated: true
|
|
3017
|
+
});
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
function processTextLikeChildren(nodes, context) {
|
|
3021
|
+
const exps = [];
|
|
3022
|
+
for (const node of nodes) {
|
|
3023
|
+
let exp;
|
|
3024
|
+
markNonTemplate(node, context);
|
|
3025
|
+
if (node.type === 2) exp = (0, _vue_compiler_dom.createSimpleExpression)(node.content, true, node.loc);
|
|
3026
|
+
else exp = node.content;
|
|
3027
|
+
if (exp.content) exps.push(exp);
|
|
3028
|
+
}
|
|
3029
|
+
return exps;
|
|
3030
|
+
}
|
|
3031
|
+
function isTextLike(node) {
|
|
3032
|
+
return node.type === 5 || node.type === 2;
|
|
3033
|
+
}
|
|
3034
|
+
|
|
3035
|
+
//#endregion
|
|
3036
|
+
//#region packages/compiler-vapor/src/transforms/vModel.ts
|
|
3037
|
+
const transformVModel = (dir, node, context) => {
|
|
3038
|
+
const { exp, arg } = dir;
|
|
3039
|
+
if (!exp) {
|
|
3040
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(41, dir.loc));
|
|
3041
|
+
return;
|
|
3042
|
+
}
|
|
3043
|
+
const rawExp = exp.loc.source;
|
|
3044
|
+
const bindingType = context.options.bindingMetadata[rawExp];
|
|
3045
|
+
if (bindingType === "props" || bindingType === "props-aliased") {
|
|
3046
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(44, exp.loc));
|
|
3047
|
+
return;
|
|
3048
|
+
}
|
|
3049
|
+
const expString = exp.content;
|
|
3050
|
+
const maybeRef = context.options.inline && (bindingType === "setup-let" || bindingType === "setup-ref" || bindingType === "setup-maybe-ref");
|
|
3051
|
+
if (!expString.trim() || !(0, _vue_compiler_dom.isMemberExpression)(exp, context.options) && !maybeRef) {
|
|
3052
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(42, exp.loc));
|
|
3053
|
+
return;
|
|
3054
|
+
}
|
|
3055
|
+
if (node.tagType === 1) return {
|
|
3056
|
+
key: arg ? arg : (0, _vue_compiler_dom.createSimpleExpression)("modelValue", true),
|
|
3057
|
+
value: exp,
|
|
3058
|
+
model: true,
|
|
3059
|
+
modelModifiers: dir.modifiers.map((m) => m.content)
|
|
3060
|
+
};
|
|
3061
|
+
if (dir.arg) context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(59, dir.arg.loc));
|
|
3062
|
+
const { tag } = node;
|
|
3063
|
+
const isCustomElement = context.options.isCustomElement(tag);
|
|
3064
|
+
let modelType = "text";
|
|
3065
|
+
if (tag === "input" || tag === "textarea" || tag === "select" || isCustomElement) if (tag === "input" || isCustomElement) {
|
|
3066
|
+
const type = (0, _vue_compiler_dom.findProp)(node, "type");
|
|
3067
|
+
if (type) {
|
|
3068
|
+
if (type.type === 7) modelType = "dynamic";
|
|
3069
|
+
else if (type.value) switch (type.value.content) {
|
|
3070
|
+
case "radio":
|
|
3071
|
+
modelType = "radio";
|
|
3072
|
+
break;
|
|
3073
|
+
case "checkbox":
|
|
3074
|
+
modelType = "checkbox";
|
|
3075
|
+
break;
|
|
3076
|
+
case "file":
|
|
3077
|
+
modelType = void 0;
|
|
3078
|
+
context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(60, dir.loc));
|
|
3079
|
+
break;
|
|
3080
|
+
default:
|
|
3081
|
+
checkDuplicatedValue();
|
|
3082
|
+
break;
|
|
3083
|
+
}
|
|
3084
|
+
} else if ((0, _vue_compiler_dom.hasDynamicKeyVBind)(node)) modelType = "dynamic";
|
|
3085
|
+
else checkDuplicatedValue();
|
|
3086
|
+
} else if (tag === "select") modelType = "select";
|
|
3087
|
+
else checkDuplicatedValue();
|
|
3088
|
+
else context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(58, dir.loc));
|
|
3089
|
+
if (modelType) context.registerOperation({
|
|
3090
|
+
type: 13,
|
|
3091
|
+
node,
|
|
3092
|
+
element: context.reference(),
|
|
3093
|
+
dir,
|
|
3094
|
+
name: "model",
|
|
3095
|
+
modelType,
|
|
3096
|
+
builtin: true
|
|
3097
|
+
});
|
|
3098
|
+
function checkDuplicatedValue() {
|
|
3099
|
+
const value = (0, _vue_compiler_dom.findDir)(node, "bind");
|
|
3100
|
+
if (value && (0, _vue_compiler_dom.isStaticArgOf)(value.arg, "value")) context.options.onError((0, _vue_compiler_dom.createDOMCompilerError)(61, value.loc));
|
|
3101
|
+
}
|
|
3102
|
+
};
|
|
3103
|
+
|
|
3104
|
+
//#endregion
|
|
3105
|
+
//#region packages/compiler-vapor/src/transforms/transformComment.ts
|
|
3106
|
+
const transformComment = (node, context) => {
|
|
3107
|
+
if (node.type !== 3) return;
|
|
3108
|
+
if (getSiblingIf(context)) {
|
|
3109
|
+
context.comment.push(node);
|
|
3110
|
+
context.dynamic.flags |= 2;
|
|
3111
|
+
} else context.template += `<!--${(0, _vue_shared.escapeHtml)(node.content)}-->`;
|
|
3112
|
+
};
|
|
3113
|
+
function getSiblingIf(context, reverse) {
|
|
3114
|
+
const parent = context.parent;
|
|
3115
|
+
if (!parent) return;
|
|
3116
|
+
const siblings = parent.node.children;
|
|
3117
|
+
let sibling;
|
|
3118
|
+
let i = siblings.indexOf(context.node);
|
|
3119
|
+
while (reverse ? --i >= 0 : ++i < siblings.length) {
|
|
3120
|
+
sibling = siblings[i];
|
|
3121
|
+
if (!(0, _vue_compiler_dom.isCommentOrWhitespace)(sibling)) break;
|
|
3122
|
+
}
|
|
3123
|
+
if (sibling && sibling.type === 1 && sibling.props.some(({ type, name }) => type === 7 && ["else-if", reverse ? "if" : "else"].includes(name))) return sibling;
|
|
3124
|
+
}
|
|
3125
|
+
|
|
3126
|
+
//#endregion
|
|
3127
|
+
//#region packages/compiler-vapor/src/transforms/vIf.ts
|
|
3128
|
+
const transformVIf = createStructuralDirectiveTransform([
|
|
3129
|
+
"if",
|
|
3130
|
+
"else",
|
|
3131
|
+
"else-if"
|
|
3132
|
+
], processIf);
|
|
3133
|
+
function processIf(node, dir, context) {
|
|
3134
|
+
if (dir.name !== "else" && (!dir.exp || !dir.exp.content.trim())) {
|
|
3135
|
+
const loc = dir.exp ? dir.exp.loc : node.loc;
|
|
3136
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(28, dir.loc));
|
|
3137
|
+
dir.exp = (0, _vue_compiler_dom.createSimpleExpression)(`true`, false, loc);
|
|
3138
|
+
}
|
|
3139
|
+
context.dynamic.flags |= 2;
|
|
3140
|
+
if (dir.name === "if") {
|
|
3141
|
+
const id = context.reference();
|
|
3142
|
+
context.dynamic.flags |= 4;
|
|
3143
|
+
const [branch, onExit] = createIfBranch(node, context);
|
|
3144
|
+
return () => {
|
|
3145
|
+
onExit();
|
|
3146
|
+
context.dynamic.operation = {
|
|
3147
|
+
type: 14,
|
|
3148
|
+
node,
|
|
3149
|
+
id,
|
|
3150
|
+
condition: dir.exp,
|
|
3151
|
+
positive: branch,
|
|
3152
|
+
index: isInTransition(context) ? context.root.nextIfIndex() : void 0,
|
|
3153
|
+
once: context.inVOnce || isStaticExpression(dir.exp, context.options.bindingMetadata)
|
|
3154
|
+
};
|
|
3155
|
+
};
|
|
3156
|
+
} else {
|
|
3157
|
+
const siblingIf = getSiblingIf(context, true);
|
|
3158
|
+
const siblings = context.parent && context.parent.dynamic.children;
|
|
3159
|
+
let lastIfNode;
|
|
3160
|
+
if (siblings) {
|
|
3161
|
+
let i = siblings.length;
|
|
3162
|
+
while (i--) if (siblings[i].operation && siblings[i].operation.type === 14) {
|
|
3163
|
+
lastIfNode = siblings[i].operation;
|
|
3164
|
+
break;
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
if (!siblingIf || !lastIfNode || lastIfNode.type !== 14) {
|
|
3168
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(30, node.loc));
|
|
3169
|
+
return;
|
|
3170
|
+
}
|
|
3171
|
+
while (lastIfNode.negative && lastIfNode.negative.type === 14) lastIfNode = lastIfNode.negative;
|
|
3172
|
+
if (dir.name === "else-if" && lastIfNode.negative) context.options.onError((0, _vue_compiler_dom.createCompilerError)(30, node.loc));
|
|
3173
|
+
if (context.root.comment.length) {
|
|
3174
|
+
node = wrapTemplate(node, ["else-if", "else"]);
|
|
3175
|
+
context.node = node = (0, _vue_shared.extend)({}, node, { children: [...context.comment, ...node.children] });
|
|
3176
|
+
}
|
|
3177
|
+
context.root.comment = [];
|
|
3178
|
+
const [branch, onExit] = createIfBranch(node, context);
|
|
3179
|
+
if (dir.name === "else") lastIfNode.negative = branch;
|
|
3180
|
+
else lastIfNode.negative = {
|
|
3181
|
+
type: 14,
|
|
3182
|
+
node,
|
|
3183
|
+
id: -1,
|
|
3184
|
+
condition: dir.exp,
|
|
3185
|
+
positive: branch,
|
|
3186
|
+
index: isInTransition(context) ? context.root.nextIfIndex() : void 0,
|
|
3187
|
+
once: context.inVOnce || isStaticExpression(dir.exp, context.options.bindingMetadata)
|
|
3188
|
+
};
|
|
3189
|
+
return () => onExit();
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
function createIfBranch(node, context) {
|
|
3193
|
+
context.node = node = wrapTemplate(node, [
|
|
3194
|
+
"if",
|
|
3195
|
+
"else-if",
|
|
3196
|
+
"else"
|
|
3197
|
+
]);
|
|
3198
|
+
const branch = newBlock(node);
|
|
3199
|
+
const exitBlock = context.enterBlock(branch);
|
|
3200
|
+
context.reference();
|
|
3201
|
+
return [branch, exitBlock];
|
|
3202
|
+
}
|
|
3203
|
+
|
|
3204
|
+
//#endregion
|
|
3205
|
+
//#region packages/compiler-vapor/src/transforms/vFor.ts
|
|
3206
|
+
const transformVFor = createStructuralDirectiveTransform("for", processFor);
|
|
3207
|
+
function processFor(node, dir, context) {
|
|
3208
|
+
if (!dir.exp) {
|
|
3209
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(31, dir.loc));
|
|
3210
|
+
return;
|
|
3211
|
+
}
|
|
3212
|
+
const parseResult = dir.forParseResult;
|
|
3213
|
+
if (!parseResult) {
|
|
3214
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(32, dir.loc));
|
|
3215
|
+
return;
|
|
3216
|
+
}
|
|
3217
|
+
const { source, value, key, index } = parseResult;
|
|
3218
|
+
const keyProp = findProp$1(node, "key");
|
|
3219
|
+
const keyProperty = keyProp && propToExpression(keyProp);
|
|
3220
|
+
const typeProp = findProp$1(node, "type");
|
|
3221
|
+
const typeProperty = typeProp && propToExpression(typeProp);
|
|
3222
|
+
const isComponent = node.tagType === 1 || isTemplateWithSingleComponent(node);
|
|
3223
|
+
context.node = node = wrapTemplate(node, ["for"]);
|
|
3224
|
+
context.dynamic.flags |= 6;
|
|
3225
|
+
const id = context.reference();
|
|
3226
|
+
const render = newBlock(node);
|
|
3227
|
+
const exitBlock = context.enterBlock(render, true);
|
|
3228
|
+
context.reference();
|
|
3229
|
+
return () => {
|
|
3230
|
+
exitBlock();
|
|
3231
|
+
const { parent } = context;
|
|
3232
|
+
const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
|
|
3233
|
+
context.dynamic.operation = {
|
|
3234
|
+
type: 15,
|
|
3235
|
+
node,
|
|
3236
|
+
id,
|
|
3237
|
+
source,
|
|
3238
|
+
value,
|
|
3239
|
+
key,
|
|
3240
|
+
index,
|
|
3241
|
+
keyProp: keyProperty,
|
|
3242
|
+
typeProp: typeProperty,
|
|
3243
|
+
render,
|
|
3244
|
+
once: context.inVOnce || isStaticExpression(source, context.options.bindingMetadata),
|
|
3245
|
+
component: isComponent && node.children[0].type === 1 && node.children[0].tagType === 1,
|
|
3246
|
+
onlyChild: !!isOnlyChild
|
|
3247
|
+
};
|
|
3248
|
+
};
|
|
3249
|
+
}
|
|
3250
|
+
function isTemplateWithSingleComponent(node) {
|
|
3251
|
+
if (node.tag !== "template") return false;
|
|
3252
|
+
const nonCommentChildren = node.children.filter((c) => c.type !== 3);
|
|
3253
|
+
return nonCommentChildren.length === 1 && nonCommentChildren[0].type === 1 && nonCommentChildren[0].tagType === 1;
|
|
3254
|
+
}
|
|
3255
|
+
|
|
3256
|
+
//#endregion
|
|
3257
|
+
//#region packages/compiler-vapor/src/transforms/transformSlotOutlet.ts
|
|
3258
|
+
const transformSlotOutlet = (node, context) => {
|
|
3259
|
+
if (node.type !== 1 || node.tag !== "slot") return;
|
|
3260
|
+
const id = context.reference();
|
|
3261
|
+
context.dynamic.flags |= 6;
|
|
3262
|
+
const [fallback, exitBlock] = createFallback(node, context);
|
|
3263
|
+
let slotName;
|
|
3264
|
+
const slotProps = [];
|
|
3265
|
+
for (const prop of node.props) if (prop.type === 6) {
|
|
3266
|
+
if (prop.value) if (prop.name === "name") slotName = (0, _vue_compiler_dom.createSimpleExpression)(prop.value.content, true, prop.loc);
|
|
3267
|
+
else slotProps.push((0, _vue_shared.extend)({}, prop, { name: (0, _vue_shared.camelize)(prop.name) }));
|
|
3268
|
+
} else if (prop.name === "bind" && (0, _vue_compiler_dom.isStaticArgOf)(prop.arg, "name")) if (prop.exp) slotName = prop.exp;
|
|
3269
|
+
else {
|
|
3270
|
+
slotName = (0, _vue_compiler_dom.createSimpleExpression)((0, _vue_shared.camelize)(prop.arg.content), false, prop.arg.loc);
|
|
3271
|
+
slotName.ast = null;
|
|
3272
|
+
}
|
|
3273
|
+
else {
|
|
3274
|
+
let slotProp = prop;
|
|
3275
|
+
if (slotProp.name === "bind" && slotProp.arg && (0, _vue_compiler_dom.isStaticExp)(slotProp.arg)) slotProp = (0, _vue_shared.extend)({}, prop, { arg: (0, _vue_shared.extend)({}, slotProp.arg, { content: (0, _vue_shared.camelize)(slotProp.arg.content) }) });
|
|
3276
|
+
slotProps.push(slotProp);
|
|
3277
|
+
}
|
|
3278
|
+
slotName || (slotName = (0, _vue_compiler_dom.createSimpleExpression)("default", true));
|
|
3279
|
+
let irProps = [];
|
|
3280
|
+
if (slotProps.length) {
|
|
3281
|
+
const [isDynamic, props] = buildProps((0, _vue_shared.extend)({}, node, { props: slotProps }), context, true);
|
|
3282
|
+
irProps = isDynamic ? props : [props];
|
|
3283
|
+
const runtimeDirective = context.block.operation.find((oper) => oper.type === 13 && oper.element === id);
|
|
3284
|
+
if (runtimeDirective) context.options.onError((0, _vue_compiler_dom.createCompilerError)(36, runtimeDirective.dir.loc));
|
|
3285
|
+
}
|
|
3286
|
+
return () => {
|
|
3287
|
+
exitBlock && exitBlock();
|
|
3288
|
+
context.dynamic.operation = {
|
|
3289
|
+
type: 12,
|
|
3290
|
+
node,
|
|
3291
|
+
id,
|
|
3292
|
+
name: slotName,
|
|
3293
|
+
props: irProps,
|
|
3294
|
+
fallback,
|
|
3295
|
+
noSlotted: !!(context.options.scopeId && !context.options.slotted),
|
|
3296
|
+
once: context.inVOnce
|
|
3297
|
+
};
|
|
3298
|
+
};
|
|
3299
|
+
};
|
|
3300
|
+
function createFallback(node, context) {
|
|
3301
|
+
if (!node.children.length) return [];
|
|
3302
|
+
context.node = node = (0, _vue_shared.extend)({}, node, {
|
|
3303
|
+
type: 1,
|
|
3304
|
+
tag: "template",
|
|
3305
|
+
props: [],
|
|
3306
|
+
tagType: 3,
|
|
3307
|
+
children: node.children
|
|
3308
|
+
});
|
|
3309
|
+
const fallback = newBlock(node);
|
|
3310
|
+
const exitBlock = context.enterBlock(fallback);
|
|
3311
|
+
context.reference();
|
|
3312
|
+
return [fallback, exitBlock];
|
|
3313
|
+
}
|
|
3314
|
+
|
|
3315
|
+
//#endregion
|
|
3316
|
+
//#region packages/compiler-vapor/src/transforms/vSlot.ts
|
|
3317
|
+
const transformVSlot = (node, context) => {
|
|
3318
|
+
if (node.type !== 1) return;
|
|
3319
|
+
const dir = findDir$2(node, "slot", true);
|
|
3320
|
+
const { tagType, children } = node;
|
|
3321
|
+
const { parent } = context;
|
|
3322
|
+
const isComponent = tagType === 1;
|
|
3323
|
+
const isSlotTemplate = (0, _vue_compiler_dom.isTemplateNode)(node) && parent && parent.node.type === 1 && parent.node.tagType === 1;
|
|
3324
|
+
if (isComponent && children.length) return transformComponentSlot(node, dir, context);
|
|
3325
|
+
else if (isSlotTemplate && dir) return transformTemplateSlot(node, dir, context);
|
|
3326
|
+
else if (!isComponent && dir) context.options.onError((0, _vue_compiler_dom.createCompilerError)(40, dir.loc));
|
|
3327
|
+
};
|
|
3328
|
+
function transformComponentSlot(node, dir, context) {
|
|
3329
|
+
const { children } = node;
|
|
3330
|
+
const arg = dir && dir.arg;
|
|
3331
|
+
const emptyTextNodes = [];
|
|
3332
|
+
const nonSlotTemplateChildren = children.filter((n) => {
|
|
3333
|
+
if (isNonWhitespaceContent(n)) return !(n.type === 1 && n.props.some(_vue_compiler_dom.isVSlot));
|
|
3334
|
+
else emptyTextNodes.push(n);
|
|
3335
|
+
});
|
|
3336
|
+
if (!nonSlotTemplateChildren.length) emptyTextNodes.forEach((n) => {
|
|
3337
|
+
markNonTemplate(n, context);
|
|
3338
|
+
});
|
|
3339
|
+
const [block, onExit] = createSlotBlock(node, dir, context);
|
|
3340
|
+
if (isTransitionNode(node) && nonSlotTemplateChildren.length) {
|
|
3341
|
+
const nonCommentChild = nonSlotTemplateChildren.find((n) => !(0, _vue_compiler_dom.isCommentOrWhitespace)(n));
|
|
3342
|
+
if (nonCommentChild) {
|
|
3343
|
+
const keyProp = findProp$1(nonCommentChild, "key");
|
|
3344
|
+
if (keyProp) block.key = keyProp.exp;
|
|
3345
|
+
}
|
|
3346
|
+
}
|
|
3347
|
+
const { slots } = context;
|
|
3348
|
+
return () => {
|
|
3349
|
+
onExit();
|
|
3350
|
+
const hasOtherSlots = !!slots.length;
|
|
3351
|
+
if (dir && hasOtherSlots) {
|
|
3352
|
+
context.options.onError((0, _vue_compiler_dom.createCompilerError)(37, dir.loc));
|
|
3353
|
+
return;
|
|
3354
|
+
}
|
|
3355
|
+
if (nonSlotTemplateChildren.length) if (hasStaticSlot(slots, "default")) context.options.onError((0, _vue_compiler_dom.createCompilerError)(39, nonSlotTemplateChildren[0].loc));
|
|
3356
|
+
else {
|
|
3357
|
+
registerSlot(slots, arg, block);
|
|
3358
|
+
context.slots = slots;
|
|
3359
|
+
}
|
|
3360
|
+
else if (hasOtherSlots) context.slots = slots;
|
|
3361
|
+
};
|
|
3362
|
+
}
|
|
3363
|
+
function transformTemplateSlot(node, dir, context) {
|
|
3364
|
+
context.dynamic.flags |= 2;
|
|
3365
|
+
const arg = dir.arg && resolveExpression(dir.arg);
|
|
3366
|
+
const vFor = findDir$2(node, "for");
|
|
3367
|
+
const vIf = findDir$2(node, "if");
|
|
3368
|
+
const vElse = findDir$2(node, /^else(-if)?$/, true);
|
|
3369
|
+
const { slots } = context;
|
|
3370
|
+
const [block, onExit] = createSlotBlock(node, dir, context);
|
|
3371
|
+
if (!vFor && !vIf && !vElse) {
|
|
3372
|
+
const slotName = arg ? arg.isStatic && arg.content : "default";
|
|
3373
|
+
if (slotName && hasStaticSlot(slots, slotName)) context.options.onError((0, _vue_compiler_dom.createCompilerError)(38, dir.loc));
|
|
3374
|
+
else registerSlot(slots, arg, block);
|
|
3375
|
+
} else if (vIf) registerDynamicSlot(slots, {
|
|
3376
|
+
slotType: 3,
|
|
3377
|
+
condition: vIf.exp,
|
|
3378
|
+
positive: {
|
|
3379
|
+
slotType: 1,
|
|
3380
|
+
name: arg,
|
|
3381
|
+
fn: block
|
|
3382
|
+
}
|
|
3383
|
+
});
|
|
3384
|
+
else if (vElse) {
|
|
3385
|
+
const vIfSlot = slots[slots.length - 1];
|
|
3386
|
+
if (vIfSlot.slotType === 3) {
|
|
3387
|
+
let ifNode = vIfSlot;
|
|
3388
|
+
while (ifNode.negative && ifNode.negative.slotType === 3) ifNode = ifNode.negative;
|
|
3389
|
+
const negative = vElse.exp ? {
|
|
3390
|
+
slotType: 3,
|
|
3391
|
+
condition: vElse.exp,
|
|
3392
|
+
positive: {
|
|
3393
|
+
slotType: 1,
|
|
3394
|
+
name: arg,
|
|
3395
|
+
fn: block
|
|
3396
|
+
}
|
|
3397
|
+
} : {
|
|
3398
|
+
slotType: 1,
|
|
3399
|
+
name: arg,
|
|
3400
|
+
fn: block
|
|
3401
|
+
};
|
|
3402
|
+
ifNode.negative = negative;
|
|
3403
|
+
} else context.options.onError((0, _vue_compiler_dom.createCompilerError)(30, vElse.loc));
|
|
3404
|
+
} else if (vFor) if (vFor.forParseResult) registerDynamicSlot(slots, {
|
|
3405
|
+
slotType: 2,
|
|
3406
|
+
name: arg,
|
|
3407
|
+
fn: block,
|
|
3408
|
+
loop: vFor.forParseResult
|
|
3409
|
+
});
|
|
3410
|
+
else context.options.onError((0, _vue_compiler_dom.createCompilerError)(32, vFor.loc));
|
|
3411
|
+
return onExit;
|
|
3412
|
+
}
|
|
3413
|
+
function ensureStaticSlots(slots) {
|
|
3414
|
+
let lastSlots = slots[slots.length - 1];
|
|
3415
|
+
if (!slots.length || lastSlots.slotType !== 0) slots.push(lastSlots = {
|
|
3416
|
+
slotType: 0,
|
|
3417
|
+
slots: {}
|
|
3418
|
+
});
|
|
3419
|
+
return lastSlots.slots;
|
|
3420
|
+
}
|
|
3421
|
+
function registerSlot(slots, name, block) {
|
|
3422
|
+
if (!name || name.isStatic) {
|
|
3423
|
+
const staticSlots = ensureStaticSlots(slots);
|
|
3424
|
+
staticSlots[name ? name.content : "default"] = block;
|
|
3425
|
+
} else slots.push({
|
|
3426
|
+
slotType: 1,
|
|
3427
|
+
name,
|
|
3428
|
+
fn: block
|
|
3429
|
+
});
|
|
3430
|
+
}
|
|
3431
|
+
function registerDynamicSlot(allSlots, dynamic) {
|
|
3432
|
+
allSlots.push(dynamic);
|
|
3433
|
+
}
|
|
3434
|
+
function hasStaticSlot(slots, name) {
|
|
3435
|
+
return slots.some((slot) => {
|
|
3436
|
+
if (slot.slotType === 0) return !!slot.slots[name];
|
|
3437
|
+
});
|
|
3438
|
+
}
|
|
3439
|
+
function createSlotBlock(slotNode, dir, context) {
|
|
3440
|
+
const block = newBlock(slotNode);
|
|
3441
|
+
block.props = dir && dir.exp;
|
|
3442
|
+
return [block, context.enterBlock(block)];
|
|
3443
|
+
}
|
|
3444
|
+
function isNonWhitespaceContent(node) {
|
|
3445
|
+
if (node.type !== 2) return true;
|
|
3446
|
+
return !!node.content.trim();
|
|
3447
|
+
}
|
|
3448
|
+
|
|
3449
|
+
//#endregion
|
|
3450
|
+
//#region packages/compiler-vapor/src/transforms/transformTransition.ts
|
|
3451
|
+
const transformTransition = (node, context) => {
|
|
3452
|
+
if (node.type === 1 && node.tagType === 1) {
|
|
3453
|
+
if (isTransitionTag(node.tag)) return (0, _vue_compiler_dom.postTransformTransition)(node, context.options.onError, hasMultipleChildren);
|
|
3454
|
+
}
|
|
3455
|
+
};
|
|
3456
|
+
function hasMultipleChildren(node) {
|
|
3457
|
+
const children = node.children = node.children.filter((c) => c.type !== 3 && !(c.type === 2 && !c.content.trim()));
|
|
3458
|
+
const first = children[0];
|
|
3459
|
+
if (children.length === 1 && first.type === 1 && (findDir$2(first, "for") || (0, _vue_compiler_dom.isTemplateNode)(first))) return true;
|
|
3460
|
+
const hasElse = (node) => findDir$2(node, "else-if") || findDir$2(node, "else", true);
|
|
3461
|
+
if (children.every((c, index) => c.type === 1 && !(0, _vue_compiler_dom.isTemplateNode)(c) && !findDir$2(c, "for") && (index === 0 ? findDir$2(c, "if") : hasElse(c)))) return false;
|
|
3462
|
+
return children.length > 1;
|
|
3463
|
+
}
|
|
3464
|
+
|
|
3465
|
+
//#endregion
|
|
3466
|
+
//#region packages/compiler-vapor/src/compile.ts
|
|
3467
|
+
function compile(source, options = {}) {
|
|
3468
|
+
const resolvedOptions = (0, _vue_shared.extend)({}, options);
|
|
3469
|
+
const ast = (0, _vue_shared.isString)(source) ? (0, _vue_compiler_dom.parse)(source, resolvedOptions) : source;
|
|
3470
|
+
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset();
|
|
3471
|
+
if (options.isTS) {
|
|
3472
|
+
const { expressionPlugins } = options;
|
|
3473
|
+
if (!expressionPlugins || !expressionPlugins.includes("typescript")) resolvedOptions.expressionPlugins = [...expressionPlugins || [], "typescript"];
|
|
3474
|
+
}
|
|
3475
|
+
return generate(transform(ast, (0, _vue_shared.extend)({}, resolvedOptions, {
|
|
3476
|
+
nodeTransforms: [
|
|
3477
|
+
...nodeTransforms,
|
|
3478
|
+
...[transformTransition],
|
|
3479
|
+
...options.nodeTransforms || []
|
|
3480
|
+
],
|
|
3481
|
+
directiveTransforms: (0, _vue_shared.extend)({}, directiveTransforms, options.directiveTransforms || {})
|
|
3482
|
+
})), resolvedOptions);
|
|
3483
|
+
}
|
|
3484
|
+
function getBaseTransformPreset() {
|
|
3485
|
+
return [[
|
|
3486
|
+
transformVOnce,
|
|
3487
|
+
transformVIf,
|
|
3488
|
+
transformVFor,
|
|
3489
|
+
transformSlotOutlet,
|
|
3490
|
+
transformTemplateRef,
|
|
3491
|
+
transformElement,
|
|
3492
|
+
transformText,
|
|
3493
|
+
transformVSlot,
|
|
3494
|
+
transformComment,
|
|
3495
|
+
transformChildren
|
|
3496
|
+
], {
|
|
3497
|
+
bind: transformVBind,
|
|
3498
|
+
on: transformVOn,
|
|
3499
|
+
html: transformVHtml,
|
|
3500
|
+
text: transformVText,
|
|
3501
|
+
show: transformVShow,
|
|
3502
|
+
model: transformVModel
|
|
3503
|
+
}];
|
|
3504
|
+
}
|
|
3505
|
+
|
|
3506
|
+
//#endregion
|
|
3507
|
+
//#region packages/compiler-vapor/src/errors.ts
|
|
3508
|
+
function createVaporCompilerError(code, loc) {
|
|
3509
|
+
return (0, _vue_compiler_dom.createCompilerError)(code, loc, VaporErrorMessages);
|
|
3510
|
+
}
|
|
3511
|
+
const VaporErrorCodes = {
|
|
3512
|
+
"X_V_PLACEHOLDER": 100,
|
|
3513
|
+
"100": "X_V_PLACEHOLDER",
|
|
3514
|
+
"__EXTEND_POINT__": 101,
|
|
3515
|
+
"101": "__EXTEND_POINT__"
|
|
3516
|
+
};
|
|
3517
|
+
const VaporErrorMessages = {
|
|
3518
|
+
[100]: `[placeholder]`,
|
|
3519
|
+
[101]: ``
|
|
3520
|
+
};
|
|
3521
|
+
|
|
3522
|
+
//#endregion
|
|
3523
|
+
exports.CodegenContext = CodegenContext;
|
|
3524
|
+
exports.DELIMITERS_ARRAY = DELIMITERS_ARRAY;
|
|
3525
|
+
exports.DELIMITERS_ARRAY_NEWLINE = DELIMITERS_ARRAY_NEWLINE;
|
|
3526
|
+
exports.DELIMITERS_OBJECT = DELIMITERS_OBJECT;
|
|
3527
|
+
exports.DELIMITERS_OBJECT_NEWLINE = DELIMITERS_OBJECT_NEWLINE;
|
|
3528
|
+
exports.DynamicFlag = DynamicFlag;
|
|
3529
|
+
exports.IMPORT_EXPR_RE = IMPORT_EXPR_RE;
|
|
3530
|
+
exports.IMPORT_EXP_END = IMPORT_EXP_END;
|
|
3531
|
+
exports.IMPORT_EXP_START = IMPORT_EXP_START;
|
|
3532
|
+
exports.INDENT_END = INDENT_END;
|
|
3533
|
+
exports.INDENT_START = INDENT_START;
|
|
3534
|
+
exports.IRDynamicPropsKind = IRDynamicPropsKind;
|
|
3535
|
+
exports.IRNodeTypes = IRNodeTypes;
|
|
3536
|
+
exports.IRSlotType = IRSlotType;
|
|
3537
|
+
exports.LF = LF;
|
|
3538
|
+
exports.NEWLINE = NEWLINE;
|
|
3539
|
+
exports.TEXT_NODE_PLACEHOLDER = TEXT_NODE_PLACEHOLDER;
|
|
3540
|
+
exports.TEXT_PLACEHOLDER = TEXT_PLACEHOLDER;
|
|
3541
|
+
exports.VaporErrorCodes = VaporErrorCodes;
|
|
3542
|
+
exports.VaporErrorMessages = VaporErrorMessages;
|
|
3543
|
+
exports.analyzeExpressions = analyzeExpressions;
|
|
3544
|
+
exports.buildCodeFragment = buildCodeFragment;
|
|
3545
|
+
exports.buildDestructureIdMap = buildDestructureIdMap;
|
|
3546
|
+
exports.codeFragmentToString = codeFragmentToString;
|
|
3547
|
+
exports.compile = compile;
|
|
3548
|
+
exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
|
|
3549
|
+
exports.createVaporCompilerError = createVaporCompilerError;
|
|
3550
|
+
exports.genCall = genCall;
|
|
3551
|
+
exports.genMulti = genMulti;
|
|
3552
|
+
exports.generate = generate;
|
|
3553
|
+
exports.getBaseTransformPreset = getBaseTransformPreset;
|
|
3554
|
+
exports.getLiteralExpressionValue = getLiteralExpressionValue;
|
|
3555
|
+
exports.isBlockOperation = isBlockOperation;
|
|
3556
|
+
exports.isBuiltInComponent = isBuiltInComponent;
|
|
3557
|
+
exports.isConstantExpression = isConstantExpression;
|
|
3558
|
+
exports.isKeepAliveTag = isKeepAliveTag;
|
|
3559
|
+
exports.isStaticExpression = isStaticExpression;
|
|
3560
|
+
exports.isTeleportTag = isTeleportTag;
|
|
3561
|
+
exports.isTransitionGroupTag = isTransitionGroupTag;
|
|
3562
|
+
exports.isTransitionTag = isTransitionTag;
|
|
3563
|
+
exports.needsVaporCtx = needsVaporCtx;
|
|
3564
|
+
exports.parse = _vue_compiler_dom.parse;
|
|
3565
|
+
exports.parseValueDestructure = parseValueDestructure;
|
|
3566
|
+
exports.propToExpression = propToExpression;
|
|
3567
|
+
exports.transform = transform;
|
|
3568
|
+
exports.transformChildren = transformChildren;
|
|
3569
|
+
exports.transformComment = transformComment;
|
|
3570
|
+
exports.transformElement = transformElement;
|
|
3571
|
+
exports.transformSlotOutlet = transformSlotOutlet;
|
|
3572
|
+
exports.transformTemplateRef = transformTemplateRef;
|
|
3573
|
+
exports.transformText = transformText;
|
|
3574
|
+
exports.transformVBind = transformVBind;
|
|
3575
|
+
exports.transformVFor = transformVFor;
|
|
3576
|
+
exports.transformVHtml = transformVHtml;
|
|
3577
|
+
exports.transformVIf = transformVIf;
|
|
3578
|
+
exports.transformVModel = transformVModel;
|
|
3579
|
+
exports.transformVOn = transformVOn;
|
|
3580
|
+
exports.transformVOnce = transformVOnce;
|
|
3581
|
+
exports.transformVShow = transformVShow;
|
|
3582
|
+
exports.transformVSlot = transformVSlot;
|
|
3583
|
+
exports.transformVText = transformVText;
|
|
3584
|
+
exports.wrapTemplate = wrapTemplate;
|