@vue/compiler-vapor 3.6.0-alpha.4 → 3.6.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler-vapor.cjs.js +270 -178
- package/dist/compiler-vapor.d.ts +3 -4
- package/dist/compiler-vapor.esm-browser.js +310 -188
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-vapor v3.6.0-alpha.
|
|
2
|
+
* @vue/compiler-vapor v3.6.0-alpha.6
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -24,8 +24,7 @@ const newBlock = (node) => ({
|
|
|
24
24
|
effect: [],
|
|
25
25
|
operation: [],
|
|
26
26
|
returns: [],
|
|
27
|
-
tempId: 0
|
|
28
|
-
hasDeferredVShow: false
|
|
27
|
+
tempId: 0
|
|
29
28
|
});
|
|
30
29
|
function wrapTemplate(node, dirs) {
|
|
31
30
|
if (node.tagType === 3) {
|
|
@@ -282,10 +281,12 @@ function transform(node, options = {}) {
|
|
|
282
281
|
source: node.source,
|
|
283
282
|
template: /* @__PURE__ */ new Map(),
|
|
284
283
|
templateIndexMap: /* @__PURE__ */ new Map(),
|
|
284
|
+
rootTemplateIndexes: /* @__PURE__ */ new Set(),
|
|
285
285
|
component: /* @__PURE__ */ new Set(),
|
|
286
286
|
directive: /* @__PURE__ */ new Set(),
|
|
287
287
|
block: newBlock(node),
|
|
288
|
-
hasTemplateRef: false
|
|
288
|
+
hasTemplateRef: false,
|
|
289
|
+
hasDeferredVShow: false
|
|
289
290
|
};
|
|
290
291
|
const context = new TransformContext(ir, node, options);
|
|
291
292
|
transformNode(context);
|
|
@@ -778,8 +779,10 @@ function analyzeExpressions(expressions) {
|
|
|
778
779
|
exp.ast === null && registerVariable(exp.content, exp, true);
|
|
779
780
|
continue;
|
|
780
781
|
}
|
|
782
|
+
const seenParents = /* @__PURE__ */ new Set();
|
|
781
783
|
compilerDom.walkIdentifiers(exp.ast, (currentNode, parent, parentStack) => {
|
|
782
|
-
if (parent && isMemberExpression(parent)) {
|
|
784
|
+
if (parent && isMemberExpression(parent) && !seenParents.has(parent)) {
|
|
785
|
+
seenParents.add(parent);
|
|
783
786
|
const memberExp = extractMemberExpression(parent, (id) => {
|
|
784
787
|
registerVariable(id.name, exp, true, {
|
|
785
788
|
start: id.start,
|
|
@@ -881,7 +884,7 @@ function shouldDeclareVariable(name, expToVariableMap, exps) {
|
|
|
881
884
|
}
|
|
882
885
|
return true;
|
|
883
886
|
}
|
|
884
|
-
if (vars.
|
|
887
|
+
if (vars.every((v) => v.every((e, idx) => e === first[idx]))) {
|
|
885
888
|
return false;
|
|
886
889
|
}
|
|
887
890
|
return true;
|
|
@@ -890,7 +893,9 @@ function processRepeatedExpressions(context, expressions, varDeclarations, updat
|
|
|
890
893
|
const declarations = [];
|
|
891
894
|
const seenExp = expressions.reduce(
|
|
892
895
|
(acc, exp) => {
|
|
893
|
-
const
|
|
896
|
+
const vars = expToVariableMap.get(exp);
|
|
897
|
+
if (!vars) return acc;
|
|
898
|
+
const variables = vars.map((v) => v.name);
|
|
894
899
|
if (exp.ast && exp.ast.type !== "Identifier" && !(variables && variables.some((v) => updatedVariable.has(v)))) {
|
|
895
900
|
acc[exp.content] = (acc[exp.content] || 0) + 1;
|
|
896
901
|
}
|
|
@@ -1006,12 +1011,14 @@ function extractMemberExpression(exp, onIdentifier) {
|
|
|
1006
1011
|
const object = extractMemberExpression(exp.object, onIdentifier);
|
|
1007
1012
|
const prop = exp.computed ? `[${extractMemberExpression(exp.property, onIdentifier)}]` : `.${extractMemberExpression(exp.property, shared.NOOP)}`;
|
|
1008
1013
|
return `${object}${prop}`;
|
|
1014
|
+
case "TSNonNullExpression":
|
|
1015
|
+
return `${extractMemberExpression(exp.expression, onIdentifier)}`;
|
|
1009
1016
|
default:
|
|
1010
1017
|
return "";
|
|
1011
1018
|
}
|
|
1012
1019
|
}
|
|
1013
1020
|
const isMemberExpression = (node) => {
|
|
1014
|
-
return node.type === "MemberExpression" || node.type === "OptionalMemberExpression";
|
|
1021
|
+
return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "TSNonNullExpression";
|
|
1015
1022
|
};
|
|
1016
1023
|
|
|
1017
1024
|
function genSetEvent(oper, context) {
|
|
@@ -1020,7 +1027,7 @@ function genSetEvent(oper, context) {
|
|
|
1020
1027
|
const name = genName();
|
|
1021
1028
|
const handler = [
|
|
1022
1029
|
`${context.helper("createInvoker")}(`,
|
|
1023
|
-
...genEventHandler(context, value, modifiers),
|
|
1030
|
+
...genEventHandler(context, [value], modifiers),
|
|
1024
1031
|
`)`
|
|
1025
1032
|
];
|
|
1026
1033
|
const eventOptions = genEventOptions();
|
|
@@ -1077,37 +1084,47 @@ function genSetDynamicEvents(oper, context) {
|
|
|
1077
1084
|
)
|
|
1078
1085
|
];
|
|
1079
1086
|
}
|
|
1080
|
-
function genEventHandler(context,
|
|
1081
|
-
let handlerExp = [
|
|
1082
|
-
if (
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
if (
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1087
|
+
function genEventHandler(context, values, modifiers = { nonKeys: [], keys: [] }, extraWrap = false) {
|
|
1088
|
+
let handlerExp = [];
|
|
1089
|
+
if (values) {
|
|
1090
|
+
values.forEach((value, index) => {
|
|
1091
|
+
let exp = [];
|
|
1092
|
+
if (value && value.content.trim()) {
|
|
1093
|
+
if (compilerDom.isMemberExpression(value, context.options)) {
|
|
1094
|
+
exp = genExpression(value, context);
|
|
1095
|
+
if (!isConstantBinding(value, context) && !extraWrap) {
|
|
1096
|
+
const isTSNode = value.ast && compilerDom.TS_NODE_TYPES.includes(value.ast.type);
|
|
1097
|
+
exp = [
|
|
1098
|
+
`e => `,
|
|
1099
|
+
isTSNode ? "(" : "",
|
|
1100
|
+
...exp,
|
|
1101
|
+
isTSNode ? ")" : "",
|
|
1102
|
+
`(e)`
|
|
1103
|
+
];
|
|
1104
|
+
}
|
|
1105
|
+
} else if (compilerDom.isFnExpression(value, context.options)) {
|
|
1106
|
+
exp = genExpression(value, context);
|
|
1107
|
+
} else {
|
|
1108
|
+
const referencesEvent = value.content.includes("$event");
|
|
1109
|
+
const hasMultipleStatements = value.content.includes(`;`);
|
|
1110
|
+
const expr = referencesEvent ? context.withId(() => genExpression(value, context), {
|
|
1111
|
+
$event: null
|
|
1112
|
+
}) : genExpression(value, context);
|
|
1113
|
+
exp = [
|
|
1114
|
+
referencesEvent ? "$event => " : "() => ",
|
|
1115
|
+
hasMultipleStatements ? "{" : "(",
|
|
1116
|
+
...expr,
|
|
1117
|
+
hasMultipleStatements ? "}" : ")"
|
|
1118
|
+
];
|
|
1119
|
+
}
|
|
1120
|
+
handlerExp = handlerExp.concat([index !== 0 ? ", " : "", ...exp]);
|
|
1094
1121
|
}
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
const referencesEvent = value.content.includes("$event");
|
|
1099
|
-
const hasMultipleStatements = value.content.includes(`;`);
|
|
1100
|
-
const expr = referencesEvent ? context.withId(() => genExpression(value, context), {
|
|
1101
|
-
$event: null
|
|
1102
|
-
}) : genExpression(value, context);
|
|
1103
|
-
handlerExp = [
|
|
1104
|
-
referencesEvent ? "$event => " : "() => ",
|
|
1105
|
-
hasMultipleStatements ? "{" : "(",
|
|
1106
|
-
...expr,
|
|
1107
|
-
hasMultipleStatements ? "}" : ")"
|
|
1108
|
-
];
|
|
1122
|
+
});
|
|
1123
|
+
if (values.length > 1) {
|
|
1124
|
+
handlerExp = ["[", ...handlerExp, "]"];
|
|
1109
1125
|
}
|
|
1110
1126
|
}
|
|
1127
|
+
if (handlerExp.length === 0) handlerExp = ["() => {}"];
|
|
1111
1128
|
const { keys, nonKeys } = modifiers;
|
|
1112
1129
|
if (nonKeys.length)
|
|
1113
1130
|
handlerExp = genWithModifiers(context, handlerExp, nonKeys);
|
|
@@ -1148,35 +1165,19 @@ function genFor(oper, context) {
|
|
|
1148
1165
|
component,
|
|
1149
1166
|
onlyChild
|
|
1150
1167
|
} = oper;
|
|
1151
|
-
|
|
1168
|
+
const rawValue = value && value.content;
|
|
1152
1169
|
const rawKey = key && key.content;
|
|
1153
1170
|
const rawIndex = index && index.content;
|
|
1154
1171
|
const sourceExpr = ["() => (", ...genExpression(source, context), ")"];
|
|
1155
|
-
const idToPathMap = parseValueDestructure();
|
|
1172
|
+
const idToPathMap = parseValueDestructure(value, context);
|
|
1156
1173
|
const [depth, exitScope] = context.enterScope();
|
|
1157
|
-
const idMap = {};
|
|
1158
1174
|
const itemVar = `_for_item${depth}`;
|
|
1175
|
+
const idMap = buildDestructureIdMap(
|
|
1176
|
+
idToPathMap,
|
|
1177
|
+
`${itemVar}.value`,
|
|
1178
|
+
context.options.expressionPlugins
|
|
1179
|
+
);
|
|
1159
1180
|
idMap[itemVar] = null;
|
|
1160
|
-
idToPathMap.forEach((pathInfo, id2) => {
|
|
1161
|
-
let path = `${itemVar}.value${pathInfo ? pathInfo.path : ""}`;
|
|
1162
|
-
if (pathInfo) {
|
|
1163
|
-
if (pathInfo.helper) {
|
|
1164
|
-
idMap[pathInfo.helper] = null;
|
|
1165
|
-
path = `${pathInfo.helper}(${path}, ${pathInfo.helperArgs})`;
|
|
1166
|
-
}
|
|
1167
|
-
if (pathInfo.dynamic) {
|
|
1168
|
-
const node = idMap[id2] = compilerDom.createSimpleExpression(path);
|
|
1169
|
-
const plugins = context.options.expressionPlugins;
|
|
1170
|
-
node.ast = parser.parseExpression(`(${path})`, {
|
|
1171
|
-
plugins: plugins ? [...plugins, "typescript"] : ["typescript"]
|
|
1172
|
-
});
|
|
1173
|
-
} else {
|
|
1174
|
-
idMap[id2] = path;
|
|
1175
|
-
}
|
|
1176
|
-
} else {
|
|
1177
|
-
idMap[id2] = path;
|
|
1178
|
-
}
|
|
1179
|
-
});
|
|
1180
1181
|
const args = [itemVar];
|
|
1181
1182
|
if (rawKey) {
|
|
1182
1183
|
const keyVar = `_for_key${depth}`;
|
|
@@ -1274,77 +1275,6 @@ function genFor(oper, context) {
|
|
|
1274
1275
|
// todo: hydrationNode
|
|
1275
1276
|
)
|
|
1276
1277
|
];
|
|
1277
|
-
function parseValueDestructure() {
|
|
1278
|
-
const map = /* @__PURE__ */ new Map();
|
|
1279
|
-
if (value) {
|
|
1280
|
-
rawValue = value && value.content;
|
|
1281
|
-
if (value.ast) {
|
|
1282
|
-
compilerDom.walkIdentifiers(
|
|
1283
|
-
value.ast,
|
|
1284
|
-
(id2, _, parentStack, ___, isLocal) => {
|
|
1285
|
-
if (isLocal) {
|
|
1286
|
-
let path = "";
|
|
1287
|
-
let isDynamic = false;
|
|
1288
|
-
let helper2;
|
|
1289
|
-
let helperArgs;
|
|
1290
|
-
for (let i = 0; i < parentStack.length; i++) {
|
|
1291
|
-
const parent = parentStack[i];
|
|
1292
|
-
const child = parentStack[i + 1] || id2;
|
|
1293
|
-
if (parent.type === "ObjectProperty" && parent.value === child) {
|
|
1294
|
-
if (parent.key.type === "StringLiteral") {
|
|
1295
|
-
path += `[${JSON.stringify(parent.key.value)}]`;
|
|
1296
|
-
} else if (parent.computed) {
|
|
1297
|
-
isDynamic = true;
|
|
1298
|
-
path += `[${value.content.slice(
|
|
1299
|
-
parent.key.start - 1,
|
|
1300
|
-
parent.key.end - 1
|
|
1301
|
-
)}]`;
|
|
1302
|
-
} else {
|
|
1303
|
-
path += `.${parent.key.name}`;
|
|
1304
|
-
}
|
|
1305
|
-
} else if (parent.type === "ArrayPattern") {
|
|
1306
|
-
const index2 = parent.elements.indexOf(child);
|
|
1307
|
-
if (child.type === "RestElement") {
|
|
1308
|
-
path += `.slice(${index2})`;
|
|
1309
|
-
} else {
|
|
1310
|
-
path += `[${index2}]`;
|
|
1311
|
-
}
|
|
1312
|
-
} else if (parent.type === "ObjectPattern" && child.type === "RestElement") {
|
|
1313
|
-
helper2 = context.helper("getRestElement");
|
|
1314
|
-
helperArgs = "[" + parent.properties.filter((p) => p.type === "ObjectProperty").map((p) => {
|
|
1315
|
-
if (p.key.type === "StringLiteral") {
|
|
1316
|
-
return JSON.stringify(p.key.value);
|
|
1317
|
-
} else if (p.computed) {
|
|
1318
|
-
isDynamic = true;
|
|
1319
|
-
return value.content.slice(
|
|
1320
|
-
p.key.start - 1,
|
|
1321
|
-
p.key.end - 1
|
|
1322
|
-
);
|
|
1323
|
-
} else {
|
|
1324
|
-
return JSON.stringify(p.key.name);
|
|
1325
|
-
}
|
|
1326
|
-
}).join(", ") + "]";
|
|
1327
|
-
}
|
|
1328
|
-
if (child.type === "AssignmentPattern" && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
|
|
1329
|
-
isDynamic = true;
|
|
1330
|
-
helper2 = context.helper("getDefaultValue");
|
|
1331
|
-
helperArgs = value.content.slice(
|
|
1332
|
-
child.right.start - 1,
|
|
1333
|
-
child.right.end - 1
|
|
1334
|
-
);
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
map.set(id2.name, { path, dynamic: isDynamic, helper: helper2, helperArgs });
|
|
1338
|
-
}
|
|
1339
|
-
},
|
|
1340
|
-
true
|
|
1341
|
-
);
|
|
1342
|
-
} else {
|
|
1343
|
-
map.set(rawValue, null);
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
return map;
|
|
1347
|
-
}
|
|
1348
1278
|
function genCallback(expr) {
|
|
1349
1279
|
if (!expr) return false;
|
|
1350
1280
|
const res = context.withId(
|
|
@@ -1371,6 +1301,98 @@ function genFor(oper, context) {
|
|
|
1371
1301
|
return idMap2;
|
|
1372
1302
|
}
|
|
1373
1303
|
}
|
|
1304
|
+
function parseValueDestructure(value, context) {
|
|
1305
|
+
const map = /* @__PURE__ */ new Map();
|
|
1306
|
+
if (value) {
|
|
1307
|
+
const rawValue = value.content;
|
|
1308
|
+
if (value.ast) {
|
|
1309
|
+
compilerDom.walkIdentifiers(
|
|
1310
|
+
value.ast,
|
|
1311
|
+
(id, _, parentStack, ___, isLocal) => {
|
|
1312
|
+
if (isLocal) {
|
|
1313
|
+
let path = "";
|
|
1314
|
+
let isDynamic = false;
|
|
1315
|
+
let helper;
|
|
1316
|
+
let helperArgs;
|
|
1317
|
+
for (let i = 0; i < parentStack.length; i++) {
|
|
1318
|
+
const parent = parentStack[i];
|
|
1319
|
+
const child = parentStack[i + 1] || id;
|
|
1320
|
+
if (parent.type === "ObjectProperty" && parent.value === child) {
|
|
1321
|
+
if (parent.key.type === "StringLiteral") {
|
|
1322
|
+
path += `[${JSON.stringify(parent.key.value)}]`;
|
|
1323
|
+
} else if (parent.computed) {
|
|
1324
|
+
isDynamic = true;
|
|
1325
|
+
path += `[${rawValue.slice(
|
|
1326
|
+
parent.key.start - 1,
|
|
1327
|
+
parent.key.end - 1
|
|
1328
|
+
)}]`;
|
|
1329
|
+
} else {
|
|
1330
|
+
path += `.${parent.key.name}`;
|
|
1331
|
+
}
|
|
1332
|
+
} else if (parent.type === "ArrayPattern") {
|
|
1333
|
+
const index = parent.elements.indexOf(child);
|
|
1334
|
+
if (child.type === "RestElement") {
|
|
1335
|
+
path += `.slice(${index})`;
|
|
1336
|
+
} else {
|
|
1337
|
+
path += `[${index}]`;
|
|
1338
|
+
}
|
|
1339
|
+
} else if (parent.type === "ObjectPattern" && child.type === "RestElement") {
|
|
1340
|
+
helper = context.helper("getRestElement");
|
|
1341
|
+
helperArgs = "[" + parent.properties.filter((p) => p.type === "ObjectProperty").map((p) => {
|
|
1342
|
+
if (p.key.type === "StringLiteral") {
|
|
1343
|
+
return JSON.stringify(p.key.value);
|
|
1344
|
+
} else if (p.computed) {
|
|
1345
|
+
isDynamic = true;
|
|
1346
|
+
return rawValue.slice(p.key.start - 1, p.key.end - 1);
|
|
1347
|
+
} else {
|
|
1348
|
+
return JSON.stringify(p.key.name);
|
|
1349
|
+
}
|
|
1350
|
+
}).join(", ") + "]";
|
|
1351
|
+
}
|
|
1352
|
+
if (child.type === "AssignmentPattern" && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
|
|
1353
|
+
isDynamic = true;
|
|
1354
|
+
helper = context.helper("getDefaultValue");
|
|
1355
|
+
helperArgs = rawValue.slice(
|
|
1356
|
+
child.right.start - 1,
|
|
1357
|
+
child.right.end - 1
|
|
1358
|
+
);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
map.set(id.name, { path, dynamic: isDynamic, helper, helperArgs });
|
|
1362
|
+
}
|
|
1363
|
+
},
|
|
1364
|
+
true
|
|
1365
|
+
);
|
|
1366
|
+
} else if (rawValue) {
|
|
1367
|
+
map.set(rawValue, null);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
return map;
|
|
1371
|
+
}
|
|
1372
|
+
function buildDestructureIdMap(idToPathMap, baseAccessor, plugins) {
|
|
1373
|
+
const idMap = {};
|
|
1374
|
+
idToPathMap.forEach((pathInfo, id) => {
|
|
1375
|
+
let path = baseAccessor;
|
|
1376
|
+
if (pathInfo) {
|
|
1377
|
+
path = `${baseAccessor}${pathInfo.path}`;
|
|
1378
|
+
if (pathInfo.helper) {
|
|
1379
|
+
idMap[pathInfo.helper] = null;
|
|
1380
|
+
path = pathInfo.helperArgs ? `${pathInfo.helper}(${path}, ${pathInfo.helperArgs})` : `${pathInfo.helper}(${path})`;
|
|
1381
|
+
}
|
|
1382
|
+
if (pathInfo.dynamic) {
|
|
1383
|
+
const node = idMap[id] = compilerDom.createSimpleExpression(path);
|
|
1384
|
+
node.ast = parser.parseExpression(`(${path})`, {
|
|
1385
|
+
plugins: plugins ? [...plugins, "typescript"] : ["typescript"]
|
|
1386
|
+
});
|
|
1387
|
+
} else {
|
|
1388
|
+
idMap[id] = path;
|
|
1389
|
+
}
|
|
1390
|
+
} else {
|
|
1391
|
+
idMap[id] = path;
|
|
1392
|
+
}
|
|
1393
|
+
});
|
|
1394
|
+
return idMap;
|
|
1395
|
+
}
|
|
1374
1396
|
function matchPatterns(render, keyProp, idMap) {
|
|
1375
1397
|
const selectorPatterns = [];
|
|
1376
1398
|
const keyOnlyBindingPatterns = [];
|
|
@@ -1582,7 +1604,6 @@ function genDynamicProps$1(oper, context) {
|
|
|
1582
1604
|
helper("setDynamicProps"),
|
|
1583
1605
|
`n${oper.element}`,
|
|
1584
1606
|
genMulti(DELIMITERS_ARRAY, ...values),
|
|
1585
|
-
oper.root && "true",
|
|
1586
1607
|
isSVG && "true"
|
|
1587
1608
|
)
|
|
1588
1609
|
];
|
|
@@ -1612,6 +1633,7 @@ function genPropKey({ key: node, modifier, runtimeCamelize, handler, handlerModi
|
|
|
1612
1633
|
}
|
|
1613
1634
|
let key = genExpression(node, context);
|
|
1614
1635
|
if (runtimeCamelize) {
|
|
1636
|
+
key.push(' || ""');
|
|
1615
1637
|
key = genCall(helper("camelize"), key);
|
|
1616
1638
|
}
|
|
1617
1639
|
if (handler) {
|
|
@@ -1853,7 +1875,7 @@ function genCreateComponent(operation, context) {
|
|
|
1853
1875
|
const rawProps = context.withId(() => genRawProps(props, context), ids);
|
|
1854
1876
|
const inlineHandlers = handlers.reduce(
|
|
1855
1877
|
(acc, { name, value }) => {
|
|
1856
|
-
const handler = genEventHandler(context, value, void 0, false);
|
|
1878
|
+
const handler = genEventHandler(context, [value], void 0, false);
|
|
1857
1879
|
return [...acc, `const ${name} = `, ...handler, NEWLINE];
|
|
1858
1880
|
},
|
|
1859
1881
|
[]
|
|
@@ -1987,7 +2009,7 @@ function genProp(prop, context, isStatic) {
|
|
|
1987
2009
|
": ",
|
|
1988
2010
|
...prop.handler ? genEventHandler(
|
|
1989
2011
|
context,
|
|
1990
|
-
prop.values
|
|
2012
|
+
prop.values,
|
|
1991
2013
|
prop.handlerModifiers,
|
|
1992
2014
|
true
|
|
1993
2015
|
) : isStatic ? ["() => (", ...values, ")"] : values,
|
|
@@ -2115,35 +2137,29 @@ function genConditionalSlot(slot, context) {
|
|
|
2115
2137
|
];
|
|
2116
2138
|
}
|
|
2117
2139
|
function genSlotBlockWithProps(oper, context) {
|
|
2118
|
-
let isDestructureAssignment = false;
|
|
2119
|
-
let rawProps;
|
|
2120
2140
|
let propsName;
|
|
2121
2141
|
let exitScope;
|
|
2122
2142
|
let depth;
|
|
2123
2143
|
const { props, key, node } = oper;
|
|
2124
|
-
const
|
|
2144
|
+
const idToPathMap = props ? parseValueDestructure(props, context) : /* @__PURE__ */ new Map();
|
|
2125
2145
|
if (props) {
|
|
2126
|
-
|
|
2127
|
-
if (isDestructureAssignment = !!props.ast) {
|
|
2146
|
+
if (props.ast) {
|
|
2128
2147
|
[depth, exitScope] = context.enterScope();
|
|
2129
2148
|
propsName = `_slotProps${depth}`;
|
|
2130
|
-
compilerDom.walkIdentifiers(
|
|
2131
|
-
props.ast,
|
|
2132
|
-
(id, _, __, ___, isLocal) => {
|
|
2133
|
-
if (isLocal) idsOfProps.add(id.name);
|
|
2134
|
-
},
|
|
2135
|
-
true
|
|
2136
|
-
);
|
|
2137
2149
|
} else {
|
|
2138
|
-
|
|
2150
|
+
propsName = props.content;
|
|
2139
2151
|
}
|
|
2140
2152
|
}
|
|
2141
|
-
const idMap =
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2153
|
+
const idMap = idToPathMap.size ? buildDestructureIdMap(
|
|
2154
|
+
idToPathMap,
|
|
2155
|
+
propsName || "",
|
|
2156
|
+
context.options.expressionPlugins
|
|
2157
|
+
) : {};
|
|
2158
|
+
if (propsName) {
|
|
2159
|
+
idMap[propsName] = null;
|
|
2160
|
+
}
|
|
2145
2161
|
let blockFn = context.withId(
|
|
2146
|
-
() => genBlock(oper, context, [propsName]),
|
|
2162
|
+
() => genBlock(oper, context, propsName ? [propsName] : []),
|
|
2147
2163
|
idMap
|
|
2148
2164
|
);
|
|
2149
2165
|
exitScope && exitScope();
|
|
@@ -2164,14 +2180,69 @@ function genSlotBlockWithProps(oper, context) {
|
|
|
2164
2180
|
];
|
|
2165
2181
|
}
|
|
2166
2182
|
if (node.type === 1) {
|
|
2167
|
-
|
|
2183
|
+
if (needsVaporCtx(oper)) {
|
|
2184
|
+
blockFn = [`${context.helper("withVaporCtx")}(`, ...blockFn, `)`];
|
|
2185
|
+
}
|
|
2168
2186
|
}
|
|
2169
2187
|
return blockFn;
|
|
2170
2188
|
}
|
|
2189
|
+
function needsVaporCtx(block) {
|
|
2190
|
+
return hasComponentOrSlotInBlock(block);
|
|
2191
|
+
}
|
|
2192
|
+
function hasComponentOrSlotInBlock(block) {
|
|
2193
|
+
if (hasComponentOrSlotInOperations(block.operation)) return true;
|
|
2194
|
+
return hasComponentOrSlotInDynamic(block.dynamic);
|
|
2195
|
+
}
|
|
2196
|
+
function hasComponentOrSlotInDynamic(dynamic) {
|
|
2197
|
+
if (dynamic.operation) {
|
|
2198
|
+
const type = dynamic.operation.type;
|
|
2199
|
+
if (type === 11 || type === 12) {
|
|
2200
|
+
return true;
|
|
2201
|
+
}
|
|
2202
|
+
if (type === 15) {
|
|
2203
|
+
if (hasComponentOrSlotInIf(dynamic.operation)) return true;
|
|
2204
|
+
}
|
|
2205
|
+
if (type === 16) {
|
|
2206
|
+
if (hasComponentOrSlotInBlock(dynamic.operation.render))
|
|
2207
|
+
return true;
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
for (const child of dynamic.children) {
|
|
2211
|
+
if (hasComponentOrSlotInDynamic(child)) return true;
|
|
2212
|
+
}
|
|
2213
|
+
return false;
|
|
2214
|
+
}
|
|
2215
|
+
function hasComponentOrSlotInOperations(operations) {
|
|
2216
|
+
for (const op of operations) {
|
|
2217
|
+
switch (op.type) {
|
|
2218
|
+
case 11:
|
|
2219
|
+
case 12:
|
|
2220
|
+
return true;
|
|
2221
|
+
case 15:
|
|
2222
|
+
if (hasComponentOrSlotInIf(op)) return true;
|
|
2223
|
+
break;
|
|
2224
|
+
case 16:
|
|
2225
|
+
if (hasComponentOrSlotInBlock(op.render)) return true;
|
|
2226
|
+
break;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
return false;
|
|
2230
|
+
}
|
|
2231
|
+
function hasComponentOrSlotInIf(node) {
|
|
2232
|
+
if (hasComponentOrSlotInBlock(node.positive)) return true;
|
|
2233
|
+
if (node.negative) {
|
|
2234
|
+
if ("positive" in node.negative) {
|
|
2235
|
+
return hasComponentOrSlotInIf(node.negative);
|
|
2236
|
+
} else {
|
|
2237
|
+
return hasComponentOrSlotInBlock(node.negative);
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
return false;
|
|
2241
|
+
}
|
|
2171
2242
|
|
|
2172
2243
|
function genSlotOutlet(oper, context) {
|
|
2173
2244
|
const { helper } = context;
|
|
2174
|
-
const { id, name, fallback, noSlotted } = oper;
|
|
2245
|
+
const { id, name, fallback, noSlotted, once } = oper;
|
|
2175
2246
|
const [frag, push] = buildCodeFragment();
|
|
2176
2247
|
const nameExpr = name.isStatic ? genExpression(name, context) : ["() => (", ...genExpression(name, context), ")"];
|
|
2177
2248
|
let fallbackArg;
|
|
@@ -2186,8 +2257,10 @@ function genSlotOutlet(oper, context) {
|
|
|
2186
2257
|
nameExpr,
|
|
2187
2258
|
genRawProps(oper.props, context) || "null",
|
|
2188
2259
|
fallbackArg,
|
|
2189
|
-
noSlotted && "true"
|
|
2260
|
+
noSlotted && "true",
|
|
2190
2261
|
// noSlotted
|
|
2262
|
+
once && "true"
|
|
2263
|
+
// v-once
|
|
2191
2264
|
)
|
|
2192
2265
|
);
|
|
2193
2266
|
return frag;
|
|
@@ -2319,7 +2392,7 @@ function genInsertionState(operation, context) {
|
|
|
2319
2392
|
];
|
|
2320
2393
|
}
|
|
2321
2394
|
|
|
2322
|
-
function genTemplates(templates,
|
|
2395
|
+
function genTemplates(templates, rootIndexes, context) {
|
|
2323
2396
|
const result = [];
|
|
2324
2397
|
let i = 0;
|
|
2325
2398
|
templates.forEach((ns, template) => {
|
|
@@ -2330,7 +2403,7 @@ function genTemplates(templates, rootIndex, context) {
|
|
|
2330
2403
|
// replace import expressions with string concatenation
|
|
2331
2404
|
IMPORT_EXPR_RE,
|
|
2332
2405
|
`" + $1 + "`
|
|
2333
|
-
)}${i
|
|
2406
|
+
)}${rootIndexes.has(i) ? ", true" : ns ? ", false" : ""}${ns ? `, ${ns}` : ""})
|
|
2334
2407
|
`
|
|
2335
2408
|
);
|
|
2336
2409
|
i++;
|
|
@@ -2437,9 +2510,6 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
2437
2510
|
const [frag, push] = buildCodeFragment();
|
|
2438
2511
|
const { dynamic, effect, operation, returns, key } = block;
|
|
2439
2512
|
const resetBlock = context.enterBlock(block);
|
|
2440
|
-
if (block.hasDeferredVShow) {
|
|
2441
|
-
push(NEWLINE, `const deferredApplyVShows = []`);
|
|
2442
|
-
}
|
|
2443
2513
|
if (root) {
|
|
2444
2514
|
for (let name of context.ir.component) {
|
|
2445
2515
|
const id = compilerDom.toValidAssetId(name, "component");
|
|
@@ -2468,7 +2538,7 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
2468
2538
|
}
|
|
2469
2539
|
push(...genOperations(operation, context));
|
|
2470
2540
|
push(...genEffects(effect, context, genEffectsExtraFrag));
|
|
2471
|
-
if (
|
|
2541
|
+
if (root && context.ir.hasDeferredVShow) {
|
|
2472
2542
|
push(NEWLINE, `deferredApplyVShows.forEach(fn => fn())`);
|
|
2473
2543
|
}
|
|
2474
2544
|
if (dynamic.needsKey) {
|
|
@@ -2624,13 +2694,16 @@ function generate(ir, options = {}) {
|
|
|
2624
2694
|
`const ${setTemplateRefIdent} = ${context.helper("createTemplateRefSetter")}()`
|
|
2625
2695
|
);
|
|
2626
2696
|
}
|
|
2697
|
+
if (ir.hasDeferredVShow) {
|
|
2698
|
+
push(NEWLINE, `const deferredApplyVShows = []`);
|
|
2699
|
+
}
|
|
2627
2700
|
push(...genBlockContent(ir.block, context, true));
|
|
2628
2701
|
push(INDENT_END, NEWLINE);
|
|
2629
2702
|
if (!inline) {
|
|
2630
2703
|
push("}");
|
|
2631
2704
|
}
|
|
2632
2705
|
const delegates = genDelegates(context);
|
|
2633
|
-
const templates = genTemplates(ir.template, ir.
|
|
2706
|
+
const templates = genTemplates(ir.template, ir.rootTemplateIndexes, context);
|
|
2634
2707
|
const imports = genHelperImports(context) + genAssetImports(context);
|
|
2635
2708
|
const preamble = imports + templates + delegates;
|
|
2636
2709
|
const newlineCount = [...preamble].filter((c) => c === "\n").length;
|
|
@@ -2777,6 +2850,11 @@ const isReservedProp = /* @__PURE__ */ shared.makeMap(
|
|
|
2777
2850
|
const transformElement = (node, context) => {
|
|
2778
2851
|
let effectIndex = context.block.effect.length;
|
|
2779
2852
|
const getEffectIndex = () => effectIndex++;
|
|
2853
|
+
let parentSlots;
|
|
2854
|
+
if (node.type === 1 && (node.tagType === 1 || context.options.isCustomElement(node.tag))) {
|
|
2855
|
+
parentSlots = context.slots;
|
|
2856
|
+
context.slots = [];
|
|
2857
|
+
}
|
|
2780
2858
|
return function postTransformElement() {
|
|
2781
2859
|
({ node } = context);
|
|
2782
2860
|
if (!(node.type === 1 && (node.tagType === 0 || node.tagType === 1)))
|
|
@@ -2791,11 +2869,7 @@ const transformElement = (node, context) => {
|
|
|
2791
2869
|
isDynamicComponent,
|
|
2792
2870
|
getEffectIndex
|
|
2793
2871
|
);
|
|
2794
|
-
|
|
2795
|
-
while (parent && parent.parent && parent.node.type === 1 && parent.node.tagType === 3) {
|
|
2796
|
-
parent = parent.parent;
|
|
2797
|
-
}
|
|
2798
|
-
const singleRoot = context.root === parent && parent.node.children.filter((child) => child.type !== 3).length === 1 || isCustomElement;
|
|
2872
|
+
const singleRoot = isSingleRoot(context);
|
|
2799
2873
|
if (isComponent) {
|
|
2800
2874
|
transformComponentElement(
|
|
2801
2875
|
node,
|
|
@@ -2814,8 +2888,27 @@ const transformElement = (node, context) => {
|
|
|
2814
2888
|
getEffectIndex
|
|
2815
2889
|
);
|
|
2816
2890
|
}
|
|
2891
|
+
if (parentSlots) {
|
|
2892
|
+
context.slots = parentSlots;
|
|
2893
|
+
}
|
|
2817
2894
|
};
|
|
2818
2895
|
};
|
|
2896
|
+
function isSingleRoot(context) {
|
|
2897
|
+
if (context.inVFor) {
|
|
2898
|
+
return false;
|
|
2899
|
+
}
|
|
2900
|
+
let { parent } = context;
|
|
2901
|
+
if (parent && !(compilerDom.hasSingleChild(parent.node) || compilerDom.isSingleIfBlock(parent.node))) {
|
|
2902
|
+
return false;
|
|
2903
|
+
}
|
|
2904
|
+
while (parent && parent.parent && parent.node.type === 1 && parent.node.tagType === 3) {
|
|
2905
|
+
parent = parent.parent;
|
|
2906
|
+
if (!(compilerDom.hasSingleChild(parent.node) || compilerDom.isSingleIfBlock(parent.node))) {
|
|
2907
|
+
return false;
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2910
|
+
return context.root === parent;
|
|
2911
|
+
}
|
|
2819
2912
|
function transformComponentElement(node, propsResult, singleRoot, context, isDynamicComponent, isCustomElement) {
|
|
2820
2913
|
const dynamicComponent = isDynamicComponent ? resolveDynamicComponent(node) : void 0;
|
|
2821
2914
|
let { tag } = node;
|
|
@@ -2853,7 +2946,7 @@ function transformComponentElement(node, propsResult, singleRoot, context, isDyn
|
|
|
2853
2946
|
tag,
|
|
2854
2947
|
props: propsResult[0] ? propsResult[1] : [propsResult[1]],
|
|
2855
2948
|
asset,
|
|
2856
|
-
root: singleRoot
|
|
2949
|
+
root: singleRoot,
|
|
2857
2950
|
slots: [...context.slots],
|
|
2858
2951
|
once: context.inVOnce,
|
|
2859
2952
|
dynamic: dynamicComponent,
|
|
@@ -2904,7 +2997,6 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
2904
2997
|
type: 3,
|
|
2905
2998
|
element: context.reference(),
|
|
2906
2999
|
props: dynamicArgs,
|
|
2907
|
-
root: singleRoot,
|
|
2908
3000
|
tag
|
|
2909
3001
|
},
|
|
2910
3002
|
getEffectIndex
|
|
@@ -2928,7 +3020,6 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
2928
3020
|
type: 2,
|
|
2929
3021
|
element: context.reference(),
|
|
2930
3022
|
prop,
|
|
2931
|
-
root: singleRoot,
|
|
2932
3023
|
tag
|
|
2933
3024
|
},
|
|
2934
3025
|
getEffectIndex
|
|
@@ -2941,7 +3032,7 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
2941
3032
|
template += `</${tag}>`;
|
|
2942
3033
|
}
|
|
2943
3034
|
if (singleRoot) {
|
|
2944
|
-
context.ir.
|
|
3035
|
+
context.ir.rootTemplateIndexes.add(context.ir.template.size);
|
|
2945
3036
|
}
|
|
2946
3037
|
if (context.parent && context.parent.node.type === 1 && !compilerDom.isValidHTMLNesting(context.parent.node.tag, tag)) {
|
|
2947
3038
|
context.reference();
|
|
@@ -3074,7 +3165,7 @@ function dedupeProperties(results) {
|
|
|
3074
3165
|
const name = prop.key.content;
|
|
3075
3166
|
const existing = knownProps.get(name);
|
|
3076
3167
|
if (existing && existing.handler === prop.handler) {
|
|
3077
|
-
if (name === "style" || name === "class") {
|
|
3168
|
+
if (name === "style" || name === "class" || prop.handler) {
|
|
3078
3169
|
mergePropValues(existing, prop);
|
|
3079
3170
|
}
|
|
3080
3171
|
} else {
|
|
@@ -3252,6 +3343,9 @@ const transformVOn = (dir, node, context) => {
|
|
|
3252
3343
|
keyOverride = ["click", "contextmenu"];
|
|
3253
3344
|
}
|
|
3254
3345
|
}
|
|
3346
|
+
if (keyModifiers.length && compilerDom.isStaticExp(arg) && !compilerDom.isKeyboardEvent(`on${arg.content.toLowerCase()}`)) {
|
|
3347
|
+
keyModifiers.length = 0;
|
|
3348
|
+
}
|
|
3255
3349
|
if (isComponent || isSlotOutlet) {
|
|
3256
3350
|
const handler = exp || EMPTY_EXPRESSION;
|
|
3257
3351
|
return {
|
|
@@ -3305,7 +3399,7 @@ const transformVShow = (dir, node, context) => {
|
|
|
3305
3399
|
if (parentNode && parentNode.type === 1) {
|
|
3306
3400
|
shouldDeferred = !!(isTransitionTag(parentNode.tag) && findProp(parentNode, "appear", false, true));
|
|
3307
3401
|
if (shouldDeferred) {
|
|
3308
|
-
context.
|
|
3402
|
+
context.ir.hasDeferredVShow = true;
|
|
3309
3403
|
}
|
|
3310
3404
|
}
|
|
3311
3405
|
context.registerOperation({
|
|
@@ -3578,7 +3672,7 @@ function getSiblingIf(context, reverse) {
|
|
|
3578
3672
|
let i = siblings.indexOf(context.node);
|
|
3579
3673
|
while (reverse ? --i >= 0 : ++i < siblings.length) {
|
|
3580
3674
|
sibling = siblings[i];
|
|
3581
|
-
if (!
|
|
3675
|
+
if (!compilerDom.isCommentOrWhitespace(sibling)) {
|
|
3582
3676
|
break;
|
|
3583
3677
|
}
|
|
3584
3678
|
}
|
|
@@ -3588,9 +3682,6 @@ function getSiblingIf(context, reverse) {
|
|
|
3588
3682
|
return sibling;
|
|
3589
3683
|
}
|
|
3590
3684
|
}
|
|
3591
|
-
function isCommentLike(node) {
|
|
3592
|
-
return node.type === 3 || node.type === 2 && !node.content.trim().length;
|
|
3593
|
-
}
|
|
3594
3685
|
|
|
3595
3686
|
const transformVIf = createStructuralDirectiveTransform(
|
|
3596
3687
|
["if", "else", "else-if"],
|
|
@@ -3814,7 +3905,8 @@ const transformSlotOutlet = (node, context) => {
|
|
|
3814
3905
|
name: slotName,
|
|
3815
3906
|
props: irProps,
|
|
3816
3907
|
fallback,
|
|
3817
|
-
noSlotted: !!(context.options.scopeId && !context.options.slotted)
|
|
3908
|
+
noSlotted: !!(context.options.scopeId && !context.options.slotted),
|
|
3909
|
+
once: context.inVOnce
|
|
3818
3910
|
};
|
|
3819
3911
|
};
|
|
3820
3912
|
};
|