@vue/compiler-sfc 3.6.0-beta.12 → 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-sfc.cjs.js +7 -4
- package/dist/compiler-sfc.esm-browser.js +853 -147
- package/package.json +7 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-sfc v3.6.0-beta.
|
|
2
|
+
* @vue/compiler-sfc v3.6.0-beta.13
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -389,6 +389,13 @@ const isBlockTag = /* @__PURE__ */ makeMap(BLOCK_TAGS);
|
|
|
389
389
|
* The full list is needed during SSR to produce the correct initial markup.
|
|
390
390
|
*/
|
|
391
391
|
const isBooleanAttr = /* @__PURE__ */ makeMap("itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly,async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected");
|
|
392
|
+
/**
|
|
393
|
+
* Boolean attributes should be included if the value is truthy or ''.
|
|
394
|
+
* e.g. `<select multiple>` compiles to `{ multiple: '' }`
|
|
395
|
+
*/
|
|
396
|
+
function includeBooleanAttr(value) {
|
|
397
|
+
return !!value || value === "";
|
|
398
|
+
}
|
|
392
399
|
const unsafeAttrCharRE = /[>/="'\u0009\u000a\u000c\u0020]/;
|
|
393
400
|
const attrValidationCache = {};
|
|
394
401
|
function isSSRSafeAttrName(name) {
|
|
@@ -20765,12 +20772,9 @@ const transformFor = createStructuralDirectiveTransform$1("for", (node, dir, con
|
|
|
20765
20772
|
const keyProp = findProp$1(node, `key`, false, true);
|
|
20766
20773
|
const isDirKey = keyProp && keyProp.type === 7;
|
|
20767
20774
|
let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
|
|
20768
|
-
|
|
20769
|
-
|
|
20770
|
-
if (isTemplate)
|
|
20771
|
-
if (memo) memo.exp = processExpression(memo.exp, context);
|
|
20772
|
-
if (keyProperty && keyProp.type !== 6) keyProperty.value = processExpression(keyProperty.value, context);
|
|
20773
|
-
}
|
|
20775
|
+
const keyProperty = keyExp ? createObjectProperty(`key`, keyExp) : null;
|
|
20776
|
+
if (isTemplate && memo) memo.exp = processExpression(memo.exp, context);
|
|
20777
|
+
if ((isTemplate || memo) && keyProperty && isDirKey) keyExp = keyProp.exp = keyProperty.value = processExpression(keyProperty.value, context);
|
|
20774
20778
|
const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
|
|
20775
20779
|
const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
|
|
20776
20780
|
forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), void 0, renderExp, fragmentFlag, void 0, void 0, true, !isStableFragment, false, node.loc);
|
|
@@ -25329,7 +25333,9 @@ function genPrependNode(oper, { helper }) {
|
|
|
25329
25333
|
}
|
|
25330
25334
|
//#endregion
|
|
25331
25335
|
//#region packages/compiler-vapor/src/generators/expression.ts
|
|
25336
|
+
init_objectSpread2();
|
|
25332
25337
|
function genExpression(node, context, assignment) {
|
|
25338
|
+
node = context.getExpressionReplacement(node);
|
|
25333
25339
|
const { content, ast, isStatic, loc } = node;
|
|
25334
25340
|
if (isStatic) return [[
|
|
25335
25341
|
JSON.stringify(content),
|
|
@@ -25444,11 +25450,12 @@ function canPrefix(name) {
|
|
|
25444
25450
|
return true;
|
|
25445
25451
|
}
|
|
25446
25452
|
function processExpressions(context, expressions, shouldDeclare) {
|
|
25453
|
+
const expressionReplacements = /* @__PURE__ */ new Map();
|
|
25447
25454
|
const { seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
|
|
25448
25455
|
const reservedNames = new Set(seenIdentifier);
|
|
25449
|
-
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames);
|
|
25450
|
-
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames);
|
|
25451
|
-
return genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare);
|
|
25456
|
+
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames, expressionReplacements);
|
|
25457
|
+
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames, expressionReplacements);
|
|
25458
|
+
return _objectSpread2(_objectSpread2({}, genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare)), {}, { expressionReplacements });
|
|
25452
25459
|
}
|
|
25453
25460
|
function analyzeExpressions(expressions) {
|
|
25454
25461
|
const seenVariable = Object.create(null);
|
|
@@ -25506,7 +25513,13 @@ function analyzeExpressions(expressions) {
|
|
|
25506
25513
|
updatedVariable
|
|
25507
25514
|
};
|
|
25508
25515
|
}
|
|
25509
|
-
function
|
|
25516
|
+
function getProcessedExpression(exp, expressionReplacements) {
|
|
25517
|
+
return expressionReplacements.get(exp) || exp;
|
|
25518
|
+
}
|
|
25519
|
+
function setExpressionReplacement(expressionReplacements, exp, content, ast) {
|
|
25520
|
+
expressionReplacements.set(exp, extend({ ast }, createSimpleExpression(content, exp.isStatic, exp.loc, exp.constType)));
|
|
25521
|
+
}
|
|
25522
|
+
function processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames, expressionReplacements) {
|
|
25510
25523
|
const declarations = [];
|
|
25511
25524
|
const expToReplacementMap = /* @__PURE__ */ new Map();
|
|
25512
25525
|
for (const [name, exps] of variableToExpMap) {
|
|
@@ -25539,14 +25552,15 @@ function processRepeatedVariables(context, seenVariable, variableToExpMap, expTo
|
|
|
25539
25552
|
}
|
|
25540
25553
|
}
|
|
25541
25554
|
for (const [exp, replacements] of expToReplacementMap) {
|
|
25555
|
+
let content = getProcessedExpression(exp, expressionReplacements).content;
|
|
25542
25556
|
replacements.flatMap(({ name, locs }) => locs.map(({ start, end }) => ({
|
|
25543
25557
|
start,
|
|
25544
25558
|
end,
|
|
25545
25559
|
name
|
|
25546
25560
|
}))).sort((a, b) => b.end - a.end).forEach(({ start, end, name }) => {
|
|
25547
|
-
|
|
25561
|
+
content = content.slice(0, start - 1) + name + content.slice(end - 1);
|
|
25548
25562
|
});
|
|
25549
|
-
exp
|
|
25563
|
+
setExpressionReplacement(expressionReplacements, exp, content, parseExp(context, content));
|
|
25550
25564
|
}
|
|
25551
25565
|
return declarations;
|
|
25552
25566
|
}
|
|
@@ -25562,13 +25576,14 @@ function shouldDeclareVariable(name, expToVariableMap, exps) {
|
|
|
25562
25576
|
if (vars.every((v) => v.every((e, idx) => e === first[idx]))) return false;
|
|
25563
25577
|
return true;
|
|
25564
25578
|
}
|
|
25565
|
-
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames) {
|
|
25579
|
+
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames, expressionReplacements) {
|
|
25566
25580
|
const declarations = [];
|
|
25567
25581
|
const seenExp = expressions.reduce((acc, exp) => {
|
|
25568
25582
|
const vars = expToVariableMap.get(exp);
|
|
25569
25583
|
if (!vars) return acc;
|
|
25584
|
+
const processed = getProcessedExpression(exp, expressionReplacements);
|
|
25570
25585
|
const variables = vars.map((v) => v.name);
|
|
25571
|
-
if (
|
|
25586
|
+
if (processed.ast && processed.ast.type !== "Identifier" && !(variables && variables.some((v) => updatedVariable.has(v))) && !variables.some((v) => isGloballyAllowed(v))) acc[processed.content] = (acc[processed.content] || 0) + 1;
|
|
25572
25587
|
return acc;
|
|
25573
25588
|
}, Object.create(null));
|
|
25574
25589
|
Object.entries(seenExp).forEach(([content, count]) => {
|
|
@@ -25577,13 +25592,13 @@ function processRepeatedExpressions(context, expressions, varDeclarations, updat
|
|
|
25577
25592
|
for (let i = varDeclarations.length - 1; i >= 0; i--) {
|
|
25578
25593
|
const item = varDeclarations[i];
|
|
25579
25594
|
if (!item.exps || !item.seenCount) continue;
|
|
25580
|
-
if ([...item.exps].every((node) => node.content === content && item.seenCount === count)) {
|
|
25595
|
+
if ([...item.exps].every((node) => getProcessedExpression(node, expressionReplacements).content === content && item.seenCount === count)) {
|
|
25581
25596
|
delVars[item.name] = item.rawName;
|
|
25582
25597
|
reservedNames.delete(item.name);
|
|
25583
25598
|
varDeclarations.splice(i, 1);
|
|
25584
25599
|
}
|
|
25585
25600
|
}
|
|
25586
|
-
const value = extend({}, expressions.find((exp) => exp.content === content));
|
|
25601
|
+
const value = extend({}, getProcessedExpression(expressions.find((exp) => getProcessedExpression(exp, expressionReplacements).content === content), expressionReplacements));
|
|
25587
25602
|
Object.keys(delVars).forEach((name) => {
|
|
25588
25603
|
value.content = value.content.replace(name, delVars[name]);
|
|
25589
25604
|
if (value.ast) value.ast = parseExp(context, value.content);
|
|
@@ -25594,12 +25609,11 @@ function processRepeatedExpressions(context, expressions, varDeclarations, updat
|
|
|
25594
25609
|
value
|
|
25595
25610
|
});
|
|
25596
25611
|
expressions.forEach((exp) => {
|
|
25597
|
-
|
|
25598
|
-
|
|
25599
|
-
|
|
25600
|
-
|
|
25601
|
-
|
|
25602
|
-
exp.ast = parseExp(context, exp.content);
|
|
25612
|
+
const processed = getProcessedExpression(exp, expressionReplacements);
|
|
25613
|
+
if (processed.content === content) setExpressionReplacement(expressionReplacements, exp, varName, null);
|
|
25614
|
+
else if (processed.content.includes(content)) {
|
|
25615
|
+
const replacedContent = processed.content.replace(new RegExp(escapeRegExp(content), "g"), varName);
|
|
25616
|
+
setExpressionReplacement(expressionReplacements, exp, replacedContent, parseExp(context, replacedContent));
|
|
25603
25617
|
}
|
|
25604
25618
|
});
|
|
25605
25619
|
}
|
|
@@ -25678,22 +25692,31 @@ const isMemberExpression = (node) => {
|
|
|
25678
25692
|
function genSetEvent(oper, context) {
|
|
25679
25693
|
const { helper } = context;
|
|
25680
25694
|
const { element, key, keyOverride, value, modifiers, delegate, effect } = oper;
|
|
25681
|
-
|
|
25682
|
-
const handler = [
|
|
25683
|
-
`${context.helper("createInvoker")}(`,
|
|
25684
|
-
...genEventHandler(context, [value], modifiers),
|
|
25685
|
-
`)`
|
|
25686
|
-
];
|
|
25687
|
-
const eventOptions = genEventOptions();
|
|
25695
|
+
let handler;
|
|
25688
25696
|
if (delegate) {
|
|
25689
25697
|
context.delegates.add(key.content);
|
|
25690
25698
|
if (!context.block.operation.some(isSameDelegateEvent)) return [
|
|
25691
25699
|
NEWLINE,
|
|
25692
25700
|
`n${element}.$evt${key.content} = `,
|
|
25693
|
-
...
|
|
25701
|
+
...genDirectHandler()
|
|
25702
|
+
];
|
|
25703
|
+
}
|
|
25704
|
+
const name = genName();
|
|
25705
|
+
const eventOptions = genEventOptions();
|
|
25706
|
+
return [NEWLINE, ...genCall(helper(effect ? "onBinding" : delegate ? "delegate" : "on"), `n${element}`, name, genHandler(), eventOptions)];
|
|
25707
|
+
function genHandler() {
|
|
25708
|
+
return handler || (handler = genEventHandler(context, [value], modifiers));
|
|
25709
|
+
}
|
|
25710
|
+
function genInvoker() {
|
|
25711
|
+
return [
|
|
25712
|
+
`${helper("createInvoker")}(`,
|
|
25713
|
+
...genHandler(),
|
|
25714
|
+
`)`
|
|
25694
25715
|
];
|
|
25695
25716
|
}
|
|
25696
|
-
|
|
25717
|
+
function genDirectHandler() {
|
|
25718
|
+
return modifiers.keys.length || modifiers.nonKeys.length ? genEventHandler(context, [value], modifiers, { modifierHelper: "vapor" }) : genInvoker();
|
|
25719
|
+
}
|
|
25697
25720
|
function genName() {
|
|
25698
25721
|
const expr = genExpression(key, context);
|
|
25699
25722
|
if (keyOverride) {
|
|
@@ -25713,8 +25736,8 @@ function genSetEvent(oper, context) {
|
|
|
25713
25736
|
}
|
|
25714
25737
|
function genEventOptions() {
|
|
25715
25738
|
let { options } = modifiers;
|
|
25716
|
-
if (!options.length
|
|
25717
|
-
return genMulti(DELIMITERS_OBJECT_NEWLINE,
|
|
25739
|
+
if (!options.length) return;
|
|
25740
|
+
return genMulti(DELIMITERS_OBJECT_NEWLINE, ...options.map((option) => [`${option}: true`]));
|
|
25718
25741
|
}
|
|
25719
25742
|
function isSameDelegateEvent(op) {
|
|
25720
25743
|
if (op.type === 6 && op !== oper && op.delegate && op.element === oper.element && op.key.content === key.content) return true;
|
|
@@ -25727,7 +25750,9 @@ function genSetDynamicEvents(oper, context) {
|
|
|
25727
25750
|
function genEventHandler(context, values, modifiers = {
|
|
25728
25751
|
nonKeys: [],
|
|
25729
25752
|
keys: []
|
|
25730
|
-
},
|
|
25753
|
+
}, options = {}) {
|
|
25754
|
+
const { asComponentProp = false, extraWrap = false, modifierHelper = "runtime" } = options;
|
|
25755
|
+
const useVaporModifierHelper = modifierHelper === "vapor";
|
|
25731
25756
|
let handlerExp = [];
|
|
25732
25757
|
if (values) {
|
|
25733
25758
|
values.forEach((value, index) => {
|
|
@@ -25768,16 +25793,16 @@ function genEventHandler(context, values, modifiers = {
|
|
|
25768
25793
|
}
|
|
25769
25794
|
if (handlerExp.length === 0) handlerExp = ["() => {}"];
|
|
25770
25795
|
const { keys, nonKeys } = modifiers;
|
|
25771
|
-
if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys);
|
|
25772
|
-
if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys);
|
|
25796
|
+
if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys, useVaporModifierHelper && !keys.length);
|
|
25797
|
+
if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys, useVaporModifierHelper);
|
|
25773
25798
|
if (extraWrap) handlerExp.unshift(`() => `);
|
|
25774
25799
|
return handlerExp;
|
|
25775
25800
|
}
|
|
25776
|
-
function genWithModifiers(context, handler, nonKeys) {
|
|
25777
|
-
return genCall(context.helper("withModifiers"), handler, JSON.stringify(nonKeys));
|
|
25801
|
+
function genWithModifiers(context, handler, nonKeys, useVaporHelper = false) {
|
|
25802
|
+
return genCall(context.helper(useVaporHelper ? "withVaporModifiers" : "withModifiers"), handler, JSON.stringify(nonKeys));
|
|
25778
25803
|
}
|
|
25779
|
-
function genWithKeys(context, handler, keys) {
|
|
25780
|
-
return genCall(context.helper("withKeys"), handler, JSON.stringify(keys));
|
|
25804
|
+
function genWithKeys(context, handler, keys, useVaporHelper = false) {
|
|
25805
|
+
return genCall(context.helper(useVaporHelper ? "withVaporKeys" : "withKeys"), handler, JSON.stringify(keys));
|
|
25781
25806
|
}
|
|
25782
25807
|
function isConstantBinding(value, context) {
|
|
25783
25808
|
if (value.ast === null) {
|
|
@@ -25844,6 +25869,8 @@ function genFor(oper, context) {
|
|
|
25844
25869
|
let flags = 0;
|
|
25845
25870
|
if (onlyChild) flags |= 1;
|
|
25846
25871
|
if (component) flags |= 2;
|
|
25872
|
+
if (isFragmentBlock(render)) flags |= 16;
|
|
25873
|
+
if (!component && isSingleNodeBlock(render)) flags |= 8;
|
|
25847
25874
|
if (once) flags |= 4;
|
|
25848
25875
|
const onResetCalls = [];
|
|
25849
25876
|
for (let i = 0; i < selectorPatterns.length; i++) onResetCalls.push(NEWLINE, `n${id}.onReset(${selectorName(i)}.reset)`);
|
|
@@ -25876,6 +25903,21 @@ function genFor(oper, context) {
|
|
|
25876
25903
|
return idMap;
|
|
25877
25904
|
}
|
|
25878
25905
|
}
|
|
25906
|
+
function isSingleNodeBlock(block) {
|
|
25907
|
+
const child = getSingleReturnedChild(block);
|
|
25908
|
+
return !!child && child.template != null;
|
|
25909
|
+
}
|
|
25910
|
+
function isFragmentBlock(block) {
|
|
25911
|
+
const child = getSingleReturnedChild(block);
|
|
25912
|
+
const operation = child && child.operation;
|
|
25913
|
+
if (!operation) return false;
|
|
25914
|
+
return operation.type === 13 || operation.type === 16 || operation.type === 17 || operation.type === 15 && !operation.once || operation.type === 12 && !!operation.dynamic && !operation.dynamic.isStatic;
|
|
25915
|
+
}
|
|
25916
|
+
function getSingleReturnedChild(block) {
|
|
25917
|
+
if (block.returns.length !== 1) return;
|
|
25918
|
+
const id = block.returns[0];
|
|
25919
|
+
for (const child of block.dynamic.children) if (child.id === id) return child;
|
|
25920
|
+
}
|
|
25879
25921
|
function parseValueDestructure(value, context) {
|
|
25880
25922
|
const map = /* @__PURE__ */ new Map();
|
|
25881
25923
|
if (value) {
|
|
@@ -26061,6 +26103,7 @@ function genIf(oper, context, isNested = false) {
|
|
|
26061
26103
|
const { helper } = context;
|
|
26062
26104
|
const { condition, positive, negative, once, index, blockShape } = oper;
|
|
26063
26105
|
const [frag, push] = buildCodeFragment();
|
|
26106
|
+
const flags = genIfFlags(blockShape, once, negative ? index : void 0);
|
|
26064
26107
|
const conditionExpr = [
|
|
26065
26108
|
"() => (",
|
|
26066
26109
|
...genExpression(condition, context),
|
|
@@ -26071,9 +26114,24 @@ function genIf(oper, context, isNested = false) {
|
|
|
26071
26114
|
if (negative) if (negative.type === 1) negativeArg = genBlock(negative, context);
|
|
26072
26115
|
else negativeArg = ["() => ", ...genIf(negative, context, true)];
|
|
26073
26116
|
if (!isNested) push(NEWLINE, `const n${oper.id} = `);
|
|
26074
|
-
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg,
|
|
26117
|
+
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, flags));
|
|
26075
26118
|
return frag;
|
|
26076
26119
|
}
|
|
26120
|
+
function genIfFlags(blockShape, once, index) {
|
|
26121
|
+
let flags = blockShape;
|
|
26122
|
+
if (once) flags |= 16;
|
|
26123
|
+
else if (index !== void 0) flags |= index + 1 << 7;
|
|
26124
|
+
if (flags === 1) return false;
|
|
26125
|
+
return `${flags} /* ${genIfFlagNames(once, index, blockShape)} */`;
|
|
26126
|
+
}
|
|
26127
|
+
function genIfFlagNames(once, index, blockShape) {
|
|
26128
|
+
const names = ["BLOCK_SHAPE"];
|
|
26129
|
+
if (blockShape & 32) names.push("TRUE_NO_SCOPE");
|
|
26130
|
+
if (blockShape & 64) names.push("FALSE_NO_SCOPE");
|
|
26131
|
+
if (once) names.push("ONCE");
|
|
26132
|
+
else if (index !== void 0) names.push("INDEX_SHIFT");
|
|
26133
|
+
return names.join(", ");
|
|
26134
|
+
}
|
|
26077
26135
|
//#endregion
|
|
26078
26136
|
//#region packages/compiler-vapor/src/generators/prop.ts
|
|
26079
26137
|
const helpers = {
|
|
@@ -26123,15 +26181,16 @@ function resolveClassName(values, context) {
|
|
|
26123
26181
|
const entries = [];
|
|
26124
26182
|
let sawDynamic = false;
|
|
26125
26183
|
let sawSuffix = false;
|
|
26126
|
-
for (const
|
|
26184
|
+
for (const rawValue of values) {
|
|
26185
|
+
const value = context.getExpressionReplacement(rawValue);
|
|
26127
26186
|
const staticValue = getLiteralExpressionValue(value, true);
|
|
26128
26187
|
if (staticValue != null) {
|
|
26129
26188
|
const normalized = normalizeClass(staticValue);
|
|
26130
|
-
if (normalized) if (sawSuffix) suffix = appendClass(suffix, normalized);
|
|
26189
|
+
if (normalized) if (sawSuffix) suffix = appendClass$1(suffix, normalized);
|
|
26131
26190
|
else if (sawDynamic) {
|
|
26132
26191
|
sawSuffix = true;
|
|
26133
|
-
suffix = appendClass(suffix, normalized);
|
|
26134
|
-
} else prefix = appendClass(prefix, normalized);
|
|
26192
|
+
suffix = appendClass$1(suffix, normalized);
|
|
26193
|
+
} else prefix = appendClass$1(prefix, normalized);
|
|
26135
26194
|
continue;
|
|
26136
26195
|
}
|
|
26137
26196
|
const ast = value.ast;
|
|
@@ -26152,7 +26211,7 @@ function resolveClassName(values, context) {
|
|
|
26152
26211
|
function resolveObjectClassName(source, ast, entries, context) {
|
|
26153
26212
|
for (const prop of ast.properties) {
|
|
26154
26213
|
if (prop.type !== "ObjectProperty" || prop.computed) return false;
|
|
26155
|
-
const rawClassName = getObjectPropertyName(prop);
|
|
26214
|
+
const rawClassName = getObjectPropertyName$1(prop);
|
|
26156
26215
|
if (rawClassName == null) return false;
|
|
26157
26216
|
const className = normalizeClass(rawClassName);
|
|
26158
26217
|
if (!className) continue;
|
|
@@ -26197,10 +26256,10 @@ function genClassFlags(entries, context) {
|
|
|
26197
26256
|
});
|
|
26198
26257
|
return values;
|
|
26199
26258
|
}
|
|
26200
|
-
function appendClass(base, value) {
|
|
26259
|
+
function appendClass$1(base, value) {
|
|
26201
26260
|
return base ? value ? `${base} ${value}` : base : value;
|
|
26202
26261
|
}
|
|
26203
|
-
function getObjectPropertyName(prop) {
|
|
26262
|
+
function getObjectPropertyName$1(prop) {
|
|
26204
26263
|
const key = prop.key;
|
|
26205
26264
|
if (key.type === "Identifier") return key.name;
|
|
26206
26265
|
else if (key.type === "StringLiteral") return key.value;
|
|
@@ -26292,8 +26351,23 @@ function getSpecialHelper(keyName, tagName, isSVG) {
|
|
|
26292
26351
|
const setTemplateRefIdent = `_setTemplateRef`;
|
|
26293
26352
|
function genSetTemplateRef(oper, context) {
|
|
26294
26353
|
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
26354
|
+
if (context.staticTemplateRefHelperCandidate === oper) return genSetStaticTemplateRef(oper, refValue, refKey, context);
|
|
26355
|
+
context.needsTemplateRefSetter = true;
|
|
26295
26356
|
return [NEWLINE, ...genCall(setTemplateRefIdent, `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
26296
26357
|
}
|
|
26358
|
+
function genSetStaticTemplateRef(oper, refValue, refKey, context) {
|
|
26359
|
+
return [NEWLINE, ...genCall(context.helper("setStaticTemplateRef"), `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
26360
|
+
}
|
|
26361
|
+
function genSetTemplateRefBinding(oper, context) {
|
|
26362
|
+
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
26363
|
+
const setter = context.inSlotBlock && setTemplateRefIdent;
|
|
26364
|
+
if (context.inSlotBlock) context.needsTemplateRefSetter = true;
|
|
26365
|
+
return [NEWLINE, ...genCall([context.helper("setTemplateRefBinding"), "undefined"], `n${oper.element}`, ["() => ", ...refValue], ...setter || oper.refFor || refKey ? [
|
|
26366
|
+
setter,
|
|
26367
|
+
oper.refFor && "true",
|
|
26368
|
+
refKey
|
|
26369
|
+
] : [])];
|
|
26370
|
+
}
|
|
26297
26371
|
function genRefValue(value, context) {
|
|
26298
26372
|
if (value && context.options.inline) {
|
|
26299
26373
|
const binding = context.options.bindingMetadata[value.content];
|
|
@@ -26397,15 +26471,18 @@ function filterCustomDirectives(id, operations) {
|
|
|
26397
26471
|
//#region packages/compiler-vapor/src/generators/component.ts
|
|
26398
26472
|
function genCreateComponent(operation, context) {
|
|
26399
26473
|
const { helper } = context;
|
|
26474
|
+
const singleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
26475
|
+
const useAssetComponentHelper = operation.asset && !operation.dynamic && context.block === context.ir.block && !!singleUseAssetComponentNames && singleUseAssetComponentNames.has(operation.tag);
|
|
26476
|
+
const maybeSelfReference = useAssetComponentHelper && operation.tag.endsWith("__self");
|
|
26400
26477
|
const tag = genTag();
|
|
26401
26478
|
const { root, props, slots, once } = operation;
|
|
26402
26479
|
const rawSlots = genRawSlots(slots, context);
|
|
26403
26480
|
const [ids, handlers] = processInlineHandlers(props, context);
|
|
26404
|
-
const rawProps = context.withId(() => genRawProps(props, context), ids);
|
|
26481
|
+
const rawProps = context.withId(() => genRawProps(props, context, true), ids);
|
|
26405
26482
|
return [
|
|
26406
26483
|
NEWLINE,
|
|
26407
26484
|
...handlers.reduce((acc, { name, value }) => {
|
|
26408
|
-
const handler = genEventHandler(context, [value]
|
|
26485
|
+
const handler = genEventHandler(context, [value]);
|
|
26409
26486
|
return [
|
|
26410
26487
|
...acc,
|
|
26411
26488
|
`const ${name} = `,
|
|
@@ -26414,7 +26491,7 @@ function genCreateComponent(operation, context) {
|
|
|
26414
26491
|
];
|
|
26415
26492
|
}, []),
|
|
26416
26493
|
`const n${operation.id} = `,
|
|
26417
|
-
...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"),
|
|
26494
|
+
...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"),
|
|
26418
26495
|
...genDirectivesForElement(operation.id, context)
|
|
26419
26496
|
];
|
|
26420
26497
|
function genTag() {
|
|
@@ -26425,7 +26502,10 @@ function genCreateComponent(operation, context) {
|
|
|
26425
26502
|
...genExpression(operation.dynamic, context),
|
|
26426
26503
|
")"
|
|
26427
26504
|
];
|
|
26428
|
-
else if (
|
|
26505
|
+
else if (useAssetComponentHelper) {
|
|
26506
|
+
const name = maybeSelfReference ? operation.tag.slice(0, -6) : operation.tag;
|
|
26507
|
+
return JSON.stringify(name);
|
|
26508
|
+
} else if (operation.asset) return toValidAssetId(operation.tag, "component");
|
|
26429
26509
|
else {
|
|
26430
26510
|
const { tag } = operation;
|
|
26431
26511
|
const builtInTag = isBuiltInComponent(tag);
|
|
@@ -26465,14 +26545,14 @@ function processInlineHandlers(props, context) {
|
|
|
26465
26545
|
}
|
|
26466
26546
|
return [ids, handlers];
|
|
26467
26547
|
}
|
|
26468
|
-
function genRawProps(props, context) {
|
|
26548
|
+
function genRawProps(props, context, directStaticLiteralProps = false) {
|
|
26469
26549
|
const staticProps = props[0];
|
|
26470
26550
|
if (isArray$3(staticProps)) {
|
|
26471
26551
|
if (!staticProps.length && props.length === 1) return;
|
|
26472
|
-
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context));
|
|
26473
|
-
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context));
|
|
26552
|
+
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context, directStaticLiteralProps), directStaticLiteralProps);
|
|
26553
|
+
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context, directStaticLiteralProps), directStaticLiteralProps);
|
|
26474
26554
|
}
|
|
26475
|
-
function genStaticProps(props, context, dynamicProps) {
|
|
26555
|
+
function genStaticProps(props, context, dynamicProps, directStaticLiteralProps = false) {
|
|
26476
26556
|
const args = [];
|
|
26477
26557
|
const handlerGroups = /* @__PURE__ */ new Map();
|
|
26478
26558
|
const ensureHandlerGroup = (keyName, keyFrag) => {
|
|
@@ -26505,11 +26585,11 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
26505
26585
|
continue;
|
|
26506
26586
|
}
|
|
26507
26587
|
const keyFrag = genPropKey(prop, context);
|
|
26508
|
-
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
|
|
26509
|
-
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, true
|
|
26588
|
+
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 }));
|
|
26589
|
+
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, { asComponentProp: true }));
|
|
26510
26590
|
continue;
|
|
26511
26591
|
}
|
|
26512
|
-
args.push(genProp(prop, context, true));
|
|
26592
|
+
args.push(genProp(prop, context, true, true, directStaticLiteralProps && isDirectStaticLiteralProp(prop, context)));
|
|
26513
26593
|
if (prop.model) {
|
|
26514
26594
|
if (prop.key.isStatic) {
|
|
26515
26595
|
const keyName = `onUpdate:${camelize(prop.key.content)}`;
|
|
@@ -26534,7 +26614,7 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
26534
26614
|
" + \"Modifiers\"]"
|
|
26535
26615
|
];
|
|
26536
26616
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
26537
|
-
args.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
|
|
26617
|
+
args.push([...modifiersKey, directStaticLiteralProps ? `: { ${modifiersVal} }` : `: () => ({ ${modifiersVal} })`]);
|
|
26538
26618
|
}
|
|
26539
26619
|
}
|
|
26540
26620
|
}
|
|
@@ -26549,13 +26629,13 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
26549
26629
|
if (dynamicProps) args.push([`$: `, ...dynamicProps]);
|
|
26550
26630
|
return genMulti(args.length > 1 ? DELIMITERS_OBJECT_NEWLINE : DELIMITERS_OBJECT, ...args);
|
|
26551
26631
|
}
|
|
26552
|
-
function genDynamicProps(props, context) {
|
|
26632
|
+
function genDynamicProps(props, context, directStaticLiteralProps = false) {
|
|
26553
26633
|
const { helper } = context;
|
|
26554
26634
|
const frags = [];
|
|
26555
26635
|
for (const p of props) {
|
|
26556
26636
|
let expr;
|
|
26557
26637
|
if (isArray$3(p)) {
|
|
26558
|
-
if (p.length) frags.push(genStaticProps(p, context));
|
|
26638
|
+
if (p.length) frags.push(genStaticProps(p, context, void 0, directStaticLiteralProps));
|
|
26559
26639
|
continue;
|
|
26560
26640
|
} else if (p.kind === 1) if (p.model) {
|
|
26561
26641
|
const entries = [genProp(p, context)];
|
|
@@ -26566,7 +26646,7 @@ function genDynamicProps(props, context) {
|
|
|
26566
26646
|
];
|
|
26567
26647
|
entries.push([
|
|
26568
26648
|
...updateKey,
|
|
26569
|
-
":
|
|
26649
|
+
": ",
|
|
26570
26650
|
...genModelHandler(p.values[0], context)
|
|
26571
26651
|
]);
|
|
26572
26652
|
const { modelModifiers } = p;
|
|
@@ -26577,10 +26657,10 @@ function genDynamicProps(props, context) {
|
|
|
26577
26657
|
" + \"Modifiers\"]"
|
|
26578
26658
|
];
|
|
26579
26659
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
26580
|
-
entries.push([...modifiersKey, `:
|
|
26660
|
+
entries.push([...modifiersKey, `: { ${modifiersVal} }`]);
|
|
26581
26661
|
}
|
|
26582
26662
|
expr = genMulti(DELIMITERS_OBJECT_NEWLINE, ...entries);
|
|
26583
|
-
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context));
|
|
26663
|
+
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context, false, false));
|
|
26584
26664
|
else {
|
|
26585
26665
|
expr = genExpression(p.value, context);
|
|
26586
26666
|
if (p.handler) expr = genCall(helper("toHandlers"), expr);
|
|
@@ -26593,27 +26673,79 @@ function genDynamicProps(props, context) {
|
|
|
26593
26673
|
}
|
|
26594
26674
|
if (frags.length) return genMulti(DELIMITERS_ARRAY_NEWLINE, ...frags);
|
|
26595
26675
|
}
|
|
26596
|
-
function genProp(prop, context, isStatic) {
|
|
26676
|
+
function genProp(prop, context, isStatic, wrapHandler = true, directStaticLiteral = false) {
|
|
26597
26677
|
const values = genPropValue(prop.values, context);
|
|
26598
26678
|
return [
|
|
26599
26679
|
...genPropKey(prop, context),
|
|
26600
26680
|
": ",
|
|
26601
|
-
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers,
|
|
26681
|
+
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, {
|
|
26682
|
+
asComponentProp: true,
|
|
26683
|
+
extraWrap: wrapHandler
|
|
26684
|
+
}) : isStatic ? directStaticLiteral ? values : [
|
|
26602
26685
|
"() => (",
|
|
26603
26686
|
...values,
|
|
26604
26687
|
")"
|
|
26605
26688
|
] : values
|
|
26606
26689
|
];
|
|
26607
26690
|
}
|
|
26691
|
+
/**
|
|
26692
|
+
* Static literal values are safe to emit directly because reading them cannot
|
|
26693
|
+
* touch reactive state. Keep handlers, v-model values, and dynamic expressions
|
|
26694
|
+
* as getter sources to preserve lazy access and merge semantics.
|
|
26695
|
+
*/
|
|
26696
|
+
function isDirectStaticLiteralProp(prop, context) {
|
|
26697
|
+
return prop.key.isStatic && prop.values.length === 1 && !prop.handler && !prop.model && isDirectConstantValue(prop.values[0], context);
|
|
26698
|
+
}
|
|
26699
|
+
function isDirectConstantValue(value, context) {
|
|
26700
|
+
value = context.getExpressionReplacement(value);
|
|
26701
|
+
if (value.isStatic) return true;
|
|
26702
|
+
const ast = value.ast;
|
|
26703
|
+
if (ast === null) return value.content === "true" || value.content === "false" || value.content === "null" || value.content === "undefined";
|
|
26704
|
+
if (!ast) return false;
|
|
26705
|
+
return isDirectConstantAst(ast);
|
|
26706
|
+
}
|
|
26707
|
+
function isDirectConstantAst(node) {
|
|
26708
|
+
switch (node.type) {
|
|
26709
|
+
case "StringLiteral":
|
|
26710
|
+
case "NumericLiteral":
|
|
26711
|
+
case "BooleanLiteral":
|
|
26712
|
+
case "NullLiteral":
|
|
26713
|
+
case "BigIntLiteral": return true;
|
|
26714
|
+
case "Identifier": return node.name === "undefined";
|
|
26715
|
+
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
26716
|
+
case "ArrayExpression": return node.elements.every((element) => element === null || element.type !== "SpreadElement" && isDirectConstantAst(element));
|
|
26717
|
+
case "ObjectExpression": return node.properties.every((prop) => prop.type === "ObjectProperty" && !prop.computed && isDirectConstantAst(prop.value));
|
|
26718
|
+
}
|
|
26719
|
+
return false;
|
|
26720
|
+
}
|
|
26721
|
+
function isDirectTemplateConstantAst(node) {
|
|
26722
|
+
switch (node.type) {
|
|
26723
|
+
case "StringLiteral":
|
|
26724
|
+
case "NumericLiteral":
|
|
26725
|
+
case "BooleanLiteral":
|
|
26726
|
+
case "NullLiteral":
|
|
26727
|
+
case "BigIntLiteral": return true;
|
|
26728
|
+
case "Identifier": return node.name === "undefined";
|
|
26729
|
+
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
26730
|
+
}
|
|
26731
|
+
return false;
|
|
26732
|
+
}
|
|
26608
26733
|
function genRawSlots(slots, context) {
|
|
26609
26734
|
if (!slots.length) return;
|
|
26610
26735
|
const staticSlots = slots[0];
|
|
26611
|
-
if (staticSlots.slotType === 0)
|
|
26612
|
-
|
|
26736
|
+
if (staticSlots.slotType === 0) {
|
|
26737
|
+
const defaultSlot = getSingleDefaultSlot(staticSlots);
|
|
26738
|
+
if (defaultSlot && slots.length === 1) return genSlotBlockWithProps(defaultSlot, context);
|
|
26739
|
+
return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
|
|
26740
|
+
} else return genStaticSlots({
|
|
26613
26741
|
slotType: 0,
|
|
26614
26742
|
slots: {}
|
|
26615
26743
|
}, context, slots);
|
|
26616
26744
|
}
|
|
26745
|
+
function getSingleDefaultSlot({ slots }) {
|
|
26746
|
+
const names = Object.keys(slots);
|
|
26747
|
+
return names.length === 1 && names[0] === "default" ? slots.default : void 0;
|
|
26748
|
+
}
|
|
26617
26749
|
function genStaticSlots({ slots }, context, dynamicSlots) {
|
|
26618
26750
|
const args = Object.keys(slots).map((name) => [`${JSON.stringify(name)}: `, ...genSlotBlockWithProps(slots[name], context)]);
|
|
26619
26751
|
if (dynamicSlots) args.push([`$: `, ...genDynamicSlots(dynamicSlots, context)]);
|
|
@@ -26705,7 +26837,9 @@ function genSlotBlockWithProps(oper, context) {
|
|
|
26705
26837
|
} else propsName = props.content;
|
|
26706
26838
|
const idMap = idToPathMap.size ? buildDestructureIdMap(idToPathMap, propsName || "", context.options.expressionPlugins) : {};
|
|
26707
26839
|
if (propsName) idMap[propsName] = null;
|
|
26840
|
+
const exitSlotBlock = context.enterSlotBlock();
|
|
26708
26841
|
let blockFn = context.withId(() => genBlock(oper, context, propsName ? [propsName] : []), idMap);
|
|
26842
|
+
exitSlotBlock();
|
|
26709
26843
|
exitScope && exitScope();
|
|
26710
26844
|
if (node.type === 1) {
|
|
26711
26845
|
if (needsVaporCtx(oper)) blockFn = [
|
|
@@ -26766,16 +26900,18 @@ function hasComponentOrSlotInIf(node) {
|
|
|
26766
26900
|
//#region packages/compiler-vapor/src/generators/slotOutlet.ts
|
|
26767
26901
|
function genSlotOutlet(oper, context) {
|
|
26768
26902
|
const { helper } = context;
|
|
26769
|
-
const { id, name, fallback,
|
|
26903
|
+
const { id, name, fallback, flags } = oper;
|
|
26770
26904
|
const [frag, push] = buildCodeFragment();
|
|
26771
|
-
|
|
26905
|
+
let fallbackArg;
|
|
26906
|
+
if (fallback) fallbackArg = genBlock(fallback, context);
|
|
26907
|
+
const createSlot = helper("createSlot");
|
|
26908
|
+
const rawPropsArg = genRawProps(oper.props, context, true);
|
|
26909
|
+
const nameArg = name.isStatic && name.content === "default" && !rawPropsArg && !fallbackArg && !flags ? void 0 : name.isStatic ? genExpression(name, context) : [
|
|
26772
26910
|
"() => (",
|
|
26773
26911
|
...genExpression(name, context),
|
|
26774
26912
|
")"
|
|
26775
26913
|
];
|
|
26776
|
-
|
|
26777
|
-
if (fallback) fallbackArg = genBlock(fallback, context);
|
|
26778
|
-
push(NEWLINE, `const n${id} = `, ...genCall(helper("createSlot"), nameExpr, genRawProps(oper.props, context) || "null", fallbackArg, noSlotted && "true", once && "true"));
|
|
26914
|
+
push(NEWLINE, `const n${id} = `, ...genCall(createSlot, nameArg, rawPropsArg, fallbackArg, flags ? String(flags) : void 0));
|
|
26779
26915
|
return frag;
|
|
26780
26916
|
}
|
|
26781
26917
|
//#endregion
|
|
@@ -26835,28 +26971,35 @@ function genEffects(effects, context, genExtraFrag) {
|
|
|
26835
26971
|
const [frag, push, unshift] = buildCodeFragment();
|
|
26836
26972
|
const shouldDeclare = genExtraFrag === void 0;
|
|
26837
26973
|
let operationsCount = 0;
|
|
26838
|
-
const { ids, frag: declarationFrags, varNames } = processExpressions(context, expressions, shouldDeclare);
|
|
26839
|
-
|
|
26840
|
-
|
|
26841
|
-
const
|
|
26842
|
-
|
|
26843
|
-
|
|
26844
|
-
|
|
26845
|
-
|
|
26846
|
-
|
|
26847
|
-
|
|
26848
|
-
|
|
26849
|
-
|
|
26850
|
-
|
|
26851
|
-
|
|
26852
|
-
|
|
26853
|
-
|
|
26854
|
-
|
|
26855
|
-
|
|
26856
|
-
|
|
26857
|
-
|
|
26858
|
-
|
|
26859
|
-
|
|
26974
|
+
const { ids, frag: declarationFrags, varNames, expressionReplacements } = processExpressions(context, expressions, shouldDeclare);
|
|
26975
|
+
if (shouldDeclare && !declarationFrags.length && !varNames.length) {
|
|
26976
|
+
const effect = effects.length === 1 ? effects[0] : void 0;
|
|
26977
|
+
const operation = effect && effect.operations.length === 1 ? effect.operations[0] : void 0;
|
|
26978
|
+
if (operation && operation.type === 9 && operation.effect && !operation.refFor) return context.withExpressionReplacements(expressionReplacements, () => context.withId(() => genSetTemplateRefBinding(operation, context), ids));
|
|
26979
|
+
}
|
|
26980
|
+
return context.withExpressionReplacements(expressionReplacements, () => {
|
|
26981
|
+
push(...declarationFrags);
|
|
26982
|
+
for (let i = 0; i < effects.length; i++) {
|
|
26983
|
+
const effect = effects[i];
|
|
26984
|
+
operationsCount += effect.operations.length;
|
|
26985
|
+
const frags = context.withId(() => genEffect(effect, context), ids);
|
|
26986
|
+
i > 0 && push(NEWLINE);
|
|
26987
|
+
if (frag[frag.length - 1] === ")" && frags[0] === "(") push(";");
|
|
26988
|
+
push(...frags);
|
|
26989
|
+
}
|
|
26990
|
+
if (frag.filter((frag) => frag === NEWLINE).length > 1 || operationsCount > 1 || declarationFrags.length > 0) {
|
|
26991
|
+
unshift(`{`, INDENT_START, NEWLINE);
|
|
26992
|
+
push(INDENT_END, NEWLINE, "}");
|
|
26993
|
+
if (!effects.length) unshift(NEWLINE);
|
|
26994
|
+
}
|
|
26995
|
+
if (effects.length) {
|
|
26996
|
+
unshift(NEWLINE, `${helper("renderEffect")}(() => `);
|
|
26997
|
+
push(`)`);
|
|
26998
|
+
}
|
|
26999
|
+
if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
|
|
27000
|
+
if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
|
|
27001
|
+
return frag;
|
|
27002
|
+
});
|
|
26860
27003
|
}
|
|
26861
27004
|
function genEffect({ operations }, context) {
|
|
26862
27005
|
const [frag, push] = buildCodeFragment();
|
|
@@ -26875,9 +27018,8 @@ function genTemplates(templates, context) {
|
|
|
26875
27018
|
const result = [];
|
|
26876
27019
|
templates.forEach(({ content, ns, root, static: isStatic }, i) => {
|
|
26877
27020
|
let args = JSON.stringify(content).replace(IMPORT_EXPR_RE, `" + $1 + "`);
|
|
26878
|
-
|
|
26879
|
-
|
|
26880
|
-
if (isStatic || ns) args += `, ${isStatic ? "true" : "false"}`;
|
|
27021
|
+
const flags = (root ? 1 : 0) | (isStatic ? 2 : 0);
|
|
27022
|
+
if (flags || ns) args += `, ${flags}`;
|
|
26881
27023
|
if (ns) args += `, ${ns}`;
|
|
26882
27024
|
result.push(`const ${context.tName(i)} = ${context.helper("template")}(${args})\n`);
|
|
26883
27025
|
});
|
|
@@ -26895,10 +27037,13 @@ function genSelf(dynamic, context, flushBeforeDynamic) {
|
|
|
26895
27037
|
return frag;
|
|
26896
27038
|
}
|
|
26897
27039
|
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flushBeforeDynamic) {
|
|
26898
|
-
const { helper } = context;
|
|
26899
27040
|
const [frag, push] = buildCodeFragment();
|
|
26900
27041
|
const { children } = dynamic;
|
|
26901
27042
|
let offset = 0;
|
|
27043
|
+
/**
|
|
27044
|
+
* `reusable` means the previous access target is a p* cursor that can be
|
|
27045
|
+
* reassigned by the next lookup. Referenced n* variables must stay stable.
|
|
27046
|
+
*/
|
|
26902
27047
|
let prev;
|
|
26903
27048
|
for (const [index, child] of children.entries()) {
|
|
26904
27049
|
if (child.flags & 2) offset--;
|
|
@@ -26915,27 +27060,118 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flush
|
|
|
26915
27060
|
}
|
|
26916
27061
|
const elementIndex = index + offset;
|
|
26917
27062
|
const logicalIndex = child.logicalIndex !== void 0 ? String(child.logicalIndex) : void 0;
|
|
26918
|
-
const
|
|
26919
|
-
|
|
26920
|
-
if (
|
|
26921
|
-
|
|
26922
|
-
|
|
26923
|
-
|
|
26924
|
-
|
|
26925
|
-
|
|
26926
|
-
|
|
26927
|
-
|
|
27063
|
+
const inlinePlaceholder = id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6);
|
|
27064
|
+
const accessPath = genAccessPath(context, from, child, elementIndex, logicalIndex, prev);
|
|
27065
|
+
if (inlinePlaceholder) {
|
|
27066
|
+
if (prev && prev[2]) {
|
|
27067
|
+
push(...genChildren(child, context, pushBlock, [
|
|
27068
|
+
"(",
|
|
27069
|
+
prev[0],
|
|
27070
|
+
" = ",
|
|
27071
|
+
...accessPath,
|
|
27072
|
+
")"
|
|
27073
|
+
], flushBeforeDynamic));
|
|
27074
|
+
prev = [
|
|
27075
|
+
prev[0],
|
|
27076
|
+
elementIndex,
|
|
27077
|
+
true
|
|
27078
|
+
];
|
|
27079
|
+
continue;
|
|
27080
|
+
}
|
|
27081
|
+
if (!hasAdjacentFollowingAccessChild(children, index, elementIndex, offset)) {
|
|
27082
|
+
push(...genChildren(child, context, pushBlock, accessPath, flushBeforeDynamic));
|
|
27083
|
+
continue;
|
|
27084
|
+
}
|
|
27085
|
+
}
|
|
27086
|
+
let variable;
|
|
27087
|
+
if (id === void 0 && prev && prev[2]) {
|
|
27088
|
+
variable = prev[0];
|
|
27089
|
+
pushBlock(NEWLINE, `${variable} = `, ...accessPath);
|
|
27090
|
+
} else {
|
|
27091
|
+
variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
|
|
27092
|
+
pushBlock(NEWLINE, id === void 0 ? `let ${variable} = ` : `const ${variable} = `, ...accessPath);
|
|
26928
27093
|
}
|
|
26929
27094
|
if (id === child.anchor && !child.hasDynamicChild) {
|
|
26930
27095
|
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
26931
27096
|
push(...genSelf(child, context, flushBeforeDynamic));
|
|
26932
27097
|
}
|
|
26933
27098
|
if (id !== void 0) push(...genDirectivesForElement(id, context));
|
|
26934
|
-
prev = [
|
|
27099
|
+
prev = [
|
|
27100
|
+
variable,
|
|
27101
|
+
elementIndex,
|
|
27102
|
+
id === void 0
|
|
27103
|
+
];
|
|
26935
27104
|
push(...genChildren(child, context, pushBlock, variable, flushBeforeDynamic));
|
|
26936
27105
|
}
|
|
26937
27106
|
return frag;
|
|
26938
27107
|
}
|
|
27108
|
+
/**
|
|
27109
|
+
* Build one DOM lookup path while preserving the fast sibling walk:
|
|
27110
|
+
* adjacent nodes use _next(prev), otherwise fall back to _nthChild(parent).
|
|
27111
|
+
*/
|
|
27112
|
+
function genAccessPath({ helper }, from, child, elementIndex, logicalIndex, prev) {
|
|
27113
|
+
if (prev) return elementIndex - prev[1] === 1 ? genCall(helper("next"), prev[0], logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
27114
|
+
if (elementIndex === 0) return genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0);
|
|
27115
|
+
const firstChild = genCall(helper("child"), from);
|
|
27116
|
+
return elementIndex === 1 ? genCall(helper("next"), firstChild, logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
27117
|
+
}
|
|
27118
|
+
/**
|
|
27119
|
+
* Only inline a placeholder when materializing it would not save a parent
|
|
27120
|
+
* lookup. If its child tree needs the parent more than once, keep p* so the
|
|
27121
|
+
* generated code does not duplicate _child/_nthChild work.
|
|
27122
|
+
*/
|
|
27123
|
+
function canInlinePlaceholder(dynamic) {
|
|
27124
|
+
return dynamic.hasDynamicChild === true && countParentAccessUsages(dynamic) === 1;
|
|
27125
|
+
}
|
|
27126
|
+
/**
|
|
27127
|
+
* A following access can reuse the current placeholder cursor only when it is
|
|
27128
|
+
* the next DOM sibling. Gapped siblings need _nthChild(parent, index) instead.
|
|
27129
|
+
*/
|
|
27130
|
+
function hasAdjacentFollowingAccessChild(children, index, elementIndex, offset) {
|
|
27131
|
+
let futureOffset = offset;
|
|
27132
|
+
for (let i = index + 1; i < children.length; i++) {
|
|
27133
|
+
const child = children[i];
|
|
27134
|
+
if (child.flags & 2) futureOffset--;
|
|
27135
|
+
if (!(child.flags & 4 && child.template != null) && (!!(child.flags & 1) || child.hasDynamicChild)) return i + futureOffset - elementIndex === 1;
|
|
27136
|
+
}
|
|
27137
|
+
return false;
|
|
27138
|
+
}
|
|
27139
|
+
/**
|
|
27140
|
+
* Mirrors genChildren's traversal closely enough to count how many emitted
|
|
27141
|
+
* access paths would start from this placeholder's parent. This is the guard
|
|
27142
|
+
* that keeps inline placeholders from duplicating parent lookups.
|
|
27143
|
+
*/
|
|
27144
|
+
function countParentAccessUsages(dynamic) {
|
|
27145
|
+
let usages = 0;
|
|
27146
|
+
let offset = 0;
|
|
27147
|
+
let prev;
|
|
27148
|
+
for (const [index, child] of dynamic.children.entries()) {
|
|
27149
|
+
if (child.flags & 2) offset--;
|
|
27150
|
+
if (child.flags & 4 && child.template != null) continue;
|
|
27151
|
+
const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
|
|
27152
|
+
if (id === void 0 && !child.hasDynamicChild) continue;
|
|
27153
|
+
const elementIndex = index + offset;
|
|
27154
|
+
const usesParent = !prev || elementIndex - prev[0] !== 1;
|
|
27155
|
+
if (id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6)) {
|
|
27156
|
+
if (prev && prev[1]) {
|
|
27157
|
+
if (usesParent) usages++;
|
|
27158
|
+
prev = [elementIndex, true];
|
|
27159
|
+
continue;
|
|
27160
|
+
}
|
|
27161
|
+
if (!hasAdjacentFollowingAccessChild(dynamic.children, index, elementIndex, offset)) {
|
|
27162
|
+
if (usesParent) usages++;
|
|
27163
|
+
continue;
|
|
27164
|
+
}
|
|
27165
|
+
}
|
|
27166
|
+
if (usesParent) usages++;
|
|
27167
|
+
prev = [elementIndex, id === void 0];
|
|
27168
|
+
}
|
|
27169
|
+
return usages;
|
|
27170
|
+
}
|
|
27171
|
+
function genNthChild(nthChild, from, elementIndex, logicalIndex) {
|
|
27172
|
+
const index = String(elementIndex);
|
|
27173
|
+
return genCall(nthChild, from, index, logicalIndex === index ? void 0 : logicalIndex);
|
|
27174
|
+
}
|
|
26939
27175
|
//#endregion
|
|
26940
27176
|
//#region packages/compiler-vapor/src/generators/block.ts
|
|
26941
27177
|
function genBlock(oper, context, args = [], root) {
|
|
@@ -26954,8 +27190,12 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
26954
27190
|
const [frag, push] = buildCodeFragment();
|
|
26955
27191
|
const { dynamic, effect, operation, returns } = block;
|
|
26956
27192
|
const resetBlock = context.enterBlock(block);
|
|
27193
|
+
const singleUseAssetComponentNames = root ? collectSingleUseAssetComponents(block) : void 0;
|
|
27194
|
+
const prevSingleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
27195
|
+
if (singleUseAssetComponentNames) context.singleUseAssetComponentNames = singleUseAssetComponentNames;
|
|
26957
27196
|
if (root) {
|
|
26958
27197
|
for (let name of context.ir.component) {
|
|
27198
|
+
if (singleUseAssetComponentNames && singleUseAssetComponentNames.has(name)) continue;
|
|
26959
27199
|
const id = toValidAssetId(name, "component");
|
|
26960
27200
|
const maybeSelfReference = name.endsWith("__self");
|
|
26961
27201
|
if (maybeSelfReference) name = name.slice(0, -6);
|
|
@@ -26991,15 +27231,101 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
26991
27231
|
const returnNodes = returns.map((n) => `n${n}`);
|
|
26992
27232
|
push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"]);
|
|
26993
27233
|
resetBlock();
|
|
27234
|
+
context.singleUseAssetComponentNames = prevSingleUseAssetComponentNames;
|
|
26994
27235
|
return frag;
|
|
26995
27236
|
function genResolveAssets(kind, helper) {
|
|
26996
27237
|
for (const name of context.ir[kind]) push(NEWLINE, `const ${toValidAssetId(name, kind)} = `, ...genCall(context.helper(helper), JSON.stringify(name)));
|
|
26997
27238
|
}
|
|
26998
27239
|
}
|
|
27240
|
+
function collectSingleUseAssetComponents(block) {
|
|
27241
|
+
const usageMap = /* @__PURE__ */ new Map();
|
|
27242
|
+
const seenOperations = /* @__PURE__ */ new Set();
|
|
27243
|
+
visitBlock(block, true);
|
|
27244
|
+
const names = /* @__PURE__ */ new Set();
|
|
27245
|
+
for (const [name, usage] of usageMap) if (usage.count === 1 && usage.root) names.add(name);
|
|
27246
|
+
return names;
|
|
27247
|
+
function visitBlock(block, rootCandidate) {
|
|
27248
|
+
visitDynamic(block.dynamic, rootCandidate);
|
|
27249
|
+
for (const operation of block.operation) visitOperation(operation, rootCandidate);
|
|
27250
|
+
for (const effect of block.effect) for (const operation of effect.operations) visitOperation(operation, false);
|
|
27251
|
+
}
|
|
27252
|
+
function visitDynamic(dynamic, rootCandidate) {
|
|
27253
|
+
if (dynamic.operation) visitOperation(dynamic.operation, rootCandidate);
|
|
27254
|
+
for (const child of dynamic.children) visitDynamic(child, rootCandidate);
|
|
27255
|
+
}
|
|
27256
|
+
function visitOperation(operation, rootCandidate) {
|
|
27257
|
+
if (seenOperations.has(operation)) return;
|
|
27258
|
+
seenOperations.add(operation);
|
|
27259
|
+
if (operation.type === 12) {
|
|
27260
|
+
if (operation.asset) {
|
|
27261
|
+
const usage = usageMap.get(operation.tag) || {
|
|
27262
|
+
count: 0,
|
|
27263
|
+
root: false
|
|
27264
|
+
};
|
|
27265
|
+
usage.count++;
|
|
27266
|
+
if (rootCandidate) usage.root = true;
|
|
27267
|
+
usageMap.set(operation.tag, usage);
|
|
27268
|
+
}
|
|
27269
|
+
visitSlots(operation.slots);
|
|
27270
|
+
return;
|
|
27271
|
+
}
|
|
27272
|
+
switch (operation.type) {
|
|
27273
|
+
case 15:
|
|
27274
|
+
visitBlock(operation.positive, false);
|
|
27275
|
+
if (operation.negative) if (operation.negative.type === 15) visitOperation(operation.negative, false);
|
|
27276
|
+
else visitBlock(operation.negative, false);
|
|
27277
|
+
break;
|
|
27278
|
+
case 16:
|
|
27279
|
+
visitBlock(operation.render, false);
|
|
27280
|
+
break;
|
|
27281
|
+
case 17:
|
|
27282
|
+
visitBlock(operation.block, false);
|
|
27283
|
+
break;
|
|
27284
|
+
case 13:
|
|
27285
|
+
if (operation.fallback) visitBlock(operation.fallback, false);
|
|
27286
|
+
break;
|
|
27287
|
+
}
|
|
27288
|
+
}
|
|
27289
|
+
function visitSlots(slots) {
|
|
27290
|
+
for (const slot of slots) switch (slot.slotType) {
|
|
27291
|
+
case 0:
|
|
27292
|
+
for (const name in slot.slots) visitBlock(slot.slots[name], false);
|
|
27293
|
+
break;
|
|
27294
|
+
case 1:
|
|
27295
|
+
case 2:
|
|
27296
|
+
visitBlock(slot.fn, false);
|
|
27297
|
+
break;
|
|
27298
|
+
case 3:
|
|
27299
|
+
visitSlots([slot.positive]);
|
|
27300
|
+
if (slot.negative) visitSlots([slot.negative]);
|
|
27301
|
+
break;
|
|
27302
|
+
}
|
|
27303
|
+
}
|
|
27304
|
+
}
|
|
26999
27305
|
//#endregion
|
|
27000
27306
|
//#region packages/compiler-vapor/src/generate.ts
|
|
27001
27307
|
const idWithTrailingDigitsRE = /^([A-Za-z_$][\w$]*)(\d+)$/;
|
|
27308
|
+
const helperNameAliases = {
|
|
27309
|
+
withVaporKeys: "withKeys",
|
|
27310
|
+
withVaporModifiers: "withModifiers"
|
|
27311
|
+
};
|
|
27002
27312
|
var CodegenContext = class {
|
|
27313
|
+
withExpressionReplacements(map, fn) {
|
|
27314
|
+
if (map.size === 0) return fn();
|
|
27315
|
+
this.expressionReplacements.unshift(map);
|
|
27316
|
+
try {
|
|
27317
|
+
return fn();
|
|
27318
|
+
} finally {
|
|
27319
|
+
remove(this.expressionReplacements, map);
|
|
27320
|
+
}
|
|
27321
|
+
}
|
|
27322
|
+
getExpressionReplacement(node) {
|
|
27323
|
+
for (const map of this.expressionReplacements) {
|
|
27324
|
+
const replacement = map.get(node);
|
|
27325
|
+
if (replacement) return replacement;
|
|
27326
|
+
}
|
|
27327
|
+
return node;
|
|
27328
|
+
}
|
|
27003
27329
|
withId(fn, map) {
|
|
27004
27330
|
const { identifiers } = this;
|
|
27005
27331
|
const ids = Object.keys(map);
|
|
@@ -27016,9 +27342,19 @@ var CodegenContext = class {
|
|
|
27016
27342
|
this.block = block;
|
|
27017
27343
|
return () => this.block = parent;
|
|
27018
27344
|
}
|
|
27345
|
+
enterSlotBlock() {
|
|
27346
|
+
const parent = this.inSlotBlock;
|
|
27347
|
+
this.inSlotBlock = true;
|
|
27348
|
+
return () => this.inSlotBlock = parent;
|
|
27349
|
+
}
|
|
27019
27350
|
enterScope() {
|
|
27020
27351
|
return [this.scopeLevel++, () => this.scopeLevel--];
|
|
27021
27352
|
}
|
|
27353
|
+
isHelperNameAvailable(name) {
|
|
27354
|
+
if (this.bindingNames.has(name)) return false;
|
|
27355
|
+
for (const alias of this.helpers.values()) if (alias === name) return false;
|
|
27356
|
+
return true;
|
|
27357
|
+
}
|
|
27022
27358
|
initNextIdMap() {
|
|
27023
27359
|
if (this.bindingNames.size === 0) return;
|
|
27024
27360
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -27053,19 +27389,29 @@ var CodegenContext = class {
|
|
|
27053
27389
|
this.ir = ir;
|
|
27054
27390
|
this.bindingNames = /* @__PURE__ */ new Set();
|
|
27055
27391
|
this.helpers = /* @__PURE__ */ new Map();
|
|
27392
|
+
this.needsTemplateRefSetter = false;
|
|
27393
|
+
this.inSlotBlock = false;
|
|
27056
27394
|
this.helper = (name) => {
|
|
27057
27395
|
if (this.helpers.has(name)) return this.helpers.get(name);
|
|
27058
|
-
const base = `_${name}`;
|
|
27059
|
-
if (this.
|
|
27396
|
+
const base = `_${helperNameAliases[name] || name}`;
|
|
27397
|
+
if (this.isHelperNameAvailable(base)) {
|
|
27060
27398
|
this.helpers.set(name, base);
|
|
27061
27399
|
return base;
|
|
27062
27400
|
}
|
|
27063
|
-
const
|
|
27064
|
-
|
|
27065
|
-
|
|
27401
|
+
const map = this.nextIdMap.get(base);
|
|
27402
|
+
let next = 1;
|
|
27403
|
+
while (true) {
|
|
27404
|
+
const alias = `${base}${getNextId(map, next)}`;
|
|
27405
|
+
if (this.isHelperNameAvailable(alias)) {
|
|
27406
|
+
this.helpers.set(name, alias);
|
|
27407
|
+
return alias;
|
|
27408
|
+
}
|
|
27409
|
+
next++;
|
|
27410
|
+
}
|
|
27066
27411
|
};
|
|
27067
27412
|
this.delegates = /* @__PURE__ */ new Set();
|
|
27068
27413
|
this.identifiers = Object.create(null);
|
|
27414
|
+
this.expressionReplacements = [];
|
|
27069
27415
|
this.seenInlineHandlerNames = Object.create(null);
|
|
27070
27416
|
this.scopeLevel = 0;
|
|
27071
27417
|
this.templateVars = /* @__PURE__ */ new Map();
|
|
@@ -27092,6 +27438,7 @@ var CodegenContext = class {
|
|
|
27092
27438
|
this.block = ir.block;
|
|
27093
27439
|
this.bindingNames = new Set(this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []);
|
|
27094
27440
|
this.initNextIdMap();
|
|
27441
|
+
this.staticTemplateRefHelperCandidate = getStaticTemplateRefHelperCandidate(ir.block);
|
|
27095
27442
|
}
|
|
27096
27443
|
};
|
|
27097
27444
|
function generate(ir, options = {}) {
|
|
@@ -27104,8 +27451,11 @@ function generate(ir, options = {}) {
|
|
|
27104
27451
|
const signature = (options.isTS ? args.map((arg) => `${arg}: any`) : args).join(", ");
|
|
27105
27452
|
if (!inline) push(NEWLINE, `export function ${functionName}(${signature}) {`);
|
|
27106
27453
|
push(INDENT_START);
|
|
27107
|
-
|
|
27108
|
-
|
|
27454
|
+
const templateRefSetterHelper = ir.hasTemplateRef ? context.helper("createTemplateRefSetter") : void 0;
|
|
27455
|
+
const body = genBlockContent(ir.block, context, true);
|
|
27456
|
+
if (context.needsTemplateRefSetter) push(NEWLINE, `const ${setTemplateRefIdent} = ${templateRefSetterHelper}()`);
|
|
27457
|
+
else if (templateRefSetterHelper) context.helpers.delete("createTemplateRefSetter");
|
|
27458
|
+
push(...body);
|
|
27109
27459
|
push(INDENT_END, NEWLINE);
|
|
27110
27460
|
if (!inline) push("}");
|
|
27111
27461
|
const delegates = genDelegates(context);
|
|
@@ -27140,6 +27490,11 @@ function genAssetImports({ ir }) {
|
|
|
27140
27490
|
}
|
|
27141
27491
|
return imports;
|
|
27142
27492
|
}
|
|
27493
|
+
function getStaticTemplateRefHelperCandidate(block) {
|
|
27494
|
+
if (block.operation.length !== 1) return;
|
|
27495
|
+
const operation = block.operation[0];
|
|
27496
|
+
if (operation.type === 9 && !operation.effect && !operation.refFor && operation.value.isStatic) return operation;
|
|
27497
|
+
}
|
|
27143
27498
|
//#endregion
|
|
27144
27499
|
//#region packages/compiler-vapor/src/transforms/vBind.ts
|
|
27145
27500
|
function normalizeBindShorthand(arg, context) {
|
|
@@ -27306,6 +27661,7 @@ function resolveSetupReference(name, context) {
|
|
|
27306
27661
|
}
|
|
27307
27662
|
const dynamicKeys = ["indeterminate"];
|
|
27308
27663
|
const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
|
|
27664
|
+
const UNSAFE_ATTR_NAME_RE = /[\u0000-\u0020"'<=/>]/;
|
|
27309
27665
|
function transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, omitEndTag) {
|
|
27310
27666
|
const { tag } = node;
|
|
27311
27667
|
const { scopeId } = context.options;
|
|
@@ -27323,18 +27679,55 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
27323
27679
|
}, getEffectIndex);
|
|
27324
27680
|
} else {
|
|
27325
27681
|
let prevWasQuoted = false;
|
|
27682
|
+
const appendTemplateProp = (key, value = "", generated = false) => {
|
|
27683
|
+
if (!prevWasQuoted) template += ` `;
|
|
27684
|
+
template += key;
|
|
27685
|
+
if (value) {
|
|
27686
|
+
const escapedValue = generated ? escapeGeneratedAttrValue(value) : value.replace(/"/g, """);
|
|
27687
|
+
template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${escapedValue}"` : `=${escapedValue}`;
|
|
27688
|
+
} else prevWasQuoted = false;
|
|
27689
|
+
};
|
|
27326
27690
|
for (const prop of propsResult[1]) {
|
|
27327
27691
|
const { key, values } = prop;
|
|
27328
27692
|
if (context.imports.some((imported) => values[0].content.includes(imported.exp.content))) {
|
|
27329
27693
|
if (!prevWasQuoted) template += ` `;
|
|
27330
27694
|
template += `${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
|
|
27331
27695
|
prevWasQuoted = true;
|
|
27696
|
+
} else if (key.isStatic && !prop.modifier && isBooleanAttr(key.content)) if (values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
27697
|
+
const value = values[0].content === "''" ? "" : values[0].content;
|
|
27698
|
+
appendTemplateProp(key.content, value);
|
|
27699
|
+
} else {
|
|
27700
|
+
const include = foldBooleanAttrValue(values);
|
|
27701
|
+
if (include != null) {
|
|
27702
|
+
if (include) appendTemplateProp(key.content);
|
|
27703
|
+
} else {
|
|
27704
|
+
dynamicProps.push(key.content);
|
|
27705
|
+
context.registerEffect(values, {
|
|
27706
|
+
type: 3,
|
|
27707
|
+
element: context.reference(),
|
|
27708
|
+
prop,
|
|
27709
|
+
tag
|
|
27710
|
+
}, getEffectIndex);
|
|
27711
|
+
}
|
|
27712
|
+
}
|
|
27713
|
+
else if (key.isStatic && !prop.modifier && hasBoundValue(values)) {
|
|
27714
|
+
let foldedValue;
|
|
27715
|
+
if (key.content === "class") foldedValue = foldClassValues(values);
|
|
27716
|
+
else if (key.content === "style") foldedValue = foldStyleValues(values);
|
|
27717
|
+
if (foldedValue != null) {
|
|
27718
|
+
if (foldedValue) appendTemplateProp(key.content, foldedValue, true);
|
|
27719
|
+
} else {
|
|
27720
|
+
dynamicProps.push(key.content);
|
|
27721
|
+
context.registerEffect(values, {
|
|
27722
|
+
type: 3,
|
|
27723
|
+
element: context.reference(),
|
|
27724
|
+
prop,
|
|
27725
|
+
tag
|
|
27726
|
+
}, getEffectIndex);
|
|
27727
|
+
}
|
|
27332
27728
|
} else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
27333
|
-
if (!prevWasQuoted) template += ` `;
|
|
27334
27729
|
const value = values[0].content === "''" ? "" : values[0].content;
|
|
27335
|
-
|
|
27336
|
-
if (value) template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${value.replace(/"/g, """)}"` : `=${value}`;
|
|
27337
|
-
else prevWasQuoted = false;
|
|
27730
|
+
appendTemplateProp(key.content, value);
|
|
27338
27731
|
} else {
|
|
27339
27732
|
dynamicProps.push(key.content);
|
|
27340
27733
|
context.registerEffect(values, {
|
|
@@ -27356,6 +27749,123 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
27356
27749
|
} else context.template += template;
|
|
27357
27750
|
if (staticKey) context.registerOperation(createSetBlockKey(context.reference(), staticKey));
|
|
27358
27751
|
}
|
|
27752
|
+
function escapeGeneratedAttrValue(value) {
|
|
27753
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
27754
|
+
}
|
|
27755
|
+
function foldBooleanAttrValue(values) {
|
|
27756
|
+
if (values.length !== 1) return;
|
|
27757
|
+
const evaluated = evaluateConstantExpression(values[0]);
|
|
27758
|
+
if (!evaluated) return;
|
|
27759
|
+
const value = evaluated.value;
|
|
27760
|
+
if (value === true || value === false || value == null) return includeBooleanAttr(value);
|
|
27761
|
+
}
|
|
27762
|
+
function foldStyleValues(values) {
|
|
27763
|
+
const evaluatedValues = [];
|
|
27764
|
+
for (const value of values) {
|
|
27765
|
+
const evaluated = evaluateConstantExpression(value);
|
|
27766
|
+
if (!evaluated || !isStaticStyleValue(evaluated.value)) return;
|
|
27767
|
+
evaluatedValues.push(evaluated.value);
|
|
27768
|
+
}
|
|
27769
|
+
return stringifyStyle(normalizeStyle(evaluatedValues.length === 1 ? evaluatedValues[0] : evaluatedValues));
|
|
27770
|
+
}
|
|
27771
|
+
function isStaticStyleValue(value) {
|
|
27772
|
+
if (typeof value === "string") return true;
|
|
27773
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
27774
|
+
for (const key in value) {
|
|
27775
|
+
const propValue = value[key];
|
|
27776
|
+
if (!isSafeStylePropertyName(key) || !isSafeStylePropertyValue(propValue)) return false;
|
|
27777
|
+
}
|
|
27778
|
+
return true;
|
|
27779
|
+
}
|
|
27780
|
+
function isSafeStylePropertyName(key) {
|
|
27781
|
+
return !!key && !/[;:]/.test(key);
|
|
27782
|
+
}
|
|
27783
|
+
function isSafeStylePropertyValue(value) {
|
|
27784
|
+
return typeof value === "number" || typeof value === "string" && !value.includes(";");
|
|
27785
|
+
}
|
|
27786
|
+
function hasBoundValue(values) {
|
|
27787
|
+
return values.some((value) => !value.isStatic && value.content !== "''");
|
|
27788
|
+
}
|
|
27789
|
+
function foldClassValues(values) {
|
|
27790
|
+
let templateValue = "";
|
|
27791
|
+
let changed = false;
|
|
27792
|
+
for (const value of values) {
|
|
27793
|
+
const evaluated = evaluateConstantExpression(value);
|
|
27794
|
+
if (evaluated) {
|
|
27795
|
+
const normalized = normalizeClass(evaluated.value);
|
|
27796
|
+
if (normalized) templateValue = appendClass(templateValue, normalized);
|
|
27797
|
+
else changed = true;
|
|
27798
|
+
continue;
|
|
27799
|
+
}
|
|
27800
|
+
return;
|
|
27801
|
+
}
|
|
27802
|
+
return changed || templateValue ? templateValue : void 0;
|
|
27803
|
+
}
|
|
27804
|
+
function appendClass(base, value) {
|
|
27805
|
+
return base ? value ? `${base} ${value}` : base : value;
|
|
27806
|
+
}
|
|
27807
|
+
function getObjectPropertyName(prop) {
|
|
27808
|
+
const key = prop.key;
|
|
27809
|
+
if (key.type === "Identifier") return key.name;
|
|
27810
|
+
else if (key.type === "StringLiteral") return key.value;
|
|
27811
|
+
else if (key.type === "NumericLiteral") return String(key.value);
|
|
27812
|
+
}
|
|
27813
|
+
function evaluateConstantExpression(node) {
|
|
27814
|
+
if (node.isStatic) return { value: node.content };
|
|
27815
|
+
const ast = node.ast;
|
|
27816
|
+
if (ast === null) {
|
|
27817
|
+
if (node.content === "true") return { value: true };
|
|
27818
|
+
else if (node.content === "false") return { value: false };
|
|
27819
|
+
else if (node.content === "null") return { value: null };
|
|
27820
|
+
else if (node.content === "undefined") return { value: void 0 };
|
|
27821
|
+
}
|
|
27822
|
+
if (!ast) return;
|
|
27823
|
+
return evaluateConstantAst(ast);
|
|
27824
|
+
}
|
|
27825
|
+
function evaluateConstantAst(node) {
|
|
27826
|
+
switch (node.type) {
|
|
27827
|
+
case "StringLiteral": return { value: node.value };
|
|
27828
|
+
case "NumericLiteral": return { value: node.value };
|
|
27829
|
+
case "BooleanLiteral": return { value: node.value };
|
|
27830
|
+
case "NullLiteral": return { value: null };
|
|
27831
|
+
case "Identifier": return node.name === "undefined" ? { value: void 0 } : void 0;
|
|
27832
|
+
case "UnaryExpression":
|
|
27833
|
+
if (node.operator === "void") return { value: void 0 };
|
|
27834
|
+
else if (node.operator === "-") {
|
|
27835
|
+
const value = evaluateConstantAst(node.argument);
|
|
27836
|
+
return value && typeof value.value === "number" ? { value: -value.value } : void 0;
|
|
27837
|
+
}
|
|
27838
|
+
return;
|
|
27839
|
+
case "TemplateLiteral": return evaluateTemplateLiteral(node);
|
|
27840
|
+
case "ObjectExpression": return evaluateObjectExpression(node);
|
|
27841
|
+
}
|
|
27842
|
+
}
|
|
27843
|
+
function evaluateTemplateLiteral(node) {
|
|
27844
|
+
if (node.type !== "TemplateLiteral") return;
|
|
27845
|
+
let value = "";
|
|
27846
|
+
for (const [index, quasi] of node.quasis.entries()) {
|
|
27847
|
+
value += quasi.value.cooked || "";
|
|
27848
|
+
const expression = node.expressions[index];
|
|
27849
|
+
if (expression) {
|
|
27850
|
+
const evaluated = evaluateConstantAst(expression);
|
|
27851
|
+
if (!evaluated) return;
|
|
27852
|
+
value += evaluated.value;
|
|
27853
|
+
}
|
|
27854
|
+
}
|
|
27855
|
+
return { value };
|
|
27856
|
+
}
|
|
27857
|
+
function evaluateObjectExpression(node) {
|
|
27858
|
+
const value = {};
|
|
27859
|
+
for (const prop of node.properties) {
|
|
27860
|
+
if (prop.type !== "ObjectProperty" || prop.computed) return;
|
|
27861
|
+
const key = getObjectPropertyName(prop);
|
|
27862
|
+
if (key == null) return;
|
|
27863
|
+
const evaluated = evaluateConstantAst(prop.value);
|
|
27864
|
+
if (!evaluated) return;
|
|
27865
|
+
value[key] = evaluated.value;
|
|
27866
|
+
}
|
|
27867
|
+
return { value };
|
|
27868
|
+
}
|
|
27359
27869
|
function resolveStaticKey(node, context, isComponent) {
|
|
27360
27870
|
const keyProp = findProp(node, "key", false, true);
|
|
27361
27871
|
if (!keyProp) return;
|
|
@@ -27382,27 +27892,42 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
27382
27892
|
results = [];
|
|
27383
27893
|
}
|
|
27384
27894
|
}
|
|
27895
|
+
function pushStaticObjectLiteralProps(props) {
|
|
27896
|
+
if (dynamicArgs.length) {
|
|
27897
|
+
pushMergeArg();
|
|
27898
|
+
dynamicArgs.push(props);
|
|
27899
|
+
} else results.push(...props.map(toDirectiveResult));
|
|
27900
|
+
}
|
|
27385
27901
|
for (const prop of props) {
|
|
27386
27902
|
if (prop.type === 7 && !prop.arg) {
|
|
27387
27903
|
if (prop.name === "bind") {
|
|
27388
27904
|
if (prop.exp) {
|
|
27389
|
-
|
|
27390
|
-
|
|
27391
|
-
|
|
27392
|
-
|
|
27393
|
-
|
|
27394
|
-
|
|
27905
|
+
const objectLiteralProps = isComponent ? resolveComponentObjectLiteralBindProps(prop.exp, context, props, prop) : resolveNativeObjectLiteralBindProps(prop.exp, context, props, prop);
|
|
27906
|
+
if (objectLiteralProps) if (isComponent) pushStaticObjectLiteralProps(objectLiteralProps);
|
|
27907
|
+
else results.push(...objectLiteralProps.map(toDirectiveResult));
|
|
27908
|
+
else {
|
|
27909
|
+
dynamicExpr.push(prop.exp);
|
|
27910
|
+
pushMergeArg();
|
|
27911
|
+
dynamicArgs.push({
|
|
27912
|
+
kind: 0,
|
|
27913
|
+
value: prop.exp
|
|
27914
|
+
});
|
|
27915
|
+
}
|
|
27395
27916
|
} else context.options.onError(createCompilerError(34, prop.loc));
|
|
27396
27917
|
continue;
|
|
27397
27918
|
} else if (prop.name === "on") {
|
|
27398
27919
|
if (prop.exp) if (isComponent) {
|
|
27399
|
-
|
|
27400
|
-
|
|
27401
|
-
|
|
27402
|
-
|
|
27403
|
-
|
|
27404
|
-
|
|
27405
|
-
|
|
27920
|
+
const objectLiteralProps = resolveComponentObjectLiteralOnProps(prop.exp, context, props, prop);
|
|
27921
|
+
if (objectLiteralProps) pushStaticObjectLiteralProps(objectLiteralProps);
|
|
27922
|
+
else {
|
|
27923
|
+
dynamicExpr.push(prop.exp);
|
|
27924
|
+
pushMergeArg();
|
|
27925
|
+
dynamicArgs.push({
|
|
27926
|
+
kind: 0,
|
|
27927
|
+
value: prop.exp,
|
|
27928
|
+
handler: true
|
|
27929
|
+
});
|
|
27930
|
+
}
|
|
27406
27931
|
} else context.registerEffect([prop.exp], {
|
|
27407
27932
|
type: 7,
|
|
27408
27933
|
element: context.reference(),
|
|
@@ -27432,6 +27957,151 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
27432
27957
|
}
|
|
27433
27958
|
return [false, dedupeProperties(results)];
|
|
27434
27959
|
}
|
|
27960
|
+
function resolveObjectLiteralProps(exp, context, keyTransform, isValidKey) {
|
|
27961
|
+
const ast = exp.ast;
|
|
27962
|
+
if (!ast || ast.type !== "ObjectExpression") return;
|
|
27963
|
+
const props = [];
|
|
27964
|
+
const knownKeys = /* @__PURE__ */ new Set();
|
|
27965
|
+
for (const property of ast.properties) {
|
|
27966
|
+
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
27967
|
+
let key = getObjectPropertyName(property);
|
|
27968
|
+
if (key == null || key === "__proto__") return;
|
|
27969
|
+
if (isValidKey && !isValidKey(key)) return;
|
|
27970
|
+
if (keyTransform) key = keyTransform(key);
|
|
27971
|
+
if (knownKeys.has(key)) return;
|
|
27972
|
+
knownKeys.add(key);
|
|
27973
|
+
props.push({
|
|
27974
|
+
key: createSimpleExpression(key, true),
|
|
27975
|
+
values: [resolveExpression(createObjectBindSubExpression(exp, property.value, context), true)]
|
|
27976
|
+
});
|
|
27977
|
+
}
|
|
27978
|
+
return props;
|
|
27979
|
+
}
|
|
27980
|
+
function resolveComponentObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
27981
|
+
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeObjectLiteralBindKey);
|
|
27982
|
+
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
27983
|
+
return props;
|
|
27984
|
+
}
|
|
27985
|
+
function resolveNativeObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
27986
|
+
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeNativeObjectLiteralBindKey);
|
|
27987
|
+
if (!props || hasNativeObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
27988
|
+
return props;
|
|
27989
|
+
}
|
|
27990
|
+
function resolveComponentObjectLiteralOnProps(exp, context, nodeProps, currentProp) {
|
|
27991
|
+
const props = resolveObjectLiteralProps(exp, context, toHandlerKey);
|
|
27992
|
+
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
27993
|
+
return props;
|
|
27994
|
+
}
|
|
27995
|
+
function isSafeNativeObjectLiteralBindKey(key) {
|
|
27996
|
+
return key !== "" && !UNSAFE_ATTR_NAME_RE.test(key) && isSafeObjectLiteralBindKey(key) && !isOn(key) && key.charCodeAt(0) !== 46 && key.charCodeAt(0) !== 94;
|
|
27997
|
+
}
|
|
27998
|
+
function isSafeObjectLiteralBindKey(key) {
|
|
27999
|
+
return !isReservedProp(key);
|
|
28000
|
+
}
|
|
28001
|
+
function hasComponentObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
28002
|
+
const keys = createComponentConflictKeySet(objectLiteralProps.map((prop) => prop.key.content));
|
|
28003
|
+
for (const prop of props) {
|
|
28004
|
+
if (prop === currentProp) continue;
|
|
28005
|
+
let key;
|
|
28006
|
+
if (prop.type === 6) key = prop.name;
|
|
28007
|
+
else if (prop.name === "bind") {
|
|
28008
|
+
if (!prop.arg) {
|
|
28009
|
+
const bindKeys = getObjectLiteralKeys(prop.exp);
|
|
28010
|
+
if (bindKeys && hasComponentKeyOverlap(keys, bindKeys)) return true;
|
|
28011
|
+
continue;
|
|
28012
|
+
}
|
|
28013
|
+
key = getStaticBindKey(prop);
|
|
28014
|
+
} else if (prop.name === "on") key = getStaticHandlerKey(prop);
|
|
28015
|
+
else if (prop.name === "model") {
|
|
28016
|
+
if (hasComponentModelKey(keys, prop)) return true;
|
|
28017
|
+
}
|
|
28018
|
+
if (key && hasComponentKey(keys, key)) return true;
|
|
28019
|
+
}
|
|
28020
|
+
return false;
|
|
28021
|
+
}
|
|
28022
|
+
function hasComponentModelKey(keys, prop) {
|
|
28023
|
+
const { arg } = prop;
|
|
28024
|
+
if (arg && (arg.type !== 4 || !arg.isStatic)) return true;
|
|
28025
|
+
const key = arg ? arg.content : "modelValue";
|
|
28026
|
+
return hasComponentKey(keys, key) || hasComponentKey(keys, `onUpdate:${camelize(key)}`) || prop.modifiers.length > 0 && hasComponentKey(keys, getModifierPropName(key));
|
|
28027
|
+
}
|
|
28028
|
+
function hasNativeObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
28029
|
+
const keys = new Set(objectLiteralProps.map((prop) => prop.key.content));
|
|
28030
|
+
for (const prop of props) {
|
|
28031
|
+
if (prop === currentProp) continue;
|
|
28032
|
+
let key;
|
|
28033
|
+
if (prop.type === 6) key = prop.name;
|
|
28034
|
+
else if (prop.name === "bind") {
|
|
28035
|
+
if (!prop.arg) return true;
|
|
28036
|
+
key = getStaticBindKey(prop);
|
|
28037
|
+
if (!key) return true;
|
|
28038
|
+
}
|
|
28039
|
+
if (key && keys.has(key)) return true;
|
|
28040
|
+
}
|
|
28041
|
+
return false;
|
|
28042
|
+
}
|
|
28043
|
+
function getStaticBindKey(prop) {
|
|
28044
|
+
const { arg } = prop;
|
|
28045
|
+
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
28046
|
+
let key = arg.content;
|
|
28047
|
+
if (isReservedProp(key)) return;
|
|
28048
|
+
if (prop.modifiers.some((modifier) => modifier.content === "camel")) key = camelize(key);
|
|
28049
|
+
return key;
|
|
28050
|
+
}
|
|
28051
|
+
function getStaticHandlerKey(prop) {
|
|
28052
|
+
const { arg } = prop;
|
|
28053
|
+
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
28054
|
+
let key = arg.content;
|
|
28055
|
+
if (key.startsWith("vue:")) key = `vnode-${key.slice(4)}`;
|
|
28056
|
+
const { nonKeyModifiers, eventOptionModifiers } = resolveModifiers(`on${key}`, prop.modifiers, null, prop.loc);
|
|
28057
|
+
if (key.toLowerCase() === "click") {
|
|
28058
|
+
if (nonKeyModifiers.includes("middle")) key = "mouseup";
|
|
28059
|
+
if (nonKeyModifiers.includes("right")) key = "contextmenu";
|
|
28060
|
+
}
|
|
28061
|
+
key = toHandlerKey(camelize(key));
|
|
28062
|
+
const optionPostfix = eventOptionModifiers.map(capitalize).join("");
|
|
28063
|
+
if (optionPostfix) key += optionPostfix;
|
|
28064
|
+
return key;
|
|
28065
|
+
}
|
|
28066
|
+
function getObjectLiteralKeys(exp) {
|
|
28067
|
+
const ast = exp && exp.ast;
|
|
28068
|
+
if (!ast || ast.type !== "ObjectExpression") return;
|
|
28069
|
+
const keys = /* @__PURE__ */ new Set();
|
|
28070
|
+
for (const property of ast.properties) {
|
|
28071
|
+
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
28072
|
+
const key = getObjectPropertyName(property);
|
|
28073
|
+
if (key == null) return;
|
|
28074
|
+
keys.add(key);
|
|
28075
|
+
}
|
|
28076
|
+
return keys;
|
|
28077
|
+
}
|
|
28078
|
+
function createComponentConflictKeySet(keys) {
|
|
28079
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
28080
|
+
for (const key of keys) {
|
|
28081
|
+
normalized.add(key);
|
|
28082
|
+
normalized.add(camelize(key));
|
|
28083
|
+
}
|
|
28084
|
+
return normalized;
|
|
28085
|
+
}
|
|
28086
|
+
function hasComponentKey(keys, key) {
|
|
28087
|
+
return keys.has(key) || keys.has(camelize(key));
|
|
28088
|
+
}
|
|
28089
|
+
function hasComponentKeyOverlap(left, right) {
|
|
28090
|
+
for (const key of right) if (hasComponentKey(left, key)) return true;
|
|
28091
|
+
return false;
|
|
28092
|
+
}
|
|
28093
|
+
function createObjectBindSubExpression(source, node, context) {
|
|
28094
|
+
const start = node.start == null ? 0 : node.start - 1;
|
|
28095
|
+
const end = node.end == null ? source.content.length : node.end - 1;
|
|
28096
|
+
const content = source.content.slice(start, end);
|
|
28097
|
+
const expression = createSimpleExpression(content, false, {
|
|
28098
|
+
start: advancePositionWithClone(source.loc.start, source.content, start),
|
|
28099
|
+
end: advancePositionWithClone(source.loc.start, source.content, end),
|
|
28100
|
+
source: content
|
|
28101
|
+
});
|
|
28102
|
+
expression.ast = isSimpleIdentifier(content) ? null : (0, import_lib.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
28103
|
+
return expression;
|
|
28104
|
+
}
|
|
27435
28105
|
function transformProp(prop, node, context) {
|
|
27436
28106
|
let { name } = prop;
|
|
27437
28107
|
if (prop.type === 6) {
|
|
@@ -27482,6 +28152,12 @@ function resolveDirectiveResult(prop) {
|
|
|
27482
28152
|
values: [prop.value]
|
|
27483
28153
|
});
|
|
27484
28154
|
}
|
|
28155
|
+
function toDirectiveResult(prop) {
|
|
28156
|
+
return extend({}, prop, {
|
|
28157
|
+
values: void 0,
|
|
28158
|
+
value: prop.values[0]
|
|
28159
|
+
});
|
|
28160
|
+
}
|
|
27485
28161
|
function mergePropValues(existing, incoming) {
|
|
27486
28162
|
const newValues = incoming.values;
|
|
27487
28163
|
existing.values.push(...newValues);
|
|
@@ -27996,6 +28672,7 @@ function processIf(node, dir, context) {
|
|
|
27996
28672
|
}
|
|
27997
28673
|
context.dynamic.flags |= 2;
|
|
27998
28674
|
const forceMultiRoot = shouldForceMultiRoot(context);
|
|
28675
|
+
const allowNoScope = context.block === context.root.block;
|
|
27999
28676
|
if (dir.name === "if") {
|
|
28000
28677
|
const id = context.reference();
|
|
28001
28678
|
context.dynamic.flags |= 4;
|
|
@@ -28006,7 +28683,7 @@ function processIf(node, dir, context) {
|
|
|
28006
28683
|
type: 15,
|
|
28007
28684
|
id
|
|
28008
28685
|
}, context.effectBoundary()), {}, {
|
|
28009
|
-
blockShape: encodeIfBlockShape(branch, forceMultiRoot),
|
|
28686
|
+
blockShape: encodeIfBlockShape(branch, forceMultiRoot, void 0, allowNoScope),
|
|
28010
28687
|
condition: dir.exp,
|
|
28011
28688
|
positive: branch,
|
|
28012
28689
|
index: context.root.nextIfIndex(),
|
|
@@ -28048,8 +28725,8 @@ function processIf(node, dir, context) {
|
|
|
28048
28725
|
};
|
|
28049
28726
|
return () => {
|
|
28050
28727
|
onExit();
|
|
28051
|
-
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot);
|
|
28052
|
-
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative);
|
|
28728
|
+
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot, void 0, allowNoScope);
|
|
28729
|
+
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative, allowNoScope);
|
|
28053
28730
|
};
|
|
28054
28731
|
}
|
|
28055
28732
|
}
|
|
@@ -28064,14 +28741,38 @@ function createIfBranch(node, context) {
|
|
|
28064
28741
|
context.reference();
|
|
28065
28742
|
return [branch, exitBlock];
|
|
28066
28743
|
}
|
|
28067
|
-
function encodeIfBlockShape(positive, forceMultiRoot = false, negative) {
|
|
28744
|
+
function encodeIfBlockShape(positive, forceMultiRoot = false, negative, allowNoScope = true) {
|
|
28068
28745
|
if (forceMultiRoot) return 10;
|
|
28069
|
-
|
|
28746
|
+
const positiveNoScope = allowNoScope && canSkipIfBranchScope(positive);
|
|
28747
|
+
const negativeNoScope = allowNoScope && negative && negative.type !== 15 && canSkipIfBranchScope(negative);
|
|
28748
|
+
return getBlockShape(positive) | getNegativeIfBranchShape(negative) << 2 | (positiveNoScope ? 32 : 0) | (negativeNoScope ? 64 : 0);
|
|
28070
28749
|
}
|
|
28071
|
-
function
|
|
28750
|
+
function getNegativeIfBranchShape(negative) {
|
|
28072
28751
|
if (!negative) return 0;
|
|
28073
28752
|
return negative.type === 15 ? 1 : getBlockShape(negative);
|
|
28074
28753
|
}
|
|
28754
|
+
function canSkipIfBranchScope(block) {
|
|
28755
|
+
if (block.effect.length || block.operation.length) return false;
|
|
28756
|
+
if (!isStaticBranch(block.node)) return false;
|
|
28757
|
+
if (block.returns.length === 0 || block.dynamic.children.length !== block.returns.length) return false;
|
|
28758
|
+
return block.returns.every((id) => {
|
|
28759
|
+
const returned = findReturnedDynamic(block, id);
|
|
28760
|
+
return !!(returned && returned.template != null && !returned.operation && !returned.hasDynamicChild && !(returned.flags & 6));
|
|
28761
|
+
});
|
|
28762
|
+
}
|
|
28763
|
+
function findReturnedDynamic(block, id) {
|
|
28764
|
+
return block.dynamic.children.find((child) => child.id === id);
|
|
28765
|
+
}
|
|
28766
|
+
function isStaticBranch(node) {
|
|
28767
|
+
if (node.type !== 1 || node.tagType !== 3 || node.children.length === 0) return false;
|
|
28768
|
+
return node.children.every((child) => isStaticTemplateNode(child));
|
|
28769
|
+
}
|
|
28770
|
+
function isStaticTemplateNode(node) {
|
|
28771
|
+
if (node.type === 2 || node.type === 3) return true;
|
|
28772
|
+
if (node.type !== 1 || node.tagType !== 0) return false;
|
|
28773
|
+
for (const prop of node.props) if (prop.type === 7 || prop.name === "ref") return false;
|
|
28774
|
+
return node.children.every((child) => isStaticTemplateNode(child));
|
|
28775
|
+
}
|
|
28075
28776
|
function shouldForceMultiRoot(context) {
|
|
28076
28777
|
const parent = context.parent && context.parent.node;
|
|
28077
28778
|
return !!parent && parent.type === 1 && parent.tagType === 3 && parent.props.some((prop) => prop.type === 7 && prop.name === "for");
|
|
@@ -28158,6 +28859,9 @@ const transformSlotOutlet = (node, context) => {
|
|
|
28158
28859
|
}
|
|
28159
28860
|
return () => {
|
|
28160
28861
|
exitBlock && exitBlock();
|
|
28862
|
+
let flags = 0;
|
|
28863
|
+
if (context.options.scopeId && !context.options.slotted) flags |= 1;
|
|
28864
|
+
if (context.inVOnce) flags |= 2;
|
|
28161
28865
|
context.dynamic.operation = _objectSpread2(_objectSpread2({
|
|
28162
28866
|
type: 13,
|
|
28163
28867
|
id
|
|
@@ -28165,8 +28869,7 @@ const transformSlotOutlet = (node, context) => {
|
|
|
28165
28869
|
name: slotName,
|
|
28166
28870
|
props: irProps,
|
|
28167
28871
|
fallback,
|
|
28168
|
-
|
|
28169
|
-
once: context.inVOnce
|
|
28872
|
+
flags
|
|
28170
28873
|
});
|
|
28171
28874
|
};
|
|
28172
28875
|
};
|
|
@@ -39926,25 +40629,28 @@ function resolveExt(filename, fs) {
|
|
|
39926
40629
|
const tsConfigCache = createCache();
|
|
39927
40630
|
const tsConfigRefMap = /* @__PURE__ */ new Map();
|
|
39928
40631
|
const fileToScopeCache = createCache();
|
|
40632
|
+
const fileToGlobalScopeCache = createCache();
|
|
39929
40633
|
/**
|
|
39930
40634
|
* @private
|
|
39931
40635
|
*/
|
|
39932
40636
|
function invalidateTypeCache(filename) {
|
|
39933
40637
|
filename = normalizePath(filename);
|
|
39934
40638
|
fileToScopeCache.delete(filename);
|
|
40639
|
+
fileToGlobalScopeCache.delete(filename);
|
|
39935
40640
|
tsConfigCache.delete(filename);
|
|
39936
40641
|
const affectedConfig = tsConfigRefMap.get(filename);
|
|
39937
40642
|
if (affectedConfig) tsConfigCache.delete(affectedConfig);
|
|
39938
40643
|
}
|
|
39939
40644
|
function fileToScope(ctx, filename, asGlobal = false) {
|
|
39940
|
-
const
|
|
40645
|
+
const cache = asGlobal ? fileToGlobalScopeCache : fileToScopeCache;
|
|
40646
|
+
const cached = cache.get(filename);
|
|
39941
40647
|
if (cached) return cached;
|
|
39942
40648
|
const fs = resolveFS(ctx);
|
|
39943
40649
|
const source = fs.readFile(filename) || "";
|
|
39944
40650
|
const body = parseFile(filename, source, fs, ctx.options.babelParserPlugins);
|
|
39945
40651
|
const scope = new TypeScope(filename, source, 0, recordImports(body));
|
|
39946
40652
|
recordTypes(ctx, body, scope, asGlobal);
|
|
39947
|
-
|
|
40653
|
+
cache.set(filename, scope);
|
|
39948
40654
|
return scope;
|
|
39949
40655
|
}
|
|
39950
40656
|
function parseFile(filename, content, fs, parserPlugins) {
|
|
@@ -41471,7 +42177,7 @@ function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
|
|
|
41471
42177
|
//#endregion
|
|
41472
42178
|
//#region packages/compiler-sfc/src/index.ts
|
|
41473
42179
|
init_objectSpread2();
|
|
41474
|
-
const version = "3.6.0-beta.
|
|
42180
|
+
const version = "3.6.0-beta.13";
|
|
41475
42181
|
const parseCache = parseCache$1;
|
|
41476
42182
|
const errorMessages = _objectSpread2(_objectSpread2({}, errorMessages$1), DOMErrorMessages);
|
|
41477
42183
|
const walk = walk$2;
|