@vue/compiler-vapor 3.6.0-beta.12 → 3.6.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler-vapor.cjs.js +839 -138
- package/dist/compiler-vapor.d.ts +56 -32
- package/dist/compiler-vapor.esm-browser.js +951 -199
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-vapor v3.6.0-beta.
|
|
2
|
+
* @vue/compiler-vapor v3.6.0-beta.13
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -32,6 +32,7 @@ const NOOP = () => {};
|
|
|
32
32
|
* Always return false.
|
|
33
33
|
*/
|
|
34
34
|
const NO = () => false;
|
|
35
|
+
const isOn = (key) => key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && (key.charCodeAt(2) > 122 || key.charCodeAt(2) < 97);
|
|
35
36
|
const extend = Object.assign;
|
|
36
37
|
const remove = (arr, el) => {
|
|
37
38
|
const i = arr.indexOf(el);
|
|
@@ -53,6 +54,11 @@ const camelizeReplacer = (_, c) => c ? c.toUpperCase() : "";
|
|
|
53
54
|
* @private
|
|
54
55
|
*/
|
|
55
56
|
const camelize = cacheStringFunction((str) => str.replace(camelizeRE, camelizeReplacer));
|
|
57
|
+
const hyphenateRE = /\B([A-Z])/g;
|
|
58
|
+
/**
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
const hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
|
|
56
62
|
/**
|
|
57
63
|
* @private
|
|
58
64
|
*/
|
|
@@ -84,6 +90,43 @@ function canSetValueDirectly(tagName) {
|
|
|
84
90
|
const isGloballyAllowed = /* @__PURE__ */ makeMap("Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error,Symbol");
|
|
85
91
|
//#endregion
|
|
86
92
|
//#region packages/shared/src/normalizeProp.ts
|
|
93
|
+
function normalizeStyle(value) {
|
|
94
|
+
if (isArray$1(value)) {
|
|
95
|
+
const res = {};
|
|
96
|
+
for (let i = 0; i < value.length; i++) {
|
|
97
|
+
const item = value[i];
|
|
98
|
+
const normalized = isString(item) ? parseStringStyle(item) : normalizeStyle(item);
|
|
99
|
+
if (normalized) for (const key in normalized) res[key] = normalized[key];
|
|
100
|
+
}
|
|
101
|
+
return res;
|
|
102
|
+
} else if (isString(value) || isObject(value)) return value;
|
|
103
|
+
}
|
|
104
|
+
const listDelimiterRE = /;(?![^(]*\))/g;
|
|
105
|
+
const propertyDelimiterRE = /:([^]+)/;
|
|
106
|
+
const styleCommentRE = /\/\*[^]*?\*\//g;
|
|
107
|
+
function parseStringStyle(cssText) {
|
|
108
|
+
const ret = {};
|
|
109
|
+
cssText.replace(styleCommentRE, "").split(listDelimiterRE).forEach((item) => {
|
|
110
|
+
if (item) {
|
|
111
|
+
const tmp = item.split(propertyDelimiterRE);
|
|
112
|
+
tmp.length > 1 && (ret[tmp[0].trim()] = tmp[1].trim());
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return ret;
|
|
116
|
+
}
|
|
117
|
+
function stringifyStyle(styles) {
|
|
118
|
+
if (!styles) return "";
|
|
119
|
+
if (isString(styles)) return styles;
|
|
120
|
+
let ret = "";
|
|
121
|
+
for (const key in styles) {
|
|
122
|
+
const value = styles[key];
|
|
123
|
+
if (isString(value) || typeof value === "number") {
|
|
124
|
+
const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key);
|
|
125
|
+
ret += `${normalizedKey}:${value};`;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return ret;
|
|
129
|
+
}
|
|
87
130
|
function normalizeClass(value) {
|
|
88
131
|
let res = "";
|
|
89
132
|
if (isString(value)) res = value;
|
|
@@ -146,6 +189,17 @@ const isInlineTag = /* @__PURE__ */ makeMap(INLINE_TAGS);
|
|
|
146
189
|
* Do NOT use in runtime code paths unless behind `__DEV__` flag.
|
|
147
190
|
*/
|
|
148
191
|
const isBlockTag = /* @__PURE__ */ makeMap(BLOCK_TAGS);
|
|
192
|
+
/**
|
|
193
|
+
* The full list is needed during SSR to produce the correct initial markup.
|
|
194
|
+
*/
|
|
195
|
+
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");
|
|
196
|
+
/**
|
|
197
|
+
* Boolean attributes should be included if the value is truthy or ''.
|
|
198
|
+
* e.g. `<select multiple>` compiles to `{ multiple: '' }`
|
|
199
|
+
*/
|
|
200
|
+
function includeBooleanAttr(value) {
|
|
201
|
+
return !!value || value === "";
|
|
202
|
+
}
|
|
149
203
|
function shouldSetAsAttr(tagName, key) {
|
|
150
204
|
if (key === "spellcheck" || key === "draggable" || key === "translate" || key === "autocorrect") return true;
|
|
151
205
|
if (key === "form") return true;
|
|
@@ -19547,8 +19601,70 @@ function genPrependNode(oper, { helper }) {
|
|
|
19547
19601
|
return [NEWLINE, ...genCall(helper("prepend"), `n${oper.parent}`, ...oper.elements.map((el) => `n${el}`))];
|
|
19548
19602
|
}
|
|
19549
19603
|
//#endregion
|
|
19604
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
|
|
19605
|
+
function _typeof(o) {
|
|
19606
|
+
"@babel/helpers - typeof";
|
|
19607
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
19608
|
+
return typeof o;
|
|
19609
|
+
} : function(o) {
|
|
19610
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
19611
|
+
}, _typeof(o);
|
|
19612
|
+
}
|
|
19613
|
+
//#endregion
|
|
19614
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
|
|
19615
|
+
function toPrimitive(t, r) {
|
|
19616
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
19617
|
+
var e = t[Symbol.toPrimitive];
|
|
19618
|
+
if (void 0 !== e) {
|
|
19619
|
+
var i = e.call(t, r || "default");
|
|
19620
|
+
if ("object" != _typeof(i)) return i;
|
|
19621
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
19622
|
+
}
|
|
19623
|
+
return ("string" === r ? String : Number)(t);
|
|
19624
|
+
}
|
|
19625
|
+
//#endregion
|
|
19626
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
|
|
19627
|
+
function toPropertyKey(t) {
|
|
19628
|
+
var i = toPrimitive(t, "string");
|
|
19629
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
19630
|
+
}
|
|
19631
|
+
//#endregion
|
|
19632
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
|
|
19633
|
+
function _defineProperty(e, r, t) {
|
|
19634
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
19635
|
+
value: t,
|
|
19636
|
+
enumerable: !0,
|
|
19637
|
+
configurable: !0,
|
|
19638
|
+
writable: !0
|
|
19639
|
+
}) : e[r] = t, e;
|
|
19640
|
+
}
|
|
19641
|
+
//#endregion
|
|
19642
|
+
//#region \0@oxc-project+runtime@0.129.0/helpers/objectSpread2.js
|
|
19643
|
+
function ownKeys(e, r) {
|
|
19644
|
+
var t = Object.keys(e);
|
|
19645
|
+
if (Object.getOwnPropertySymbols) {
|
|
19646
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
19647
|
+
r && (o = o.filter(function(r) {
|
|
19648
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
19649
|
+
})), t.push.apply(t, o);
|
|
19650
|
+
}
|
|
19651
|
+
return t;
|
|
19652
|
+
}
|
|
19653
|
+
function _objectSpread2(e) {
|
|
19654
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
19655
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
19656
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
19657
|
+
_defineProperty(e, r, t[r]);
|
|
19658
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
19659
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
19660
|
+
});
|
|
19661
|
+
}
|
|
19662
|
+
return e;
|
|
19663
|
+
}
|
|
19664
|
+
//#endregion
|
|
19550
19665
|
//#region packages/compiler-vapor/src/generators/expression.ts
|
|
19551
19666
|
function genExpression(node, context, assignment) {
|
|
19667
|
+
node = context.getExpressionReplacement(node);
|
|
19552
19668
|
const { content, ast, isStatic, loc } = node;
|
|
19553
19669
|
if (isStatic) return [[
|
|
19554
19670
|
JSON.stringify(content),
|
|
@@ -19663,11 +19779,12 @@ function canPrefix(name) {
|
|
|
19663
19779
|
return true;
|
|
19664
19780
|
}
|
|
19665
19781
|
function processExpressions(context, expressions, shouldDeclare) {
|
|
19782
|
+
const expressionReplacements = /* @__PURE__ */ new Map();
|
|
19666
19783
|
const { seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable } = analyzeExpressions(expressions);
|
|
19667
19784
|
const reservedNames = new Set(seenIdentifier);
|
|
19668
|
-
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames);
|
|
19669
|
-
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames);
|
|
19670
|
-
return genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare);
|
|
19785
|
+
const varDeclarations = processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames, expressionReplacements);
|
|
19786
|
+
const expDeclarations = processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames, expressionReplacements);
|
|
19787
|
+
return _objectSpread2(_objectSpread2({}, genDeclarations([...varDeclarations, ...expDeclarations], context, shouldDeclare)), {}, { expressionReplacements });
|
|
19671
19788
|
}
|
|
19672
19789
|
function analyzeExpressions(expressions) {
|
|
19673
19790
|
const seenVariable = Object.create(null);
|
|
@@ -19725,7 +19842,13 @@ function analyzeExpressions(expressions) {
|
|
|
19725
19842
|
updatedVariable
|
|
19726
19843
|
};
|
|
19727
19844
|
}
|
|
19728
|
-
function
|
|
19845
|
+
function getProcessedExpression(exp, expressionReplacements) {
|
|
19846
|
+
return expressionReplacements.get(exp) || exp;
|
|
19847
|
+
}
|
|
19848
|
+
function setExpressionReplacement(expressionReplacements, exp, content, ast) {
|
|
19849
|
+
expressionReplacements.set(exp, extend({ ast }, createSimpleExpression(content, exp.isStatic, exp.loc, exp.constType)));
|
|
19850
|
+
}
|
|
19851
|
+
function processRepeatedVariables(context, seenVariable, variableToExpMap, expToVariableMap, seenIdentifier, updatedVariable, reservedNames, expressionReplacements) {
|
|
19729
19852
|
const declarations = [];
|
|
19730
19853
|
const expToReplacementMap = /* @__PURE__ */ new Map();
|
|
19731
19854
|
for (const [name, exps] of variableToExpMap) {
|
|
@@ -19758,14 +19881,15 @@ function processRepeatedVariables(context, seenVariable, variableToExpMap, expTo
|
|
|
19758
19881
|
}
|
|
19759
19882
|
}
|
|
19760
19883
|
for (const [exp, replacements] of expToReplacementMap) {
|
|
19884
|
+
let content = getProcessedExpression(exp, expressionReplacements).content;
|
|
19761
19885
|
replacements.flatMap(({ name, locs }) => locs.map(({ start, end }) => ({
|
|
19762
19886
|
start,
|
|
19763
19887
|
end,
|
|
19764
19888
|
name
|
|
19765
19889
|
}))).sort((a, b) => b.end - a.end).forEach(({ start, end, name }) => {
|
|
19766
|
-
|
|
19890
|
+
content = content.slice(0, start - 1) + name + content.slice(end - 1);
|
|
19767
19891
|
});
|
|
19768
|
-
exp
|
|
19892
|
+
setExpressionReplacement(expressionReplacements, exp, content, parseExp(context, content));
|
|
19769
19893
|
}
|
|
19770
19894
|
return declarations;
|
|
19771
19895
|
}
|
|
@@ -19781,13 +19905,14 @@ function shouldDeclareVariable(name, expToVariableMap, exps) {
|
|
|
19781
19905
|
if (vars.every((v) => v.every((e, idx) => e === first[idx]))) return false;
|
|
19782
19906
|
return true;
|
|
19783
19907
|
}
|
|
19784
|
-
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames) {
|
|
19908
|
+
function processRepeatedExpressions(context, expressions, varDeclarations, updatedVariable, expToVariableMap, reservedNames, expressionReplacements) {
|
|
19785
19909
|
const declarations = [];
|
|
19786
19910
|
const seenExp = expressions.reduce((acc, exp) => {
|
|
19787
19911
|
const vars = expToVariableMap.get(exp);
|
|
19788
19912
|
if (!vars) return acc;
|
|
19913
|
+
const processed = getProcessedExpression(exp, expressionReplacements);
|
|
19789
19914
|
const variables = vars.map((v) => v.name);
|
|
19790
|
-
if (
|
|
19915
|
+
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;
|
|
19791
19916
|
return acc;
|
|
19792
19917
|
}, Object.create(null));
|
|
19793
19918
|
Object.entries(seenExp).forEach(([content, count]) => {
|
|
@@ -19796,13 +19921,13 @@ function processRepeatedExpressions(context, expressions, varDeclarations, updat
|
|
|
19796
19921
|
for (let i = varDeclarations.length - 1; i >= 0; i--) {
|
|
19797
19922
|
const item = varDeclarations[i];
|
|
19798
19923
|
if (!item.exps || !item.seenCount) continue;
|
|
19799
|
-
if ([...item.exps].every((node) => node.content === content && item.seenCount === count)) {
|
|
19924
|
+
if ([...item.exps].every((node) => getProcessedExpression(node, expressionReplacements).content === content && item.seenCount === count)) {
|
|
19800
19925
|
delVars[item.name] = item.rawName;
|
|
19801
19926
|
reservedNames.delete(item.name);
|
|
19802
19927
|
varDeclarations.splice(i, 1);
|
|
19803
19928
|
}
|
|
19804
19929
|
}
|
|
19805
|
-
const value = extend({}, expressions.find((exp) => exp.content === content));
|
|
19930
|
+
const value = extend({}, getProcessedExpression(expressions.find((exp) => getProcessedExpression(exp, expressionReplacements).content === content), expressionReplacements));
|
|
19806
19931
|
Object.keys(delVars).forEach((name) => {
|
|
19807
19932
|
value.content = value.content.replace(name, delVars[name]);
|
|
19808
19933
|
if (value.ast) value.ast = parseExp(context, value.content);
|
|
@@ -19813,12 +19938,11 @@ function processRepeatedExpressions(context, expressions, varDeclarations, updat
|
|
|
19813
19938
|
value
|
|
19814
19939
|
});
|
|
19815
19940
|
expressions.forEach((exp) => {
|
|
19816
|
-
|
|
19817
|
-
|
|
19818
|
-
|
|
19819
|
-
|
|
19820
|
-
|
|
19821
|
-
exp.ast = parseExp(context, exp.content);
|
|
19941
|
+
const processed = getProcessedExpression(exp, expressionReplacements);
|
|
19942
|
+
if (processed.content === content) setExpressionReplacement(expressionReplacements, exp, varName, null);
|
|
19943
|
+
else if (processed.content.includes(content)) {
|
|
19944
|
+
const replacedContent = processed.content.replace(new RegExp(escapeRegExp(content), "g"), varName);
|
|
19945
|
+
setExpressionReplacement(expressionReplacements, exp, replacedContent, parseExp(context, replacedContent));
|
|
19822
19946
|
}
|
|
19823
19947
|
});
|
|
19824
19948
|
}
|
|
@@ -19897,22 +20021,31 @@ const isMemberExpression = (node) => {
|
|
|
19897
20021
|
function genSetEvent(oper, context) {
|
|
19898
20022
|
const { helper } = context;
|
|
19899
20023
|
const { element, key, keyOverride, value, modifiers, delegate, effect } = oper;
|
|
19900
|
-
|
|
19901
|
-
const handler = [
|
|
19902
|
-
`${context.helper("createInvoker")}(`,
|
|
19903
|
-
...genEventHandler(context, [value], modifiers),
|
|
19904
|
-
`)`
|
|
19905
|
-
];
|
|
19906
|
-
const eventOptions = genEventOptions();
|
|
20024
|
+
let handler;
|
|
19907
20025
|
if (delegate) {
|
|
19908
20026
|
context.delegates.add(key.content);
|
|
19909
20027
|
if (!context.block.operation.some(isSameDelegateEvent)) return [
|
|
19910
20028
|
NEWLINE,
|
|
19911
20029
|
`n${element}.$evt${key.content} = `,
|
|
19912
|
-
...
|
|
20030
|
+
...genDirectHandler()
|
|
19913
20031
|
];
|
|
19914
20032
|
}
|
|
19915
|
-
|
|
20033
|
+
const name = genName();
|
|
20034
|
+
const eventOptions = genEventOptions();
|
|
20035
|
+
return [NEWLINE, ...genCall(helper(effect ? "onBinding" : delegate ? "delegate" : "on"), `n${element}`, name, genHandler(), eventOptions)];
|
|
20036
|
+
function genHandler() {
|
|
20037
|
+
return handler || (handler = genEventHandler(context, [value], modifiers));
|
|
20038
|
+
}
|
|
20039
|
+
function genInvoker() {
|
|
20040
|
+
return [
|
|
20041
|
+
`${helper("createInvoker")}(`,
|
|
20042
|
+
...genHandler(),
|
|
20043
|
+
`)`
|
|
20044
|
+
];
|
|
20045
|
+
}
|
|
20046
|
+
function genDirectHandler() {
|
|
20047
|
+
return modifiers.keys.length || modifiers.nonKeys.length ? genEventHandler(context, [value], modifiers, { modifierHelper: "vapor" }) : genInvoker();
|
|
20048
|
+
}
|
|
19916
20049
|
function genName() {
|
|
19917
20050
|
const expr = genExpression(key, context);
|
|
19918
20051
|
if (keyOverride) {
|
|
@@ -19932,8 +20065,8 @@ function genSetEvent(oper, context) {
|
|
|
19932
20065
|
}
|
|
19933
20066
|
function genEventOptions() {
|
|
19934
20067
|
let { options } = modifiers;
|
|
19935
|
-
if (!options.length
|
|
19936
|
-
return genMulti(DELIMITERS_OBJECT_NEWLINE,
|
|
20068
|
+
if (!options.length) return;
|
|
20069
|
+
return genMulti(DELIMITERS_OBJECT_NEWLINE, ...options.map((option) => [`${option}: true`]));
|
|
19937
20070
|
}
|
|
19938
20071
|
function isSameDelegateEvent(op) {
|
|
19939
20072
|
if (op.type === 6 && op !== oper && op.delegate && op.element === oper.element && op.key.content === key.content) return true;
|
|
@@ -19946,7 +20079,9 @@ function genSetDynamicEvents(oper, context) {
|
|
|
19946
20079
|
function genEventHandler(context, values, modifiers = {
|
|
19947
20080
|
nonKeys: [],
|
|
19948
20081
|
keys: []
|
|
19949
|
-
},
|
|
20082
|
+
}, options = {}) {
|
|
20083
|
+
const { asComponentProp = false, extraWrap = false, modifierHelper = "runtime" } = options;
|
|
20084
|
+
const useVaporModifierHelper = modifierHelper === "vapor";
|
|
19950
20085
|
let handlerExp = [];
|
|
19951
20086
|
if (values) {
|
|
19952
20087
|
values.forEach((value, index) => {
|
|
@@ -19987,16 +20122,16 @@ function genEventHandler(context, values, modifiers = {
|
|
|
19987
20122
|
}
|
|
19988
20123
|
if (handlerExp.length === 0) handlerExp = ["() => {}"];
|
|
19989
20124
|
const { keys, nonKeys } = modifiers;
|
|
19990
|
-
if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys);
|
|
19991
|
-
if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys);
|
|
20125
|
+
if (nonKeys.length) handlerExp = genWithModifiers(context, handlerExp, nonKeys, useVaporModifierHelper && !keys.length);
|
|
20126
|
+
if (keys.length) handlerExp = genWithKeys(context, handlerExp, keys, useVaporModifierHelper);
|
|
19992
20127
|
if (extraWrap) handlerExp.unshift(`() => `);
|
|
19993
20128
|
return handlerExp;
|
|
19994
20129
|
}
|
|
19995
|
-
function genWithModifiers(context, handler, nonKeys) {
|
|
19996
|
-
return genCall(context.helper("withModifiers"), handler, JSON.stringify(nonKeys));
|
|
20130
|
+
function genWithModifiers(context, handler, nonKeys, useVaporHelper = false) {
|
|
20131
|
+
return genCall(context.helper(useVaporHelper ? "withVaporModifiers" : "withModifiers"), handler, JSON.stringify(nonKeys));
|
|
19997
20132
|
}
|
|
19998
|
-
function genWithKeys(context, handler, keys) {
|
|
19999
|
-
return genCall(context.helper("withKeys"), handler, JSON.stringify(keys));
|
|
20133
|
+
function genWithKeys(context, handler, keys, useVaporHelper = false) {
|
|
20134
|
+
return genCall(context.helper(useVaporHelper ? "withVaporKeys" : "withKeys"), handler, JSON.stringify(keys));
|
|
20000
20135
|
}
|
|
20001
20136
|
function isConstantBinding(value, context) {
|
|
20002
20137
|
if (value.ast === null) {
|
|
@@ -20063,6 +20198,8 @@ function genFor(oper, context) {
|
|
|
20063
20198
|
let flags = 0;
|
|
20064
20199
|
if (onlyChild) flags |= 1;
|
|
20065
20200
|
if (component) flags |= 2;
|
|
20201
|
+
if (isFragmentBlock(render)) flags |= 16;
|
|
20202
|
+
if (!component && isSingleNodeBlock(render)) flags |= 8;
|
|
20066
20203
|
if (once) flags |= 4;
|
|
20067
20204
|
const onResetCalls = [];
|
|
20068
20205
|
for (let i = 0; i < selectorPatterns.length; i++) onResetCalls.push(NEWLINE, `n${id}.onReset(${selectorName(i)}.reset)`);
|
|
@@ -20095,6 +20232,21 @@ function genFor(oper, context) {
|
|
|
20095
20232
|
return idMap;
|
|
20096
20233
|
}
|
|
20097
20234
|
}
|
|
20235
|
+
function isSingleNodeBlock(block) {
|
|
20236
|
+
const child = getSingleReturnedChild(block);
|
|
20237
|
+
return !!child && child.template != null;
|
|
20238
|
+
}
|
|
20239
|
+
function isFragmentBlock(block) {
|
|
20240
|
+
const child = getSingleReturnedChild(block);
|
|
20241
|
+
const operation = child && child.operation;
|
|
20242
|
+
if (!operation) return false;
|
|
20243
|
+
return operation.type === 13 || operation.type === 16 || operation.type === 17 || operation.type === 15 && !operation.once || operation.type === 12 && !!operation.dynamic && !operation.dynamic.isStatic;
|
|
20244
|
+
}
|
|
20245
|
+
function getSingleReturnedChild(block) {
|
|
20246
|
+
if (block.returns.length !== 1) return;
|
|
20247
|
+
const id = block.returns[0];
|
|
20248
|
+
for (const child of block.dynamic.children) if (child.id === id) return child;
|
|
20249
|
+
}
|
|
20098
20250
|
function parseValueDestructure(value, context) {
|
|
20099
20251
|
const map = /* @__PURE__ */ new Map();
|
|
20100
20252
|
if (value) {
|
|
@@ -20280,6 +20432,7 @@ function genIf(oper, context, isNested = false) {
|
|
|
20280
20432
|
const { helper } = context;
|
|
20281
20433
|
const { condition, positive, negative, once, index, blockShape } = oper;
|
|
20282
20434
|
const [frag, push] = buildCodeFragment();
|
|
20435
|
+
const flags = genIfFlags(blockShape, once, negative ? index : void 0);
|
|
20283
20436
|
const conditionExpr = [
|
|
20284
20437
|
"() => (",
|
|
20285
20438
|
...genExpression(condition, context),
|
|
@@ -20290,9 +20443,24 @@ function genIf(oper, context, isNested = false) {
|
|
|
20290
20443
|
if (negative) if (negative.type === 1) negativeArg = genBlock(negative, context);
|
|
20291
20444
|
else negativeArg = ["() => ", ...genIf(negative, context, true)];
|
|
20292
20445
|
if (!isNested) push(NEWLINE, `const n${oper.id} = `);
|
|
20293
|
-
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg,
|
|
20446
|
+
push(...genCall(helper("createIf"), conditionExpr, positiveArg, negativeArg, flags));
|
|
20294
20447
|
return frag;
|
|
20295
20448
|
}
|
|
20449
|
+
function genIfFlags(blockShape, once, index) {
|
|
20450
|
+
let flags = blockShape;
|
|
20451
|
+
if (once) flags |= 16;
|
|
20452
|
+
else if (index !== void 0) flags |= index + 1 << 7;
|
|
20453
|
+
if (flags === 1) return false;
|
|
20454
|
+
return `${flags} /* ${genIfFlagNames(once, index, blockShape)} */`;
|
|
20455
|
+
}
|
|
20456
|
+
function genIfFlagNames(once, index, blockShape) {
|
|
20457
|
+
const names = ["BLOCK_SHAPE"];
|
|
20458
|
+
if (blockShape & 32) names.push("TRUE_NO_SCOPE");
|
|
20459
|
+
if (blockShape & 64) names.push("FALSE_NO_SCOPE");
|
|
20460
|
+
if (once) names.push("ONCE");
|
|
20461
|
+
else if (index !== void 0) names.push("INDEX_SHIFT");
|
|
20462
|
+
return names.join(", ");
|
|
20463
|
+
}
|
|
20296
20464
|
//#endregion
|
|
20297
20465
|
//#region packages/compiler-vapor/src/generators/prop.ts
|
|
20298
20466
|
const helpers = {
|
|
@@ -20342,15 +20510,16 @@ function resolveClassName(values, context) {
|
|
|
20342
20510
|
const entries = [];
|
|
20343
20511
|
let sawDynamic = false;
|
|
20344
20512
|
let sawSuffix = false;
|
|
20345
|
-
for (const
|
|
20513
|
+
for (const rawValue of values) {
|
|
20514
|
+
const value = context.getExpressionReplacement(rawValue);
|
|
20346
20515
|
const staticValue = getLiteralExpressionValue(value, true);
|
|
20347
20516
|
if (staticValue != null) {
|
|
20348
20517
|
const normalized = normalizeClass(staticValue);
|
|
20349
|
-
if (normalized) if (sawSuffix) suffix = appendClass(suffix, normalized);
|
|
20518
|
+
if (normalized) if (sawSuffix) suffix = appendClass$1(suffix, normalized);
|
|
20350
20519
|
else if (sawDynamic) {
|
|
20351
20520
|
sawSuffix = true;
|
|
20352
|
-
suffix = appendClass(suffix, normalized);
|
|
20353
|
-
} else prefix = appendClass(prefix, normalized);
|
|
20521
|
+
suffix = appendClass$1(suffix, normalized);
|
|
20522
|
+
} else prefix = appendClass$1(prefix, normalized);
|
|
20354
20523
|
continue;
|
|
20355
20524
|
}
|
|
20356
20525
|
const ast = value.ast;
|
|
@@ -20371,7 +20540,7 @@ function resolveClassName(values, context) {
|
|
|
20371
20540
|
function resolveObjectClassName(source, ast, entries, context) {
|
|
20372
20541
|
for (const prop of ast.properties) {
|
|
20373
20542
|
if (prop.type !== "ObjectProperty" || prop.computed) return false;
|
|
20374
|
-
const rawClassName = getObjectPropertyName(prop);
|
|
20543
|
+
const rawClassName = getObjectPropertyName$1(prop);
|
|
20375
20544
|
if (rawClassName == null) return false;
|
|
20376
20545
|
const className = normalizeClass(rawClassName);
|
|
20377
20546
|
if (!className) continue;
|
|
@@ -20416,10 +20585,10 @@ function genClassFlags(entries, context) {
|
|
|
20416
20585
|
});
|
|
20417
20586
|
return values;
|
|
20418
20587
|
}
|
|
20419
|
-
function appendClass(base, value) {
|
|
20588
|
+
function appendClass$1(base, value) {
|
|
20420
20589
|
return base ? value ? `${base} ${value}` : base : value;
|
|
20421
20590
|
}
|
|
20422
|
-
function getObjectPropertyName(prop) {
|
|
20591
|
+
function getObjectPropertyName$1(prop) {
|
|
20423
20592
|
const key = prop.key;
|
|
20424
20593
|
if (key.type === "Identifier") return key.name;
|
|
20425
20594
|
else if (key.type === "StringLiteral") return key.value;
|
|
@@ -20511,8 +20680,23 @@ function getSpecialHelper(keyName, tagName, isSVG) {
|
|
|
20511
20680
|
const setTemplateRefIdent = `_setTemplateRef`;
|
|
20512
20681
|
function genSetTemplateRef(oper, context) {
|
|
20513
20682
|
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
20683
|
+
if (context.staticTemplateRefHelperCandidate === oper) return genSetStaticTemplateRef(oper, refValue, refKey, context);
|
|
20684
|
+
context.needsTemplateRefSetter = true;
|
|
20514
20685
|
return [NEWLINE, ...genCall(setTemplateRefIdent, `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
20515
20686
|
}
|
|
20687
|
+
function genSetStaticTemplateRef(oper, refValue, refKey, context) {
|
|
20688
|
+
return [NEWLINE, ...genCall(context.helper("setStaticTemplateRef"), `n${oper.element}`, refValue, oper.refFor && "true", refKey)];
|
|
20689
|
+
}
|
|
20690
|
+
function genSetTemplateRefBinding(oper, context) {
|
|
20691
|
+
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
20692
|
+
const setter = context.inSlotBlock && setTemplateRefIdent;
|
|
20693
|
+
if (context.inSlotBlock) context.needsTemplateRefSetter = true;
|
|
20694
|
+
return [NEWLINE, ...genCall([context.helper("setTemplateRefBinding"), "undefined"], `n${oper.element}`, ["() => ", ...refValue], ...setter || oper.refFor || refKey ? [
|
|
20695
|
+
setter,
|
|
20696
|
+
oper.refFor && "true",
|
|
20697
|
+
refKey
|
|
20698
|
+
] : [])];
|
|
20699
|
+
}
|
|
20516
20700
|
function genRefValue(value, context) {
|
|
20517
20701
|
if (value && context.options.inline) {
|
|
20518
20702
|
const binding = context.options.bindingMetadata[value.content];
|
|
@@ -20616,15 +20800,18 @@ function filterCustomDirectives(id, operations) {
|
|
|
20616
20800
|
//#region packages/compiler-vapor/src/generators/component.ts
|
|
20617
20801
|
function genCreateComponent(operation, context) {
|
|
20618
20802
|
const { helper } = context;
|
|
20803
|
+
const singleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
20804
|
+
const useAssetComponentHelper = operation.asset && !operation.dynamic && context.block === context.ir.block && !!singleUseAssetComponentNames && singleUseAssetComponentNames.has(operation.tag);
|
|
20805
|
+
const maybeSelfReference = useAssetComponentHelper && operation.tag.endsWith("__self");
|
|
20619
20806
|
const tag = genTag();
|
|
20620
20807
|
const { root, props, slots, once } = operation;
|
|
20621
20808
|
const rawSlots = genRawSlots(slots, context);
|
|
20622
20809
|
const [ids, handlers] = processInlineHandlers(props, context);
|
|
20623
|
-
const rawProps = context.withId(() => genRawProps(props, context), ids);
|
|
20810
|
+
const rawProps = context.withId(() => genRawProps(props, context, true), ids);
|
|
20624
20811
|
return [
|
|
20625
20812
|
NEWLINE,
|
|
20626
20813
|
...handlers.reduce((acc, { name, value }) => {
|
|
20627
|
-
const handler = genEventHandler(context, [value]
|
|
20814
|
+
const handler = genEventHandler(context, [value]);
|
|
20628
20815
|
return [
|
|
20629
20816
|
...acc,
|
|
20630
20817
|
`const ${name} = `,
|
|
@@ -20633,7 +20820,7 @@ function genCreateComponent(operation, context) {
|
|
|
20633
20820
|
];
|
|
20634
20821
|
}, []),
|
|
20635
20822
|
`const n${operation.id} = `,
|
|
20636
|
-
...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"),
|
|
20823
|
+
...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"),
|
|
20637
20824
|
...genDirectivesForElement(operation.id, context)
|
|
20638
20825
|
];
|
|
20639
20826
|
function genTag() {
|
|
@@ -20644,7 +20831,10 @@ function genCreateComponent(operation, context) {
|
|
|
20644
20831
|
...genExpression(operation.dynamic, context),
|
|
20645
20832
|
")"
|
|
20646
20833
|
];
|
|
20647
|
-
else if (
|
|
20834
|
+
else if (useAssetComponentHelper) {
|
|
20835
|
+
const name = maybeSelfReference ? operation.tag.slice(0, -6) : operation.tag;
|
|
20836
|
+
return JSON.stringify(name);
|
|
20837
|
+
} else if (operation.asset) return toValidAssetId(operation.tag, "component");
|
|
20648
20838
|
else {
|
|
20649
20839
|
const { tag } = operation;
|
|
20650
20840
|
const builtInTag = isBuiltInComponent(tag);
|
|
@@ -20684,14 +20874,14 @@ function processInlineHandlers(props, context) {
|
|
|
20684
20874
|
}
|
|
20685
20875
|
return [ids, handlers];
|
|
20686
20876
|
}
|
|
20687
|
-
function genRawProps(props, context) {
|
|
20877
|
+
function genRawProps(props, context, directStaticLiteralProps = false) {
|
|
20688
20878
|
const staticProps = props[0];
|
|
20689
20879
|
if (isArray$1(staticProps)) {
|
|
20690
20880
|
if (!staticProps.length && props.length === 1) return;
|
|
20691
|
-
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context));
|
|
20692
|
-
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context));
|
|
20881
|
+
return genStaticProps(staticProps, context, genDynamicProps(props.slice(1), context, directStaticLiteralProps), directStaticLiteralProps);
|
|
20882
|
+
} else if (props.length) return genStaticProps([], context, genDynamicProps(props, context, directStaticLiteralProps), directStaticLiteralProps);
|
|
20693
20883
|
}
|
|
20694
|
-
function genStaticProps(props, context, dynamicProps) {
|
|
20884
|
+
function genStaticProps(props, context, dynamicProps, directStaticLiteralProps = false) {
|
|
20695
20885
|
const args = [];
|
|
20696
20886
|
const handlerGroups = /* @__PURE__ */ new Map();
|
|
20697
20887
|
const ensureHandlerGroup = (keyName, keyFrag) => {
|
|
@@ -20724,11 +20914,11 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
20724
20914
|
continue;
|
|
20725
20915
|
}
|
|
20726
20916
|
const keyFrag = genPropKey(prop, context);
|
|
20727
|
-
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
|
|
20728
|
-
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, true
|
|
20917
|
+
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 }));
|
|
20918
|
+
else for (const value of prop.values) addHandler(keyName, keyFrag, genEventHandler(context, [value], prop.handlerModifiers, { asComponentProp: true }));
|
|
20729
20919
|
continue;
|
|
20730
20920
|
}
|
|
20731
|
-
args.push(genProp(prop, context, true));
|
|
20921
|
+
args.push(genProp(prop, context, true, true, directStaticLiteralProps && isDirectStaticLiteralProp(prop, context)));
|
|
20732
20922
|
if (prop.model) {
|
|
20733
20923
|
if (prop.key.isStatic) {
|
|
20734
20924
|
const keyName = `onUpdate:${camelize(prop.key.content)}`;
|
|
@@ -20753,7 +20943,7 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
20753
20943
|
" + \"Modifiers\"]"
|
|
20754
20944
|
];
|
|
20755
20945
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
20756
|
-
args.push([...modifiersKey, `: () => ({ ${modifiersVal} })`]);
|
|
20946
|
+
args.push([...modifiersKey, directStaticLiteralProps ? `: { ${modifiersVal} }` : `: () => ({ ${modifiersVal} })`]);
|
|
20757
20947
|
}
|
|
20758
20948
|
}
|
|
20759
20949
|
}
|
|
@@ -20768,13 +20958,13 @@ function genStaticProps(props, context, dynamicProps) {
|
|
|
20768
20958
|
if (dynamicProps) args.push([`$: `, ...dynamicProps]);
|
|
20769
20959
|
return genMulti(args.length > 1 ? DELIMITERS_OBJECT_NEWLINE : DELIMITERS_OBJECT, ...args);
|
|
20770
20960
|
}
|
|
20771
|
-
function genDynamicProps(props, context) {
|
|
20961
|
+
function genDynamicProps(props, context, directStaticLiteralProps = false) {
|
|
20772
20962
|
const { helper } = context;
|
|
20773
20963
|
const frags = [];
|
|
20774
20964
|
for (const p of props) {
|
|
20775
20965
|
let expr;
|
|
20776
20966
|
if (isArray$1(p)) {
|
|
20777
|
-
if (p.length) frags.push(genStaticProps(p, context));
|
|
20967
|
+
if (p.length) frags.push(genStaticProps(p, context, void 0, directStaticLiteralProps));
|
|
20778
20968
|
continue;
|
|
20779
20969
|
} else if (p.kind === 1) if (p.model) {
|
|
20780
20970
|
const entries = [genProp(p, context)];
|
|
@@ -20785,7 +20975,7 @@ function genDynamicProps(props, context) {
|
|
|
20785
20975
|
];
|
|
20786
20976
|
entries.push([
|
|
20787
20977
|
...updateKey,
|
|
20788
|
-
":
|
|
20978
|
+
": ",
|
|
20789
20979
|
...genModelHandler(p.values[0], context)
|
|
20790
20980
|
]);
|
|
20791
20981
|
const { modelModifiers } = p;
|
|
@@ -20796,10 +20986,10 @@ function genDynamicProps(props, context) {
|
|
|
20796
20986
|
" + \"Modifiers\"]"
|
|
20797
20987
|
];
|
|
20798
20988
|
const modifiersVal = genDirectiveModifiers(modelModifiers);
|
|
20799
|
-
entries.push([...modifiersKey, `:
|
|
20989
|
+
entries.push([...modifiersKey, `: { ${modifiersVal} }`]);
|
|
20800
20990
|
}
|
|
20801
20991
|
expr = genMulti(DELIMITERS_OBJECT_NEWLINE, ...entries);
|
|
20802
|
-
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context));
|
|
20992
|
+
} else expr = genMulti(DELIMITERS_OBJECT, genProp(p, context, false, false));
|
|
20803
20993
|
else {
|
|
20804
20994
|
expr = genExpression(p.value, context);
|
|
20805
20995
|
if (p.handler) expr = genCall(helper("toHandlers"), expr);
|
|
@@ -20812,27 +21002,79 @@ function genDynamicProps(props, context) {
|
|
|
20812
21002
|
}
|
|
20813
21003
|
if (frags.length) return genMulti(DELIMITERS_ARRAY_NEWLINE, ...frags);
|
|
20814
21004
|
}
|
|
20815
|
-
function genProp(prop, context, isStatic) {
|
|
21005
|
+
function genProp(prop, context, isStatic, wrapHandler = true, directStaticLiteral = false) {
|
|
20816
21006
|
const values = genPropValue(prop.values, context);
|
|
20817
21007
|
return [
|
|
20818
21008
|
...genPropKey(prop, context),
|
|
20819
21009
|
": ",
|
|
20820
|
-
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers,
|
|
21010
|
+
...prop.handler ? genEventHandler(context, prop.values, prop.handlerModifiers, {
|
|
21011
|
+
asComponentProp: true,
|
|
21012
|
+
extraWrap: wrapHandler
|
|
21013
|
+
}) : isStatic ? directStaticLiteral ? values : [
|
|
20821
21014
|
"() => (",
|
|
20822
21015
|
...values,
|
|
20823
21016
|
")"
|
|
20824
21017
|
] : values
|
|
20825
21018
|
];
|
|
20826
21019
|
}
|
|
21020
|
+
/**
|
|
21021
|
+
* Static literal values are safe to emit directly because reading them cannot
|
|
21022
|
+
* touch reactive state. Keep handlers, v-model values, and dynamic expressions
|
|
21023
|
+
* as getter sources to preserve lazy access and merge semantics.
|
|
21024
|
+
*/
|
|
21025
|
+
function isDirectStaticLiteralProp(prop, context) {
|
|
21026
|
+
return prop.key.isStatic && prop.values.length === 1 && !prop.handler && !prop.model && isDirectConstantValue(prop.values[0], context);
|
|
21027
|
+
}
|
|
21028
|
+
function isDirectConstantValue(value, context) {
|
|
21029
|
+
value = context.getExpressionReplacement(value);
|
|
21030
|
+
if (value.isStatic) return true;
|
|
21031
|
+
const ast = value.ast;
|
|
21032
|
+
if (ast === null) return value.content === "true" || value.content === "false" || value.content === "null" || value.content === "undefined";
|
|
21033
|
+
if (!ast) return false;
|
|
21034
|
+
return isDirectConstantAst(ast);
|
|
21035
|
+
}
|
|
21036
|
+
function isDirectConstantAst(node) {
|
|
21037
|
+
switch (node.type) {
|
|
21038
|
+
case "StringLiteral":
|
|
21039
|
+
case "NumericLiteral":
|
|
21040
|
+
case "BooleanLiteral":
|
|
21041
|
+
case "NullLiteral":
|
|
21042
|
+
case "BigIntLiteral": return true;
|
|
21043
|
+
case "Identifier": return node.name === "undefined";
|
|
21044
|
+
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
21045
|
+
case "ArrayExpression": return node.elements.every((element) => element === null || element.type !== "SpreadElement" && isDirectConstantAst(element));
|
|
21046
|
+
case "ObjectExpression": return node.properties.every((prop) => prop.type === "ObjectProperty" && !prop.computed && isDirectConstantAst(prop.value));
|
|
21047
|
+
}
|
|
21048
|
+
return false;
|
|
21049
|
+
}
|
|
21050
|
+
function isDirectTemplateConstantAst(node) {
|
|
21051
|
+
switch (node.type) {
|
|
21052
|
+
case "StringLiteral":
|
|
21053
|
+
case "NumericLiteral":
|
|
21054
|
+
case "BooleanLiteral":
|
|
21055
|
+
case "NullLiteral":
|
|
21056
|
+
case "BigIntLiteral": return true;
|
|
21057
|
+
case "Identifier": return node.name === "undefined";
|
|
21058
|
+
case "TemplateLiteral": return node.expressions.every((expression) => isDirectTemplateConstantAst(expression));
|
|
21059
|
+
}
|
|
21060
|
+
return false;
|
|
21061
|
+
}
|
|
20827
21062
|
function genRawSlots(slots, context) {
|
|
20828
21063
|
if (!slots.length) return;
|
|
20829
21064
|
const staticSlots = slots[0];
|
|
20830
|
-
if (staticSlots.slotType === 0)
|
|
20831
|
-
|
|
21065
|
+
if (staticSlots.slotType === 0) {
|
|
21066
|
+
const defaultSlot = getSingleDefaultSlot(staticSlots);
|
|
21067
|
+
if (defaultSlot && slots.length === 1) return genSlotBlockWithProps(defaultSlot, context);
|
|
21068
|
+
return genStaticSlots(staticSlots, context, slots.length > 1 ? slots.slice(1) : void 0);
|
|
21069
|
+
} else return genStaticSlots({
|
|
20832
21070
|
slotType: 0,
|
|
20833
21071
|
slots: {}
|
|
20834
21072
|
}, context, slots);
|
|
20835
21073
|
}
|
|
21074
|
+
function getSingleDefaultSlot({ slots }) {
|
|
21075
|
+
const names = Object.keys(slots);
|
|
21076
|
+
return names.length === 1 && names[0] === "default" ? slots.default : void 0;
|
|
21077
|
+
}
|
|
20836
21078
|
function genStaticSlots({ slots }, context, dynamicSlots) {
|
|
20837
21079
|
const args = Object.keys(slots).map((name) => [`${JSON.stringify(name)}: `, ...genSlotBlockWithProps(slots[name], context)]);
|
|
20838
21080
|
if (dynamicSlots) args.push([`$: `, ...genDynamicSlots(dynamicSlots, context)]);
|
|
@@ -20924,7 +21166,9 @@ function genSlotBlockWithProps(oper, context) {
|
|
|
20924
21166
|
} else propsName = props.content;
|
|
20925
21167
|
const idMap = idToPathMap.size ? buildDestructureIdMap(idToPathMap, propsName || "", context.options.expressionPlugins) : {};
|
|
20926
21168
|
if (propsName) idMap[propsName] = null;
|
|
21169
|
+
const exitSlotBlock = context.enterSlotBlock();
|
|
20927
21170
|
let blockFn = context.withId(() => genBlock(oper, context, propsName ? [propsName] : []), idMap);
|
|
21171
|
+
exitSlotBlock();
|
|
20928
21172
|
exitScope && exitScope();
|
|
20929
21173
|
if (node.type === 1) {
|
|
20930
21174
|
if (needsVaporCtx(oper)) blockFn = [
|
|
@@ -20985,16 +21229,18 @@ function hasComponentOrSlotInIf(node) {
|
|
|
20985
21229
|
//#region packages/compiler-vapor/src/generators/slotOutlet.ts
|
|
20986
21230
|
function genSlotOutlet(oper, context) {
|
|
20987
21231
|
const { helper } = context;
|
|
20988
|
-
const { id, name, fallback,
|
|
21232
|
+
const { id, name, fallback, flags } = oper;
|
|
20989
21233
|
const [frag, push] = buildCodeFragment();
|
|
20990
|
-
|
|
21234
|
+
let fallbackArg;
|
|
21235
|
+
if (fallback) fallbackArg = genBlock(fallback, context);
|
|
21236
|
+
const createSlot = helper("createSlot");
|
|
21237
|
+
const rawPropsArg = genRawProps(oper.props, context, true);
|
|
21238
|
+
const nameArg = name.isStatic && name.content === "default" && !rawPropsArg && !fallbackArg && !flags ? void 0 : name.isStatic ? genExpression(name, context) : [
|
|
20991
21239
|
"() => (",
|
|
20992
21240
|
...genExpression(name, context),
|
|
20993
21241
|
")"
|
|
20994
21242
|
];
|
|
20995
|
-
|
|
20996
|
-
if (fallback) fallbackArg = genBlock(fallback, context);
|
|
20997
|
-
push(NEWLINE, `const n${id} = `, ...genCall(helper("createSlot"), nameExpr, genRawProps(oper.props, context) || "null", fallbackArg, noSlotted && "true", once && "true"));
|
|
21243
|
+
push(NEWLINE, `const n${id} = `, ...genCall(createSlot, nameArg, rawPropsArg, fallbackArg, flags ? String(flags) : void 0));
|
|
20998
21244
|
return frag;
|
|
20999
21245
|
}
|
|
21000
21246
|
//#endregion
|
|
@@ -21054,28 +21300,35 @@ function genEffects(effects, context, genExtraFrag) {
|
|
|
21054
21300
|
const [frag, push, unshift] = buildCodeFragment();
|
|
21055
21301
|
const shouldDeclare = genExtraFrag === void 0;
|
|
21056
21302
|
let operationsCount = 0;
|
|
21057
|
-
const { ids, frag: declarationFrags, varNames } = processExpressions(context, expressions, shouldDeclare);
|
|
21058
|
-
|
|
21059
|
-
|
|
21060
|
-
const
|
|
21061
|
-
|
|
21062
|
-
|
|
21063
|
-
|
|
21064
|
-
|
|
21065
|
-
|
|
21066
|
-
|
|
21067
|
-
|
|
21068
|
-
|
|
21069
|
-
|
|
21070
|
-
|
|
21071
|
-
|
|
21072
|
-
|
|
21073
|
-
|
|
21074
|
-
|
|
21075
|
-
|
|
21076
|
-
|
|
21077
|
-
|
|
21078
|
-
|
|
21303
|
+
const { ids, frag: declarationFrags, varNames, expressionReplacements } = processExpressions(context, expressions, shouldDeclare);
|
|
21304
|
+
if (shouldDeclare && !declarationFrags.length && !varNames.length) {
|
|
21305
|
+
const effect = effects.length === 1 ? effects[0] : void 0;
|
|
21306
|
+
const operation = effect && effect.operations.length === 1 ? effect.operations[0] : void 0;
|
|
21307
|
+
if (operation && operation.type === 9 && operation.effect && !operation.refFor) return context.withExpressionReplacements(expressionReplacements, () => context.withId(() => genSetTemplateRefBinding(operation, context), ids));
|
|
21308
|
+
}
|
|
21309
|
+
return context.withExpressionReplacements(expressionReplacements, () => {
|
|
21310
|
+
push(...declarationFrags);
|
|
21311
|
+
for (let i = 0; i < effects.length; i++) {
|
|
21312
|
+
const effect = effects[i];
|
|
21313
|
+
operationsCount += effect.operations.length;
|
|
21314
|
+
const frags = context.withId(() => genEffect(effect, context), ids);
|
|
21315
|
+
i > 0 && push(NEWLINE);
|
|
21316
|
+
if (frag[frag.length - 1] === ")" && frags[0] === "(") push(";");
|
|
21317
|
+
push(...frags);
|
|
21318
|
+
}
|
|
21319
|
+
if (frag.filter((frag) => frag === NEWLINE).length > 1 || operationsCount > 1 || declarationFrags.length > 0) {
|
|
21320
|
+
unshift(`{`, INDENT_START, NEWLINE);
|
|
21321
|
+
push(INDENT_END, NEWLINE, "}");
|
|
21322
|
+
if (!effects.length) unshift(NEWLINE);
|
|
21323
|
+
}
|
|
21324
|
+
if (effects.length) {
|
|
21325
|
+
unshift(NEWLINE, `${helper("renderEffect")}(() => `);
|
|
21326
|
+
push(`)`);
|
|
21327
|
+
}
|
|
21328
|
+
if (!shouldDeclare && varNames.length) unshift(NEWLINE, `let `, varNames.join(", "));
|
|
21329
|
+
if (genExtraFrag) push(...context.withId(genExtraFrag, ids));
|
|
21330
|
+
return frag;
|
|
21331
|
+
});
|
|
21079
21332
|
}
|
|
21080
21333
|
function genEffect({ operations }, context) {
|
|
21081
21334
|
const [frag, push] = buildCodeFragment();
|
|
@@ -21094,9 +21347,8 @@ function genTemplates(templates, context) {
|
|
|
21094
21347
|
const result = [];
|
|
21095
21348
|
templates.forEach(({ content, ns, root, static: isStatic }, i) => {
|
|
21096
21349
|
let args = JSON.stringify(content).replace(IMPORT_EXPR_RE, `" + $1 + "`);
|
|
21097
|
-
|
|
21098
|
-
|
|
21099
|
-
if (isStatic || ns) args += `, ${isStatic ? "true" : "false"}`;
|
|
21350
|
+
const flags = (root ? 1 : 0) | (isStatic ? 2 : 0);
|
|
21351
|
+
if (flags || ns) args += `, ${flags}`;
|
|
21100
21352
|
if (ns) args += `, ${ns}`;
|
|
21101
21353
|
result.push(`const ${context.tName(i)} = ${context.helper("template")}(${args})\n`);
|
|
21102
21354
|
});
|
|
@@ -21114,10 +21366,13 @@ function genSelf(dynamic, context, flushBeforeDynamic) {
|
|
|
21114
21366
|
return frag;
|
|
21115
21367
|
}
|
|
21116
21368
|
function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flushBeforeDynamic) {
|
|
21117
|
-
const { helper } = context;
|
|
21118
21369
|
const [frag, push] = buildCodeFragment();
|
|
21119
21370
|
const { children } = dynamic;
|
|
21120
21371
|
let offset = 0;
|
|
21372
|
+
/**
|
|
21373
|
+
* `reusable` means the previous access target is a p* cursor that can be
|
|
21374
|
+
* reassigned by the next lookup. Referenced n* variables must stay stable.
|
|
21375
|
+
*/
|
|
21121
21376
|
let prev;
|
|
21122
21377
|
for (const [index, child] of children.entries()) {
|
|
21123
21378
|
if (child.flags & 2) offset--;
|
|
@@ -21134,27 +21389,118 @@ function genChildren(dynamic, context, pushBlock, from = `n${dynamic.id}`, flush
|
|
|
21134
21389
|
}
|
|
21135
21390
|
const elementIndex = index + offset;
|
|
21136
21391
|
const logicalIndex = child.logicalIndex !== void 0 ? String(child.logicalIndex) : void 0;
|
|
21137
|
-
const
|
|
21138
|
-
|
|
21139
|
-
if (
|
|
21140
|
-
|
|
21141
|
-
|
|
21142
|
-
|
|
21143
|
-
|
|
21144
|
-
|
|
21145
|
-
|
|
21146
|
-
|
|
21392
|
+
const inlinePlaceholder = id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6);
|
|
21393
|
+
const accessPath = genAccessPath(context, from, child, elementIndex, logicalIndex, prev);
|
|
21394
|
+
if (inlinePlaceholder) {
|
|
21395
|
+
if (prev && prev[2]) {
|
|
21396
|
+
push(...genChildren(child, context, pushBlock, [
|
|
21397
|
+
"(",
|
|
21398
|
+
prev[0],
|
|
21399
|
+
" = ",
|
|
21400
|
+
...accessPath,
|
|
21401
|
+
")"
|
|
21402
|
+
], flushBeforeDynamic));
|
|
21403
|
+
prev = [
|
|
21404
|
+
prev[0],
|
|
21405
|
+
elementIndex,
|
|
21406
|
+
true
|
|
21407
|
+
];
|
|
21408
|
+
continue;
|
|
21409
|
+
}
|
|
21410
|
+
if (!hasAdjacentFollowingAccessChild(children, index, elementIndex, offset)) {
|
|
21411
|
+
push(...genChildren(child, context, pushBlock, accessPath, flushBeforeDynamic));
|
|
21412
|
+
continue;
|
|
21413
|
+
}
|
|
21414
|
+
}
|
|
21415
|
+
let variable;
|
|
21416
|
+
if (id === void 0 && prev && prev[2]) {
|
|
21417
|
+
variable = prev[0];
|
|
21418
|
+
pushBlock(NEWLINE, `${variable} = `, ...accessPath);
|
|
21419
|
+
} else {
|
|
21420
|
+
variable = id === void 0 ? context.pName(context.block.tempId++) : `n${id}`;
|
|
21421
|
+
pushBlock(NEWLINE, id === void 0 ? `let ${variable} = ` : `const ${variable} = `, ...accessPath);
|
|
21147
21422
|
}
|
|
21148
21423
|
if (id === child.anchor && !child.hasDynamicChild) {
|
|
21149
21424
|
flushBeforeDynamic && flushBeforeDynamic(child, push);
|
|
21150
21425
|
push(...genSelf(child, context, flushBeforeDynamic));
|
|
21151
21426
|
}
|
|
21152
21427
|
if (id !== void 0) push(...genDirectivesForElement(id, context));
|
|
21153
|
-
prev = [
|
|
21428
|
+
prev = [
|
|
21429
|
+
variable,
|
|
21430
|
+
elementIndex,
|
|
21431
|
+
id === void 0
|
|
21432
|
+
];
|
|
21154
21433
|
push(...genChildren(child, context, pushBlock, variable, flushBeforeDynamic));
|
|
21155
21434
|
}
|
|
21156
21435
|
return frag;
|
|
21157
21436
|
}
|
|
21437
|
+
/**
|
|
21438
|
+
* Build one DOM lookup path while preserving the fast sibling walk:
|
|
21439
|
+
* adjacent nodes use _next(prev), otherwise fall back to _nthChild(parent).
|
|
21440
|
+
*/
|
|
21441
|
+
function genAccessPath({ helper }, from, child, elementIndex, logicalIndex, prev) {
|
|
21442
|
+
if (prev) return elementIndex - prev[1] === 1 ? genCall(helper("next"), prev[0], logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
21443
|
+
if (elementIndex === 0) return genCall(helper("child"), from, child.logicalIndex !== 0 ? logicalIndex : void 0);
|
|
21444
|
+
const firstChild = genCall(helper("child"), from);
|
|
21445
|
+
return elementIndex === 1 ? genCall(helper("next"), firstChild, logicalIndex) : genNthChild(helper("nthChild"), from, elementIndex, logicalIndex);
|
|
21446
|
+
}
|
|
21447
|
+
/**
|
|
21448
|
+
* Only inline a placeholder when materializing it would not save a parent
|
|
21449
|
+
* lookup. If its child tree needs the parent more than once, keep p* so the
|
|
21450
|
+
* generated code does not duplicate _child/_nthChild work.
|
|
21451
|
+
*/
|
|
21452
|
+
function canInlinePlaceholder(dynamic) {
|
|
21453
|
+
return dynamic.hasDynamicChild === true && countParentAccessUsages(dynamic) === 1;
|
|
21454
|
+
}
|
|
21455
|
+
/**
|
|
21456
|
+
* A following access can reuse the current placeholder cursor only when it is
|
|
21457
|
+
* the next DOM sibling. Gapped siblings need _nthChild(parent, index) instead.
|
|
21458
|
+
*/
|
|
21459
|
+
function hasAdjacentFollowingAccessChild(children, index, elementIndex, offset) {
|
|
21460
|
+
let futureOffset = offset;
|
|
21461
|
+
for (let i = index + 1; i < children.length; i++) {
|
|
21462
|
+
const child = children[i];
|
|
21463
|
+
if (child.flags & 2) futureOffset--;
|
|
21464
|
+
if (!(child.flags & 4 && child.template != null) && (!!(child.flags & 1) || child.hasDynamicChild)) return i + futureOffset - elementIndex === 1;
|
|
21465
|
+
}
|
|
21466
|
+
return false;
|
|
21467
|
+
}
|
|
21468
|
+
/**
|
|
21469
|
+
* Mirrors genChildren's traversal closely enough to count how many emitted
|
|
21470
|
+
* access paths would start from this placeholder's parent. This is the guard
|
|
21471
|
+
* that keeps inline placeholders from duplicating parent lookups.
|
|
21472
|
+
*/
|
|
21473
|
+
function countParentAccessUsages(dynamic) {
|
|
21474
|
+
let usages = 0;
|
|
21475
|
+
let offset = 0;
|
|
21476
|
+
let prev;
|
|
21477
|
+
for (const [index, child] of dynamic.children.entries()) {
|
|
21478
|
+
if (child.flags & 2) offset--;
|
|
21479
|
+
if (child.flags & 4 && child.template != null) continue;
|
|
21480
|
+
const id = child.flags & 1 ? child.flags & 4 ? child.anchor : child.id : void 0;
|
|
21481
|
+
if (id === void 0 && !child.hasDynamicChild) continue;
|
|
21482
|
+
const elementIndex = index + offset;
|
|
21483
|
+
const usesParent = !prev || elementIndex - prev[0] !== 1;
|
|
21484
|
+
if (id === void 0 && canInlinePlaceholder(child) && child.template == null && child.operation === void 0 && !(child.flags & 6)) {
|
|
21485
|
+
if (prev && prev[1]) {
|
|
21486
|
+
if (usesParent) usages++;
|
|
21487
|
+
prev = [elementIndex, true];
|
|
21488
|
+
continue;
|
|
21489
|
+
}
|
|
21490
|
+
if (!hasAdjacentFollowingAccessChild(dynamic.children, index, elementIndex, offset)) {
|
|
21491
|
+
if (usesParent) usages++;
|
|
21492
|
+
continue;
|
|
21493
|
+
}
|
|
21494
|
+
}
|
|
21495
|
+
if (usesParent) usages++;
|
|
21496
|
+
prev = [elementIndex, id === void 0];
|
|
21497
|
+
}
|
|
21498
|
+
return usages;
|
|
21499
|
+
}
|
|
21500
|
+
function genNthChild(nthChild, from, elementIndex, logicalIndex) {
|
|
21501
|
+
const index = String(elementIndex);
|
|
21502
|
+
return genCall(nthChild, from, index, logicalIndex === index ? void 0 : logicalIndex);
|
|
21503
|
+
}
|
|
21158
21504
|
//#endregion
|
|
21159
21505
|
//#region packages/compiler-vapor/src/generators/block.ts
|
|
21160
21506
|
function genBlock(oper, context, args = [], root) {
|
|
@@ -21173,8 +21519,12 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
21173
21519
|
const [frag, push] = buildCodeFragment();
|
|
21174
21520
|
const { dynamic, effect, operation, returns } = block;
|
|
21175
21521
|
const resetBlock = context.enterBlock(block);
|
|
21522
|
+
const singleUseAssetComponentNames = root ? collectSingleUseAssetComponents(block) : void 0;
|
|
21523
|
+
const prevSingleUseAssetComponentNames = context.singleUseAssetComponentNames;
|
|
21524
|
+
if (singleUseAssetComponentNames) context.singleUseAssetComponentNames = singleUseAssetComponentNames;
|
|
21176
21525
|
if (root) {
|
|
21177
21526
|
for (let name of context.ir.component) {
|
|
21527
|
+
if (singleUseAssetComponentNames && singleUseAssetComponentNames.has(name)) continue;
|
|
21178
21528
|
const id = toValidAssetId(name, "component");
|
|
21179
21529
|
const maybeSelfReference = name.endsWith("__self");
|
|
21180
21530
|
if (maybeSelfReference) name = name.slice(0, -6);
|
|
@@ -21210,15 +21560,101 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
21210
21560
|
const returnNodes = returns.map((n) => `n${n}`);
|
|
21211
21561
|
push(...returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"]);
|
|
21212
21562
|
resetBlock();
|
|
21563
|
+
context.singleUseAssetComponentNames = prevSingleUseAssetComponentNames;
|
|
21213
21564
|
return frag;
|
|
21214
21565
|
function genResolveAssets(kind, helper) {
|
|
21215
21566
|
for (const name of context.ir[kind]) push(NEWLINE, `const ${toValidAssetId(name, kind)} = `, ...genCall(context.helper(helper), JSON.stringify(name)));
|
|
21216
21567
|
}
|
|
21217
21568
|
}
|
|
21569
|
+
function collectSingleUseAssetComponents(block) {
|
|
21570
|
+
const usageMap = /* @__PURE__ */ new Map();
|
|
21571
|
+
const seenOperations = /* @__PURE__ */ new Set();
|
|
21572
|
+
visitBlock(block, true);
|
|
21573
|
+
const names = /* @__PURE__ */ new Set();
|
|
21574
|
+
for (const [name, usage] of usageMap) if (usage.count === 1 && usage.root) names.add(name);
|
|
21575
|
+
return names;
|
|
21576
|
+
function visitBlock(block, rootCandidate) {
|
|
21577
|
+
visitDynamic(block.dynamic, rootCandidate);
|
|
21578
|
+
for (const operation of block.operation) visitOperation(operation, rootCandidate);
|
|
21579
|
+
for (const effect of block.effect) for (const operation of effect.operations) visitOperation(operation, false);
|
|
21580
|
+
}
|
|
21581
|
+
function visitDynamic(dynamic, rootCandidate) {
|
|
21582
|
+
if (dynamic.operation) visitOperation(dynamic.operation, rootCandidate);
|
|
21583
|
+
for (const child of dynamic.children) visitDynamic(child, rootCandidate);
|
|
21584
|
+
}
|
|
21585
|
+
function visitOperation(operation, rootCandidate) {
|
|
21586
|
+
if (seenOperations.has(operation)) return;
|
|
21587
|
+
seenOperations.add(operation);
|
|
21588
|
+
if (operation.type === 12) {
|
|
21589
|
+
if (operation.asset) {
|
|
21590
|
+
const usage = usageMap.get(operation.tag) || {
|
|
21591
|
+
count: 0,
|
|
21592
|
+
root: false
|
|
21593
|
+
};
|
|
21594
|
+
usage.count++;
|
|
21595
|
+
if (rootCandidate) usage.root = true;
|
|
21596
|
+
usageMap.set(operation.tag, usage);
|
|
21597
|
+
}
|
|
21598
|
+
visitSlots(operation.slots);
|
|
21599
|
+
return;
|
|
21600
|
+
}
|
|
21601
|
+
switch (operation.type) {
|
|
21602
|
+
case 15:
|
|
21603
|
+
visitBlock(operation.positive, false);
|
|
21604
|
+
if (operation.negative) if (operation.negative.type === 15) visitOperation(operation.negative, false);
|
|
21605
|
+
else visitBlock(operation.negative, false);
|
|
21606
|
+
break;
|
|
21607
|
+
case 16:
|
|
21608
|
+
visitBlock(operation.render, false);
|
|
21609
|
+
break;
|
|
21610
|
+
case 17:
|
|
21611
|
+
visitBlock(operation.block, false);
|
|
21612
|
+
break;
|
|
21613
|
+
case 13:
|
|
21614
|
+
if (operation.fallback) visitBlock(operation.fallback, false);
|
|
21615
|
+
break;
|
|
21616
|
+
}
|
|
21617
|
+
}
|
|
21618
|
+
function visitSlots(slots) {
|
|
21619
|
+
for (const slot of slots) switch (slot.slotType) {
|
|
21620
|
+
case 0:
|
|
21621
|
+
for (const name in slot.slots) visitBlock(slot.slots[name], false);
|
|
21622
|
+
break;
|
|
21623
|
+
case 1:
|
|
21624
|
+
case 2:
|
|
21625
|
+
visitBlock(slot.fn, false);
|
|
21626
|
+
break;
|
|
21627
|
+
case 3:
|
|
21628
|
+
visitSlots([slot.positive]);
|
|
21629
|
+
if (slot.negative) visitSlots([slot.negative]);
|
|
21630
|
+
break;
|
|
21631
|
+
}
|
|
21632
|
+
}
|
|
21633
|
+
}
|
|
21218
21634
|
//#endregion
|
|
21219
21635
|
//#region packages/compiler-vapor/src/generate.ts
|
|
21220
21636
|
const idWithTrailingDigitsRE = /^([A-Za-z_$][\w$]*)(\d+)$/;
|
|
21637
|
+
const helperNameAliases = {
|
|
21638
|
+
withVaporKeys: "withKeys",
|
|
21639
|
+
withVaporModifiers: "withModifiers"
|
|
21640
|
+
};
|
|
21221
21641
|
var CodegenContext = class {
|
|
21642
|
+
withExpressionReplacements(map, fn) {
|
|
21643
|
+
if (map.size === 0) return fn();
|
|
21644
|
+
this.expressionReplacements.unshift(map);
|
|
21645
|
+
try {
|
|
21646
|
+
return fn();
|
|
21647
|
+
} finally {
|
|
21648
|
+
remove(this.expressionReplacements, map);
|
|
21649
|
+
}
|
|
21650
|
+
}
|
|
21651
|
+
getExpressionReplacement(node) {
|
|
21652
|
+
for (const map of this.expressionReplacements) {
|
|
21653
|
+
const replacement = map.get(node);
|
|
21654
|
+
if (replacement) return replacement;
|
|
21655
|
+
}
|
|
21656
|
+
return node;
|
|
21657
|
+
}
|
|
21222
21658
|
withId(fn, map) {
|
|
21223
21659
|
const { identifiers } = this;
|
|
21224
21660
|
const ids = Object.keys(map);
|
|
@@ -21235,9 +21671,19 @@ var CodegenContext = class {
|
|
|
21235
21671
|
this.block = block;
|
|
21236
21672
|
return () => this.block = parent;
|
|
21237
21673
|
}
|
|
21674
|
+
enterSlotBlock() {
|
|
21675
|
+
const parent = this.inSlotBlock;
|
|
21676
|
+
this.inSlotBlock = true;
|
|
21677
|
+
return () => this.inSlotBlock = parent;
|
|
21678
|
+
}
|
|
21238
21679
|
enterScope() {
|
|
21239
21680
|
return [this.scopeLevel++, () => this.scopeLevel--];
|
|
21240
21681
|
}
|
|
21682
|
+
isHelperNameAvailable(name) {
|
|
21683
|
+
if (this.bindingNames.has(name)) return false;
|
|
21684
|
+
for (const alias of this.helpers.values()) if (alias === name) return false;
|
|
21685
|
+
return true;
|
|
21686
|
+
}
|
|
21241
21687
|
initNextIdMap() {
|
|
21242
21688
|
if (this.bindingNames.size === 0) return;
|
|
21243
21689
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -21272,19 +21718,29 @@ var CodegenContext = class {
|
|
|
21272
21718
|
this.ir = ir;
|
|
21273
21719
|
this.bindingNames = /* @__PURE__ */ new Set();
|
|
21274
21720
|
this.helpers = /* @__PURE__ */ new Map();
|
|
21721
|
+
this.needsTemplateRefSetter = false;
|
|
21722
|
+
this.inSlotBlock = false;
|
|
21275
21723
|
this.helper = (name) => {
|
|
21276
21724
|
if (this.helpers.has(name)) return this.helpers.get(name);
|
|
21277
|
-
const base = `_${name}`;
|
|
21278
|
-
if (this.
|
|
21725
|
+
const base = `_${helperNameAliases[name] || name}`;
|
|
21726
|
+
if (this.isHelperNameAvailable(base)) {
|
|
21279
21727
|
this.helpers.set(name, base);
|
|
21280
21728
|
return base;
|
|
21281
21729
|
}
|
|
21282
|
-
const
|
|
21283
|
-
|
|
21284
|
-
|
|
21730
|
+
const map = this.nextIdMap.get(base);
|
|
21731
|
+
let next = 1;
|
|
21732
|
+
while (true) {
|
|
21733
|
+
const alias = `${base}${getNextId(map, next)}`;
|
|
21734
|
+
if (this.isHelperNameAvailable(alias)) {
|
|
21735
|
+
this.helpers.set(name, alias);
|
|
21736
|
+
return alias;
|
|
21737
|
+
}
|
|
21738
|
+
next++;
|
|
21739
|
+
}
|
|
21285
21740
|
};
|
|
21286
21741
|
this.delegates = /* @__PURE__ */ new Set();
|
|
21287
21742
|
this.identifiers = Object.create(null);
|
|
21743
|
+
this.expressionReplacements = [];
|
|
21288
21744
|
this.seenInlineHandlerNames = Object.create(null);
|
|
21289
21745
|
this.scopeLevel = 0;
|
|
21290
21746
|
this.templateVars = /* @__PURE__ */ new Map();
|
|
@@ -21311,6 +21767,7 @@ var CodegenContext = class {
|
|
|
21311
21767
|
this.block = ir.block;
|
|
21312
21768
|
this.bindingNames = new Set(this.options.bindingMetadata ? Object.keys(this.options.bindingMetadata) : []);
|
|
21313
21769
|
this.initNextIdMap();
|
|
21770
|
+
this.staticTemplateRefHelperCandidate = getStaticTemplateRefHelperCandidate(ir.block);
|
|
21314
21771
|
}
|
|
21315
21772
|
};
|
|
21316
21773
|
function generate(ir, options = {}) {
|
|
@@ -21323,8 +21780,11 @@ function generate(ir, options = {}) {
|
|
|
21323
21780
|
const signature = (options.isTS ? args.map((arg) => `${arg}: any`) : args).join(", ");
|
|
21324
21781
|
if (!inline) push(NEWLINE, `export function ${functionName}(${signature}) {`);
|
|
21325
21782
|
push(INDENT_START);
|
|
21326
|
-
|
|
21327
|
-
|
|
21783
|
+
const templateRefSetterHelper = ir.hasTemplateRef ? context.helper("createTemplateRefSetter") : void 0;
|
|
21784
|
+
const body = genBlockContent(ir.block, context, true);
|
|
21785
|
+
if (context.needsTemplateRefSetter) push(NEWLINE, `const ${setTemplateRefIdent} = ${templateRefSetterHelper}()`);
|
|
21786
|
+
else if (templateRefSetterHelper) context.helpers.delete("createTemplateRefSetter");
|
|
21787
|
+
push(...body);
|
|
21328
21788
|
push(INDENT_END, NEWLINE);
|
|
21329
21789
|
if (!inline) push("}");
|
|
21330
21790
|
const delegates = genDelegates(context);
|
|
@@ -21359,6 +21819,11 @@ function genAssetImports({ ir }) {
|
|
|
21359
21819
|
}
|
|
21360
21820
|
return imports;
|
|
21361
21821
|
}
|
|
21822
|
+
function getStaticTemplateRefHelperCandidate(block) {
|
|
21823
|
+
if (block.operation.length !== 1) return;
|
|
21824
|
+
const operation = block.operation[0];
|
|
21825
|
+
if (operation.type === 9 && !operation.effect && !operation.refFor && operation.value.isStatic) return operation;
|
|
21826
|
+
}
|
|
21362
21827
|
//#endregion
|
|
21363
21828
|
//#region packages/compiler-vapor/src/transforms/vBind.ts
|
|
21364
21829
|
function normalizeBindShorthand(arg, context) {
|
|
@@ -21396,67 +21861,6 @@ const transformVBind = (dir, node, context) => {
|
|
|
21396
21861
|
};
|
|
21397
21862
|
};
|
|
21398
21863
|
//#endregion
|
|
21399
|
-
//#region \0@oxc-project+runtime@0.129.0/helpers/typeof.js
|
|
21400
|
-
function _typeof(o) {
|
|
21401
|
-
"@babel/helpers - typeof";
|
|
21402
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
21403
|
-
return typeof o;
|
|
21404
|
-
} : function(o) {
|
|
21405
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
21406
|
-
}, _typeof(o);
|
|
21407
|
-
}
|
|
21408
|
-
//#endregion
|
|
21409
|
-
//#region \0@oxc-project+runtime@0.129.0/helpers/toPrimitive.js
|
|
21410
|
-
function toPrimitive(t, r) {
|
|
21411
|
-
if ("object" != _typeof(t) || !t) return t;
|
|
21412
|
-
var e = t[Symbol.toPrimitive];
|
|
21413
|
-
if (void 0 !== e) {
|
|
21414
|
-
var i = e.call(t, r || "default");
|
|
21415
|
-
if ("object" != _typeof(i)) return i;
|
|
21416
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
21417
|
-
}
|
|
21418
|
-
return ("string" === r ? String : Number)(t);
|
|
21419
|
-
}
|
|
21420
|
-
//#endregion
|
|
21421
|
-
//#region \0@oxc-project+runtime@0.129.0/helpers/toPropertyKey.js
|
|
21422
|
-
function toPropertyKey(t) {
|
|
21423
|
-
var i = toPrimitive(t, "string");
|
|
21424
|
-
return "symbol" == _typeof(i) ? i : i + "";
|
|
21425
|
-
}
|
|
21426
|
-
//#endregion
|
|
21427
|
-
//#region \0@oxc-project+runtime@0.129.0/helpers/defineProperty.js
|
|
21428
|
-
function _defineProperty(e, r, t) {
|
|
21429
|
-
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
21430
|
-
value: t,
|
|
21431
|
-
enumerable: !0,
|
|
21432
|
-
configurable: !0,
|
|
21433
|
-
writable: !0
|
|
21434
|
-
}) : e[r] = t, e;
|
|
21435
|
-
}
|
|
21436
|
-
//#endregion
|
|
21437
|
-
//#region \0@oxc-project+runtime@0.129.0/helpers/objectSpread2.js
|
|
21438
|
-
function ownKeys(e, r) {
|
|
21439
|
-
var t = Object.keys(e);
|
|
21440
|
-
if (Object.getOwnPropertySymbols) {
|
|
21441
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
21442
|
-
r && (o = o.filter(function(r) {
|
|
21443
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
21444
|
-
})), t.push.apply(t, o);
|
|
21445
|
-
}
|
|
21446
|
-
return t;
|
|
21447
|
-
}
|
|
21448
|
-
function _objectSpread2(e) {
|
|
21449
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
21450
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
21451
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
21452
|
-
_defineProperty(e, r, t[r]);
|
|
21453
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
21454
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
21455
|
-
});
|
|
21456
|
-
}
|
|
21457
|
-
return e;
|
|
21458
|
-
}
|
|
21459
|
-
//#endregion
|
|
21460
21864
|
//#region packages/compiler-vapor/src/transforms/transformElement.ts
|
|
21461
21865
|
const isReservedProp = /* @__PURE__ */ makeMap(",key,ref,ref_for,ref_key,");
|
|
21462
21866
|
const transformElement = (node, context) => {
|
|
@@ -21585,6 +21989,7 @@ function resolveSetupReference(name, context) {
|
|
|
21585
21989
|
}
|
|
21586
21990
|
const dynamicKeys = ["indeterminate"];
|
|
21587
21991
|
const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
|
|
21992
|
+
const UNSAFE_ATTR_NAME_RE = /[\u0000-\u0020"'<=/>]/;
|
|
21588
21993
|
function transformNativeElement(node, propsResult, staticKey, singleRoot, context, getEffectIndex, omitEndTag) {
|
|
21589
21994
|
const { tag } = node;
|
|
21590
21995
|
const { scopeId } = context.options;
|
|
@@ -21602,18 +22007,55 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
21602
22007
|
}, getEffectIndex);
|
|
21603
22008
|
} else {
|
|
21604
22009
|
let prevWasQuoted = false;
|
|
22010
|
+
const appendTemplateProp = (key, value = "", generated = false) => {
|
|
22011
|
+
if (!prevWasQuoted) template += ` `;
|
|
22012
|
+
template += key;
|
|
22013
|
+
if (value) {
|
|
22014
|
+
const escapedValue = generated ? escapeGeneratedAttrValue(value) : value.replace(/"/g, """);
|
|
22015
|
+
template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${escapedValue}"` : `=${escapedValue}`;
|
|
22016
|
+
} else prevWasQuoted = false;
|
|
22017
|
+
};
|
|
21605
22018
|
for (const prop of propsResult[1]) {
|
|
21606
22019
|
const { key, values } = prop;
|
|
21607
22020
|
if (context.imports.some((imported) => values[0].content.includes(imported.exp.content))) {
|
|
21608
22021
|
if (!prevWasQuoted) template += ` `;
|
|
21609
22022
|
template += `${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
|
|
21610
22023
|
prevWasQuoted = true;
|
|
22024
|
+
} else if (key.isStatic && !prop.modifier && isBooleanAttr(key.content)) if (values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
22025
|
+
const value = values[0].content === "''" ? "" : values[0].content;
|
|
22026
|
+
appendTemplateProp(key.content, value);
|
|
22027
|
+
} else {
|
|
22028
|
+
const include = foldBooleanAttrValue(values);
|
|
22029
|
+
if (include != null) {
|
|
22030
|
+
if (include) appendTemplateProp(key.content);
|
|
22031
|
+
} else {
|
|
22032
|
+
dynamicProps.push(key.content);
|
|
22033
|
+
context.registerEffect(values, {
|
|
22034
|
+
type: 3,
|
|
22035
|
+
element: context.reference(),
|
|
22036
|
+
prop,
|
|
22037
|
+
tag
|
|
22038
|
+
}, getEffectIndex);
|
|
22039
|
+
}
|
|
22040
|
+
}
|
|
22041
|
+
else if (key.isStatic && !prop.modifier && hasBoundValue(values)) {
|
|
22042
|
+
let foldedValue;
|
|
22043
|
+
if (key.content === "class") foldedValue = foldClassValues(values);
|
|
22044
|
+
else if (key.content === "style") foldedValue = foldStyleValues(values);
|
|
22045
|
+
if (foldedValue != null) {
|
|
22046
|
+
if (foldedValue) appendTemplateProp(key.content, foldedValue, true);
|
|
22047
|
+
} else {
|
|
22048
|
+
dynamicProps.push(key.content);
|
|
22049
|
+
context.registerEffect(values, {
|
|
22050
|
+
type: 3,
|
|
22051
|
+
element: context.reference(),
|
|
22052
|
+
prop,
|
|
22053
|
+
tag
|
|
22054
|
+
}, getEffectIndex);
|
|
22055
|
+
}
|
|
21611
22056
|
} else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
21612
|
-
if (!prevWasQuoted) template += ` `;
|
|
21613
22057
|
const value = values[0].content === "''" ? "" : values[0].content;
|
|
21614
|
-
|
|
21615
|
-
if (value) template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${value.replace(/"/g, """)}"` : `=${value}`;
|
|
21616
|
-
else prevWasQuoted = false;
|
|
22058
|
+
appendTemplateProp(key.content, value);
|
|
21617
22059
|
} else {
|
|
21618
22060
|
dynamicProps.push(key.content);
|
|
21619
22061
|
context.registerEffect(values, {
|
|
@@ -21635,6 +22077,123 @@ function transformNativeElement(node, propsResult, staticKey, singleRoot, contex
|
|
|
21635
22077
|
} else context.template += template;
|
|
21636
22078
|
if (staticKey) context.registerOperation(createSetBlockKey(context.reference(), staticKey));
|
|
21637
22079
|
}
|
|
22080
|
+
function escapeGeneratedAttrValue(value) {
|
|
22081
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
22082
|
+
}
|
|
22083
|
+
function foldBooleanAttrValue(values) {
|
|
22084
|
+
if (values.length !== 1) return;
|
|
22085
|
+
const evaluated = evaluateConstantExpression(values[0]);
|
|
22086
|
+
if (!evaluated) return;
|
|
22087
|
+
const value = evaluated.value;
|
|
22088
|
+
if (value === true || value === false || value == null) return includeBooleanAttr(value);
|
|
22089
|
+
}
|
|
22090
|
+
function foldStyleValues(values) {
|
|
22091
|
+
const evaluatedValues = [];
|
|
22092
|
+
for (const value of values) {
|
|
22093
|
+
const evaluated = evaluateConstantExpression(value);
|
|
22094
|
+
if (!evaluated || !isStaticStyleValue(evaluated.value)) return;
|
|
22095
|
+
evaluatedValues.push(evaluated.value);
|
|
22096
|
+
}
|
|
22097
|
+
return stringifyStyle(normalizeStyle(evaluatedValues.length === 1 ? evaluatedValues[0] : evaluatedValues));
|
|
22098
|
+
}
|
|
22099
|
+
function isStaticStyleValue(value) {
|
|
22100
|
+
if (typeof value === "string") return true;
|
|
22101
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
22102
|
+
for (const key in value) {
|
|
22103
|
+
const propValue = value[key];
|
|
22104
|
+
if (!isSafeStylePropertyName(key) || !isSafeStylePropertyValue(propValue)) return false;
|
|
22105
|
+
}
|
|
22106
|
+
return true;
|
|
22107
|
+
}
|
|
22108
|
+
function isSafeStylePropertyName(key) {
|
|
22109
|
+
return !!key && !/[;:]/.test(key);
|
|
22110
|
+
}
|
|
22111
|
+
function isSafeStylePropertyValue(value) {
|
|
22112
|
+
return typeof value === "number" || typeof value === "string" && !value.includes(";");
|
|
22113
|
+
}
|
|
22114
|
+
function hasBoundValue(values) {
|
|
22115
|
+
return values.some((value) => !value.isStatic && value.content !== "''");
|
|
22116
|
+
}
|
|
22117
|
+
function foldClassValues(values) {
|
|
22118
|
+
let templateValue = "";
|
|
22119
|
+
let changed = false;
|
|
22120
|
+
for (const value of values) {
|
|
22121
|
+
const evaluated = evaluateConstantExpression(value);
|
|
22122
|
+
if (evaluated) {
|
|
22123
|
+
const normalized = normalizeClass(evaluated.value);
|
|
22124
|
+
if (normalized) templateValue = appendClass(templateValue, normalized);
|
|
22125
|
+
else changed = true;
|
|
22126
|
+
continue;
|
|
22127
|
+
}
|
|
22128
|
+
return;
|
|
22129
|
+
}
|
|
22130
|
+
return changed || templateValue ? templateValue : void 0;
|
|
22131
|
+
}
|
|
22132
|
+
function appendClass(base, value) {
|
|
22133
|
+
return base ? value ? `${base} ${value}` : base : value;
|
|
22134
|
+
}
|
|
22135
|
+
function getObjectPropertyName(prop) {
|
|
22136
|
+
const key = prop.key;
|
|
22137
|
+
if (key.type === "Identifier") return key.name;
|
|
22138
|
+
else if (key.type === "StringLiteral") return key.value;
|
|
22139
|
+
else if (key.type === "NumericLiteral") return String(key.value);
|
|
22140
|
+
}
|
|
22141
|
+
function evaluateConstantExpression(node) {
|
|
22142
|
+
if (node.isStatic) return { value: node.content };
|
|
22143
|
+
const ast = node.ast;
|
|
22144
|
+
if (ast === null) {
|
|
22145
|
+
if (node.content === "true") return { value: true };
|
|
22146
|
+
else if (node.content === "false") return { value: false };
|
|
22147
|
+
else if (node.content === "null") return { value: null };
|
|
22148
|
+
else if (node.content === "undefined") return { value: void 0 };
|
|
22149
|
+
}
|
|
22150
|
+
if (!ast) return;
|
|
22151
|
+
return evaluateConstantAst(ast);
|
|
22152
|
+
}
|
|
22153
|
+
function evaluateConstantAst(node) {
|
|
22154
|
+
switch (node.type) {
|
|
22155
|
+
case "StringLiteral": return { value: node.value };
|
|
22156
|
+
case "NumericLiteral": return { value: node.value };
|
|
22157
|
+
case "BooleanLiteral": return { value: node.value };
|
|
22158
|
+
case "NullLiteral": return { value: null };
|
|
22159
|
+
case "Identifier": return node.name === "undefined" ? { value: void 0 } : void 0;
|
|
22160
|
+
case "UnaryExpression":
|
|
22161
|
+
if (node.operator === "void") return { value: void 0 };
|
|
22162
|
+
else if (node.operator === "-") {
|
|
22163
|
+
const value = evaluateConstantAst(node.argument);
|
|
22164
|
+
return value && typeof value.value === "number" ? { value: -value.value } : void 0;
|
|
22165
|
+
}
|
|
22166
|
+
return;
|
|
22167
|
+
case "TemplateLiteral": return evaluateTemplateLiteral(node);
|
|
22168
|
+
case "ObjectExpression": return evaluateObjectExpression(node);
|
|
22169
|
+
}
|
|
22170
|
+
}
|
|
22171
|
+
function evaluateTemplateLiteral(node) {
|
|
22172
|
+
if (node.type !== "TemplateLiteral") return;
|
|
22173
|
+
let value = "";
|
|
22174
|
+
for (const [index, quasi] of node.quasis.entries()) {
|
|
22175
|
+
value += quasi.value.cooked || "";
|
|
22176
|
+
const expression = node.expressions[index];
|
|
22177
|
+
if (expression) {
|
|
22178
|
+
const evaluated = evaluateConstantAst(expression);
|
|
22179
|
+
if (!evaluated) return;
|
|
22180
|
+
value += evaluated.value;
|
|
22181
|
+
}
|
|
22182
|
+
}
|
|
22183
|
+
return { value };
|
|
22184
|
+
}
|
|
22185
|
+
function evaluateObjectExpression(node) {
|
|
22186
|
+
const value = {};
|
|
22187
|
+
for (const prop of node.properties) {
|
|
22188
|
+
if (prop.type !== "ObjectProperty" || prop.computed) return;
|
|
22189
|
+
const key = getObjectPropertyName(prop);
|
|
22190
|
+
if (key == null) return;
|
|
22191
|
+
const evaluated = evaluateConstantAst(prop.value);
|
|
22192
|
+
if (!evaluated) return;
|
|
22193
|
+
value[key] = evaluated.value;
|
|
22194
|
+
}
|
|
22195
|
+
return { value };
|
|
22196
|
+
}
|
|
21638
22197
|
function resolveStaticKey(node, context, isComponent) {
|
|
21639
22198
|
const keyProp = findProp(node, "key", false, true);
|
|
21640
22199
|
if (!keyProp) return;
|
|
@@ -21661,27 +22220,42 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
21661
22220
|
results = [];
|
|
21662
22221
|
}
|
|
21663
22222
|
}
|
|
22223
|
+
function pushStaticObjectLiteralProps(props) {
|
|
22224
|
+
if (dynamicArgs.length) {
|
|
22225
|
+
pushMergeArg();
|
|
22226
|
+
dynamicArgs.push(props);
|
|
22227
|
+
} else results.push(...props.map(toDirectiveResult));
|
|
22228
|
+
}
|
|
21664
22229
|
for (const prop of props) {
|
|
21665
22230
|
if (prop.type === 7 && !prop.arg) {
|
|
21666
22231
|
if (prop.name === "bind") {
|
|
21667
22232
|
if (prop.exp) {
|
|
21668
|
-
|
|
21669
|
-
|
|
21670
|
-
|
|
21671
|
-
|
|
21672
|
-
|
|
21673
|
-
|
|
22233
|
+
const objectLiteralProps = isComponent ? resolveComponentObjectLiteralBindProps(prop.exp, context, props, prop) : resolveNativeObjectLiteralBindProps(prop.exp, context, props, prop);
|
|
22234
|
+
if (objectLiteralProps) if (isComponent) pushStaticObjectLiteralProps(objectLiteralProps);
|
|
22235
|
+
else results.push(...objectLiteralProps.map(toDirectiveResult));
|
|
22236
|
+
else {
|
|
22237
|
+
dynamicExpr.push(prop.exp);
|
|
22238
|
+
pushMergeArg();
|
|
22239
|
+
dynamicArgs.push({
|
|
22240
|
+
kind: 0,
|
|
22241
|
+
value: prop.exp
|
|
22242
|
+
});
|
|
22243
|
+
}
|
|
21674
22244
|
} else context.options.onError(createCompilerError(34, prop.loc));
|
|
21675
22245
|
continue;
|
|
21676
22246
|
} else if (prop.name === "on") {
|
|
21677
22247
|
if (prop.exp) if (isComponent) {
|
|
21678
|
-
|
|
21679
|
-
|
|
21680
|
-
|
|
21681
|
-
|
|
21682
|
-
|
|
21683
|
-
|
|
21684
|
-
|
|
22248
|
+
const objectLiteralProps = resolveComponentObjectLiteralOnProps(prop.exp, context, props, prop);
|
|
22249
|
+
if (objectLiteralProps) pushStaticObjectLiteralProps(objectLiteralProps);
|
|
22250
|
+
else {
|
|
22251
|
+
dynamicExpr.push(prop.exp);
|
|
22252
|
+
pushMergeArg();
|
|
22253
|
+
dynamicArgs.push({
|
|
22254
|
+
kind: 0,
|
|
22255
|
+
value: prop.exp,
|
|
22256
|
+
handler: true
|
|
22257
|
+
});
|
|
22258
|
+
}
|
|
21685
22259
|
} else context.registerEffect([prop.exp], {
|
|
21686
22260
|
type: 7,
|
|
21687
22261
|
element: context.reference(),
|
|
@@ -21711,6 +22285,151 @@ function buildProps(node, context, isComponent, isDynamicComponent, getEffectInd
|
|
|
21711
22285
|
}
|
|
21712
22286
|
return [false, dedupeProperties(results)];
|
|
21713
22287
|
}
|
|
22288
|
+
function resolveObjectLiteralProps(exp, context, keyTransform, isValidKey) {
|
|
22289
|
+
const ast = exp.ast;
|
|
22290
|
+
if (!ast || ast.type !== "ObjectExpression") return;
|
|
22291
|
+
const props = [];
|
|
22292
|
+
const knownKeys = /* @__PURE__ */ new Set();
|
|
22293
|
+
for (const property of ast.properties) {
|
|
22294
|
+
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
22295
|
+
let key = getObjectPropertyName(property);
|
|
22296
|
+
if (key == null || key === "__proto__") return;
|
|
22297
|
+
if (isValidKey && !isValidKey(key)) return;
|
|
22298
|
+
if (keyTransform) key = keyTransform(key);
|
|
22299
|
+
if (knownKeys.has(key)) return;
|
|
22300
|
+
knownKeys.add(key);
|
|
22301
|
+
props.push({
|
|
22302
|
+
key: createSimpleExpression(key, true),
|
|
22303
|
+
values: [resolveExpression(createObjectBindSubExpression(exp, property.value, context), true)]
|
|
22304
|
+
});
|
|
22305
|
+
}
|
|
22306
|
+
return props;
|
|
22307
|
+
}
|
|
22308
|
+
function resolveComponentObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
22309
|
+
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeObjectLiteralBindKey);
|
|
22310
|
+
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
22311
|
+
return props;
|
|
22312
|
+
}
|
|
22313
|
+
function resolveNativeObjectLiteralBindProps(exp, context, nodeProps, currentProp) {
|
|
22314
|
+
const props = resolveObjectLiteralProps(exp, context, void 0, isSafeNativeObjectLiteralBindKey);
|
|
22315
|
+
if (!props || hasNativeObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
22316
|
+
return props;
|
|
22317
|
+
}
|
|
22318
|
+
function resolveComponentObjectLiteralOnProps(exp, context, nodeProps, currentProp) {
|
|
22319
|
+
const props = resolveObjectLiteralProps(exp, context, toHandlerKey);
|
|
22320
|
+
if (!props || hasComponentObjectLiteralBindConflict(nodeProps, currentProp, props)) return;
|
|
22321
|
+
return props;
|
|
22322
|
+
}
|
|
22323
|
+
function isSafeNativeObjectLiteralBindKey(key) {
|
|
22324
|
+
return key !== "" && !UNSAFE_ATTR_NAME_RE.test(key) && isSafeObjectLiteralBindKey(key) && !isOn(key) && key.charCodeAt(0) !== 46 && key.charCodeAt(0) !== 94;
|
|
22325
|
+
}
|
|
22326
|
+
function isSafeObjectLiteralBindKey(key) {
|
|
22327
|
+
return !isReservedProp(key);
|
|
22328
|
+
}
|
|
22329
|
+
function hasComponentObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
22330
|
+
const keys = createComponentConflictKeySet(objectLiteralProps.map((prop) => prop.key.content));
|
|
22331
|
+
for (const prop of props) {
|
|
22332
|
+
if (prop === currentProp) continue;
|
|
22333
|
+
let key;
|
|
22334
|
+
if (prop.type === 6) key = prop.name;
|
|
22335
|
+
else if (prop.name === "bind") {
|
|
22336
|
+
if (!prop.arg) {
|
|
22337
|
+
const bindKeys = getObjectLiteralKeys(prop.exp);
|
|
22338
|
+
if (bindKeys && hasComponentKeyOverlap(keys, bindKeys)) return true;
|
|
22339
|
+
continue;
|
|
22340
|
+
}
|
|
22341
|
+
key = getStaticBindKey(prop);
|
|
22342
|
+
} else if (prop.name === "on") key = getStaticHandlerKey(prop);
|
|
22343
|
+
else if (prop.name === "model") {
|
|
22344
|
+
if (hasComponentModelKey(keys, prop)) return true;
|
|
22345
|
+
}
|
|
22346
|
+
if (key && hasComponentKey(keys, key)) return true;
|
|
22347
|
+
}
|
|
22348
|
+
return false;
|
|
22349
|
+
}
|
|
22350
|
+
function hasComponentModelKey(keys, prop) {
|
|
22351
|
+
const { arg } = prop;
|
|
22352
|
+
if (arg && (arg.type !== 4 || !arg.isStatic)) return true;
|
|
22353
|
+
const key = arg ? arg.content : "modelValue";
|
|
22354
|
+
return hasComponentKey(keys, key) || hasComponentKey(keys, `onUpdate:${camelize(key)}`) || prop.modifiers.length > 0 && hasComponentKey(keys, getModifierPropName(key));
|
|
22355
|
+
}
|
|
22356
|
+
function hasNativeObjectLiteralBindConflict(props, currentProp, objectLiteralProps) {
|
|
22357
|
+
const keys = new Set(objectLiteralProps.map((prop) => prop.key.content));
|
|
22358
|
+
for (const prop of props) {
|
|
22359
|
+
if (prop === currentProp) continue;
|
|
22360
|
+
let key;
|
|
22361
|
+
if (prop.type === 6) key = prop.name;
|
|
22362
|
+
else if (prop.name === "bind") {
|
|
22363
|
+
if (!prop.arg) return true;
|
|
22364
|
+
key = getStaticBindKey(prop);
|
|
22365
|
+
if (!key) return true;
|
|
22366
|
+
}
|
|
22367
|
+
if (key && keys.has(key)) return true;
|
|
22368
|
+
}
|
|
22369
|
+
return false;
|
|
22370
|
+
}
|
|
22371
|
+
function getStaticBindKey(prop) {
|
|
22372
|
+
const { arg } = prop;
|
|
22373
|
+
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
22374
|
+
let key = arg.content;
|
|
22375
|
+
if (isReservedProp(key)) return;
|
|
22376
|
+
if (prop.modifiers.some((modifier) => modifier.content === "camel")) key = camelize(key);
|
|
22377
|
+
return key;
|
|
22378
|
+
}
|
|
22379
|
+
function getStaticHandlerKey(prop) {
|
|
22380
|
+
const { arg } = prop;
|
|
22381
|
+
if (!arg || arg.type !== 4 || !arg.isStatic) return;
|
|
22382
|
+
let key = arg.content;
|
|
22383
|
+
if (key.startsWith("vue:")) key = `vnode-${key.slice(4)}`;
|
|
22384
|
+
const { nonKeyModifiers, eventOptionModifiers } = resolveModifiers(`on${key}`, prop.modifiers, null, prop.loc);
|
|
22385
|
+
if (key.toLowerCase() === "click") {
|
|
22386
|
+
if (nonKeyModifiers.includes("middle")) key = "mouseup";
|
|
22387
|
+
if (nonKeyModifiers.includes("right")) key = "contextmenu";
|
|
22388
|
+
}
|
|
22389
|
+
key = toHandlerKey(camelize(key));
|
|
22390
|
+
const optionPostfix = eventOptionModifiers.map(capitalize).join("");
|
|
22391
|
+
if (optionPostfix) key += optionPostfix;
|
|
22392
|
+
return key;
|
|
22393
|
+
}
|
|
22394
|
+
function getObjectLiteralKeys(exp) {
|
|
22395
|
+
const ast = exp && exp.ast;
|
|
22396
|
+
if (!ast || ast.type !== "ObjectExpression") return;
|
|
22397
|
+
const keys = /* @__PURE__ */ new Set();
|
|
22398
|
+
for (const property of ast.properties) {
|
|
22399
|
+
if (property.type !== "ObjectProperty" || property.computed) return;
|
|
22400
|
+
const key = getObjectPropertyName(property);
|
|
22401
|
+
if (key == null) return;
|
|
22402
|
+
keys.add(key);
|
|
22403
|
+
}
|
|
22404
|
+
return keys;
|
|
22405
|
+
}
|
|
22406
|
+
function createComponentConflictKeySet(keys) {
|
|
22407
|
+
const normalized = /* @__PURE__ */ new Set();
|
|
22408
|
+
for (const key of keys) {
|
|
22409
|
+
normalized.add(key);
|
|
22410
|
+
normalized.add(camelize(key));
|
|
22411
|
+
}
|
|
22412
|
+
return normalized;
|
|
22413
|
+
}
|
|
22414
|
+
function hasComponentKey(keys, key) {
|
|
22415
|
+
return keys.has(key) || keys.has(camelize(key));
|
|
22416
|
+
}
|
|
22417
|
+
function hasComponentKeyOverlap(left, right) {
|
|
22418
|
+
for (const key of right) if (hasComponentKey(left, key)) return true;
|
|
22419
|
+
return false;
|
|
22420
|
+
}
|
|
22421
|
+
function createObjectBindSubExpression(source, node, context) {
|
|
22422
|
+
const start = node.start == null ? 0 : node.start - 1;
|
|
22423
|
+
const end = node.end == null ? source.content.length : node.end - 1;
|
|
22424
|
+
const content = source.content.slice(start, end);
|
|
22425
|
+
const expression = createSimpleExpression(content, false, {
|
|
22426
|
+
start: advancePositionWithClone(source.loc.start, source.content, start),
|
|
22427
|
+
end: advancePositionWithClone(source.loc.start, source.content, end),
|
|
22428
|
+
source: content
|
|
22429
|
+
});
|
|
22430
|
+
expression.ast = isSimpleIdentifier(content) ? null : (0, import_lib.parseExpression)(`(${content})`, getParserOptions(context.options.expressionPlugins));
|
|
22431
|
+
return expression;
|
|
22432
|
+
}
|
|
21714
22433
|
function transformProp(prop, node, context) {
|
|
21715
22434
|
let { name } = prop;
|
|
21716
22435
|
if (prop.type === 6) {
|
|
@@ -21761,6 +22480,12 @@ function resolveDirectiveResult(prop) {
|
|
|
21761
22480
|
values: [prop.value]
|
|
21762
22481
|
});
|
|
21763
22482
|
}
|
|
22483
|
+
function toDirectiveResult(prop) {
|
|
22484
|
+
return extend({}, prop, {
|
|
22485
|
+
values: void 0,
|
|
22486
|
+
value: prop.values[0]
|
|
22487
|
+
});
|
|
22488
|
+
}
|
|
21764
22489
|
function mergePropValues(existing, incoming) {
|
|
21765
22490
|
const newValues = incoming.values;
|
|
21766
22491
|
existing.values.push(...newValues);
|
|
@@ -22274,6 +22999,7 @@ function processIf(node, dir, context) {
|
|
|
22274
22999
|
}
|
|
22275
23000
|
context.dynamic.flags |= 2;
|
|
22276
23001
|
const forceMultiRoot = shouldForceMultiRoot(context);
|
|
23002
|
+
const allowNoScope = context.block === context.root.block;
|
|
22277
23003
|
if (dir.name === "if") {
|
|
22278
23004
|
const id = context.reference();
|
|
22279
23005
|
context.dynamic.flags |= 4;
|
|
@@ -22284,7 +23010,7 @@ function processIf(node, dir, context) {
|
|
|
22284
23010
|
type: 15,
|
|
22285
23011
|
id
|
|
22286
23012
|
}, context.effectBoundary()), {}, {
|
|
22287
|
-
blockShape: encodeIfBlockShape(branch, forceMultiRoot),
|
|
23013
|
+
blockShape: encodeIfBlockShape(branch, forceMultiRoot, void 0, allowNoScope),
|
|
22288
23014
|
condition: dir.exp,
|
|
22289
23015
|
positive: branch,
|
|
22290
23016
|
index: context.root.nextIfIndex(),
|
|
@@ -22326,8 +23052,8 @@ function processIf(node, dir, context) {
|
|
|
22326
23052
|
};
|
|
22327
23053
|
return () => {
|
|
22328
23054
|
onExit();
|
|
22329
|
-
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot);
|
|
22330
|
-
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative);
|
|
23055
|
+
if (lastIfNode.negative.type === 15) lastIfNode.negative.blockShape = encodeIfBlockShape(lastIfNode.negative.positive, forceMultiRoot, void 0, allowNoScope);
|
|
23056
|
+
lastIfNode.blockShape = encodeIfBlockShape(lastIfNode.positive, forceMultiRoot, lastIfNode.negative, allowNoScope);
|
|
22331
23057
|
};
|
|
22332
23058
|
}
|
|
22333
23059
|
}
|
|
@@ -22342,14 +23068,38 @@ function createIfBranch(node, context) {
|
|
|
22342
23068
|
context.reference();
|
|
22343
23069
|
return [branch, exitBlock];
|
|
22344
23070
|
}
|
|
22345
|
-
function encodeIfBlockShape(positive, forceMultiRoot = false, negative) {
|
|
23071
|
+
function encodeIfBlockShape(positive, forceMultiRoot = false, negative, allowNoScope = true) {
|
|
22346
23072
|
if (forceMultiRoot) return 10;
|
|
22347
|
-
|
|
23073
|
+
const positiveNoScope = allowNoScope && canSkipIfBranchScope(positive);
|
|
23074
|
+
const negativeNoScope = allowNoScope && negative && negative.type !== 15 && canSkipIfBranchScope(negative);
|
|
23075
|
+
return getBlockShape(positive) | getNegativeIfBranchShape(negative) << 2 | (positiveNoScope ? 32 : 0) | (negativeNoScope ? 64 : 0);
|
|
22348
23076
|
}
|
|
22349
|
-
function
|
|
23077
|
+
function getNegativeIfBranchShape(negative) {
|
|
22350
23078
|
if (!negative) return 0;
|
|
22351
23079
|
return negative.type === 15 ? 1 : getBlockShape(negative);
|
|
22352
23080
|
}
|
|
23081
|
+
function canSkipIfBranchScope(block) {
|
|
23082
|
+
if (block.effect.length || block.operation.length) return false;
|
|
23083
|
+
if (!isStaticBranch(block.node)) return false;
|
|
23084
|
+
if (block.returns.length === 0 || block.dynamic.children.length !== block.returns.length) return false;
|
|
23085
|
+
return block.returns.every((id) => {
|
|
23086
|
+
const returned = findReturnedDynamic(block, id);
|
|
23087
|
+
return !!(returned && returned.template != null && !returned.operation && !returned.hasDynamicChild && !(returned.flags & 6));
|
|
23088
|
+
});
|
|
23089
|
+
}
|
|
23090
|
+
function findReturnedDynamic(block, id) {
|
|
23091
|
+
return block.dynamic.children.find((child) => child.id === id);
|
|
23092
|
+
}
|
|
23093
|
+
function isStaticBranch(node) {
|
|
23094
|
+
if (node.type !== 1 || node.tagType !== 3 || node.children.length === 0) return false;
|
|
23095
|
+
return node.children.every((child) => isStaticTemplateNode(child));
|
|
23096
|
+
}
|
|
23097
|
+
function isStaticTemplateNode(node) {
|
|
23098
|
+
if (node.type === 2 || node.type === 3) return true;
|
|
23099
|
+
if (node.type !== 1 || node.tagType !== 0) return false;
|
|
23100
|
+
for (const prop of node.props) if (prop.type === 7 || prop.name === "ref") return false;
|
|
23101
|
+
return node.children.every((child) => isStaticTemplateNode(child));
|
|
23102
|
+
}
|
|
22353
23103
|
function shouldForceMultiRoot(context) {
|
|
22354
23104
|
const parent = context.parent && context.parent.node;
|
|
22355
23105
|
return !!parent && parent.type === 1 && parent.tagType === 3 && parent.props.some((prop) => prop.type === 7 && prop.name === "for");
|
|
@@ -22434,6 +23184,9 @@ const transformSlotOutlet = (node, context) => {
|
|
|
22434
23184
|
}
|
|
22435
23185
|
return () => {
|
|
22436
23186
|
exitBlock && exitBlock();
|
|
23187
|
+
let flags = 0;
|
|
23188
|
+
if (context.options.scopeId && !context.options.slotted) flags |= 1;
|
|
23189
|
+
if (context.inVOnce) flags |= 2;
|
|
22437
23190
|
context.dynamic.operation = _objectSpread2(_objectSpread2({
|
|
22438
23191
|
type: 13,
|
|
22439
23192
|
id
|
|
@@ -22441,8 +23194,7 @@ const transformSlotOutlet = (node, context) => {
|
|
|
22441
23194
|
name: slotName,
|
|
22442
23195
|
props: irProps,
|
|
22443
23196
|
fallback,
|
|
22444
|
-
|
|
22445
|
-
once: context.inVOnce
|
|
23197
|
+
flags
|
|
22446
23198
|
});
|
|
22447
23199
|
};
|
|
22448
23200
|
};
|