@vue/compiler-sfc 3.6.0-beta.11 → 3.6.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler-sfc.cjs.js +14 -11
- package/dist/compiler-sfc.d.ts +3 -3
- package/dist/compiler-sfc.esm-browser.js +1052 -184
- package/package.json +7 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-sfc v3.6.0-beta.
|
|
2
|
+
* @vue/compiler-sfc v3.6.0-beta.13
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -41,7 +41,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
41
41
|
throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
|
|
42
42
|
});
|
|
43
43
|
//#endregion
|
|
44
|
-
//#region \0@oxc-project+runtime@0.
|
|
44
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
|
|
45
45
|
function _typeof(o) {
|
|
46
46
|
"@babel/helpers - typeof";
|
|
47
47
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -52,7 +52,7 @@ function _typeof(o) {
|
|
|
52
52
|
}
|
|
53
53
|
var init_typeof = __esmMin((() => {}));
|
|
54
54
|
//#endregion
|
|
55
|
-
//#region \0@oxc-project+runtime@0.
|
|
55
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
|
|
56
56
|
function toPrimitive(t, r) {
|
|
57
57
|
if ("object" != _typeof(t) || !t) return t;
|
|
58
58
|
var e = t[Symbol.toPrimitive];
|
|
@@ -67,7 +67,7 @@ var init_toPrimitive = __esmMin((() => {
|
|
|
67
67
|
init_typeof();
|
|
68
68
|
}));
|
|
69
69
|
//#endregion
|
|
70
|
-
//#region \0@oxc-project+runtime@0.
|
|
70
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
|
|
71
71
|
function toPropertyKey(t) {
|
|
72
72
|
var i = toPrimitive(t, "string");
|
|
73
73
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
@@ -77,7 +77,7 @@ var init_toPropertyKey = __esmMin((() => {
|
|
|
77
77
|
init_toPrimitive();
|
|
78
78
|
}));
|
|
79
79
|
//#endregion
|
|
80
|
-
//#region \0@oxc-project+runtime@0.
|
|
80
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
|
|
81
81
|
function _defineProperty(e, r, t) {
|
|
82
82
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
83
83
|
value: t,
|
|
@@ -90,7 +90,7 @@ var init_defineProperty = __esmMin((() => {
|
|
|
90
90
|
init_toPropertyKey();
|
|
91
91
|
}));
|
|
92
92
|
//#endregion
|
|
93
|
-
//#region \0@oxc-project+runtime@0.
|
|
93
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/objectSpread2.js
|
|
94
94
|
function ownKeys(e, r) {
|
|
95
95
|
var t = Object.keys(e);
|
|
96
96
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -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) {
|
|
@@ -1069,6 +1076,12 @@ function write(buffer, value, offset, isLE, mLen, nBytes) {
|
|
|
1069
1076
|
for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8);
|
|
1070
1077
|
buffer[offset + i - d] |= s * 128;
|
|
1071
1078
|
}
|
|
1079
|
+
/*!
|
|
1080
|
+
* The buffer module from node.js, for the browser.
|
|
1081
|
+
*
|
|
1082
|
+
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
|
1083
|
+
* @license MIT
|
|
1084
|
+
*/
|
|
1072
1085
|
function kMaxLength() {
|
|
1073
1086
|
return Buffer$1.TYPED_ARRAY_SUPPORT ? 2147483647 : 1073741823;
|
|
1074
1087
|
}
|
|
@@ -16182,7 +16195,7 @@ var require_lib$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
16182
16195
|
exports.parseExpression = parseExpression;
|
|
16183
16196
|
}));
|
|
16184
16197
|
//#endregion
|
|
16185
|
-
//#region \0@oxc-project+runtime@0.
|
|
16198
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/asyncToGenerator.js
|
|
16186
16199
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
16187
16200
|
try {
|
|
16188
16201
|
var i = n[a](c), u = i.value;
|
|
@@ -20759,12 +20772,9 @@ const transformFor = createStructuralDirectiveTransform$1("for", (node, dir, con
|
|
|
20759
20772
|
const keyProp = findProp$1(node, `key`, false, true);
|
|
20760
20773
|
const isDirKey = keyProp && keyProp.type === 7;
|
|
20761
20774
|
let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
|
|
20762
|
-
|
|
20763
|
-
|
|
20764
|
-
if (isTemplate)
|
|
20765
|
-
if (memo) memo.exp = processExpression(memo.exp, context);
|
|
20766
|
-
if (keyProperty && keyProp.type !== 6) keyProperty.value = processExpression(keyProperty.value, context);
|
|
20767
|
-
}
|
|
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);
|
|
20768
20778
|
const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
|
|
20769
20779
|
const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
|
|
20770
20780
|
forNode.codegenNode = createVNodeCall(context, helper(FRAGMENT), void 0, renderExp, fragmentFlag, void 0, void 0, true, !isStableFragment, false, node.loc);
|
|
@@ -23365,6 +23375,7 @@ var init__polyfill_node_path = __esmMin((() => {
|
|
|
23365
23375
|
}));
|
|
23366
23376
|
//#endregion
|
|
23367
23377
|
//#region \0polyfill-node.punycode.js
|
|
23378
|
+
/*! https://mths.be/punycode v1.4.1 by @mathias */
|
|
23368
23379
|
/**
|
|
23369
23380
|
* A generic error utility function.
|
|
23370
23381
|
* @private
|
|
@@ -24910,7 +24921,8 @@ var TransformContext = class TransformContext {
|
|
|
24910
24921
|
this.operationIndex = this.block.operation.length;
|
|
24911
24922
|
this.isLastEffectiveChild = true;
|
|
24912
24923
|
this.isOnRightmostPath = true;
|
|
24913
|
-
this.
|
|
24924
|
+
this.templateCloseTags = void 0;
|
|
24925
|
+
this.templateCloseBlocks = false;
|
|
24914
24926
|
this.globalId = 0;
|
|
24915
24927
|
this.nextIdMap = null;
|
|
24916
24928
|
this.ifIndex = 0;
|
|
@@ -25036,11 +25048,6 @@ var TransformContext = class TransformContext {
|
|
|
25036
25048
|
while (effectiveParent && effectiveParent.node.type === 1 && effectiveParent.node.tagType === 3) effectiveParent = effectiveParent.parent;
|
|
25037
25049
|
const isLastEffectiveChild = this.isEffectivelyLastChild(index);
|
|
25038
25050
|
const isOnRightmostPath = this.isOnRightmostPath && isLastEffectiveChild;
|
|
25039
|
-
let hasInlineAncestorNeedingClose = this.hasInlineAncestorNeedingClose;
|
|
25040
|
-
if (this.node.type === 1) {
|
|
25041
|
-
if (this.node.tag === "template") hasInlineAncestorNeedingClose = false;
|
|
25042
|
-
else if (!hasInlineAncestorNeedingClose && !this.isOnRightmostPath && isInlineTag(this.node.tag)) hasInlineAncestorNeedingClose = true;
|
|
25043
|
-
}
|
|
25044
25051
|
return Object.assign(Object.create(TransformContext.prototype), this, {
|
|
25045
25052
|
node,
|
|
25046
25053
|
parent: this,
|
|
@@ -25055,7 +25062,8 @@ var TransformContext = class TransformContext {
|
|
|
25055
25062
|
effectiveParent,
|
|
25056
25063
|
isLastEffectiveChild,
|
|
25057
25064
|
isOnRightmostPath,
|
|
25058
|
-
|
|
25065
|
+
templateCloseTags: this.templateCloseTags,
|
|
25066
|
+
templateCloseBlocks: this.templateCloseBlocks
|
|
25059
25067
|
});
|
|
25060
25068
|
}
|
|
25061
25069
|
shiftEffectBoundaries(index, dynamic = this.dynamic) {
|
|
@@ -25248,6 +25256,9 @@ function genCall(name, ...frags) {
|
|
|
25248
25256
|
hasPlaceholder ? name[1] : "null"
|
|
25249
25257
|
], ...frags)];
|
|
25250
25258
|
}
|
|
25259
|
+
function getParserOptions(plugins) {
|
|
25260
|
+
return { plugins: plugins ? plugins.some((plugin) => plugin === "typescript") ? plugins : [...plugins, "typescript"] : ["typescript"] };
|
|
25261
|
+
}
|
|
25251
25262
|
function codeFragmentToString(code, context) {
|
|
25252
25263
|
const { options: { filename, sourceMap } } = context;
|
|
25253
25264
|
let map;
|
|
@@ -25322,7 +25333,9 @@ function genPrependNode(oper, { helper }) {
|
|
|
25322
25333
|
}
|
|
25323
25334
|
//#endregion
|
|
25324
25335
|
//#region packages/compiler-vapor/src/generators/expression.ts
|
|
25336
|
+
init_objectSpread2();
|
|
25325
25337
|
function genExpression(node, context, assignment) {
|
|
25338
|
+
node = context.getExpressionReplacement(node);
|
|
25326
25339
|
const { content, ast, isStatic, loc } = node;
|
|
25327
25340
|
if (isStatic) return [[
|
|
25328
25341
|
JSON.stringify(content),
|
|
@@ -25437,11 +25450,12 @@ function canPrefix(name) {
|
|
|
25437
25450
|
return true;
|
|
25438
25451
|
}
|
|
25439
25452
|
function processExpressions(context, expressions, shouldDeclare) {
|
|
25453
|
+
const expressionReplacements = /* @__PURE__ */ new Map();
|
|
25440
25454
|
const { seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
|
|
25441
25455
|
const reservedNames = new Set(seenIdentifier);
|
|
25442
|
-
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames);
|
|
25443
|
-
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames);
|
|
25444
|
-
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 });
|
|
25445
25459
|
}
|
|
25446
25460
|
function analyzeExpressions(expressions) {
|
|
25447
25461
|
const seenVariable = Object.create(null);
|
|
@@ -25499,7 +25513,13 @@ function analyzeExpressions(expressions) {
|
|
|
25499
25513
|
updatedVariable
|
|
25500
25514
|
};
|
|
25501
25515
|
}
|
|
25502
|
-
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) {
|
|
25503
25523
|
const declarations = [];
|
|
25504
25524
|
const expToReplacementMap = /* @__PURE__ */ new Map();
|
|
25505
25525
|
for (const [name, exps] of variableToExpMap) {
|
|
@@ -25532,14 +25552,15 @@ function processRepeatedVariables(context, seenVariable, variableToExpMap, expTo
|
|
|
25532
25552
|
}
|
|
25533
25553
|
}
|
|
25534
25554
|
for (const [exp, replacements] of expToReplacementMap) {
|
|
25555
|
+
let content = getProcessedExpression(exp, expressionReplacements).content;
|
|
25535
25556
|
replacements.flatMap(({ name, locs }) => locs.map(({ start, end }) => ({
|
|
25536
25557
|
start,
|
|
25537
25558
|
end,
|
|
25538
25559
|
name
|
|
25539
25560
|
}))).sort((a, b) => b.end - a.end).forEach(({ start, end, name }) => {
|
|
25540
|
-
|
|
25561
|
+
content = content.slice(0, start - 1) + name + content.slice(end - 1);
|
|
25541
25562
|
});
|
|
25542
|
-
exp
|
|
25563
|
+
setExpressionReplacement(expressionReplacements, exp, content, parseExp(context, content));
|
|
25543
25564
|
}
|
|
25544
25565
|
return declarations;
|
|
25545
25566
|
}
|
|
@@ -25555,13 +25576,14 @@ function shouldDeclareVariable(name, expToVariableMap, exps) {
|
|
|
25555
25576
|
if (vars.every((v) => v.every((e, idx) => e === first[idx]))) return false;
|
|
25556
25577
|
return true;
|
|
25557
25578
|
}
|
|
25558
|
-
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames) {
|
|
25579
|
+
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames, expressionReplacements) {
|
|
25559
25580
|
const declarations = [];
|
|
25560
25581
|
const seenExp = expressions.reduce((acc, exp) => {
|
|
25561
25582
|
const vars = expToVariableMap.get(exp);
|
|
25562
25583
|
if (!vars) return acc;
|
|
25584
|
+
const processed = getProcessedExpression(exp, expressionReplacements);
|
|
25563
25585
|
const variables = vars.map((v) => v.name);
|
|
25564
|
-
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;
|
|
25565
25587
|
return acc;
|
|
25566
25588
|
}, Object.create(null));
|
|
25567
25589
|
Object.entries(seenExp).forEach(([content, count]) => {
|
|
@@ -25570,13 +25592,13 @@ function processRepeatedExpressions(context, expressions, varDeclarations, updat
|
|
|
25570
25592
|
for (let i = varDeclarations.length - 1; i >= 0; i--) {
|
|
25571
25593
|
const item = varDeclarations[i];
|
|
25572
25594
|
if (!item.exps || !item.seenCount) continue;
|
|
25573
|
-
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)) {
|
|
25574
25596
|
delVars[item.name] = item.rawName;
|
|
25575
25597
|
reservedNames.delete(item.name);
|
|
25576
25598
|
varDeclarations.splice(i, 1);
|
|
25577
25599
|
}
|
|
25578
25600
|
}
|
|
25579
|
-
const value = extend({}, expressions.find((exp) => exp.content === content));
|
|
25601
|
+
const value = extend({}, getProcessedExpression(expressions.find((exp) => getProcessedExpression(exp, expressionReplacements).content === content), expressionReplacements));
|
|
25580
25602
|
Object.keys(delVars).forEach((name) => {
|
|
25581
25603
|
value.content = value.content.replace(name, delVars[name]);
|
|
25582
25604
|
if (value.ast) value.ast = parseExp(context, value.content);
|
|
@@ -25587,12 +25609,11 @@ function processRepeatedExpressions(context, expressions, varDeclarations, updat
|
|
|
25587
25609
|
value
|
|
25588
25610
|
});
|
|
25589
25611
|
expressions.forEach((exp) => {
|
|
25590
|
-
|
|
25591
|
-
|
|
25592
|
-
|
|
25593
|
-
|
|
25594
|
-
|
|
25595
|
-
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));
|
|
25596
25617
|
}
|
|
25597
25618
|
});
|
|
25598
25619
|
}
|
|
@@ -25630,9 +25651,7 @@ function escapeRegExp(string) {
|
|
|
25630
25651
|
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
25631
25652
|
}
|
|
25632
25653
|
function parseExp(context, content) {
|
|
25633
|
-
|
|
25634
|
-
const options = { plugins: plugins ? [...plugins, "typescript"] : ["typescript"] };
|
|
25635
|
-
return (0, import_lib.parseExpression)(`(${content})`, options);
|
|
25654
|
+
return (0, import_lib.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
25636
25655
|
}
|
|
25637
25656
|
function genVarName(exp) {
|
|
25638
25657
|
return `${exp.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/_+$/, "")}`;
|
|
@@ -25673,22 +25692,31 @@ const isMemberExpression = (node) => {
|
|
|
25673
25692
|
function genSetEvent(oper, context) {
|
|
25674
25693
|
const { helper } = context;
|
|
25675
25694
|
const { element, key, keyOverride, value, modifiers, delegate, effect } = oper;
|
|
25676
|
-
|
|
25677
|
-
const handler = [
|
|
25678
|
-
`${context.helper("createInvoker")}(`,
|
|
25679
|
-
...genEventHandler(context, [value], modifiers),
|
|
25680
|
-
`)`
|
|
25681
|
-
];
|
|
25682
|
-
const eventOptions = genEventOptions();
|
|
25695
|
+
let handler;
|
|
25683
25696
|
if (delegate) {
|
|
25684
25697
|
context.delegates.add(key.content);
|
|
25685
25698
|
if (!context.block.operation.some(isSameDelegateEvent)) return [
|
|
25686
25699
|
NEWLINE,
|
|
25687
25700
|
`n${element}.$evt${key.content} = `,
|
|
25688
|
-
...
|
|
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
|
+
`)`
|
|
25689
25715
|
];
|
|
25690
25716
|
}
|
|
25691
|
-
|
|
25717
|
+
function genDirectHandler() {
|
|
25718
|
+
return modifiers.keys.length || modifiers.nonKeys.length ? genEventHandler(context, [value], modifiers, { modifierHelper: "vapor" }) : genInvoker();
|
|
25719
|
+
}
|
|
25692
25720
|
function genName() {
|
|
25693
25721
|
const expr = genExpression(key, context);
|
|
25694
25722
|
if (keyOverride) {
|
|
@@ -25708,8 +25736,8 @@ function genSetEvent(oper, context) {
|
|
|
25708
25736
|
}
|
|
25709
25737
|
function genEventOptions() {
|
|
25710
25738
|
let { options } = modifiers;
|
|
25711
|
-
if (!options.length
|
|
25712
|
-
return genMulti(DELIMITERS_OBJECT_NEWLINE,
|
|
25739
|
+
if (!options.length) return;
|
|
25740
|
+
return genMulti(DELIMITERS_OBJECT_NEWLINE, ...options.map((option) => [`${option}: true`]));
|
|
25713
25741
|
}
|
|
25714
25742
|
function isSameDelegateEvent(op) {
|
|
25715
25743
|
if (op.type === 6 && op !== oper && op.delegate && op.element === oper.element && op.key.content === key.content) return true;
|
|
@@ -25722,7 +25750,9 @@ function genSetDynamicEvents(oper, context) {
|
|
|
25722
25750
|
function genEventHandler(context, values, modifiers = {
|
|
25723
25751
|
nonKeys: [],
|
|
25724
25752
|
keys: []
|
|
25725
|
-
},
|
|
25753
|
+
}, options = {}) {
|
|
25754
|
+
const { asComponentProp = false, extraWrap = false, modifierHelper = "runtime" } = options;
|
|
25755
|
+
const useVaporModifierHelper = modifierHelper === "vapor";
|
|
25726
25756
|
let handlerExp = [];
|
|
25727
25757
|
if (values) {
|
|
25728
25758
|
values.forEach((value, index) => {
|
|
@@ -25763,16 +25793,16 @@ function genEventHandler(context, values, modifiers = {
|
|
|
25763
25793
|
}
|
|
25764
25794
|
if (handlerExp.length === 0) handlerExp = ["() => {}"];
|
|
25765
25795
|
const { keys, nonKeys } = modifiers;
|
|
25766
|
-
if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys);
|
|
25767
|
-
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);
|
|
25768
25798
|
if (extraWrap) handlerExp.unshift(`() => `);
|
|
25769
25799
|
return handlerExp;
|
|
25770
25800
|
}
|
|
25771
|
-
function genWithModifiers(context, handler, nonKeys) {
|
|
25772
|
-
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));
|
|
25773
25803
|
}
|
|
25774
|
-
function genWithKeys(context, handler, keys) {
|
|
25775
|
-
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));
|
|
25776
25806
|
}
|
|
25777
25807
|
function isConstantBinding(value, context) {
|
|
25778
25808
|
if (value.ast === null) {
|
|
@@ -25810,16 +25840,12 @@ function genFor(oper, context) {
|
|
|
25810
25840
|
idMap[rawIndex] = `${indexVar}.value`;
|
|
25811
25841
|
idMap[indexVar] = null;
|
|
25812
25842
|
}
|
|
25813
|
-
const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap);
|
|
25843
|
+
const { selectorPatterns, keyOnlyBindingPatterns } = matchPatterns(render, keyProp, idMap, context);
|
|
25814
25844
|
const selectorDeclarations = [];
|
|
25815
|
-
const
|
|
25845
|
+
const selectorName = (i) => selectorPatterns.length > 1 ? `_selector${id}_${i}` : `_selector${id}`;
|
|
25816
25846
|
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
25817
25847
|
const { selector } = selectorPatterns[i];
|
|
25818
|
-
const selectorName = `
|
|
25819
|
-
selectorDeclarations.push(`let ${selectorName}`, NEWLINE);
|
|
25820
|
-
if (i === 0) selectorSetup.push(`({ createSelector }) => {`, INDENT_START);
|
|
25821
|
-
selectorSetup.push(NEWLINE, `${selectorName} = `, ...genCall(`createSelector`, [`() => `, ...genExpression(selector, context)]));
|
|
25822
|
-
if (i === selectorPatterns.length - 1) selectorSetup.push(INDENT_END, NEWLINE, "}");
|
|
25848
|
+
selectorDeclarations.push(`const ${selectorName(i)} = `, ...genCall(helper("createSelector"), [`() => `, ...genExpression(selector, context)]), NEWLINE);
|
|
25823
25849
|
}
|
|
25824
25850
|
const blockFn = context.withId(() => {
|
|
25825
25851
|
const frag = [];
|
|
@@ -25828,7 +25854,7 @@ function genFor(oper, context) {
|
|
|
25828
25854
|
const patternFrag = [];
|
|
25829
25855
|
for (let i = 0; i < selectorPatterns.length; i++) {
|
|
25830
25856
|
const { effect } = selectorPatterns[i];
|
|
25831
|
-
patternFrag.push(NEWLINE,
|
|
25857
|
+
patternFrag.push(NEWLINE, `${selectorName(i)}(`, ...genExpression(keyProp, context), `, () => {`, INDENT_START);
|
|
25832
25858
|
for (const oper of effect.operations) patternFrag.push(...genOperation(oper, context));
|
|
25833
25859
|
patternFrag.push(INDENT_END, NEWLINE, `})`);
|
|
25834
25860
|
}
|
|
@@ -25843,12 +25869,17 @@ function genFor(oper, context) {
|
|
|
25843
25869
|
let flags = 0;
|
|
25844
25870
|
if (onlyChild) flags |= 1;
|
|
25845
25871
|
if (component) flags |= 2;
|
|
25872
|
+
if (isFragmentBlock(render)) flags |= 16;
|
|
25873
|
+
if (!component && isSingleNodeBlock(render)) flags |= 8;
|
|
25846
25874
|
if (once) flags |= 4;
|
|
25875
|
+
const onResetCalls = [];
|
|
25876
|
+
for (let i = 0; i < selectorPatterns.length; i++) onResetCalls.push(NEWLINE, `n${id}.onReset(${selectorName(i)}.reset)`);
|
|
25847
25877
|
return [
|
|
25848
25878
|
NEWLINE,
|
|
25849
25879
|
...selectorDeclarations,
|
|
25850
25880
|
`const n${id} = `,
|
|
25851
|
-
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags ? String(flags) : void 0,
|
|
25881
|
+
...genCall([helper("createFor"), "undefined"], sourceExpr, blockFn, genCallback(keyProp), flags ? String(flags) : void 0),
|
|
25882
|
+
...onResetCalls
|
|
25852
25883
|
];
|
|
25853
25884
|
function genCallback(expr) {
|
|
25854
25885
|
if (!expr) return false;
|
|
@@ -25872,6 +25903,21 @@ function genFor(oper, context) {
|
|
|
25872
25903
|
return idMap;
|
|
25873
25904
|
}
|
|
25874
25905
|
}
|
|
25906
|
+
function isSingleNodeBlock(block) {
|
|
25907
|
+
const child = getSingleReturnedChild(block);
|
|
25908
|
+
return !!child && child.template != null;
|
|
25909
|
+
}
|
|
25910
|
+
function isFragmentBlock(block) {
|
|
25911
|
+
const child = getSingleReturnedChild(block);
|
|
25912
|
+
const operation = child && child.operation;
|
|
25913
|
+
if (!operation) return false;
|
|
25914
|
+
return operation.type === 13 || operation.type === 16 || operation.type === 17 || operation.type === 15 && !operation.once || operation.type === 12 && !!operation.dynamic && !operation.dynamic.isStatic;
|
|
25915
|
+
}
|
|
25916
|
+
function getSingleReturnedChild(block) {
|
|
25917
|
+
if (block.returns.length !== 1) return;
|
|
25918
|
+
const id = block.returns[0];
|
|
25919
|
+
for (const child of block.dynamic.children) if (child.id === id) return child;
|
|
25920
|
+
}
|
|
25875
25921
|
function parseValueDestructure(value, context) {
|
|
25876
25922
|
const map = /* @__PURE__ */ new Map();
|
|
25877
25923
|
if (value) {
|
|
@@ -25934,19 +25980,19 @@ function buildDestructureIdMap(idToPathMap, baseAccessor, plugins) {
|
|
|
25934
25980
|
}
|
|
25935
25981
|
if (pathInfo.dynamic) {
|
|
25936
25982
|
const node = idMap[id] = createSimpleExpression(path);
|
|
25937
|
-
node.ast = (0, import_lib.parseExpression)(`(${path})`,
|
|
25983
|
+
node.ast = (0, import_lib.parseExpression)(`(${path})`, getParserOptions(plugins));
|
|
25938
25984
|
} else idMap[id] = path;
|
|
25939
25985
|
} else idMap[id] = path;
|
|
25940
25986
|
});
|
|
25941
25987
|
return idMap;
|
|
25942
25988
|
}
|
|
25943
|
-
function matchPatterns(render, keyProp, idMap) {
|
|
25989
|
+
function matchPatterns(render, keyProp, idMap, context) {
|
|
25944
25990
|
const selectorPatterns = [];
|
|
25945
25991
|
const keyOnlyBindingPatterns = [];
|
|
25946
25992
|
const removedEffectIndexes = [];
|
|
25947
25993
|
render.effect = render.effect.filter((effect, index) => {
|
|
25948
25994
|
if (keyProp !== void 0) {
|
|
25949
|
-
const selector = matchSelectorPattern(effect, keyProp.content, idMap);
|
|
25995
|
+
const selector = matchSelectorPattern(effect, keyProp.content, idMap, context);
|
|
25950
25996
|
if (selector) {
|
|
25951
25997
|
selectorPatterns.push(selector);
|
|
25952
25998
|
removedEffectIndexes.push(index);
|
|
@@ -25985,7 +26031,7 @@ function matchKeyOnlyBindingPattern(effect, key) {
|
|
|
25985
26031
|
}
|
|
25986
26032
|
}
|
|
25987
26033
|
}
|
|
25988
|
-
function matchSelectorPattern(effect, key, idMap) {
|
|
26034
|
+
function matchSelectorPattern(effect, key, idMap, context) {
|
|
25989
26035
|
if (effect.expressions.length === 1) {
|
|
25990
26036
|
const { ast, content } = effect.expressions[0];
|
|
25991
26037
|
if (typeof ast === "object" && ast) {
|
|
@@ -26010,17 +26056,11 @@ function matchSelectorPattern(effect, key, idMap) {
|
|
|
26010
26056
|
}, false);
|
|
26011
26057
|
if (!hasExtraId) {
|
|
26012
26058
|
const name = content.slice(selector.start - 1, selector.end - 1);
|
|
26059
|
+
const selectorExpression = createSimpleExpression(name, false, selector.loc);
|
|
26060
|
+
selectorExpression.ast = (0, import_lib.parseExpression)(`(${name})`, getParserOptions(context.options.expressionPlugins));
|
|
26013
26061
|
return {
|
|
26014
26062
|
effect,
|
|
26015
|
-
selector:
|
|
26016
|
-
content: name,
|
|
26017
|
-
ast: extend({}, selector, {
|
|
26018
|
-
start: 1,
|
|
26019
|
-
end: name.length + 1
|
|
26020
|
-
}),
|
|
26021
|
-
loc: selector.loc,
|
|
26022
|
-
isStatic: false
|
|
26023
|
-
}
|
|
26063
|
+
selector: selectorExpression
|
|
26024
26064
|
};
|
|
26025
26065
|
}
|
|
26026
26066
|
}
|
|
@@ -26063,6 +26103,7 @@ function genIf(oper, context, isNested = false) {
|
|
|
26063
26103
|
const { helper } = context;
|
|
26064
26104
|
const { condition, positive, negative, once, index, blockShape } = oper;
|
|
26065
26105
|
const [frag, push] = buildCodeFragment();
|
|
26106
|
+
const flags = genIfFlags(blockShape, once, negative ? index : void 0);
|
|
26066
26107
|
const conditionExpr = [
|
|
26067
26108
|
"() => (",
|
|
26068
26109
|
...genExpression(condition, context),
|
|
@@ -26073,15 +26114,31 @@ function genIf(oper, context, isNested = false) {
|
|
|
26073
26114
|
if (negative) if (negative.type === 1) negativeArg = genBlock(negative, context);
|
|
26074
26115
|
else negativeArg = ["() => ", ...genIf(negative, context, true)];
|
|
26075
26116
|
if (!isNested) push(NEWLINE, `const n${oper.id} = `);
|
|
26076
|
-
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg,
|
|
26117
|
+
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, flags));
|
|
26077
26118
|
return frag;
|
|
26078
26119
|
}
|
|
26120
|
+
function genIfFlags(blockShape, once, index) {
|
|
26121
|
+
let flags = blockShape;
|
|
26122
|
+
if (once) flags |= 16;
|
|
26123
|
+
else if (index !== void 0) flags |= index + 1 << 7;
|
|
26124
|
+
if (flags === 1) return false;
|
|
26125
|
+
return `${flags} /* ${genIfFlagNames(once, index, blockShape)} */`;
|
|
26126
|
+
}
|
|
26127
|
+
function genIfFlagNames(once, index, blockShape) {
|
|
26128
|
+
const names = ["BLOCK_SHAPE"];
|
|
26129
|
+
if (blockShape & 32) names.push("TRUE_NO_SCOPE");
|
|
26130
|
+
if (blockShape & 64) names.push("FALSE_NO_SCOPE");
|
|
26131
|
+
if (once) names.push("ONCE");
|
|
26132
|
+
else if (index !== void 0) names.push("INDEX_SHIFT");
|
|
26133
|
+
return names.join(", ");
|
|
26134
|
+
}
|
|
26079
26135
|
//#endregion
|
|
26080
26136
|
//#region packages/compiler-vapor/src/generators/prop.ts
|
|
26081
26137
|
const helpers = {
|
|
26082
26138
|
setText: { name: "setText" },
|
|
26083
26139
|
setHtml: { name: "setHtml" },
|
|
26084
26140
|
setClass: { name: "setClass" },
|
|
26141
|
+
setClassName: { name: "setClassName" },
|
|
26085
26142
|
setStyle: { name: "setStyle" },
|
|
26086
26143
|
setValue: { name: "setValue" },
|
|
26087
26144
|
setAttr: {
|
|
@@ -26101,9 +26158,133 @@ function genSetProp(oper, context) {
|
|
|
26101
26158
|
const { helper } = context;
|
|
26102
26159
|
const { prop: { key, values, modifier }, tag } = oper;
|
|
26103
26160
|
const resolvedHelper = getRuntimeHelper(tag, key.content, modifier);
|
|
26161
|
+
if (key.content === "class" && !resolvedHelper.isSVG && resolvedHelper.name === "setClass") {
|
|
26162
|
+
const className = genSetClassName(oper, context);
|
|
26163
|
+
if (className) return className;
|
|
26164
|
+
}
|
|
26104
26165
|
const propValue = genPropValue(values, context);
|
|
26105
26166
|
return [NEWLINE, ...genCall([helper(resolvedHelper.name), null], `n${oper.element}`, resolvedHelper.needKey ? genExpression(key, context) : false, propValue, resolvedHelper.isSVG && "true")];
|
|
26106
26167
|
}
|
|
26168
|
+
const MAX_CLASS_NAME_ENTRIES = 31;
|
|
26169
|
+
function genSetClassName(oper, context) {
|
|
26170
|
+
const info = resolveClassName(oper.prop.values, context);
|
|
26171
|
+
if (!info) return;
|
|
26172
|
+
const { helper } = context;
|
|
26173
|
+
const flags = genClassFlags(info.entries, context);
|
|
26174
|
+
const classFragments = info.entries.map((entry) => JSON.stringify(!info.prefix && info.entries.length === 1 ? entry.className : ` ${entry.className}`));
|
|
26175
|
+
const fragments = classFragments.length === 1 ? classFragments[0] : genMulti(DELIMITERS_ARRAY, ...classFragments);
|
|
26176
|
+
return [NEWLINE, ...genCall([helper("setClassName"), "\"\""], `n${oper.element}`, flags, fragments, info.prefix && JSON.stringify(info.prefix), info.suffix && JSON.stringify(info.suffix))];
|
|
26177
|
+
}
|
|
26178
|
+
function resolveClassName(values, context) {
|
|
26179
|
+
let prefix = "";
|
|
26180
|
+
let suffix = "";
|
|
26181
|
+
const entries = [];
|
|
26182
|
+
let sawDynamic = false;
|
|
26183
|
+
let sawSuffix = false;
|
|
26184
|
+
for (const rawValue of values) {
|
|
26185
|
+
const value = context.getExpressionReplacement(rawValue);
|
|
26186
|
+
const staticValue = getLiteralExpressionValue(value, true);
|
|
26187
|
+
if (staticValue != null) {
|
|
26188
|
+
const normalized = normalizeClass(staticValue);
|
|
26189
|
+
if (normalized) if (sawSuffix) suffix = appendClass$1(suffix, normalized);
|
|
26190
|
+
else if (sawDynamic) {
|
|
26191
|
+
sawSuffix = true;
|
|
26192
|
+
suffix = appendClass$1(suffix, normalized);
|
|
26193
|
+
} else prefix = appendClass$1(prefix, normalized);
|
|
26194
|
+
continue;
|
|
26195
|
+
}
|
|
26196
|
+
const ast = value.ast;
|
|
26197
|
+
if (!ast || sawSuffix) return;
|
|
26198
|
+
sawDynamic = true;
|
|
26199
|
+
if (ast.type === "ObjectExpression") {
|
|
26200
|
+
if (!resolveObjectClassName(value, ast, entries, context)) return;
|
|
26201
|
+
} else if (ast.type === "ConditionalExpression") {
|
|
26202
|
+
if (!resolveConditionalClassName(value, ast, entries, context)) return;
|
|
26203
|
+
} else return;
|
|
26204
|
+
}
|
|
26205
|
+
return entries.length && entries.length <= MAX_CLASS_NAME_ENTRIES ? {
|
|
26206
|
+
prefix,
|
|
26207
|
+
suffix,
|
|
26208
|
+
entries
|
|
26209
|
+
} : void 0;
|
|
26210
|
+
}
|
|
26211
|
+
function resolveObjectClassName(source, ast, entries, context) {
|
|
26212
|
+
for (const prop of ast.properties) {
|
|
26213
|
+
if (prop.type !== "ObjectProperty" || prop.computed) return false;
|
|
26214
|
+
const rawClassName = getObjectPropertyName$1(prop);
|
|
26215
|
+
if (rawClassName == null) return false;
|
|
26216
|
+
const className = normalizeClass(rawClassName);
|
|
26217
|
+
if (!className) continue;
|
|
26218
|
+
const value = getBooleanValue(prop.value);
|
|
26219
|
+
entries.push({
|
|
26220
|
+
className,
|
|
26221
|
+
value,
|
|
26222
|
+
condition: value == null ? createSubExpression(source, prop.value, context) : void 0
|
|
26223
|
+
});
|
|
26224
|
+
}
|
|
26225
|
+
return true;
|
|
26226
|
+
}
|
|
26227
|
+
function resolveConditionalClassName(source, ast, entries, context) {
|
|
26228
|
+
const consequent = getStringClassValue(ast.consequent);
|
|
26229
|
+
const alternate = getStringClassValue(ast.alternate);
|
|
26230
|
+
if (consequent && alternate === "") {
|
|
26231
|
+
entries.push({
|
|
26232
|
+
className: consequent,
|
|
26233
|
+
condition: createSubExpression(source, ast.test, context)
|
|
26234
|
+
});
|
|
26235
|
+
return true;
|
|
26236
|
+
} else if (alternate && consequent === "") {
|
|
26237
|
+
entries.push({
|
|
26238
|
+
className: alternate,
|
|
26239
|
+
condition: createSubExpression(source, ast.test, context),
|
|
26240
|
+
negate: true
|
|
26241
|
+
});
|
|
26242
|
+
return true;
|
|
26243
|
+
}
|
|
26244
|
+
return false;
|
|
26245
|
+
}
|
|
26246
|
+
function genClassFlags(entries, context) {
|
|
26247
|
+
const values = [];
|
|
26248
|
+
entries.forEach((entry, index) => {
|
|
26249
|
+
if (index) values.push(" | ");
|
|
26250
|
+
const bit = 1 << index;
|
|
26251
|
+
if (entry.value != null) {
|
|
26252
|
+
values.push(entry.value ? String(bit) : "0");
|
|
26253
|
+
return;
|
|
26254
|
+
}
|
|
26255
|
+
values.push("(", ...genExpression(entry.condition, context), entry.negate ? ` ? 0 : ${bit}` : ` ? ${bit} : 0`, ")");
|
|
26256
|
+
});
|
|
26257
|
+
return values;
|
|
26258
|
+
}
|
|
26259
|
+
function appendClass$1(base, value) {
|
|
26260
|
+
return base ? value ? `${base} ${value}` : base : value;
|
|
26261
|
+
}
|
|
26262
|
+
function getObjectPropertyName$1(prop) {
|
|
26263
|
+
const key = prop.key;
|
|
26264
|
+
if (key.type === "Identifier") return key.name;
|
|
26265
|
+
else if (key.type === "StringLiteral") return key.value;
|
|
26266
|
+
else if (key.type === "NumericLiteral") return String(key.value);
|
|
26267
|
+
}
|
|
26268
|
+
function getStringClassValue(node) {
|
|
26269
|
+
if (node.type === "StringLiteral") return normalizeClass(node.value);
|
|
26270
|
+
else if (node.type === "TemplateLiteral" && node.expressions.length === 0) return normalizeClass(node.quasis[0].value.cooked || "");
|
|
26271
|
+
else if (node.type === "NullLiteral" || node.type === "BooleanLiteral" && !node.value) return "";
|
|
26272
|
+
}
|
|
26273
|
+
function getBooleanValue(node) {
|
|
26274
|
+
if (node.type === "BooleanLiteral") return node.value;
|
|
26275
|
+
}
|
|
26276
|
+
function createSubExpression(source, node, context) {
|
|
26277
|
+
const start = node.start == null ? 0 : node.start - 1;
|
|
26278
|
+
const end = node.end == null ? source.content.length : node.end - 1;
|
|
26279
|
+
const content = source.content.slice(start, end);
|
|
26280
|
+
const expression = createSimpleExpression(content, false, {
|
|
26281
|
+
start: advancePositionWithClone(source.loc.start, source.content, start),
|
|
26282
|
+
end: advancePositionWithClone(source.loc.start, source.content, end),
|
|
26283
|
+
source: content
|
|
26284
|
+
});
|
|
26285
|
+
expression.ast = isSimpleIdentifier(content) ? null : (0, import_lib.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
26286
|
+
return expression;
|
|
26287
|
+
}
|
|
26107
26288
|
function genDynamicProps$1(oper, context) {
|
|
26108
26289
|
const { helper } = context;
|
|
26109
26290
|
const isSVG = isSVGTag(oper.tag);
|
|
@@ -26170,8 +26351,23 @@ function getSpecialHelper(keyName, tagName, isSVG) {
|
|
|
26170
26351
|
const setTemplateRefIdent = `_setTemplateRef`;
|
|
26171
26352
|
function genSetTemplateRef(oper, context) {
|
|
26172
26353
|
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
26354
|
+
if (context.staticTemplateRefHelperCandidate === oper) return genSetStaticTemplateRef(oper, refValue, refKey, context);
|
|
26355
|
+
context.needsTemplateRefSetter = true;
|
|
26173
26356
|
return [NEWLINE, ...genCall(setTemplateRefIdent, `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
26174
26357
|
}
|
|
26358
|
+
function genSetStaticTemplateRef(oper, refValue, refKey, context) {
|
|
26359
|
+
return [NEWLINE, ...genCall(context.helper("setStaticTemplateRef"), `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
26360
|
+
}
|
|
26361
|
+
function genSetTemplateRefBinding(oper, context) {
|
|
26362
|
+
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
26363
|
+
const setter = context.inSlotBlock && setTemplateRefIdent;
|
|
26364
|
+
if (context.inSlotBlock) context.needsTemplateRefSetter = true;
|
|
26365
|
+
return [NEWLINE, ...genCall([context.helper("setTemplateRefBinding"), "undefined"], `n${oper.element}`, ["() => ", ...refValue], ...setter || oper.refFor || refKey ? [
|
|
26366
|
+
setter,
|
|
26367
|
+
oper.refFor && "true",
|
|
26368
|
+
refKey
|
|
26369
|
+
] : [])];
|
|
26370
|
+
}
|
|
26175
26371
|
function genRefValue(value, context) {
|
|
26176
26372
|
if (value && context.options.inline) {
|
|
26177
26373
|
const binding = context.options.bindingMetadata[value.content];
|
|
@@ -26275,15 +26471,18 @@ function filterCustomDirectives(id, operations) {
|
|
|
26275
26471
|
//#region packages/compiler-vapor/src/generators/component.ts
|
|
26276
26472
|
function genCreateComponent(operation, context) {
|
|
26277
26473
|
const { helper } = context;
|
|
26474
|
+
const singleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
26475
|
+
const useAssetComponentHelper = operation.asset && !operation.dynamic && context.block === context.ir.block && !!singleUseAssetComponentNames && singleUseAssetComponentNames.has(operation.tag);
|
|
26476
|
+
const maybeSelfReference = useAssetComponentHelper && operation.tag.endsWith("__self");
|
|
26278
26477
|
const tag = genTag();
|
|
26279
26478
|
const { root, props, slots, once } = operation;
|
|
26280
26479
|
const rawSlots = genRawSlots(slots, context);
|
|
26281
26480
|
const [ids, handlers] = processInlineHandlers(props, context);
|
|
26282
|
-
const rawProps = context.withId(() => genRawProps(props, context), ids);
|
|
26481
|
+
const rawProps = context.withId(() => genRawProps(props, context, true), ids);
|
|
26283
26482
|
return [
|
|
26284
26483
|
NEWLINE,
|
|
26285
26484
|
...handlers.reduce((acc, { name, value }) => {
|
|
26286
|
-
const handler = genEventHandler(context, [value]
|
|
26485
|
+
const handler = genEventHandler(context, [value]);
|
|
26287
26486
|
return [
|
|
26288
26487
|
...acc,
|
|
26289
26488
|
`const ${name} = `,
|
|
@@ -26292,7 +26491,7 @@ function genCreateComponent(operation, context) {
|
|
|
26292
26491
|
];
|
|
26293
26492
|
}, []),
|
|
26294
26493
|
`const n${operation.id} = `,
|
|
26295
|
-
...genCall(operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.useCreateElement ? helper("createPlainElement") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, root ? "true" : false, once && "true"),
|
|
26494
|
+
...genCall(operation.dynamic && !operation.dynamic.isStatic ? helper("createDynamicComponent") : operation.useCreateElement ? helper("createPlainElement") : useAssetComponentHelper ? helper("createAssetComponent") : operation.asset ? helper("createComponentWithFallback") : helper("createComponent"), tag, rawProps, rawSlots, root ? "true" : false, once && "true", maybeSelfReference && "true"),
|
|
26296
26495
|
...genDirectivesForElement(operation.id, context)
|
|
26297
26496
|
];
|
|
26298
26497
|
function genTag() {
|
|
@@ -26303,7 +26502,10 @@ function genCreateComponent(operation, context) {
|
|
|
26303
26502
|
...genExpression(operation.dynamic, context),
|
|
26304
26503
|
")"
|
|
26305
26504
|
];
|
|
26306
|
-
else if (
|
|
26505
|
+
else if (useAssetComponentHelper) {
|
|
26506
|
+
const name = maybeSelfReference ? operation.tag.slice(0, -6) : operation.tag;
|
|
26507
|
+
return JSON.stringify(name);
|
|
26508
|
+
} else if (operation.asset) return toValidAssetId(operation.tag, "component");
|
|
26307
26509
|
else {
|
|
26308
26510
|
const { tag } = operation;
|
|
26309
26511
|
const builtInTag = isBuiltInComponent(tag);
|
|
@@ -26343,14 +26545,14 @@ function processInlineHandlers(props, context) {
|
|
|
26343
26545
|
}
|
|
26344
26546
|
return [ids, handlers];
|
|
26345
26547
|
}
|
|
26346
|
-
function genRawProps(props, context) {
|
|
26548
|
+
function genRawProps(props, context, directStaticLiteralProps = false) {
|
|
26347
26549
|
const staticProps = props[0];
|
|
26348
26550
|
if (isArray$3(staticProps)) {
|
|
26349
26551
|
if (!staticProps.length && props.length === 1) return;
|
|
26350
|
-
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context));
|
|
26351
|
-
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context));
|
|
26552
|
+
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context, directStaticLiteralProps), directStaticLiteralProps);
|
|
26553
|
+
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context, directStaticLiteralProps), directStaticLiteralProps);
|
|
26352
26554
|
}
|
|
26353
|
-
function genStaticProps(props, context, dynamicProps) {
|
|
26555
|
+
function genStaticProps(props, context, dynamicProps, directStaticLiteralProps = false) {
|
|
26354
26556
|
const args = [];
|
|
26355
26557
|
const handlerGroups = /* @__PURE__ */ new Map();
|
|
26356
26558
|
const ensureHandlerGroup = (keyName, keyFrag) => {
|
|
@@ -26383,11 +26585,11 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
26383
26585
|
continue;
|
|
26384
26586
|
}
|
|
26385
26587
|
const keyFrag = genPropKey(prop, context);
|
|
26386
|
-
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
|
|
26387
|
-
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, true
|
|
26588
|
+
if (!!prop.handlerModifiers && (prop.handlerModifiers.keys.length > 0 || prop.handlerModifiers.nonKeys.length > 0) || prop.values.length <= 1) addHandler(keyName, keyFrag, genEventHandler(context, prop.values, prop.handlerModifiers, { asComponentProp: true }));
|
|
26589
|
+
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, { asComponentProp: true }));
|
|
26388
26590
|
continue;
|
|
26389
26591
|
}
|
|
26390
|
-
args.push(genProp(prop, context, true));
|
|
26592
|
+
args.push(genProp(prop, context, true, true, directStaticLiteralProps && isDirectStaticLiteralProp(prop, context)));
|
|
26391
26593
|
if (prop.model) {
|
|
26392
26594
|
if (prop.key.isStatic) {
|
|
26393
26595
|
const keyName = `onUpdate:${camelize(prop.key.content)}`;
|
|
@@ -26412,7 +26614,7 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
26412
26614
|
" + \"Modifiers\"]"
|
|
26413
26615
|
];
|
|
26414
26616
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
26415
|
-
args.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
|
|
26617
|
+
args.push([...modifiersKey, directStaticLiteralProps ? `: { ${modifiersVal} }` : `: () => ({ ${modifiersVal} })`]);
|
|
26416
26618
|
}
|
|
26417
26619
|
}
|
|
26418
26620
|
}
|
|
@@ -26427,13 +26629,13 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
26427
26629
|
if (dynamicProps) args.push([`$: `, ...dynamicProps]);
|
|
26428
26630
|
return genMulti(args.length > 1 ? DELIMITERS_OBJECT_NEWLINE : DELIMITERS_OBJECT, ...args);
|
|
26429
26631
|
}
|
|
26430
|
-
function genDynamicProps(props, context) {
|
|
26632
|
+
function genDynamicProps(props, context, directStaticLiteralProps = false) {
|
|
26431
26633
|
const { helper } = context;
|
|
26432
26634
|
const frags = [];
|
|
26433
26635
|
for (const p of props) {
|
|
26434
26636
|
let expr;
|
|
26435
26637
|
if (isArray$3(p)) {
|
|
26436
|
-
if (p.length) frags.push(genStaticProps(p, context));
|
|
26638
|
+
if (p.length) frags.push(genStaticProps(p, context, void 0, directStaticLiteralProps));
|
|
26437
26639
|
continue;
|
|
26438
26640
|
} else if (p.kind === 1) if (p.model) {
|
|
26439
26641
|
const entries = [genProp(p, context)];
|
|
@@ -26444,7 +26646,7 @@ function genDynamicProps(props, context) {
|
|
|
26444
26646
|
];
|
|
26445
26647
|
entries.push([
|
|
26446
26648
|
...updateKey,
|
|
26447
|
-
":
|
|
26649
|
+
": ",
|
|
26448
26650
|
...genModelHandler(p.values[0], context)
|
|
26449
26651
|
]);
|
|
26450
26652
|
const { modelModifiers } = p;
|
|
@@ -26455,10 +26657,10 @@ function genDynamicProps(props, context) {
|
|
|
26455
26657
|
" + \"Modifiers\"]"
|
|
26456
26658
|
];
|
|
26457
26659
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
26458
|
-
entries.push([...modifiersKey, `:
|
|
26660
|
+
entries.push([...modifiersKey, `: { ${modifiersVal} }`]);
|
|
26459
26661
|
}
|
|
26460
26662
|
expr = genMulti(DELIMITERS_OBJECT_NEWLINE, ...entries);
|
|
26461
|
-
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context));
|
|
26663
|
+
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context, false, false));
|
|
26462
26664
|
else {
|
|
26463
26665
|
expr = genExpression(p.value, context);
|
|
26464
26666
|
if (p.handler) expr = genCall(helper("toHandlers"), expr);
|
|
@@ -26471,27 +26673,79 @@ function genDynamicProps(props, context) {
|
|
|
26471
26673
|
}
|
|
26472
26674
|
if (frags.length) return genMulti(DELIMITERS_ARRAY_NEWLINE, ...frags);
|
|
26473
26675
|
}
|
|
26474
|
-
function genProp(prop, context, isStatic) {
|
|
26676
|
+
function genProp(prop, context, isStatic, wrapHandler = true, directStaticLiteral = false) {
|
|
26475
26677
|
const values = genPropValue(prop.values, context);
|
|
26476
26678
|
return [
|
|
26477
26679
|
...genPropKey(prop, context),
|
|
26478
26680
|
": ",
|
|
26479
|
-
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers,
|
|
26681
|
+
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, {
|
|
26682
|
+
asComponentProp: true,
|
|
26683
|
+
extraWrap: wrapHandler
|
|
26684
|
+
}) : isStatic ? directStaticLiteral ? values : [
|
|
26480
26685
|
"() => (",
|
|
26481
26686
|
...values,
|
|
26482
26687
|
")"
|
|
26483
26688
|
] : values
|
|
26484
26689
|
];
|
|
26485
26690
|
}
|
|
26691
|
+
/**
|
|
26692
|
+
* Static literal values are safe to emit directly because reading them cannot
|
|
26693
|
+
* touch reactive state. Keep handlers, v-model values, and dynamic expressions
|
|
26694
|
+
* as getter sources to preserve lazy access and merge semantics.
|
|
26695
|
+
*/
|
|
26696
|
+
function isDirectStaticLiteralProp(prop, context) {
|
|
26697
|
+
return prop.key.isStatic && prop.values.length === 1 && !prop.handler && !prop.model && isDirectConstantValue(prop.values[0], context);
|
|
26698
|
+
}
|
|
26699
|
+
function isDirectConstantValue(value, context) {
|
|
26700
|
+
value = context.getExpressionReplacement(value);
|
|
26701
|
+
if (value.isStatic) return true;
|
|
26702
|
+
const ast = value.ast;
|
|
26703
|
+
if (ast === null) return value.content === "true" || value.content === "false" || value.content === "null" || value.content === "undefined";
|
|
26704
|
+
if (!ast) return false;
|
|
26705
|
+
return isDirectConstantAst(ast);
|
|
26706
|
+
}
|
|
26707
|
+
function isDirectConstantAst(node) {
|
|
26708
|
+
switch (node.type) {
|
|
26709
|
+
case "StringLiteral":
|
|
26710
|
+
case "NumericLiteral":
|
|
26711
|
+
case "BooleanLiteral":
|
|
26712
|
+
case "NullLiteral":
|
|
26713
|
+
case "BigIntLiteral": return true;
|
|
26714
|
+
case "Identifier": return node.name === "undefined";
|
|
26715
|
+
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
26716
|
+
case "ArrayExpression": return node.elements.every((element) => element === null || element.type !== "SpreadElement" && isDirectConstantAst(element));
|
|
26717
|
+
case "ObjectExpression": return node.properties.every((prop) => prop.type === "ObjectProperty" && !prop.computed && isDirectConstantAst(prop.value));
|
|
26718
|
+
}
|
|
26719
|
+
return false;
|
|
26720
|
+
}
|
|
26721
|
+
function isDirectTemplateConstantAst(node) {
|
|
26722
|
+
switch (node.type) {
|
|
26723
|
+
case "StringLiteral":
|
|
26724
|
+
case "NumericLiteral":
|
|
26725
|
+
case "BooleanLiteral":
|
|
26726
|
+
case "NullLiteral":
|
|
26727
|
+
case "BigIntLiteral": return true;
|
|
26728
|
+
case "Identifier": return node.name === "undefined";
|
|
26729
|
+
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
26730
|
+
}
|
|
26731
|
+
return false;
|
|
26732
|
+
}
|
|
26486
26733
|
function genRawSlots(slots, context) {
|
|
26487
26734
|
if (!slots.length) return;
|
|
26488
26735
|
const staticSlots = slots[0];
|
|
26489
|
-
if (staticSlots.slotType === 0)
|
|
26490
|
-
|
|
26736
|
+
if (staticSlots.slotType === 0) {
|
|
26737
|
+
const defaultSlot = getSingleDefaultSlot(staticSlots);
|
|
26738
|
+
if (defaultSlot && slots.length === 1) return genSlotBlockWithProps(defaultSlot, context);
|
|
26739
|
+
return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
|
|
26740
|
+
} else return genStaticSlots({
|
|
26491
26741
|
slotType: 0,
|
|
26492
26742
|
slots: {}
|
|
26493
26743
|
}, context, slots);
|
|
26494
26744
|
}
|
|
26745
|
+
function getSingleDefaultSlot({ slots }) {
|
|
26746
|
+
const names = Object.keys(slots);
|
|
26747
|
+
return names.length === 1 && names[0] === "default" ? slots.default : void 0;
|
|
26748
|
+
}
|
|
26495
26749
|
function genStaticSlots({ slots }, context, dynamicSlots) {
|
|
26496
26750
|
const args = Object.keys(slots).map((name) => [`${JSON.stringify(name)}: `, ...genSlotBlockWithProps(slots[name], context)]);
|
|
26497
26751
|
if (dynamicSlots) args.push([`$: `, ...genDynamicSlots(dynamicSlots, context)]);
|
|
@@ -26513,11 +26767,23 @@ function genDynamicSlot(slot, context, withFunction = false) {
|
|
|
26513
26767
|
frag = genConditionalSlot(slot, context);
|
|
26514
26768
|
break;
|
|
26515
26769
|
}
|
|
26516
|
-
|
|
26770
|
+
if (!withFunction) return frag;
|
|
26771
|
+
return needsDynamicSlotSourceCtx(slot) ? [
|
|
26772
|
+
`${context.helper("withVaporCtx")}(() => (`,
|
|
26773
|
+
...frag,
|
|
26774
|
+
"))"
|
|
26775
|
+
] : [
|
|
26517
26776
|
"() => (",
|
|
26518
26777
|
...frag,
|
|
26519
26778
|
")"
|
|
26520
|
-
]
|
|
26779
|
+
];
|
|
26780
|
+
}
|
|
26781
|
+
function needsDynamicSlotSourceCtx(slot) {
|
|
26782
|
+
switch (slot.slotType) {
|
|
26783
|
+
case 1: return needsVaporCtx(slot.fn);
|
|
26784
|
+
case 2: return needsVaporCtx(slot.fn);
|
|
26785
|
+
case 3: return needsDynamicSlotSourceCtx(slot.positive) || (slot.negative ? needsDynamicSlotSourceCtx(slot.negative) : false);
|
|
26786
|
+
}
|
|
26521
26787
|
}
|
|
26522
26788
|
function genBasicDynamicSlot(slot, context) {
|
|
26523
26789
|
const { name, fn } = slot;
|
|
@@ -26571,7 +26837,9 @@ function genSlotBlockWithProps(oper, context) {
|
|
|
26571
26837
|
} else propsName = props.content;
|
|
26572
26838
|
const idMap = idToPathMap.size ? buildDestructureIdMap(idToPathMap, propsName || "", context.options.expressionPlugins) : {};
|
|
26573
26839
|
if (propsName) idMap[propsName] = null;
|
|
26840
|
+
const exitSlotBlock = context.enterSlotBlock();
|
|
26574
26841
|
let blockFn = context.withId(() => genBlock(oper, context, propsName ? [propsName] : []), idMap);
|
|
26842
|
+
exitSlotBlock();
|
|
26575
26843
|
exitScope && exitScope();
|
|
26576
26844
|
if (node.type === 1) {
|
|
26577
26845
|
if (needsVaporCtx(oper)) blockFn = [
|
|
@@ -26632,16 +26900,18 @@ function hasComponentOrSlotInIf(node) {
|
|
|
26632
26900
|
//#region packages/compiler-vapor/src/generators/slotOutlet.ts
|
|
26633
26901
|
function genSlotOutlet(oper, context) {
|
|
26634
26902
|
const { helper } = context;
|
|
26635
|
-
const { id, name, fallback,
|
|
26903
|
+
const { id, name, fallback, flags } = oper;
|
|
26636
26904
|
const [frag, push] = buildCodeFragment();
|
|
26637
|
-
|
|
26905
|
+
let fallbackArg;
|
|
26906
|
+
if (fallback) fallbackArg = genBlock(fallback, context);
|
|
26907
|
+
const createSlot = helper("createSlot");
|
|
26908
|
+
const rawPropsArg = genRawProps(oper.props, context, true);
|
|
26909
|
+
const nameArg = name.isStatic && name.content === "default" && !rawPropsArg && !fallbackArg && !flags ? void 0 : name.isStatic ? genExpression(name, context) : [
|
|
26638
26910
|
"() => (",
|
|
26639
26911
|
...genExpression(name, context),
|
|
26640
26912
|
")"
|
|
26641
26913
|
];
|
|
26642
|
-
|
|
26643
|
-
if (fallback) fallbackArg = genBlock(fallback, context);
|
|
26644
|
-
push(NEWLINE, `const n${id} = `, ...genCall(helper("createSlot"), nameExpr, genRawProps(oper.props, context) || "null", fallbackArg, noSlotted && "true", once && "true"));
|
|
26914
|
+
push(NEWLINE, `const n${id} = `, ...genCall(createSlot, nameArg, rawPropsArg, fallbackArg, flags ? String(flags) : void 0));
|
|
26645
26915
|
return frag;
|
|
26646
26916
|
}
|
|
26647
26917
|
//#endregion
|
|
@@ -26701,28 +26971,35 @@ function genEffects(effects, context, genExtraFrag) {
|
|
|
26701
26971
|
const [frag, push, unshift] = buildCodeFragment();
|
|
26702
26972
|
const shouldDeclare = genExtraFrag === void 0;
|
|
26703
26973
|
let operationsCount = 0;
|
|
26704
|
-
const { ids, frag: declarationFrags, varNames } = processExpressions(context, expressions, shouldDeclare);
|
|
26705
|
-
|
|
26706
|
-
|
|
26707
|
-
const
|
|
26708
|
-
|
|
26709
|
-
|
|
26710
|
-
|
|
26711
|
-
|
|
26712
|
-
|
|
26713
|
-
|
|
26714
|
-
|
|
26715
|
-
|
|
26716
|
-
|
|
26717
|
-
|
|
26718
|
-
|
|
26719
|
-
|
|
26720
|
-
|
|
26721
|
-
|
|
26722
|
-
|
|
26723
|
-
|
|
26724
|
-
|
|
26725
|
-
|
|
26974
|
+
const { ids, frag: declarationFrags, varNames, expressionReplacements } = processExpressions(context, expressions, shouldDeclare);
|
|
26975
|
+
if (shouldDeclare && !declarationFrags.length && !varNames.length) {
|
|
26976
|
+
const effect = effects.length === 1 ? effects[0] : void 0;
|
|
26977
|
+
const operation = effect && effect.operations.length === 1 ? effect.operations[0] : void 0;
|
|
26978
|
+
if (operation && operation.type === 9 && operation.effect && !operation.refFor) return context.withExpressionReplacements(expressionReplacements, () => context.withId(() => genSetTemplateRefBinding(operation, context), ids));
|
|
26979
|
+
}
|
|
26980
|
+
return context.withExpressionReplacements(expressionReplacements, () => {
|
|
26981
|
+
push(...declarationFrags);
|
|
26982
|
+
for (let i = 0; i < effects.length; i++) {
|
|
26983
|
+
const effect = effects[i];
|
|
26984
|
+
operationsCount += effect.operations.length;
|
|
26985
|
+
const frags = context.withId(() => genEffect(effect, context), ids);
|
|
26986
|
+
i > 0 && push(NEWLINE);
|
|
26987
|
+
if (frag[frag.length - 1] === ")" && frags[0] === "(") push(";");
|
|
26988
|
+
push(...frags);
|
|
26989
|
+
}
|
|
26990
|
+
if (frag.filter((frag) => frag === NEWLINE).length > 1 || operationsCount > 1 || declarationFrags.length > 0) {
|
|
26991
|
+
unshift(`{`, INDENT_START, NEWLINE);
|
|
26992
|
+
push(INDENT_END, NEWLINE, "}");
|
|
26993
|
+
if (!effects.length) unshift(NEWLINE);
|
|
26994
|
+
}
|
|
26995
|
+
if (effects.length) {
|
|
26996
|
+
unshift(NEWLINE, `${helper("renderEffect")}(() => `);
|
|
26997
|
+
push(`)`);
|
|
26998
|
+
}
|
|
26999
|
+
if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
|
|
27000
|
+
if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
|
|
27001
|
+
return frag;
|
|
27002
|
+
});
|
|
26726
27003
|
}
|
|
26727
27004
|
function genEffect({ operations }, context) {
|
|
26728
27005
|
const [frag, push] = buildCodeFragment();
|
|
@@ -26741,9 +27018,8 @@ function genTemplates(templates, context) {
|
|
|
26741
27018
|
const result = [];
|
|
26742
27019
|
templates.forEach(({ content, ns, root, static: isStatic }, i) => {
|
|
26743
27020
|
let args = JSON.stringify(content).replace(IMPORT_EXPR_RE, `" + $1 + "`);
|
|
26744
|
-
|
|
26745
|
-
|
|
26746
|
-
if (isStatic || ns) args += `, ${isStatic ? "true" : "false"}`;
|
|
27021
|
+
const flags = (root ? 1 : 0) | (isStatic ? 2 : 0);
|
|
27022
|
+
if (flags || ns) args += `, ${flags}`;
|
|
26747
27023
|
if (ns) args += `, ${ns}`;
|
|
26748
27024
|
result.push(`const ${context.tName(i)} = ${context.helper("template")}(${args})\n`);
|
|
26749
27025
|
});
|
|
@@ -26761,10 +27037,13 @@ function genSelf(dynamic, context, flushBeforeDynamic) {
|
|
|
26761
27037
|
return frag;
|
|
26762
27038
|
}
|
|
26763
27039
|
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flushBeforeDynamic) {
|
|
26764
|
-
const { helper } = context;
|
|
26765
27040
|
const [frag, push] = buildCodeFragment();
|
|
26766
27041
|
const { children } = dynamic;
|
|
26767
27042
|
let offset = 0;
|
|
27043
|
+
/**
|
|
27044
|
+
* `reusable` means the previous access target is a p* cursor that can be
|
|
27045
|
+
* reassigned by the next lookup. Referenced n* variables must stay stable.
|
|
27046
|
+
*/
|
|
26768
27047
|
let prev;
|
|
26769
27048
|
for (const [index, child] of children.entries()) {
|
|
26770
27049
|
if (child.flags & 2) offset--;
|
|
@@ -26781,27 +27060,118 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flush
|
|
|
26781
27060
|
}
|
|
26782
27061
|
const elementIndex = index + offset;
|
|
26783
27062
|
const logicalIndex = child.logicalIndex !== void 0 ? String(child.logicalIndex) : void 0;
|
|
26784
|
-
const
|
|
26785
|
-
|
|
26786
|
-
if (
|
|
26787
|
-
|
|
26788
|
-
|
|
26789
|
-
|
|
26790
|
-
|
|
26791
|
-
|
|
26792
|
-
|
|
26793
|
-
|
|
27063
|
+
const inlinePlaceholder = id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6);
|
|
27064
|
+
const accessPath = genAccessPath(context, from, child, elementIndex, logicalIndex, prev);
|
|
27065
|
+
if (inlinePlaceholder) {
|
|
27066
|
+
if (prev && prev[2]) {
|
|
27067
|
+
push(...genChildren(child, context, pushBlock, [
|
|
27068
|
+
"(",
|
|
27069
|
+
prev[0],
|
|
27070
|
+
" = ",
|
|
27071
|
+
...accessPath,
|
|
27072
|
+
")"
|
|
27073
|
+
], flushBeforeDynamic));
|
|
27074
|
+
prev = [
|
|
27075
|
+
prev[0],
|
|
27076
|
+
elementIndex,
|
|
27077
|
+
true
|
|
27078
|
+
];
|
|
27079
|
+
continue;
|
|
27080
|
+
}
|
|
27081
|
+
if (!hasAdjacentFollowingAccessChild(children, index, elementIndex, offset)) {
|
|
27082
|
+
push(...genChildren(child, context, pushBlock, accessPath, flushBeforeDynamic));
|
|
27083
|
+
continue;
|
|
27084
|
+
}
|
|
27085
|
+
}
|
|
27086
|
+
let variable;
|
|
27087
|
+
if (id === void 0 && prev && prev[2]) {
|
|
27088
|
+
variable = prev[0];
|
|
27089
|
+
pushBlock(NEWLINE, `${variable} = `, ...accessPath);
|
|
27090
|
+
} else {
|
|
27091
|
+
variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
|
|
27092
|
+
pushBlock(NEWLINE, id === void 0 ? `let ${variable} = ` : `const ${variable} = `, ...accessPath);
|
|
26794
27093
|
}
|
|
26795
27094
|
if (id === child.anchor && !child.hasDynamicChild) {
|
|
26796
27095
|
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
26797
27096
|
push(...genSelf(child, context, flushBeforeDynamic));
|
|
26798
27097
|
}
|
|
26799
27098
|
if (id !== void 0) push(...genDirectivesForElement(id, context));
|
|
26800
|
-
prev = [
|
|
27099
|
+
prev = [
|
|
27100
|
+
variable,
|
|
27101
|
+
elementIndex,
|
|
27102
|
+
id === void 0
|
|
27103
|
+
];
|
|
26801
27104
|
push(...genChildren(child, context, pushBlock, variable, flushBeforeDynamic));
|
|
26802
27105
|
}
|
|
26803
27106
|
return frag;
|
|
26804
27107
|
}
|
|
27108
|
+
/**
|
|
27109
|
+
* Build one DOM lookup path while preserving the fast sibling walk:
|
|
27110
|
+
* adjacent nodes use _next(prev), otherwise fall back to _nthChild(parent).
|
|
27111
|
+
*/
|
|
27112
|
+
function genAccessPath({ helper }, from, child, elementIndex, logicalIndex, prev) {
|
|
27113
|
+
if (prev) return elementIndex - prev[1] === 1 ? genCall(helper("next"), prev[0], logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
27114
|
+
if (elementIndex === 0) return genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0);
|
|
27115
|
+
const firstChild = genCall(helper("child"), from);
|
|
27116
|
+
return elementIndex === 1 ? genCall(helper("next"), firstChild, logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
27117
|
+
}
|
|
27118
|
+
/**
|
|
27119
|
+
* Only inline a placeholder when materializing it would not save a parent
|
|
27120
|
+
* lookup. If its child tree needs the parent more than once, keep p* so the
|
|
27121
|
+
* generated code does not duplicate _child/_nthChild work.
|
|
27122
|
+
*/
|
|
27123
|
+
function canInlinePlaceholder(dynamic) {
|
|
27124
|
+
return dynamic.hasDynamicChild === true && countParentAccessUsages(dynamic) === 1;
|
|
27125
|
+
}
|
|
27126
|
+
/**
|
|
27127
|
+
* A following access can reuse the current placeholder cursor only when it is
|
|
27128
|
+
* the next DOM sibling. Gapped siblings need _nthChild(parent, index) instead.
|
|
27129
|
+
*/
|
|
27130
|
+
function hasAdjacentFollowingAccessChild(children, index, elementIndex, offset) {
|
|
27131
|
+
let futureOffset = offset;
|
|
27132
|
+
for (let i = index + 1; i < children.length; i++) {
|
|
27133
|
+
const child = children[i];
|
|
27134
|
+
if (child.flags & 2) futureOffset--;
|
|
27135
|
+
if (!(child.flags & 4 && child.template != null) && (!!(child.flags & 1) || child.hasDynamicChild)) return i + futureOffset - elementIndex === 1;
|
|
27136
|
+
}
|
|
27137
|
+
return false;
|
|
27138
|
+
}
|
|
27139
|
+
/**
|
|
27140
|
+
* Mirrors genChildren's traversal closely enough to count how many emitted
|
|
27141
|
+
* access paths would start from this placeholder's parent. This is the guard
|
|
27142
|
+
* that keeps inline placeholders from duplicating parent lookups.
|
|
27143
|
+
*/
|
|
27144
|
+
function countParentAccessUsages(dynamic) {
|
|
27145
|
+
let usages = 0;
|
|
27146
|
+
let offset = 0;
|
|
27147
|
+
let prev;
|
|
27148
|
+
for (const [index, child] of dynamic.children.entries()) {
|
|
27149
|
+
if (child.flags & 2) offset--;
|
|
27150
|
+
if (child.flags & 4 && child.template != null) continue;
|
|
27151
|
+
const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
|
|
27152
|
+
if (id === void 0 && !child.hasDynamicChild) continue;
|
|
27153
|
+
const elementIndex = index + offset;
|
|
27154
|
+
const usesParent = !prev || elementIndex - prev[0] !== 1;
|
|
27155
|
+
if (id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6)) {
|
|
27156
|
+
if (prev && prev[1]) {
|
|
27157
|
+
if (usesParent) usages++;
|
|
27158
|
+
prev = [elementIndex, true];
|
|
27159
|
+
continue;
|
|
27160
|
+
}
|
|
27161
|
+
if (!hasAdjacentFollowingAccessChild(dynamic.children, index, elementIndex, offset)) {
|
|
27162
|
+
if (usesParent) usages++;
|
|
27163
|
+
continue;
|
|
27164
|
+
}
|
|
27165
|
+
}
|
|
27166
|
+
if (usesParent) usages++;
|
|
27167
|
+
prev = [elementIndex, id === void 0];
|
|
27168
|
+
}
|
|
27169
|
+
return usages;
|
|
27170
|
+
}
|
|
27171
|
+
function genNthChild(nthChild, from, elementIndex, logicalIndex) {
|
|
27172
|
+
const index = String(elementIndex);
|
|
27173
|
+
return genCall(nthChild, from, index, logicalIndex === index ? void 0 : logicalIndex);
|
|
27174
|
+
}
|
|
26805
27175
|
//#endregion
|
|
26806
27176
|
//#region packages/compiler-vapor/src/generators/block.ts
|
|
26807
27177
|
function genBlock(oper, context, args = [], root) {
|
|
@@ -26820,8 +27190,12 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
26820
27190
|
const [frag, push] = buildCodeFragment();
|
|
26821
27191
|
const { dynamic, effect, operation, returns } = block;
|
|
26822
27192
|
const resetBlock = context.enterBlock(block);
|
|
27193
|
+
const singleUseAssetComponentNames = root ? collectSingleUseAssetComponents(block) : void 0;
|
|
27194
|
+
const prevSingleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
27195
|
+
if (singleUseAssetComponentNames) context.singleUseAssetComponentNames = singleUseAssetComponentNames;
|
|
26823
27196
|
if (root) {
|
|
26824
27197
|
for (let name of context.ir.component) {
|
|
27198
|
+
if (singleUseAssetComponentNames && singleUseAssetComponentNames.has(name)) continue;
|
|
26825
27199
|
const id = toValidAssetId(name, "component");
|
|
26826
27200
|
const maybeSelfReference = name.endsWith("__self");
|
|
26827
27201
|
if (maybeSelfReference) name = name.slice(0, -6);
|
|
@@ -26857,15 +27231,101 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
26857
27231
|
const returnNodes = returns.map((n) => `n${n}`);
|
|
26858
27232
|
push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"]);
|
|
26859
27233
|
resetBlock();
|
|
27234
|
+
context.singleUseAssetComponentNames = prevSingleUseAssetComponentNames;
|
|
26860
27235
|
return frag;
|
|
26861
27236
|
function genResolveAssets(kind, helper) {
|
|
26862
27237
|
for (const name of context.ir[kind]) push(NEWLINE, `const ${toValidAssetId(name, kind)} = `, ...genCall(context.helper(helper), JSON.stringify(name)));
|
|
26863
27238
|
}
|
|
26864
27239
|
}
|
|
27240
|
+
function collectSingleUseAssetComponents(block) {
|
|
27241
|
+
const usageMap = /* @__PURE__ */ new Map();
|
|
27242
|
+
const seenOperations = /* @__PURE__ */ new Set();
|
|
27243
|
+
visitBlock(block, true);
|
|
27244
|
+
const names = /* @__PURE__ */ new Set();
|
|
27245
|
+
for (const [name, usage] of usageMap) if (usage.count === 1 && usage.root) names.add(name);
|
|
27246
|
+
return names;
|
|
27247
|
+
function visitBlock(block, rootCandidate) {
|
|
27248
|
+
visitDynamic(block.dynamic, rootCandidate);
|
|
27249
|
+
for (const operation of block.operation) visitOperation(operation, rootCandidate);
|
|
27250
|
+
for (const effect of block.effect) for (const operation of effect.operations) visitOperation(operation, false);
|
|
27251
|
+
}
|
|
27252
|
+
function visitDynamic(dynamic, rootCandidate) {
|
|
27253
|
+
if (dynamic.operation) visitOperation(dynamic.operation, rootCandidate);
|
|
27254
|
+
for (const child of dynamic.children) visitDynamic(child, rootCandidate);
|
|
27255
|
+
}
|
|
27256
|
+
function visitOperation(operation, rootCandidate) {
|
|
27257
|
+
if (seenOperations.has(operation)) return;
|
|
27258
|
+
seenOperations.add(operation);
|
|
27259
|
+
if (operation.type === 12) {
|
|
27260
|
+
if (operation.asset) {
|
|
27261
|
+
const usage = usageMap.get(operation.tag) || {
|
|
27262
|
+
count: 0,
|
|
27263
|
+
root: false
|
|
27264
|
+
};
|
|
27265
|
+
usage.count++;
|
|
27266
|
+
if (rootCandidate) usage.root = true;
|
|
27267
|
+
usageMap.set(operation.tag, usage);
|
|
27268
|
+
}
|
|
27269
|
+
visitSlots(operation.slots);
|
|
27270
|
+
return;
|
|
27271
|
+
}
|
|
27272
|
+
switch (operation.type) {
|
|
27273
|
+
case 15:
|
|
27274
|
+
visitBlock(operation.positive, false);
|
|
27275
|
+
if (operation.negative) if (operation.negative.type === 15) visitOperation(operation.negative, false);
|
|
27276
|
+
else visitBlock(operation.negative, false);
|
|
27277
|
+
break;
|
|
27278
|
+
case 16:
|
|
27279
|
+
visitBlock(operation.render, false);
|
|
27280
|
+
break;
|
|
27281
|
+
case 17:
|
|
27282
|
+
visitBlock(operation.block, false);
|
|
27283
|
+
break;
|
|
27284
|
+
case 13:
|
|
27285
|
+
if (operation.fallback) visitBlock(operation.fallback, false);
|
|
27286
|
+
break;
|
|
27287
|
+
}
|
|
27288
|
+
}
|
|
27289
|
+
function visitSlots(slots) {
|
|
27290
|
+
for (const slot of slots) switch (slot.slotType) {
|
|
27291
|
+
case 0:
|
|
27292
|
+
for (const name in slot.slots) visitBlock(slot.slots[name], false);
|
|
27293
|
+
break;
|
|
27294
|
+
case 1:
|
|
27295
|
+
case 2:
|
|
27296
|
+
visitBlock(slot.fn, false);
|
|
27297
|
+
break;
|
|
27298
|
+
case 3:
|
|
27299
|
+
visitSlots([slot.positive]);
|
|
27300
|
+
if (slot.negative) visitSlots([slot.negative]);
|
|
27301
|
+
break;
|
|
27302
|
+
}
|
|
27303
|
+
}
|
|
27304
|
+
}
|
|
26865
27305
|
//#endregion
|
|
26866
27306
|
//#region packages/compiler-vapor/src/generate.ts
|
|
26867
27307
|
const idWithTrailingDigitsRE = /^([A-Za-z_$][\w$]*)(\d+)$/;
|
|
27308
|
+
const helperNameAliases = {
|
|
27309
|
+
withVaporKeys: "withKeys",
|
|
27310
|
+
withVaporModifiers: "withModifiers"
|
|
27311
|
+
};
|
|
26868
27312
|
var CodegenContext = class {
|
|
27313
|
+
withExpressionReplacements(map, fn) {
|
|
27314
|
+
if (map.size === 0) return fn();
|
|
27315
|
+
this.expressionReplacements.unshift(map);
|
|
27316
|
+
try {
|
|
27317
|
+
return fn();
|
|
27318
|
+
} finally {
|
|
27319
|
+
remove(this.expressionReplacements, map);
|
|
27320
|
+
}
|
|
27321
|
+
}
|
|
27322
|
+
getExpressionReplacement(node) {
|
|
27323
|
+
for (const map of this.expressionReplacements) {
|
|
27324
|
+
const replacement = map.get(node);
|
|
27325
|
+
if (replacement) return replacement;
|
|
27326
|
+
}
|
|
27327
|
+
return node;
|
|
27328
|
+
}
|
|
26869
27329
|
withId(fn, map) {
|
|
26870
27330
|
const { identifiers } = this;
|
|
26871
27331
|
const ids = Object.keys(map);
|
|
@@ -26882,9 +27342,19 @@ var CodegenContext = class {
|
|
|
26882
27342
|
this.block = block;
|
|
26883
27343
|
return () => this.block = parent;
|
|
26884
27344
|
}
|
|
27345
|
+
enterSlotBlock() {
|
|
27346
|
+
const parent = this.inSlotBlock;
|
|
27347
|
+
this.inSlotBlock = true;
|
|
27348
|
+
return () => this.inSlotBlock = parent;
|
|
27349
|
+
}
|
|
26885
27350
|
enterScope() {
|
|
26886
27351
|
return [this.scopeLevel++, () => this.scopeLevel--];
|
|
26887
27352
|
}
|
|
27353
|
+
isHelperNameAvailable(name) {
|
|
27354
|
+
if (this.bindingNames.has(name)) return false;
|
|
27355
|
+
for (const alias of this.helpers.values()) if (alias === name) return false;
|
|
27356
|
+
return true;
|
|
27357
|
+
}
|
|
26888
27358
|
initNextIdMap() {
|
|
26889
27359
|
if (this.bindingNames.size === 0) return;
|
|
26890
27360
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -26919,19 +27389,29 @@ var CodegenContext = class {
|
|
|
26919
27389
|
this.ir = ir;
|
|
26920
27390
|
this.bindingNames = /* @__PURE__ */ new Set();
|
|
26921
27391
|
this.helpers = /* @__PURE__ */ new Map();
|
|
27392
|
+
this.needsTemplateRefSetter = false;
|
|
27393
|
+
this.inSlotBlock = false;
|
|
26922
27394
|
this.helper = (name) => {
|
|
26923
27395
|
if (this.helpers.has(name)) return this.helpers.get(name);
|
|
26924
|
-
const base = `_${name}`;
|
|
26925
|
-
if (this.
|
|
27396
|
+
const base = `_${helperNameAliases[name] || name}`;
|
|
27397
|
+
if (this.isHelperNameAvailable(base)) {
|
|
26926
27398
|
this.helpers.set(name, base);
|
|
26927
27399
|
return base;
|
|
26928
27400
|
}
|
|
26929
|
-
const
|
|
26930
|
-
|
|
26931
|
-
|
|
27401
|
+
const map = this.nextIdMap.get(base);
|
|
27402
|
+
let next = 1;
|
|
27403
|
+
while (true) {
|
|
27404
|
+
const alias = `${base}${getNextId(map, next)}`;
|
|
27405
|
+
if (this.isHelperNameAvailable(alias)) {
|
|
27406
|
+
this.helpers.set(name, alias);
|
|
27407
|
+
return alias;
|
|
27408
|
+
}
|
|
27409
|
+
next++;
|
|
27410
|
+
}
|
|
26932
27411
|
};
|
|
26933
27412
|
this.delegates = /* @__PURE__ */ new Set();
|
|
26934
27413
|
this.identifiers = Object.create(null);
|
|
27414
|
+
this.expressionReplacements = [];
|
|
26935
27415
|
this.seenInlineHandlerNames = Object.create(null);
|
|
26936
27416
|
this.scopeLevel = 0;
|
|
26937
27417
|
this.templateVars = /* @__PURE__ */ new Map();
|
|
@@ -26958,6 +27438,7 @@ var CodegenContext = class {
|
|
|
26958
27438
|
this.block = ir.block;
|
|
26959
27439
|
this.bindingNames = new Set(this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []);
|
|
26960
27440
|
this.initNextIdMap();
|
|
27441
|
+
this.staticTemplateRefHelperCandidate = getStaticTemplateRefHelperCandidate(ir.block);
|
|
26961
27442
|
}
|
|
26962
27443
|
};
|
|
26963
27444
|
function generate(ir, options = {}) {
|
|
@@ -26970,8 +27451,11 @@ function generate(ir, options = {}) {
|
|
|
26970
27451
|
const signature = (options.isTS ? args.map((arg) => `${arg}: any`) : args).join(", ");
|
|
26971
27452
|
if (!inline) push(NEWLINE, `export function ${functionName}(${signature}) {`);
|
|
26972
27453
|
push(INDENT_START);
|
|
26973
|
-
|
|
26974
|
-
|
|
27454
|
+
const templateRefSetterHelper = ir.hasTemplateRef ? context.helper("createTemplateRefSetter") : void 0;
|
|
27455
|
+
const body = genBlockContent(ir.block, context, true);
|
|
27456
|
+
if (context.needsTemplateRefSetter) push(NEWLINE, `const ${setTemplateRefIdent} = ${templateRefSetterHelper}()`);
|
|
27457
|
+
else if (templateRefSetterHelper) context.helpers.delete("createTemplateRefSetter");
|
|
27458
|
+
push(...body);
|
|
26975
27459
|
push(INDENT_END, NEWLINE);
|
|
26976
27460
|
if (!inline) push("}");
|
|
26977
27461
|
const delegates = genDelegates(context);
|
|
@@ -27006,6 +27490,11 @@ function genAssetImports({ ir }) {
|
|
|
27006
27490
|
}
|
|
27007
27491
|
return imports;
|
|
27008
27492
|
}
|
|
27493
|
+
function getStaticTemplateRefHelperCandidate(block) {
|
|
27494
|
+
if (block.operation.length !== 1) return;
|
|
27495
|
+
const operation = block.operation[0];
|
|
27496
|
+
if (operation.type === 9 && !operation.effect && !operation.refFor && operation.value.isStatic) return operation;
|
|
27497
|
+
}
|
|
27009
27498
|
//#endregion
|
|
27010
27499
|
//#region packages/compiler-vapor/src/transforms/vBind.ts
|
|
27011
27500
|
function normalizeBindShorthand(arg, context) {
|
|
@@ -27072,11 +27561,35 @@ function canOmitEndTag(node, context) {
|
|
|
27072
27561
|
const { block, parent } = context;
|
|
27073
27562
|
if (!parent) return false;
|
|
27074
27563
|
if (block !== parent.block) return true;
|
|
27564
|
+
if (context.templateCloseTags && (context.templateCloseTags.has(node.tag) || isAlwaysCloseTag(node.tag) || isFormattingTag(node.tag)) || context.templateCloseBlocks && isBlockTag(node.tag)) return false;
|
|
27075
27565
|
if (isAlwaysCloseTag(node.tag) && !context.isOnRightmostPath) return false;
|
|
27076
27566
|
if (isFormattingTag(node.tag) || parent.node.type === 1 && node.tag === parent.node.tag) return context.isOnRightmostPath;
|
|
27077
|
-
if (isBlockTag(node.tag) && context.hasInlineAncestorNeedingClose) return false;
|
|
27078
27567
|
return context.isLastEffectiveChild;
|
|
27079
27568
|
}
|
|
27569
|
+
function getChildTemplateCloseState(context) {
|
|
27570
|
+
const { node } = context;
|
|
27571
|
+
if (node.type !== 1 || node.tagType !== 0 || shouldUseCreateElement(node, context)) return;
|
|
27572
|
+
const inSameTemplateAsParent = isInSameTemplateAsParent(context);
|
|
27573
|
+
const inheritedTags = inSameTemplateAsParent ? context.templateCloseTags : void 0;
|
|
27574
|
+
const inheritedBlocks = inSameTemplateAsParent && context.templateCloseBlocks;
|
|
27575
|
+
if (context.root === context.effectiveParent || canOmitEndTag(node, context) || isVoidTag(node.tag)) return inheritedTags || inheritedBlocks ? {
|
|
27576
|
+
tags: inheritedTags,
|
|
27577
|
+
blocks: inheritedBlocks
|
|
27578
|
+
} : void 0;
|
|
27579
|
+
const tags = new Set(inheritedTags);
|
|
27580
|
+
tags.add(node.tag);
|
|
27581
|
+
return {
|
|
27582
|
+
tags,
|
|
27583
|
+
blocks: inheritedBlocks || isInlineTag(node.tag)
|
|
27584
|
+
};
|
|
27585
|
+
}
|
|
27586
|
+
function isInSameTemplateAsParent(context) {
|
|
27587
|
+
const { parent, node, block } = context;
|
|
27588
|
+
if (!parent || block !== parent.block) return false;
|
|
27589
|
+
const parentNode = parent.node;
|
|
27590
|
+
if (parentNode.type !== 1 || parentNode.tagType !== 0) return false;
|
|
27591
|
+
return !shouldUseCreateElement(parentNode, parent) && isValidHTMLNesting(parentNode.tag, node.tag);
|
|
27592
|
+
}
|
|
27080
27593
|
function isSingleRoot(context) {
|
|
27081
27594
|
if (context.inVFor) return false;
|
|
27082
27595
|
let { parent } = context;
|
|
@@ -27148,6 +27661,7 @@ function resolveSetupReference(name, context) {
|
|
|
27148
27661
|
}
|
|
27149
27662
|
const dynamicKeys = ["indeterminate"];
|
|
27150
27663
|
const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
|
|
27664
|
+
const UNSAFE_ATTR_NAME_RE = /[\u0000-\u0020"'<=/>]/;
|
|
27151
27665
|
function transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, omitEndTag) {
|
|
27152
27666
|
const { tag } = node;
|
|
27153
27667
|
const { scopeId } = context.options;
|
|
@@ -27165,18 +27679,55 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
27165
27679
|
}, getEffectIndex);
|
|
27166
27680
|
} else {
|
|
27167
27681
|
let prevWasQuoted = false;
|
|
27682
|
+
const appendTemplateProp = (key, value = "", generated = false) => {
|
|
27683
|
+
if (!prevWasQuoted) template += ` `;
|
|
27684
|
+
template += key;
|
|
27685
|
+
if (value) {
|
|
27686
|
+
const escapedValue = generated ? escapeGeneratedAttrValue(value) : value.replace(/"/g, """);
|
|
27687
|
+
template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${escapedValue}"` : `=${escapedValue}`;
|
|
27688
|
+
} else prevWasQuoted = false;
|
|
27689
|
+
};
|
|
27168
27690
|
for (const prop of propsResult[1]) {
|
|
27169
27691
|
const { key, values } = prop;
|
|
27170
27692
|
if (context.imports.some((imported) => values[0].content.includes(imported.exp.content))) {
|
|
27171
27693
|
if (!prevWasQuoted) template += ` `;
|
|
27172
27694
|
template += `${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
|
|
27173
27695
|
prevWasQuoted = true;
|
|
27696
|
+
} else if (key.isStatic && !prop.modifier && isBooleanAttr(key.content)) if (values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
27697
|
+
const value = values[0].content === "''" ? "" : values[0].content;
|
|
27698
|
+
appendTemplateProp(key.content, value);
|
|
27699
|
+
} else {
|
|
27700
|
+
const include = foldBooleanAttrValue(values);
|
|
27701
|
+
if (include != null) {
|
|
27702
|
+
if (include) appendTemplateProp(key.content);
|
|
27703
|
+
} else {
|
|
27704
|
+
dynamicProps.push(key.content);
|
|
27705
|
+
context.registerEffect(values, {
|
|
27706
|
+
type: 3,
|
|
27707
|
+
element: context.reference(),
|
|
27708
|
+
prop,
|
|
27709
|
+
tag
|
|
27710
|
+
}, getEffectIndex);
|
|
27711
|
+
}
|
|
27712
|
+
}
|
|
27713
|
+
else if (key.isStatic && !prop.modifier && hasBoundValue(values)) {
|
|
27714
|
+
let foldedValue;
|
|
27715
|
+
if (key.content === "class") foldedValue = foldClassValues(values);
|
|
27716
|
+
else if (key.content === "style") foldedValue = foldStyleValues(values);
|
|
27717
|
+
if (foldedValue != null) {
|
|
27718
|
+
if (foldedValue) appendTemplateProp(key.content, foldedValue, true);
|
|
27719
|
+
} else {
|
|
27720
|
+
dynamicProps.push(key.content);
|
|
27721
|
+
context.registerEffect(values, {
|
|
27722
|
+
type: 3,
|
|
27723
|
+
element: context.reference(),
|
|
27724
|
+
prop,
|
|
27725
|
+
tag
|
|
27726
|
+
}, getEffectIndex);
|
|
27727
|
+
}
|
|
27174
27728
|
} else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
27175
|
-
if (!prevWasQuoted) template += ` `;
|
|
27176
27729
|
const value = values[0].content === "''" ? "" : values[0].content;
|
|
27177
|
-
|
|
27178
|
-
if (value) template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${value.replace(/"/g, """)}"` : `=${value}`;
|
|
27179
|
-
else prevWasQuoted = false;
|
|
27730
|
+
appendTemplateProp(key.content, value);
|
|
27180
27731
|
} else {
|
|
27181
27732
|
dynamicProps.push(key.content);
|
|
27182
27733
|
context.registerEffect(values, {
|
|
@@ -27198,6 +27749,123 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
27198
27749
|
} else context.template += template;
|
|
27199
27750
|
if (staticKey) context.registerOperation(createSetBlockKey(context.reference(), staticKey));
|
|
27200
27751
|
}
|
|
27752
|
+
function escapeGeneratedAttrValue(value) {
|
|
27753
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
27754
|
+
}
|
|
27755
|
+
function foldBooleanAttrValue(values) {
|
|
27756
|
+
if (values.length !== 1) return;
|
|
27757
|
+
const evaluated = evaluateConstantExpression(values[0]);
|
|
27758
|
+
if (!evaluated) return;
|
|
27759
|
+
const value = evaluated.value;
|
|
27760
|
+
if (value === true || value === false || value == null) return includeBooleanAttr(value);
|
|
27761
|
+
}
|
|
27762
|
+
function foldStyleValues(values) {
|
|
27763
|
+
const evaluatedValues = [];
|
|
27764
|
+
for (const value of values) {
|
|
27765
|
+
const evaluated = evaluateConstantExpression(value);
|
|
27766
|
+
if (!evaluated || !isStaticStyleValue(evaluated.value)) return;
|
|
27767
|
+
evaluatedValues.push(evaluated.value);
|
|
27768
|
+
}
|
|
27769
|
+
return stringifyStyle(normalizeStyle(evaluatedValues.length === 1 ? evaluatedValues[0] : evaluatedValues));
|
|
27770
|
+
}
|
|
27771
|
+
function isStaticStyleValue(value) {
|
|
27772
|
+
if (typeof value === "string") return true;
|
|
27773
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
27774
|
+
for (const key in value) {
|
|
27775
|
+
const propValue = value[key];
|
|
27776
|
+
if (!isSafeStylePropertyName(key) || !isSafeStylePropertyValue(propValue)) return false;
|
|
27777
|
+
}
|
|
27778
|
+
return true;
|
|
27779
|
+
}
|
|
27780
|
+
function isSafeStylePropertyName(key) {
|
|
27781
|
+
return !!key && !/[;:]/.test(key);
|
|
27782
|
+
}
|
|
27783
|
+
function isSafeStylePropertyValue(value) {
|
|
27784
|
+
return typeof value === "number" || typeof value === "string" && !value.includes(";");
|
|
27785
|
+
}
|
|
27786
|
+
function hasBoundValue(values) {
|
|
27787
|
+
return values.some((value) => !value.isStatic && value.content !== "''");
|
|
27788
|
+
}
|
|
27789
|
+
function foldClassValues(values) {
|
|
27790
|
+
let templateValue = "";
|
|
27791
|
+
let changed = false;
|
|
27792
|
+
for (const value of values) {
|
|
27793
|
+
const evaluated = evaluateConstantExpression(value);
|
|
27794
|
+
if (evaluated) {
|
|
27795
|
+
const normalized = normalizeClass(evaluated.value);
|
|
27796
|
+
if (normalized) templateValue = appendClass(templateValue, normalized);
|
|
27797
|
+
else changed = true;
|
|
27798
|
+
continue;
|
|
27799
|
+
}
|
|
27800
|
+
return;
|
|
27801
|
+
}
|
|
27802
|
+
return changed || templateValue ? templateValue : void 0;
|
|
27803
|
+
}
|
|
27804
|
+
function appendClass(base, value) {
|
|
27805
|
+
return base ? value ? `${base} ${value}` : base : value;
|
|
27806
|
+
}
|
|
27807
|
+
function getObjectPropertyName(prop) {
|
|
27808
|
+
const key = prop.key;
|
|
27809
|
+
if (key.type === "Identifier") return key.name;
|
|
27810
|
+
else if (key.type === "StringLiteral") return key.value;
|
|
27811
|
+
else if (key.type === "NumericLiteral") return String(key.value);
|
|
27812
|
+
}
|
|
27813
|
+
function evaluateConstantExpression(node) {
|
|
27814
|
+
if (node.isStatic) return { value: node.content };
|
|
27815
|
+
const ast = node.ast;
|
|
27816
|
+
if (ast === null) {
|
|
27817
|
+
if (node.content === "true") return { value: true };
|
|
27818
|
+
else if (node.content === "false") return { value: false };
|
|
27819
|
+
else if (node.content === "null") return { value: null };
|
|
27820
|
+
else if (node.content === "undefined") return { value: void 0 };
|
|
27821
|
+
}
|
|
27822
|
+
if (!ast) return;
|
|
27823
|
+
return evaluateConstantAst(ast);
|
|
27824
|
+
}
|
|
27825
|
+
function evaluateConstantAst(node) {
|
|
27826
|
+
switch (node.type) {
|
|
27827
|
+
case "StringLiteral": return { value: node.value };
|
|
27828
|
+
case "NumericLiteral": return { value: node.value };
|
|
27829
|
+
case "BooleanLiteral": return { value: node.value };
|
|
27830
|
+
case "NullLiteral": return { value: null };
|
|
27831
|
+
case "Identifier": return node.name === "undefined" ? { value: void 0 } : void 0;
|
|
27832
|
+
case "UnaryExpression":
|
|
27833
|
+
if (node.operator === "void") return { value: void 0 };
|
|
27834
|
+
else if (node.operator === "-") {
|
|
27835
|
+
const value = evaluateConstantAst(node.argument);
|
|
27836
|
+
return value && typeof value.value === "number" ? { value: -value.value } : void 0;
|
|
27837
|
+
}
|
|
27838
|
+
return;
|
|
27839
|
+
case "TemplateLiteral": return evaluateTemplateLiteral(node);
|
|
27840
|
+
case "ObjectExpression": return evaluateObjectExpression(node);
|
|
27841
|
+
}
|
|
27842
|
+
}
|
|
27843
|
+
function evaluateTemplateLiteral(node) {
|
|
27844
|
+
if (node.type !== "TemplateLiteral") return;
|
|
27845
|
+
let value = "";
|
|
27846
|
+
for (const [index, quasi] of node.quasis.entries()) {
|
|
27847
|
+
value += quasi.value.cooked || "";
|
|
27848
|
+
const expression = node.expressions[index];
|
|
27849
|
+
if (expression) {
|
|
27850
|
+
const evaluated = evaluateConstantAst(expression);
|
|
27851
|
+
if (!evaluated) return;
|
|
27852
|
+
value += evaluated.value;
|
|
27853
|
+
}
|
|
27854
|
+
}
|
|
27855
|
+
return { value };
|
|
27856
|
+
}
|
|
27857
|
+
function evaluateObjectExpression(node) {
|
|
27858
|
+
const value = {};
|
|
27859
|
+
for (const prop of node.properties) {
|
|
27860
|
+
if (prop.type !== "ObjectProperty" || prop.computed) return;
|
|
27861
|
+
const key = getObjectPropertyName(prop);
|
|
27862
|
+
if (key == null) return;
|
|
27863
|
+
const evaluated = evaluateConstantAst(prop.value);
|
|
27864
|
+
if (!evaluated) return;
|
|
27865
|
+
value[key] = evaluated.value;
|
|
27866
|
+
}
|
|
27867
|
+
return { value };
|
|
27868
|
+
}
|
|
27201
27869
|
function resolveStaticKey(node, context, isComponent) {
|
|
27202
27870
|
const keyProp = findProp(node, "key", false, true);
|
|
27203
27871
|
if (!keyProp) return;
|
|
@@ -27224,27 +27892,42 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
27224
27892
|
results = [];
|
|
27225
27893
|
}
|
|
27226
27894
|
}
|
|
27895
|
+
function pushStaticObjectLiteralProps(props) {
|
|
27896
|
+
if (dynamicArgs.length) {
|
|
27897
|
+
pushMergeArg();
|
|
27898
|
+
dynamicArgs.push(props);
|
|
27899
|
+
} else results.push(...props.map(toDirectiveResult));
|
|
27900
|
+
}
|
|
27227
27901
|
for (const prop of props) {
|
|
27228
27902
|
if (prop.type === 7 && !prop.arg) {
|
|
27229
27903
|
if (prop.name === "bind") {
|
|
27230
27904
|
if (prop.exp) {
|
|
27231
|
-
|
|
27232
|
-
|
|
27233
|
-
|
|
27234
|
-
|
|
27235
|
-
|
|
27236
|
-
|
|
27905
|
+
const objectLiteralProps = isComponent ? resolveComponentObjectLiteralBindProps(prop.exp, context, props, prop) : resolveNativeObjectLiteralBindProps(prop.exp, context, props, prop);
|
|
27906
|
+
if (objectLiteralProps) if (isComponent) pushStaticObjectLiteralProps(objectLiteralProps);
|
|
27907
|
+
else results.push(...objectLiteralProps.map(toDirectiveResult));
|
|
27908
|
+
else {
|
|
27909
|
+
dynamicExpr.push(prop.exp);
|
|
27910
|
+
pushMergeArg();
|
|
27911
|
+
dynamicArgs.push({
|
|
27912
|
+
kind: 0,
|
|
27913
|
+
value: prop.exp
|
|
27914
|
+
});
|
|
27915
|
+
}
|
|
27237
27916
|
} else context.options.onError(createCompilerError(34, prop.loc));
|
|
27238
27917
|
continue;
|
|
27239
27918
|
} else if (prop.name === "on") {
|
|
27240
27919
|
if (prop.exp) if (isComponent) {
|
|
27241
|
-
|
|
27242
|
-
|
|
27243
|
-
|
|
27244
|
-
|
|
27245
|
-
|
|
27246
|
-
|
|
27247
|
-
|
|
27920
|
+
const objectLiteralProps = resolveComponentObjectLiteralOnProps(prop.exp, context, props, prop);
|
|
27921
|
+
if (objectLiteralProps) pushStaticObjectLiteralProps(objectLiteralProps);
|
|
27922
|
+
else {
|
|
27923
|
+
dynamicExpr.push(prop.exp);
|
|
27924
|
+
pushMergeArg();
|
|
27925
|
+
dynamicArgs.push({
|
|
27926
|
+
kind: 0,
|
|
27927
|
+
value: prop.exp,
|
|
27928
|
+
handler: true
|
|
27929
|
+
});
|
|
27930
|
+
}
|
|
27248
27931
|
} else context.registerEffect([prop.exp], {
|
|
27249
27932
|
type: 7,
|
|
27250
27933
|
element: context.reference(),
|
|
@@ -27274,6 +27957,151 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
27274
27957
|
}
|
|
27275
27958
|
return [false, dedupeProperties(results)];
|
|
27276
27959
|
}
|
|
27960
|
+
function resolveObjectLiteralProps(exp, context, keyTransform, isValidKey) {
|
|
27961
|
+
const ast = exp.ast;
|
|
27962
|
+
if (!ast || ast.type !== "ObjectExpression") return;
|
|
27963
|
+
const props = [];
|
|
27964
|
+
const knownKeys = /* @__PURE__ */ new Set();
|
|
27965
|
+
for (const property of ast.properties) {
|
|
27966
|
+
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
27967
|
+
let key = getObjectPropertyName(property);
|
|
27968
|
+
if (key == null || key === "__proto__") return;
|
|
27969
|
+
if (isValidKey && !isValidKey(key)) return;
|
|
27970
|
+
if (keyTransform) key = keyTransform(key);
|
|
27971
|
+
if (knownKeys.has(key)) return;
|
|
27972
|
+
knownKeys.add(key);
|
|
27973
|
+
props.push({
|
|
27974
|
+
key: createSimpleExpression(key, true),
|
|
27975
|
+
values: [resolveExpression(createObjectBindSubExpression(exp, property.value, context), true)]
|
|
27976
|
+
});
|
|
27977
|
+
}
|
|
27978
|
+
return props;
|
|
27979
|
+
}
|
|
27980
|
+
function resolveComponentObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
27981
|
+
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeObjectLiteralBindKey);
|
|
27982
|
+
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
27983
|
+
return props;
|
|
27984
|
+
}
|
|
27985
|
+
function resolveNativeObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
27986
|
+
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeNativeObjectLiteralBindKey);
|
|
27987
|
+
if (!props || hasNativeObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
27988
|
+
return props;
|
|
27989
|
+
}
|
|
27990
|
+
function resolveComponentObjectLiteralOnProps(exp, context, nodeProps, currentProp) {
|
|
27991
|
+
const props = resolveObjectLiteralProps(exp, context, toHandlerKey);
|
|
27992
|
+
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
27993
|
+
return props;
|
|
27994
|
+
}
|
|
27995
|
+
function isSafeNativeObjectLiteralBindKey(key) {
|
|
27996
|
+
return key !== "" && !UNSAFE_ATTR_NAME_RE.test(key) && isSafeObjectLiteralBindKey(key) && !isOn(key) && key.charCodeAt(0) !== 46 && key.charCodeAt(0) !== 94;
|
|
27997
|
+
}
|
|
27998
|
+
function isSafeObjectLiteralBindKey(key) {
|
|
27999
|
+
return !isReservedProp(key);
|
|
28000
|
+
}
|
|
28001
|
+
function hasComponentObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
28002
|
+
const keys = createComponentConflictKeySet(objectLiteralProps.map((prop) => prop.key.content));
|
|
28003
|
+
for (const prop of props) {
|
|
28004
|
+
if (prop === currentProp) continue;
|
|
28005
|
+
let key;
|
|
28006
|
+
if (prop.type === 6) key = prop.name;
|
|
28007
|
+
else if (prop.name === "bind") {
|
|
28008
|
+
if (!prop.arg) {
|
|
28009
|
+
const bindKeys = getObjectLiteralKeys(prop.exp);
|
|
28010
|
+
if (bindKeys && hasComponentKeyOverlap(keys, bindKeys)) return true;
|
|
28011
|
+
continue;
|
|
28012
|
+
}
|
|
28013
|
+
key = getStaticBindKey(prop);
|
|
28014
|
+
} else if (prop.name === "on") key = getStaticHandlerKey(prop);
|
|
28015
|
+
else if (prop.name === "model") {
|
|
28016
|
+
if (hasComponentModelKey(keys, prop)) return true;
|
|
28017
|
+
}
|
|
28018
|
+
if (key && hasComponentKey(keys, key)) return true;
|
|
28019
|
+
}
|
|
28020
|
+
return false;
|
|
28021
|
+
}
|
|
28022
|
+
function hasComponentModelKey(keys, prop) {
|
|
28023
|
+
const { arg } = prop;
|
|
28024
|
+
if (arg && (arg.type !== 4 || !arg.isStatic)) return true;
|
|
28025
|
+
const key = arg ? arg.content : "modelValue";
|
|
28026
|
+
return hasComponentKey(keys, key) || hasComponentKey(keys, `onUpdate:${camelize(key)}`) || prop.modifiers.length > 0 && hasComponentKey(keys, getModifierPropName(key));
|
|
28027
|
+
}
|
|
28028
|
+
function hasNativeObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
28029
|
+
const keys = new Set(objectLiteralProps.map((prop) => prop.key.content));
|
|
28030
|
+
for (const prop of props) {
|
|
28031
|
+
if (prop === currentProp) continue;
|
|
28032
|
+
let key;
|
|
28033
|
+
if (prop.type === 6) key = prop.name;
|
|
28034
|
+
else if (prop.name === "bind") {
|
|
28035
|
+
if (!prop.arg) return true;
|
|
28036
|
+
key = getStaticBindKey(prop);
|
|
28037
|
+
if (!key) return true;
|
|
28038
|
+
}
|
|
28039
|
+
if (key && keys.has(key)) return true;
|
|
28040
|
+
}
|
|
28041
|
+
return false;
|
|
28042
|
+
}
|
|
28043
|
+
function getStaticBindKey(prop) {
|
|
28044
|
+
const { arg } = prop;
|
|
28045
|
+
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
28046
|
+
let key = arg.content;
|
|
28047
|
+
if (isReservedProp(key)) return;
|
|
28048
|
+
if (prop.modifiers.some((modifier) => modifier.content === "camel")) key = camelize(key);
|
|
28049
|
+
return key;
|
|
28050
|
+
}
|
|
28051
|
+
function getStaticHandlerKey(prop) {
|
|
28052
|
+
const { arg } = prop;
|
|
28053
|
+
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
28054
|
+
let key = arg.content;
|
|
28055
|
+
if (key.startsWith("vue:")) key = `vnode-${key.slice(4)}`;
|
|
28056
|
+
const { nonKeyModifiers, eventOptionModifiers } = resolveModifiers(`on${key}`, prop.modifiers, null, prop.loc);
|
|
28057
|
+
if (key.toLowerCase() === "click") {
|
|
28058
|
+
if (nonKeyModifiers.includes("middle")) key = "mouseup";
|
|
28059
|
+
if (nonKeyModifiers.includes("right")) key = "contextmenu";
|
|
28060
|
+
}
|
|
28061
|
+
key = toHandlerKey(camelize(key));
|
|
28062
|
+
const optionPostfix = eventOptionModifiers.map(capitalize).join("");
|
|
28063
|
+
if (optionPostfix) key += optionPostfix;
|
|
28064
|
+
return key;
|
|
28065
|
+
}
|
|
28066
|
+
function getObjectLiteralKeys(exp) {
|
|
28067
|
+
const ast = exp && exp.ast;
|
|
28068
|
+
if (!ast || ast.type !== "ObjectExpression") return;
|
|
28069
|
+
const keys = /* @__PURE__ */ new Set();
|
|
28070
|
+
for (const property of ast.properties) {
|
|
28071
|
+
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
28072
|
+
const key = getObjectPropertyName(property);
|
|
28073
|
+
if (key == null) return;
|
|
28074
|
+
keys.add(key);
|
|
28075
|
+
}
|
|
28076
|
+
return keys;
|
|
28077
|
+
}
|
|
28078
|
+
function createComponentConflictKeySet(keys) {
|
|
28079
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
28080
|
+
for (const key of keys) {
|
|
28081
|
+
normalized.add(key);
|
|
28082
|
+
normalized.add(camelize(key));
|
|
28083
|
+
}
|
|
28084
|
+
return normalized;
|
|
28085
|
+
}
|
|
28086
|
+
function hasComponentKey(keys, key) {
|
|
28087
|
+
return keys.has(key) || keys.has(camelize(key));
|
|
28088
|
+
}
|
|
28089
|
+
function hasComponentKeyOverlap(left, right) {
|
|
28090
|
+
for (const key of right) if (hasComponentKey(left, key)) return true;
|
|
28091
|
+
return false;
|
|
28092
|
+
}
|
|
28093
|
+
function createObjectBindSubExpression(source, node, context) {
|
|
28094
|
+
const start = node.start == null ? 0 : node.start - 1;
|
|
28095
|
+
const end = node.end == null ? source.content.length : node.end - 1;
|
|
28096
|
+
const content = source.content.slice(start, end);
|
|
28097
|
+
const expression = createSimpleExpression(content, false, {
|
|
28098
|
+
start: advancePositionWithClone(source.loc.start, source.content, start),
|
|
28099
|
+
end: advancePositionWithClone(source.loc.start, source.content, end),
|
|
28100
|
+
source: content
|
|
28101
|
+
});
|
|
28102
|
+
expression.ast = isSimpleIdentifier(content) ? null : (0, import_lib.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
28103
|
+
return expression;
|
|
28104
|
+
}
|
|
27277
28105
|
function transformProp(prop, node, context) {
|
|
27278
28106
|
let { name } = prop;
|
|
27279
28107
|
if (prop.type === 6) {
|
|
@@ -27324,6 +28152,12 @@ function resolveDirectiveResult(prop) {
|
|
|
27324
28152
|
values: [prop.value]
|
|
27325
28153
|
});
|
|
27326
28154
|
}
|
|
28155
|
+
function toDirectiveResult(prop) {
|
|
28156
|
+
return extend({}, prop, {
|
|
28157
|
+
values: void 0,
|
|
28158
|
+
value: prop.values[0]
|
|
28159
|
+
});
|
|
28160
|
+
}
|
|
27327
28161
|
function mergePropValues(existing, incoming) {
|
|
27328
28162
|
const newValues = incoming.values;
|
|
27329
28163
|
existing.values.push(...newValues);
|
|
@@ -27340,8 +28174,12 @@ const transformChildren = (node, context) => {
|
|
|
27340
28174
|
const isFragment = node.type === 0 || node.type === 1 && (node.tagType === 3 || node.tagType === 1);
|
|
27341
28175
|
if (!isFragment && node.type !== 1) return;
|
|
27342
28176
|
const useCreateElement = node.type === 1 && shouldUseCreateElement(node, context);
|
|
28177
|
+
const childTemplateCloseState = !isFragment && !useCreateElement ? getChildTemplateCloseState(context) : void 0;
|
|
27343
28178
|
for (const [i, child] of node.children.entries()) {
|
|
27344
28179
|
const childContext = context.create(child, i);
|
|
28180
|
+
const isInSameTemplate = childTemplateCloseState && child.type === 1 && child.tagType === 0 && isInSameTemplateAsParent(childContext);
|
|
28181
|
+
childContext.templateCloseTags = isInSameTemplate ? childTemplateCloseState.tags : void 0;
|
|
28182
|
+
childContext.templateCloseBlocks = isInSameTemplate ? childTemplateCloseState.blocks : false;
|
|
27345
28183
|
transformNode(childContext);
|
|
27346
28184
|
const childDynamic = childContext.dynamic;
|
|
27347
28185
|
if (isFragment) {
|
|
@@ -27834,6 +28672,7 @@ function processIf(node, dir, context) {
|
|
|
27834
28672
|
}
|
|
27835
28673
|
context.dynamic.flags |= 2;
|
|
27836
28674
|
const forceMultiRoot = shouldForceMultiRoot(context);
|
|
28675
|
+
const allowNoScope = context.block === context.root.block;
|
|
27837
28676
|
if (dir.name === "if") {
|
|
27838
28677
|
const id = context.reference();
|
|
27839
28678
|
context.dynamic.flags |= 4;
|
|
@@ -27844,7 +28683,7 @@ function processIf(node, dir, context) {
|
|
|
27844
28683
|
type: 15,
|
|
27845
28684
|
id
|
|
27846
28685
|
}, context.effectBoundary()), {}, {
|
|
27847
|
-
blockShape: encodeIfBlockShape(branch, forceMultiRoot),
|
|
28686
|
+
blockShape: encodeIfBlockShape(branch, forceMultiRoot, void 0, allowNoScope),
|
|
27848
28687
|
condition: dir.exp,
|
|
27849
28688
|
positive: branch,
|
|
27850
28689
|
index: context.root.nextIfIndex(),
|
|
@@ -27886,8 +28725,8 @@ function processIf(node, dir, context) {
|
|
|
27886
28725
|
};
|
|
27887
28726
|
return () => {
|
|
27888
28727
|
onExit();
|
|
27889
|
-
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot);
|
|
27890
|
-
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative);
|
|
28728
|
+
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot, void 0, allowNoScope);
|
|
28729
|
+
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative, allowNoScope);
|
|
27891
28730
|
};
|
|
27892
28731
|
}
|
|
27893
28732
|
}
|
|
@@ -27902,14 +28741,38 @@ function createIfBranch(node, context) {
|
|
|
27902
28741
|
context.reference();
|
|
27903
28742
|
return [branch, exitBlock];
|
|
27904
28743
|
}
|
|
27905
|
-
function encodeIfBlockShape(positive, forceMultiRoot = false, negative) {
|
|
28744
|
+
function encodeIfBlockShape(positive, forceMultiRoot = false, negative, allowNoScope = true) {
|
|
27906
28745
|
if (forceMultiRoot) return 10;
|
|
27907
|
-
|
|
28746
|
+
const positiveNoScope = allowNoScope && canSkipIfBranchScope(positive);
|
|
28747
|
+
const negativeNoScope = allowNoScope && negative && negative.type !== 15 && canSkipIfBranchScope(negative);
|
|
28748
|
+
return getBlockShape(positive) | getNegativeIfBranchShape(negative) << 2 | (positiveNoScope ? 32 : 0) | (negativeNoScope ? 64 : 0);
|
|
27908
28749
|
}
|
|
27909
|
-
function
|
|
28750
|
+
function getNegativeIfBranchShape(negative) {
|
|
27910
28751
|
if (!negative) return 0;
|
|
27911
28752
|
return negative.type === 15 ? 1 : getBlockShape(negative);
|
|
27912
28753
|
}
|
|
28754
|
+
function canSkipIfBranchScope(block) {
|
|
28755
|
+
if (block.effect.length || block.operation.length) return false;
|
|
28756
|
+
if (!isStaticBranch(block.node)) return false;
|
|
28757
|
+
if (block.returns.length === 0 || block.dynamic.children.length !== block.returns.length) return false;
|
|
28758
|
+
return block.returns.every((id) => {
|
|
28759
|
+
const returned = findReturnedDynamic(block, id);
|
|
28760
|
+
return !!(returned && returned.template != null && !returned.operation && !returned.hasDynamicChild && !(returned.flags & 6));
|
|
28761
|
+
});
|
|
28762
|
+
}
|
|
28763
|
+
function findReturnedDynamic(block, id) {
|
|
28764
|
+
return block.dynamic.children.find((child) => child.id === id);
|
|
28765
|
+
}
|
|
28766
|
+
function isStaticBranch(node) {
|
|
28767
|
+
if (node.type !== 1 || node.tagType !== 3 || node.children.length === 0) return false;
|
|
28768
|
+
return node.children.every((child) => isStaticTemplateNode(child));
|
|
28769
|
+
}
|
|
28770
|
+
function isStaticTemplateNode(node) {
|
|
28771
|
+
if (node.type === 2 || node.type === 3) return true;
|
|
28772
|
+
if (node.type !== 1 || node.tagType !== 0) return false;
|
|
28773
|
+
for (const prop of node.props) if (prop.type === 7 || prop.name === "ref") return false;
|
|
28774
|
+
return node.children.every((child) => isStaticTemplateNode(child));
|
|
28775
|
+
}
|
|
27913
28776
|
function shouldForceMultiRoot(context) {
|
|
27914
28777
|
const parent = context.parent && context.parent.node;
|
|
27915
28778
|
return !!parent && parent.type === 1 && parent.tagType === 3 && parent.props.some((prop) => prop.type === 7 && prop.name === "for");
|
|
@@ -27996,6 +28859,9 @@ const transformSlotOutlet = (node, context) => {
|
|
|
27996
28859
|
}
|
|
27997
28860
|
return () => {
|
|
27998
28861
|
exitBlock && exitBlock();
|
|
28862
|
+
let flags = 0;
|
|
28863
|
+
if (context.options.scopeId && !context.options.slotted) flags |= 1;
|
|
28864
|
+
if (context.inVOnce) flags |= 2;
|
|
27999
28865
|
context.dynamic.operation = _objectSpread2(_objectSpread2({
|
|
28000
28866
|
type: 13,
|
|
28001
28867
|
id
|
|
@@ -28003,8 +28869,7 @@ const transformSlotOutlet = (node, context) => {
|
|
|
28003
28869
|
name: slotName,
|
|
28004
28870
|
props: irProps,
|
|
28005
28871
|
fallback,
|
|
28006
|
-
|
|
28007
|
-
once: context.inVOnce
|
|
28872
|
+
flags
|
|
28008
28873
|
});
|
|
28009
28874
|
};
|
|
28010
28875
|
};
|
|
@@ -30400,7 +31265,7 @@ var require_document = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
30400
31265
|
Document.default = Document;
|
|
30401
31266
|
}));
|
|
30402
31267
|
//#endregion
|
|
30403
|
-
//#region \0@oxc-project+runtime@0.
|
|
31268
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/objectWithoutPropertiesLoose.js
|
|
30404
31269
|
function _objectWithoutPropertiesLoose(r, e) {
|
|
30405
31270
|
if (null == r) return {};
|
|
30406
31271
|
var t = {};
|
|
@@ -30412,7 +31277,7 @@ function _objectWithoutPropertiesLoose(r, e) {
|
|
|
30412
31277
|
}
|
|
30413
31278
|
var init_objectWithoutPropertiesLoose = __esmMin((() => {}));
|
|
30414
31279
|
//#endregion
|
|
30415
|
-
//#region \0@oxc-project+runtime@0.
|
|
31280
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/objectWithoutProperties.js
|
|
30416
31281
|
function _objectWithoutProperties(e, t) {
|
|
30417
31282
|
if (null == e) return {};
|
|
30418
31283
|
var o, r, i = _objectWithoutPropertiesLoose(e, t);
|
|
@@ -39764,25 +40629,28 @@ function resolveExt(filename, fs) {
|
|
|
39764
40629
|
const tsConfigCache = createCache();
|
|
39765
40630
|
const tsConfigRefMap = /* @__PURE__ */ new Map();
|
|
39766
40631
|
const fileToScopeCache = createCache();
|
|
40632
|
+
const fileToGlobalScopeCache = createCache();
|
|
39767
40633
|
/**
|
|
39768
40634
|
* @private
|
|
39769
40635
|
*/
|
|
39770
40636
|
function invalidateTypeCache(filename) {
|
|
39771
40637
|
filename = normalizePath(filename);
|
|
39772
40638
|
fileToScopeCache.delete(filename);
|
|
40639
|
+
fileToGlobalScopeCache.delete(filename);
|
|
39773
40640
|
tsConfigCache.delete(filename);
|
|
39774
40641
|
const affectedConfig = tsConfigRefMap.get(filename);
|
|
39775
40642
|
if (affectedConfig) tsConfigCache.delete(affectedConfig);
|
|
39776
40643
|
}
|
|
39777
40644
|
function fileToScope(ctx, filename, asGlobal = false) {
|
|
39778
|
-
const
|
|
40645
|
+
const cache = asGlobal ? fileToGlobalScopeCache : fileToScopeCache;
|
|
40646
|
+
const cached = cache.get(filename);
|
|
39779
40647
|
if (cached) return cached;
|
|
39780
40648
|
const fs = resolveFS(ctx);
|
|
39781
40649
|
const source = fs.readFile(filename) || "";
|
|
39782
40650
|
const body = parseFile(filename, source, fs, ctx.options.babelParserPlugins);
|
|
39783
40651
|
const scope = new TypeScope(filename, source, 0, recordImports(body));
|
|
39784
40652
|
recordTypes(ctx, body, scope, asGlobal);
|
|
39785
|
-
|
|
40653
|
+
cache.set(filename, scope);
|
|
39786
40654
|
return scope;
|
|
39787
40655
|
}
|
|
39788
40656
|
function parseFile(filename, content, fs, parserPlugins) {
|
|
@@ -41151,7 +42019,7 @@ function compileScript(sfc, options) {
|
|
|
41151
42019
|
if (emitsDecl) runtimeOptions += `\n emits: ${emitsDecl},`;
|
|
41152
42020
|
if (vapor && !ssr && sfc.template && !sfc.template.src) {
|
|
41153
42021
|
var _options$templateOpti2;
|
|
41154
|
-
|
|
42022
|
+
if (isMultiRoot(sfc.template.ast, (_options$templateOpti2 = options.templateOptions) === null || _options$templateOpti2 === void 0 ? void 0 : _options$templateOpti2.compilerOptions)) runtimeOptions += `\n __multiRoot: true,`;
|
|
41155
42023
|
}
|
|
41156
42024
|
let definedOptions = "";
|
|
41157
42025
|
if (ctx.optionsRuntimeDecl) definedOptions = scriptSetup.content.slice(ctx.optionsRuntimeDecl.start, ctx.optionsRuntimeDecl.end).trim();
|
|
@@ -41309,7 +42177,7 @@ function mergeSourceMaps(scriptMap, templateMap, templateLineOffset) {
|
|
|
41309
42177
|
//#endregion
|
|
41310
42178
|
//#region packages/compiler-sfc/src/index.ts
|
|
41311
42179
|
init_objectSpread2();
|
|
41312
|
-
const version = "3.6.0-beta.
|
|
42180
|
+
const version = "3.6.0-beta.13";
|
|
41313
42181
|
const parseCache = parseCache$1;
|
|
41314
42182
|
const errorMessages = _objectSpread2(_objectSpread2({}, errorMessages$1), DOMErrorMessages);
|
|
41315
42183
|
const walk = walk$2;
|