@vue/compiler-sfc 3.6.0-beta.12 → 3.6.0-beta.14
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 -5
- package/dist/compiler-sfc.esm-browser.js +904 -218
- 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.14
|
|
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) {
|
|
@@ -25788,7 +25813,7 @@ function isConstantBinding(value, context) {
|
|
|
25788
25813
|
//#region packages/compiler-vapor/src/generators/for.ts
|
|
25789
25814
|
function genFor(oper, context) {
|
|
25790
25815
|
const { helper } = context;
|
|
25791
|
-
const { source, value, key, index, render, keyProp, once, id, component, onlyChild } = oper;
|
|
25816
|
+
const { source, value, key, index, render, keyProp, once, id, component, onlyChild, slotRoot } = oper;
|
|
25792
25817
|
const rawValue = value && value.content;
|
|
25793
25818
|
const rawKey = key && key.content;
|
|
25794
25819
|
const rawIndex = index && index.content;
|
|
@@ -25844,7 +25869,10 @@ 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;
|
|
25875
|
+
if (slotRoot) flags |= 32;
|
|
25848
25876
|
const onResetCalls = [];
|
|
25849
25877
|
for (let i = 0; i < selectorPatterns.length; i++) onResetCalls.push(NEWLINE, `n${id}.onReset(${selectorName(i)}.reset)`);
|
|
25850
25878
|
return [
|
|
@@ -25876,6 +25904,21 @@ function genFor(oper, context) {
|
|
|
25876
25904
|
return idMap;
|
|
25877
25905
|
}
|
|
25878
25906
|
}
|
|
25907
|
+
function isSingleNodeBlock(block) {
|
|
25908
|
+
const child = getSingleReturnedChild(block);
|
|
25909
|
+
return !!child && child.template != null;
|
|
25910
|
+
}
|
|
25911
|
+
function isFragmentBlock(block) {
|
|
25912
|
+
const child = getSingleReturnedChild(block);
|
|
25913
|
+
const operation = child && child.operation;
|
|
25914
|
+
if (!operation) return false;
|
|
25915
|
+
return operation.type === 13 || operation.type === 16 || operation.type === 17 || operation.type === 15 && !operation.once || operation.type === 12 && !!operation.dynamic && !operation.dynamic.isStatic;
|
|
25916
|
+
}
|
|
25917
|
+
function getSingleReturnedChild(block) {
|
|
25918
|
+
if (block.returns.length !== 1) return;
|
|
25919
|
+
const id = block.returns[0];
|
|
25920
|
+
for (const child of block.dynamic.children) if (child.id === id) return child;
|
|
25921
|
+
}
|
|
25879
25922
|
function parseValueDestructure(value, context) {
|
|
25880
25923
|
const map = /* @__PURE__ */ new Map();
|
|
25881
25924
|
if (value) {
|
|
@@ -25911,7 +25954,7 @@ function parseValueDestructure(value, context) {
|
|
|
25911
25954
|
if (child.type === "AssignmentPattern" && (parent.type === "ObjectProperty" || parent.type === "ArrayPattern")) {
|
|
25912
25955
|
isDynamic = true;
|
|
25913
25956
|
helper = context.helper("getDefaultValue");
|
|
25914
|
-
helperArgs = rawValue.slice(child.right.start - 1, child.right.end - 1)
|
|
25957
|
+
helperArgs = `() => (${rawValue.slice(child.right.start - 1, child.right.end - 1)})`;
|
|
25915
25958
|
}
|
|
25916
25959
|
}
|
|
25917
25960
|
map.set(id.name, {
|
|
@@ -26059,8 +26102,9 @@ function genSetHtml(oper, context) {
|
|
|
26059
26102
|
//#region packages/compiler-vapor/src/generators/if.ts
|
|
26060
26103
|
function genIf(oper, context, isNested = false) {
|
|
26061
26104
|
const { helper } = context;
|
|
26062
|
-
const { condition, positive, negative, once, index, blockShape } = oper;
|
|
26105
|
+
const { condition, positive, negative, once, slotRoot, index, blockShape } = oper;
|
|
26063
26106
|
const [frag, push] = buildCodeFragment();
|
|
26107
|
+
const flags = genIfFlags(blockShape, once, slotRoot, negative ? index : void 0);
|
|
26064
26108
|
const conditionExpr = [
|
|
26065
26109
|
"() => (",
|
|
26066
26110
|
...genExpression(condition, context),
|
|
@@ -26071,9 +26115,26 @@ function genIf(oper, context, isNested = false) {
|
|
|
26071
26115
|
if (negative) if (negative.type === 1) negativeArg = genBlock(negative, context);
|
|
26072
26116
|
else negativeArg = ["() => ", ...genIf(negative, context, true)];
|
|
26073
26117
|
if (!isNested) push(NEWLINE, `const n${oper.id} = `);
|
|
26074
|
-
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg,
|
|
26118
|
+
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, flags));
|
|
26075
26119
|
return frag;
|
|
26076
26120
|
}
|
|
26121
|
+
function genIfFlags(blockShape, once, slotRoot, index) {
|
|
26122
|
+
let flags = blockShape;
|
|
26123
|
+
if (slotRoot) flags |= 128;
|
|
26124
|
+
if (once) flags |= 16;
|
|
26125
|
+
else if (index !== void 0) flags |= index + 1 << 8;
|
|
26126
|
+
if (flags === 1) return false;
|
|
26127
|
+
return `${flags} /* ${genIfFlagNames(once, slotRoot, index, blockShape)} */`;
|
|
26128
|
+
}
|
|
26129
|
+
function genIfFlagNames(once, slotRoot, index, blockShape) {
|
|
26130
|
+
const names = ["BLOCK_SHAPE"];
|
|
26131
|
+
if (blockShape & 32) names.push("TRUE_NO_SCOPE");
|
|
26132
|
+
if (blockShape & 64) names.push("FALSE_NO_SCOPE");
|
|
26133
|
+
if (once) names.push("ONCE");
|
|
26134
|
+
if (slotRoot) names.push("SLOT_ROOT");
|
|
26135
|
+
if (!once && index !== void 0) names.push("INDEX_SHIFT");
|
|
26136
|
+
return names.join(", ");
|
|
26137
|
+
}
|
|
26077
26138
|
//#endregion
|
|
26078
26139
|
//#region packages/compiler-vapor/src/generators/prop.ts
|
|
26079
26140
|
const helpers = {
|
|
@@ -26123,15 +26184,16 @@ function resolveClassName(values, context) {
|
|
|
26123
26184
|
const entries = [];
|
|
26124
26185
|
let sawDynamic = false;
|
|
26125
26186
|
let sawSuffix = false;
|
|
26126
|
-
for (const
|
|
26187
|
+
for (const rawValue of values) {
|
|
26188
|
+
const value = context.getExpressionReplacement(rawValue);
|
|
26127
26189
|
const staticValue = getLiteralExpressionValue(value, true);
|
|
26128
26190
|
if (staticValue != null) {
|
|
26129
26191
|
const normalized = normalizeClass(staticValue);
|
|
26130
|
-
if (normalized) if (sawSuffix) suffix = appendClass(suffix, normalized);
|
|
26192
|
+
if (normalized) if (sawSuffix) suffix = appendClass$1(suffix, normalized);
|
|
26131
26193
|
else if (sawDynamic) {
|
|
26132
26194
|
sawSuffix = true;
|
|
26133
|
-
suffix = appendClass(suffix, normalized);
|
|
26134
|
-
} else prefix = appendClass(prefix, normalized);
|
|
26195
|
+
suffix = appendClass$1(suffix, normalized);
|
|
26196
|
+
} else prefix = appendClass$1(prefix, normalized);
|
|
26135
26197
|
continue;
|
|
26136
26198
|
}
|
|
26137
26199
|
const ast = value.ast;
|
|
@@ -26152,7 +26214,7 @@ function resolveClassName(values, context) {
|
|
|
26152
26214
|
function resolveObjectClassName(source, ast, entries, context) {
|
|
26153
26215
|
for (const prop of ast.properties) {
|
|
26154
26216
|
if (prop.type !== "ObjectProperty" || prop.computed) return false;
|
|
26155
|
-
const rawClassName = getObjectPropertyName(prop);
|
|
26217
|
+
const rawClassName = getObjectPropertyName$1(prop);
|
|
26156
26218
|
if (rawClassName == null) return false;
|
|
26157
26219
|
const className = normalizeClass(rawClassName);
|
|
26158
26220
|
if (!className) continue;
|
|
@@ -26197,10 +26259,10 @@ function genClassFlags(entries, context) {
|
|
|
26197
26259
|
});
|
|
26198
26260
|
return values;
|
|
26199
26261
|
}
|
|
26200
|
-
function appendClass(base, value) {
|
|
26262
|
+
function appendClass$1(base, value) {
|
|
26201
26263
|
return base ? value ? `${base} ${value}` : base : value;
|
|
26202
26264
|
}
|
|
26203
|
-
function getObjectPropertyName(prop) {
|
|
26265
|
+
function getObjectPropertyName$1(prop) {
|
|
26204
26266
|
const key = prop.key;
|
|
26205
26267
|
if (key.type === "Identifier") return key.name;
|
|
26206
26268
|
else if (key.type === "StringLiteral") return key.value;
|
|
@@ -26292,8 +26354,23 @@ function getSpecialHelper(keyName, tagName, isSVG) {
|
|
|
26292
26354
|
const setTemplateRefIdent = `_setTemplateRef`;
|
|
26293
26355
|
function genSetTemplateRef(oper, context) {
|
|
26294
26356
|
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
26357
|
+
if (context.staticTemplateRefHelperCandidate === oper) return genSetStaticTemplateRef(oper, refValue, refKey, context);
|
|
26358
|
+
context.needsTemplateRefSetter = true;
|
|
26295
26359
|
return [NEWLINE, ...genCall(setTemplateRefIdent, `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
26296
26360
|
}
|
|
26361
|
+
function genSetStaticTemplateRef(oper, refValue, refKey, context) {
|
|
26362
|
+
return [NEWLINE, ...genCall(context.helper("setStaticTemplateRef"), `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
26363
|
+
}
|
|
26364
|
+
function genSetTemplateRefBinding(oper, context) {
|
|
26365
|
+
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
26366
|
+
const setter = context.inSlotBlock && setTemplateRefIdent;
|
|
26367
|
+
if (context.inSlotBlock) context.needsTemplateRefSetter = true;
|
|
26368
|
+
return [NEWLINE, ...genCall([context.helper("setTemplateRefBinding"), "undefined"], `n${oper.element}`, ["() => ", ...refValue], ...setter || oper.refFor || refKey ? [
|
|
26369
|
+
setter,
|
|
26370
|
+
oper.refFor && "true",
|
|
26371
|
+
refKey
|
|
26372
|
+
] : [])];
|
|
26373
|
+
}
|
|
26297
26374
|
function genRefValue(value, context) {
|
|
26298
26375
|
if (value && context.options.inline) {
|
|
26299
26376
|
const binding = context.options.bindingMetadata[value.content];
|
|
@@ -26397,15 +26474,20 @@ function filterCustomDirectives(id, operations) {
|
|
|
26397
26474
|
//#region packages/compiler-vapor/src/generators/component.ts
|
|
26398
26475
|
function genCreateComponent(operation, context) {
|
|
26399
26476
|
const { helper } = context;
|
|
26477
|
+
const singleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
26478
|
+
const useAssetComponentHelper = operation.asset && !operation.dynamic && context.block === context.ir.block && !!singleUseAssetComponentNames && singleUseAssetComponentNames.has(operation.tag);
|
|
26479
|
+
const maybeSelfReference = useAssetComponentHelper && operation.tag.endsWith("__self");
|
|
26400
26480
|
const tag = genTag();
|
|
26401
|
-
const { root, props, slots, once } = operation;
|
|
26481
|
+
const { root, props, slots, once, slotRoot } = operation;
|
|
26482
|
+
const isRuntimeDynamicComponent = !!(operation.dynamic && !operation.dynamic.isStatic);
|
|
26483
|
+
const dynamicComponentFlags = isRuntimeDynamicComponent ? (root ? 1 : 0) | (once ? 2 : 0) | (slotRoot ? 4 : 0) : 0;
|
|
26402
26484
|
const rawSlots = genRawSlots(slots, context);
|
|
26403
26485
|
const [ids, handlers] = processInlineHandlers(props, context);
|
|
26404
|
-
const rawProps = context.withId(() => genRawProps(props, context), ids);
|
|
26486
|
+
const rawProps = context.withId(() => genRawProps(props, context, true), ids);
|
|
26405
26487
|
return [
|
|
26406
26488
|
NEWLINE,
|
|
26407
26489
|
...handlers.reduce((acc, { name, value }) => {
|
|
26408
|
-
const handler = genEventHandler(context, [value]
|
|
26490
|
+
const handler = genEventHandler(context, [value]);
|
|
26409
26491
|
return [
|
|
26410
26492
|
...acc,
|
|
26411
26493
|
`const ${name} = `,
|
|
@@ -26414,7 +26496,7 @@ function genCreateComponent(operation, context) {
|
|
|
26414
26496
|
];
|
|
26415
26497
|
}, []),
|
|
26416
26498
|
`const n${operation.id} = `,
|
|
26417
|
-
...genCall(
|
|
26499
|
+
...genCall(isRuntimeDynamicComponent ? helper("createDynamicComponent") : operation.useCreateElement ? helper("createPlainElement") : useAssetComponentHelper ? helper("createAssetComponent") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, isRuntimeDynamicComponent ? dynamicComponentFlags ? String(dynamicComponentFlags) : false : root ? "true" : false, isRuntimeDynamicComponent ? false : once && "true", isRuntimeDynamicComponent ? false : maybeSelfReference && "true"),
|
|
26418
26500
|
...genDirectivesForElement(operation.id, context)
|
|
26419
26501
|
];
|
|
26420
26502
|
function genTag() {
|
|
@@ -26425,7 +26507,10 @@ function genCreateComponent(operation, context) {
|
|
|
26425
26507
|
...genExpression(operation.dynamic, context),
|
|
26426
26508
|
")"
|
|
26427
26509
|
];
|
|
26428
|
-
else if (
|
|
26510
|
+
else if (useAssetComponentHelper) {
|
|
26511
|
+
const name = maybeSelfReference ? operation.tag.slice(0, -6) : operation.tag;
|
|
26512
|
+
return JSON.stringify(name);
|
|
26513
|
+
} else if (operation.asset) return toValidAssetId(operation.tag, "component");
|
|
26429
26514
|
else {
|
|
26430
26515
|
const { tag } = operation;
|
|
26431
26516
|
const builtInTag = isBuiltInComponent(tag);
|
|
@@ -26465,14 +26550,14 @@ function processInlineHandlers(props, context) {
|
|
|
26465
26550
|
}
|
|
26466
26551
|
return [ids, handlers];
|
|
26467
26552
|
}
|
|
26468
|
-
function genRawProps(props, context) {
|
|
26553
|
+
function genRawProps(props, context, directStaticLiteralProps = false) {
|
|
26469
26554
|
const staticProps = props[0];
|
|
26470
26555
|
if (isArray$3(staticProps)) {
|
|
26471
26556
|
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));
|
|
26557
|
+
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context, directStaticLiteralProps), directStaticLiteralProps);
|
|
26558
|
+
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context, directStaticLiteralProps), directStaticLiteralProps);
|
|
26474
26559
|
}
|
|
26475
|
-
function genStaticProps(props, context, dynamicProps) {
|
|
26560
|
+
function genStaticProps(props, context, dynamicProps, directStaticLiteralProps = false) {
|
|
26476
26561
|
const args = [];
|
|
26477
26562
|
const handlerGroups = /* @__PURE__ */ new Map();
|
|
26478
26563
|
const ensureHandlerGroup = (keyName, keyFrag) => {
|
|
@@ -26505,11 +26590,11 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
26505
26590
|
continue;
|
|
26506
26591
|
}
|
|
26507
26592
|
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
|
|
26593
|
+
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 }));
|
|
26594
|
+
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, { asComponentProp: true }));
|
|
26510
26595
|
continue;
|
|
26511
26596
|
}
|
|
26512
|
-
args.push(genProp(prop, context, true));
|
|
26597
|
+
args.push(genProp(prop, context, true, true, directStaticLiteralProps && isDirectStaticLiteralProp(prop, context)));
|
|
26513
26598
|
if (prop.model) {
|
|
26514
26599
|
if (prop.key.isStatic) {
|
|
26515
26600
|
const keyName = `onUpdate:${camelize(prop.key.content)}`;
|
|
@@ -26534,7 +26619,7 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
26534
26619
|
" + \"Modifiers\"]"
|
|
26535
26620
|
];
|
|
26536
26621
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
26537
|
-
args.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
|
|
26622
|
+
args.push([...modifiersKey, directStaticLiteralProps ? `: { ${modifiersVal} }` : `: () => ({ ${modifiersVal} })`]);
|
|
26538
26623
|
}
|
|
26539
26624
|
}
|
|
26540
26625
|
}
|
|
@@ -26549,13 +26634,13 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
26549
26634
|
if (dynamicProps) args.push([`$: `, ...dynamicProps]);
|
|
26550
26635
|
return genMulti(args.length > 1 ? DELIMITERS_OBJECT_NEWLINE : DELIMITERS_OBJECT, ...args);
|
|
26551
26636
|
}
|
|
26552
|
-
function genDynamicProps(props, context) {
|
|
26637
|
+
function genDynamicProps(props, context, directStaticLiteralProps = false) {
|
|
26553
26638
|
const { helper } = context;
|
|
26554
26639
|
const frags = [];
|
|
26555
26640
|
for (const p of props) {
|
|
26556
26641
|
let expr;
|
|
26557
26642
|
if (isArray$3(p)) {
|
|
26558
|
-
if (p.length) frags.push(genStaticProps(p, context));
|
|
26643
|
+
if (p.length) frags.push(genStaticProps(p, context, void 0, directStaticLiteralProps));
|
|
26559
26644
|
continue;
|
|
26560
26645
|
} else if (p.kind === 1) if (p.model) {
|
|
26561
26646
|
const entries = [genProp(p, context)];
|
|
@@ -26566,7 +26651,7 @@ function genDynamicProps(props, context) {
|
|
|
26566
26651
|
];
|
|
26567
26652
|
entries.push([
|
|
26568
26653
|
...updateKey,
|
|
26569
|
-
":
|
|
26654
|
+
": ",
|
|
26570
26655
|
...genModelHandler(p.values[0], context)
|
|
26571
26656
|
]);
|
|
26572
26657
|
const { modelModifiers } = p;
|
|
@@ -26577,10 +26662,10 @@ function genDynamicProps(props, context) {
|
|
|
26577
26662
|
" + \"Modifiers\"]"
|
|
26578
26663
|
];
|
|
26579
26664
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
26580
|
-
entries.push([...modifiersKey, `:
|
|
26665
|
+
entries.push([...modifiersKey, `: { ${modifiersVal} }`]);
|
|
26581
26666
|
}
|
|
26582
26667
|
expr = genMulti(DELIMITERS_OBJECT_NEWLINE, ...entries);
|
|
26583
|
-
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context));
|
|
26668
|
+
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context, false, false));
|
|
26584
26669
|
else {
|
|
26585
26670
|
expr = genExpression(p.value, context);
|
|
26586
26671
|
if (p.handler) expr = genCall(helper("toHandlers"), expr);
|
|
@@ -26593,27 +26678,79 @@ function genDynamicProps(props, context) {
|
|
|
26593
26678
|
}
|
|
26594
26679
|
if (frags.length) return genMulti(DELIMITERS_ARRAY_NEWLINE, ...frags);
|
|
26595
26680
|
}
|
|
26596
|
-
function genProp(prop, context, isStatic) {
|
|
26681
|
+
function genProp(prop, context, isStatic, wrapHandler = true, directStaticLiteral = false) {
|
|
26597
26682
|
const values = genPropValue(prop.values, context);
|
|
26598
26683
|
return [
|
|
26599
26684
|
...genPropKey(prop, context),
|
|
26600
26685
|
": ",
|
|
26601
|
-
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers,
|
|
26686
|
+
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, {
|
|
26687
|
+
asComponentProp: true,
|
|
26688
|
+
extraWrap: wrapHandler
|
|
26689
|
+
}) : isStatic ? directStaticLiteral ? values : [
|
|
26602
26690
|
"() => (",
|
|
26603
26691
|
...values,
|
|
26604
26692
|
")"
|
|
26605
26693
|
] : values
|
|
26606
26694
|
];
|
|
26607
26695
|
}
|
|
26696
|
+
/**
|
|
26697
|
+
* Static literal values are safe to emit directly because reading them cannot
|
|
26698
|
+
* touch reactive state. Keep handlers, v-model values, and dynamic expressions
|
|
26699
|
+
* as getter sources to preserve lazy access and merge semantics.
|
|
26700
|
+
*/
|
|
26701
|
+
function isDirectStaticLiteralProp(prop, context) {
|
|
26702
|
+
return prop.key.isStatic && prop.values.length === 1 && !prop.handler && !prop.model && isDirectConstantValue(prop.values[0], context);
|
|
26703
|
+
}
|
|
26704
|
+
function isDirectConstantValue(value, context) {
|
|
26705
|
+
value = context.getExpressionReplacement(value);
|
|
26706
|
+
if (value.isStatic) return true;
|
|
26707
|
+
const ast = value.ast;
|
|
26708
|
+
if (ast === null) return value.content === "true" || value.content === "false" || value.content === "null" || value.content === "undefined";
|
|
26709
|
+
if (!ast) return false;
|
|
26710
|
+
return isDirectConstantAst(ast);
|
|
26711
|
+
}
|
|
26712
|
+
function isDirectConstantAst(node) {
|
|
26713
|
+
switch (node.type) {
|
|
26714
|
+
case "StringLiteral":
|
|
26715
|
+
case "NumericLiteral":
|
|
26716
|
+
case "BooleanLiteral":
|
|
26717
|
+
case "NullLiteral":
|
|
26718
|
+
case "BigIntLiteral": return true;
|
|
26719
|
+
case "Identifier": return node.name === "undefined";
|
|
26720
|
+
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
26721
|
+
case "ArrayExpression": return node.elements.every((element) => element === null || element.type !== "SpreadElement" && isDirectConstantAst(element));
|
|
26722
|
+
case "ObjectExpression": return node.properties.every((prop) => prop.type === "ObjectProperty" && !prop.computed && isDirectConstantAst(prop.value));
|
|
26723
|
+
}
|
|
26724
|
+
return false;
|
|
26725
|
+
}
|
|
26726
|
+
function isDirectTemplateConstantAst(node) {
|
|
26727
|
+
switch (node.type) {
|
|
26728
|
+
case "StringLiteral":
|
|
26729
|
+
case "NumericLiteral":
|
|
26730
|
+
case "BooleanLiteral":
|
|
26731
|
+
case "NullLiteral":
|
|
26732
|
+
case "BigIntLiteral": return true;
|
|
26733
|
+
case "Identifier": return node.name === "undefined";
|
|
26734
|
+
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
26735
|
+
}
|
|
26736
|
+
return false;
|
|
26737
|
+
}
|
|
26608
26738
|
function genRawSlots(slots, context) {
|
|
26609
26739
|
if (!slots.length) return;
|
|
26610
26740
|
const staticSlots = slots[0];
|
|
26611
|
-
if (staticSlots.slotType === 0)
|
|
26612
|
-
|
|
26741
|
+
if (staticSlots.slotType === 0) {
|
|
26742
|
+
const defaultSlot = getSingleDefaultSlot(staticSlots);
|
|
26743
|
+
if (defaultSlot && slots.length === 1) return genSlotBlockWithProps(defaultSlot, context);
|
|
26744
|
+
return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
|
|
26745
|
+
} else return genStaticSlots({
|
|
26613
26746
|
slotType: 0,
|
|
26614
26747
|
slots: {}
|
|
26615
26748
|
}, context, slots);
|
|
26616
26749
|
}
|
|
26750
|
+
function getSingleDefaultSlot({ slots }) {
|
|
26751
|
+
const names = Object.keys(slots);
|
|
26752
|
+
return names.length === 1 && names[0] === "default" ? slots.default : void 0;
|
|
26753
|
+
}
|
|
26617
26754
|
function genStaticSlots({ slots }, context, dynamicSlots) {
|
|
26618
26755
|
const args = Object.keys(slots).map((name) => [`${JSON.stringify(name)}: `, ...genSlotBlockWithProps(slots[name], context)]);
|
|
26619
26756
|
if (dynamicSlots) args.push([`$: `, ...genDynamicSlots(dynamicSlots, context)]);
|
|
@@ -26636,23 +26773,12 @@ function genDynamicSlot(slot, context, withFunction = false) {
|
|
|
26636
26773
|
break;
|
|
26637
26774
|
}
|
|
26638
26775
|
if (!withFunction) return frag;
|
|
26639
|
-
return
|
|
26640
|
-
`${context.helper("withVaporCtx")}(() => (`,
|
|
26641
|
-
...frag,
|
|
26642
|
-
"))"
|
|
26643
|
-
] : [
|
|
26776
|
+
return [
|
|
26644
26777
|
"() => (",
|
|
26645
26778
|
...frag,
|
|
26646
26779
|
")"
|
|
26647
26780
|
];
|
|
26648
26781
|
}
|
|
26649
|
-
function needsDynamicSlotSourceCtx(slot) {
|
|
26650
|
-
switch (slot.slotType) {
|
|
26651
|
-
case 1: return needsVaporCtx(slot.fn);
|
|
26652
|
-
case 2: return needsVaporCtx(slot.fn);
|
|
26653
|
-
case 3: return needsDynamicSlotSourceCtx(slot.positive) || (slot.negative ? needsDynamicSlotSourceCtx(slot.negative) : false);
|
|
26654
|
-
}
|
|
26655
|
-
}
|
|
26656
26782
|
function genBasicDynamicSlot(slot, context) {
|
|
26657
26783
|
const { name, fn } = slot;
|
|
26658
26784
|
return genMulti(DELIMITERS_OBJECT_NEWLINE, ["name: ", ...genExpression(name, context)], ["fn: ", ...genSlotBlockWithProps(fn, context)]);
|
|
@@ -26697,7 +26823,7 @@ function genSlotBlockWithProps(oper, context) {
|
|
|
26697
26823
|
let propsName;
|
|
26698
26824
|
let exitScope;
|
|
26699
26825
|
let depth;
|
|
26700
|
-
const { props
|
|
26826
|
+
const { props } = oper;
|
|
26701
26827
|
const idToPathMap = props ? parseValueDestructure(props, context) : /* @__PURE__ */ new Map();
|
|
26702
26828
|
if (props) if (props.ast) {
|
|
26703
26829
|
[depth, exitScope] = context.enterScope();
|
|
@@ -26705,77 +26831,32 @@ function genSlotBlockWithProps(oper, context) {
|
|
|
26705
26831
|
} else propsName = props.content;
|
|
26706
26832
|
const idMap = idToPathMap.size ? buildDestructureIdMap(idToPathMap, propsName || "", context.options.expressionPlugins) : {};
|
|
26707
26833
|
if (propsName) idMap[propsName] = null;
|
|
26834
|
+
const exitSlotBlock = context.enterSlotBlock();
|
|
26835
|
+
markSlotRootOperations(oper);
|
|
26708
26836
|
let blockFn = context.withId(() => genBlock(oper, context, propsName ? [propsName] : []), idMap);
|
|
26837
|
+
exitSlotBlock();
|
|
26709
26838
|
exitScope && exitScope();
|
|
26710
|
-
if (node.type === 1) {
|
|
26711
|
-
if (needsVaporCtx(oper)) blockFn = [
|
|
26712
|
-
`${context.helper("withVaporCtx")}(`,
|
|
26713
|
-
...blockFn,
|
|
26714
|
-
`)`
|
|
26715
|
-
];
|
|
26716
|
-
}
|
|
26717
26839
|
return blockFn;
|
|
26718
26840
|
}
|
|
26719
|
-
/**
|
|
26720
|
-
* Check if a slot block needs withVaporCtx wrapper.
|
|
26721
|
-
* Returns true if the block contains:
|
|
26722
|
-
* - Component creation (needs scopeId inheritance)
|
|
26723
|
-
* - Slot outlet (needs rawSlots from slot owner)
|
|
26724
|
-
*/
|
|
26725
|
-
function needsVaporCtx(block) {
|
|
26726
|
-
return hasComponentOrSlotInBlock(block);
|
|
26727
|
-
}
|
|
26728
|
-
function hasComponentOrSlotInBlock(block) {
|
|
26729
|
-
if (hasComponentOrSlotInOperations(block.operation)) return true;
|
|
26730
|
-
return hasComponentOrSlotInDynamic(block.dynamic);
|
|
26731
|
-
}
|
|
26732
|
-
function hasComponentOrSlotInDynamic(dynamic) {
|
|
26733
|
-
if (dynamic.operation) {
|
|
26734
|
-
const type = dynamic.operation.type;
|
|
26735
|
-
if (type === 12 || type === 13) return true;
|
|
26736
|
-
if (type === 15) {
|
|
26737
|
-
if (hasComponentOrSlotInIf(dynamic.operation)) return true;
|
|
26738
|
-
}
|
|
26739
|
-
if (type === 16) {
|
|
26740
|
-
if (hasComponentOrSlotInBlock(dynamic.operation.render)) return true;
|
|
26741
|
-
}
|
|
26742
|
-
}
|
|
26743
|
-
for (const child of dynamic.children) if (hasComponentOrSlotInDynamic(child)) return true;
|
|
26744
|
-
return false;
|
|
26745
|
-
}
|
|
26746
|
-
function hasComponentOrSlotInOperations(operations) {
|
|
26747
|
-
for (const op of operations) switch (op.type) {
|
|
26748
|
-
case 12:
|
|
26749
|
-
case 13: return true;
|
|
26750
|
-
case 15:
|
|
26751
|
-
if (hasComponentOrSlotInIf(op)) return true;
|
|
26752
|
-
break;
|
|
26753
|
-
case 16:
|
|
26754
|
-
if (hasComponentOrSlotInBlock(op.render)) return true;
|
|
26755
|
-
break;
|
|
26756
|
-
}
|
|
26757
|
-
return false;
|
|
26758
|
-
}
|
|
26759
|
-
function hasComponentOrSlotInIf(node) {
|
|
26760
|
-
if (hasComponentOrSlotInBlock(node.positive)) return true;
|
|
26761
|
-
if (node.negative) if ("positive" in node.negative) return hasComponentOrSlotInIf(node.negative);
|
|
26762
|
-
else return hasComponentOrSlotInBlock(node.negative);
|
|
26763
|
-
return false;
|
|
26764
|
-
}
|
|
26765
26841
|
//#endregion
|
|
26766
26842
|
//#region packages/compiler-vapor/src/generators/slotOutlet.ts
|
|
26767
26843
|
function genSlotOutlet(oper, context) {
|
|
26768
26844
|
const { helper } = context;
|
|
26769
|
-
const { id, name, fallback,
|
|
26845
|
+
const { id, name, fallback, flags } = oper;
|
|
26770
26846
|
const [frag, push] = buildCodeFragment();
|
|
26771
|
-
|
|
26847
|
+
let fallbackArg;
|
|
26848
|
+
if (fallback) {
|
|
26849
|
+
markSlotRootOperations(fallback);
|
|
26850
|
+
fallbackArg = genBlock(fallback, context);
|
|
26851
|
+
}
|
|
26852
|
+
const createSlot = helper("createSlot");
|
|
26853
|
+
const rawPropsArg = genRawProps(oper.props, context, true);
|
|
26854
|
+
const nameArg = name.isStatic && name.content === "default" && !rawPropsArg && !fallbackArg && !flags ? void 0 : name.isStatic ? genExpression(name, context) : [
|
|
26772
26855
|
"() => (",
|
|
26773
26856
|
...genExpression(name, context),
|
|
26774
26857
|
")"
|
|
26775
26858
|
];
|
|
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"));
|
|
26859
|
+
push(NEWLINE, `const n${id} = `, ...genCall(createSlot, nameArg, rawPropsArg, fallbackArg, flags ? String(flags) : void 0));
|
|
26779
26860
|
return frag;
|
|
26780
26861
|
}
|
|
26781
26862
|
//#endregion
|
|
@@ -26835,28 +26916,35 @@ function genEffects(effects, context, genExtraFrag) {
|
|
|
26835
26916
|
const [frag, push, unshift] = buildCodeFragment();
|
|
26836
26917
|
const shouldDeclare = genExtraFrag === void 0;
|
|
26837
26918
|
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
|
-
|
|
26919
|
+
const { ids, frag: declarationFrags, varNames, expressionReplacements } = processExpressions(context, expressions, shouldDeclare);
|
|
26920
|
+
if (shouldDeclare && !declarationFrags.length && !varNames.length) {
|
|
26921
|
+
const effect = effects.length === 1 ? effects[0] : void 0;
|
|
26922
|
+
const operation = effect && effect.operations.length === 1 ? effect.operations[0] : void 0;
|
|
26923
|
+
if (operation && operation.type === 9 && operation.effect && !operation.refFor) return context.withExpressionReplacements(expressionReplacements, () => context.withId(() => genSetTemplateRefBinding(operation, context), ids));
|
|
26924
|
+
}
|
|
26925
|
+
return context.withExpressionReplacements(expressionReplacements, () => {
|
|
26926
|
+
push(...declarationFrags);
|
|
26927
|
+
for (let i = 0; i < effects.length; i++) {
|
|
26928
|
+
const effect = effects[i];
|
|
26929
|
+
operationsCount += effect.operations.length;
|
|
26930
|
+
const frags = context.withId(() => genEffect(effect, context), ids);
|
|
26931
|
+
i > 0 && push(NEWLINE);
|
|
26932
|
+
if (frag[frag.length - 1] === ")" && frags[0] === "(") push(";");
|
|
26933
|
+
push(...frags);
|
|
26934
|
+
}
|
|
26935
|
+
if (frag.filter((frag) => frag === NEWLINE).length > 1 || operationsCount > 1 || declarationFrags.length > 0) {
|
|
26936
|
+
unshift(`{`, INDENT_START, NEWLINE);
|
|
26937
|
+
push(INDENT_END, NEWLINE, "}");
|
|
26938
|
+
if (!effects.length) unshift(NEWLINE);
|
|
26939
|
+
}
|
|
26940
|
+
if (effects.length) {
|
|
26941
|
+
unshift(NEWLINE, `${helper("renderEffect")}(() => `);
|
|
26942
|
+
push(`)`);
|
|
26943
|
+
}
|
|
26944
|
+
if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
|
|
26945
|
+
if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
|
|
26946
|
+
return frag;
|
|
26947
|
+
});
|
|
26860
26948
|
}
|
|
26861
26949
|
function genEffect({ operations }, context) {
|
|
26862
26950
|
const [frag, push] = buildCodeFragment();
|
|
@@ -26875,9 +26963,8 @@ function genTemplates(templates, context) {
|
|
|
26875
26963
|
const result = [];
|
|
26876
26964
|
templates.forEach(({ content, ns, root, static: isStatic }, i) => {
|
|
26877
26965
|
let args = JSON.stringify(content).replace(IMPORT_EXPR_RE, `" + $1 + "`);
|
|
26878
|
-
|
|
26879
|
-
|
|
26880
|
-
if (isStatic || ns) args += `, ${isStatic ? "true" : "false"}`;
|
|
26966
|
+
const flags = (root ? 1 : 0) | (isStatic ? 2 : 0);
|
|
26967
|
+
if (flags || ns) args += `, ${flags}`;
|
|
26881
26968
|
if (ns) args += `, ${ns}`;
|
|
26882
26969
|
result.push(`const ${context.tName(i)} = ${context.helper("template")}(${args})\n`);
|
|
26883
26970
|
});
|
|
@@ -26895,10 +26982,13 @@ function genSelf(dynamic, context, flushBeforeDynamic) {
|
|
|
26895
26982
|
return frag;
|
|
26896
26983
|
}
|
|
26897
26984
|
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flushBeforeDynamic) {
|
|
26898
|
-
const { helper } = context;
|
|
26899
26985
|
const [frag, push] = buildCodeFragment();
|
|
26900
26986
|
const { children } = dynamic;
|
|
26901
26987
|
let offset = 0;
|
|
26988
|
+
/**
|
|
26989
|
+
* `reusable` means the previous access target is a p* cursor that can be
|
|
26990
|
+
* reassigned by the next lookup. Referenced n* variables must stay stable.
|
|
26991
|
+
*/
|
|
26902
26992
|
let prev;
|
|
26903
26993
|
for (const [index, child] of children.entries()) {
|
|
26904
26994
|
if (child.flags & 2) offset--;
|
|
@@ -26915,27 +27005,118 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flush
|
|
|
26915
27005
|
}
|
|
26916
27006
|
const elementIndex = index + offset;
|
|
26917
27007
|
const logicalIndex = child.logicalIndex !== void 0 ? String(child.logicalIndex) : void 0;
|
|
26918
|
-
const
|
|
26919
|
-
|
|
26920
|
-
if (
|
|
26921
|
-
|
|
26922
|
-
|
|
26923
|
-
|
|
26924
|
-
|
|
26925
|
-
|
|
26926
|
-
|
|
26927
|
-
|
|
27008
|
+
const inlinePlaceholder = id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6);
|
|
27009
|
+
const accessPath = genAccessPath(context, from, child, elementIndex, logicalIndex, prev);
|
|
27010
|
+
if (inlinePlaceholder) {
|
|
27011
|
+
if (prev && prev[2]) {
|
|
27012
|
+
push(...genChildren(child, context, pushBlock, [
|
|
27013
|
+
"(",
|
|
27014
|
+
prev[0],
|
|
27015
|
+
" = ",
|
|
27016
|
+
...accessPath,
|
|
27017
|
+
")"
|
|
27018
|
+
], flushBeforeDynamic));
|
|
27019
|
+
prev = [
|
|
27020
|
+
prev[0],
|
|
27021
|
+
elementIndex,
|
|
27022
|
+
true
|
|
27023
|
+
];
|
|
27024
|
+
continue;
|
|
27025
|
+
}
|
|
27026
|
+
if (!hasAdjacentFollowingAccessChild(children, index, elementIndex, offset)) {
|
|
27027
|
+
push(...genChildren(child, context, pushBlock, accessPath, flushBeforeDynamic));
|
|
27028
|
+
continue;
|
|
27029
|
+
}
|
|
27030
|
+
}
|
|
27031
|
+
let variable;
|
|
27032
|
+
if (id === void 0 && prev && prev[2]) {
|
|
27033
|
+
variable = prev[0];
|
|
27034
|
+
pushBlock(NEWLINE, `${variable} = `, ...accessPath);
|
|
27035
|
+
} else {
|
|
27036
|
+
variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
|
|
27037
|
+
pushBlock(NEWLINE, id === void 0 ? `let ${variable} = ` : `const ${variable} = `, ...accessPath);
|
|
26928
27038
|
}
|
|
26929
27039
|
if (id === child.anchor && !child.hasDynamicChild) {
|
|
26930
27040
|
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
26931
27041
|
push(...genSelf(child, context, flushBeforeDynamic));
|
|
26932
27042
|
}
|
|
26933
27043
|
if (id !== void 0) push(...genDirectivesForElement(id, context));
|
|
26934
|
-
prev = [
|
|
27044
|
+
prev = [
|
|
27045
|
+
variable,
|
|
27046
|
+
elementIndex,
|
|
27047
|
+
id === void 0
|
|
27048
|
+
];
|
|
26935
27049
|
push(...genChildren(child, context, pushBlock, variable, flushBeforeDynamic));
|
|
26936
27050
|
}
|
|
26937
27051
|
return frag;
|
|
26938
27052
|
}
|
|
27053
|
+
/**
|
|
27054
|
+
* Build one DOM lookup path while preserving the fast sibling walk:
|
|
27055
|
+
* adjacent nodes use _next(prev), otherwise fall back to _nthChild(parent).
|
|
27056
|
+
*/
|
|
27057
|
+
function genAccessPath({ helper }, from, child, elementIndex, logicalIndex, prev) {
|
|
27058
|
+
if (prev) return elementIndex - prev[1] === 1 ? genCall(helper("next"), prev[0], logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
27059
|
+
if (elementIndex === 0) return genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0);
|
|
27060
|
+
const firstChild = genCall(helper("child"), from);
|
|
27061
|
+
return elementIndex === 1 ? genCall(helper("next"), firstChild, logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
27062
|
+
}
|
|
27063
|
+
/**
|
|
27064
|
+
* Only inline a placeholder when materializing it would not save a parent
|
|
27065
|
+
* lookup. If its child tree needs the parent more than once, keep p* so the
|
|
27066
|
+
* generated code does not duplicate _child/_nthChild work.
|
|
27067
|
+
*/
|
|
27068
|
+
function canInlinePlaceholder(dynamic) {
|
|
27069
|
+
return dynamic.hasDynamicChild === true && countParentAccessUsages(dynamic) === 1;
|
|
27070
|
+
}
|
|
27071
|
+
/**
|
|
27072
|
+
* A following access can reuse the current placeholder cursor only when it is
|
|
27073
|
+
* the next DOM sibling. Gapped siblings need _nthChild(parent, index) instead.
|
|
27074
|
+
*/
|
|
27075
|
+
function hasAdjacentFollowingAccessChild(children, index, elementIndex, offset) {
|
|
27076
|
+
let futureOffset = offset;
|
|
27077
|
+
for (let i = index + 1; i < children.length; i++) {
|
|
27078
|
+
const child = children[i];
|
|
27079
|
+
if (child.flags & 2) futureOffset--;
|
|
27080
|
+
if (!(child.flags & 4 && child.template != null) && (!!(child.flags & 1) || child.hasDynamicChild)) return i + futureOffset - elementIndex === 1;
|
|
27081
|
+
}
|
|
27082
|
+
return false;
|
|
27083
|
+
}
|
|
27084
|
+
/**
|
|
27085
|
+
* Mirrors genChildren's traversal closely enough to count how many emitted
|
|
27086
|
+
* access paths would start from this placeholder's parent. This is the guard
|
|
27087
|
+
* that keeps inline placeholders from duplicating parent lookups.
|
|
27088
|
+
*/
|
|
27089
|
+
function countParentAccessUsages(dynamic) {
|
|
27090
|
+
let usages = 0;
|
|
27091
|
+
let offset = 0;
|
|
27092
|
+
let prev;
|
|
27093
|
+
for (const [index, child] of dynamic.children.entries()) {
|
|
27094
|
+
if (child.flags & 2) offset--;
|
|
27095
|
+
if (child.flags & 4 && child.template != null) continue;
|
|
27096
|
+
const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
|
|
27097
|
+
if (id === void 0 && !child.hasDynamicChild) continue;
|
|
27098
|
+
const elementIndex = index + offset;
|
|
27099
|
+
const usesParent = !prev || elementIndex - prev[0] !== 1;
|
|
27100
|
+
if (id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6)) {
|
|
27101
|
+
if (prev && prev[1]) {
|
|
27102
|
+
if (usesParent) usages++;
|
|
27103
|
+
prev = [elementIndex, true];
|
|
27104
|
+
continue;
|
|
27105
|
+
}
|
|
27106
|
+
if (!hasAdjacentFollowingAccessChild(dynamic.children, index, elementIndex, offset)) {
|
|
27107
|
+
if (usesParent) usages++;
|
|
27108
|
+
continue;
|
|
27109
|
+
}
|
|
27110
|
+
}
|
|
27111
|
+
if (usesParent) usages++;
|
|
27112
|
+
prev = [elementIndex, id === void 0];
|
|
27113
|
+
}
|
|
27114
|
+
return usages;
|
|
27115
|
+
}
|
|
27116
|
+
function genNthChild(nthChild, from, elementIndex, logicalIndex) {
|
|
27117
|
+
const index = String(elementIndex);
|
|
27118
|
+
return genCall(nthChild, from, index, logicalIndex === index ? void 0 : logicalIndex);
|
|
27119
|
+
}
|
|
26939
27120
|
//#endregion
|
|
26940
27121
|
//#region packages/compiler-vapor/src/generators/block.ts
|
|
26941
27122
|
function genBlock(oper, context, args = [], root) {
|
|
@@ -26954,8 +27135,12 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
26954
27135
|
const [frag, push] = buildCodeFragment();
|
|
26955
27136
|
const { dynamic, effect, operation, returns } = block;
|
|
26956
27137
|
const resetBlock = context.enterBlock(block);
|
|
27138
|
+
const singleUseAssetComponentNames = root ? collectSingleUseAssetComponents(block) : void 0;
|
|
27139
|
+
const prevSingleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
27140
|
+
if (singleUseAssetComponentNames) context.singleUseAssetComponentNames = singleUseAssetComponentNames;
|
|
26957
27141
|
if (root) {
|
|
26958
27142
|
for (let name of context.ir.component) {
|
|
27143
|
+
if (singleUseAssetComponentNames && singleUseAssetComponentNames.has(name)) continue;
|
|
26959
27144
|
const id = toValidAssetId(name, "component");
|
|
26960
27145
|
const maybeSelfReference = name.endsWith("__self");
|
|
26961
27146
|
if (maybeSelfReference) name = name.slice(0, -6);
|
|
@@ -26991,15 +27176,137 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
26991
27176
|
const returnNodes = returns.map((n) => `n${n}`);
|
|
26992
27177
|
push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"]);
|
|
26993
27178
|
resetBlock();
|
|
27179
|
+
context.singleUseAssetComponentNames = prevSingleUseAssetComponentNames;
|
|
26994
27180
|
return frag;
|
|
26995
27181
|
function genResolveAssets(kind, helper) {
|
|
26996
27182
|
for (const name of context.ir[kind]) push(NEWLINE, `const ${toValidAssetId(name, kind)} = `, ...genCall(context.helper(helper), JSON.stringify(name)));
|
|
26997
27183
|
}
|
|
26998
27184
|
}
|
|
27185
|
+
function markSlotRootOperations(block) {
|
|
27186
|
+
for (let i = 0; i < block.returns.length; i++) {
|
|
27187
|
+
const child = findReturnedDynamic$1(block, block.returns[i]);
|
|
27188
|
+
const operation = child && child.operation;
|
|
27189
|
+
if (!operation) continue;
|
|
27190
|
+
if (operation.type === 15) markSlotRootIf(operation);
|
|
27191
|
+
else if (operation.type === 16) markSlotRootFor(operation);
|
|
27192
|
+
else if (operation.type === 13) markSlotRootSlotOutlet(operation);
|
|
27193
|
+
else if (operation.type === 12) markSlotRootComponent(operation);
|
|
27194
|
+
}
|
|
27195
|
+
}
|
|
27196
|
+
function markSlotRootIf(operation) {
|
|
27197
|
+
if (!operation.once) operation.slotRoot = true;
|
|
27198
|
+
markSlotRootOperations(operation.positive);
|
|
27199
|
+
const negative = operation.negative;
|
|
27200
|
+
if (!negative) return;
|
|
27201
|
+
if (negative.type === 15) markSlotRootIf(negative);
|
|
27202
|
+
else markSlotRootOperations(negative);
|
|
27203
|
+
}
|
|
27204
|
+
function markSlotRootFor(operation) {
|
|
27205
|
+
if (!operation.once) operation.slotRoot = true;
|
|
27206
|
+
markSlotRootOperations(operation.render);
|
|
27207
|
+
}
|
|
27208
|
+
function markSlotRootSlotOutlet(operation) {
|
|
27209
|
+
operation.flags |= 4;
|
|
27210
|
+
if (operation.fallback) markSlotRootOperations(operation.fallback);
|
|
27211
|
+
}
|
|
27212
|
+
function markSlotRootComponent(operation) {
|
|
27213
|
+
if (!operation.once && operation.dynamic && !operation.dynamic.isStatic) operation.slotRoot = true;
|
|
27214
|
+
}
|
|
27215
|
+
function findReturnedDynamic$1(block, id) {
|
|
27216
|
+
for (let i = 0; i < block.dynamic.children.length; i++) {
|
|
27217
|
+
const child = block.dynamic.children[i];
|
|
27218
|
+
if (child.id === id) return child;
|
|
27219
|
+
}
|
|
27220
|
+
}
|
|
27221
|
+
function collectSingleUseAssetComponents(block) {
|
|
27222
|
+
const usageMap = /* @__PURE__ */ new Map();
|
|
27223
|
+
const seenOperations = /* @__PURE__ */ new Set();
|
|
27224
|
+
visitBlock(block, true);
|
|
27225
|
+
const names = /* @__PURE__ */ new Set();
|
|
27226
|
+
for (const [name, usage] of usageMap) if (usage.count === 1 && usage.root) names.add(name);
|
|
27227
|
+
return names;
|
|
27228
|
+
function visitBlock(block, rootCandidate) {
|
|
27229
|
+
visitDynamic(block.dynamic, rootCandidate);
|
|
27230
|
+
for (const operation of block.operation) visitOperation(operation, rootCandidate);
|
|
27231
|
+
for (const effect of block.effect) for (const operation of effect.operations) visitOperation(operation, false);
|
|
27232
|
+
}
|
|
27233
|
+
function visitDynamic(dynamic, rootCandidate) {
|
|
27234
|
+
if (dynamic.operation) visitOperation(dynamic.operation, rootCandidate);
|
|
27235
|
+
for (const child of dynamic.children) visitDynamic(child, rootCandidate);
|
|
27236
|
+
}
|
|
27237
|
+
function visitOperation(operation, rootCandidate) {
|
|
27238
|
+
if (seenOperations.has(operation)) return;
|
|
27239
|
+
seenOperations.add(operation);
|
|
27240
|
+
if (operation.type === 12) {
|
|
27241
|
+
if (operation.asset) {
|
|
27242
|
+
const usage = usageMap.get(operation.tag) || {
|
|
27243
|
+
count: 0,
|
|
27244
|
+
root: false
|
|
27245
|
+
};
|
|
27246
|
+
usage.count++;
|
|
27247
|
+
if (rootCandidate) usage.root = true;
|
|
27248
|
+
usageMap.set(operation.tag, usage);
|
|
27249
|
+
}
|
|
27250
|
+
visitSlots(operation.slots);
|
|
27251
|
+
return;
|
|
27252
|
+
}
|
|
27253
|
+
switch (operation.type) {
|
|
27254
|
+
case 15:
|
|
27255
|
+
visitBlock(operation.positive, false);
|
|
27256
|
+
if (operation.negative) if (operation.negative.type === 15) visitOperation(operation.negative, false);
|
|
27257
|
+
else visitBlock(operation.negative, false);
|
|
27258
|
+
break;
|
|
27259
|
+
case 16:
|
|
27260
|
+
visitBlock(operation.render, false);
|
|
27261
|
+
break;
|
|
27262
|
+
case 17:
|
|
27263
|
+
visitBlock(operation.block, false);
|
|
27264
|
+
break;
|
|
27265
|
+
case 13:
|
|
27266
|
+
if (operation.fallback) visitBlock(operation.fallback, false);
|
|
27267
|
+
break;
|
|
27268
|
+
}
|
|
27269
|
+
}
|
|
27270
|
+
function visitSlots(slots) {
|
|
27271
|
+
for (const slot of slots) switch (slot.slotType) {
|
|
27272
|
+
case 0:
|
|
27273
|
+
for (const name in slot.slots) visitBlock(slot.slots[name], false);
|
|
27274
|
+
break;
|
|
27275
|
+
case 1:
|
|
27276
|
+
case 2:
|
|
27277
|
+
visitBlock(slot.fn, false);
|
|
27278
|
+
break;
|
|
27279
|
+
case 3:
|
|
27280
|
+
visitSlots([slot.positive]);
|
|
27281
|
+
if (slot.negative) visitSlots([slot.negative]);
|
|
27282
|
+
break;
|
|
27283
|
+
}
|
|
27284
|
+
}
|
|
27285
|
+
}
|
|
26999
27286
|
//#endregion
|
|
27000
27287
|
//#region packages/compiler-vapor/src/generate.ts
|
|
27001
27288
|
const idWithTrailingDigitsRE = /^([A-Za-z_$][\w$]*)(\d+)$/;
|
|
27289
|
+
const helperNameAliases = {
|
|
27290
|
+
withVaporKeys: "withKeys",
|
|
27291
|
+
withVaporModifiers: "withModifiers"
|
|
27292
|
+
};
|
|
27002
27293
|
var CodegenContext = class {
|
|
27294
|
+
withExpressionReplacements(map, fn) {
|
|
27295
|
+
if (map.size === 0) return fn();
|
|
27296
|
+
this.expressionReplacements.unshift(map);
|
|
27297
|
+
try {
|
|
27298
|
+
return fn();
|
|
27299
|
+
} finally {
|
|
27300
|
+
remove(this.expressionReplacements, map);
|
|
27301
|
+
}
|
|
27302
|
+
}
|
|
27303
|
+
getExpressionReplacement(node) {
|
|
27304
|
+
for (const map of this.expressionReplacements) {
|
|
27305
|
+
const replacement = map.get(node);
|
|
27306
|
+
if (replacement) return replacement;
|
|
27307
|
+
}
|
|
27308
|
+
return node;
|
|
27309
|
+
}
|
|
27003
27310
|
withId(fn, map) {
|
|
27004
27311
|
const { identifiers } = this;
|
|
27005
27312
|
const ids = Object.keys(map);
|
|
@@ -27016,9 +27323,19 @@ var CodegenContext = class {
|
|
|
27016
27323
|
this.block = block;
|
|
27017
27324
|
return () => this.block = parent;
|
|
27018
27325
|
}
|
|
27326
|
+
enterSlotBlock() {
|
|
27327
|
+
const parent = this.inSlotBlock;
|
|
27328
|
+
this.inSlotBlock = true;
|
|
27329
|
+
return () => this.inSlotBlock = parent;
|
|
27330
|
+
}
|
|
27019
27331
|
enterScope() {
|
|
27020
27332
|
return [this.scopeLevel++, () => this.scopeLevel--];
|
|
27021
27333
|
}
|
|
27334
|
+
isHelperNameAvailable(name) {
|
|
27335
|
+
if (this.bindingNames.has(name)) return false;
|
|
27336
|
+
for (const alias of this.helpers.values()) if (alias === name) return false;
|
|
27337
|
+
return true;
|
|
27338
|
+
}
|
|
27022
27339
|
initNextIdMap() {
|
|
27023
27340
|
if (this.bindingNames.size === 0) return;
|
|
27024
27341
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -27053,19 +27370,29 @@ var CodegenContext = class {
|
|
|
27053
27370
|
this.ir = ir;
|
|
27054
27371
|
this.bindingNames = /* @__PURE__ */ new Set();
|
|
27055
27372
|
this.helpers = /* @__PURE__ */ new Map();
|
|
27373
|
+
this.needsTemplateRefSetter = false;
|
|
27374
|
+
this.inSlotBlock = false;
|
|
27056
27375
|
this.helper = (name) => {
|
|
27057
27376
|
if (this.helpers.has(name)) return this.helpers.get(name);
|
|
27058
|
-
const base = `_${name}`;
|
|
27059
|
-
if (this.
|
|
27377
|
+
const base = `_${helperNameAliases[name] || name}`;
|
|
27378
|
+
if (this.isHelperNameAvailable(base)) {
|
|
27060
27379
|
this.helpers.set(name, base);
|
|
27061
27380
|
return base;
|
|
27062
27381
|
}
|
|
27063
|
-
const
|
|
27064
|
-
|
|
27065
|
-
|
|
27382
|
+
const map = this.nextIdMap.get(base);
|
|
27383
|
+
let next = 1;
|
|
27384
|
+
while (true) {
|
|
27385
|
+
const alias = `${base}${getNextId(map, next)}`;
|
|
27386
|
+
if (this.isHelperNameAvailable(alias)) {
|
|
27387
|
+
this.helpers.set(name, alias);
|
|
27388
|
+
return alias;
|
|
27389
|
+
}
|
|
27390
|
+
next++;
|
|
27391
|
+
}
|
|
27066
27392
|
};
|
|
27067
27393
|
this.delegates = /* @__PURE__ */ new Set();
|
|
27068
27394
|
this.identifiers = Object.create(null);
|
|
27395
|
+
this.expressionReplacements = [];
|
|
27069
27396
|
this.seenInlineHandlerNames = Object.create(null);
|
|
27070
27397
|
this.scopeLevel = 0;
|
|
27071
27398
|
this.templateVars = /* @__PURE__ */ new Map();
|
|
@@ -27092,6 +27419,7 @@ var CodegenContext = class {
|
|
|
27092
27419
|
this.block = ir.block;
|
|
27093
27420
|
this.bindingNames = new Set(this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []);
|
|
27094
27421
|
this.initNextIdMap();
|
|
27422
|
+
this.staticTemplateRefHelperCandidate = getStaticTemplateRefHelperCandidate(ir.block);
|
|
27095
27423
|
}
|
|
27096
27424
|
};
|
|
27097
27425
|
function generate(ir, options = {}) {
|
|
@@ -27104,8 +27432,11 @@ function generate(ir, options = {}) {
|
|
|
27104
27432
|
const signature = (options.isTS ? args.map((arg) => `${arg}: any`) : args).join(", ");
|
|
27105
27433
|
if (!inline) push(NEWLINE, `export function ${functionName}(${signature}) {`);
|
|
27106
27434
|
push(INDENT_START);
|
|
27107
|
-
|
|
27108
|
-
|
|
27435
|
+
const templateRefSetterHelper = ir.hasTemplateRef ? context.helper("createTemplateRefSetter") : void 0;
|
|
27436
|
+
const body = genBlockContent(ir.block, context, true);
|
|
27437
|
+
if (context.needsTemplateRefSetter) push(NEWLINE, `const ${setTemplateRefIdent} = ${templateRefSetterHelper}()`);
|
|
27438
|
+
else if (templateRefSetterHelper) context.helpers.delete("createTemplateRefSetter");
|
|
27439
|
+
push(...body);
|
|
27109
27440
|
push(INDENT_END, NEWLINE);
|
|
27110
27441
|
if (!inline) push("}");
|
|
27111
27442
|
const delegates = genDelegates(context);
|
|
@@ -27140,6 +27471,11 @@ function genAssetImports({ ir }) {
|
|
|
27140
27471
|
}
|
|
27141
27472
|
return imports;
|
|
27142
27473
|
}
|
|
27474
|
+
function getStaticTemplateRefHelperCandidate(block) {
|
|
27475
|
+
if (block.operation.length !== 1) return;
|
|
27476
|
+
const operation = block.operation[0];
|
|
27477
|
+
if (operation.type === 9 && !operation.effect && !operation.refFor && operation.value.isStatic) return operation;
|
|
27478
|
+
}
|
|
27143
27479
|
//#endregion
|
|
27144
27480
|
//#region packages/compiler-vapor/src/transforms/vBind.ts
|
|
27145
27481
|
function normalizeBindShorthand(arg, context) {
|
|
@@ -27306,6 +27642,7 @@ function resolveSetupReference(name, context) {
|
|
|
27306
27642
|
}
|
|
27307
27643
|
const dynamicKeys = ["indeterminate"];
|
|
27308
27644
|
const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
|
|
27645
|
+
const UNSAFE_ATTR_NAME_RE = /[\u0000-\u0020"'<=/>]/;
|
|
27309
27646
|
function transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, omitEndTag) {
|
|
27310
27647
|
const { tag } = node;
|
|
27311
27648
|
const { scopeId } = context.options;
|
|
@@ -27323,18 +27660,55 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
27323
27660
|
}, getEffectIndex);
|
|
27324
27661
|
} else {
|
|
27325
27662
|
let prevWasQuoted = false;
|
|
27663
|
+
const appendTemplateProp = (key, value = "", generated = false) => {
|
|
27664
|
+
if (!prevWasQuoted) template += ` `;
|
|
27665
|
+
template += key;
|
|
27666
|
+
if (value) {
|
|
27667
|
+
const escapedValue = generated ? escapeGeneratedAttrValue(value) : value.replace(/"/g, """);
|
|
27668
|
+
template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${escapedValue}"` : `=${escapedValue}`;
|
|
27669
|
+
} else prevWasQuoted = false;
|
|
27670
|
+
};
|
|
27326
27671
|
for (const prop of propsResult[1]) {
|
|
27327
27672
|
const { key, values } = prop;
|
|
27328
27673
|
if (context.imports.some((imported) => values[0].content.includes(imported.exp.content))) {
|
|
27329
27674
|
if (!prevWasQuoted) template += ` `;
|
|
27330
27675
|
template += `${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
|
|
27331
27676
|
prevWasQuoted = true;
|
|
27677
|
+
} else if (key.isStatic && !prop.modifier && isBooleanAttr(key.content)) if (values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
27678
|
+
const value = values[0].content === "''" ? "" : values[0].content;
|
|
27679
|
+
appendTemplateProp(key.content, value);
|
|
27680
|
+
} else {
|
|
27681
|
+
const include = foldBooleanAttrValue(values);
|
|
27682
|
+
if (include != null) {
|
|
27683
|
+
if (include) appendTemplateProp(key.content);
|
|
27684
|
+
} else {
|
|
27685
|
+
dynamicProps.push(key.content);
|
|
27686
|
+
context.registerEffect(values, {
|
|
27687
|
+
type: 3,
|
|
27688
|
+
element: context.reference(),
|
|
27689
|
+
prop,
|
|
27690
|
+
tag
|
|
27691
|
+
}, getEffectIndex);
|
|
27692
|
+
}
|
|
27693
|
+
}
|
|
27694
|
+
else if (key.isStatic && !prop.modifier && hasBoundValue(values)) {
|
|
27695
|
+
let foldedValue;
|
|
27696
|
+
if (key.content === "class") foldedValue = foldClassValues(values);
|
|
27697
|
+
else if (key.content === "style") foldedValue = foldStyleValues(values);
|
|
27698
|
+
if (foldedValue != null) {
|
|
27699
|
+
if (foldedValue) appendTemplateProp(key.content, foldedValue, true);
|
|
27700
|
+
} else {
|
|
27701
|
+
dynamicProps.push(key.content);
|
|
27702
|
+
context.registerEffect(values, {
|
|
27703
|
+
type: 3,
|
|
27704
|
+
element: context.reference(),
|
|
27705
|
+
prop,
|
|
27706
|
+
tag
|
|
27707
|
+
}, getEffectIndex);
|
|
27708
|
+
}
|
|
27332
27709
|
} else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
27333
|
-
if (!prevWasQuoted) template += ` `;
|
|
27334
27710
|
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;
|
|
27711
|
+
appendTemplateProp(key.content, value);
|
|
27338
27712
|
} else {
|
|
27339
27713
|
dynamicProps.push(key.content);
|
|
27340
27714
|
context.registerEffect(values, {
|
|
@@ -27356,6 +27730,123 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
27356
27730
|
} else context.template += template;
|
|
27357
27731
|
if (staticKey) context.registerOperation(createSetBlockKey(context.reference(), staticKey));
|
|
27358
27732
|
}
|
|
27733
|
+
function escapeGeneratedAttrValue(value) {
|
|
27734
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
27735
|
+
}
|
|
27736
|
+
function foldBooleanAttrValue(values) {
|
|
27737
|
+
if (values.length !== 1) return;
|
|
27738
|
+
const evaluated = evaluateConstantExpression(values[0]);
|
|
27739
|
+
if (!evaluated) return;
|
|
27740
|
+
const value = evaluated.value;
|
|
27741
|
+
if (value === true || value === false || value == null) return includeBooleanAttr(value);
|
|
27742
|
+
}
|
|
27743
|
+
function foldStyleValues(values) {
|
|
27744
|
+
const evaluatedValues = [];
|
|
27745
|
+
for (const value of values) {
|
|
27746
|
+
const evaluated = evaluateConstantExpression(value);
|
|
27747
|
+
if (!evaluated || !isStaticStyleValue(evaluated.value)) return;
|
|
27748
|
+
evaluatedValues.push(evaluated.value);
|
|
27749
|
+
}
|
|
27750
|
+
return stringifyStyle(normalizeStyle(evaluatedValues.length === 1 ? evaluatedValues[0] : evaluatedValues));
|
|
27751
|
+
}
|
|
27752
|
+
function isStaticStyleValue(value) {
|
|
27753
|
+
if (typeof value === "string") return true;
|
|
27754
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
27755
|
+
for (const key in value) {
|
|
27756
|
+
const propValue = value[key];
|
|
27757
|
+
if (!isSafeStylePropertyName(key) || !isSafeStylePropertyValue(propValue)) return false;
|
|
27758
|
+
}
|
|
27759
|
+
return true;
|
|
27760
|
+
}
|
|
27761
|
+
function isSafeStylePropertyName(key) {
|
|
27762
|
+
return !!key && !/[;:]/.test(key);
|
|
27763
|
+
}
|
|
27764
|
+
function isSafeStylePropertyValue(value) {
|
|
27765
|
+
return typeof value === "number" || typeof value === "string" && !value.includes(";");
|
|
27766
|
+
}
|
|
27767
|
+
function hasBoundValue(values) {
|
|
27768
|
+
return values.some((value) => !value.isStatic && value.content !== "''");
|
|
27769
|
+
}
|
|
27770
|
+
function foldClassValues(values) {
|
|
27771
|
+
let templateValue = "";
|
|
27772
|
+
let changed = false;
|
|
27773
|
+
for (const value of values) {
|
|
27774
|
+
const evaluated = evaluateConstantExpression(value);
|
|
27775
|
+
if (evaluated) {
|
|
27776
|
+
const normalized = normalizeClass(evaluated.value);
|
|
27777
|
+
if (normalized) templateValue = appendClass(templateValue, normalized);
|
|
27778
|
+
else changed = true;
|
|
27779
|
+
continue;
|
|
27780
|
+
}
|
|
27781
|
+
return;
|
|
27782
|
+
}
|
|
27783
|
+
return changed || templateValue ? templateValue : void 0;
|
|
27784
|
+
}
|
|
27785
|
+
function appendClass(base, value) {
|
|
27786
|
+
return base ? value ? `${base} ${value}` : base : value;
|
|
27787
|
+
}
|
|
27788
|
+
function getObjectPropertyName(prop) {
|
|
27789
|
+
const key = prop.key;
|
|
27790
|
+
if (key.type === "Identifier") return key.name;
|
|
27791
|
+
else if (key.type === "StringLiteral") return key.value;
|
|
27792
|
+
else if (key.type === "NumericLiteral") return String(key.value);
|
|
27793
|
+
}
|
|
27794
|
+
function evaluateConstantExpression(node) {
|
|
27795
|
+
if (node.isStatic) return { value: node.content };
|
|
27796
|
+
const ast = node.ast;
|
|
27797
|
+
if (ast === null) {
|
|
27798
|
+
if (node.content === "true") return { value: true };
|
|
27799
|
+
else if (node.content === "false") return { value: false };
|
|
27800
|
+
else if (node.content === "null") return { value: null };
|
|
27801
|
+
else if (node.content === "undefined") return { value: void 0 };
|
|
27802
|
+
}
|
|
27803
|
+
if (!ast) return;
|
|
27804
|
+
return evaluateConstantAst(ast);
|
|
27805
|
+
}
|
|
27806
|
+
function evaluateConstantAst(node) {
|
|
27807
|
+
switch (node.type) {
|
|
27808
|
+
case "StringLiteral": return { value: node.value };
|
|
27809
|
+
case "NumericLiteral": return { value: node.value };
|
|
27810
|
+
case "BooleanLiteral": return { value: node.value };
|
|
27811
|
+
case "NullLiteral": return { value: null };
|
|
27812
|
+
case "Identifier": return node.name === "undefined" ? { value: void 0 } : void 0;
|
|
27813
|
+
case "UnaryExpression":
|
|
27814
|
+
if (node.operator === "void") return { value: void 0 };
|
|
27815
|
+
else if (node.operator === "-") {
|
|
27816
|
+
const value = evaluateConstantAst(node.argument);
|
|
27817
|
+
return value && typeof value.value === "number" ? { value: -value.value } : void 0;
|
|
27818
|
+
}
|
|
27819
|
+
return;
|
|
27820
|
+
case "TemplateLiteral": return evaluateTemplateLiteral(node);
|
|
27821
|
+
case "ObjectExpression": return evaluateObjectExpression(node);
|
|
27822
|
+
}
|
|
27823
|
+
}
|
|
27824
|
+
function evaluateTemplateLiteral(node) {
|
|
27825
|
+
if (node.type !== "TemplateLiteral") return;
|
|
27826
|
+
let value = "";
|
|
27827
|
+
for (const [index, quasi] of node.quasis.entries()) {
|
|
27828
|
+
value += quasi.value.cooked || "";
|
|
27829
|
+
const expression = node.expressions[index];
|
|
27830
|
+
if (expression) {
|
|
27831
|
+
const evaluated = evaluateConstantAst(expression);
|
|
27832
|
+
if (!evaluated) return;
|
|
27833
|
+
value += evaluated.value;
|
|
27834
|
+
}
|
|
27835
|
+
}
|
|
27836
|
+
return { value };
|
|
27837
|
+
}
|
|
27838
|
+
function evaluateObjectExpression(node) {
|
|
27839
|
+
const value = {};
|
|
27840
|
+
for (const prop of node.properties) {
|
|
27841
|
+
if (prop.type !== "ObjectProperty" || prop.computed) return;
|
|
27842
|
+
const key = getObjectPropertyName(prop);
|
|
27843
|
+
if (key == null) return;
|
|
27844
|
+
const evaluated = evaluateConstantAst(prop.value);
|
|
27845
|
+
if (!evaluated) return;
|
|
27846
|
+
value[key] = evaluated.value;
|
|
27847
|
+
}
|
|
27848
|
+
return { value };
|
|
27849
|
+
}
|
|
27359
27850
|
function resolveStaticKey(node, context, isComponent) {
|
|
27360
27851
|
const keyProp = findProp(node, "key", false, true);
|
|
27361
27852
|
if (!keyProp) return;
|
|
@@ -27382,27 +27873,42 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
27382
27873
|
results = [];
|
|
27383
27874
|
}
|
|
27384
27875
|
}
|
|
27876
|
+
function pushStaticObjectLiteralProps(props) {
|
|
27877
|
+
if (dynamicArgs.length) {
|
|
27878
|
+
pushMergeArg();
|
|
27879
|
+
dynamicArgs.push(props);
|
|
27880
|
+
} else results.push(...props.map(toDirectiveResult));
|
|
27881
|
+
}
|
|
27385
27882
|
for (const prop of props) {
|
|
27386
27883
|
if (prop.type === 7 && !prop.arg) {
|
|
27387
27884
|
if (prop.name === "bind") {
|
|
27388
27885
|
if (prop.exp) {
|
|
27389
|
-
|
|
27390
|
-
|
|
27391
|
-
|
|
27392
|
-
|
|
27393
|
-
|
|
27394
|
-
|
|
27886
|
+
const objectLiteralProps = isComponent ? resolveComponentObjectLiteralBindProps(prop.exp, context, props, prop) : resolveNativeObjectLiteralBindProps(prop.exp, context, props, prop);
|
|
27887
|
+
if (objectLiteralProps) if (isComponent) pushStaticObjectLiteralProps(objectLiteralProps);
|
|
27888
|
+
else results.push(...objectLiteralProps.map(toDirectiveResult));
|
|
27889
|
+
else {
|
|
27890
|
+
dynamicExpr.push(prop.exp);
|
|
27891
|
+
pushMergeArg();
|
|
27892
|
+
dynamicArgs.push({
|
|
27893
|
+
kind: 0,
|
|
27894
|
+
value: prop.exp
|
|
27895
|
+
});
|
|
27896
|
+
}
|
|
27395
27897
|
} else context.options.onError(createCompilerError(34, prop.loc));
|
|
27396
27898
|
continue;
|
|
27397
27899
|
} else if (prop.name === "on") {
|
|
27398
27900
|
if (prop.exp) if (isComponent) {
|
|
27399
|
-
|
|
27400
|
-
|
|
27401
|
-
|
|
27402
|
-
|
|
27403
|
-
|
|
27404
|
-
|
|
27405
|
-
|
|
27901
|
+
const objectLiteralProps = resolveComponentObjectLiteralOnProps(prop.exp, context, props, prop);
|
|
27902
|
+
if (objectLiteralProps) pushStaticObjectLiteralProps(objectLiteralProps);
|
|
27903
|
+
else {
|
|
27904
|
+
dynamicExpr.push(prop.exp);
|
|
27905
|
+
pushMergeArg();
|
|
27906
|
+
dynamicArgs.push({
|
|
27907
|
+
kind: 0,
|
|
27908
|
+
value: prop.exp,
|
|
27909
|
+
handler: true
|
|
27910
|
+
});
|
|
27911
|
+
}
|
|
27406
27912
|
} else context.registerEffect([prop.exp], {
|
|
27407
27913
|
type: 7,
|
|
27408
27914
|
element: context.reference(),
|
|
@@ -27432,6 +27938,151 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
27432
27938
|
}
|
|
27433
27939
|
return [false, dedupeProperties(results)];
|
|
27434
27940
|
}
|
|
27941
|
+
function resolveObjectLiteralProps(exp, context, keyTransform, isValidKey) {
|
|
27942
|
+
const ast = exp.ast;
|
|
27943
|
+
if (!ast || ast.type !== "ObjectExpression") return;
|
|
27944
|
+
const props = [];
|
|
27945
|
+
const knownKeys = /* @__PURE__ */ new Set();
|
|
27946
|
+
for (const property of ast.properties) {
|
|
27947
|
+
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
27948
|
+
let key = getObjectPropertyName(property);
|
|
27949
|
+
if (key == null || key === "__proto__") return;
|
|
27950
|
+
if (isValidKey && !isValidKey(key)) return;
|
|
27951
|
+
if (keyTransform) key = keyTransform(key);
|
|
27952
|
+
if (knownKeys.has(key)) return;
|
|
27953
|
+
knownKeys.add(key);
|
|
27954
|
+
props.push({
|
|
27955
|
+
key: createSimpleExpression(key, true),
|
|
27956
|
+
values: [resolveExpression(createObjectBindSubExpression(exp, property.value, context), true)]
|
|
27957
|
+
});
|
|
27958
|
+
}
|
|
27959
|
+
return props;
|
|
27960
|
+
}
|
|
27961
|
+
function resolveComponentObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
27962
|
+
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeObjectLiteralBindKey);
|
|
27963
|
+
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
27964
|
+
return props;
|
|
27965
|
+
}
|
|
27966
|
+
function resolveNativeObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
27967
|
+
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeNativeObjectLiteralBindKey);
|
|
27968
|
+
if (!props || hasNativeObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
27969
|
+
return props;
|
|
27970
|
+
}
|
|
27971
|
+
function resolveComponentObjectLiteralOnProps(exp, context, nodeProps, currentProp) {
|
|
27972
|
+
const props = resolveObjectLiteralProps(exp, context, toHandlerKey);
|
|
27973
|
+
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
27974
|
+
return props;
|
|
27975
|
+
}
|
|
27976
|
+
function isSafeNativeObjectLiteralBindKey(key) {
|
|
27977
|
+
return key !== "" && !UNSAFE_ATTR_NAME_RE.test(key) && isSafeObjectLiteralBindKey(key) && !isOn(key) && key.charCodeAt(0) !== 46 && key.charCodeAt(0) !== 94;
|
|
27978
|
+
}
|
|
27979
|
+
function isSafeObjectLiteralBindKey(key) {
|
|
27980
|
+
return !isReservedProp(key);
|
|
27981
|
+
}
|
|
27982
|
+
function hasComponentObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
27983
|
+
const keys = createComponentConflictKeySet(objectLiteralProps.map((prop) => prop.key.content));
|
|
27984
|
+
for (const prop of props) {
|
|
27985
|
+
if (prop === currentProp) continue;
|
|
27986
|
+
let key;
|
|
27987
|
+
if (prop.type === 6) key = prop.name;
|
|
27988
|
+
else if (prop.name === "bind") {
|
|
27989
|
+
if (!prop.arg) {
|
|
27990
|
+
const bindKeys = getObjectLiteralKeys(prop.exp);
|
|
27991
|
+
if (bindKeys && hasComponentKeyOverlap(keys, bindKeys)) return true;
|
|
27992
|
+
continue;
|
|
27993
|
+
}
|
|
27994
|
+
key = getStaticBindKey(prop);
|
|
27995
|
+
} else if (prop.name === "on") key = getStaticHandlerKey(prop);
|
|
27996
|
+
else if (prop.name === "model") {
|
|
27997
|
+
if (hasComponentModelKey(keys, prop)) return true;
|
|
27998
|
+
}
|
|
27999
|
+
if (key && hasComponentKey(keys, key)) return true;
|
|
28000
|
+
}
|
|
28001
|
+
return false;
|
|
28002
|
+
}
|
|
28003
|
+
function hasComponentModelKey(keys, prop) {
|
|
28004
|
+
const { arg } = prop;
|
|
28005
|
+
if (arg && (arg.type !== 4 || !arg.isStatic)) return true;
|
|
28006
|
+
const key = arg ? arg.content : "modelValue";
|
|
28007
|
+
return hasComponentKey(keys, key) || hasComponentKey(keys, `onUpdate:${camelize(key)}`) || prop.modifiers.length > 0 && hasComponentKey(keys, getModifierPropName(key));
|
|
28008
|
+
}
|
|
28009
|
+
function hasNativeObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
28010
|
+
const keys = new Set(objectLiteralProps.map((prop) => prop.key.content));
|
|
28011
|
+
for (const prop of props) {
|
|
28012
|
+
if (prop === currentProp) continue;
|
|
28013
|
+
let key;
|
|
28014
|
+
if (prop.type === 6) key = prop.name;
|
|
28015
|
+
else if (prop.name === "bind") {
|
|
28016
|
+
if (!prop.arg) return true;
|
|
28017
|
+
key = getStaticBindKey(prop);
|
|
28018
|
+
if (!key) return true;
|
|
28019
|
+
}
|
|
28020
|
+
if (key && keys.has(key)) return true;
|
|
28021
|
+
}
|
|
28022
|
+
return false;
|
|
28023
|
+
}
|
|
28024
|
+
function getStaticBindKey(prop) {
|
|
28025
|
+
const { arg } = prop;
|
|
28026
|
+
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
28027
|
+
let key = arg.content;
|
|
28028
|
+
if (isReservedProp(key)) return;
|
|
28029
|
+
if (prop.modifiers.some((modifier) => modifier.content === "camel")) key = camelize(key);
|
|
28030
|
+
return key;
|
|
28031
|
+
}
|
|
28032
|
+
function getStaticHandlerKey(prop) {
|
|
28033
|
+
const { arg } = prop;
|
|
28034
|
+
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
28035
|
+
let key = arg.content;
|
|
28036
|
+
if (key.startsWith("vue:")) key = `vnode-${key.slice(4)}`;
|
|
28037
|
+
const { nonKeyModifiers, eventOptionModifiers } = resolveModifiers(`on${key}`, prop.modifiers, null, prop.loc);
|
|
28038
|
+
if (key.toLowerCase() === "click") {
|
|
28039
|
+
if (nonKeyModifiers.includes("middle")) key = "mouseup";
|
|
28040
|
+
if (nonKeyModifiers.includes("right")) key = "contextmenu";
|
|
28041
|
+
}
|
|
28042
|
+
key = toHandlerKey(camelize(key));
|
|
28043
|
+
const optionPostfix = eventOptionModifiers.map(capitalize).join("");
|
|
28044
|
+
if (optionPostfix) key += optionPostfix;
|
|
28045
|
+
return key;
|
|
28046
|
+
}
|
|
28047
|
+
function getObjectLiteralKeys(exp) {
|
|
28048
|
+
const ast = exp && exp.ast;
|
|
28049
|
+
if (!ast || ast.type !== "ObjectExpression") return;
|
|
28050
|
+
const keys = /* @__PURE__ */ new Set();
|
|
28051
|
+
for (const property of ast.properties) {
|
|
28052
|
+
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
28053
|
+
const key = getObjectPropertyName(property);
|
|
28054
|
+
if (key == null) return;
|
|
28055
|
+
keys.add(key);
|
|
28056
|
+
}
|
|
28057
|
+
return keys;
|
|
28058
|
+
}
|
|
28059
|
+
function createComponentConflictKeySet(keys) {
|
|
28060
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
28061
|
+
for (const key of keys) {
|
|
28062
|
+
normalized.add(key);
|
|
28063
|
+
normalized.add(camelize(key));
|
|
28064
|
+
}
|
|
28065
|
+
return normalized;
|
|
28066
|
+
}
|
|
28067
|
+
function hasComponentKey(keys, key) {
|
|
28068
|
+
return keys.has(key) || keys.has(camelize(key));
|
|
28069
|
+
}
|
|
28070
|
+
function hasComponentKeyOverlap(left, right) {
|
|
28071
|
+
for (const key of right) if (hasComponentKey(left, key)) return true;
|
|
28072
|
+
return false;
|
|
28073
|
+
}
|
|
28074
|
+
function createObjectBindSubExpression(source, node, context) {
|
|
28075
|
+
const start = node.start == null ? 0 : node.start - 1;
|
|
28076
|
+
const end = node.end == null ? source.content.length : node.end - 1;
|
|
28077
|
+
const content = source.content.slice(start, end);
|
|
28078
|
+
const expression = createSimpleExpression(content, false, {
|
|
28079
|
+
start: advancePositionWithClone(source.loc.start, source.content, start),
|
|
28080
|
+
end: advancePositionWithClone(source.loc.start, source.content, end),
|
|
28081
|
+
source: content
|
|
28082
|
+
});
|
|
28083
|
+
expression.ast = isSimpleIdentifier(content) ? null : (0, import_lib.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
28084
|
+
return expression;
|
|
28085
|
+
}
|
|
27435
28086
|
function transformProp(prop, node, context) {
|
|
27436
28087
|
let { name } = prop;
|
|
27437
28088
|
if (prop.type === 6) {
|
|
@@ -27482,6 +28133,12 @@ function resolveDirectiveResult(prop) {
|
|
|
27482
28133
|
values: [prop.value]
|
|
27483
28134
|
});
|
|
27484
28135
|
}
|
|
28136
|
+
function toDirectiveResult(prop) {
|
|
28137
|
+
return extend({}, prop, {
|
|
28138
|
+
values: void 0,
|
|
28139
|
+
value: prop.values[0]
|
|
28140
|
+
});
|
|
28141
|
+
}
|
|
27485
28142
|
function mergePropValues(existing, incoming) {
|
|
27486
28143
|
const newValues = incoming.values;
|
|
27487
28144
|
existing.values.push(...newValues);
|
|
@@ -27996,6 +28653,7 @@ function processIf(node, dir, context) {
|
|
|
27996
28653
|
}
|
|
27997
28654
|
context.dynamic.flags |= 2;
|
|
27998
28655
|
const forceMultiRoot = shouldForceMultiRoot(context);
|
|
28656
|
+
const allowNoScope = context.block === context.root.block;
|
|
27999
28657
|
if (dir.name === "if") {
|
|
28000
28658
|
const id = context.reference();
|
|
28001
28659
|
context.dynamic.flags |= 4;
|
|
@@ -28006,7 +28664,7 @@ function processIf(node, dir, context) {
|
|
|
28006
28664
|
type: 15,
|
|
28007
28665
|
id
|
|
28008
28666
|
}, context.effectBoundary()), {}, {
|
|
28009
|
-
blockShape: encodeIfBlockShape(branch, forceMultiRoot),
|
|
28667
|
+
blockShape: encodeIfBlockShape(branch, forceMultiRoot, void 0, allowNoScope),
|
|
28010
28668
|
condition: dir.exp,
|
|
28011
28669
|
positive: branch,
|
|
28012
28670
|
index: context.root.nextIfIndex(),
|
|
@@ -28048,8 +28706,8 @@ function processIf(node, dir, context) {
|
|
|
28048
28706
|
};
|
|
28049
28707
|
return () => {
|
|
28050
28708
|
onExit();
|
|
28051
|
-
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot);
|
|
28052
|
-
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative);
|
|
28709
|
+
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot, void 0, allowNoScope);
|
|
28710
|
+
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative, allowNoScope);
|
|
28053
28711
|
};
|
|
28054
28712
|
}
|
|
28055
28713
|
}
|
|
@@ -28064,14 +28722,38 @@ function createIfBranch(node, context) {
|
|
|
28064
28722
|
context.reference();
|
|
28065
28723
|
return [branch, exitBlock];
|
|
28066
28724
|
}
|
|
28067
|
-
function encodeIfBlockShape(positive, forceMultiRoot = false, negative) {
|
|
28725
|
+
function encodeIfBlockShape(positive, forceMultiRoot = false, negative, allowNoScope = true) {
|
|
28068
28726
|
if (forceMultiRoot) return 10;
|
|
28069
|
-
|
|
28727
|
+
const positiveNoScope = allowNoScope && canSkipIfBranchScope(positive);
|
|
28728
|
+
const negativeNoScope = allowNoScope && negative && negative.type !== 15 && canSkipIfBranchScope(negative);
|
|
28729
|
+
return getBlockShape(positive) | getNegativeIfBranchShape(negative) << 2 | (positiveNoScope ? 32 : 0) | (negativeNoScope ? 64 : 0);
|
|
28070
28730
|
}
|
|
28071
|
-
function
|
|
28731
|
+
function getNegativeIfBranchShape(negative) {
|
|
28072
28732
|
if (!negative) return 0;
|
|
28073
28733
|
return negative.type === 15 ? 1 : getBlockShape(negative);
|
|
28074
28734
|
}
|
|
28735
|
+
function canSkipIfBranchScope(block) {
|
|
28736
|
+
if (block.effect.length || block.operation.length) return false;
|
|
28737
|
+
if (!isStaticBranch(block.node)) return false;
|
|
28738
|
+
if (block.returns.length === 0 || block.dynamic.children.length !== block.returns.length) return false;
|
|
28739
|
+
return block.returns.every((id) => {
|
|
28740
|
+
const returned = findReturnedDynamic(block, id);
|
|
28741
|
+
return !!(returned && returned.template != null && !returned.operation && !returned.hasDynamicChild && !(returned.flags & 6));
|
|
28742
|
+
});
|
|
28743
|
+
}
|
|
28744
|
+
function findReturnedDynamic(block, id) {
|
|
28745
|
+
return block.dynamic.children.find((child) => child.id === id);
|
|
28746
|
+
}
|
|
28747
|
+
function isStaticBranch(node) {
|
|
28748
|
+
if (node.type !== 1 || node.tagType !== 3 || node.children.length === 0) return false;
|
|
28749
|
+
return node.children.every((child) => isStaticTemplateNode(child));
|
|
28750
|
+
}
|
|
28751
|
+
function isStaticTemplateNode(node) {
|
|
28752
|
+
if (node.type === 2 || node.type === 3) return true;
|
|
28753
|
+
if (node.type !== 1 || node.tagType !== 0) return false;
|
|
28754
|
+
for (const prop of node.props) if (prop.type === 7 || prop.name === "ref") return false;
|
|
28755
|
+
return node.children.every((child) => isStaticTemplateNode(child));
|
|
28756
|
+
}
|
|
28075
28757
|
function shouldForceMultiRoot(context) {
|
|
28076
28758
|
const parent = context.parent && context.parent.node;
|
|
28077
28759
|
return !!parent && parent.type === 1 && parent.tagType === 3 && parent.props.some((prop) => prop.type === 7 && prop.name === "for");
|
|
@@ -28158,6 +28840,9 @@ const transformSlotOutlet = (node, context) => {
|
|
|
28158
28840
|
}
|
|
28159
28841
|
return () => {
|
|
28160
28842
|
exitBlock && exitBlock();
|
|
28843
|
+
let flags = 0;
|
|
28844
|
+
if (context.options.scopeId && !context.options.slotted) flags |= 1;
|
|
28845
|
+
if (context.inVOnce) flags |= 2;
|
|
28161
28846
|
context.dynamic.operation = _objectSpread2(_objectSpread2({
|
|
28162
28847
|
type: 13,
|
|
28163
28848
|
id
|
|
@@ -28165,8 +28850,7 @@ const transformSlotOutlet = (node, context) => {
|
|
|
28165
28850
|
name: slotName,
|
|
28166
28851
|
props: irProps,
|
|
28167
28852
|
fallback,
|
|
28168
|
-
|
|
28169
|
-
once: context.inVOnce
|
|
28853
|
+
flags
|
|
28170
28854
|
});
|
|
28171
28855
|
};
|
|
28172
28856
|
};
|
|
@@ -39926,25 +40610,28 @@ function resolveExt(filename, fs) {
|
|
|
39926
40610
|
const tsConfigCache = createCache();
|
|
39927
40611
|
const tsConfigRefMap = /* @__PURE__ */ new Map();
|
|
39928
40612
|
const fileToScopeCache = createCache();
|
|
40613
|
+
const fileToGlobalScopeCache = createCache();
|
|
39929
40614
|
/**
|
|
39930
40615
|
* @private
|
|
39931
40616
|
*/
|
|
39932
40617
|
function invalidateTypeCache(filename) {
|
|
39933
40618
|
filename = normalizePath(filename);
|
|
39934
40619
|
fileToScopeCache.delete(filename);
|
|
40620
|
+
fileToGlobalScopeCache.delete(filename);
|
|
39935
40621
|
tsConfigCache.delete(filename);
|
|
39936
40622
|
const affectedConfig = tsConfigRefMap.get(filename);
|
|
39937
40623
|
if (affectedConfig) tsConfigCache.delete(affectedConfig);
|
|
39938
40624
|
}
|
|
39939
40625
|
function fileToScope(ctx, filename, asGlobal = false) {
|
|
39940
|
-
const
|
|
40626
|
+
const cache = asGlobal ? fileToGlobalScopeCache : fileToScopeCache;
|
|
40627
|
+
const cached = cache.get(filename);
|
|
39941
40628
|
if (cached) return cached;
|
|
39942
40629
|
const fs = resolveFS(ctx);
|
|
39943
40630
|
const source = fs.readFile(filename) || "";
|
|
39944
40631
|
const body = parseFile(filename, source, fs, ctx.options.babelParserPlugins);
|
|
39945
40632
|
const scope = new TypeScope(filename, source, 0, recordImports(body));
|
|
39946
40633
|
recordTypes(ctx, body, scope, asGlobal);
|
|
39947
|
-
|
|
40634
|
+
cache.set(filename, scope);
|
|
39948
40635
|
return scope;
|
|
39949
40636
|
}
|
|
39950
40637
|
function parseFile(filename, content, fs, parserPlugins) {
|
|
@@ -41076,7 +41763,6 @@ function compileScript(sfc, options) {
|
|
|
41076
41763
|
const local = specifier.local.name;
|
|
41077
41764
|
const imported = getImportedName(specifier);
|
|
41078
41765
|
const source = node.source.value;
|
|
41079
|
-
if (vapor && ssr && specifier.type === "ImportSpecifier" && source === "vue" && imported === "defineVaporAsyncComponent") ctx.s.overwrite(specifier.start + startOffset, specifier.end + startOffset, `defineAsyncComponent as ${local}`);
|
|
41080
41766
|
const existing = ctx.userImports[local];
|
|
41081
41767
|
if (source === "vue" && MACROS.includes(imported)) {
|
|
41082
41768
|
if (local === imported) warnOnce(`\`${imported}\` is a compiler macro and no longer needs to be imported.`);
|
|
@@ -41471,7 +42157,7 @@ function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
|
|
|
41471
42157
|
//#endregion
|
|
41472
42158
|
//#region packages/compiler-sfc/src/index.ts
|
|
41473
42159
|
init_objectSpread2();
|
|
41474
|
-
const version = "3.6.0-beta.
|
|
42160
|
+
const version = "3.6.0-beta.14";
|
|
41475
42161
|
const parseCache = parseCache$1;
|
|
41476
42162
|
const errorMessages = _objectSpread2(_objectSpread2({}, errorMessages$1), DOMErrorMessages);
|
|
41477
42163
|
const walk = walk$2;
|