@barefootjs/jsx 0.39.2 → 0.39.3
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/adapters/line-statement-text.d.ts +17 -0
- package/dist/adapters/line-statement-text.d.ts.map +1 -0
- package/dist/analyzer.d.ts +1 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/augment-inherited-props.d.ts +20 -0
- package/dist/augment-inherited-props.d.ts.map +1 -1
- package/dist/html-types.d.ts +15 -0
- package/dist/html-types.d.ts.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +260 -91
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +73 -0
- package/dist/nullable-signal-attr.d.ts.map +1 -0
- package/dist/scope/root-prop-alias.d.ts +43 -0
- package/dist/scope/root-prop-alias.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +3 -3
- package/src/__tests__/attribute-fallback-wrap.test.ts +24 -0
- package/src/__tests__/compiler-stress-1244.test.ts +10 -13
- package/src/__tests__/conditional-fallback-wrap.test.ts +20 -0
- package/src/__tests__/html-event-handler-names.test.ts +107 -0
- package/src/__tests__/line-statement-text.test.ts +25 -0
- package/src/__tests__/lookup-literal-const.test.ts +46 -0
- package/src/__tests__/loop-param-accessor-key-member-safety.test.ts +66 -19
- package/src/__tests__/nullable-signal-attr.test.ts +124 -0
- package/src/__tests__/profile-binding-ids.test.ts +102 -0
- package/src/__tests__/root-prop-alias.test.ts +62 -0
- package/src/adapters/line-statement-text.ts +24 -0
- package/src/analyzer.ts +50 -26
- package/src/augment-inherited-props.ts +49 -0
- package/src/html-types.ts +15 -0
- package/src/index.ts +13 -2
- package/src/ir-to-client-js/collect-elements.ts +7 -1
- package/src/ir-to-client-js/control-flow/plan/build-component-loop.ts +2 -2
- package/src/ir-to-client-js/stringify/declaration-emit.ts +5 -5
- package/src/ir-to-client-js/utils.ts +88 -117
- package/src/jsx-to-ir.ts +7 -0
- package/src/nullable-signal-attr.ts +156 -0
- package/src/scope/root-prop-alias.ts +81 -0
package/dist/index.js
CHANGED
|
@@ -2432,24 +2432,6 @@ function templatePartsToJsExpr(parts, opts) {
|
|
|
2432
2432
|
return result;
|
|
2433
2433
|
}
|
|
2434
2434
|
|
|
2435
|
-
// src/identifier-pattern.ts
|
|
2436
|
-
function withUnicodeFlag(flags) {
|
|
2437
|
-
return flags.includes("u") ? flags : `${flags}u`;
|
|
2438
|
-
}
|
|
2439
|
-
function escapeIdentifierForRegex(name) {
|
|
2440
|
-
return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2441
|
-
}
|
|
2442
|
-
var ID_BOUNDARY_BEFORE = "(?<![\\p{ID_Continue}$])";
|
|
2443
|
-
var ID_BOUNDARY_AFTER = "(?![\\p{ID_Continue}$])";
|
|
2444
|
-
function identifierPattern(name, flags = "") {
|
|
2445
|
-
const esc = escapeIdentifierForRegex(name);
|
|
2446
|
-
return new RegExp(`${ID_BOUNDARY_BEFORE}${esc}${ID_BOUNDARY_AFTER}`, withUnicodeFlag(flags));
|
|
2447
|
-
}
|
|
2448
|
-
function identifierCallPattern(name, flags = "") {
|
|
2449
|
-
const esc = escapeIdentifierForRegex(name);
|
|
2450
|
-
return new RegExp(`${ID_BOUNDARY_BEFORE}${esc}\\s*\\(`, withUnicodeFlag(flags));
|
|
2451
|
-
}
|
|
2452
|
-
|
|
2453
2435
|
// src/ir-to-client-js/utils.ts
|
|
2454
2436
|
import {
|
|
2455
2437
|
BF_KEY as DATA_KEY,
|
|
@@ -2556,6 +2538,24 @@ function collectValueReferencedNames(code) {
|
|
|
2556
2538
|
return names;
|
|
2557
2539
|
}
|
|
2558
2540
|
|
|
2541
|
+
// src/identifier-pattern.ts
|
|
2542
|
+
function withUnicodeFlag(flags) {
|
|
2543
|
+
return flags.includes("u") ? flags : `${flags}u`;
|
|
2544
|
+
}
|
|
2545
|
+
function escapeIdentifierForRegex(name) {
|
|
2546
|
+
return name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2547
|
+
}
|
|
2548
|
+
var ID_BOUNDARY_BEFORE = "(?<![\\p{ID_Continue}$])";
|
|
2549
|
+
var ID_BOUNDARY_AFTER = "(?![\\p{ID_Continue}$])";
|
|
2550
|
+
function identifierPattern(name, flags = "") {
|
|
2551
|
+
const esc = escapeIdentifierForRegex(name);
|
|
2552
|
+
return new RegExp(`${ID_BOUNDARY_BEFORE}${esc}${ID_BOUNDARY_AFTER}`, withUnicodeFlag(flags));
|
|
2553
|
+
}
|
|
2554
|
+
function identifierCallPattern(name, flags = "") {
|
|
2555
|
+
const esc = escapeIdentifierForRegex(name);
|
|
2556
|
+
return new RegExp(`${ID_BOUNDARY_BEFORE}${esc}\\s*\\(`, withUnicodeFlag(flags));
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
2559
|
// src/ir-to-client-js/imports.ts
|
|
2560
2560
|
var RUNTIME_IMPORT_CANDIDATES = [
|
|
2561
2561
|
"createSignal",
|
|
@@ -3093,33 +3093,54 @@ function wrapIndexParamAsAccessor(expr, indexParam) {
|
|
|
3093
3093
|
return rewriteIdentifierAsAccessor(expr, indexParam);
|
|
3094
3094
|
}
|
|
3095
3095
|
function rewriteIdentifierAsAccessor(expr, name) {
|
|
3096
|
-
|
|
3096
|
+
return rewriteIdentifierReferences(expr, new Map([[name, `${name}()`]]), { skipCallee: true });
|
|
3097
|
+
}
|
|
3098
|
+
function rewriteIdentifierReferences(expr, replacements, opts) {
|
|
3099
|
+
let any = false;
|
|
3100
|
+
for (const name of replacements.keys()) {
|
|
3101
|
+
if (expr.includes(name)) {
|
|
3102
|
+
any = true;
|
|
3103
|
+
break;
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
if (!any)
|
|
3097
3107
|
return expr;
|
|
3098
3108
|
const wrapped = `(${expr})`;
|
|
3099
3109
|
const sf = ts5.createSourceFile("__bf_expr.ts", wrapped, ts5.ScriptTarget.Latest, true);
|
|
3100
3110
|
const edits = [];
|
|
3101
|
-
const visit = (node) => {
|
|
3102
|
-
if (ts5.isFunctionExpression(node) && node.name
|
|
3111
|
+
const visit = (node, active) => {
|
|
3112
|
+
if (ts5.isFunctionExpression(node) && node.name && active.has(node.name.text)) {
|
|
3113
|
+
const inner = new Map(active);
|
|
3114
|
+
inner.delete(node.name.text);
|
|
3115
|
+
if (inner.size === 0)
|
|
3116
|
+
return;
|
|
3117
|
+
ts5.forEachChild(node, (child) => visit(child, inner));
|
|
3103
3118
|
return;
|
|
3104
|
-
|
|
3119
|
+
}
|
|
3120
|
+
if (ts5.isIdentifier(node)) {
|
|
3121
|
+
const replacement = active.get(node.text);
|
|
3122
|
+
if (replacement === undefined)
|
|
3123
|
+
return;
|
|
3105
3124
|
const p = node.parent;
|
|
3106
3125
|
if (isNonReferenceIdentifierPosition(node))
|
|
3107
3126
|
return;
|
|
3108
|
-
if (
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3127
|
+
if (opts.skipCallee) {
|
|
3128
|
+
if (ts5.isFunctionDeclaration(p) && p.name === node)
|
|
3129
|
+
return;
|
|
3130
|
+
if (ts5.isCallExpression(p) && p.expression === node)
|
|
3131
|
+
return;
|
|
3132
|
+
if (ts5.isNewExpression(p) && p.expression === node)
|
|
3133
|
+
return;
|
|
3134
|
+
}
|
|
3114
3135
|
const isShorthand = ts5.isShorthandPropertyAssignment(p) && p.name === node;
|
|
3115
3136
|
const start = node.getStart(sf) - 1;
|
|
3116
3137
|
const end = node.getEnd() - 1;
|
|
3117
|
-
edits.push({ start, end, replacement: isShorthand ? `${
|
|
3138
|
+
edits.push({ start, end, replacement: isShorthand ? `${node.text}: ${replacement}` : replacement });
|
|
3118
3139
|
return;
|
|
3119
3140
|
}
|
|
3120
|
-
ts5.forEachChild(node, visit);
|
|
3141
|
+
ts5.forEachChild(node, (child) => visit(child, active));
|
|
3121
3142
|
};
|
|
3122
|
-
visit(sf);
|
|
3143
|
+
visit(sf, replacements);
|
|
3123
3144
|
if (edits.length === 0)
|
|
3124
3145
|
return expr;
|
|
3125
3146
|
edits.sort((a, b) => b.start - a.start);
|
|
@@ -3130,38 +3151,10 @@ function rewriteIdentifierAsAccessor(expr, name) {
|
|
|
3130
3151
|
return out;
|
|
3131
3152
|
}
|
|
3132
3153
|
function rewriteLoopBindingRefs(expr, bindings, accessor) {
|
|
3133
|
-
const
|
|
3154
|
+
const replacements = new Map;
|
|
3134
3155
|
for (const b of bindings)
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
const alt = bindings.map((b) => escapeIdentifierForRegex(b.name)).join("|");
|
|
3138
|
-
const re = new RegExp(`${ID_BOUNDARY_BEFORE}(${alt})${ID_BOUNDARY_AFTER}`, "gu");
|
|
3139
|
-
return replaceInExprContexts(preprocessed, re, (_m, name) => renderLoopBindingAccess(byName.get(name), accessor));
|
|
3140
|
-
}
|
|
3141
|
-
function expandShorthandBindings(expr, bindingNames) {
|
|
3142
|
-
if (!expr.includes("{"))
|
|
3143
|
-
return expr;
|
|
3144
|
-
const wrapped = `(${expr})`;
|
|
3145
|
-
const sf = ts5.createSourceFile("__bf_expr.ts", wrapped, ts5.ScriptTarget.Latest, true);
|
|
3146
|
-
const edits = [];
|
|
3147
|
-
const visit = (node) => {
|
|
3148
|
-
if (ts5.isShorthandPropertyAssignment(node) && ts5.isIdentifier(node.name) && bindingNames.has(node.name.text)) {
|
|
3149
|
-
const start = node.getStart(sf) - 1;
|
|
3150
|
-
const end = node.getEnd() - 1;
|
|
3151
|
-
const name = node.name.text;
|
|
3152
|
-
edits.push({ start, end, replacement: `${JSON.stringify(name)}: ${name}` });
|
|
3153
|
-
}
|
|
3154
|
-
ts5.forEachChild(node, visit);
|
|
3155
|
-
};
|
|
3156
|
-
visit(sf);
|
|
3157
|
-
if (edits.length === 0)
|
|
3158
|
-
return expr;
|
|
3159
|
-
edits.sort((a, b) => b.start - a.start);
|
|
3160
|
-
let out = expr;
|
|
3161
|
-
for (const e of edits) {
|
|
3162
|
-
out = out.slice(0, e.start) + e.replacement + out.slice(e.end);
|
|
3163
|
-
}
|
|
3164
|
-
return out;
|
|
3156
|
+
replacements.set(b.name, renderLoopBindingAccess(b, accessor));
|
|
3157
|
+
return rewriteIdentifierReferences(expr, replacements, { skipCallee: false });
|
|
3165
3158
|
}
|
|
3166
3159
|
function substituteLoopBindings(expr, bindings, accessor) {
|
|
3167
3160
|
if (!bindings || bindings.length === 0)
|
|
@@ -8039,14 +8032,9 @@ function collectSignal(node, ctx) {
|
|
|
8039
8032
|
if (getterElided && !setter)
|
|
8040
8033
|
return;
|
|
8041
8034
|
const getter = getterElided ? `__bfGet_${setter}` : elements[0].name.text;
|
|
8042
|
-
const initialValue = callExpr
|
|
8035
|
+
const initialValue = signalInitialValueText(callExpr, ctx);
|
|
8043
8036
|
const typedInitialValue = callExpr.arguments[0] ? callExpr.arguments[0].getText(ctx.sourceFile) : undefined;
|
|
8044
|
-
|
|
8045
|
-
if (callExpr.typeArguments && callExpr.typeArguments.length > 0) {
|
|
8046
|
-
type = typeNodeToTypeInfo(callExpr.typeArguments[0], ctx.sourceFile) ?? type;
|
|
8047
|
-
} else {
|
|
8048
|
-
type = inferTypeFromValue(initialValue);
|
|
8049
|
-
}
|
|
8037
|
+
const type = signalTypeInfo(callExpr, initialValue, ctx);
|
|
8050
8038
|
const envReader = resolveEnvSignalKey(callExpr, ctx) ?? undefined;
|
|
8051
8039
|
const envFactory = envReader ? callExpr.expression.getText(ctx.sourceFile) : undefined;
|
|
8052
8040
|
let templateInitialValue;
|
|
@@ -8189,17 +8177,34 @@ function isSignalIndexAccess(node, ctx) {
|
|
|
8189
8177
|
}
|
|
8190
8178
|
return null;
|
|
8191
8179
|
}
|
|
8180
|
+
function signalInitialValueText(callExpr, ctx) {
|
|
8181
|
+
return callExpr.arguments[0] ? ctx.getJS(callExpr.arguments[0]) : "undefined";
|
|
8182
|
+
}
|
|
8183
|
+
function signalTypeInfo(callExpr, initialValue, ctx) {
|
|
8184
|
+
const typeArg = callExpr.typeArguments?.[0];
|
|
8185
|
+
if (!typeArg)
|
|
8186
|
+
return inferTypeFromValue(initialValue);
|
|
8187
|
+
const type = typeNodeToTypeInfo(typeArg, ctx.sourceFile) ?? { kind: "unknown", raw: "unknown" };
|
|
8188
|
+
return callExpr.arguments[0] ? type : withUndefined(type);
|
|
8189
|
+
}
|
|
8190
|
+
function withUndefined(type) {
|
|
8191
|
+
const members = type.kind === "union" && type.unionTypes ? type.unionTypes : [type];
|
|
8192
|
+
if (members.some((t) => t.kind === "primitive" && t.primitive === "undefined"))
|
|
8193
|
+
return type;
|
|
8194
|
+
if (type.kind === "unknown")
|
|
8195
|
+
return type;
|
|
8196
|
+
return {
|
|
8197
|
+
kind: "union",
|
|
8198
|
+
raw: `${type.raw} | undefined`,
|
|
8199
|
+
unionTypes: [...members, { kind: "primitive", raw: "undefined", primitive: "undefined" }]
|
|
8200
|
+
};
|
|
8201
|
+
}
|
|
8192
8202
|
function collectSignalTupleRef(node, ctx) {
|
|
8193
8203
|
const name = node.name.text;
|
|
8194
8204
|
const callExpr = node.initializer;
|
|
8195
|
-
const initialValue = callExpr
|
|
8205
|
+
const initialValue = signalInitialValueText(callExpr, ctx);
|
|
8196
8206
|
const typedInitialValue = callExpr.arguments[0] ? callExpr.arguments[0].getText(ctx.sourceFile) : undefined;
|
|
8197
|
-
|
|
8198
|
-
if (callExpr.typeArguments && callExpr.typeArguments.length > 0) {
|
|
8199
|
-
type = typeNodeToTypeInfo(callExpr.typeArguments[0], ctx.sourceFile) ?? type;
|
|
8200
|
-
} else {
|
|
8201
|
-
type = inferTypeFromValue(initialValue);
|
|
8202
|
-
}
|
|
8207
|
+
const type = signalTypeInfo(callExpr, initialValue, ctx);
|
|
8203
8208
|
ctx.signalTupleRefs.set(name, {
|
|
8204
8209
|
initialValue,
|
|
8205
8210
|
typedInitialValue: typedInitialValue !== initialValue ? typedInitialValue : undefined,
|
|
@@ -8214,14 +8219,9 @@ function collectSignalFromIndexAccess(node, match, ctx) {
|
|
|
8214
8219
|
const varName = node.name.text;
|
|
8215
8220
|
if (match.kind === "direct") {
|
|
8216
8221
|
const callExpr = match.callExpr;
|
|
8217
|
-
const initialValue = callExpr
|
|
8222
|
+
const initialValue = signalInitialValueText(callExpr, ctx);
|
|
8218
8223
|
const typedInitialValue = callExpr.arguments[0] ? callExpr.arguments[0].getText(ctx.sourceFile) : undefined;
|
|
8219
|
-
|
|
8220
|
-
if (callExpr.typeArguments && callExpr.typeArguments.length > 0) {
|
|
8221
|
-
type = typeNodeToTypeInfo(callExpr.typeArguments[0], ctx.sourceFile) ?? type;
|
|
8222
|
-
} else {
|
|
8223
|
-
type = inferTypeFromValue(initialValue);
|
|
8224
|
-
}
|
|
8224
|
+
const type = signalTypeInfo(callExpr, initialValue, ctx);
|
|
8225
8225
|
const loc = getSourceLocation(node, ctx.sourceFile, ctx.filePath);
|
|
8226
8226
|
const initialFreeIdentifiers = callExpr.arguments[0] ? extractFreeIdentifiersFromNode(callExpr.arguments[0]) : new Set;
|
|
8227
8227
|
if (match.index === 0) {
|
|
@@ -16786,6 +16786,8 @@ function hasReactiveAttributes(attrs, ctx) {
|
|
|
16786
16786
|
if (isSignalOrMemoReference(valueToCheck, ctx) || isPropsReference(valueToCheck, ctx)) {
|
|
16787
16787
|
return true;
|
|
16788
16788
|
}
|
|
16789
|
+
if (attr.callsReactiveGetters || attr.hasFunctionCalls)
|
|
16790
|
+
return true;
|
|
16789
16791
|
const scopeValueNames = ctx.scope.valueBoundNames();
|
|
16790
16792
|
if (scopeValueNames.size > 0) {
|
|
16791
16793
|
for (const p of scopeValueNames) {
|
|
@@ -18244,7 +18246,7 @@ function collectBranchTextEffects(node) {
|
|
|
18244
18246
|
walkIR(node, null, {
|
|
18245
18247
|
...stopAt("conditional", "ifStatement", "loop"),
|
|
18246
18248
|
expression: ({ node: n }) => {
|
|
18247
|
-
if (n.
|
|
18249
|
+
if (decideWrapFromAstFlags(n).wrap && n.slotId && !n.clientOnly) {
|
|
18248
18250
|
effects.push({ slotId: n.slotId, expression: n.expr });
|
|
18249
18251
|
}
|
|
18250
18252
|
}
|
|
@@ -20032,25 +20034,25 @@ function emitSignal(lines, plan) {
|
|
|
20032
20034
|
lines.push(` const [${bindings}] = ${plan.initializerOverride}`);
|
|
20033
20035
|
return;
|
|
20034
20036
|
}
|
|
20035
|
-
const
|
|
20037
|
+
const args = `${plan.initialValueExpr}${bfIdArg(plan.bfId)}`;
|
|
20036
20038
|
if (plan.branchCondition) {
|
|
20037
20039
|
if (plan.setter) {
|
|
20038
20040
|
lines.push(plan.getterElided ? ` let ${plan.setter}` : ` let ${plan.getter}, ${plan.setter}`);
|
|
20039
20041
|
lines.push(` if (${plan.branchCondition}) {`);
|
|
20040
|
-
lines.push(` ;[${getterSlot}, ${plan.setter}] = createSignal(${
|
|
20042
|
+
lines.push(` ;[${getterSlot}, ${plan.setter}] = createSignal(${args})`);
|
|
20041
20043
|
lines.push(` }`);
|
|
20042
20044
|
} else {
|
|
20043
20045
|
lines.push(` let ${plan.getter}`);
|
|
20044
20046
|
lines.push(` if (${plan.branchCondition}) {`);
|
|
20045
|
-
lines.push(` ;[${plan.getter}] = createSignal(${
|
|
20047
|
+
lines.push(` ;[${plan.getter}] = createSignal(${args})`);
|
|
20046
20048
|
lines.push(` }`);
|
|
20047
20049
|
}
|
|
20048
20050
|
return;
|
|
20049
20051
|
}
|
|
20050
20052
|
if (plan.setter) {
|
|
20051
|
-
lines.push(` const [${getterSlot}, ${plan.setter}] = createSignal(${
|
|
20053
|
+
lines.push(` const [${getterSlot}, ${plan.setter}] = createSignal(${args})`);
|
|
20052
20054
|
} else {
|
|
20053
|
-
lines.push(` const [${plan.getter}] = createSignal(${
|
|
20055
|
+
lines.push(` const [${plan.getter}] = createSignal(${args})`);
|
|
20054
20056
|
}
|
|
20055
20057
|
if (plan.controlledEffect) {
|
|
20056
20058
|
emitControlledEffect(lines, plan.controlledEffect);
|
|
@@ -21519,7 +21521,7 @@ function collectTextOnlySlotIds(nodes, into) {
|
|
|
21519
21521
|
}
|
|
21520
21522
|
function buildComponentLoopPlan(elem, profileComponentName) {
|
|
21521
21523
|
const { name } = elem.childComponent;
|
|
21522
|
-
const propsExpr = buildComponentPropsExpr2(elem.childComponent, elem.param,
|
|
21524
|
+
const propsExpr = buildComponentPropsExpr2(elem.childComponent, elem.param, elem.paramBindings, elem.index);
|
|
21523
21525
|
const keyExpr = wrapLoopParamAsAccessor(elem.key || "__idx", elem.param, elem.paramBindings, elem.index);
|
|
21524
21526
|
const { head: paramHead, unwrap: paramUnwrap } = destructureLoopParam(elem.param, elem.paramBindings);
|
|
21525
21527
|
const mapPreambleWrapped = elem.preamble ? renderPreamble(elem.preamble, {
|
|
@@ -21542,7 +21544,7 @@ function buildComponentLoopPlan(elem, profileComponentName) {
|
|
|
21542
21544
|
return {
|
|
21543
21545
|
componentName: comp.name,
|
|
21544
21546
|
selector: buildCompSelector(comp),
|
|
21545
|
-
propsExpr: buildComponentPropsExpr2(comp, elem.param,
|
|
21547
|
+
propsExpr: buildComponentPropsExpr2(comp, elem.param, elem.paramBindings, elem.index),
|
|
21546
21548
|
childrenTextEffect: childrenRefsLoop ? buildChildrenTextEffect(comp.children, rawChildrenExpr, wrap) : null
|
|
21547
21549
|
};
|
|
21548
21550
|
});
|
|
@@ -26699,6 +26701,39 @@ function lookupStaticRecordLiteral(objectName, key, constants, isShadowed) {
|
|
|
26699
26701
|
}
|
|
26700
26702
|
return null;
|
|
26701
26703
|
}
|
|
26704
|
+
function lookupLiteralConst(name, constants, isShadowed) {
|
|
26705
|
+
if (isShadowed(name))
|
|
26706
|
+
return null;
|
|
26707
|
+
const c = (constants ?? []).find((lc) => lc.name === name);
|
|
26708
|
+
if (c?.value === undefined)
|
|
26709
|
+
return null;
|
|
26710
|
+
const p = c.parsed;
|
|
26711
|
+
if (p?.kind === "literal") {
|
|
26712
|
+
if (p.literalType === "string" && typeof p.value === "string")
|
|
26713
|
+
return { kind: "string", text: p.value };
|
|
26714
|
+
if (p.literalType === "boolean" && typeof p.value === "boolean")
|
|
26715
|
+
return { kind: "boolean", text: String(p.value) };
|
|
26716
|
+
if (p.literalType === "null")
|
|
26717
|
+
return { kind: "null", text: "null" };
|
|
26718
|
+
if (p.literalType === "number" && typeof p.value === "number" && Number.isFinite(p.value)) {
|
|
26719
|
+
return { kind: "number", text: String(p.value) };
|
|
26720
|
+
}
|
|
26721
|
+
}
|
|
26722
|
+
if (p?.kind === "unary" && p.op === "-" && p.argument.kind === "literal" && p.argument.literalType === "number" && typeof p.argument.value === "number" && Number.isFinite(p.argument.value)) {
|
|
26723
|
+
return { kind: "number", text: String(-p.argument.value) };
|
|
26724
|
+
}
|
|
26725
|
+
if (p)
|
|
26726
|
+
return null;
|
|
26727
|
+
const v = c.value.trim();
|
|
26728
|
+
if (/^-?\d+(\.\d+)?$/.test(v))
|
|
26729
|
+
return { kind: "number", text: v };
|
|
26730
|
+
if (v === "true" || v === "false")
|
|
26731
|
+
return { kind: "boolean", text: v };
|
|
26732
|
+
if (v === "null")
|
|
26733
|
+
return { kind: "null", text: "null" };
|
|
26734
|
+
const strLit2 = /^'([^'\\]*)'$/.exec(v) ?? /^"([^"\\]*)"$/.exec(v);
|
|
26735
|
+
return strLit2 ? { kind: "string", text: strLit2[1] } : null;
|
|
26736
|
+
}
|
|
26702
26737
|
function evalStringArrayJoin(source) {
|
|
26703
26738
|
const sf = ts26.createSourceFile("__join.ts", `const __x = (${source});`, ts26.ScriptTarget.Latest, false);
|
|
26704
26739
|
const stmt = sf.statements[0];
|
|
@@ -28898,6 +28933,83 @@ function resolveStaticLoopSource(arrayParsed, localConstants, opts) {
|
|
|
28898
28933
|
return null;
|
|
28899
28934
|
return resolved.value;
|
|
28900
28935
|
}
|
|
28936
|
+
// src/nullable-signal-attr.ts
|
|
28937
|
+
function isNullishType(type) {
|
|
28938
|
+
return type.kind === "primitive" && (type.primitive === "undefined" || type.primitive === "null");
|
|
28939
|
+
}
|
|
28940
|
+
function admitsNullish(type) {
|
|
28941
|
+
if (isNullishType(type))
|
|
28942
|
+
return true;
|
|
28943
|
+
return type.kind === "union" && (type.unionTypes ?? []).some(isNullishType);
|
|
28944
|
+
}
|
|
28945
|
+
function isNullishLiteral(expr) {
|
|
28946
|
+
if (!expr)
|
|
28947
|
+
return false;
|
|
28948
|
+
if (expr.kind === "identifier")
|
|
28949
|
+
return expr.name === "undefined";
|
|
28950
|
+
return expr.kind === "literal" && expr.literalType === "null";
|
|
28951
|
+
}
|
|
28952
|
+
function isNullableSignal(signal) {
|
|
28953
|
+
if (admitsNullish(signal.type))
|
|
28954
|
+
return true;
|
|
28955
|
+
return signal.type.kind === "unknown" && isNullishLiteral(signal.parsed);
|
|
28956
|
+
}
|
|
28957
|
+
function collectNullableSignalGetters(ir) {
|
|
28958
|
+
return new Set((ir.metadata.signals ?? []).filter(isNullableSignal).map((s) => s.getter));
|
|
28959
|
+
}
|
|
28960
|
+
function bareGetterCallName(parsed) {
|
|
28961
|
+
if (!parsed || parsed.kind !== "call" || parsed.args.length !== 0)
|
|
28962
|
+
return null;
|
|
28963
|
+
return parsed.callee.kind === "identifier" ? parsed.callee.name : null;
|
|
28964
|
+
}
|
|
28965
|
+
function nullableSignalAttrGetter(parsed, nullable) {
|
|
28966
|
+
const getter = bareGetterCallName(parsed);
|
|
28967
|
+
return getter !== null && nullable.has(getter) ? getter : null;
|
|
28968
|
+
}
|
|
28969
|
+
function collectNullishAttrContext(ir) {
|
|
28970
|
+
return {
|
|
28971
|
+
nullableSignals: collectNullableSignalGetters(ir),
|
|
28972
|
+
memos: new Map((ir.metadata.memos ?? []).map((m) => [m.name, m]))
|
|
28973
|
+
};
|
|
28974
|
+
}
|
|
28975
|
+
function attrValueMayBeNullish(parsed, ctx, isShadowed = () => false) {
|
|
28976
|
+
const visiting = new Set;
|
|
28977
|
+
const walk = (expr, shadowed) => {
|
|
28978
|
+
switch (expr.kind) {
|
|
28979
|
+
case "identifier":
|
|
28980
|
+
return expr.name === "undefined";
|
|
28981
|
+
case "literal":
|
|
28982
|
+
return expr.literalType === "null";
|
|
28983
|
+
case "call": {
|
|
28984
|
+
const getter = bareGetterCallName(expr);
|
|
28985
|
+
if (getter === null || shadowed(getter))
|
|
28986
|
+
return false;
|
|
28987
|
+
if (ctx.nullableSignals.has(getter))
|
|
28988
|
+
return true;
|
|
28989
|
+
const memo = ctx.memos.get(getter);
|
|
28990
|
+
if (!memo || visiting.has(getter))
|
|
28991
|
+
return false;
|
|
28992
|
+
if (admitsNullish(memo.type))
|
|
28993
|
+
return true;
|
|
28994
|
+
visiting.add(getter);
|
|
28995
|
+
const result = memo.parsed !== undefined && walk(memo.parsed, () => false);
|
|
28996
|
+
visiting.delete(getter);
|
|
28997
|
+
return result;
|
|
28998
|
+
}
|
|
28999
|
+
case "member":
|
|
29000
|
+
return expr.optional || walk(expr.object, shadowed);
|
|
29001
|
+
case "index-access":
|
|
29002
|
+
return walk(expr.object, shadowed);
|
|
29003
|
+
case "conditional":
|
|
29004
|
+
return walk(expr.consequent, shadowed) || walk(expr.alternate, shadowed);
|
|
29005
|
+
case "logical":
|
|
29006
|
+
return expr.op === "&&" ? walk(expr.left, shadowed) || walk(expr.right, shadowed) : walk(expr.right, shadowed);
|
|
29007
|
+
default:
|
|
29008
|
+
return false;
|
|
29009
|
+
}
|
|
29010
|
+
};
|
|
29011
|
+
return parsed !== undefined && walk(parsed, isShadowed);
|
|
29012
|
+
}
|
|
28901
29013
|
// src/query-href-lowering.ts
|
|
28902
29014
|
function matchQueryHrefCall(callee, args, localNames) {
|
|
28903
29015
|
if (callee.kind !== "identifier" || !localNames.has(callee.name))
|
|
@@ -29039,6 +29151,15 @@ function emitAttrValue(value, emitter, name) {
|
|
|
29039
29151
|
}
|
|
29040
29152
|
}
|
|
29041
29153
|
}
|
|
29154
|
+
// src/adapters/line-statement-text.ts
|
|
29155
|
+
function escapeLineStatementSigil(text, sigil, literal) {
|
|
29156
|
+
return text.split(`
|
|
29157
|
+
`).map((line) => {
|
|
29158
|
+
const indent = line.length - line.trimStart().length;
|
|
29159
|
+
return line.startsWith(sigil, indent) ? line.slice(0, indent) + literal + line.slice(indent + sigil.length) : line;
|
|
29160
|
+
}).join(`
|
|
29161
|
+
`);
|
|
29162
|
+
}
|
|
29042
29163
|
// src/adapters/dangerous-inner-html.ts
|
|
29043
29164
|
var DANGEROUS_INNER_HTML_ATTR = "dangerouslySetInnerHTML";
|
|
29044
29165
|
function isDangerousInnerHtmlAttr(attr) {
|
|
@@ -29357,6 +29478,42 @@ function restNamesMisused(loop, names) {
|
|
|
29357
29478
|
function escapeRe(s) {
|
|
29358
29479
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
29359
29480
|
}
|
|
29481
|
+
// src/scope/root-prop-alias.ts
|
|
29482
|
+
function rootPropAliasNames(ir, propNames) {
|
|
29483
|
+
const { metadata } = ir;
|
|
29484
|
+
const props = [...propNames];
|
|
29485
|
+
const taken = new Set([
|
|
29486
|
+
...props,
|
|
29487
|
+
...metadata.localConstants.map((c) => c.name),
|
|
29488
|
+
...metadata.localFunctions.map((f) => f.name),
|
|
29489
|
+
...metadata.signals.flatMap((s) => s.setter ? [s.getter, s.setter] : [s.getter]),
|
|
29490
|
+
...metadata.memos.map((m) => m.name),
|
|
29491
|
+
...collectLoopBoundNames(ir)
|
|
29492
|
+
]);
|
|
29493
|
+
const aliases = new Map;
|
|
29494
|
+
for (const name of props) {
|
|
29495
|
+
let alias = `__bf_root_${name}`;
|
|
29496
|
+
while (taken.has(alias))
|
|
29497
|
+
alias += "_";
|
|
29498
|
+
taken.add(alias);
|
|
29499
|
+
aliases.set(name, alias);
|
|
29500
|
+
}
|
|
29501
|
+
return aliases;
|
|
29502
|
+
}
|
|
29503
|
+
function rootPropAliasesForLoop(outer, row, aliases) {
|
|
29504
|
+
const shadowed = [];
|
|
29505
|
+
for (const name of row.boundNames()) {
|
|
29506
|
+
const alias = aliases.get(name);
|
|
29507
|
+
if (alias !== undefined && !outer.isBound(name))
|
|
29508
|
+
shadowed.push({ name, alias });
|
|
29509
|
+
}
|
|
29510
|
+
return shadowed;
|
|
29511
|
+
}
|
|
29512
|
+
function rootPropReadName(name, scope, aliases) {
|
|
29513
|
+
if (!scope.isBound(name))
|
|
29514
|
+
return name;
|
|
29515
|
+
return aliases.get(name) ?? name;
|
|
29516
|
+
}
|
|
29360
29517
|
// src/debug.ts
|
|
29361
29518
|
import ts31 from "typescript";
|
|
29362
29519
|
function buildComponentGraph(source, filePath, componentName) {
|
|
@@ -32168,6 +32325,9 @@ export {
|
|
|
32168
32325
|
serializeParsedExpr,
|
|
32169
32326
|
searchParamsLocalNames,
|
|
32170
32327
|
scanComponentFile,
|
|
32328
|
+
rootPropReadName,
|
|
32329
|
+
rootPropAliasesForLoop,
|
|
32330
|
+
rootPropAliasNames,
|
|
32171
32331
|
rewriteImportsForTemplate,
|
|
32172
32332
|
rewriteDynamicImportsInSource,
|
|
32173
32333
|
resolveStaticLoopSource,
|
|
@@ -32193,6 +32353,7 @@ export {
|
|
|
32193
32353
|
parseExpression,
|
|
32194
32354
|
parseBlockBodyTolerant,
|
|
32195
32355
|
parseBlockBody,
|
|
32356
|
+
nullableSignalAttrGetter,
|
|
32196
32357
|
needsTypeBasedDetection,
|
|
32197
32358
|
materializeGetterCalls,
|
|
32198
32359
|
matchSearchParamsMethodCall,
|
|
@@ -32201,6 +32362,7 @@ export {
|
|
|
32201
32362
|
makeIdCallRegex,
|
|
32202
32363
|
loweringNodeChildren,
|
|
32203
32364
|
lookupStaticRecordLiteral,
|
|
32365
|
+
lookupLiteralConst,
|
|
32204
32366
|
literalMemberIndex,
|
|
32205
32367
|
listComponentFunctions as listExportedComponents,
|
|
32206
32368
|
listComponentFunctions,
|
|
@@ -32213,6 +32375,8 @@ export {
|
|
|
32213
32375
|
isStringTypedOperand,
|
|
32214
32376
|
isStringConcatBinary,
|
|
32215
32377
|
isOpaqueLocalAccessorName,
|
|
32378
|
+
isNullishLiteral,
|
|
32379
|
+
isNullableSignal,
|
|
32216
32380
|
isLowerableObjectRestDestructure,
|
|
32217
32381
|
isLowerableLoopDestructure,
|
|
32218
32382
|
isIdentifierName,
|
|
@@ -32266,6 +32430,7 @@ export {
|
|
|
32266
32430
|
evaluateStaticLiteral,
|
|
32267
32431
|
evaluateProfileGates,
|
|
32268
32432
|
evalStringArrayJoin,
|
|
32433
|
+
escapeLineStatementSigil,
|
|
32269
32434
|
envSignalReaderFor,
|
|
32270
32435
|
envSignalLocalNames,
|
|
32271
32436
|
enableCompilerInstrumentation,
|
|
@@ -32290,6 +32455,8 @@ export {
|
|
|
32290
32455
|
compileJSX,
|
|
32291
32456
|
combineParentChildClientJs,
|
|
32292
32457
|
collectValueReferencedNames,
|
|
32458
|
+
collectNullishAttrContext,
|
|
32459
|
+
collectNullableSignalGetters,
|
|
32293
32460
|
collectModuleStringConsts,
|
|
32294
32461
|
collectLoopBoundNames,
|
|
32295
32462
|
collectContextConsumers,
|
|
@@ -32313,6 +32480,7 @@ export {
|
|
|
32313
32480
|
buildComponentGraph,
|
|
32314
32481
|
buildComponentAnalysis,
|
|
32315
32482
|
augmentInheritedPropAccesses,
|
|
32483
|
+
attrValueMayBeNullish,
|
|
32316
32484
|
asCallbackMethodCall,
|
|
32317
32485
|
applyCssLayerPrefix,
|
|
32318
32486
|
analyzeWastedReReruns,
|
|
@@ -32335,6 +32503,7 @@ export {
|
|
|
32335
32503
|
ESCAPE_SSR_COST,
|
|
32336
32504
|
ENV_SIGNAL_READERS,
|
|
32337
32505
|
CLIENT_EXPRESSION_DIRECTIVE,
|
|
32506
|
+
CLIENT_EXPORTS,
|
|
32338
32507
|
CALLBACK_METHODS,
|
|
32339
32508
|
BindingScope,
|
|
32340
32509
|
BaseAdapter,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coll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xB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAkB,gBAAgB,EAAE,aAAa,EAAE,MAAM,EAAc,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9H,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/ir-to-client-js/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAkB,gBAAgB,EAAE,aAAa,EAAE,MAAM,EAAc,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9H,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAGtE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAM5D,OAAO,EACL,MAAM,IAAI,QAAQ,EAClB,aAAa,IAAI,eAAe,EAChC,cAAc,IAAI,UAAU,EAC5B,aAAa,EACb,WAAW,EACX,eAAe,EACf,aAAa,EACb,cAAc,EACd,cAAc,IAAI,cAAc,EAChC,WAAW,IAAI,iBAAiB,EAEjC,MAAM,oBAAoB,CAAA;AAG3B,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,CAAA;AAE5I;;;GAGG;AACH,eAAO,MAAM,WAAW,OAAO,CAAA;AAK/B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAG9D;AAED;;;;;;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,EAAE,UAAU,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,MAAM,CAQ/G"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nullish-attribute omission for signal reads (#3304).
|
|
3
|
+
*
|
|
4
|
+
* Hono omits an attribute whose value is `undefined` or `null`
|
|
5
|
+
* (`title={s()}` with `s()` undefined renders no `title`). A DSL adapter
|
|
6
|
+
* emits `name="<value>"` unconditionally, so a nil value renders
|
|
7
|
+
* `title=""` unless the adapter guards the attribute on a nil check. Each
|
|
8
|
+
* DSL adapter already guards a bare reference to a no-default optional prop
|
|
9
|
+
* that way; this module is the one decision for the signal half, which
|
|
10
|
+
* every adapter consults instead of re-deriving it.
|
|
11
|
+
*
|
|
12
|
+
* Only the SSR value matters here — a signal's SSR value is its initial
|
|
13
|
+
* value — and the guard is presence-only: a non-nil value renders exactly
|
|
14
|
+
* as it did unguarded, so over-including a signal never changes output for
|
|
15
|
+
* a non-nil value.
|
|
16
|
+
*/
|
|
17
|
+
import type { ParsedExpr } from './expression-parser.ts';
|
|
18
|
+
import type { ComponentIR, MemoInfo, SignalInfo } from './types.ts';
|
|
19
|
+
/** `undefined` / `null` as a parsed initial value. */
|
|
20
|
+
export declare function isNullishLiteral(expr: ParsedExpr | undefined): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the signal's SSR value can be nullish. The witness is its type
|
|
23
|
+
* admitting `undefined`/`null` (a zero-arg `createSignal<T>()` is typed
|
|
24
|
+
* `T | undefined`, #3215), or, for an untyped signal, a literal `undefined` /
|
|
25
|
+
* `null` initial value.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isNullableSignal(signal: SignalInfo): boolean;
|
|
28
|
+
/** Getter names of the component's signals whose SSR value can be nullish. */
|
|
29
|
+
export declare function collectNullableSignalGetters(ir: ComponentIR): Set<string>;
|
|
30
|
+
/**
|
|
31
|
+
* The getter an attribute value reads when the whole value is a bare,
|
|
32
|
+
* zero-argument getter call (`s()`); `null` for any other shape. A member
|
|
33
|
+
* read, a ternary or a template literal around the call is not matched:
|
|
34
|
+
* the attribute's presence then depends on more than the signal.
|
|
35
|
+
*/
|
|
36
|
+
export declare function bareGetterCallName(parsed: ParsedExpr | undefined): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* The signal getter whose nil check should guard this attribute, or `null`
|
|
39
|
+
* when the attribute is not a bare read of a nullable signal. `nullable` is
|
|
40
|
+
* the set `collectNullableSignalGetters` built for the component.
|
|
41
|
+
*/
|
|
42
|
+
export declare function nullableSignalAttrGetter(parsed: ParsedExpr | undefined, nullable: ReadonlySet<string>): string | null;
|
|
43
|
+
/**
|
|
44
|
+
* What `attrValueMayBeNullish` needs to know about the component: its
|
|
45
|
+
* nullable signal getters and its memos by name.
|
|
46
|
+
*/
|
|
47
|
+
export interface NullishAttrContext {
|
|
48
|
+
readonly nullableSignals: ReadonlySet<string>;
|
|
49
|
+
readonly memos: ReadonlyMap<string, MemoInfo>;
|
|
50
|
+
}
|
|
51
|
+
export declare function collectNullishAttrContext(ir: ComponentIR): NullishAttrContext;
|
|
52
|
+
/**
|
|
53
|
+
* Whether an attribute value's SSR value can be `undefined` / `null`, so a
|
|
54
|
+
* DSL adapter must guard the attribute on a nil check to omit it the way
|
|
55
|
+
* Hono does (#3322) — the derived-value half of the bare-signal guard
|
|
56
|
+
* (`nullableSignalAttrGetter`, #3304). Matches a value that reaches a
|
|
57
|
+
* nullish value through:
|
|
58
|
+
*
|
|
59
|
+
* - a read of a nullable signal or of a memo whose type or body can be
|
|
60
|
+
* nullish (`label()` with `label = createMemo(() => s())`);
|
|
61
|
+
* - an optional member read (`user()?.name`), or a member read of a value
|
|
62
|
+
* that can itself be nullish;
|
|
63
|
+
* - a ternary branch, or an `??` / `||` / `&&` operand the result can be;
|
|
64
|
+
* - a literal `undefined` / `null`.
|
|
65
|
+
*
|
|
66
|
+
* Like the bare-signal guard it is presence-only: a non-nil value renders
|
|
67
|
+
* exactly as unguarded, so over-including a value never changes output for
|
|
68
|
+
* a present value (`''`, `0` and `false` still render). `isShadowed` names
|
|
69
|
+
* a getter a loop binding hides at the attribute site, which is then not
|
|
70
|
+
* the signal / memo; a memo's own body is read in its declaration scope.
|
|
71
|
+
*/
|
|
72
|
+
export declare function attrValueMayBeNullish(parsed: ParsedExpr | undefined, ctx: NullishAttrContext, isShadowed?: (name: string) => boolean): boolean;
|
|
73
|
+
//# sourceMappingURL=nullable-signal-attr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nullable-signal-attr.d.ts","sourceRoot":"","sources":["../src/nullable-signal-attr.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAY,MAAM,YAAY,CAAA;AAY7E,sDAAsD;AACtD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,OAAO,CAItE;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAG5D;AAED,8EAA8E;AAC9E,wBAAgB,4BAA4B,CAAC,EAAE,EAAE,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAGhF;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,UAAU,GAAG,SAAS,EAC9B,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,GAC5B,MAAM,GAAG,IAAI,CAGf;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;IAC7C,QAAQ,CAAC,KAAK,E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