@vue/compiler-vapor 3.6.0-beta.16 → 3.6.0-beta.17
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 +399 -177
- package/dist/compiler-vapor.d.ts +11 -8
- package/dist/compiler-vapor.esm-browser.js +389 -181
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-vapor v3.6.0-beta.
|
|
2
|
+
* @vue/compiler-vapor v3.6.0-beta.17
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -152,7 +152,7 @@ const EMPTY_EXPRESSION = (0, _vue_compiler_dom.createSimpleExpression)("", true)
|
|
|
152
152
|
//#region packages/compiler-vapor/src/utils.ts
|
|
153
153
|
const findProp$1 = _vue_compiler_dom.findProp;
|
|
154
154
|
/** find directive */
|
|
155
|
-
const findDir$
|
|
155
|
+
const findDir$4 = _vue_compiler_dom.findDir;
|
|
156
156
|
function propToExpression(prop) {
|
|
157
157
|
return prop.type === 6 ? prop.value ? (0, _vue_compiler_dom.createSimpleExpression)(prop.value.content, true, prop.value.loc) : EMPTY_EXPRESSION : prop.exp;
|
|
158
158
|
}
|
|
@@ -230,6 +230,7 @@ function getBlockShape(block) {
|
|
|
230
230
|
//#endregion
|
|
231
231
|
//#region packages/compiler-vapor/src/transform.ts
|
|
232
232
|
const generatedVarRE = /^[nxr](\d+)$/;
|
|
233
|
+
const childContextInfoCache = /* @__PURE__ */ new WeakMap();
|
|
233
234
|
var TransformContext = class TransformContext {
|
|
234
235
|
constructor(ir, node, options = {}) {
|
|
235
236
|
this.ir = ir;
|
|
@@ -255,6 +256,7 @@ var TransformContext = class TransformContext {
|
|
|
255
256
|
this.operationIndex = this.block.operation.length;
|
|
256
257
|
this.isLastEffectiveChild = true;
|
|
257
258
|
this.isOnRightmostPath = true;
|
|
259
|
+
this.isSingleRoot = false;
|
|
258
260
|
this.templateCloseTags = void 0;
|
|
259
261
|
this.templateCloseBlocks = false;
|
|
260
262
|
this.globalId = 0;
|
|
@@ -380,8 +382,10 @@ var TransformContext = class TransformContext {
|
|
|
380
382
|
create(node, index) {
|
|
381
383
|
let effectiveParent = this;
|
|
382
384
|
while (effectiveParent && effectiveParent.node.type === 1 && effectiveParent.node.tagType === 3) effectiveParent = effectiveParent.parent;
|
|
383
|
-
const
|
|
385
|
+
const childInfo = this.getChildContextInfo();
|
|
386
|
+
const isLastEffectiveChild = childInfo.isLastEffectiveChild[index];
|
|
384
387
|
const isOnRightmostPath = this.isOnRightmostPath && isLastEffectiveChild;
|
|
388
|
+
const isSingleRoot = this.isSingleRootChild(childInfo);
|
|
385
389
|
return Object.assign(Object.create(TransformContext.prototype), this, {
|
|
386
390
|
node,
|
|
387
391
|
parent: this,
|
|
@@ -396,6 +400,7 @@ var TransformContext = class TransformContext {
|
|
|
396
400
|
effectiveParent,
|
|
397
401
|
isLastEffectiveChild,
|
|
398
402
|
isOnRightmostPath,
|
|
403
|
+
isSingleRoot,
|
|
399
404
|
templateCloseTags: this.templateCloseTags,
|
|
400
405
|
templateCloseBlocks: this.templateCloseBlocks
|
|
401
406
|
});
|
|
@@ -405,12 +410,59 @@ var TransformContext = class TransformContext {
|
|
|
405
410
|
if (operation && isBlockOperation(operation) && operation.effectIndex !== void 0 && operation.effectIndex >= index) operation.effectIndex++;
|
|
406
411
|
for (const child of dynamic.children) this.shiftEffectBoundaries(index, child);
|
|
407
412
|
}
|
|
408
|
-
|
|
409
|
-
const
|
|
410
|
-
if (
|
|
411
|
-
|
|
413
|
+
getChildContextInfo() {
|
|
414
|
+
const node = this.node;
|
|
415
|
+
if (node.type !== 0 && node.type !== 1) return {
|
|
416
|
+
node,
|
|
417
|
+
hasSingleRootChild: true,
|
|
418
|
+
isLastEffectiveChild: []
|
|
419
|
+
};
|
|
420
|
+
const cached = childContextInfoCache.get(this);
|
|
421
|
+
if (cached && cached.node === node) return cached;
|
|
422
|
+
const { children } = node;
|
|
423
|
+
const isLastEffectiveChild = new Array(children.length);
|
|
424
|
+
let hasFollowingEffectiveChild = false;
|
|
425
|
+
for (let i = children.length - 1; i >= 0; i--) {
|
|
426
|
+
isLastEffectiveChild[i] = !hasFollowingEffectiveChild;
|
|
427
|
+
if (!isComponentChild(children[i])) hasFollowingEffectiveChild = true;
|
|
428
|
+
}
|
|
429
|
+
const childInfo = {
|
|
430
|
+
node,
|
|
431
|
+
hasSingleRootChild: hasSingleRootChild(children),
|
|
432
|
+
isLastEffectiveChild
|
|
433
|
+
};
|
|
434
|
+
childContextInfoCache.set(this, childInfo);
|
|
435
|
+
return childInfo;
|
|
436
|
+
}
|
|
437
|
+
isSingleRootChild(childInfo) {
|
|
438
|
+
if (this.inVFor || !childInfo.hasSingleRootChild) return false;
|
|
439
|
+
if (this.node.type === 0) return true;
|
|
440
|
+
return this.node.type === 1 && this.node.tagType === 3 && !!this.parent && this.isSingleRoot;
|
|
412
441
|
}
|
|
413
442
|
};
|
|
443
|
+
function hasSingleRootChild(children) {
|
|
444
|
+
let nonCommentChildren = 0;
|
|
445
|
+
let hasEncounteredIf = false;
|
|
446
|
+
let isSingleIfBlock = true;
|
|
447
|
+
for (const child of children) {
|
|
448
|
+
if ((0, _vue_compiler_dom.isCommentOrWhitespace)(child)) continue;
|
|
449
|
+
nonCommentChildren++;
|
|
450
|
+
if (isIfChild(child)) {
|
|
451
|
+
if (hasEncounteredIf) isSingleIfBlock = false;
|
|
452
|
+
hasEncounteredIf = true;
|
|
453
|
+
} else if (!hasEncounteredIf || !isElseChild(child)) isSingleIfBlock = false;
|
|
454
|
+
}
|
|
455
|
+
return nonCommentChildren === 1 || isSingleIfBlock;
|
|
456
|
+
}
|
|
457
|
+
function isComponentChild(child) {
|
|
458
|
+
return child.type === 1 && child.tagType === 1;
|
|
459
|
+
}
|
|
460
|
+
function isIfChild(child) {
|
|
461
|
+
return child.type === 9 || child.type === 1 && !!(0, _vue_compiler_dom.findDir)(child, "if");
|
|
462
|
+
}
|
|
463
|
+
function isElseChild(child) {
|
|
464
|
+
return child.type === 1 && !!(0, _vue_compiler_dom.findDir)(child, /^else(-if)?$/, true);
|
|
465
|
+
}
|
|
414
466
|
const defaultOptions = {
|
|
415
467
|
filename: "",
|
|
416
468
|
prefixIdentifiers: true,
|
|
@@ -825,10 +877,10 @@ function canPrefix(name) {
|
|
|
825
877
|
}
|
|
826
878
|
function processExpressions(context, expressions, shouldDeclare) {
|
|
827
879
|
const expressionReplacements = /* @__PURE__ */ new Map();
|
|
828
|
-
const { seenVariable, variableToExpMap,
|
|
880
|
+
const { seenVariable, variableToExpMap, expressionRecords, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
|
|
829
881
|
const reservedNames = new Set(seenIdentifier);
|
|
830
|
-
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap,
|
|
831
|
-
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable,
|
|
882
|
+
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expressionRecords, seenIdentifier, updatedVariable, reservedNames, expressionReplacements);
|
|
883
|
+
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expressionRecords, reservedNames, expressionReplacements);
|
|
832
884
|
return {
|
|
833
885
|
...genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare),
|
|
834
886
|
expressionReplacements
|
|
@@ -837,19 +889,22 @@ function processExpressions(context, expressions, shouldDeclare) {
|
|
|
837
889
|
function analyzeExpressions(expressions) {
|
|
838
890
|
const seenVariable = Object.create(null);
|
|
839
891
|
const variableToExpMap = /* @__PURE__ */ new Map();
|
|
840
|
-
const
|
|
892
|
+
const expressionRecords = /* @__PURE__ */ new Map();
|
|
841
893
|
const seenIdentifier = /* @__PURE__ */ new Set();
|
|
842
894
|
const updatedVariable = /* @__PURE__ */ new Set();
|
|
895
|
+
const getRecord = (exp) => {
|
|
896
|
+
let record = expressionRecords.get(exp);
|
|
897
|
+
if (!record) expressionRecords.set(exp, record = { variables: [] });
|
|
898
|
+
return record;
|
|
899
|
+
};
|
|
843
900
|
const registerVariable = (name, exp, isIdentifier, loc, parentStack = []) => {
|
|
844
901
|
if (isIdentifier) seenIdentifier.add(name);
|
|
845
902
|
seenVariable[name] = (seenVariable[name] || 0) + 1;
|
|
846
903
|
variableToExpMap.set(name, (variableToExpMap.get(name) || /* @__PURE__ */ new Set()).add(exp));
|
|
847
|
-
|
|
848
|
-
variables.push({
|
|
904
|
+
getRecord(exp).variables.push({
|
|
849
905
|
name,
|
|
850
906
|
loc
|
|
851
907
|
});
|
|
852
|
-
expToVariableMap.set(exp, variables);
|
|
853
908
|
if (parentStack.some((p) => p.type === "UpdateExpression" || p.type === "AssignmentExpression")) updatedVariable.add(name);
|
|
854
909
|
};
|
|
855
910
|
for (const exp of expressions) {
|
|
@@ -886,7 +941,7 @@ function analyzeExpressions(expressions) {
|
|
|
886
941
|
seenVariable,
|
|
887
942
|
seenIdentifier,
|
|
888
943
|
variableToExpMap,
|
|
889
|
-
|
|
944
|
+
expressionRecords,
|
|
890
945
|
updatedVariable
|
|
891
946
|
};
|
|
892
947
|
}
|
|
@@ -896,9 +951,10 @@ function getProcessedExpression(exp, expressionReplacements) {
|
|
|
896
951
|
function setExpressionReplacement(expressionReplacements, exp, content, ast) {
|
|
897
952
|
expressionReplacements.set(exp, (0, _vue_shared.extend)({ ast }, (0, _vue_compiler_dom.createSimpleExpression)(content, exp.isStatic, exp.loc, exp.constType)));
|
|
898
953
|
}
|
|
899
|
-
function processRepeatedVariables(context, seenVariable, variableToExpMap,
|
|
954
|
+
function processRepeatedVariables(context, seenVariable, variableToExpMap, expressionRecords, seenIdentifier, updatedVariable, reservedNames, expressionReplacements) {
|
|
900
955
|
const declarations = [];
|
|
901
|
-
const
|
|
956
|
+
const declaredNames = /* @__PURE__ */ new Set();
|
|
957
|
+
const replacementPlan = /* @__PURE__ */ new Map();
|
|
902
958
|
for (const [name, exps] of variableToExpMap) {
|
|
903
959
|
if (updatedVariable.has(name)) continue;
|
|
904
960
|
if ((0, _vue_shared.isGloballyAllowed)(name)) continue;
|
|
@@ -907,96 +963,201 @@ function processRepeatedVariables(context, seenVariable, variableToExpMap, expTo
|
|
|
907
963
|
const varName = isIdentifier ? name : getUniqueDeclarationName(genVarName(name), reservedNames);
|
|
908
964
|
exps.forEach((node) => {
|
|
909
965
|
if (node.ast && varName !== name) {
|
|
910
|
-
const
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
if (v.name === name && v.loc) locs.push(v.loc);
|
|
915
|
-
return locs;
|
|
916
|
-
}, [])
|
|
966
|
+
for (const variable of getExpressionVariables(expressionRecords, node)) if (variable.name === name && variable.loc) queueContentReplacement(replacementPlan, node, {
|
|
967
|
+
start: variable.loc.start - 1,
|
|
968
|
+
end: variable.loc.end - 1,
|
|
969
|
+
content: varName
|
|
917
970
|
});
|
|
918
|
-
expToReplacementMap.set(node, replacements);
|
|
919
971
|
}
|
|
920
972
|
});
|
|
921
|
-
if (!
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
973
|
+
if (!declaredNames.has(varName) && (!isIdentifier || shouldDeclareVariable(name, expressionRecords, exps))) {
|
|
974
|
+
declaredNames.add(varName);
|
|
975
|
+
declarations.push({
|
|
976
|
+
name: varName,
|
|
977
|
+
isIdentifier,
|
|
978
|
+
value: (0, _vue_shared.extend)({ ast: isIdentifier ? null : parseExp(context, name) }, (0, _vue_compiler_dom.createSimpleExpression)(name)),
|
|
979
|
+
rawName: name,
|
|
980
|
+
exps,
|
|
981
|
+
seenCount: seenVariable[name]
|
|
982
|
+
});
|
|
983
|
+
}
|
|
929
984
|
}
|
|
930
985
|
}
|
|
931
|
-
|
|
932
|
-
let content = getProcessedExpression(exp, expressionReplacements).content;
|
|
933
|
-
replacements.flatMap(({ name, locs }) => locs.map(({ start, end }) => ({
|
|
934
|
-
start,
|
|
935
|
-
end,
|
|
936
|
-
name
|
|
937
|
-
}))).sort((a, b) => b.end - a.end).forEach(({ start, end, name }) => {
|
|
938
|
-
content = content.slice(0, start - 1) + name + content.slice(end - 1);
|
|
939
|
-
});
|
|
940
|
-
setExpressionReplacement(expressionReplacements, exp, content, parseExp(context, content));
|
|
941
|
-
}
|
|
986
|
+
applyReplacementPlan(context, expressionReplacements, replacementPlan);
|
|
942
987
|
return declarations;
|
|
943
988
|
}
|
|
944
|
-
function shouldDeclareVariable(name,
|
|
945
|
-
const
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
989
|
+
function shouldDeclareVariable(name, expressionRecords, exps) {
|
|
990
|
+
const variableUsages = [];
|
|
991
|
+
let allSingleVariable = true;
|
|
992
|
+
let hasRepeatedName = false;
|
|
993
|
+
let hasDifferentLength = false;
|
|
994
|
+
outer: for (const exp of exps) {
|
|
995
|
+
const variables = getExpressionVariables(expressionRecords, exp);
|
|
996
|
+
if (allSingleVariable && variables.length !== 1) allSingleVariable = false;
|
|
997
|
+
if (!hasDifferentLength && variableUsages.length > 0 && variables.length !== variableUsages[0].length) hasDifferentLength = true;
|
|
998
|
+
let nameCount = 0;
|
|
999
|
+
for (const variable of variables) if (variable.name === name && ++nameCount > 1) {
|
|
1000
|
+
hasRepeatedName = true;
|
|
1001
|
+
break outer;
|
|
1002
|
+
}
|
|
1003
|
+
variableUsages.push(variables);
|
|
1004
|
+
}
|
|
1005
|
+
if (allSingleVariable) return true;
|
|
1006
|
+
if (hasRepeatedName) return true;
|
|
1007
|
+
const first = variableUsages[0];
|
|
1008
|
+
if (hasDifferentLength) {
|
|
1009
|
+
for (const variables of variableUsages) {
|
|
1010
|
+
if (variables.length === first.length) continue;
|
|
1011
|
+
const longer = variables.length > first.length ? variables : first;
|
|
1012
|
+
const shorter = variables.length > first.length ? first : variables;
|
|
1013
|
+
const shorterNames = /* @__PURE__ */ new Set();
|
|
1014
|
+
for (const variable of shorter) shorterNames.add(variable.name);
|
|
1015
|
+
let isSubset = true;
|
|
1016
|
+
for (const variable of longer) if (!shorterNames.has(variable.name)) {
|
|
1017
|
+
isSubset = false;
|
|
1018
|
+
break;
|
|
1019
|
+
}
|
|
1020
|
+
if (isSubset) return false;
|
|
1021
|
+
}
|
|
951
1022
|
return true;
|
|
952
1023
|
}
|
|
953
|
-
|
|
954
|
-
return
|
|
1024
|
+
for (const variables of variableUsages) for (let i = 0; i < variables.length; i++) if (variables[i].name !== first[i].name) return true;
|
|
1025
|
+
return false;
|
|
955
1026
|
}
|
|
956
|
-
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable,
|
|
1027
|
+
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expressionRecords, reservedNames, expressionReplacements) {
|
|
957
1028
|
const declarations = [];
|
|
958
|
-
const seenExp =
|
|
959
|
-
|
|
960
|
-
|
|
1029
|
+
const seenExp = /* @__PURE__ */ new Map();
|
|
1030
|
+
for (const exp of expressions) {
|
|
1031
|
+
var _expressionRecords$ge;
|
|
1032
|
+
const vars = (_expressionRecords$ge = expressionRecords.get(exp)) === null || _expressionRecords$ge === void 0 ? void 0 : _expressionRecords$ge.variables;
|
|
1033
|
+
if (!vars) continue;
|
|
961
1034
|
const processed = getProcessedExpression(exp, expressionReplacements);
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
const delVars = {};
|
|
969
|
-
for (let i = varDeclarations.length - 1; i >= 0; i--) {
|
|
970
|
-
const item = varDeclarations[i];
|
|
971
|
-
if (!item.exps || !item.seenCount) continue;
|
|
972
|
-
if ([...item.exps].every((node) => getProcessedExpression(node, expressionReplacements).content === content && item.seenCount === count)) {
|
|
973
|
-
delVars[item.name] = item.rawName;
|
|
974
|
-
reservedNames.delete(item.name);
|
|
975
|
-
varDeclarations.splice(i, 1);
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
const value = (0, _vue_shared.extend)({}, getProcessedExpression(expressions.find((exp) => getProcessedExpression(exp, expressionReplacements).content === content), expressionReplacements));
|
|
979
|
-
Object.keys(delVars).forEach((name) => {
|
|
980
|
-
value.content = value.content.replace(name, delVars[name]);
|
|
981
|
-
if (value.ast) value.ast = parseExp(context, value.content);
|
|
1035
|
+
if (canCacheExpression(processed, vars, updatedVariable)) {
|
|
1036
|
+
const seen = seenExp.get(processed.content);
|
|
1037
|
+
if (seen) seen.count++;
|
|
1038
|
+
else seenExp.set(processed.content, {
|
|
1039
|
+
count: 1,
|
|
1040
|
+
first: exp
|
|
982
1041
|
});
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
1042
|
+
}
|
|
1043
|
+
}
|
|
1044
|
+
const repeatedExpressions = [...seenExp].sort(([contentA], [contentB]) => contentB.length - contentA.length);
|
|
1045
|
+
for (const [content, { count, first }] of repeatedExpressions) if (count > 1) {
|
|
1046
|
+
const removedDeclarations = [];
|
|
1047
|
+
for (let i = varDeclarations.length - 1; i >= 0; i--) {
|
|
1048
|
+
const item = varDeclarations[i];
|
|
1049
|
+
if (!item.exps || !item.seenCount) continue;
|
|
1050
|
+
if ([...item.exps].every((node) => getProcessedExpression(node, expressionReplacements).content === content && item.seenCount === count)) {
|
|
1051
|
+
removedDeclarations.push({
|
|
1052
|
+
name: item.name,
|
|
1053
|
+
rawName: item.rawName
|
|
1054
|
+
});
|
|
1055
|
+
reservedNames.delete(item.name);
|
|
1056
|
+
varDeclarations.splice(i, 1);
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
const value = (0, _vue_shared.extend)({}, getProcessedExpression(first, expressionReplacements));
|
|
1060
|
+
const restorePlan = [];
|
|
1061
|
+
for (const { name, rawName } of removedDeclarations) restorePlan.push(...findIdentifierReplacements(value, name, rawName));
|
|
1062
|
+
if (restorePlan.length) {
|
|
1063
|
+
value.content = applyContentReplacements(value.content, restorePlan);
|
|
1064
|
+
if (value.ast) value.ast = parseExp(context, value.content);
|
|
1065
|
+
}
|
|
1066
|
+
const varName = getUniqueDeclarationName(genVarName(content), reservedNames);
|
|
1067
|
+
declarations.push({
|
|
1068
|
+
name: varName,
|
|
1069
|
+
value
|
|
1070
|
+
});
|
|
1071
|
+
for (const exp of expressions) {
|
|
1072
|
+
const processed = getProcessedExpression(exp, expressionReplacements);
|
|
1073
|
+
if (processed.content === content) setExpressionReplacement(expressionReplacements, exp, varName, null);
|
|
1074
|
+
else if (processed.content.includes(content)) {
|
|
1075
|
+
const replacements = findContentReplacements(processed, content, varName);
|
|
1076
|
+
if (replacements.length) {
|
|
1077
|
+
const replacedContent = applyContentReplacements(processed.content, replacements);
|
|
993
1078
|
setExpressionReplacement(expressionReplacements, exp, replacedContent, parseExp(context, replacedContent));
|
|
994
1079
|
}
|
|
995
|
-
}
|
|
1080
|
+
}
|
|
996
1081
|
}
|
|
997
|
-
}
|
|
1082
|
+
}
|
|
998
1083
|
return declarations;
|
|
999
1084
|
}
|
|
1085
|
+
function canCacheExpression(processed, vars, updatedVariable) {
|
|
1086
|
+
if (!processed.ast || processed.ast.type === "Identifier") return false;
|
|
1087
|
+
for (const { name } of vars) if (updatedVariable.has(name) || (0, _vue_shared.isGloballyAllowed)(name)) return false;
|
|
1088
|
+
return true;
|
|
1089
|
+
}
|
|
1090
|
+
function getExpressionVariables(expressionRecords, exp) {
|
|
1091
|
+
var _expressionRecords$ge2;
|
|
1092
|
+
return ((_expressionRecords$ge2 = expressionRecords.get(exp)) === null || _expressionRecords$ge2 === void 0 ? void 0 : _expressionRecords$ge2.variables) || [];
|
|
1093
|
+
}
|
|
1094
|
+
function queueContentReplacement(replacementPlan, exp, replacement) {
|
|
1095
|
+
const replacements = replacementPlan.get(exp);
|
|
1096
|
+
if (replacements) replacements.push(replacement);
|
|
1097
|
+
else replacementPlan.set(exp, [replacement]);
|
|
1098
|
+
}
|
|
1099
|
+
function applyReplacementPlan(context, expressionReplacements, replacementPlan) {
|
|
1100
|
+
for (const [exp, replacements] of replacementPlan) {
|
|
1101
|
+
if (!replacements.length) continue;
|
|
1102
|
+
const content = applyContentReplacements(getProcessedExpression(exp, expressionReplacements).content, replacements);
|
|
1103
|
+
setExpressionReplacement(expressionReplacements, exp, content, parseExp(context, content));
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
function findContentReplacements(exp, content, replacement) {
|
|
1107
|
+
const identifiers = getIdentifierRanges(exp);
|
|
1108
|
+
if (!identifiers.length) return [];
|
|
1109
|
+
const replacements = [];
|
|
1110
|
+
let searchStart = 0;
|
|
1111
|
+
let start = exp.content.indexOf(content, searchStart);
|
|
1112
|
+
while (start !== -1) {
|
|
1113
|
+
const end = start + content.length;
|
|
1114
|
+
let canReplace = false;
|
|
1115
|
+
for (const identifier of identifiers) {
|
|
1116
|
+
if (start >= identifier.end || end <= identifier.start) continue;
|
|
1117
|
+
if (start > identifier.start || end < identifier.end) {
|
|
1118
|
+
canReplace = false;
|
|
1119
|
+
break;
|
|
1120
|
+
}
|
|
1121
|
+
canReplace = true;
|
|
1122
|
+
}
|
|
1123
|
+
if (canReplace) {
|
|
1124
|
+
replacements.push({
|
|
1125
|
+
start,
|
|
1126
|
+
end,
|
|
1127
|
+
content: replacement
|
|
1128
|
+
});
|
|
1129
|
+
searchStart = end;
|
|
1130
|
+
} else searchStart = start + 1;
|
|
1131
|
+
start = exp.content.indexOf(content, searchStart);
|
|
1132
|
+
}
|
|
1133
|
+
return replacements;
|
|
1134
|
+
}
|
|
1135
|
+
function findIdentifierReplacements(exp, name, replacement) {
|
|
1136
|
+
const replacements = [];
|
|
1137
|
+
for (const { start, end } of getIdentifierRanges(exp)) if (exp.content.slice(start, end) === name) replacements.push({
|
|
1138
|
+
start,
|
|
1139
|
+
end,
|
|
1140
|
+
content: replacement
|
|
1141
|
+
});
|
|
1142
|
+
return replacements;
|
|
1143
|
+
}
|
|
1144
|
+
function getIdentifierRanges(exp) {
|
|
1145
|
+
if (!exp.ast || typeof exp.ast !== "object") return [];
|
|
1146
|
+
const identifiers = [];
|
|
1147
|
+
(0, _vue_compiler_dom.walkIdentifiers)(exp.ast, (id) => {
|
|
1148
|
+
identifiers.push({
|
|
1149
|
+
start: id.start - 1,
|
|
1150
|
+
end: id.end - 1
|
|
1151
|
+
});
|
|
1152
|
+
}, false);
|
|
1153
|
+
return identifiers;
|
|
1154
|
+
}
|
|
1155
|
+
function applyContentReplacements(content, replacements) {
|
|
1156
|
+
replacements.sort((a, b) => b.start - a.start).forEach(({ start, end, content: replacement }) => {
|
|
1157
|
+
content = content.slice(0, start) + replacement + content.slice(end);
|
|
1158
|
+
});
|
|
1159
|
+
return content;
|
|
1160
|
+
}
|
|
1000
1161
|
function genDeclarations(declarations, context, shouldDeclare) {
|
|
1001
1162
|
const [frag, push] = buildCodeFragment();
|
|
1002
1163
|
const ids = Object.create(null);
|
|
@@ -1024,9 +1185,6 @@ function genDeclarations(declarations, context, shouldDeclare) {
|
|
|
1024
1185
|
varNames: [...varNames]
|
|
1025
1186
|
};
|
|
1026
1187
|
}
|
|
1027
|
-
function escapeRegExp(string) {
|
|
1028
|
-
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1029
|
-
}
|
|
1030
1188
|
function parseExp(context, content) {
|
|
1031
1189
|
return (0, _babel_parser.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
1032
1190
|
}
|
|
@@ -1217,7 +1375,7 @@ function genFor(oper, context) {
|
|
|
1217
1375
|
idMap[rawIndex] = `${indexVar}.value`;
|
|
1218
1376
|
idMap[indexVar] = null;
|
|
1219
1377
|
}
|
|
1220
|
-
const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap, context);
|
|
1378
|
+
const { selectorPatterns, keyOnlyBindingPatterns, skippedEffectIndexes } = matchPatterns(render, keyProp, idMap, context);
|
|
1221
1379
|
const selectorDeclarations = [];
|
|
1222
1380
|
const selectorName = (i) => selectorPatterns.length > 1 ? `_selector${id}_${i}` : `_selector${id}`;
|
|
1223
1381
|
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
@@ -1237,26 +1395,20 @@ function genFor(oper, context) {
|
|
|
1237
1395
|
}
|
|
1238
1396
|
for (const { effect } of keyOnlyBindingPatterns) for (const oper of effect.operations) patternFrag.push(...genOperation(oper, context));
|
|
1239
1397
|
return patternFrag;
|
|
1240
|
-
}));
|
|
1398
|
+
}, skippedEffectIndexes));
|
|
1241
1399
|
else frag.push(...genBlockContent(render, context));
|
|
1242
1400
|
frag.push(INDENT_END, NEWLINE, "}");
|
|
1243
1401
|
return frag;
|
|
1244
1402
|
}, idMap);
|
|
1245
1403
|
exitScope();
|
|
1246
|
-
|
|
1247
|
-
if (onlyChild) flags |= 1;
|
|
1248
|
-
if (component) flags |= 2;
|
|
1249
|
-
if (isFragmentBlock(render)) flags |= 16;
|
|
1250
|
-
if (!component && isSingleNodeBlock(render)) flags |= 8;
|
|
1251
|
-
if (once) flags |= 4;
|
|
1252
|
-
if (slotRoot) flags |= 32;
|
|
1404
|
+
const flags = genForFlags(onlyChild, component, isFragmentBlock(render), !component && isSingleNodeBlock(render), once, slotRoot);
|
|
1253
1405
|
const onResetCalls = [];
|
|
1254
1406
|
for (let i = 0; i < selectorPatterns.length; i++) onResetCalls.push(NEWLINE, `n${id}.onReset(${selectorName(i)}.reset)`);
|
|
1255
1407
|
return [
|
|
1256
1408
|
NEWLINE,
|
|
1257
1409
|
...selectorDeclarations,
|
|
1258
1410
|
`const n${id} = `,
|
|
1259
|
-
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags
|
|
1411
|
+
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags),
|
|
1260
1412
|
...onResetCalls
|
|
1261
1413
|
];
|
|
1262
1414
|
function genCallback(expr) {
|
|
@@ -1281,6 +1433,36 @@ function genFor(oper, context) {
|
|
|
1281
1433
|
return idMap;
|
|
1282
1434
|
}
|
|
1283
1435
|
}
|
|
1436
|
+
function genForFlags(onlyChild, component, isFragment, isSingleNode, once, slotRoot) {
|
|
1437
|
+
let flags = 0;
|
|
1438
|
+
const names = [];
|
|
1439
|
+
if (onlyChild) {
|
|
1440
|
+
flags |= 1;
|
|
1441
|
+
names.push("FAST_REMOVE");
|
|
1442
|
+
}
|
|
1443
|
+
if (component) {
|
|
1444
|
+
flags |= 2;
|
|
1445
|
+
names.push("IS_COMPONENT");
|
|
1446
|
+
}
|
|
1447
|
+
if (isFragment) {
|
|
1448
|
+
flags |= 16;
|
|
1449
|
+
names.push("IS_FRAGMENT");
|
|
1450
|
+
}
|
|
1451
|
+
if (isSingleNode) {
|
|
1452
|
+
flags |= 8;
|
|
1453
|
+
names.push("IS_SINGLE_NODE");
|
|
1454
|
+
}
|
|
1455
|
+
if (once) {
|
|
1456
|
+
flags |= 4;
|
|
1457
|
+
names.push("ONCE");
|
|
1458
|
+
}
|
|
1459
|
+
if (slotRoot) {
|
|
1460
|
+
flags |= 32;
|
|
1461
|
+
names.push("SLOT_ROOT");
|
|
1462
|
+
}
|
|
1463
|
+
if (!flags) return;
|
|
1464
|
+
return `${flags} /* ${names.join(", ")} */`;
|
|
1465
|
+
}
|
|
1284
1466
|
function isSingleNodeBlock(block) {
|
|
1285
1467
|
const child = getSingleReturnedChild(block);
|
|
1286
1468
|
return !!child && child.template != null;
|
|
@@ -1367,39 +1549,35 @@ function buildDestructureIdMap(idToPathMap, baseAccessor, plugins) {
|
|
|
1367
1549
|
function matchPatterns(render, keyProp, idMap, context) {
|
|
1368
1550
|
const selectorPatterns = [];
|
|
1369
1551
|
const keyOnlyBindingPatterns = [];
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
return false;
|
|
1384
|
-
}
|
|
1552
|
+
let skippedEffectIndexes;
|
|
1553
|
+
if (keyProp === void 0) return {
|
|
1554
|
+
keyOnlyBindingPatterns,
|
|
1555
|
+
selectorPatterns,
|
|
1556
|
+
skippedEffectIndexes
|
|
1557
|
+
};
|
|
1558
|
+
for (let index = 0; index < render.effect.length; index++) {
|
|
1559
|
+
const effect = render.effect[index];
|
|
1560
|
+
const selector = matchSelectorPattern(effect, keyProp.content, idMap, context);
|
|
1561
|
+
if (selector) {
|
|
1562
|
+
selectorPatterns.push(selector);
|
|
1563
|
+
skipEffect(index);
|
|
1564
|
+
continue;
|
|
1385
1565
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1566
|
+
const keyOnly = matchKeyOnlyBindingPattern(effect, keyProp.content);
|
|
1567
|
+
if (keyOnly) {
|
|
1568
|
+
keyOnlyBindingPatterns.push(keyOnly);
|
|
1569
|
+
skipEffect(index);
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1389
1572
|
return {
|
|
1390
1573
|
keyOnlyBindingPatterns,
|
|
1391
|
-
selectorPatterns
|
|
1574
|
+
selectorPatterns,
|
|
1575
|
+
skippedEffectIndexes
|
|
1392
1576
|
};
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
if (operation && isBlockOperation(operation) && operation.effectIndex !== void 0) {
|
|
1397
|
-
let offset = 0;
|
|
1398
|
-
for (const removedIndex of removedEffectIndexes) if (removedIndex < operation.effectIndex) offset++;
|
|
1399
|
-
else break;
|
|
1400
|
-
operation.effectIndex -= offset;
|
|
1577
|
+
function skipEffect(index) {
|
|
1578
|
+
if (!skippedEffectIndexes) skippedEffectIndexes = /* @__PURE__ */ new Set();
|
|
1579
|
+
skippedEffectIndexes.add(index);
|
|
1401
1580
|
}
|
|
1402
|
-
for (const child of dynamic.children) shiftEffectBoundaries(child, removedEffectIndexes);
|
|
1403
1581
|
}
|
|
1404
1582
|
function matchKeyOnlyBindingPattern(effect, key) {
|
|
1405
1583
|
if (effect.expressions.length === 1) {
|
|
@@ -1504,14 +1682,25 @@ function genIfFlags(blockShape, once, slotRoot, index) {
|
|
|
1504
1682
|
return `${flags} /* ${genIfFlagNames(once, slotRoot, index, blockShape)} */`;
|
|
1505
1683
|
}
|
|
1506
1684
|
function genIfFlagNames(once, slotRoot, index, blockShape) {
|
|
1507
|
-
const names = [
|
|
1685
|
+
const names = [`TRUE_${genBlockShapeName(blockShape)}`];
|
|
1686
|
+
const falseShape = blockShape >> 2;
|
|
1687
|
+
const hasFalseBranch = (falseShape & 3) !== 0;
|
|
1688
|
+
if (hasFalseBranch) names.push(`FALSE_${genBlockShapeName(falseShape)}`);
|
|
1508
1689
|
if (blockShape & 32) names.push("TRUE_NO_SCOPE");
|
|
1509
|
-
if (blockShape & 64) names.push("FALSE_NO_SCOPE");
|
|
1690
|
+
if (hasFalseBranch && blockShape & 64) names.push("FALSE_NO_SCOPE");
|
|
1510
1691
|
if (once) names.push("ONCE");
|
|
1511
1692
|
if (slotRoot) names.push("SLOT_ROOT");
|
|
1512
|
-
if (!once && index !== void 0) names.push(
|
|
1693
|
+
if (!once && index !== void 0) names.push(`KEYED_INDEX_${index}`);
|
|
1513
1694
|
return names.join(", ");
|
|
1514
1695
|
}
|
|
1696
|
+
function genBlockShapeName(flags) {
|
|
1697
|
+
switch (flags & 3) {
|
|
1698
|
+
case 0: return "EMPTY";
|
|
1699
|
+
case 1: return "SINGLE_ROOT";
|
|
1700
|
+
case 2: return "MULTI_ROOT";
|
|
1701
|
+
}
|
|
1702
|
+
return "UNKNOWN";
|
|
1703
|
+
}
|
|
1515
1704
|
//#endregion
|
|
1516
1705
|
//#region packages/compiler-vapor/src/generators/prop.ts
|
|
1517
1706
|
const helpers = {
|
|
@@ -1868,7 +2057,7 @@ function genCreateComponent(operation, context) {
|
|
|
1868
2057
|
const tag = genTag();
|
|
1869
2058
|
const { root, props, slots, once, slotRoot } = operation;
|
|
1870
2059
|
const isRuntimeDynamicComponent = !!(operation.dynamic && !operation.dynamic.isStatic);
|
|
1871
|
-
const dynamicComponentFlags = isRuntimeDynamicComponent ? (root
|
|
2060
|
+
const dynamicComponentFlags = isRuntimeDynamicComponent ? genDynamicComponentFlags(root, once, slotRoot) : false;
|
|
1872
2061
|
const rawSlots = genRawSlots(slots, context);
|
|
1873
2062
|
const [ids, handlers] = processInlineHandlers(props, context);
|
|
1874
2063
|
const rawProps = context.withId(() => genRawProps(props, context, true), ids);
|
|
@@ -1884,7 +2073,7 @@ function genCreateComponent(operation, context) {
|
|
|
1884
2073
|
];
|
|
1885
2074
|
}, []),
|
|
1886
2075
|
`const n${operation.id} = `,
|
|
1887
|
-
...genCall(isRuntimeDynamicComponent ? helper("createDynamicComponent") : operation.useCreateElement ? helper("createPlainElement") : useAssetComponentHelper ? helper("createAssetComponent") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, isRuntimeDynamicComponent ? dynamicComponentFlags
|
|
2076
|
+
...genCall(isRuntimeDynamicComponent ? helper("createDynamicComponent") : operation.useCreateElement ? helper("createPlainElement") : useAssetComponentHelper ? helper("createAssetComponent") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, isRuntimeDynamicComponent ? dynamicComponentFlags : root ? "true" : false, isRuntimeDynamicComponent ? false : once && "true", isRuntimeDynamicComponent ? false : maybeSelfReference && "true"),
|
|
1888
2077
|
...genDirectivesForElement(operation.id, context)
|
|
1889
2078
|
];
|
|
1890
2079
|
function genTag() {
|
|
@@ -1910,6 +2099,24 @@ function genCreateComponent(operation, context) {
|
|
|
1910
2099
|
}
|
|
1911
2100
|
}
|
|
1912
2101
|
}
|
|
2102
|
+
function genDynamicComponentFlags(root, once, slotRoot) {
|
|
2103
|
+
let flags = 0;
|
|
2104
|
+
const names = [];
|
|
2105
|
+
if (root) {
|
|
2106
|
+
flags |= 1;
|
|
2107
|
+
names.push("SINGLE_ROOT");
|
|
2108
|
+
}
|
|
2109
|
+
if (once) {
|
|
2110
|
+
flags |= 2;
|
|
2111
|
+
names.push("ONCE");
|
|
2112
|
+
}
|
|
2113
|
+
if (slotRoot) {
|
|
2114
|
+
flags |= 4;
|
|
2115
|
+
names.push("SLOT_ROOT");
|
|
2116
|
+
}
|
|
2117
|
+
if (!flags) return false;
|
|
2118
|
+
return `${flags} /* ${names.join(", ")} */`;
|
|
2119
|
+
}
|
|
1913
2120
|
function getUniqueHandlerName(context, name) {
|
|
1914
2121
|
const { seenInlineHandlerNames } = context;
|
|
1915
2122
|
name = genVarName(name);
|
|
@@ -2220,13 +2427,22 @@ function genSlotBlockWithProps(oper, context, emitNonStableFlag = true) {
|
|
|
2220
2427
|
const idMap = idToPathMap.size ? buildDestructureIdMap(idToPathMap, propsName || "", context.options.expressionPlugins) : {};
|
|
2221
2428
|
if (propsName) idMap[propsName] = null;
|
|
2222
2429
|
const exitSlotBlock = context.enterSlotBlock();
|
|
2223
|
-
|
|
2430
|
+
const hasStableRoot = hasStableSlotRoot(oper, context);
|
|
2431
|
+
if (!hasStableRoot) markSlotRootOperations(oper);
|
|
2224
2432
|
let blockFn = context.withId(() => genBlock(oper, context, propsName ? [propsName] : []), idMap);
|
|
2225
|
-
if (emitNonStableFlag && !
|
|
2433
|
+
if (emitNonStableFlag && !hasStableRoot) blockFn = genCall(context.helper("extend"), blockFn, [`{ _: ${genSlotFlags$1(8)} }`]);
|
|
2226
2434
|
exitSlotBlock();
|
|
2227
2435
|
exitScope && exitScope();
|
|
2228
2436
|
return blockFn;
|
|
2229
2437
|
}
|
|
2438
|
+
function genSlotFlags$1(flags) {
|
|
2439
|
+
const names = [];
|
|
2440
|
+
if (flags & 1) names.push("NO_SLOTTED");
|
|
2441
|
+
if (flags & 2) names.push("ONCE");
|
|
2442
|
+
if (flags & 4) names.push("SLOT_ROOT");
|
|
2443
|
+
if (flags & 8) names.push("NON_STABLE");
|
|
2444
|
+
return `${flags} /* ${names.join(", ")} */`;
|
|
2445
|
+
}
|
|
2230
2446
|
const commentOnlyTemplateRE = /^(?:<!--[\s\S]*?-->)+$/;
|
|
2231
2447
|
function hasStableSlotRoot(block, context) {
|
|
2232
2448
|
let hasValidRoot = false;
|
|
@@ -2244,14 +2460,14 @@ function hasStableSlotRoot(block, context) {
|
|
|
2244
2460
|
hasValidRoot = true;
|
|
2245
2461
|
continue;
|
|
2246
2462
|
}
|
|
2247
|
-
|
|
2463
|
+
continue;
|
|
2248
2464
|
case 17:
|
|
2249
2465
|
if (hasStableSlotRoot(operation.block, context)) {
|
|
2250
2466
|
hasValidRoot = true;
|
|
2251
2467
|
continue;
|
|
2252
2468
|
}
|
|
2253
|
-
|
|
2254
|
-
default:
|
|
2469
|
+
continue;
|
|
2470
|
+
default: continue;
|
|
2255
2471
|
}
|
|
2256
2472
|
}
|
|
2257
2473
|
return hasValidRoot;
|
|
@@ -2269,7 +2485,7 @@ function genSlotOutlet(oper, context) {
|
|
|
2269
2485
|
const [frag, push] = buildCodeFragment();
|
|
2270
2486
|
let fallbackArg;
|
|
2271
2487
|
if (fallback) {
|
|
2272
|
-
markSlotRootOperations(fallback);
|
|
2488
|
+
if (context.inSlotBlock) markSlotRootOperations(fallback);
|
|
2273
2489
|
fallbackArg = genBlock(fallback, context);
|
|
2274
2490
|
}
|
|
2275
2491
|
const createSlot = helper("createSlot");
|
|
@@ -2279,9 +2495,17 @@ function genSlotOutlet(oper, context) {
|
|
|
2279
2495
|
...genExpression(name, context),
|
|
2280
2496
|
")"
|
|
2281
2497
|
];
|
|
2282
|
-
push(NEWLINE, `const n${id} = `, ...genCall(createSlot, nameArg, rawPropsArg, fallbackArg,
|
|
2498
|
+
push(NEWLINE, `const n${id} = `, ...genCall(createSlot, nameArg, rawPropsArg, fallbackArg, genSlotFlags(flags)));
|
|
2283
2499
|
return frag;
|
|
2284
2500
|
}
|
|
2501
|
+
function genSlotFlags(flags) {
|
|
2502
|
+
if (!flags) return;
|
|
2503
|
+
const names = [];
|
|
2504
|
+
if (flags & 1) names.push("NO_SLOTTED");
|
|
2505
|
+
if (flags & 2) names.push("ONCE");
|
|
2506
|
+
if (flags & 4) names.push("SLOT_ROOT");
|
|
2507
|
+
return `${flags} /* ${names.join(", ")} */`;
|
|
2508
|
+
}
|
|
2285
2509
|
//#endregion
|
|
2286
2510
|
//#region packages/compiler-vapor/src/generators/key.ts
|
|
2287
2511
|
function genKey(oper, context) {
|
|
@@ -2554,7 +2778,7 @@ function genBlock(oper, context, args = [], root) {
|
|
|
2554
2778
|
"}"
|
|
2555
2779
|
];
|
|
2556
2780
|
}
|
|
2557
|
-
function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
2781
|
+
function genBlockContent(block, context, root, genEffectsExtraFrag, skippedEffectIndexes) {
|
|
2558
2782
|
const [frag, push] = buildCodeFragment();
|
|
2559
2783
|
const { dynamic, effect, operation, returns } = block;
|
|
2560
2784
|
const resetBlock = context.enterBlock(block);
|
|
@@ -2579,7 +2803,7 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
2579
2803
|
operationIndex++;
|
|
2580
2804
|
}
|
|
2581
2805
|
if (effectIndex < effectEnd) {
|
|
2582
|
-
push(...
|
|
2806
|
+
push(...genEffectRange(effectIndex, effectEnd));
|
|
2583
2807
|
effectIndex = effectEnd;
|
|
2584
2808
|
}
|
|
2585
2809
|
};
|
|
@@ -2593,7 +2817,7 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
2593
2817
|
}
|
|
2594
2818
|
for (const child of dynamic.children) if (!child.hasDynamicChild) push(...genChildren(child, context, push, `n${child.id}`, flushBeforeDynamic));
|
|
2595
2819
|
if (operationIndex < operation.length) push(...genOperations(operation.slice(operationIndex), context));
|
|
2596
|
-
if (effectIndex < effect.length) push(...
|
|
2820
|
+
if (effectIndex < effect.length) push(...genEffectRange(effectIndex, effect.length, genEffectsExtraFrag));
|
|
2597
2821
|
else if (genEffectsExtraFrag) push(...genEffects([], context, genEffectsExtraFrag));
|
|
2598
2822
|
push(NEWLINE, `return `);
|
|
2599
2823
|
const returnNodes = returns.map((n) => `n${n}`);
|
|
@@ -2601,6 +2825,13 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
2601
2825
|
resetBlock();
|
|
2602
2826
|
context.singleUseAssetComponentNames = prevSingleUseAssetComponentNames;
|
|
2603
2827
|
return frag;
|
|
2828
|
+
function genEffectRange(start, end, genExtraFrag) {
|
|
2829
|
+
if (!skippedEffectIndexes) return genEffects(effect.slice(start, end), context, genExtraFrag);
|
|
2830
|
+
const effects = [];
|
|
2831
|
+
for (let i = start; i < end; i++) if (!skippedEffectIndexes.has(i)) effects.push(effect[i]);
|
|
2832
|
+
if (effects.length || genExtraFrag) return genEffects(effects, context, genExtraFrag);
|
|
2833
|
+
return [];
|
|
2834
|
+
}
|
|
2604
2835
|
function genResolveAssets(kind, helper) {
|
|
2605
2836
|
for (const name of context.ir[kind]) push(NEWLINE, `const ${(0, _vue_compiler_dom.toValidAssetId)(name, kind)} = `, ...genCall(context.helper(helper), JSON.stringify(name)));
|
|
2606
2837
|
}
|
|
@@ -2612,7 +2843,6 @@ function markSlotRootOperations(block) {
|
|
|
2612
2843
|
if (!operation) continue;
|
|
2613
2844
|
if (operation.type === 15) markSlotRootIf(operation);
|
|
2614
2845
|
else if (operation.type === 16) markSlotRootFor(operation);
|
|
2615
|
-
else if (operation.type === 13) markSlotRootSlotOutlet(operation);
|
|
2616
2846
|
else if (operation.type === 12) markSlotRootComponent(operation);
|
|
2617
2847
|
}
|
|
2618
2848
|
}
|
|
@@ -2628,10 +2858,6 @@ function markSlotRootFor(operation) {
|
|
|
2628
2858
|
if (!operation.once) operation.slotRoot = true;
|
|
2629
2859
|
markSlotRootOperations(operation.render);
|
|
2630
2860
|
}
|
|
2631
|
-
function markSlotRootSlotOutlet(operation) {
|
|
2632
|
-
operation.flags |= 4;
|
|
2633
|
-
if (operation.fallback) markSlotRootOperations(operation.fallback);
|
|
2634
|
-
}
|
|
2635
2861
|
function markSlotRootComponent(operation) {
|
|
2636
2862
|
if (!operation.once && operation.dynamic && !operation.dynamic.isStatic) operation.slotRoot = true;
|
|
2637
2863
|
}
|
|
@@ -2979,7 +3205,7 @@ const transformElement = (node, context) => {
|
|
|
2979
3205
|
const isDynamicComponent = isComponentTag(node.tag);
|
|
2980
3206
|
const staticKey = resolveStaticKey(node, context, isComponent);
|
|
2981
3207
|
const propsResult = buildProps(node, context, isComponent, isDynamicComponent, getEffectIndex);
|
|
2982
|
-
const singleRoot = isSingleRoot
|
|
3208
|
+
const singleRoot = context.isSingleRoot;
|
|
2983
3209
|
if (isComponent) transformComponentElement(node, propsResult, staticKey, singleRoot, context, isDynamicComponent, useCreateElement);
|
|
2984
3210
|
else transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, context.root === context.effectiveParent || canOmitEndTag(node, context));
|
|
2985
3211
|
if (parentSlots) context.slots = parentSlots;
|
|
@@ -3018,16 +3244,6 @@ function isInSameTemplateAsParent(context) {
|
|
|
3018
3244
|
if (parentNode.type !== 1 || parentNode.tagType !== 0) return false;
|
|
3019
3245
|
return !shouldUseCreateElement(parentNode, parent) && (0, _vue_compiler_dom.isValidHTMLNesting)(parentNode.tag, node.tag);
|
|
3020
3246
|
}
|
|
3021
|
-
function isSingleRoot(context) {
|
|
3022
|
-
if (context.inVFor) return false;
|
|
3023
|
-
let { parent } = context;
|
|
3024
|
-
if (parent && !((0, _vue_compiler_dom.hasSingleChild)(parent.node) || (0, _vue_compiler_dom.isSingleIfBlock)(parent.node))) return false;
|
|
3025
|
-
while (parent && parent.parent && parent.node.type === 1 && parent.node.tagType === 3) {
|
|
3026
|
-
parent = parent.parent;
|
|
3027
|
-
if (!((0, _vue_compiler_dom.hasSingleChild)(parent.node) || (0, _vue_compiler_dom.isSingleIfBlock)(parent.node))) return false;
|
|
3028
|
-
}
|
|
3029
|
-
return context.root === parent;
|
|
3030
|
-
}
|
|
3031
3247
|
function transformComponentElement(node, propsResult, staticKey, singleRoot, context, isDynamicComponent, useCreateElement) {
|
|
3032
3248
|
const dynamicComponent = isDynamicComponent ? resolveDynamicComponent(node) : void 0;
|
|
3033
3249
|
let { tag } = node;
|
|
@@ -3712,13 +3928,7 @@ const transformText = (node, context) => {
|
|
|
3712
3928
|
};
|
|
3713
3929
|
function processInterpolation(context) {
|
|
3714
3930
|
const parentNode = context.parent.node;
|
|
3715
|
-
const
|
|
3716
|
-
const nexts = children.slice(context.index);
|
|
3717
|
-
const idx = nexts.findIndex((n) => !isTextLike(n));
|
|
3718
|
-
const nodes = idx > -1 ? nexts.slice(0, idx) : nexts;
|
|
3719
|
-
const prev = children[context.index - 1];
|
|
3720
|
-
if (prev && prev.type === 2) nodes.unshift(prev);
|
|
3721
|
-
const values = processTextLikeChildren(nodes, context);
|
|
3931
|
+
const values = processTextLikeChildren(collectAdjacentText(context), context);
|
|
3722
3932
|
if (values.length === 0 && parentNode.type !== 0) return;
|
|
3723
3933
|
const literalValues = values.map((v) => getLiteralExpressionValue(v));
|
|
3724
3934
|
if (literalValues.every((v) => v != null) && parentNode.type !== 0) {
|
|
@@ -3740,6 +3950,18 @@ function processInterpolation(context) {
|
|
|
3740
3950
|
values
|
|
3741
3951
|
});
|
|
3742
3952
|
}
|
|
3953
|
+
function collectAdjacentText(context) {
|
|
3954
|
+
const children = context.parent.node.children;
|
|
3955
|
+
const nodes = [];
|
|
3956
|
+
const prev = children[context.index - 1];
|
|
3957
|
+
let index = prev && prev.type === 2 ? context.index - 1 : context.index;
|
|
3958
|
+
for (; index < children.length; index++) {
|
|
3959
|
+
const child = children[index];
|
|
3960
|
+
if (!isTextLike(child)) break;
|
|
3961
|
+
nodes.push(child);
|
|
3962
|
+
}
|
|
3963
|
+
return nodes;
|
|
3964
|
+
}
|
|
3743
3965
|
function processTextContainer(children, context) {
|
|
3744
3966
|
const values = processTextLikeChildren(children, context);
|
|
3745
3967
|
const literals = values.map((value) => getLiteralExpressionValue(value));
|
|
@@ -4288,7 +4510,7 @@ function createFallback(node, context) {
|
|
|
4288
4510
|
//#region packages/compiler-vapor/src/transforms/vSlot.ts
|
|
4289
4511
|
const transformVSlot = (node, context) => {
|
|
4290
4512
|
if (node.type !== 1) return;
|
|
4291
|
-
const dir = findDir$
|
|
4513
|
+
const dir = findDir$4(node, "slot", true);
|
|
4292
4514
|
const { tagType, children } = node;
|
|
4293
4515
|
const { parent } = context;
|
|
4294
4516
|
const isComponent = tagType === 1;
|
|
@@ -4339,9 +4561,9 @@ function transformTemplateSlot(node, dir, context) {
|
|
|
4339
4561
|
const resolvedArg = dir.arg && resolveExpression(dir.arg);
|
|
4340
4562
|
let arg = resolvedArg;
|
|
4341
4563
|
if (!arg) arg = (0, _vue_compiler_dom.createSimpleExpression)("default", true);
|
|
4342
|
-
const vFor = findDir$
|
|
4343
|
-
const vIf = findDir$
|
|
4344
|
-
const vElse = findDir$
|
|
4564
|
+
const vFor = findDir$4(node, "for");
|
|
4565
|
+
const vIf = findDir$4(node, "if");
|
|
4566
|
+
const vElse = findDir$4(node, /^else(-if)?$/, true);
|
|
4345
4567
|
const { slots } = context;
|
|
4346
4568
|
const [block, onExit] = createSlotBlock(node, dir, context);
|
|
4347
4569
|
if (!vFor && !vIf && !vElse) {
|
|
@@ -4422,7 +4644,7 @@ function isNonWhitespaceContent(node) {
|
|
|
4422
4644
|
return !!node.content.trim();
|
|
4423
4645
|
}
|
|
4424
4646
|
function isSlotTemplateChild(node) {
|
|
4425
|
-
return node.type === 1 && (0, _vue_compiler_dom.isTemplateNode)(node) && !!findDir$
|
|
4647
|
+
return node.type === 1 && (0, _vue_compiler_dom.isTemplateNode)(node) && !!findDir$4(node, "slot", true);
|
|
4426
4648
|
}
|
|
4427
4649
|
//#endregion
|
|
4428
4650
|
//#region packages/compiler-vapor/src/transforms/transformTransition.ts
|
|
@@ -4435,17 +4657,17 @@ function hasMultipleChildren(node) {
|
|
|
4435
4657
|
const children = node.children = node.children.filter((c) => c.type !== 3 && !(c.type === 2 && !c.content.trim()));
|
|
4436
4658
|
const first = children[0];
|
|
4437
4659
|
if (children.length === 1 && first.type === 1) {
|
|
4438
|
-
if (findDir$
|
|
4660
|
+
if (findDir$4(first, "for")) return true;
|
|
4439
4661
|
if ((0, _vue_compiler_dom.isTemplateNode)(first)) return hasMultipleChildren(first);
|
|
4440
4662
|
}
|
|
4441
|
-
const hasElse = (node) => findDir$
|
|
4442
|
-
if (children.length > 0 && children.every((c, index) => c.type === 1 && (!(0, _vue_compiler_dom.isTemplateNode)(c) || !hasMultipleChildren(c)) && !findDir$
|
|
4663
|
+
const hasElse = (node) => findDir$4(node, "else-if") || findDir$4(node, "else", true);
|
|
4664
|
+
if (children.length > 0 && children.every((c, index) => c.type === 1 && (!(0, _vue_compiler_dom.isTemplateNode)(c) || !hasMultipleChildren(c)) && !findDir$4(c, "for") && (index === 0 ? findDir$4(c, "if") : hasElse(c)))) return false;
|
|
4443
4665
|
return children.length !== 1;
|
|
4444
4666
|
}
|
|
4445
4667
|
//#endregion
|
|
4446
4668
|
//#region packages/compiler-vapor/src/transforms/transformKey.ts
|
|
4447
4669
|
const transformKey = (node, context) => {
|
|
4448
|
-
if (node.type !== 1 || context.inVOnce || findDir$
|
|
4670
|
+
if (node.type !== 1 || context.inVOnce || findDir$4(node, "for")) return;
|
|
4449
4671
|
const dir = findProp$1(node, "key", true, true);
|
|
4450
4672
|
if (!dir || dir.type === 6) return;
|
|
4451
4673
|
let value;
|