@vue/compiler-vapor 3.6.0-beta.11 → 3.6.0-beta.13
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 +1022 -166
- package/dist/compiler-vapor.d.ts +93 -40
- package/dist/compiler-vapor.esm-browser.js +1155 -227
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-vapor v3.6.0-beta.
|
|
2
|
+
* @vue/compiler-vapor v3.6.0-beta.13
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -248,7 +248,8 @@ var TransformContext = class TransformContext {
|
|
|
248
248
|
this.operationIndex = this.block.operation.length;
|
|
249
249
|
this.isLastEffectiveChild = true;
|
|
250
250
|
this.isOnRightmostPath = true;
|
|
251
|
-
this.
|
|
251
|
+
this.templateCloseTags = void 0;
|
|
252
|
+
this.templateCloseBlocks = false;
|
|
252
253
|
this.globalId = 0;
|
|
253
254
|
this.nextIdMap = null;
|
|
254
255
|
this.ifIndex = 0;
|
|
@@ -374,11 +375,6 @@ var TransformContext = class TransformContext {
|
|
|
374
375
|
while (effectiveParent && effectiveParent.node.type === 1 && effectiveParent.node.tagType === 3) effectiveParent = effectiveParent.parent;
|
|
375
376
|
const isLastEffectiveChild = this.isEffectivelyLastChild(index);
|
|
376
377
|
const isOnRightmostPath = this.isOnRightmostPath && isLastEffectiveChild;
|
|
377
|
-
let hasInlineAncestorNeedingClose = this.hasInlineAncestorNeedingClose;
|
|
378
|
-
if (this.node.type === 1) {
|
|
379
|
-
if (this.node.tag === "template") hasInlineAncestorNeedingClose = false;
|
|
380
|
-
else if (!hasInlineAncestorNeedingClose && !this.isOnRightmostPath && (0, _vue_shared.isInlineTag)(this.node.tag)) hasInlineAncestorNeedingClose = true;
|
|
381
|
-
}
|
|
382
378
|
return Object.assign(Object.create(TransformContext.prototype), this, {
|
|
383
379
|
node,
|
|
384
380
|
parent: this,
|
|
@@ -393,7 +389,8 @@ var TransformContext = class TransformContext {
|
|
|
393
389
|
effectiveParent,
|
|
394
390
|
isLastEffectiveChild,
|
|
395
391
|
isOnRightmostPath,
|
|
396
|
-
|
|
392
|
+
templateCloseTags: this.templateCloseTags,
|
|
393
|
+
templateCloseBlocks: this.templateCloseBlocks
|
|
397
394
|
});
|
|
398
395
|
}
|
|
399
396
|
shiftEffectBoundaries(index, dynamic = this.dynamic) {
|
|
@@ -586,6 +583,9 @@ function genCall(name, ...frags) {
|
|
|
586
583
|
hasPlaceholder ? name[1] : "null"
|
|
587
584
|
], ...frags)];
|
|
588
585
|
}
|
|
586
|
+
function getParserOptions(plugins) {
|
|
587
|
+
return { plugins: plugins ? plugins.some((plugin) => plugin === "typescript") ? plugins : [...plugins, "typescript"] : ["typescript"] };
|
|
588
|
+
}
|
|
589
589
|
function codeFragmentToString(code, context) {
|
|
590
590
|
const { options: { filename, sourceMap } } = context;
|
|
591
591
|
let map;
|
|
@@ -661,6 +661,7 @@ function genPrependNode(oper, { helper }) {
|
|
|
661
661
|
//#endregion
|
|
662
662
|
//#region packages/compiler-vapor/src/generators/expression.ts
|
|
663
663
|
function genExpression(node, context, assignment) {
|
|
664
|
+
node = context.getExpressionReplacement(node);
|
|
664
665
|
const { content, ast, isStatic, loc } = node;
|
|
665
666
|
if (isStatic) return [[
|
|
666
667
|
JSON.stringify(content),
|
|
@@ -775,11 +776,15 @@ function canPrefix(name) {
|
|
|
775
776
|
return true;
|
|
776
777
|
}
|
|
777
778
|
function processExpressions(context, expressions, shouldDeclare) {
|
|
779
|
+
const expressionReplacements = /* @__PURE__ */ new Map();
|
|
778
780
|
const { seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
|
|
779
781
|
const reservedNames = new Set(seenIdentifier);
|
|
780
|
-
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames);
|
|
781
|
-
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames);
|
|
782
|
-
return
|
|
782
|
+
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames, expressionReplacements);
|
|
783
|
+
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames, expressionReplacements);
|
|
784
|
+
return {
|
|
785
|
+
...genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare),
|
|
786
|
+
expressionReplacements
|
|
787
|
+
};
|
|
783
788
|
}
|
|
784
789
|
function analyzeExpressions(expressions) {
|
|
785
790
|
const seenVariable = Object.create(null);
|
|
@@ -837,7 +842,13 @@ function analyzeExpressions(expressions) {
|
|
|
837
842
|
updatedVariable
|
|
838
843
|
};
|
|
839
844
|
}
|
|
840
|
-
function
|
|
845
|
+
function getProcessedExpression(exp, expressionReplacements) {
|
|
846
|
+
return expressionReplacements.get(exp) || exp;
|
|
847
|
+
}
|
|
848
|
+
function setExpressionReplacement(expressionReplacements, exp, content, ast) {
|
|
849
|
+
expressionReplacements.set(exp, (0, _vue_shared.extend)({ ast }, (0, _vue_compiler_dom.createSimpleExpression)(content, exp.isStatic, exp.loc, exp.constType)));
|
|
850
|
+
}
|
|
851
|
+
function processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames, expressionReplacements) {
|
|
841
852
|
const declarations = [];
|
|
842
853
|
const expToReplacementMap = /* @__PURE__ */ new Map();
|
|
843
854
|
for (const [name, exps] of variableToExpMap) {
|
|
@@ -870,14 +881,15 @@ function processRepeatedVariables(context, seenVariable, variableToExpMap, expTo
|
|
|
870
881
|
}
|
|
871
882
|
}
|
|
872
883
|
for (const [exp, replacements] of expToReplacementMap) {
|
|
884
|
+
let content = getProcessedExpression(exp, expressionReplacements).content;
|
|
873
885
|
replacements.flatMap(({ name, locs }) => locs.map(({ start, end }) => ({
|
|
874
886
|
start,
|
|
875
887
|
end,
|
|
876
888
|
name
|
|
877
889
|
}))).sort((a, b) => b.end - a.end).forEach(({ start, end, name }) => {
|
|
878
|
-
|
|
890
|
+
content = content.slice(0, start - 1) + name + content.slice(end - 1);
|
|
879
891
|
});
|
|
880
|
-
exp
|
|
892
|
+
setExpressionReplacement(expressionReplacements, exp, content, parseExp(context, content));
|
|
881
893
|
}
|
|
882
894
|
return declarations;
|
|
883
895
|
}
|
|
@@ -893,13 +905,14 @@ function shouldDeclareVariable(name, expToVariableMap, exps) {
|
|
|
893
905
|
if (vars.every((v) => v.every((e, idx) => e === first[idx]))) return false;
|
|
894
906
|
return true;
|
|
895
907
|
}
|
|
896
|
-
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames) {
|
|
908
|
+
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames, expressionReplacements) {
|
|
897
909
|
const declarations = [];
|
|
898
910
|
const seenExp = expressions.reduce((acc, exp) => {
|
|
899
911
|
const vars = expToVariableMap.get(exp);
|
|
900
912
|
if (!vars) return acc;
|
|
913
|
+
const processed = getProcessedExpression(exp, expressionReplacements);
|
|
901
914
|
const variables = vars.map((v) => v.name);
|
|
902
|
-
if (
|
|
915
|
+
if (processed.ast && processed.ast.type !== "Identifier" && !(variables && variables.some((v) => updatedVariable.has(v))) && !variables.some((v) => (0, _vue_shared.isGloballyAllowed)(v))) acc[processed.content] = (acc[processed.content] || 0) + 1;
|
|
903
916
|
return acc;
|
|
904
917
|
}, Object.create(null));
|
|
905
918
|
Object.entries(seenExp).forEach(([content, count]) => {
|
|
@@ -908,13 +921,13 @@ function processRepeatedExpressions(context, expressions, varDeclarations, updat
|
|
|
908
921
|
for (let i = varDeclarations.length - 1; i >= 0; i--) {
|
|
909
922
|
const item = varDeclarations[i];
|
|
910
923
|
if (!item.exps || !item.seenCount) continue;
|
|
911
|
-
if ([...item.exps].every((node) => node.content === content && item.seenCount === count)) {
|
|
924
|
+
if ([...item.exps].every((node) => getProcessedExpression(node, expressionReplacements).content === content && item.seenCount === count)) {
|
|
912
925
|
delVars[item.name] = item.rawName;
|
|
913
926
|
reservedNames.delete(item.name);
|
|
914
927
|
varDeclarations.splice(i, 1);
|
|
915
928
|
}
|
|
916
929
|
}
|
|
917
|
-
const value = (0, _vue_shared.extend)({}, expressions.find((exp) => exp.content === content));
|
|
930
|
+
const value = (0, _vue_shared.extend)({}, getProcessedExpression(expressions.find((exp) => getProcessedExpression(exp, expressionReplacements).content === content), expressionReplacements));
|
|
918
931
|
Object.keys(delVars).forEach((name) => {
|
|
919
932
|
value.content = value.content.replace(name, delVars[name]);
|
|
920
933
|
if (value.ast) value.ast = parseExp(context, value.content);
|
|
@@ -925,12 +938,11 @@ function processRepeatedExpressions(context, expressions, varDeclarations, updat
|
|
|
925
938
|
value
|
|
926
939
|
});
|
|
927
940
|
expressions.forEach((exp) => {
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
exp.ast = parseExp(context, exp.content);
|
|
941
|
+
const processed = getProcessedExpression(exp, expressionReplacements);
|
|
942
|
+
if (processed.content === content) setExpressionReplacement(expressionReplacements, exp, varName, null);
|
|
943
|
+
else if (processed.content.includes(content)) {
|
|
944
|
+
const replacedContent = processed.content.replace(new RegExp(escapeRegExp(content), "g"), varName);
|
|
945
|
+
setExpressionReplacement(expressionReplacements, exp, replacedContent, parseExp(context, replacedContent));
|
|
934
946
|
}
|
|
935
947
|
});
|
|
936
948
|
}
|
|
@@ -968,9 +980,7 @@ function escapeRegExp(string) {
|
|
|
968
980
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
969
981
|
}
|
|
970
982
|
function parseExp(context, content) {
|
|
971
|
-
|
|
972
|
-
const options = { plugins: plugins ? [...plugins, "typescript"] : ["typescript"] };
|
|
973
|
-
return (0, _babel_parser.parseExpression)(`(${content})`, options);
|
|
983
|
+
return (0, _babel_parser.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
974
984
|
}
|
|
975
985
|
function genVarName(exp) {
|
|
976
986
|
return `${exp.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/_+$/, "")}`;
|
|
@@ -1011,22 +1021,31 @@ const isMemberExpression$3 = (node) => {
|
|
|
1011
1021
|
function genSetEvent(oper, context) {
|
|
1012
1022
|
const { helper } = context;
|
|
1013
1023
|
const { element, key, keyOverride, value, modifiers, delegate, effect } = oper;
|
|
1014
|
-
|
|
1015
|
-
const handler = [
|
|
1016
|
-
`${context.helper("createInvoker")}(`,
|
|
1017
|
-
...genEventHandler(context, [value], modifiers),
|
|
1018
|
-
`)`
|
|
1019
|
-
];
|
|
1020
|
-
const eventOptions = genEventOptions();
|
|
1024
|
+
let handler;
|
|
1021
1025
|
if (delegate) {
|
|
1022
1026
|
context.delegates.add(key.content);
|
|
1023
1027
|
if (!context.block.operation.some(isSameDelegateEvent)) return [
|
|
1024
1028
|
NEWLINE,
|
|
1025
1029
|
`n${element}.$evt${key.content} = `,
|
|
1026
|
-
...
|
|
1030
|
+
...genDirectHandler()
|
|
1031
|
+
];
|
|
1032
|
+
}
|
|
1033
|
+
const name = genName();
|
|
1034
|
+
const eventOptions = genEventOptions();
|
|
1035
|
+
return [NEWLINE, ...genCall(helper(effect ? "onBinding" : delegate ? "delegate" : "on"), `n${element}`, name, genHandler(), eventOptions)];
|
|
1036
|
+
function genHandler() {
|
|
1037
|
+
return handler || (handler = genEventHandler(context, [value], modifiers));
|
|
1038
|
+
}
|
|
1039
|
+
function genInvoker() {
|
|
1040
|
+
return [
|
|
1041
|
+
`${helper("createInvoker")}(`,
|
|
1042
|
+
...genHandler(),
|
|
1043
|
+
`)`
|
|
1027
1044
|
];
|
|
1028
1045
|
}
|
|
1029
|
-
|
|
1046
|
+
function genDirectHandler() {
|
|
1047
|
+
return modifiers.keys.length || modifiers.nonKeys.length ? genEventHandler(context, [value], modifiers, { modifierHelper: "vapor" }) : genInvoker();
|
|
1048
|
+
}
|
|
1030
1049
|
function genName() {
|
|
1031
1050
|
const expr = genExpression(key, context);
|
|
1032
1051
|
if (keyOverride) {
|
|
@@ -1046,8 +1065,8 @@ function genSetEvent(oper, context) {
|
|
|
1046
1065
|
}
|
|
1047
1066
|
function genEventOptions() {
|
|
1048
1067
|
let { options } = modifiers;
|
|
1049
|
-
if (!options.length
|
|
1050
|
-
return genMulti(DELIMITERS_OBJECT_NEWLINE,
|
|
1068
|
+
if (!options.length) return;
|
|
1069
|
+
return genMulti(DELIMITERS_OBJECT_NEWLINE, ...options.map((option) => [`${option}: true`]));
|
|
1051
1070
|
}
|
|
1052
1071
|
function isSameDelegateEvent(op) {
|
|
1053
1072
|
if (op.type === 6 && op !== oper && op.delegate && op.element === oper.element && op.key.content === key.content) return true;
|
|
@@ -1060,7 +1079,9 @@ function genSetDynamicEvents(oper, context) {
|
|
|
1060
1079
|
function genEventHandler(context, values, modifiers = {
|
|
1061
1080
|
nonKeys: [],
|
|
1062
1081
|
keys: []
|
|
1063
|
-
},
|
|
1082
|
+
}, options = {}) {
|
|
1083
|
+
const { asComponentProp = false, extraWrap = false, modifierHelper = "runtime" } = options;
|
|
1084
|
+
const useVaporModifierHelper = modifierHelper === "vapor";
|
|
1064
1085
|
let handlerExp = [];
|
|
1065
1086
|
if (values) {
|
|
1066
1087
|
values.forEach((value, index) => {
|
|
@@ -1101,16 +1122,16 @@ function genEventHandler(context, values, modifiers = {
|
|
|
1101
1122
|
}
|
|
1102
1123
|
if (handlerExp.length === 0) handlerExp = ["() => {}"];
|
|
1103
1124
|
const { keys, nonKeys } = modifiers;
|
|
1104
|
-
if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys);
|
|
1105
|
-
if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys);
|
|
1125
|
+
if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys, useVaporModifierHelper && !keys.length);
|
|
1126
|
+
if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys, useVaporModifierHelper);
|
|
1106
1127
|
if (extraWrap) handlerExp.unshift(`() => `);
|
|
1107
1128
|
return handlerExp;
|
|
1108
1129
|
}
|
|
1109
|
-
function genWithModifiers(context, handler, nonKeys) {
|
|
1110
|
-
return genCall(context.helper("withModifiers"), handler, JSON.stringify(nonKeys));
|
|
1130
|
+
function genWithModifiers(context, handler, nonKeys, useVaporHelper = false) {
|
|
1131
|
+
return genCall(context.helper(useVaporHelper ? "withVaporModifiers" : "withModifiers"), handler, JSON.stringify(nonKeys));
|
|
1111
1132
|
}
|
|
1112
|
-
function genWithKeys(context, handler, keys) {
|
|
1113
|
-
return genCall(context.helper("withKeys"), handler, JSON.stringify(keys));
|
|
1133
|
+
function genWithKeys(context, handler, keys, useVaporHelper = false) {
|
|
1134
|
+
return genCall(context.helper(useVaporHelper ? "withVaporKeys" : "withKeys"), handler, JSON.stringify(keys));
|
|
1114
1135
|
}
|
|
1115
1136
|
function isConstantBinding(value, context) {
|
|
1116
1137
|
if (value.ast === null) {
|
|
@@ -1148,16 +1169,12 @@ function genFor(oper, context) {
|
|
|
1148
1169
|
idMap[rawIndex] = `${indexVar}.value`;
|
|
1149
1170
|
idMap[indexVar] = null;
|
|
1150
1171
|
}
|
|
1151
|
-
const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap);
|
|
1172
|
+
const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap, context);
|
|
1152
1173
|
const selectorDeclarations = [];
|
|
1153
|
-
const
|
|
1174
|
+
const selectorName = (i) => selectorPatterns.length > 1 ? `_selector${id}_${i}` : `_selector${id}`;
|
|
1154
1175
|
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
1155
1176
|
const { selector } = selectorPatterns[i];
|
|
1156
|
-
const selectorName = `
|
|
1157
|
-
selectorDeclarations.push(`let ${selectorName}`, NEWLINE);
|
|
1158
|
-
if (i === 0) selectorSetup.push(`({ createSelector }) => {`, INDENT_START);
|
|
1159
|
-
selectorSetup.push(NEWLINE, `${selectorName} = `, ...genCall(`createSelector`, [`() => `, ...genExpression(selector, context)]));
|
|
1160
|
-
if (i === selectorPatterns.length - 1) selectorSetup.push(INDENT_END, NEWLINE, "}");
|
|
1177
|
+
selectorDeclarations.push(`const ${selectorName(i)} = `, ...genCall(helper("createSelector"), [`() => `, ...genExpression(selector, context)]), NEWLINE);
|
|
1161
1178
|
}
|
|
1162
1179
|
const blockFn = context.withId(() => {
|
|
1163
1180
|
const frag = [];
|
|
@@ -1166,7 +1183,7 @@ function genFor(oper, context) {
|
|
|
1166
1183
|
const patternFrag = [];
|
|
1167
1184
|
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
1168
1185
|
const { effect } = selectorPatterns[i];
|
|
1169
|
-
patternFrag.push(NEWLINE,
|
|
1186
|
+
patternFrag.push(NEWLINE, `${selectorName(i)}(`, ...genExpression(keyProp, context), `, () => {`, INDENT_START);
|
|
1170
1187
|
for (const oper of effect.operations) patternFrag.push(...genOperation(oper, context));
|
|
1171
1188
|
patternFrag.push(INDENT_END, NEWLINE, `})`);
|
|
1172
1189
|
}
|
|
@@ -1181,12 +1198,17 @@ function genFor(oper, context) {
|
|
|
1181
1198
|
let flags = 0;
|
|
1182
1199
|
if (onlyChild) flags |= 1;
|
|
1183
1200
|
if (component) flags |= 2;
|
|
1201
|
+
if (isFragmentBlock(render)) flags |= 16;
|
|
1202
|
+
if (!component && isSingleNodeBlock(render)) flags |= 8;
|
|
1184
1203
|
if (once) flags |= 4;
|
|
1204
|
+
const onResetCalls = [];
|
|
1205
|
+
for (let i = 0; i < selectorPatterns.length; i++) onResetCalls.push(NEWLINE, `n${id}.onReset(${selectorName(i)}.reset)`);
|
|
1185
1206
|
return [
|
|
1186
1207
|
NEWLINE,
|
|
1187
1208
|
...selectorDeclarations,
|
|
1188
1209
|
`const n${id} = `,
|
|
1189
|
-
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags ? String(flags) : void 0,
|
|
1210
|
+
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags ? String(flags) : void 0),
|
|
1211
|
+
...onResetCalls
|
|
1190
1212
|
];
|
|
1191
1213
|
function genCallback(expr) {
|
|
1192
1214
|
if (!expr) return false;
|
|
@@ -1210,6 +1232,21 @@ function genFor(oper, context) {
|
|
|
1210
1232
|
return idMap;
|
|
1211
1233
|
}
|
|
1212
1234
|
}
|
|
1235
|
+
function isSingleNodeBlock(block) {
|
|
1236
|
+
const child = getSingleReturnedChild(block);
|
|
1237
|
+
return !!child && child.template != null;
|
|
1238
|
+
}
|
|
1239
|
+
function isFragmentBlock(block) {
|
|
1240
|
+
const child = getSingleReturnedChild(block);
|
|
1241
|
+
const operation = child && child.operation;
|
|
1242
|
+
if (!operation) return false;
|
|
1243
|
+
return operation.type === 13 || operation.type === 16 || operation.type === 17 || operation.type === 15 && !operation.once || operation.type === 12 && !!operation.dynamic && !operation.dynamic.isStatic;
|
|
1244
|
+
}
|
|
1245
|
+
function getSingleReturnedChild(block) {
|
|
1246
|
+
if (block.returns.length !== 1) return;
|
|
1247
|
+
const id = block.returns[0];
|
|
1248
|
+
for (const child of block.dynamic.children) if (child.id === id) return child;
|
|
1249
|
+
}
|
|
1213
1250
|
function parseValueDestructure(value, context) {
|
|
1214
1251
|
const map = /* @__PURE__ */ new Map();
|
|
1215
1252
|
if (value) {
|
|
@@ -1272,19 +1309,19 @@ function buildDestructureIdMap(idToPathMap, baseAccessor, plugins) {
|
|
|
1272
1309
|
}
|
|
1273
1310
|
if (pathInfo.dynamic) {
|
|
1274
1311
|
const node = idMap[id] = (0, _vue_compiler_dom.createSimpleExpression)(path);
|
|
1275
|
-
node.ast = (0, _babel_parser.parseExpression)(`(${path})`,
|
|
1312
|
+
node.ast = (0, _babel_parser.parseExpression)(`(${path})`, getParserOptions(plugins));
|
|
1276
1313
|
} else idMap[id] = path;
|
|
1277
1314
|
} else idMap[id] = path;
|
|
1278
1315
|
});
|
|
1279
1316
|
return idMap;
|
|
1280
1317
|
}
|
|
1281
|
-
function matchPatterns(render, keyProp, idMap) {
|
|
1318
|
+
function matchPatterns(render, keyProp, idMap, context) {
|
|
1282
1319
|
const selectorPatterns = [];
|
|
1283
1320
|
const keyOnlyBindingPatterns = [];
|
|
1284
1321
|
const removedEffectIndexes = [];
|
|
1285
1322
|
render.effect = render.effect.filter((effect, index) => {
|
|
1286
1323
|
if (keyProp !== void 0) {
|
|
1287
|
-
const selector = matchSelectorPattern(effect, keyProp.content, idMap);
|
|
1324
|
+
const selector = matchSelectorPattern(effect, keyProp.content, idMap, context);
|
|
1288
1325
|
if (selector) {
|
|
1289
1326
|
selectorPatterns.push(selector);
|
|
1290
1327
|
removedEffectIndexes.push(index);
|
|
@@ -1323,7 +1360,7 @@ function matchKeyOnlyBindingPattern(effect, key) {
|
|
|
1323
1360
|
}
|
|
1324
1361
|
}
|
|
1325
1362
|
}
|
|
1326
|
-
function matchSelectorPattern(effect, key, idMap) {
|
|
1363
|
+
function matchSelectorPattern(effect, key, idMap, context) {
|
|
1327
1364
|
if (effect.expressions.length === 1) {
|
|
1328
1365
|
const { ast, content } = effect.expressions[0];
|
|
1329
1366
|
if (typeof ast === "object" && ast) {
|
|
@@ -1348,17 +1385,11 @@ function matchSelectorPattern(effect, key, idMap) {
|
|
|
1348
1385
|
}, false);
|
|
1349
1386
|
if (!hasExtraId) {
|
|
1350
1387
|
const name = content.slice(selector.start - 1, selector.end - 1);
|
|
1388
|
+
const selectorExpression = (0, _vue_compiler_dom.createSimpleExpression)(name, false, selector.loc);
|
|
1389
|
+
selectorExpression.ast = (0, _babel_parser.parseExpression)(`(${name})`, getParserOptions(context.options.expressionPlugins));
|
|
1351
1390
|
return {
|
|
1352
1391
|
effect,
|
|
1353
|
-
selector:
|
|
1354
|
-
content: name,
|
|
1355
|
-
ast: (0, _vue_shared.extend)({}, selector, {
|
|
1356
|
-
start: 1,
|
|
1357
|
-
end: name.length + 1
|
|
1358
|
-
}),
|
|
1359
|
-
loc: selector.loc,
|
|
1360
|
-
isStatic: false
|
|
1361
|
-
}
|
|
1392
|
+
selector: selectorExpression
|
|
1362
1393
|
};
|
|
1363
1394
|
}
|
|
1364
1395
|
}
|
|
@@ -1401,6 +1432,7 @@ function genIf(oper, context, isNested = false) {
|
|
|
1401
1432
|
const { helper } = context;
|
|
1402
1433
|
const { condition, positive, negative, once, index, blockShape } = oper;
|
|
1403
1434
|
const [frag, push] = buildCodeFragment();
|
|
1435
|
+
const flags = genIfFlags(blockShape, once, negative ? index : void 0);
|
|
1404
1436
|
const conditionExpr = [
|
|
1405
1437
|
"() => (",
|
|
1406
1438
|
...genExpression(condition, context),
|
|
@@ -1411,15 +1443,31 @@ function genIf(oper, context, isNested = false) {
|
|
|
1411
1443
|
if (negative) if (negative.type === 1) negativeArg = genBlock(negative, context);
|
|
1412
1444
|
else negativeArg = ["() => ", ...genIf(negative, context, true)];
|
|
1413
1445
|
if (!isNested) push(NEWLINE, `const n${oper.id} = `);
|
|
1414
|
-
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg,
|
|
1446
|
+
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, flags));
|
|
1415
1447
|
return frag;
|
|
1416
1448
|
}
|
|
1449
|
+
function genIfFlags(blockShape, once, index) {
|
|
1450
|
+
let flags = blockShape;
|
|
1451
|
+
if (once) flags |= 16;
|
|
1452
|
+
else if (index !== void 0) flags |= index + 1 << 7;
|
|
1453
|
+
if (flags === 1) return false;
|
|
1454
|
+
return `${flags} /* ${genIfFlagNames(once, index, blockShape)} */`;
|
|
1455
|
+
}
|
|
1456
|
+
function genIfFlagNames(once, index, blockShape) {
|
|
1457
|
+
const names = ["BLOCK_SHAPE"];
|
|
1458
|
+
if (blockShape & 32) names.push("TRUE_NO_SCOPE");
|
|
1459
|
+
if (blockShape & 64) names.push("FALSE_NO_SCOPE");
|
|
1460
|
+
if (once) names.push("ONCE");
|
|
1461
|
+
else if (index !== void 0) names.push("INDEX_SHIFT");
|
|
1462
|
+
return names.join(", ");
|
|
1463
|
+
}
|
|
1417
1464
|
//#endregion
|
|
1418
1465
|
//#region packages/compiler-vapor/src/generators/prop.ts
|
|
1419
1466
|
const helpers = {
|
|
1420
1467
|
setText: { name: "setText" },
|
|
1421
1468
|
setHtml: { name: "setHtml" },
|
|
1422
1469
|
setClass: { name: "setClass" },
|
|
1470
|
+
setClassName: { name: "setClassName" },
|
|
1423
1471
|
setStyle: { name: "setStyle" },
|
|
1424
1472
|
setValue: { name: "setValue" },
|
|
1425
1473
|
setAttr: {
|
|
@@ -1439,9 +1487,133 @@ function genSetProp(oper, context) {
|
|
|
1439
1487
|
const { helper } = context;
|
|
1440
1488
|
const { prop: { key, values, modifier }, tag } = oper;
|
|
1441
1489
|
const resolvedHelper = getRuntimeHelper(tag, key.content, modifier);
|
|
1490
|
+
if (key.content === "class" && !resolvedHelper.isSVG && resolvedHelper.name === "setClass") {
|
|
1491
|
+
const className = genSetClassName(oper, context);
|
|
1492
|
+
if (className) return className;
|
|
1493
|
+
}
|
|
1442
1494
|
const propValue = genPropValue(values, context);
|
|
1443
1495
|
return [NEWLINE, ...genCall([helper(resolvedHelper.name), null], `n${oper.element}`, resolvedHelper.needKey ? genExpression(key, context) : false, propValue, resolvedHelper.isSVG && "true")];
|
|
1444
1496
|
}
|
|
1497
|
+
const MAX_CLASS_NAME_ENTRIES = 31;
|
|
1498
|
+
function genSetClassName(oper, context) {
|
|
1499
|
+
const info = resolveClassName(oper.prop.values, context);
|
|
1500
|
+
if (!info) return;
|
|
1501
|
+
const { helper } = context;
|
|
1502
|
+
const flags = genClassFlags(info.entries, context);
|
|
1503
|
+
const classFragments = info.entries.map((entry) => JSON.stringify(!info.prefix && info.entries.length === 1 ? entry.className : ` ${entry.className}`));
|
|
1504
|
+
const fragments = classFragments.length === 1 ? classFragments[0] : genMulti(DELIMITERS_ARRAY, ...classFragments);
|
|
1505
|
+
return [NEWLINE, ...genCall([helper("setClassName"), "\"\""], `n${oper.element}`, flags, fragments, info.prefix && JSON.stringify(info.prefix), info.suffix && JSON.stringify(info.suffix))];
|
|
1506
|
+
}
|
|
1507
|
+
function resolveClassName(values, context) {
|
|
1508
|
+
let prefix = "";
|
|
1509
|
+
let suffix = "";
|
|
1510
|
+
const entries = [];
|
|
1511
|
+
let sawDynamic = false;
|
|
1512
|
+
let sawSuffix = false;
|
|
1513
|
+
for (const rawValue of values) {
|
|
1514
|
+
const value = context.getExpressionReplacement(rawValue);
|
|
1515
|
+
const staticValue = getLiteralExpressionValue(value, true);
|
|
1516
|
+
if (staticValue != null) {
|
|
1517
|
+
const normalized = (0, _vue_shared.normalizeClass)(staticValue);
|
|
1518
|
+
if (normalized) if (sawSuffix) suffix = appendClass$1(suffix, normalized);
|
|
1519
|
+
else if (sawDynamic) {
|
|
1520
|
+
sawSuffix = true;
|
|
1521
|
+
suffix = appendClass$1(suffix, normalized);
|
|
1522
|
+
} else prefix = appendClass$1(prefix, normalized);
|
|
1523
|
+
continue;
|
|
1524
|
+
}
|
|
1525
|
+
const ast = value.ast;
|
|
1526
|
+
if (!ast || sawSuffix) return;
|
|
1527
|
+
sawDynamic = true;
|
|
1528
|
+
if (ast.type === "ObjectExpression") {
|
|
1529
|
+
if (!resolveObjectClassName(value, ast, entries, context)) return;
|
|
1530
|
+
} else if (ast.type === "ConditionalExpression") {
|
|
1531
|
+
if (!resolveConditionalClassName(value, ast, entries, context)) return;
|
|
1532
|
+
} else return;
|
|
1533
|
+
}
|
|
1534
|
+
return entries.length && entries.length <= MAX_CLASS_NAME_ENTRIES ? {
|
|
1535
|
+
prefix,
|
|
1536
|
+
suffix,
|
|
1537
|
+
entries
|
|
1538
|
+
} : void 0;
|
|
1539
|
+
}
|
|
1540
|
+
function resolveObjectClassName(source, ast, entries, context) {
|
|
1541
|
+
for (const prop of ast.properties) {
|
|
1542
|
+
if (prop.type !== "ObjectProperty" || prop.computed) return false;
|
|
1543
|
+
const rawClassName = getObjectPropertyName$1(prop);
|
|
1544
|
+
if (rawClassName == null) return false;
|
|
1545
|
+
const className = (0, _vue_shared.normalizeClass)(rawClassName);
|
|
1546
|
+
if (!className) continue;
|
|
1547
|
+
const value = getBooleanValue(prop.value);
|
|
1548
|
+
entries.push({
|
|
1549
|
+
className,
|
|
1550
|
+
value,
|
|
1551
|
+
condition: value == null ? createSubExpression(source, prop.value, context) : void 0
|
|
1552
|
+
});
|
|
1553
|
+
}
|
|
1554
|
+
return true;
|
|
1555
|
+
}
|
|
1556
|
+
function resolveConditionalClassName(source, ast, entries, context) {
|
|
1557
|
+
const consequent = getStringClassValue(ast.consequent);
|
|
1558
|
+
const alternate = getStringClassValue(ast.alternate);
|
|
1559
|
+
if (consequent && alternate === "") {
|
|
1560
|
+
entries.push({
|
|
1561
|
+
className: consequent,
|
|
1562
|
+
condition: createSubExpression(source, ast.test, context)
|
|
1563
|
+
});
|
|
1564
|
+
return true;
|
|
1565
|
+
} else if (alternate && consequent === "") {
|
|
1566
|
+
entries.push({
|
|
1567
|
+
className: alternate,
|
|
1568
|
+
condition: createSubExpression(source, ast.test, context),
|
|
1569
|
+
negate: true
|
|
1570
|
+
});
|
|
1571
|
+
return true;
|
|
1572
|
+
}
|
|
1573
|
+
return false;
|
|
1574
|
+
}
|
|
1575
|
+
function genClassFlags(entries, context) {
|
|
1576
|
+
const values = [];
|
|
1577
|
+
entries.forEach((entry, index) => {
|
|
1578
|
+
if (index) values.push(" | ");
|
|
1579
|
+
const bit = 1 << index;
|
|
1580
|
+
if (entry.value != null) {
|
|
1581
|
+
values.push(entry.value ? String(bit) : "0");
|
|
1582
|
+
return;
|
|
1583
|
+
}
|
|
1584
|
+
values.push("(", ...genExpression(entry.condition, context), entry.negate ? ` ? 0 : ${bit}` : ` ? ${bit} : 0`, ")");
|
|
1585
|
+
});
|
|
1586
|
+
return values;
|
|
1587
|
+
}
|
|
1588
|
+
function appendClass$1(base, value) {
|
|
1589
|
+
return base ? value ? `${base} ${value}` : base : value;
|
|
1590
|
+
}
|
|
1591
|
+
function getObjectPropertyName$1(prop) {
|
|
1592
|
+
const key = prop.key;
|
|
1593
|
+
if (key.type === "Identifier") return key.name;
|
|
1594
|
+
else if (key.type === "StringLiteral") return key.value;
|
|
1595
|
+
else if (key.type === "NumericLiteral") return String(key.value);
|
|
1596
|
+
}
|
|
1597
|
+
function getStringClassValue(node) {
|
|
1598
|
+
if (node.type === "StringLiteral") return (0, _vue_shared.normalizeClass)(node.value);
|
|
1599
|
+
else if (node.type === "TemplateLiteral" && node.expressions.length === 0) return (0, _vue_shared.normalizeClass)(node.quasis[0].value.cooked || "");
|
|
1600
|
+
else if (node.type === "NullLiteral" || node.type === "BooleanLiteral" && !node.value) return "";
|
|
1601
|
+
}
|
|
1602
|
+
function getBooleanValue(node) {
|
|
1603
|
+
if (node.type === "BooleanLiteral") return node.value;
|
|
1604
|
+
}
|
|
1605
|
+
function createSubExpression(source, node, context) {
|
|
1606
|
+
const start = node.start == null ? 0 : node.start - 1;
|
|
1607
|
+
const end = node.end == null ? source.content.length : node.end - 1;
|
|
1608
|
+
const content = source.content.slice(start, end);
|
|
1609
|
+
const expression = (0, _vue_compiler_dom.createSimpleExpression)(content, false, {
|
|
1610
|
+
start: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, source.content, start),
|
|
1611
|
+
end: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, source.content, end),
|
|
1612
|
+
source: content
|
|
1613
|
+
});
|
|
1614
|
+
expression.ast = (0, _vue_compiler_dom.isSimpleIdentifier)(content) ? null : (0, _babel_parser.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
1615
|
+
return expression;
|
|
1616
|
+
}
|
|
1445
1617
|
function genDynamicProps$1(oper, context) {
|
|
1446
1618
|
const { helper } = context;
|
|
1447
1619
|
const isSVG = (0, _vue_shared.isSVGTag)(oper.tag);
|
|
@@ -1508,8 +1680,23 @@ function getSpecialHelper(keyName, tagName, isSVG) {
|
|
|
1508
1680
|
const setTemplateRefIdent = `_setTemplateRef`;
|
|
1509
1681
|
function genSetTemplateRef(oper, context) {
|
|
1510
1682
|
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
1683
|
+
if (context.staticTemplateRefHelperCandidate === oper) return genSetStaticTemplateRef(oper, refValue, refKey, context);
|
|
1684
|
+
context.needsTemplateRefSetter = true;
|
|
1511
1685
|
return [NEWLINE, ...genCall(setTemplateRefIdent, `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
1512
1686
|
}
|
|
1687
|
+
function genSetStaticTemplateRef(oper, refValue, refKey, context) {
|
|
1688
|
+
return [NEWLINE, ...genCall(context.helper("setStaticTemplateRef"), `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
1689
|
+
}
|
|
1690
|
+
function genSetTemplateRefBinding(oper, context) {
|
|
1691
|
+
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
1692
|
+
const setter = context.inSlotBlock && setTemplateRefIdent;
|
|
1693
|
+
if (context.inSlotBlock) context.needsTemplateRefSetter = true;
|
|
1694
|
+
return [NEWLINE, ...genCall([context.helper("setTemplateRefBinding"), "undefined"], `n${oper.element}`, ["() => ", ...refValue], ...setter || oper.refFor || refKey ? [
|
|
1695
|
+
setter,
|
|
1696
|
+
oper.refFor && "true",
|
|
1697
|
+
refKey
|
|
1698
|
+
] : [])];
|
|
1699
|
+
}
|
|
1513
1700
|
function genRefValue(value, context) {
|
|
1514
1701
|
if (value && context.options.inline) {
|
|
1515
1702
|
const binding = context.options.bindingMetadata[value.content];
|
|
@@ -1613,15 +1800,18 @@ function filterCustomDirectives(id, operations) {
|
|
|
1613
1800
|
//#region packages/compiler-vapor/src/generators/component.ts
|
|
1614
1801
|
function genCreateComponent(operation, context) {
|
|
1615
1802
|
const { helper } = context;
|
|
1803
|
+
const singleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
1804
|
+
const useAssetComponentHelper = operation.asset && !operation.dynamic && context.block === context.ir.block && !!singleUseAssetComponentNames && singleUseAssetComponentNames.has(operation.tag);
|
|
1805
|
+
const maybeSelfReference = useAssetComponentHelper && operation.tag.endsWith("__self");
|
|
1616
1806
|
const tag = genTag();
|
|
1617
1807
|
const { root, props, slots, once } = operation;
|
|
1618
1808
|
const rawSlots = genRawSlots(slots, context);
|
|
1619
1809
|
const [ids, handlers] = processInlineHandlers(props, context);
|
|
1620
|
-
const rawProps = context.withId(() => genRawProps(props, context), ids);
|
|
1810
|
+
const rawProps = context.withId(() => genRawProps(props, context, true), ids);
|
|
1621
1811
|
return [
|
|
1622
1812
|
NEWLINE,
|
|
1623
1813
|
...handlers.reduce((acc, { name, value }) => {
|
|
1624
|
-
const handler = genEventHandler(context, [value]
|
|
1814
|
+
const handler = genEventHandler(context, [value]);
|
|
1625
1815
|
return [
|
|
1626
1816
|
...acc,
|
|
1627
1817
|
`const ${name} = `,
|
|
@@ -1630,7 +1820,7 @@ function genCreateComponent(operation, context) {
|
|
|
1630
1820
|
];
|
|
1631
1821
|
}, []),
|
|
1632
1822
|
`const n${operation.id} = `,
|
|
1633
|
-
...genCall(operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.useCreateElement ? helper("createPlainElement") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, root ? "true" : false, once && "true"),
|
|
1823
|
+
...genCall(operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.useCreateElement ? helper("createPlainElement") : useAssetComponentHelper ? helper("createAssetComponent") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, root ? "true" : false, once && "true", maybeSelfReference && "true"),
|
|
1634
1824
|
...genDirectivesForElement(operation.id, context)
|
|
1635
1825
|
];
|
|
1636
1826
|
function genTag() {
|
|
@@ -1641,7 +1831,10 @@ function genCreateComponent(operation, context) {
|
|
|
1641
1831
|
...genExpression(operation.dynamic, context),
|
|
1642
1832
|
")"
|
|
1643
1833
|
];
|
|
1644
|
-
else if (
|
|
1834
|
+
else if (useAssetComponentHelper) {
|
|
1835
|
+
const name = maybeSelfReference ? operation.tag.slice(0, -6) : operation.tag;
|
|
1836
|
+
return JSON.stringify(name);
|
|
1837
|
+
} else if (operation.asset) return (0, _vue_compiler_dom.toValidAssetId)(operation.tag, "component");
|
|
1645
1838
|
else {
|
|
1646
1839
|
const { tag } = operation;
|
|
1647
1840
|
const builtInTag = isBuiltInComponent(tag);
|
|
@@ -1681,14 +1874,14 @@ function processInlineHandlers(props, context) {
|
|
|
1681
1874
|
}
|
|
1682
1875
|
return [ids, handlers];
|
|
1683
1876
|
}
|
|
1684
|
-
function genRawProps(props, context) {
|
|
1877
|
+
function genRawProps(props, context, directStaticLiteralProps = false) {
|
|
1685
1878
|
const staticProps = props[0];
|
|
1686
1879
|
if ((0, _vue_shared.isArray)(staticProps)) {
|
|
1687
1880
|
if (!staticProps.length && props.length === 1) return;
|
|
1688
|
-
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context));
|
|
1689
|
-
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context));
|
|
1881
|
+
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context, directStaticLiteralProps), directStaticLiteralProps);
|
|
1882
|
+
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context, directStaticLiteralProps), directStaticLiteralProps);
|
|
1690
1883
|
}
|
|
1691
|
-
function genStaticProps(props, context, dynamicProps) {
|
|
1884
|
+
function genStaticProps(props, context, dynamicProps, directStaticLiteralProps = false) {
|
|
1692
1885
|
const args = [];
|
|
1693
1886
|
const handlerGroups = /* @__PURE__ */ new Map();
|
|
1694
1887
|
const ensureHandlerGroup = (keyName, keyFrag) => {
|
|
@@ -1721,11 +1914,11 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
1721
1914
|
continue;
|
|
1722
1915
|
}
|
|
1723
1916
|
const keyFrag = genPropKey(prop, context);
|
|
1724
|
-
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
|
|
1725
|
-
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, true
|
|
1917
|
+
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, { asComponentProp: true }));
|
|
1918
|
+
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, { asComponentProp: true }));
|
|
1726
1919
|
continue;
|
|
1727
1920
|
}
|
|
1728
|
-
args.push(genProp(prop, context, true));
|
|
1921
|
+
args.push(genProp(prop, context, true, true, directStaticLiteralProps && isDirectStaticLiteralProp(prop, context)));
|
|
1729
1922
|
if (prop.model) {
|
|
1730
1923
|
if (prop.key.isStatic) {
|
|
1731
1924
|
const keyName = `onUpdate:${(0, _vue_shared.camelize)(prop.key.content)}`;
|
|
@@ -1750,7 +1943,7 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
1750
1943
|
" + \"Modifiers\"]"
|
|
1751
1944
|
];
|
|
1752
1945
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
1753
|
-
args.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
|
|
1946
|
+
args.push([...modifiersKey, directStaticLiteralProps ? `: { ${modifiersVal} }` : `: () => ({ ${modifiersVal} })`]);
|
|
1754
1947
|
}
|
|
1755
1948
|
}
|
|
1756
1949
|
}
|
|
@@ -1765,13 +1958,13 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
1765
1958
|
if (dynamicProps) args.push([`$: `, ...dynamicProps]);
|
|
1766
1959
|
return genMulti(args.length > 1 ? DELIMITERS_OBJECT_NEWLINE : DELIMITERS_OBJECT, ...args);
|
|
1767
1960
|
}
|
|
1768
|
-
function genDynamicProps(props, context) {
|
|
1961
|
+
function genDynamicProps(props, context, directStaticLiteralProps = false) {
|
|
1769
1962
|
const { helper } = context;
|
|
1770
1963
|
const frags = [];
|
|
1771
1964
|
for (const p of props) {
|
|
1772
1965
|
let expr;
|
|
1773
1966
|
if ((0, _vue_shared.isArray)(p)) {
|
|
1774
|
-
if (p.length) frags.push(genStaticProps(p, context));
|
|
1967
|
+
if (p.length) frags.push(genStaticProps(p, context, void 0, directStaticLiteralProps));
|
|
1775
1968
|
continue;
|
|
1776
1969
|
} else if (p.kind === 1) if (p.model) {
|
|
1777
1970
|
const entries = [genProp(p, context)];
|
|
@@ -1782,7 +1975,7 @@ function genDynamicProps(props, context) {
|
|
|
1782
1975
|
];
|
|
1783
1976
|
entries.push([
|
|
1784
1977
|
...updateKey,
|
|
1785
|
-
":
|
|
1978
|
+
": ",
|
|
1786
1979
|
...genModelHandler(p.values[0], context)
|
|
1787
1980
|
]);
|
|
1788
1981
|
const { modelModifiers } = p;
|
|
@@ -1793,10 +1986,10 @@ function genDynamicProps(props, context) {
|
|
|
1793
1986
|
" + \"Modifiers\"]"
|
|
1794
1987
|
];
|
|
1795
1988
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
1796
|
-
entries.push([...modifiersKey, `:
|
|
1989
|
+
entries.push([...modifiersKey, `: { ${modifiersVal} }`]);
|
|
1797
1990
|
}
|
|
1798
1991
|
expr = genMulti(DELIMITERS_OBJECT_NEWLINE, ...entries);
|
|
1799
|
-
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context));
|
|
1992
|
+
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context, false, false));
|
|
1800
1993
|
else {
|
|
1801
1994
|
expr = genExpression(p.value, context);
|
|
1802
1995
|
if (p.handler) expr = genCall(helper("toHandlers"), expr);
|
|
@@ -1809,27 +2002,79 @@ function genDynamicProps(props, context) {
|
|
|
1809
2002
|
}
|
|
1810
2003
|
if (frags.length) return genMulti(DELIMITERS_ARRAY_NEWLINE, ...frags);
|
|
1811
2004
|
}
|
|
1812
|
-
function genProp(prop, context, isStatic) {
|
|
2005
|
+
function genProp(prop, context, isStatic, wrapHandler = true, directStaticLiteral = false) {
|
|
1813
2006
|
const values = genPropValue(prop.values, context);
|
|
1814
2007
|
return [
|
|
1815
2008
|
...genPropKey(prop, context),
|
|
1816
2009
|
": ",
|
|
1817
|
-
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers,
|
|
2010
|
+
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, {
|
|
2011
|
+
asComponentProp: true,
|
|
2012
|
+
extraWrap: wrapHandler
|
|
2013
|
+
}) : isStatic ? directStaticLiteral ? values : [
|
|
1818
2014
|
"() => (",
|
|
1819
2015
|
...values,
|
|
1820
2016
|
")"
|
|
1821
2017
|
] : values
|
|
1822
2018
|
];
|
|
1823
2019
|
}
|
|
2020
|
+
/**
|
|
2021
|
+
* Static literal values are safe to emit directly because reading them cannot
|
|
2022
|
+
* touch reactive state. Keep handlers, v-model values, and dynamic expressions
|
|
2023
|
+
* as getter sources to preserve lazy access and merge semantics.
|
|
2024
|
+
*/
|
|
2025
|
+
function isDirectStaticLiteralProp(prop, context) {
|
|
2026
|
+
return prop.key.isStatic && prop.values.length === 1 && !prop.handler && !prop.model && isDirectConstantValue(prop.values[0], context);
|
|
2027
|
+
}
|
|
2028
|
+
function isDirectConstantValue(value, context) {
|
|
2029
|
+
value = context.getExpressionReplacement(value);
|
|
2030
|
+
if (value.isStatic) return true;
|
|
2031
|
+
const ast = value.ast;
|
|
2032
|
+
if (ast === null) return value.content === "true" || value.content === "false" || value.content === "null" || value.content === "undefined";
|
|
2033
|
+
if (!ast) return false;
|
|
2034
|
+
return isDirectConstantAst(ast);
|
|
2035
|
+
}
|
|
2036
|
+
function isDirectConstantAst(node) {
|
|
2037
|
+
switch (node.type) {
|
|
2038
|
+
case "StringLiteral":
|
|
2039
|
+
case "NumericLiteral":
|
|
2040
|
+
case "BooleanLiteral":
|
|
2041
|
+
case "NullLiteral":
|
|
2042
|
+
case "BigIntLiteral": return true;
|
|
2043
|
+
case "Identifier": return node.name === "undefined";
|
|
2044
|
+
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
2045
|
+
case "ArrayExpression": return node.elements.every((element) => element === null || element.type !== "SpreadElement" && isDirectConstantAst(element));
|
|
2046
|
+
case "ObjectExpression": return node.properties.every((prop) => prop.type === "ObjectProperty" && !prop.computed && isDirectConstantAst(prop.value));
|
|
2047
|
+
}
|
|
2048
|
+
return false;
|
|
2049
|
+
}
|
|
2050
|
+
function isDirectTemplateConstantAst(node) {
|
|
2051
|
+
switch (node.type) {
|
|
2052
|
+
case "StringLiteral":
|
|
2053
|
+
case "NumericLiteral":
|
|
2054
|
+
case "BooleanLiteral":
|
|
2055
|
+
case "NullLiteral":
|
|
2056
|
+
case "BigIntLiteral": return true;
|
|
2057
|
+
case "Identifier": return node.name === "undefined";
|
|
2058
|
+
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
2059
|
+
}
|
|
2060
|
+
return false;
|
|
2061
|
+
}
|
|
1824
2062
|
function genRawSlots(slots, context) {
|
|
1825
2063
|
if (!slots.length) return;
|
|
1826
2064
|
const staticSlots = slots[0];
|
|
1827
|
-
if (staticSlots.slotType === 0)
|
|
1828
|
-
|
|
2065
|
+
if (staticSlots.slotType === 0) {
|
|
2066
|
+
const defaultSlot = getSingleDefaultSlot(staticSlots);
|
|
2067
|
+
if (defaultSlot && slots.length === 1) return genSlotBlockWithProps(defaultSlot, context);
|
|
2068
|
+
return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
|
|
2069
|
+
} else return genStaticSlots({
|
|
1829
2070
|
slotType: 0,
|
|
1830
2071
|
slots: {}
|
|
1831
2072
|
}, context, slots);
|
|
1832
2073
|
}
|
|
2074
|
+
function getSingleDefaultSlot({ slots }) {
|
|
2075
|
+
const names = Object.keys(slots);
|
|
2076
|
+
return names.length === 1 && names[0] === "default" ? slots.default : void 0;
|
|
2077
|
+
}
|
|
1833
2078
|
function genStaticSlots({ slots }, context, dynamicSlots) {
|
|
1834
2079
|
const args = Object.keys(slots).map((name) => [`${JSON.stringify(name)}: `, ...genSlotBlockWithProps(slots[name], context)]);
|
|
1835
2080
|
if (dynamicSlots) args.push([`$: `, ...genDynamicSlots(dynamicSlots, context)]);
|
|
@@ -1851,11 +2096,23 @@ function genDynamicSlot(slot, context, withFunction = false) {
|
|
|
1851
2096
|
frag = genConditionalSlot(slot, context);
|
|
1852
2097
|
break;
|
|
1853
2098
|
}
|
|
1854
|
-
|
|
2099
|
+
if (!withFunction) return frag;
|
|
2100
|
+
return needsDynamicSlotSourceCtx(slot) ? [
|
|
2101
|
+
`${context.helper("withVaporCtx")}(() => (`,
|
|
2102
|
+
...frag,
|
|
2103
|
+
"))"
|
|
2104
|
+
] : [
|
|
1855
2105
|
"() => (",
|
|
1856
2106
|
...frag,
|
|
1857
2107
|
")"
|
|
1858
|
-
]
|
|
2108
|
+
];
|
|
2109
|
+
}
|
|
2110
|
+
function needsDynamicSlotSourceCtx(slot) {
|
|
2111
|
+
switch (slot.slotType) {
|
|
2112
|
+
case 1: return needsVaporCtx(slot.fn);
|
|
2113
|
+
case 2: return needsVaporCtx(slot.fn);
|
|
2114
|
+
case 3: return needsDynamicSlotSourceCtx(slot.positive) || (slot.negative ? needsDynamicSlotSourceCtx(slot.negative) : false);
|
|
2115
|
+
}
|
|
1859
2116
|
}
|
|
1860
2117
|
function genBasicDynamicSlot(slot, context) {
|
|
1861
2118
|
const { name, fn } = slot;
|
|
@@ -1909,7 +2166,9 @@ function genSlotBlockWithProps(oper, context) {
|
|
|
1909
2166
|
} else propsName = props.content;
|
|
1910
2167
|
const idMap = idToPathMap.size ? buildDestructureIdMap(idToPathMap, propsName || "", context.options.expressionPlugins) : {};
|
|
1911
2168
|
if (propsName) idMap[propsName] = null;
|
|
2169
|
+
const exitSlotBlock = context.enterSlotBlock();
|
|
1912
2170
|
let blockFn = context.withId(() => genBlock(oper, context, propsName ? [propsName] : []), idMap);
|
|
2171
|
+
exitSlotBlock();
|
|
1913
2172
|
exitScope && exitScope();
|
|
1914
2173
|
if (node.type === 1) {
|
|
1915
2174
|
if (needsVaporCtx(oper)) blockFn = [
|
|
@@ -1970,16 +2229,18 @@ function hasComponentOrSlotInIf(node) {
|
|
|
1970
2229
|
//#region packages/compiler-vapor/src/generators/slotOutlet.ts
|
|
1971
2230
|
function genSlotOutlet(oper, context) {
|
|
1972
2231
|
const { helper } = context;
|
|
1973
|
-
const { id, name, fallback,
|
|
2232
|
+
const { id, name, fallback, flags } = oper;
|
|
1974
2233
|
const [frag, push] = buildCodeFragment();
|
|
1975
|
-
|
|
2234
|
+
let fallbackArg;
|
|
2235
|
+
if (fallback) fallbackArg = genBlock(fallback, context);
|
|
2236
|
+
const createSlot = helper("createSlot");
|
|
2237
|
+
const rawPropsArg = genRawProps(oper.props, context, true);
|
|
2238
|
+
const nameArg = name.isStatic && name.content === "default" && !rawPropsArg && !fallbackArg && !flags ? void 0 : name.isStatic ? genExpression(name, context) : [
|
|
1976
2239
|
"() => (",
|
|
1977
2240
|
...genExpression(name, context),
|
|
1978
2241
|
")"
|
|
1979
2242
|
];
|
|
1980
|
-
|
|
1981
|
-
if (fallback) fallbackArg = genBlock(fallback, context);
|
|
1982
|
-
push(NEWLINE, `const n${id} = `, ...genCall(helper("createSlot"), nameExpr, genRawProps(oper.props, context) || "null", fallbackArg, noSlotted && "true", once && "true"));
|
|
2243
|
+
push(NEWLINE, `const n${id} = `, ...genCall(createSlot, nameArg, rawPropsArg, fallbackArg, flags ? String(flags) : void 0));
|
|
1983
2244
|
return frag;
|
|
1984
2245
|
}
|
|
1985
2246
|
//#endregion
|
|
@@ -2039,28 +2300,35 @@ function genEffects(effects, context, genExtraFrag) {
|
|
|
2039
2300
|
const [frag, push, unshift] = buildCodeFragment();
|
|
2040
2301
|
const shouldDeclare = genExtraFrag === void 0;
|
|
2041
2302
|
let operationsCount = 0;
|
|
2042
|
-
const { ids, frag: declarationFrags, varNames } = processExpressions(context, expressions, shouldDeclare);
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
const
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2303
|
+
const { ids, frag: declarationFrags, varNames, expressionReplacements } = processExpressions(context, expressions, shouldDeclare);
|
|
2304
|
+
if (shouldDeclare && !declarationFrags.length && !varNames.length) {
|
|
2305
|
+
const effect = effects.length === 1 ? effects[0] : void 0;
|
|
2306
|
+
const operation = effect && effect.operations.length === 1 ? effect.operations[0] : void 0;
|
|
2307
|
+
if (operation && operation.type === 9 && operation.effect && !operation.refFor) return context.withExpressionReplacements(expressionReplacements, () => context.withId(() => genSetTemplateRefBinding(operation, context), ids));
|
|
2308
|
+
}
|
|
2309
|
+
return context.withExpressionReplacements(expressionReplacements, () => {
|
|
2310
|
+
push(...declarationFrags);
|
|
2311
|
+
for (let i = 0; i < effects.length; i++) {
|
|
2312
|
+
const effect = effects[i];
|
|
2313
|
+
operationsCount += effect.operations.length;
|
|
2314
|
+
const frags = context.withId(() => genEffect(effect, context), ids);
|
|
2315
|
+
i > 0 && push(NEWLINE);
|
|
2316
|
+
if (frag[frag.length - 1] === ")" && frags[0] === "(") push(";");
|
|
2317
|
+
push(...frags);
|
|
2318
|
+
}
|
|
2319
|
+
if (frag.filter((frag) => frag === NEWLINE).length > 1 || operationsCount > 1 || declarationFrags.length > 0) {
|
|
2320
|
+
unshift(`{`, INDENT_START, NEWLINE);
|
|
2321
|
+
push(INDENT_END, NEWLINE, "}");
|
|
2322
|
+
if (!effects.length) unshift(NEWLINE);
|
|
2323
|
+
}
|
|
2324
|
+
if (effects.length) {
|
|
2325
|
+
unshift(NEWLINE, `${helper("renderEffect")}(() => `);
|
|
2326
|
+
push(`)`);
|
|
2327
|
+
}
|
|
2328
|
+
if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
|
|
2329
|
+
if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
|
|
2330
|
+
return frag;
|
|
2331
|
+
});
|
|
2064
2332
|
}
|
|
2065
2333
|
function genEffect({ operations }, context) {
|
|
2066
2334
|
const [frag, push] = buildCodeFragment();
|
|
@@ -2079,9 +2347,8 @@ function genTemplates(templates, context) {
|
|
|
2079
2347
|
const result = [];
|
|
2080
2348
|
templates.forEach(({ content, ns, root, static: isStatic }, i) => {
|
|
2081
2349
|
let args = JSON.stringify(content).replace(IMPORT_EXPR_RE, `" + $1 + "`);
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
if (isStatic || ns) args += `, ${isStatic ? "true" : "false"}`;
|
|
2350
|
+
const flags = (root ? 1 : 0) | (isStatic ? 2 : 0);
|
|
2351
|
+
if (flags || ns) args += `, ${flags}`;
|
|
2085
2352
|
if (ns) args += `, ${ns}`;
|
|
2086
2353
|
result.push(`const ${context.tName(i)} = ${context.helper("template")}(${args})\n`);
|
|
2087
2354
|
});
|
|
@@ -2099,10 +2366,13 @@ function genSelf(dynamic, context, flushBeforeDynamic) {
|
|
|
2099
2366
|
return frag;
|
|
2100
2367
|
}
|
|
2101
2368
|
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flushBeforeDynamic) {
|
|
2102
|
-
const { helper } = context;
|
|
2103
2369
|
const [frag, push] = buildCodeFragment();
|
|
2104
2370
|
const { children } = dynamic;
|
|
2105
2371
|
let offset = 0;
|
|
2372
|
+
/**
|
|
2373
|
+
* `reusable` means the previous access target is a p* cursor that can be
|
|
2374
|
+
* reassigned by the next lookup. Referenced n* variables must stay stable.
|
|
2375
|
+
*/
|
|
2106
2376
|
let prev;
|
|
2107
2377
|
for (const [index, child] of children.entries()) {
|
|
2108
2378
|
if (child.flags & 2) offset--;
|
|
@@ -2119,27 +2389,118 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flush
|
|
|
2119
2389
|
}
|
|
2120
2390
|
const elementIndex = index + offset;
|
|
2121
2391
|
const logicalIndex = child.logicalIndex !== void 0 ? String(child.logicalIndex) : void 0;
|
|
2122
|
-
const
|
|
2123
|
-
|
|
2124
|
-
if (
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2392
|
+
const inlinePlaceholder = id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6);
|
|
2393
|
+
const accessPath = genAccessPath(context, from, child, elementIndex, logicalIndex, prev);
|
|
2394
|
+
if (inlinePlaceholder) {
|
|
2395
|
+
if (prev && prev[2]) {
|
|
2396
|
+
push(...genChildren(child, context, pushBlock, [
|
|
2397
|
+
"(",
|
|
2398
|
+
prev[0],
|
|
2399
|
+
" = ",
|
|
2400
|
+
...accessPath,
|
|
2401
|
+
")"
|
|
2402
|
+
], flushBeforeDynamic));
|
|
2403
|
+
prev = [
|
|
2404
|
+
prev[0],
|
|
2405
|
+
elementIndex,
|
|
2406
|
+
true
|
|
2407
|
+
];
|
|
2408
|
+
continue;
|
|
2409
|
+
}
|
|
2410
|
+
if (!hasAdjacentFollowingAccessChild(children, index, elementIndex, offset)) {
|
|
2411
|
+
push(...genChildren(child, context, pushBlock, accessPath, flushBeforeDynamic));
|
|
2412
|
+
continue;
|
|
2413
|
+
}
|
|
2414
|
+
}
|
|
2415
|
+
let variable;
|
|
2416
|
+
if (id === void 0 && prev && prev[2]) {
|
|
2417
|
+
variable = prev[0];
|
|
2418
|
+
pushBlock(NEWLINE, `${variable} = `, ...accessPath);
|
|
2419
|
+
} else {
|
|
2420
|
+
variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
|
|
2421
|
+
pushBlock(NEWLINE, id === void 0 ? `let ${variable} = ` : `const ${variable} = `, ...accessPath);
|
|
2132
2422
|
}
|
|
2133
2423
|
if (id === child.anchor && !child.hasDynamicChild) {
|
|
2134
2424
|
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
2135
2425
|
push(...genSelf(child, context, flushBeforeDynamic));
|
|
2136
2426
|
}
|
|
2137
2427
|
if (id !== void 0) push(...genDirectivesForElement(id, context));
|
|
2138
|
-
prev = [
|
|
2428
|
+
prev = [
|
|
2429
|
+
variable,
|
|
2430
|
+
elementIndex,
|
|
2431
|
+
id === void 0
|
|
2432
|
+
];
|
|
2139
2433
|
push(...genChildren(child, context, pushBlock, variable, flushBeforeDynamic));
|
|
2140
2434
|
}
|
|
2141
2435
|
return frag;
|
|
2142
2436
|
}
|
|
2437
|
+
/**
|
|
2438
|
+
* Build one DOM lookup path while preserving the fast sibling walk:
|
|
2439
|
+
* adjacent nodes use _next(prev), otherwise fall back to _nthChild(parent).
|
|
2440
|
+
*/
|
|
2441
|
+
function genAccessPath({ helper }, from, child, elementIndex, logicalIndex, prev) {
|
|
2442
|
+
if (prev) return elementIndex - prev[1] === 1 ? genCall(helper("next"), prev[0], logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
2443
|
+
if (elementIndex === 0) return genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0);
|
|
2444
|
+
const firstChild = genCall(helper("child"), from);
|
|
2445
|
+
return elementIndex === 1 ? genCall(helper("next"), firstChild, logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
2446
|
+
}
|
|
2447
|
+
/**
|
|
2448
|
+
* Only inline a placeholder when materializing it would not save a parent
|
|
2449
|
+
* lookup. If its child tree needs the parent more than once, keep p* so the
|
|
2450
|
+
* generated code does not duplicate _child/_nthChild work.
|
|
2451
|
+
*/
|
|
2452
|
+
function canInlinePlaceholder(dynamic) {
|
|
2453
|
+
return dynamic.hasDynamicChild === true && countParentAccessUsages(dynamic) === 1;
|
|
2454
|
+
}
|
|
2455
|
+
/**
|
|
2456
|
+
* A following access can reuse the current placeholder cursor only when it is
|
|
2457
|
+
* the next DOM sibling. Gapped siblings need _nthChild(parent, index) instead.
|
|
2458
|
+
*/
|
|
2459
|
+
function hasAdjacentFollowingAccessChild(children, index, elementIndex, offset) {
|
|
2460
|
+
let futureOffset = offset;
|
|
2461
|
+
for (let i = index + 1; i < children.length; i++) {
|
|
2462
|
+
const child = children[i];
|
|
2463
|
+
if (child.flags & 2) futureOffset--;
|
|
2464
|
+
if (!(child.flags & 4 && child.template != null) && (!!(child.flags & 1) || child.hasDynamicChild)) return i + futureOffset - elementIndex === 1;
|
|
2465
|
+
}
|
|
2466
|
+
return false;
|
|
2467
|
+
}
|
|
2468
|
+
/**
|
|
2469
|
+
* Mirrors genChildren's traversal closely enough to count how many emitted
|
|
2470
|
+
* access paths would start from this placeholder's parent. This is the guard
|
|
2471
|
+
* that keeps inline placeholders from duplicating parent lookups.
|
|
2472
|
+
*/
|
|
2473
|
+
function countParentAccessUsages(dynamic) {
|
|
2474
|
+
let usages = 0;
|
|
2475
|
+
let offset = 0;
|
|
2476
|
+
let prev;
|
|
2477
|
+
for (const [index, child] of dynamic.children.entries()) {
|
|
2478
|
+
if (child.flags & 2) offset--;
|
|
2479
|
+
if (child.flags & 4 && child.template != null) continue;
|
|
2480
|
+
const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
|
|
2481
|
+
if (id === void 0 && !child.hasDynamicChild) continue;
|
|
2482
|
+
const elementIndex = index + offset;
|
|
2483
|
+
const usesParent = !prev || elementIndex - prev[0] !== 1;
|
|
2484
|
+
if (id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6)) {
|
|
2485
|
+
if (prev && prev[1]) {
|
|
2486
|
+
if (usesParent) usages++;
|
|
2487
|
+
prev = [elementIndex, true];
|
|
2488
|
+
continue;
|
|
2489
|
+
}
|
|
2490
|
+
if (!hasAdjacentFollowingAccessChild(dynamic.children, index, elementIndex, offset)) {
|
|
2491
|
+
if (usesParent) usages++;
|
|
2492
|
+
continue;
|
|
2493
|
+
}
|
|
2494
|
+
}
|
|
2495
|
+
if (usesParent) usages++;
|
|
2496
|
+
prev = [elementIndex, id === void 0];
|
|
2497
|
+
}
|
|
2498
|
+
return usages;
|
|
2499
|
+
}
|
|
2500
|
+
function genNthChild(nthChild, from, elementIndex, logicalIndex) {
|
|
2501
|
+
const index = String(elementIndex);
|
|
2502
|
+
return genCall(nthChild, from, index, logicalIndex === index ? void 0 : logicalIndex);
|
|
2503
|
+
}
|
|
2143
2504
|
//#endregion
|
|
2144
2505
|
//#region packages/compiler-vapor/src/generators/block.ts
|
|
2145
2506
|
function genBlock(oper, context, args = [], root) {
|
|
@@ -2158,8 +2519,12 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
2158
2519
|
const [frag, push] = buildCodeFragment();
|
|
2159
2520
|
const { dynamic, effect, operation, returns } = block;
|
|
2160
2521
|
const resetBlock = context.enterBlock(block);
|
|
2522
|
+
const singleUseAssetComponentNames = root ? collectSingleUseAssetComponents(block) : void 0;
|
|
2523
|
+
const prevSingleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
2524
|
+
if (singleUseAssetComponentNames) context.singleUseAssetComponentNames = singleUseAssetComponentNames;
|
|
2161
2525
|
if (root) {
|
|
2162
2526
|
for (let name of context.ir.component) {
|
|
2527
|
+
if (singleUseAssetComponentNames && singleUseAssetComponentNames.has(name)) continue;
|
|
2163
2528
|
const id = (0, _vue_compiler_dom.toValidAssetId)(name, "component");
|
|
2164
2529
|
const maybeSelfReference = name.endsWith("__self");
|
|
2165
2530
|
if (maybeSelfReference) name = name.slice(0, -6);
|
|
@@ -2195,15 +2560,101 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
2195
2560
|
const returnNodes = returns.map((n) => `n${n}`);
|
|
2196
2561
|
push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"]);
|
|
2197
2562
|
resetBlock();
|
|
2563
|
+
context.singleUseAssetComponentNames = prevSingleUseAssetComponentNames;
|
|
2198
2564
|
return frag;
|
|
2199
2565
|
function genResolveAssets(kind, helper) {
|
|
2200
2566
|
for (const name of context.ir[kind]) push(NEWLINE, `const ${(0, _vue_compiler_dom.toValidAssetId)(name, kind)} = `, ...genCall(context.helper(helper), JSON.stringify(name)));
|
|
2201
2567
|
}
|
|
2202
2568
|
}
|
|
2569
|
+
function collectSingleUseAssetComponents(block) {
|
|
2570
|
+
const usageMap = /* @__PURE__ */ new Map();
|
|
2571
|
+
const seenOperations = /* @__PURE__ */ new Set();
|
|
2572
|
+
visitBlock(block, true);
|
|
2573
|
+
const names = /* @__PURE__ */ new Set();
|
|
2574
|
+
for (const [name, usage] of usageMap) if (usage.count === 1 && usage.root) names.add(name);
|
|
2575
|
+
return names;
|
|
2576
|
+
function visitBlock(block, rootCandidate) {
|
|
2577
|
+
visitDynamic(block.dynamic, rootCandidate);
|
|
2578
|
+
for (const operation of block.operation) visitOperation(operation, rootCandidate);
|
|
2579
|
+
for (const effect of block.effect) for (const operation of effect.operations) visitOperation(operation, false);
|
|
2580
|
+
}
|
|
2581
|
+
function visitDynamic(dynamic, rootCandidate) {
|
|
2582
|
+
if (dynamic.operation) visitOperation(dynamic.operation, rootCandidate);
|
|
2583
|
+
for (const child of dynamic.children) visitDynamic(child, rootCandidate);
|
|
2584
|
+
}
|
|
2585
|
+
function visitOperation(operation, rootCandidate) {
|
|
2586
|
+
if (seenOperations.has(operation)) return;
|
|
2587
|
+
seenOperations.add(operation);
|
|
2588
|
+
if (operation.type === 12) {
|
|
2589
|
+
if (operation.asset) {
|
|
2590
|
+
const usage = usageMap.get(operation.tag) || {
|
|
2591
|
+
count: 0,
|
|
2592
|
+
root: false
|
|
2593
|
+
};
|
|
2594
|
+
usage.count++;
|
|
2595
|
+
if (rootCandidate) usage.root = true;
|
|
2596
|
+
usageMap.set(operation.tag, usage);
|
|
2597
|
+
}
|
|
2598
|
+
visitSlots(operation.slots);
|
|
2599
|
+
return;
|
|
2600
|
+
}
|
|
2601
|
+
switch (operation.type) {
|
|
2602
|
+
case 15:
|
|
2603
|
+
visitBlock(operation.positive, false);
|
|
2604
|
+
if (operation.negative) if (operation.negative.type === 15) visitOperation(operation.negative, false);
|
|
2605
|
+
else visitBlock(operation.negative, false);
|
|
2606
|
+
break;
|
|
2607
|
+
case 16:
|
|
2608
|
+
visitBlock(operation.render, false);
|
|
2609
|
+
break;
|
|
2610
|
+
case 17:
|
|
2611
|
+
visitBlock(operation.block, false);
|
|
2612
|
+
break;
|
|
2613
|
+
case 13:
|
|
2614
|
+
if (operation.fallback) visitBlock(operation.fallback, false);
|
|
2615
|
+
break;
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
function visitSlots(slots) {
|
|
2619
|
+
for (const slot of slots) switch (slot.slotType) {
|
|
2620
|
+
case 0:
|
|
2621
|
+
for (const name in slot.slots) visitBlock(slot.slots[name], false);
|
|
2622
|
+
break;
|
|
2623
|
+
case 1:
|
|
2624
|
+
case 2:
|
|
2625
|
+
visitBlock(slot.fn, false);
|
|
2626
|
+
break;
|
|
2627
|
+
case 3:
|
|
2628
|
+
visitSlots([slot.positive]);
|
|
2629
|
+
if (slot.negative) visitSlots([slot.negative]);
|
|
2630
|
+
break;
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2203
2634
|
//#endregion
|
|
2204
2635
|
//#region packages/compiler-vapor/src/generate.ts
|
|
2205
2636
|
const idWithTrailingDigitsRE = /^([A-Za-z_$][\w$]*)(\d+)$/;
|
|
2637
|
+
const helperNameAliases = {
|
|
2638
|
+
withVaporKeys: "withKeys",
|
|
2639
|
+
withVaporModifiers: "withModifiers"
|
|
2640
|
+
};
|
|
2206
2641
|
var CodegenContext = class {
|
|
2642
|
+
withExpressionReplacements(map, fn) {
|
|
2643
|
+
if (map.size === 0) return fn();
|
|
2644
|
+
this.expressionReplacements.unshift(map);
|
|
2645
|
+
try {
|
|
2646
|
+
return fn();
|
|
2647
|
+
} finally {
|
|
2648
|
+
(0, _vue_shared.remove)(this.expressionReplacements, map);
|
|
2649
|
+
}
|
|
2650
|
+
}
|
|
2651
|
+
getExpressionReplacement(node) {
|
|
2652
|
+
for (const map of this.expressionReplacements) {
|
|
2653
|
+
const replacement = map.get(node);
|
|
2654
|
+
if (replacement) return replacement;
|
|
2655
|
+
}
|
|
2656
|
+
return node;
|
|
2657
|
+
}
|
|
2207
2658
|
withId(fn, map) {
|
|
2208
2659
|
const { identifiers } = this;
|
|
2209
2660
|
const ids = Object.keys(map);
|
|
@@ -2220,9 +2671,19 @@ var CodegenContext = class {
|
|
|
2220
2671
|
this.block = block;
|
|
2221
2672
|
return () => this.block = parent;
|
|
2222
2673
|
}
|
|
2674
|
+
enterSlotBlock() {
|
|
2675
|
+
const parent = this.inSlotBlock;
|
|
2676
|
+
this.inSlotBlock = true;
|
|
2677
|
+
return () => this.inSlotBlock = parent;
|
|
2678
|
+
}
|
|
2223
2679
|
enterScope() {
|
|
2224
2680
|
return [this.scopeLevel++, () => this.scopeLevel--];
|
|
2225
2681
|
}
|
|
2682
|
+
isHelperNameAvailable(name) {
|
|
2683
|
+
if (this.bindingNames.has(name)) return false;
|
|
2684
|
+
for (const alias of this.helpers.values()) if (alias === name) return false;
|
|
2685
|
+
return true;
|
|
2686
|
+
}
|
|
2226
2687
|
initNextIdMap() {
|
|
2227
2688
|
if (this.bindingNames.size === 0) return;
|
|
2228
2689
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -2257,19 +2718,29 @@ var CodegenContext = class {
|
|
|
2257
2718
|
this.ir = ir;
|
|
2258
2719
|
this.bindingNames = /* @__PURE__ */ new Set();
|
|
2259
2720
|
this.helpers = /* @__PURE__ */ new Map();
|
|
2721
|
+
this.needsTemplateRefSetter = false;
|
|
2722
|
+
this.inSlotBlock = false;
|
|
2260
2723
|
this.helper = (name) => {
|
|
2261
2724
|
if (this.helpers.has(name)) return this.helpers.get(name);
|
|
2262
|
-
const base = `_${name}`;
|
|
2263
|
-
if (this.
|
|
2725
|
+
const base = `_${helperNameAliases[name] || name}`;
|
|
2726
|
+
if (this.isHelperNameAvailable(base)) {
|
|
2264
2727
|
this.helpers.set(name, base);
|
|
2265
2728
|
return base;
|
|
2266
2729
|
}
|
|
2267
|
-
const
|
|
2268
|
-
|
|
2269
|
-
|
|
2730
|
+
const map = this.nextIdMap.get(base);
|
|
2731
|
+
let next = 1;
|
|
2732
|
+
while (true) {
|
|
2733
|
+
const alias = `${base}${getNextId(map, next)}`;
|
|
2734
|
+
if (this.isHelperNameAvailable(alias)) {
|
|
2735
|
+
this.helpers.set(name, alias);
|
|
2736
|
+
return alias;
|
|
2737
|
+
}
|
|
2738
|
+
next++;
|
|
2739
|
+
}
|
|
2270
2740
|
};
|
|
2271
2741
|
this.delegates = /* @__PURE__ */ new Set();
|
|
2272
2742
|
this.identifiers = Object.create(null);
|
|
2743
|
+
this.expressionReplacements = [];
|
|
2273
2744
|
this.seenInlineHandlerNames = Object.create(null);
|
|
2274
2745
|
this.scopeLevel = 0;
|
|
2275
2746
|
this.templateVars = /* @__PURE__ */ new Map();
|
|
@@ -2296,6 +2767,7 @@ var CodegenContext = class {
|
|
|
2296
2767
|
this.block = ir.block;
|
|
2297
2768
|
this.bindingNames = new Set(this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []);
|
|
2298
2769
|
this.initNextIdMap();
|
|
2770
|
+
this.staticTemplateRefHelperCandidate = getStaticTemplateRefHelperCandidate(ir.block);
|
|
2299
2771
|
}
|
|
2300
2772
|
};
|
|
2301
2773
|
function generate(ir, options = {}) {
|
|
@@ -2308,8 +2780,11 @@ function generate(ir, options = {}) {
|
|
|
2308
2780
|
const signature = (options.isTS ? args.map((arg) => `${arg}: any`) : args).join(", ");
|
|
2309
2781
|
if (!inline) push(NEWLINE, `export function ${functionName}(${signature}) {`);
|
|
2310
2782
|
push(INDENT_START);
|
|
2311
|
-
|
|
2312
|
-
|
|
2783
|
+
const templateRefSetterHelper = ir.hasTemplateRef ? context.helper("createTemplateRefSetter") : void 0;
|
|
2784
|
+
const body = genBlockContent(ir.block, context, true);
|
|
2785
|
+
if (context.needsTemplateRefSetter) push(NEWLINE, `const ${setTemplateRefIdent} = ${templateRefSetterHelper}()`);
|
|
2786
|
+
else if (templateRefSetterHelper) context.helpers.delete("createTemplateRefSetter");
|
|
2787
|
+
push(...body);
|
|
2313
2788
|
push(INDENT_END, NEWLINE);
|
|
2314
2789
|
if (!inline) push("}");
|
|
2315
2790
|
const delegates = genDelegates(context);
|
|
@@ -2344,6 +2819,11 @@ function genAssetImports({ ir }) {
|
|
|
2344
2819
|
}
|
|
2345
2820
|
return imports;
|
|
2346
2821
|
}
|
|
2822
|
+
function getStaticTemplateRefHelperCandidate(block) {
|
|
2823
|
+
if (block.operation.length !== 1) return;
|
|
2824
|
+
const operation = block.operation[0];
|
|
2825
|
+
if (operation.type === 9 && !operation.effect && !operation.refFor && operation.value.isStatic) return operation;
|
|
2826
|
+
}
|
|
2347
2827
|
//#endregion
|
|
2348
2828
|
//#region packages/compiler-vapor/src/transforms/vBind.ts
|
|
2349
2829
|
function normalizeBindShorthand(arg, context) {
|
|
@@ -2409,11 +2889,35 @@ function canOmitEndTag(node, context) {
|
|
|
2409
2889
|
const { block, parent } = context;
|
|
2410
2890
|
if (!parent) return false;
|
|
2411
2891
|
if (block !== parent.block) return true;
|
|
2892
|
+
if (context.templateCloseTags && (context.templateCloseTags.has(node.tag) || (0, _vue_shared.isAlwaysCloseTag)(node.tag) || (0, _vue_shared.isFormattingTag)(node.tag)) || context.templateCloseBlocks && (0, _vue_shared.isBlockTag)(node.tag)) return false;
|
|
2412
2893
|
if ((0, _vue_shared.isAlwaysCloseTag)(node.tag) && !context.isOnRightmostPath) return false;
|
|
2413
2894
|
if ((0, _vue_shared.isFormattingTag)(node.tag) || parent.node.type === 1 && node.tag === parent.node.tag) return context.isOnRightmostPath;
|
|
2414
|
-
if ((0, _vue_shared.isBlockTag)(node.tag) && context.hasInlineAncestorNeedingClose) return false;
|
|
2415
2895
|
return context.isLastEffectiveChild;
|
|
2416
2896
|
}
|
|
2897
|
+
function getChildTemplateCloseState(context) {
|
|
2898
|
+
const { node } = context;
|
|
2899
|
+
if (node.type !== 1 || node.tagType !== 0 || shouldUseCreateElement(node, context)) return;
|
|
2900
|
+
const inSameTemplateAsParent = isInSameTemplateAsParent(context);
|
|
2901
|
+
const inheritedTags = inSameTemplateAsParent ? context.templateCloseTags : void 0;
|
|
2902
|
+
const inheritedBlocks = inSameTemplateAsParent && context.templateCloseBlocks;
|
|
2903
|
+
if (context.root === context.effectiveParent || canOmitEndTag(node, context) || (0, _vue_shared.isVoidTag)(node.tag)) return inheritedTags || inheritedBlocks ? {
|
|
2904
|
+
tags: inheritedTags,
|
|
2905
|
+
blocks: inheritedBlocks
|
|
2906
|
+
} : void 0;
|
|
2907
|
+
const tags = new Set(inheritedTags);
|
|
2908
|
+
tags.add(node.tag);
|
|
2909
|
+
return {
|
|
2910
|
+
tags,
|
|
2911
|
+
blocks: inheritedBlocks || (0, _vue_shared.isInlineTag)(node.tag)
|
|
2912
|
+
};
|
|
2913
|
+
}
|
|
2914
|
+
function isInSameTemplateAsParent(context) {
|
|
2915
|
+
const { parent, node, block } = context;
|
|
2916
|
+
if (!parent || block !== parent.block) return false;
|
|
2917
|
+
const parentNode = parent.node;
|
|
2918
|
+
if (parentNode.type !== 1 || parentNode.tagType !== 0) return false;
|
|
2919
|
+
return !shouldUseCreateElement(parentNode, parent) && (0, _vue_compiler_dom.isValidHTMLNesting)(parentNode.tag, node.tag);
|
|
2920
|
+
}
|
|
2417
2921
|
function isSingleRoot(context) {
|
|
2418
2922
|
if (context.inVFor) return false;
|
|
2419
2923
|
let { parent } = context;
|
|
@@ -2485,6 +2989,7 @@ function resolveSetupReference(name, context) {
|
|
|
2485
2989
|
}
|
|
2486
2990
|
const dynamicKeys = ["indeterminate"];
|
|
2487
2991
|
const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
|
|
2992
|
+
const UNSAFE_ATTR_NAME_RE = /[\u0000-\u0020"'<=/>]/;
|
|
2488
2993
|
function transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, omitEndTag) {
|
|
2489
2994
|
const { tag } = node;
|
|
2490
2995
|
const { scopeId } = context.options;
|
|
@@ -2502,18 +3007,55 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
2502
3007
|
}, getEffectIndex);
|
|
2503
3008
|
} else {
|
|
2504
3009
|
let prevWasQuoted = false;
|
|
3010
|
+
const appendTemplateProp = (key, value = "", generated = false) => {
|
|
3011
|
+
if (!prevWasQuoted) template += ` `;
|
|
3012
|
+
template += key;
|
|
3013
|
+
if (value) {
|
|
3014
|
+
const escapedValue = generated ? escapeGeneratedAttrValue(value) : value.replace(/"/g, """);
|
|
3015
|
+
template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${escapedValue}"` : `=${escapedValue}`;
|
|
3016
|
+
} else prevWasQuoted = false;
|
|
3017
|
+
};
|
|
2505
3018
|
for (const prop of propsResult[1]) {
|
|
2506
3019
|
const { key, values } = prop;
|
|
2507
3020
|
if (context.imports.some((imported) => values[0].content.includes(imported.exp.content))) {
|
|
2508
3021
|
if (!prevWasQuoted) template += ` `;
|
|
2509
3022
|
template += `${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
|
|
2510
3023
|
prevWasQuoted = true;
|
|
3024
|
+
} else if (key.isStatic && !prop.modifier && (0, _vue_shared.isBooleanAttr)(key.content)) if (values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
3025
|
+
const value = values[0].content === "''" ? "" : values[0].content;
|
|
3026
|
+
appendTemplateProp(key.content, value);
|
|
3027
|
+
} else {
|
|
3028
|
+
const include = foldBooleanAttrValue(values);
|
|
3029
|
+
if (include != null) {
|
|
3030
|
+
if (include) appendTemplateProp(key.content);
|
|
3031
|
+
} else {
|
|
3032
|
+
dynamicProps.push(key.content);
|
|
3033
|
+
context.registerEffect(values, {
|
|
3034
|
+
type: 3,
|
|
3035
|
+
element: context.reference(),
|
|
3036
|
+
prop,
|
|
3037
|
+
tag
|
|
3038
|
+
}, getEffectIndex);
|
|
3039
|
+
}
|
|
3040
|
+
}
|
|
3041
|
+
else if (key.isStatic && !prop.modifier && hasBoundValue(values)) {
|
|
3042
|
+
let foldedValue;
|
|
3043
|
+
if (key.content === "class") foldedValue = foldClassValues(values);
|
|
3044
|
+
else if (key.content === "style") foldedValue = foldStyleValues(values);
|
|
3045
|
+
if (foldedValue != null) {
|
|
3046
|
+
if (foldedValue) appendTemplateProp(key.content, foldedValue, true);
|
|
3047
|
+
} else {
|
|
3048
|
+
dynamicProps.push(key.content);
|
|
3049
|
+
context.registerEffect(values, {
|
|
3050
|
+
type: 3,
|
|
3051
|
+
element: context.reference(),
|
|
3052
|
+
prop,
|
|
3053
|
+
tag
|
|
3054
|
+
}, getEffectIndex);
|
|
3055
|
+
}
|
|
2511
3056
|
} else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
2512
|
-
if (!prevWasQuoted) template += ` `;
|
|
2513
3057
|
const value = values[0].content === "''" ? "" : values[0].content;
|
|
2514
|
-
|
|
2515
|
-
if (value) template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${value.replace(/"/g, """)}"` : `=${value}`;
|
|
2516
|
-
else prevWasQuoted = false;
|
|
3058
|
+
appendTemplateProp(key.content, value);
|
|
2517
3059
|
} else {
|
|
2518
3060
|
dynamicProps.push(key.content);
|
|
2519
3061
|
context.registerEffect(values, {
|
|
@@ -2535,6 +3077,123 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
2535
3077
|
} else context.template += template;
|
|
2536
3078
|
if (staticKey) context.registerOperation(createSetBlockKey(context.reference(), staticKey));
|
|
2537
3079
|
}
|
|
3080
|
+
function escapeGeneratedAttrValue(value) {
|
|
3081
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
3082
|
+
}
|
|
3083
|
+
function foldBooleanAttrValue(values) {
|
|
3084
|
+
if (values.length !== 1) return;
|
|
3085
|
+
const evaluated = evaluateConstantExpression(values[0]);
|
|
3086
|
+
if (!evaluated) return;
|
|
3087
|
+
const value = evaluated.value;
|
|
3088
|
+
if (value === true || value === false || value == null) return (0, _vue_shared.includeBooleanAttr)(value);
|
|
3089
|
+
}
|
|
3090
|
+
function foldStyleValues(values) {
|
|
3091
|
+
const evaluatedValues = [];
|
|
3092
|
+
for (const value of values) {
|
|
3093
|
+
const evaluated = evaluateConstantExpression(value);
|
|
3094
|
+
if (!evaluated || !isStaticStyleValue(evaluated.value)) return;
|
|
3095
|
+
evaluatedValues.push(evaluated.value);
|
|
3096
|
+
}
|
|
3097
|
+
return (0, _vue_shared.stringifyStyle)((0, _vue_shared.normalizeStyle)(evaluatedValues.length === 1 ? evaluatedValues[0] : evaluatedValues));
|
|
3098
|
+
}
|
|
3099
|
+
function isStaticStyleValue(value) {
|
|
3100
|
+
if (typeof value === "string") return true;
|
|
3101
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
3102
|
+
for (const key in value) {
|
|
3103
|
+
const propValue = value[key];
|
|
3104
|
+
if (!isSafeStylePropertyName(key) || !isSafeStylePropertyValue(propValue)) return false;
|
|
3105
|
+
}
|
|
3106
|
+
return true;
|
|
3107
|
+
}
|
|
3108
|
+
function isSafeStylePropertyName(key) {
|
|
3109
|
+
return !!key && !/[;:]/.test(key);
|
|
3110
|
+
}
|
|
3111
|
+
function isSafeStylePropertyValue(value) {
|
|
3112
|
+
return typeof value === "number" || typeof value === "string" && !value.includes(";");
|
|
3113
|
+
}
|
|
3114
|
+
function hasBoundValue(values) {
|
|
3115
|
+
return values.some((value) => !value.isStatic && value.content !== "''");
|
|
3116
|
+
}
|
|
3117
|
+
function foldClassValues(values) {
|
|
3118
|
+
let templateValue = "";
|
|
3119
|
+
let changed = false;
|
|
3120
|
+
for (const value of values) {
|
|
3121
|
+
const evaluated = evaluateConstantExpression(value);
|
|
3122
|
+
if (evaluated) {
|
|
3123
|
+
const normalized = (0, _vue_shared.normalizeClass)(evaluated.value);
|
|
3124
|
+
if (normalized) templateValue = appendClass(templateValue, normalized);
|
|
3125
|
+
else changed = true;
|
|
3126
|
+
continue;
|
|
3127
|
+
}
|
|
3128
|
+
return;
|
|
3129
|
+
}
|
|
3130
|
+
return changed || templateValue ? templateValue : void 0;
|
|
3131
|
+
}
|
|
3132
|
+
function appendClass(base, value) {
|
|
3133
|
+
return base ? value ? `${base} ${value}` : base : value;
|
|
3134
|
+
}
|
|
3135
|
+
function getObjectPropertyName(prop) {
|
|
3136
|
+
const key = prop.key;
|
|
3137
|
+
if (key.type === "Identifier") return key.name;
|
|
3138
|
+
else if (key.type === "StringLiteral") return key.value;
|
|
3139
|
+
else if (key.type === "NumericLiteral") return String(key.value);
|
|
3140
|
+
}
|
|
3141
|
+
function evaluateConstantExpression(node) {
|
|
3142
|
+
if (node.isStatic) return { value: node.content };
|
|
3143
|
+
const ast = node.ast;
|
|
3144
|
+
if (ast === null) {
|
|
3145
|
+
if (node.content === "true") return { value: true };
|
|
3146
|
+
else if (node.content === "false") return { value: false };
|
|
3147
|
+
else if (node.content === "null") return { value: null };
|
|
3148
|
+
else if (node.content === "undefined") return { value: void 0 };
|
|
3149
|
+
}
|
|
3150
|
+
if (!ast) return;
|
|
3151
|
+
return evaluateConstantAst(ast);
|
|
3152
|
+
}
|
|
3153
|
+
function evaluateConstantAst(node) {
|
|
3154
|
+
switch (node.type) {
|
|
3155
|
+
case "StringLiteral": return { value: node.value };
|
|
3156
|
+
case "NumericLiteral": return { value: node.value };
|
|
3157
|
+
case "BooleanLiteral": return { value: node.value };
|
|
3158
|
+
case "NullLiteral": return { value: null };
|
|
3159
|
+
case "Identifier": return node.name === "undefined" ? { value: void 0 } : void 0;
|
|
3160
|
+
case "UnaryExpression":
|
|
3161
|
+
if (node.operator === "void") return { value: void 0 };
|
|
3162
|
+
else if (node.operator === "-") {
|
|
3163
|
+
const value = evaluateConstantAst(node.argument);
|
|
3164
|
+
return value && typeof value.value === "number" ? { value: -value.value } : void 0;
|
|
3165
|
+
}
|
|
3166
|
+
return;
|
|
3167
|
+
case "TemplateLiteral": return evaluateTemplateLiteral(node);
|
|
3168
|
+
case "ObjectExpression": return evaluateObjectExpression(node);
|
|
3169
|
+
}
|
|
3170
|
+
}
|
|
3171
|
+
function evaluateTemplateLiteral(node) {
|
|
3172
|
+
if (node.type !== "TemplateLiteral") return;
|
|
3173
|
+
let value = "";
|
|
3174
|
+
for (const [index, quasi] of node.quasis.entries()) {
|
|
3175
|
+
value += quasi.value.cooked || "";
|
|
3176
|
+
const expression = node.expressions[index];
|
|
3177
|
+
if (expression) {
|
|
3178
|
+
const evaluated = evaluateConstantAst(expression);
|
|
3179
|
+
if (!evaluated) return;
|
|
3180
|
+
value += evaluated.value;
|
|
3181
|
+
}
|
|
3182
|
+
}
|
|
3183
|
+
return { value };
|
|
3184
|
+
}
|
|
3185
|
+
function evaluateObjectExpression(node) {
|
|
3186
|
+
const value = {};
|
|
3187
|
+
for (const prop of node.properties) {
|
|
3188
|
+
if (prop.type !== "ObjectProperty" || prop.computed) return;
|
|
3189
|
+
const key = getObjectPropertyName(prop);
|
|
3190
|
+
if (key == null) return;
|
|
3191
|
+
const evaluated = evaluateConstantAst(prop.value);
|
|
3192
|
+
if (!evaluated) return;
|
|
3193
|
+
value[key] = evaluated.value;
|
|
3194
|
+
}
|
|
3195
|
+
return { value };
|
|
3196
|
+
}
|
|
2538
3197
|
function resolveStaticKey(node, context, isComponent) {
|
|
2539
3198
|
const keyProp = findProp$1(node, "key", false, true);
|
|
2540
3199
|
if (!keyProp) return;
|
|
@@ -2561,27 +3220,42 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
2561
3220
|
results = [];
|
|
2562
3221
|
}
|
|
2563
3222
|
}
|
|
3223
|
+
function pushStaticObjectLiteralProps(props) {
|
|
3224
|
+
if (dynamicArgs.length) {
|
|
3225
|
+
pushMergeArg();
|
|
3226
|
+
dynamicArgs.push(props);
|
|
3227
|
+
} else results.push(...props.map(toDirectiveResult));
|
|
3228
|
+
}
|
|
2564
3229
|
for (const prop of props) {
|
|
2565
3230
|
if (prop.type === 7 && !prop.arg) {
|
|
2566
3231
|
if (prop.name === "bind") {
|
|
2567
3232
|
if (prop.exp) {
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
3233
|
+
const objectLiteralProps = isComponent ? resolveComponentObjectLiteralBindProps(prop.exp, context, props, prop) : resolveNativeObjectLiteralBindProps(prop.exp, context, props, prop);
|
|
3234
|
+
if (objectLiteralProps) if (isComponent) pushStaticObjectLiteralProps(objectLiteralProps);
|
|
3235
|
+
else results.push(...objectLiteralProps.map(toDirectiveResult));
|
|
3236
|
+
else {
|
|
3237
|
+
dynamicExpr.push(prop.exp);
|
|
3238
|
+
pushMergeArg();
|
|
3239
|
+
dynamicArgs.push({
|
|
3240
|
+
kind: 0,
|
|
3241
|
+
value: prop.exp
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
2574
3244
|
} else context.options.onError((0, _vue_compiler_dom.createCompilerError)(34, prop.loc));
|
|
2575
3245
|
continue;
|
|
2576
3246
|
} else if (prop.name === "on") {
|
|
2577
3247
|
if (prop.exp) if (isComponent) {
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
3248
|
+
const objectLiteralProps = resolveComponentObjectLiteralOnProps(prop.exp, context, props, prop);
|
|
3249
|
+
if (objectLiteralProps) pushStaticObjectLiteralProps(objectLiteralProps);
|
|
3250
|
+
else {
|
|
3251
|
+
dynamicExpr.push(prop.exp);
|
|
3252
|
+
pushMergeArg();
|
|
3253
|
+
dynamicArgs.push({
|
|
3254
|
+
kind: 0,
|
|
3255
|
+
value: prop.exp,
|
|
3256
|
+
handler: true
|
|
3257
|
+
});
|
|
3258
|
+
}
|
|
2585
3259
|
} else context.registerEffect([prop.exp], {
|
|
2586
3260
|
type: 7,
|
|
2587
3261
|
element: context.reference(),
|
|
@@ -2611,6 +3285,151 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
2611
3285
|
}
|
|
2612
3286
|
return [false, dedupeProperties(results)];
|
|
2613
3287
|
}
|
|
3288
|
+
function resolveObjectLiteralProps(exp, context, keyTransform, isValidKey) {
|
|
3289
|
+
const ast = exp.ast;
|
|
3290
|
+
if (!ast || ast.type !== "ObjectExpression") return;
|
|
3291
|
+
const props = [];
|
|
3292
|
+
const knownKeys = /* @__PURE__ */ new Set();
|
|
3293
|
+
for (const property of ast.properties) {
|
|
3294
|
+
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
3295
|
+
let key = getObjectPropertyName(property);
|
|
3296
|
+
if (key == null || key === "__proto__") return;
|
|
3297
|
+
if (isValidKey && !isValidKey(key)) return;
|
|
3298
|
+
if (keyTransform) key = keyTransform(key);
|
|
3299
|
+
if (knownKeys.has(key)) return;
|
|
3300
|
+
knownKeys.add(key);
|
|
3301
|
+
props.push({
|
|
3302
|
+
key: (0, _vue_compiler_dom.createSimpleExpression)(key, true),
|
|
3303
|
+
values: [resolveExpression(createObjectBindSubExpression(exp, property.value, context), true)]
|
|
3304
|
+
});
|
|
3305
|
+
}
|
|
3306
|
+
return props;
|
|
3307
|
+
}
|
|
3308
|
+
function resolveComponentObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
3309
|
+
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeObjectLiteralBindKey);
|
|
3310
|
+
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
3311
|
+
return props;
|
|
3312
|
+
}
|
|
3313
|
+
function resolveNativeObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
3314
|
+
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeNativeObjectLiteralBindKey);
|
|
3315
|
+
if (!props || hasNativeObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
3316
|
+
return props;
|
|
3317
|
+
}
|
|
3318
|
+
function resolveComponentObjectLiteralOnProps(exp, context, nodeProps, currentProp) {
|
|
3319
|
+
const props = resolveObjectLiteralProps(exp, context, _vue_shared.toHandlerKey);
|
|
3320
|
+
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
3321
|
+
return props;
|
|
3322
|
+
}
|
|
3323
|
+
function isSafeNativeObjectLiteralBindKey(key) {
|
|
3324
|
+
return key !== "" && !UNSAFE_ATTR_NAME_RE.test(key) && isSafeObjectLiteralBindKey(key) && !(0, _vue_shared.isOn)(key) && key.charCodeAt(0) !== 46 && key.charCodeAt(0) !== 94;
|
|
3325
|
+
}
|
|
3326
|
+
function isSafeObjectLiteralBindKey(key) {
|
|
3327
|
+
return !isReservedProp(key);
|
|
3328
|
+
}
|
|
3329
|
+
function hasComponentObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
3330
|
+
const keys = createComponentConflictKeySet(objectLiteralProps.map((prop) => prop.key.content));
|
|
3331
|
+
for (const prop of props) {
|
|
3332
|
+
if (prop === currentProp) continue;
|
|
3333
|
+
let key;
|
|
3334
|
+
if (prop.type === 6) key = prop.name;
|
|
3335
|
+
else if (prop.name === "bind") {
|
|
3336
|
+
if (!prop.arg) {
|
|
3337
|
+
const bindKeys = getObjectLiteralKeys(prop.exp);
|
|
3338
|
+
if (bindKeys && hasComponentKeyOverlap(keys, bindKeys)) return true;
|
|
3339
|
+
continue;
|
|
3340
|
+
}
|
|
3341
|
+
key = getStaticBindKey(prop);
|
|
3342
|
+
} else if (prop.name === "on") key = getStaticHandlerKey(prop);
|
|
3343
|
+
else if (prop.name === "model") {
|
|
3344
|
+
if (hasComponentModelKey(keys, prop)) return true;
|
|
3345
|
+
}
|
|
3346
|
+
if (key && hasComponentKey(keys, key)) return true;
|
|
3347
|
+
}
|
|
3348
|
+
return false;
|
|
3349
|
+
}
|
|
3350
|
+
function hasComponentModelKey(keys, prop) {
|
|
3351
|
+
const { arg } = prop;
|
|
3352
|
+
if (arg && (arg.type !== 4 || !arg.isStatic)) return true;
|
|
3353
|
+
const key = arg ? arg.content : "modelValue";
|
|
3354
|
+
return hasComponentKey(keys, key) || hasComponentKey(keys, `onUpdate:${(0, _vue_shared.camelize)(key)}`) || prop.modifiers.length > 0 && hasComponentKey(keys, (0, _vue_shared.getModifierPropName)(key));
|
|
3355
|
+
}
|
|
3356
|
+
function hasNativeObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
3357
|
+
const keys = new Set(objectLiteralProps.map((prop) => prop.key.content));
|
|
3358
|
+
for (const prop of props) {
|
|
3359
|
+
if (prop === currentProp) continue;
|
|
3360
|
+
let key;
|
|
3361
|
+
if (prop.type === 6) key = prop.name;
|
|
3362
|
+
else if (prop.name === "bind") {
|
|
3363
|
+
if (!prop.arg) return true;
|
|
3364
|
+
key = getStaticBindKey(prop);
|
|
3365
|
+
if (!key) return true;
|
|
3366
|
+
}
|
|
3367
|
+
if (key && keys.has(key)) return true;
|
|
3368
|
+
}
|
|
3369
|
+
return false;
|
|
3370
|
+
}
|
|
3371
|
+
function getStaticBindKey(prop) {
|
|
3372
|
+
const { arg } = prop;
|
|
3373
|
+
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
3374
|
+
let key = arg.content;
|
|
3375
|
+
if (isReservedProp(key)) return;
|
|
3376
|
+
if (prop.modifiers.some((modifier) => modifier.content === "camel")) key = (0, _vue_shared.camelize)(key);
|
|
3377
|
+
return key;
|
|
3378
|
+
}
|
|
3379
|
+
function getStaticHandlerKey(prop) {
|
|
3380
|
+
const { arg } = prop;
|
|
3381
|
+
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
3382
|
+
let key = arg.content;
|
|
3383
|
+
if (key.startsWith("vue:")) key = `vnode-${key.slice(4)}`;
|
|
3384
|
+
const { nonKeyModifiers, eventOptionModifiers } = (0, _vue_compiler_dom.resolveModifiers)(`on${key}`, prop.modifiers, null, prop.loc);
|
|
3385
|
+
if (key.toLowerCase() === "click") {
|
|
3386
|
+
if (nonKeyModifiers.includes("middle")) key = "mouseup";
|
|
3387
|
+
if (nonKeyModifiers.includes("right")) key = "contextmenu";
|
|
3388
|
+
}
|
|
3389
|
+
key = (0, _vue_shared.toHandlerKey)((0, _vue_shared.camelize)(key));
|
|
3390
|
+
const optionPostfix = eventOptionModifiers.map(_vue_shared.capitalize).join("");
|
|
3391
|
+
if (optionPostfix) key += optionPostfix;
|
|
3392
|
+
return key;
|
|
3393
|
+
}
|
|
3394
|
+
function getObjectLiteralKeys(exp) {
|
|
3395
|
+
const ast = exp && exp.ast;
|
|
3396
|
+
if (!ast || ast.type !== "ObjectExpression") return;
|
|
3397
|
+
const keys = /* @__PURE__ */ new Set();
|
|
3398
|
+
for (const property of ast.properties) {
|
|
3399
|
+
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
3400
|
+
const key = getObjectPropertyName(property);
|
|
3401
|
+
if (key == null) return;
|
|
3402
|
+
keys.add(key);
|
|
3403
|
+
}
|
|
3404
|
+
return keys;
|
|
3405
|
+
}
|
|
3406
|
+
function createComponentConflictKeySet(keys) {
|
|
3407
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
3408
|
+
for (const key of keys) {
|
|
3409
|
+
normalized.add(key);
|
|
3410
|
+
normalized.add((0, _vue_shared.camelize)(key));
|
|
3411
|
+
}
|
|
3412
|
+
return normalized;
|
|
3413
|
+
}
|
|
3414
|
+
function hasComponentKey(keys, key) {
|
|
3415
|
+
return keys.has(key) || keys.has((0, _vue_shared.camelize)(key));
|
|
3416
|
+
}
|
|
3417
|
+
function hasComponentKeyOverlap(left, right) {
|
|
3418
|
+
for (const key of right) if (hasComponentKey(left, key)) return true;
|
|
3419
|
+
return false;
|
|
3420
|
+
}
|
|
3421
|
+
function createObjectBindSubExpression(source, node, context) {
|
|
3422
|
+
const start = node.start == null ? 0 : node.start - 1;
|
|
3423
|
+
const end = node.end == null ? source.content.length : node.end - 1;
|
|
3424
|
+
const content = source.content.slice(start, end);
|
|
3425
|
+
const expression = (0, _vue_compiler_dom.createSimpleExpression)(content, false, {
|
|
3426
|
+
start: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, source.content, start),
|
|
3427
|
+
end: (0, _vue_compiler_dom.advancePositionWithClone)(source.loc.start, source.content, end),
|
|
3428
|
+
source: content
|
|
3429
|
+
});
|
|
3430
|
+
expression.ast = (0, _vue_compiler_dom.isSimpleIdentifier)(content) ? null : (0, _babel_parser.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
3431
|
+
return expression;
|
|
3432
|
+
}
|
|
2614
3433
|
function transformProp(prop, node, context) {
|
|
2615
3434
|
let { name } = prop;
|
|
2616
3435
|
if (prop.type === 6) {
|
|
@@ -2661,6 +3480,12 @@ function resolveDirectiveResult(prop) {
|
|
|
2661
3480
|
values: [prop.value]
|
|
2662
3481
|
});
|
|
2663
3482
|
}
|
|
3483
|
+
function toDirectiveResult(prop) {
|
|
3484
|
+
return (0, _vue_shared.extend)({}, prop, {
|
|
3485
|
+
values: void 0,
|
|
3486
|
+
value: prop.values[0]
|
|
3487
|
+
});
|
|
3488
|
+
}
|
|
2664
3489
|
function mergePropValues(existing, incoming) {
|
|
2665
3490
|
const newValues = incoming.values;
|
|
2666
3491
|
existing.values.push(...newValues);
|
|
@@ -2677,8 +3502,12 @@ const transformChildren = (node, context) => {
|
|
|
2677
3502
|
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
2678
3503
|
if (!isFragment && node.type !== 1) return;
|
|
2679
3504
|
const useCreateElement = node.type === 1 && shouldUseCreateElement(node, context);
|
|
3505
|
+
const childTemplateCloseState = !isFragment && !useCreateElement ? getChildTemplateCloseState(context) : void 0;
|
|
2680
3506
|
for (const [i, child] of node.children.entries()) {
|
|
2681
3507
|
const childContext = context.create(child, i);
|
|
3508
|
+
const isInSameTemplate = childTemplateCloseState && child.type === 1 && child.tagType === 0 && isInSameTemplateAsParent(childContext);
|
|
3509
|
+
childContext.templateCloseTags = isInSameTemplate ? childTemplateCloseState.tags : void 0;
|
|
3510
|
+
childContext.templateCloseBlocks = isInSameTemplate ? childTemplateCloseState.blocks : false;
|
|
2682
3511
|
transformNode(childContext);
|
|
2683
3512
|
const childDynamic = childContext.dynamic;
|
|
2684
3513
|
if (isFragment) {
|
|
@@ -3190,6 +4019,7 @@ function processIf(node, dir, context) {
|
|
|
3190
4019
|
}
|
|
3191
4020
|
context.dynamic.flags |= 2;
|
|
3192
4021
|
const forceMultiRoot = shouldForceMultiRoot(context);
|
|
4022
|
+
const allowNoScope = context.block === context.root.block;
|
|
3193
4023
|
if (dir.name === "if") {
|
|
3194
4024
|
const id = context.reference();
|
|
3195
4025
|
context.dynamic.flags |= 4;
|
|
@@ -3200,7 +4030,7 @@ function processIf(node, dir, context) {
|
|
|
3200
4030
|
type: 15,
|
|
3201
4031
|
id,
|
|
3202
4032
|
...context.effectBoundary(),
|
|
3203
|
-
blockShape: encodeIfBlockShape(branch, forceMultiRoot),
|
|
4033
|
+
blockShape: encodeIfBlockShape(branch, forceMultiRoot, void 0, allowNoScope),
|
|
3204
4034
|
condition: dir.exp,
|
|
3205
4035
|
positive: branch,
|
|
3206
4036
|
index: context.root.nextIfIndex(),
|
|
@@ -3242,8 +4072,8 @@ function processIf(node, dir, context) {
|
|
|
3242
4072
|
};
|
|
3243
4073
|
return () => {
|
|
3244
4074
|
onExit();
|
|
3245
|
-
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot);
|
|
3246
|
-
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative);
|
|
4075
|
+
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot, void 0, allowNoScope);
|
|
4076
|
+
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative, allowNoScope);
|
|
3247
4077
|
};
|
|
3248
4078
|
}
|
|
3249
4079
|
}
|
|
@@ -3258,14 +4088,38 @@ function createIfBranch(node, context) {
|
|
|
3258
4088
|
context.reference();
|
|
3259
4089
|
return [branch, exitBlock];
|
|
3260
4090
|
}
|
|
3261
|
-
function encodeIfBlockShape(positive, forceMultiRoot = false, negative) {
|
|
4091
|
+
function encodeIfBlockShape(positive, forceMultiRoot = false, negative, allowNoScope = true) {
|
|
3262
4092
|
if (forceMultiRoot) return 10;
|
|
3263
|
-
|
|
4093
|
+
const positiveNoScope = allowNoScope && canSkipIfBranchScope(positive);
|
|
4094
|
+
const negativeNoScope = allowNoScope && negative && negative.type !== 15 && canSkipIfBranchScope(negative);
|
|
4095
|
+
return getBlockShape(positive) | getNegativeIfBranchShape(negative) << 2 | (positiveNoScope ? 32 : 0) | (negativeNoScope ? 64 : 0);
|
|
3264
4096
|
}
|
|
3265
|
-
function
|
|
4097
|
+
function getNegativeIfBranchShape(negative) {
|
|
3266
4098
|
if (!negative) return 0;
|
|
3267
4099
|
return negative.type === 15 ? 1 : getBlockShape(negative);
|
|
3268
4100
|
}
|
|
4101
|
+
function canSkipIfBranchScope(block) {
|
|
4102
|
+
if (block.effect.length || block.operation.length) return false;
|
|
4103
|
+
if (!isStaticBranch(block.node)) return false;
|
|
4104
|
+
if (block.returns.length === 0 || block.dynamic.children.length !== block.returns.length) return false;
|
|
4105
|
+
return block.returns.every((id) => {
|
|
4106
|
+
const returned = findReturnedDynamic(block, id);
|
|
4107
|
+
return !!(returned && returned.template != null && !returned.operation && !returned.hasDynamicChild && !(returned.flags & 6));
|
|
4108
|
+
});
|
|
4109
|
+
}
|
|
4110
|
+
function findReturnedDynamic(block, id) {
|
|
4111
|
+
return block.dynamic.children.find((child) => child.id === id);
|
|
4112
|
+
}
|
|
4113
|
+
function isStaticBranch(node) {
|
|
4114
|
+
if (node.type !== 1 || node.tagType !== 3 || node.children.length === 0) return false;
|
|
4115
|
+
return node.children.every((child) => isStaticTemplateNode(child));
|
|
4116
|
+
}
|
|
4117
|
+
function isStaticTemplateNode(node) {
|
|
4118
|
+
if (node.type === 2 || node.type === 3) return true;
|
|
4119
|
+
if (node.type !== 1 || node.tagType !== 0) return false;
|
|
4120
|
+
for (const prop of node.props) if (prop.type === 7 || prop.name === "ref") return false;
|
|
4121
|
+
return node.children.every((child) => isStaticTemplateNode(child));
|
|
4122
|
+
}
|
|
3269
4123
|
function shouldForceMultiRoot(context) {
|
|
3270
4124
|
const parent = context.parent && context.parent.node;
|
|
3271
4125
|
return !!parent && parent.type === 1 && parent.tagType === 3 && parent.props.some((prop) => prop.type === 7 && prop.name === "for");
|
|
@@ -3350,6 +4204,9 @@ const transformSlotOutlet = (node, context) => {
|
|
|
3350
4204
|
}
|
|
3351
4205
|
return () => {
|
|
3352
4206
|
exitBlock && exitBlock();
|
|
4207
|
+
let flags = 0;
|
|
4208
|
+
if (context.options.scopeId && !context.options.slotted) flags |= 1;
|
|
4209
|
+
if (context.inVOnce) flags |= 2;
|
|
3353
4210
|
context.dynamic.operation = {
|
|
3354
4211
|
type: 13,
|
|
3355
4212
|
id,
|
|
@@ -3357,8 +4214,7 @@ const transformSlotOutlet = (node, context) => {
|
|
|
3357
4214
|
name: slotName,
|
|
3358
4215
|
props: irProps,
|
|
3359
4216
|
fallback,
|
|
3360
|
-
|
|
3361
|
-
once: context.inVOnce
|
|
4217
|
+
flags
|
|
3362
4218
|
};
|
|
3363
4219
|
};
|
|
3364
4220
|
};
|