@barefootjs/jsx 0.40.2 → 0.41.1
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/callback-method.d.ts +8 -1
- package/dist/adapters/callback-method.d.ts.map +1 -1
- package/dist/adapters/component-props.d.ts +14 -5
- package/dist/adapters/component-props.d.ts.map +1 -1
- package/dist/adapters/dsl-template-adapter.d.ts +3 -12
- package/dist/adapters/dsl-template-adapter.d.ts.map +1 -1
- package/dist/adapters/loop-row-type.d.ts +7 -0
- package/dist/adapters/loop-row-type.d.ts.map +1 -1
- package/dist/adapters/nil-reading.d.ts +15 -20
- package/dist/adapters/nil-reading.d.ts.map +1 -1
- package/dist/adapters/non-primitive-equality.d.ts +1 -1
- package/dist/adapters/number-value.d.ts +2 -1
- package/dist/adapters/number-value.d.ts.map +1 -1
- package/dist/adapters/parsed-expr-emitter.d.ts +11 -1
- package/dist/adapters/parsed-expr-emitter.d.ts.map +1 -1
- package/dist/adapters/primitive-plan.d.ts +40 -11
- package/dist/adapters/primitive-plan.d.ts.map +1 -1
- package/dist/adapters/prop-classes.d.ts +5 -0
- package/dist/adapters/prop-classes.d.ts.map +1 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +566 -367
- package/dist/ir-to-client-js/child-props-object.d.ts +43 -1
- package/dist/ir-to-client-js/child-props-object.d.ts.map +1 -1
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-inner-loop.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-loop-child-arm.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +2 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/phases/props-extraction.d.ts +3 -3
- package/dist/ir-to-client-js/plan/build-declaration-emit.d.ts.map +1 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +3 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/nullable-signal-attr.d.ts +4 -46
- package/dist/nullable-signal-attr.d.ts.map +1 -1
- package/dist/props-binding.d.ts +58 -13
- package/dist/props-binding.d.ts.map +1 -1
- package/dist/ssr-defaults.d.ts +39 -3
- package/dist/ssr-defaults.d.ts.map +1 -1
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +6 -6
- package/src/__tests__/body-destructured-prop-default-arrow.test.ts +2 -2
- package/src/__tests__/body-destructured-props-live.test.ts +5 -5
- package/src/__tests__/client-js-generation.test.ts +3 -3
- package/src/__tests__/destructure-default-reads-earlier-param.test.ts +7 -7
- package/src/__tests__/destructured-props-live.test.ts +1 -1
- package/src/__tests__/issue-3861-object-spread-child.test.ts +102 -0
- package/src/__tests__/memo-body-expr.test.ts +2 -2
- package/src/__tests__/nil-reading.test.ts +3 -2
- package/src/__tests__/nullable-signal-attr.test.ts +30 -103
- package/src/__tests__/primitive-plan.test.ts +90 -12
- package/src/__tests__/prop-default-undefined-only.test.ts +115 -0
- package/src/__tests__/prop-references.test.ts +2 -2
- package/src/__tests__/props-destructuring.test.ts +17 -0
- package/src/__tests__/prune-unused-prop-extractions.test.ts +3 -3
- package/src/__tests__/renamed-body-destructure-template.test.ts +7 -7
- package/src/__tests__/rewrite-destructured-props.test.ts +1 -1
- package/src/__tests__/ssr-defaults.test.ts +113 -25
- package/src/__tests__/static-const-child-prop.test.ts +85 -0
- package/src/__tests__/written-binding-substitution.test.ts +8 -8
- package/src/adapters/callback-method.ts +13 -5
- package/src/adapters/component-props.ts +20 -6
- package/src/adapters/dsl-template-adapter.ts +26 -28
- package/src/adapters/loop-row-type.ts +10 -0
- package/src/adapters/nil-reading.ts +23 -25
- package/src/adapters/non-primitive-equality.ts +1 -1
- package/src/adapters/number-value.ts +26 -2
- package/src/adapters/parsed-expr-emitter.ts +31 -2
- package/src/adapters/primitive-plan.ts +84 -15
- package/src/adapters/prop-classes.ts +16 -3
- package/src/analyzer.ts +27 -7
- package/src/index.ts +5 -12
- package/src/ir-to-client-js/child-props-object.ts +140 -6
- package/src/ir-to-client-js/collect-elements.ts +7 -14
- package/src/ir-to-client-js/control-flow/plan/build-inner-loop.ts +4 -2
- package/src/ir-to-client-js/control-flow/plan/build-loop-child-arm.ts +4 -2
- package/src/ir-to-client-js/html-template.ts +18 -9
- package/src/ir-to-client-js/imports.ts +1 -1
- package/src/ir-to-client-js/phases/props-extraction.ts +11 -7
- package/src/ir-to-client-js/plan/build-declaration-emit.ts +40 -7
- package/src/ir-to-client-js/prune-unused-prop-extractions.ts +58 -5
- package/src/ir-to-client-js/rewrite-destructured-props.ts +31 -1
- package/src/jsx-to-ir.ts +113 -60
- package/src/nullable-signal-attr.ts +11 -138
- package/src/props-binding.ts +84 -19
- package/src/ssr-defaults.ts +100 -11
- package/src/types.ts +11 -0
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts +0 -42
- package/dist/adapters/ambiguous-nil-arithmetic.d.ts.map +0 -1
- package/src/adapters/ambiguous-nil-arithmetic.ts +0 -103
package/dist/index.js
CHANGED
|
@@ -3923,6 +3923,7 @@ var RUNTIME_IMPORT_CANDIDATES = [
|
|
|
3923
3923
|
"createContext",
|
|
3924
3924
|
"useContext",
|
|
3925
3925
|
"forwardProps",
|
|
3926
|
+
"spreadChildProps",
|
|
3926
3927
|
"applyRestAttrs",
|
|
3927
3928
|
"splitProps",
|
|
3928
3929
|
"spreadAttrs",
|
|
@@ -5035,17 +5036,37 @@ function computePropsUsedAsConditions(ctx, propNames) {
|
|
|
5035
5036
|
// src/ir-to-client-js/prune-unused-prop-extractions.ts
|
|
5036
5037
|
import ts10 from "typescript";
|
|
5037
5038
|
function parsePropReadInitializer(init, objectName = PROPS_PARAM) {
|
|
5039
|
+
const defaulted = parseDefaultedPropRead(init, objectName);
|
|
5040
|
+
if (defaulted)
|
|
5041
|
+
return { ...defaulted, coalescesNull: false };
|
|
5038
5042
|
let core = init;
|
|
5039
5043
|
let fallback = null;
|
|
5040
5044
|
if (ts10.isBinaryExpression(core) && core.operatorToken.kind === ts10.SyntaxKind.QuestionQuestionToken) {
|
|
5041
5045
|
fallback = core.right;
|
|
5042
5046
|
core = core.left;
|
|
5043
5047
|
}
|
|
5044
|
-
|
|
5048
|
+
const key = propReadKey(core, objectName);
|
|
5049
|
+
return key === null ? null : { key, fallback, coalescesNull: fallback !== null };
|
|
5050
|
+
}
|
|
5051
|
+
function propReadKey(expr, objectName) {
|
|
5052
|
+
if (!ts10.isPropertyAccessExpression(expr))
|
|
5053
|
+
return null;
|
|
5054
|
+
if (!ts10.isIdentifier(expr.expression) || expr.expression.text !== objectName)
|
|
5055
|
+
return null;
|
|
5056
|
+
return expr.name.text;
|
|
5057
|
+
}
|
|
5058
|
+
function parseDefaultedPropRead(init, objectName) {
|
|
5059
|
+
if (!ts10.isConditionalExpression(init))
|
|
5045
5060
|
return null;
|
|
5046
|
-
|
|
5061
|
+
const test = init.condition;
|
|
5062
|
+
if (!ts10.isBinaryExpression(test) || test.operatorToken.kind !== ts10.SyntaxKind.EqualsEqualsEqualsToken)
|
|
5047
5063
|
return null;
|
|
5048
|
-
|
|
5064
|
+
if (!ts10.isIdentifier(test.right) || test.right.text !== "undefined")
|
|
5065
|
+
return null;
|
|
5066
|
+
const key = propReadKey(test.left, objectName);
|
|
5067
|
+
if (key === null || propReadKey(init.whenFalse, objectName) !== key)
|
|
5068
|
+
return null;
|
|
5069
|
+
return { key, fallback: init.whenTrue };
|
|
5049
5070
|
}
|
|
5050
5071
|
function propExtractionName(stmt) {
|
|
5051
5072
|
if (!ts10.isVariableStatement(stmt))
|
|
@@ -5059,8 +5080,28 @@ function propExtractionName(stmt) {
|
|
|
5059
5080
|
const parsed = parsePropReadInitializer(decl.initializer);
|
|
5060
5081
|
if (parsed === null || parsed.key !== decl.name.text && parsed.key !== "children")
|
|
5061
5082
|
return null;
|
|
5083
|
+
if (parsed.fallback !== null && mayHaveSideEffect(parsed.fallback))
|
|
5084
|
+
return null;
|
|
5062
5085
|
return decl.name.text;
|
|
5063
5086
|
}
|
|
5087
|
+
function isAssignmentOperator(kind) {
|
|
5088
|
+
return kind >= ts10.SyntaxKind.FirstAssignment && kind <= ts10.SyntaxKind.LastAssignment;
|
|
5089
|
+
}
|
|
5090
|
+
function mayHaveSideEffect(expr) {
|
|
5091
|
+
if (ts10.isArrowFunction(expr) || ts10.isFunctionExpression(expr))
|
|
5092
|
+
return false;
|
|
5093
|
+
if (ts10.isBinaryExpression(expr) && isAssignmentOperator(expr.operatorToken.kind))
|
|
5094
|
+
return true;
|
|
5095
|
+
if (ts10.isPrefixUnaryExpression(expr) || ts10.isPostfixUnaryExpression(expr)) {
|
|
5096
|
+
const op = expr.operator;
|
|
5097
|
+
if (op === ts10.SyntaxKind.PlusPlusToken || op === ts10.SyntaxKind.MinusMinusToken)
|
|
5098
|
+
return true;
|
|
5099
|
+
}
|
|
5100
|
+
if (ts10.isCallExpression(expr) || ts10.isNewExpression(expr) || ts10.isDeleteExpression(expr) || ts10.isAwaitExpression(expr) || ts10.isYieldExpression(expr) || ts10.isTaggedTemplateExpression(expr)) {
|
|
5101
|
+
return true;
|
|
5102
|
+
}
|
|
5103
|
+
return ts10.forEachChild(expr, (child) => mayHaveSideEffect(child) ? true : undefined) ?? false;
|
|
5104
|
+
}
|
|
5064
5105
|
function pruneUnusedPropExtractions(code) {
|
|
5065
5106
|
for (let round = 0;round < 10; round++) {
|
|
5066
5107
|
const referenced = collectValueReferencedNames(code);
|
|
@@ -5258,25 +5299,47 @@ function propReadBase(p) {
|
|
|
5258
5299
|
function coalesceDefaultText(defaultValue, defaultContainsArrow) {
|
|
5259
5300
|
return defaultContainsArrow ? `(${defaultValue})` : defaultValue;
|
|
5260
5301
|
}
|
|
5261
|
-
function propReadFallback(p, usage, usedAsCondition) {
|
|
5262
|
-
const defaultText = propDefaultText(p);
|
|
5302
|
+
function propReadFallback(p, usage, usedAsCondition, retained) {
|
|
5303
|
+
const defaultText = propDefaultText(p, retained);
|
|
5263
5304
|
if (defaultText)
|
|
5264
|
-
return coalesceDefaultText(defaultText, p.defaultContainsArrow);
|
|
5305
|
+
return { kind: p.coalescesNull ? "guard" : "default", text: coalesceDefaultText(defaultText, p.defaultContainsArrow) };
|
|
5265
5306
|
if (usage?.usedAsLoopArray)
|
|
5266
|
-
return "[]";
|
|
5307
|
+
return { kind: "guard", text: "[]" };
|
|
5267
5308
|
if (propHasPropertyAccess(usage) && !usedAsCondition)
|
|
5268
|
-
return "{}";
|
|
5309
|
+
return { kind: "guard", text: "{}" };
|
|
5269
5310
|
return null;
|
|
5270
5311
|
}
|
|
5271
|
-
function
|
|
5312
|
+
function composePropRead(base, fallback) {
|
|
5313
|
+
if (fallback === null)
|
|
5314
|
+
return base;
|
|
5315
|
+
return fallback.kind === "default" ? `${base} === undefined ? ${fallback.text} : ${base}` : `${base} ?? ${fallback.text}`;
|
|
5316
|
+
}
|
|
5317
|
+
function propDefaultText(p, retained = EMPTY_SET) {
|
|
5272
5318
|
if (!p.defaultParts)
|
|
5273
5319
|
return p.defaultValue;
|
|
5274
|
-
return p.defaultParts.map((part) =>
|
|
5320
|
+
return p.defaultParts.map((part) => {
|
|
5321
|
+
if (part.kind === "text")
|
|
5322
|
+
return part.text;
|
|
5323
|
+
return retained.has(part.param.name) ? part.param.name : livePropReadExpr(part.param, undefined, false, retained);
|
|
5324
|
+
}).join("");
|
|
5275
5325
|
}
|
|
5276
|
-
function
|
|
5326
|
+
function retainedPropLocals(b) {
|
|
5327
|
+
const names = new Set;
|
|
5328
|
+
if (b.propsObjectName === null) {
|
|
5329
|
+
for (const p of b.propsParams)
|
|
5330
|
+
if (!p.isRest && !keepsDeclaredValue(p))
|
|
5331
|
+
names.add(p.name);
|
|
5332
|
+
}
|
|
5333
|
+
for (const c of b.localConstants) {
|
|
5334
|
+
if (c.propsDestructure && !c.isModule && !keepsDeclaredValue(c))
|
|
5335
|
+
names.add(c.name);
|
|
5336
|
+
}
|
|
5337
|
+
return names;
|
|
5338
|
+
}
|
|
5339
|
+
function livePropReadExpr(p, usage, usedAsCondition, retained) {
|
|
5277
5340
|
const base = propReadBase(p);
|
|
5278
|
-
const fallback = propReadFallback(p, usage, usedAsCondition);
|
|
5279
|
-
return fallback === null ? base : `(${base
|
|
5341
|
+
const fallback = propReadFallback(p, usage, usedAsCondition, retained);
|
|
5342
|
+
return fallback === null ? base : `(${composePropRead(base, fallback)})`;
|
|
5280
5343
|
}
|
|
5281
5344
|
function resolveAliasOrigin(constantValues, name, terminal) {
|
|
5282
5345
|
const visited = new Set;
|
|
@@ -5371,7 +5434,7 @@ function signalSecondBinding(signal) {
|
|
|
5371
5434
|
|
|
5372
5435
|
// src/assignment-target.ts
|
|
5373
5436
|
import ts12 from "typescript";
|
|
5374
|
-
function
|
|
5437
|
+
function isAssignmentOperator2(kind) {
|
|
5375
5438
|
return kind >= ts12.SyntaxKind.FirstAssignment && kind <= ts12.SyntaxKind.LastAssignment;
|
|
5376
5439
|
}
|
|
5377
5440
|
function isTransparentWrapper(n) {
|
|
@@ -5401,7 +5464,7 @@ function isAssignmentTargetIdentifier(id) {
|
|
|
5401
5464
|
return parent.operator === ts12.SyntaxKind.PlusPlusToken || parent.operator === ts12.SyntaxKind.MinusMinusToken;
|
|
5402
5465
|
}
|
|
5403
5466
|
if (ts12.isBinaryExpression(parent)) {
|
|
5404
|
-
return parent.left === node &&
|
|
5467
|
+
return parent.left === node && isAssignmentOperator2(parent.operatorToken.kind);
|
|
5405
5468
|
}
|
|
5406
5469
|
if ((ts12.isForOfStatement(parent) || ts12.isForInStatement(parent)) && parent.initializer === node)
|
|
5407
5470
|
return true;
|
|
@@ -5831,6 +5894,130 @@ function isHydrationPayloadPropName(name) {
|
|
|
5831
5894
|
return !isEventHandlerName(name) && !name.startsWith("__");
|
|
5832
5895
|
}
|
|
5833
5896
|
|
|
5897
|
+
// src/ir-to-client-js/child-props-object.ts
|
|
5898
|
+
function isSpreadPropName(name) {
|
|
5899
|
+
return name.startsWith("...");
|
|
5900
|
+
}
|
|
5901
|
+
function lastPropsObjectSpreadIndex(props) {
|
|
5902
|
+
let at = -1;
|
|
5903
|
+
props.forEach((p, index) => {
|
|
5904
|
+
if (p.value.kind === "spread" && p.value.propsObject === true)
|
|
5905
|
+
at = index;
|
|
5906
|
+
});
|
|
5907
|
+
return at;
|
|
5908
|
+
}
|
|
5909
|
+
function callerFirstPropExpr(name, expr) {
|
|
5910
|
+
const key = codeSafeStringLiteral(name);
|
|
5911
|
+
return `(${key} in ${PROPS_PARAM} ? ${PROPS_PARAM}[${key}] : ${expr})`;
|
|
5912
|
+
}
|
|
5913
|
+
function isObjectSpreadProp(prop) {
|
|
5914
|
+
return isSpreadPropName(prop.name) && prop.value.kind === "spread" && prop.value.callerBag === undefined;
|
|
5915
|
+
}
|
|
5916
|
+
function codeSafeStringArray(values) {
|
|
5917
|
+
return `[${values.map(codeSafeStringLiteral).join(",")}]`;
|
|
5918
|
+
}
|
|
5919
|
+
function objectLiteral(entries) {
|
|
5920
|
+
return entries.length > 0 ? `{ ${entries.join(", ")} }` : "{}";
|
|
5921
|
+
}
|
|
5922
|
+
function lastObjectSpreadIndex(props) {
|
|
5923
|
+
let at = -1;
|
|
5924
|
+
props.forEach((p, index) => {
|
|
5925
|
+
if (isObjectSpreadProp(p))
|
|
5926
|
+
at = index;
|
|
5927
|
+
});
|
|
5928
|
+
return at;
|
|
5929
|
+
}
|
|
5930
|
+
function mergedExplicitPropExpr(props, index, expr, spreadOf) {
|
|
5931
|
+
const name = props[index].name;
|
|
5932
|
+
const key = codeSafeStringLiteral(name);
|
|
5933
|
+
let merged = expr;
|
|
5934
|
+
let last = null;
|
|
5935
|
+
for (let at = index + 1;at < props.length; at++) {
|
|
5936
|
+
const prop = props[at];
|
|
5937
|
+
if (prop.value.kind === "spread" && prop.value.propsObject === true) {
|
|
5938
|
+
if (last !== "props")
|
|
5939
|
+
merged = callerFirstPropExpr(name, merged);
|
|
5940
|
+
last = "props";
|
|
5941
|
+
} else if (isObjectSpreadProp(prop)) {
|
|
5942
|
+
merged = `((__s) => __s != null && ${key} in Object(__s) ? Object(__s)[${key}] : ${merged})(${spreadOf(prop)})`;
|
|
5943
|
+
last = "object";
|
|
5944
|
+
}
|
|
5945
|
+
}
|
|
5946
|
+
return merged;
|
|
5947
|
+
}
|
|
5948
|
+
function childPropsObjectExpr(props, valueOf, options = {}) {
|
|
5949
|
+
if (lastObjectSpreadIndex(props) >= 0)
|
|
5950
|
+
return spreadPartsExpr(props, valueOf, options);
|
|
5951
|
+
const spreadAt = lastPropsObjectSpreadIndex(props);
|
|
5952
|
+
const entries = [];
|
|
5953
|
+
const explicitNames = [];
|
|
5954
|
+
props.forEach((prop, index) => {
|
|
5955
|
+
if (isSpreadPropName(prop.name))
|
|
5956
|
+
return;
|
|
5957
|
+
const value = valueOf(prop);
|
|
5958
|
+
if (!value)
|
|
5959
|
+
return;
|
|
5960
|
+
explicitNames.push(prop.name);
|
|
5961
|
+
const key = quotePropName(prop.name);
|
|
5962
|
+
if (index < spreadAt) {
|
|
5963
|
+
entries.push(`get ${key}() { return ${callerFirstPropExpr(prop.name, value.expr)} }`);
|
|
5964
|
+
} else {
|
|
5965
|
+
entries.push(explicitEntry(key, value));
|
|
5966
|
+
}
|
|
5967
|
+
});
|
|
5968
|
+
entries.push(...options.trailing ?? []);
|
|
5969
|
+
const object = objectLiteral(entries);
|
|
5970
|
+
if (spreadAt < 0 && !options.forwardCaller)
|
|
5971
|
+
return object;
|
|
5972
|
+
return `forwardProps(${PROPS_PARAM}, ${object}, ${codeSafeStringArray(explicitNames)})`;
|
|
5973
|
+
}
|
|
5974
|
+
function explicitEntry(key, value) {
|
|
5975
|
+
return value.getter ? `get ${key}() { return ${value.expr} }` : `${key}: ${value.expr}`;
|
|
5976
|
+
}
|
|
5977
|
+
function spreadPartsExpr(props, valueOf, options) {
|
|
5978
|
+
const parts = [];
|
|
5979
|
+
let entries = [];
|
|
5980
|
+
const explicitNames = [];
|
|
5981
|
+
let mergesCaller = false;
|
|
5982
|
+
const flush = () => {
|
|
5983
|
+
if (entries.length > 0)
|
|
5984
|
+
parts.push(objectLiteral(entries));
|
|
5985
|
+
entries = [];
|
|
5986
|
+
};
|
|
5987
|
+
for (const prop of props) {
|
|
5988
|
+
if (prop.value.kind === "spread" && prop.value.propsObject === true) {
|
|
5989
|
+
flush();
|
|
5990
|
+
parts.push(`() => ${PROPS_PARAM}`);
|
|
5991
|
+
mergesCaller = true;
|
|
5992
|
+
continue;
|
|
5993
|
+
}
|
|
5994
|
+
if (prop.value.kind === "spread" && prop.value.callerBag === "rest" && options.restBag !== undefined) {
|
|
5995
|
+
flush();
|
|
5996
|
+
parts.push(options.restBag);
|
|
5997
|
+
mergesCaller = true;
|
|
5998
|
+
continue;
|
|
5999
|
+
}
|
|
6000
|
+
if (isSpreadPropName(prop.name) && !isObjectSpreadProp(prop))
|
|
6001
|
+
continue;
|
|
6002
|
+
const value = valueOf(prop);
|
|
6003
|
+
if (!value)
|
|
6004
|
+
continue;
|
|
6005
|
+
if (isObjectSpreadProp(prop)) {
|
|
6006
|
+
flush();
|
|
6007
|
+
parts.push(`() => (${value.expr})`);
|
|
6008
|
+
continue;
|
|
6009
|
+
}
|
|
6010
|
+
explicitNames.push(prop.name);
|
|
6011
|
+
entries.push(explicitEntry(quotePropName(prop.name), value));
|
|
6012
|
+
}
|
|
6013
|
+
entries.push(...options.trailing ?? []);
|
|
6014
|
+
flush();
|
|
6015
|
+
const merged = `spreadChildProps(${parts.join(", ")})`;
|
|
6016
|
+
if (!options.forwardCaller || mergesCaller)
|
|
6017
|
+
return merged;
|
|
6018
|
+
return `forwardProps(${PROPS_PARAM}, ${merged}, ${codeSafeStringArray(explicitNames)})`;
|
|
6019
|
+
}
|
|
6020
|
+
|
|
5834
6021
|
// src/ir-to-client-js/html-template.ts
|
|
5835
6022
|
function escapeStaticTemplateHtml(text) {
|
|
5836
6023
|
return escapeHtml(text).replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
@@ -6043,8 +6230,9 @@ function renderTemplateAttrPart(attr, attrName, wrap, restSpreadNames) {
|
|
|
6043
6230
|
function keepsTemplateComponentProp(p) {
|
|
6044
6231
|
if (p.name === "key")
|
|
6045
6232
|
return false;
|
|
6046
|
-
if (p.name === "..." || p.name.startsWith("..."))
|
|
6047
|
-
return p.value.kind === "spread" && p.value.propsObject === true;
|
|
6233
|
+
if (p.name === "..." || p.name.startsWith("...")) {
|
|
6234
|
+
return p.value.kind === "spread" && (p.value.propsObject === true || isObjectSpreadProp(p));
|
|
6235
|
+
}
|
|
6048
6236
|
return true;
|
|
6049
6237
|
}
|
|
6050
6238
|
function templatePropEntry(p, valueExpr) {
|
|
@@ -7045,7 +7233,9 @@ function computeDeferredChildSlots(node, ctx, inlinableConstants, unsafeLocalNam
|
|
|
7045
7233
|
}
|
|
7046
7234
|
if (n.slotId) {
|
|
7047
7235
|
const dropped = n.props.some((p) => {
|
|
7048
|
-
if (p.name === "
|
|
7236
|
+
if (p.name === "key")
|
|
7237
|
+
return false;
|
|
7238
|
+
if ((p.name === "..." || p.name.startsWith("...")) && !isObjectSpreadProp(p))
|
|
7049
7239
|
return false;
|
|
7050
7240
|
if (p.name === "ref")
|
|
7051
7241
|
return false;
|
|
@@ -9125,17 +9315,20 @@ function deriveStashFromDefaults(defaults, props) {
|
|
|
9125
9315
|
continue;
|
|
9126
9316
|
}
|
|
9127
9317
|
if (d.isRestProps) {
|
|
9128
|
-
extra[name] = name in props ? props[name] : d
|
|
9318
|
+
extra[name] = name in props ? props[name] : fallbackOf(d);
|
|
9129
9319
|
continue;
|
|
9130
9320
|
}
|
|
9131
9321
|
if (d.propName !== undefined && d.propName in props && props[d.propName] != null) {
|
|
9132
9322
|
extra[name] = props[d.propName];
|
|
9133
9323
|
} else {
|
|
9134
|
-
extra[name] = d
|
|
9324
|
+
extra[name] = fallbackOf(d);
|
|
9135
9325
|
}
|
|
9136
9326
|
}
|
|
9137
9327
|
return extra;
|
|
9138
9328
|
}
|
|
9329
|
+
function fallbackOf(d) {
|
|
9330
|
+
return "value" in d ? decodeUndefinedMembers(d.value) : null;
|
|
9331
|
+
}
|
|
9139
9332
|
var UNRESOLVED = Symbol("unresolved");
|
|
9140
9333
|
var NO_RETURN = Symbol("no-return");
|
|
9141
9334
|
function addPropSsrDefaults(metadata, propsLike, out) {
|
|
@@ -9150,7 +9343,7 @@ function addPropSsrDefaults(metadata, propsLike, out) {
|
|
|
9150
9343
|
const value = tryStaticEval(p.defaultValue, { bindings: {}, propsLike });
|
|
9151
9344
|
out[p.name] = { propName: callerPropName, value: resultToJsonable(value) };
|
|
9152
9345
|
} else {
|
|
9153
|
-
out[p.name] = { propName: callerPropName
|
|
9346
|
+
out[p.name] = { propName: callerPropName };
|
|
9154
9347
|
}
|
|
9155
9348
|
}
|
|
9156
9349
|
}
|
|
@@ -9246,7 +9439,40 @@ function extractSsrDefaults(metadata) {
|
|
|
9246
9439
|
out[name] = { propName: name, value: null };
|
|
9247
9440
|
}
|
|
9248
9441
|
}
|
|
9249
|
-
return Object.keys(out).length === 0 ? undefined : out;
|
|
9442
|
+
return Object.keys(out).length === 0 ? undefined : encodeSeedValues(out);
|
|
9443
|
+
}
|
|
9444
|
+
function encodeSeedValues(out) {
|
|
9445
|
+
for (const d of new Set(Object.values(out))) {
|
|
9446
|
+
if ("value" in d)
|
|
9447
|
+
d.value = encodeUndefinedMembers(d.value);
|
|
9448
|
+
}
|
|
9449
|
+
return out;
|
|
9450
|
+
}
|
|
9451
|
+
var UNDEFINED_SENTINEL = Object.freeze({ $undef: true });
|
|
9452
|
+
function encodeUndefinedMembers(v) {
|
|
9453
|
+
const member = (x) => x === undefined ? { ...UNDEFINED_SENTINEL } : encodeUndefinedMembers(x);
|
|
9454
|
+
if (Array.isArray(v))
|
|
9455
|
+
return v.map(member);
|
|
9456
|
+
if (v !== null && typeof v === "object") {
|
|
9457
|
+
return Object.fromEntries(Object.entries(v).map(([k, x]) => [k.startsWith("$") ? `$${k}` : k, member(x)]));
|
|
9458
|
+
}
|
|
9459
|
+
return v;
|
|
9460
|
+
}
|
|
9461
|
+
function decodeUndefinedMembers(v) {
|
|
9462
|
+
if (isUndefinedSentinel(v))
|
|
9463
|
+
return;
|
|
9464
|
+
if (Array.isArray(v))
|
|
9465
|
+
return v.map(decodeUndefinedMembers);
|
|
9466
|
+
if (v !== null && typeof v === "object") {
|
|
9467
|
+
return Object.fromEntries(Object.entries(v).map(([k, x]) => [k.startsWith("$$") ? k.slice(1) : k, decodeUndefinedMembers(x)]));
|
|
9468
|
+
}
|
|
9469
|
+
return v;
|
|
9470
|
+
}
|
|
9471
|
+
function isUndefinedSentinel(v) {
|
|
9472
|
+
if (v === null || typeof v !== "object" || Array.isArray(v))
|
|
9473
|
+
return false;
|
|
9474
|
+
const keys = Object.keys(v);
|
|
9475
|
+
return keys.length === 1 && keys[0] === "$undef" && v.$undef === true;
|
|
9250
9476
|
}
|
|
9251
9477
|
function localConstValuesByName(metadata) {
|
|
9252
9478
|
const out = new Map;
|
|
@@ -9415,7 +9641,7 @@ function evalNode(node, ctx) {
|
|
|
9415
9641
|
const v = evalNode(prop.initializer, ctx);
|
|
9416
9642
|
if (v === UNRESOLVED)
|
|
9417
9643
|
return UNRESOLVED;
|
|
9418
|
-
obj[key] = v
|
|
9644
|
+
obj[key] = v;
|
|
9419
9645
|
}
|
|
9420
9646
|
return obj;
|
|
9421
9647
|
}
|
|
@@ -9427,7 +9653,7 @@ function evalNode(node, ctx) {
|
|
|
9427
9653
|
const v = evalNode(elem, ctx);
|
|
9428
9654
|
if (v === UNRESOLVED)
|
|
9429
9655
|
return UNRESOLVED;
|
|
9430
|
-
arr.push(v
|
|
9656
|
+
arr.push(v);
|
|
9431
9657
|
}
|
|
9432
9658
|
return arr;
|
|
9433
9659
|
}
|
|
@@ -9474,7 +9700,7 @@ function evalNode(node, ctx) {
|
|
|
9474
9700
|
const v = evalNode(arrow.body, { ...ctx, bindings: localBindings });
|
|
9475
9701
|
if (v === UNRESOLVED)
|
|
9476
9702
|
return UNRESOLVED;
|
|
9477
|
-
mapped.push(v
|
|
9703
|
+
mapped.push(v);
|
|
9478
9704
|
}
|
|
9479
9705
|
return mapped;
|
|
9480
9706
|
}
|
|
@@ -11028,7 +11254,7 @@ function extractAssignedIdentifiersFromNode(node) {
|
|
|
11028
11254
|
if (ts23.isArrowFunction(n) || ts23.isFunctionExpression(n) || ts23.isFunctionDeclaration(n) || ts23.isMethodDeclaration(n) || ts23.isGetAccessorDeclaration(n) || ts23.isSetAccessorDeclaration(n) || ts23.isConstructorDeclaration(n)) {
|
|
11029
11255
|
return;
|
|
11030
11256
|
}
|
|
11031
|
-
if (ts23.isBinaryExpression(n) &&
|
|
11257
|
+
if (ts23.isBinaryExpression(n) && isAssignmentOperator3(n.operatorToken.kind)) {
|
|
11032
11258
|
addFromTarget(n.left);
|
|
11033
11259
|
}
|
|
11034
11260
|
if (ts23.isPrefixUnaryExpression(n) || ts23.isPostfixUnaryExpression(n)) {
|
|
@@ -11089,7 +11315,7 @@ function extractMutatedIdentifiersFromNode(node) {
|
|
|
11089
11315
|
if (ts23.isArrowFunction(n) || ts23.isFunctionExpression(n) || ts23.isFunctionDeclaration(n) || ts23.isMethodDeclaration(n) || ts23.isGetAccessorDeclaration(n) || ts23.isSetAccessorDeclaration(n) || ts23.isConstructorDeclaration(n)) {
|
|
11090
11316
|
return;
|
|
11091
11317
|
}
|
|
11092
|
-
if (ts23.isBinaryExpression(n) &&
|
|
11318
|
+
if (ts23.isBinaryExpression(n) && isAssignmentOperator3(n.operatorToken.kind)) {
|
|
11093
11319
|
if (ts23.isPropertyAccessExpression(n.left) || ts23.isElementAccessExpression(n.left)) {
|
|
11094
11320
|
const root = rootIdentifierOf(n.left);
|
|
11095
11321
|
if (root)
|
|
@@ -11122,7 +11348,7 @@ function extractMutatedIdentifiersFromNode(node) {
|
|
|
11122
11348
|
visit3(node);
|
|
11123
11349
|
return ids;
|
|
11124
11350
|
}
|
|
11125
|
-
function
|
|
11351
|
+
function isAssignmentOperator3(kind) {
|
|
11126
11352
|
return kind === ts23.SyntaxKind.EqualsToken || kind === ts23.SyntaxKind.PlusEqualsToken || kind === ts23.SyntaxKind.MinusEqualsToken || kind === ts23.SyntaxKind.AsteriskEqualsToken || kind === ts23.SyntaxKind.SlashEqualsToken || kind === ts23.SyntaxKind.PercentEqualsToken || kind === ts23.SyntaxKind.AsteriskAsteriskEqualsToken || kind === ts23.SyntaxKind.AmpersandEqualsToken || kind === ts23.SyntaxKind.BarEqualsToken || kind === ts23.SyntaxKind.CaretEqualsToken || kind === ts23.SyntaxKind.LessThanLessThanEqualsToken || kind === ts23.SyntaxKind.GreaterThanGreaterThanEqualsToken || kind === ts23.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken || kind === ts23.SyntaxKind.AmpersandAmpersandEqualsToken || kind === ts23.SyntaxKind.BarBarEqualsToken || kind === ts23.SyntaxKind.QuestionQuestionEqualsToken;
|
|
11127
11353
|
}
|
|
11128
11354
|
function collectLocalDeclarations(root) {
|
|
@@ -12457,8 +12683,8 @@ function collectKeysFromMembers(members, ctx) {
|
|
|
12457
12683
|
}
|
|
12458
12684
|
return keys;
|
|
12459
12685
|
}
|
|
12460
|
-
function isResolvableMemberType(info, localObjectMembers, visiting = new Set) {
|
|
12461
|
-
const recurse = (t) => isResolvableMemberType(t, localObjectMembers, visiting);
|
|
12686
|
+
function isResolvableMemberType(info, localObjectMembers, visiting = new Set, nested = false) {
|
|
12687
|
+
const recurse = (t) => isResolvableMemberType(t, localObjectMembers, visiting, true);
|
|
12462
12688
|
switch (info.kind) {
|
|
12463
12689
|
case "primitive":
|
|
12464
12690
|
return info.primitive === "string" || info.primitive === "number" || info.primitive === "boolean";
|
|
@@ -12471,16 +12697,24 @@ function isResolvableMemberType(info, localObjectMembers, visiting = new Set) {
|
|
|
12471
12697
|
if (!members)
|
|
12472
12698
|
return false;
|
|
12473
12699
|
const inner = new Set(visiting).add(info.raw);
|
|
12474
|
-
return members.every((t) => isResolvableMemberType(t, localObjectMembers, inner));
|
|
12700
|
+
return members.every((t) => isResolvableMemberType(t, localObjectMembers, inner, true));
|
|
12475
12701
|
}
|
|
12476
12702
|
case "array":
|
|
12477
12703
|
return !!info.elementType && recurse(info.elementType);
|
|
12478
12704
|
case "object":
|
|
12479
12705
|
return info.properties !== undefined && info.properties.every((prop) => recurse(prop.type));
|
|
12706
|
+
case "union":
|
|
12707
|
+
return nested && isNilUnionOfResolvable(info, recurse);
|
|
12480
12708
|
default:
|
|
12481
12709
|
return false;
|
|
12482
12710
|
}
|
|
12483
12711
|
}
|
|
12712
|
+
function isNilUnionOfResolvable(info, resolves) {
|
|
12713
|
+
const isNil = (t) => t.kind === "primitive" && (t.primitive === "null" || t.primitive === "undefined");
|
|
12714
|
+
const members = info.unionTypes ?? [];
|
|
12715
|
+
const present = members.filter((t) => !isNil(t));
|
|
12716
|
+
return present.length > 0 && present.length < members.length && present.every(resolves);
|
|
12717
|
+
}
|
|
12484
12718
|
function localObjectMemberTypesFor(ctx) {
|
|
12485
12719
|
const cache = new Map;
|
|
12486
12720
|
const lookup = (name) => {
|
|
@@ -14362,6 +14596,108 @@ function nullishChainParts(parsed) {
|
|
|
14362
14596
|
return fallbackChainParts(parsed, "??");
|
|
14363
14597
|
}
|
|
14364
14598
|
|
|
14599
|
+
// src/static-literal.ts
|
|
14600
|
+
function evaluateStaticLiteral(expr, bindings) {
|
|
14601
|
+
switch (expr.kind) {
|
|
14602
|
+
case "literal":
|
|
14603
|
+
return { value: expr.value };
|
|
14604
|
+
case "template-literal": {
|
|
14605
|
+
let out = "";
|
|
14606
|
+
for (const part of expr.parts) {
|
|
14607
|
+
if (part.type === "string") {
|
|
14608
|
+
out += part.value;
|
|
14609
|
+
continue;
|
|
14610
|
+
}
|
|
14611
|
+
const resolved = evaluateStaticLiteral(part.expr, bindings);
|
|
14612
|
+
if (!resolved)
|
|
14613
|
+
return null;
|
|
14614
|
+
out += String(resolved.value);
|
|
14615
|
+
}
|
|
14616
|
+
return { value: out };
|
|
14617
|
+
}
|
|
14618
|
+
case "array-literal": {
|
|
14619
|
+
const values = [];
|
|
14620
|
+
for (const element of expr.elements) {
|
|
14621
|
+
const resolved = evaluateStaticLiteral(element, bindings);
|
|
14622
|
+
if (!resolved)
|
|
14623
|
+
return null;
|
|
14624
|
+
values.push(resolved.value);
|
|
14625
|
+
}
|
|
14626
|
+
return { value: values };
|
|
14627
|
+
}
|
|
14628
|
+
case "object-literal": {
|
|
14629
|
+
const out = {};
|
|
14630
|
+
for (const prop of expr.properties) {
|
|
14631
|
+
if (prop.kind === "spread") {
|
|
14632
|
+
const resolved2 = evaluateStaticLiteral(prop.expr, bindings);
|
|
14633
|
+
if (!resolved2)
|
|
14634
|
+
return null;
|
|
14635
|
+
if (resolved2.value === null || resolved2.value === undefined)
|
|
14636
|
+
continue;
|
|
14637
|
+
if (typeof resolved2.value !== "object" || Array.isArray(resolved2.value))
|
|
14638
|
+
return null;
|
|
14639
|
+
Object.assign(out, resolved2.value);
|
|
14640
|
+
continue;
|
|
14641
|
+
}
|
|
14642
|
+
const resolved = evaluateStaticLiteral(prop.value, bindings);
|
|
14643
|
+
if (!resolved)
|
|
14644
|
+
return null;
|
|
14645
|
+
out[prop.key] = resolved.value;
|
|
14646
|
+
}
|
|
14647
|
+
return { value: out };
|
|
14648
|
+
}
|
|
14649
|
+
case "unary": {
|
|
14650
|
+
const resolved = evaluateStaticLiteral(expr.argument, bindings);
|
|
14651
|
+
if (!resolved)
|
|
14652
|
+
return null;
|
|
14653
|
+
if (expr.op === "-")
|
|
14654
|
+
return typeof resolved.value === "number" ? { value: -resolved.value } : null;
|
|
14655
|
+
if (expr.op === "+")
|
|
14656
|
+
return typeof resolved.value === "number" ? { value: +resolved.value } : null;
|
|
14657
|
+
if (expr.op === "!")
|
|
14658
|
+
return { value: !resolved.value };
|
|
14659
|
+
return null;
|
|
14660
|
+
}
|
|
14661
|
+
case "identifier":
|
|
14662
|
+
return bindings?.has(expr.name) ? { value: bindings.get(expr.name) } : null;
|
|
14663
|
+
case "member": {
|
|
14664
|
+
const base = evaluateStaticLiteral(expr.object, bindings);
|
|
14665
|
+
if (!base || base.value === null || typeof base.value !== "object")
|
|
14666
|
+
return null;
|
|
14667
|
+
return { value: base.value[expr.property] };
|
|
14668
|
+
}
|
|
14669
|
+
case "index-access": {
|
|
14670
|
+
const base = evaluateStaticLiteral(expr.object, bindings);
|
|
14671
|
+
const index = evaluateStaticLiteral(expr.index, bindings);
|
|
14672
|
+
if (!base || !index || !Array.isArray(base.value) || typeof index.value !== "number")
|
|
14673
|
+
return null;
|
|
14674
|
+
return { value: base.value[index.value] };
|
|
14675
|
+
}
|
|
14676
|
+
default:
|
|
14677
|
+
return null;
|
|
14678
|
+
}
|
|
14679
|
+
}
|
|
14680
|
+
function isFullyStaticLiteral(expr) {
|
|
14681
|
+
return evaluateStaticLiteral(expr) !== null;
|
|
14682
|
+
}
|
|
14683
|
+
function resolveStaticLoopSource(arrayParsed, localConstants, opts) {
|
|
14684
|
+
if (!arrayParsed)
|
|
14685
|
+
return null;
|
|
14686
|
+
let target = arrayParsed;
|
|
14687
|
+
if (arrayParsed.kind === "identifier") {
|
|
14688
|
+
if (opts?.isNameShadowed?.(arrayParsed.name))
|
|
14689
|
+
return null;
|
|
14690
|
+
const local = localConstants?.find((c) => c.name === arrayParsed.name);
|
|
14691
|
+
if (!local?.parsed || local.mutatedAfterDeclaration)
|
|
14692
|
+
return null;
|
|
14693
|
+
target = local.parsed;
|
|
14694
|
+
}
|
|
14695
|
+
const resolved = evaluateStaticLiteral(target);
|
|
14696
|
+
if (!resolved || !Array.isArray(resolved.value))
|
|
14697
|
+
return null;
|
|
14698
|
+
return resolved.value;
|
|
14699
|
+
}
|
|
14700
|
+
|
|
14365
14701
|
// src/relocate.ts
|
|
14366
14702
|
import ts24 from "typescript";
|
|
14367
14703
|
function classify2(name, env) {
|
|
@@ -15294,7 +15630,7 @@ function findAssignedNames(bodyText, candidates) {
|
|
|
15294
15630
|
}
|
|
15295
15631
|
};
|
|
15296
15632
|
const visit3 = (node) => {
|
|
15297
|
-
if (ts25.isBinaryExpression(node) &&
|
|
15633
|
+
if (ts25.isBinaryExpression(node) && isAssignmentOperator4(node.operatorToken.kind)) {
|
|
15298
15634
|
record(node.left);
|
|
15299
15635
|
} else if ((ts25.isPrefixUnaryExpression(node) || ts25.isPostfixUnaryExpression(node)) && (node.operator === ts25.SyntaxKind.PlusPlusToken || node.operator === ts25.SyntaxKind.MinusMinusToken)) {
|
|
15300
15636
|
record(node.operand);
|
|
@@ -15323,7 +15659,7 @@ function closeOverWritersOfMutableBindings(primaryRefs, declarations, mutableNam
|
|
|
15323
15659
|
}
|
|
15324
15660
|
return reachable;
|
|
15325
15661
|
}
|
|
15326
|
-
function
|
|
15662
|
+
function isAssignmentOperator4(kind) {
|
|
15327
15663
|
return kind >= ts25.SyntaxKind.FirstAssignment && kind <= ts25.SyntaxKind.LastAssignment;
|
|
15328
15664
|
}
|
|
15329
15665
|
function extractFunctionParams(value) {
|
|
@@ -19834,11 +20170,18 @@ function closedRestSpreadSource(attr, ctx) {
|
|
|
19834
20170
|
let expr = attr.expression;
|
|
19835
20171
|
while (ts27.isParenthesizedExpression(expr))
|
|
19836
20172
|
expr = expr.expression;
|
|
19837
|
-
if (!ts27.isIdentifier(expr) || expr.text
|
|
20173
|
+
if (!ts27.isIdentifier(expr) || !isRestBinding(expr.text, restName, ctx))
|
|
19838
20174
|
return null;
|
|
19839
20175
|
const source = ctx.analyzer.restPropsOmittedKeys && ctx.analyzer.propsObjectName ? ctx.analyzer.propsObjectName : restName;
|
|
19840
20176
|
return source !== restName && ctx.scope.isBound(source) ? null : source;
|
|
19841
20177
|
}
|
|
20178
|
+
function isRestBinding(name, restName, ctx) {
|
|
20179
|
+
if (name === restName)
|
|
20180
|
+
return true;
|
|
20181
|
+
if (ctx.scope.isBound(name))
|
|
20182
|
+
return false;
|
|
20183
|
+
return resolveAliasOrigin(childrenAliasHops(ctx.analyzer), name, (n) => n === restName ? true : null) === true;
|
|
20184
|
+
}
|
|
19842
20185
|
function refuseBodyRestSpreadUnderShadowedProps(attr, ctx) {
|
|
19843
20186
|
const restName = ctx.analyzer.restPropsName;
|
|
19844
20187
|
const propsName = ctx.analyzer.propsObjectName;
|
|
@@ -19849,7 +20192,7 @@ function refuseBodyRestSpreadUnderShadowedProps(attr, ctx) {
|
|
|
19849
20192
|
let expr = attr.expression;
|
|
19850
20193
|
while (ts27.isParenthesizedExpression(expr))
|
|
19851
20194
|
expr = expr.expression;
|
|
19852
|
-
if (!ts27.isIdentifier(expr) || expr.text
|
|
20195
|
+
if (!ts27.isIdentifier(expr) || !isRestBinding(expr.text, restName, ctx))
|
|
19853
20196
|
return false;
|
|
19854
20197
|
ctx.analyzer.errors.push({
|
|
19855
20198
|
code: "BF101",
|
|
@@ -19992,21 +20335,38 @@ function isEffectFreeExpression(expr) {
|
|
|
19992
20335
|
return false;
|
|
19993
20336
|
}
|
|
19994
20337
|
function expandStaticConstSpread(attr, ctx) {
|
|
19995
|
-
|
|
20338
|
+
const init = staticConstInitializerOf(attr.expression, ctx);
|
|
20339
|
+
if (!init || !ts27.isObjectLiteralExpression(init))
|
|
20340
|
+
return null;
|
|
20341
|
+
return staticObjectSpreadEntries(init);
|
|
20342
|
+
}
|
|
20343
|
+
function staticConstInitializerOf(expr, ctx) {
|
|
19996
20344
|
while (ts27.isParenthesizedExpression(expr))
|
|
19997
20345
|
expr = expr.expression;
|
|
19998
20346
|
if (!ts27.isIdentifier(expr))
|
|
19999
20347
|
return null;
|
|
20000
20348
|
const name = expr.text;
|
|
20001
20349
|
const constant = resolveStaticConstBinding(name, ctx.analyzer.localConstants, (n) => ctx.scope.isBound(n));
|
|
20002
|
-
|
|
20350
|
+
const kind = constant?.parsed?.kind;
|
|
20351
|
+
if (!constant || kind !== "object-literal" && kind !== "array-literal")
|
|
20003
20352
|
return null;
|
|
20004
20353
|
if (constant.isModule && componentScopeNames(ctx.analyzer).has(name))
|
|
20005
20354
|
return null;
|
|
20006
20355
|
const init = parseConstInitializer(constant);
|
|
20007
|
-
if (!init || !ts27.isObjectLiteralExpression(init))
|
|
20356
|
+
if (!init || !(ts27.isObjectLiteralExpression(init) || ts27.isArrayLiteralExpression(init)))
|
|
20008
20357
|
return null;
|
|
20009
|
-
return
|
|
20358
|
+
return init;
|
|
20359
|
+
}
|
|
20360
|
+
function withStaticConstLiteral(value, attr, ctx) {
|
|
20361
|
+
if (value.kind !== "expression" || !attr.initializer || !ts27.isJsxExpression(attr.initializer) || !attr.initializer.expression)
|
|
20362
|
+
return value;
|
|
20363
|
+
const init = staticConstInitializerOf(attr.initializer.expression, ctx);
|
|
20364
|
+
if (!init)
|
|
20365
|
+
return value;
|
|
20366
|
+
const parsed = tsNodeToParsedExpr(init);
|
|
20367
|
+
if (!isFullyStaticLiteral(parsed))
|
|
20368
|
+
return value;
|
|
20369
|
+
return { ...value, staticConstLiteral: { expr: astText(init), parsed } };
|
|
20010
20370
|
}
|
|
20011
20371
|
function staticObjectSpreadEntries(init) {
|
|
20012
20372
|
const entries = new Map;
|
|
@@ -20915,40 +21275,43 @@ function processComponentProps(attributes, ctx) {
|
|
|
20915
21275
|
continue;
|
|
20916
21276
|
}
|
|
20917
21277
|
}
|
|
20918
|
-
|
|
20919
|
-
|
|
20920
|
-
|
|
20921
|
-
|
|
20922
|
-
|
|
20923
|
-
|
|
20924
|
-
|
|
20925
|
-
|
|
20926
|
-
|
|
20927
|
-
|
|
20928
|
-
|
|
20929
|
-
|
|
20930
|
-
|
|
20931
|
-
|
|
20932
|
-
|
|
20933
|
-
|
|
20934
|
-
|
|
20935
|
-
|
|
20936
|
-
|
|
20937
|
-
|
|
20938
|
-
|
|
21278
|
+
props.push(valueComponentProp(attr, name, ctx));
|
|
21279
|
+
}
|
|
21280
|
+
return props;
|
|
21281
|
+
}
|
|
21282
|
+
function valueComponentProp(attr, name, ctx) {
|
|
21283
|
+
let value = getAttributeValue(attr, ctx);
|
|
21284
|
+
if (value.kind === "template") {
|
|
21285
|
+
const collapsed = templatePartsToJsExpr(value.parts);
|
|
21286
|
+
const collapsedTemplate = templatePartsToJsExpr(value.parts, { useTemplate: true });
|
|
21287
|
+
value = AttrValueOf.expression(collapsed, {
|
|
21288
|
+
parts: value.parts,
|
|
21289
|
+
...collapsedTemplate !== collapsed && { templateExpr: collapsedTemplate }
|
|
21290
|
+
});
|
|
21291
|
+
} else if (value.kind === "boolean-attr") {
|
|
21292
|
+
value = AttrValueOf.booleanShorthand();
|
|
21293
|
+
}
|
|
21294
|
+
let clientOnly;
|
|
21295
|
+
if (attr.initializer && ts27.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
21296
|
+
if (value.kind === "expression" && value.templateExpr === undefined) {
|
|
21297
|
+
const rewritten = rewriteBarePropRefs2(value.expr, attr.initializer.expression, ctx);
|
|
21298
|
+
if (rewritten !== value.expr) {
|
|
21299
|
+
value = { ...value, templateExpr: rewritten };
|
|
20939
21300
|
}
|
|
20940
21301
|
}
|
|
20941
|
-
|
|
20942
|
-
|
|
20943
|
-
|
|
20944
|
-
value,
|
|
20945
|
-
clientOnly,
|
|
20946
|
-
loc: getSourceLocation(attr, ctx.sourceFile, ctx.filePath),
|
|
20947
|
-
...computeReactivityFlags(attr, ctx),
|
|
20948
|
-
...freeIdentifiers2 !== undefined && { freeIdentifiers: freeIdentifiers2 }
|
|
20949
|
-
});
|
|
21302
|
+
if (hasLeadingClientDirective(attr.initializer.expression, ctx.sourceFile)) {
|
|
21303
|
+
clientOnly = true;
|
|
21304
|
+
}
|
|
20950
21305
|
}
|
|
20951
|
-
|
|
21306
|
+
const freeIdentifiers2 = attrFreeIdentifiers(attr);
|
|
21307
|
+
return {
|
|
21308
|
+
name,
|
|
21309
|
+
value: clientOnly ? value : withStaticConstLiteral(value, attr, ctx),
|
|
21310
|
+
clientOnly,
|
|
21311
|
+
loc: getSourceLocation(attr, ctx.sourceFile, ctx.filePath),
|
|
21312
|
+
...computeReactivityFlags(attr, ctx),
|
|
21313
|
+
...freeIdentifiers2 !== undefined && { freeIdentifiers: freeIdentifiers2 }
|
|
21314
|
+
};
|
|
20952
21315
|
}
|
|
20953
21316
|
function isRenderedElementAttribute(attr, ctx) {
|
|
20954
21317
|
const tagName = attr.parent.parent.tagName.getText(ctx.sourceFile);
|
|
@@ -22117,47 +22480,6 @@ function emitMultiRootTemplateCloneLines(template, indent, varEl, varExtras) {
|
|
|
22117
22480
|
];
|
|
22118
22481
|
}
|
|
22119
22482
|
|
|
22120
|
-
// src/ir-to-client-js/child-props-object.ts
|
|
22121
|
-
function isSpreadPropName(name) {
|
|
22122
|
-
return name.startsWith("...");
|
|
22123
|
-
}
|
|
22124
|
-
function lastPropsObjectSpreadIndex(props) {
|
|
22125
|
-
let at = -1;
|
|
22126
|
-
props.forEach((p, index) => {
|
|
22127
|
-
if (p.value.kind === "spread" && p.value.propsObject === true)
|
|
22128
|
-
at = index;
|
|
22129
|
-
});
|
|
22130
|
-
return at;
|
|
22131
|
-
}
|
|
22132
|
-
function callerFirstPropExpr(name, expr) {
|
|
22133
|
-
const key = JSON.stringify(name);
|
|
22134
|
-
return `(${key} in ${PROPS_PARAM} ? ${PROPS_PARAM}[${key}] : ${expr})`;
|
|
22135
|
-
}
|
|
22136
|
-
function childPropsObjectExpr(props, valueOf, options = {}) {
|
|
22137
|
-
const spreadAt = lastPropsObjectSpreadIndex(props);
|
|
22138
|
-
const entries = [];
|
|
22139
|
-
const explicitNames = [];
|
|
22140
|
-
props.forEach((prop, index) => {
|
|
22141
|
-
if (isSpreadPropName(prop.name))
|
|
22142
|
-
return;
|
|
22143
|
-
const value = valueOf(prop);
|
|
22144
|
-
if (!value)
|
|
22145
|
-
return;
|
|
22146
|
-
explicitNames.push(prop.name);
|
|
22147
|
-
const key = quotePropName(prop.name);
|
|
22148
|
-
if (index < spreadAt) {
|
|
22149
|
-
entries.push(`get ${key}() { return ${callerFirstPropExpr(prop.name, value.expr)} }`);
|
|
22150
|
-
} else {
|
|
22151
|
-
entries.push(value.getter ? `get ${key}() { return ${value.expr} }` : `${key}: ${value.expr}`);
|
|
22152
|
-
}
|
|
22153
|
-
});
|
|
22154
|
-
entries.push(...options.trailing ?? []);
|
|
22155
|
-
const object = entries.length > 0 ? `{ ${entries.join(", ")} }` : "{}";
|
|
22156
|
-
if (spreadAt < 0 && !options.forwardCaller)
|
|
22157
|
-
return object;
|
|
22158
|
-
return `forwardProps(${PROPS_PARAM}, ${object}, ${JSON.stringify(explicitNames)})`;
|
|
22159
|
-
}
|
|
22160
|
-
|
|
22161
22483
|
// src/ir-to-client-js/collect-elements.ts
|
|
22162
22484
|
import { classifyDOMProp as classifyDOMProp2 } from "@barefootjs/shared";
|
|
22163
22485
|
var EMPTY_RENDER_EXPRS = new Set(["null", "undefined", "false", "''", '""', "``"]);
|
|
@@ -22414,9 +22736,6 @@ function componentInitPropValue(prop, ctx) {
|
|
|
22414
22736
|
return { expr: "true", getter: false };
|
|
22415
22737
|
}
|
|
22416
22738
|
}
|
|
22417
|
-
function mergedMirrorExpr(name, expr, index, spreadAt) {
|
|
22418
|
-
return index < spreadAt ? callerFirstPropExpr(name, expr) : expr;
|
|
22419
|
-
}
|
|
22420
22739
|
function callerBagSpreadOrigin(value, ctx) {
|
|
22421
22740
|
if (value.kind !== "spread" || value.callerBag === undefined)
|
|
22422
22741
|
return null;
|
|
@@ -22436,12 +22755,13 @@ function buildComponentPropsExpr(props, ctx) {
|
|
|
22436
22755
|
const expr = p.value.kind === "spread" ? p.value.expr : p.value.expr;
|
|
22437
22756
|
return resolveRestSpreadOrigin(ctx, expr) !== null;
|
|
22438
22757
|
});
|
|
22758
|
+
const consumedKeys = ctx.propsParams.map((p) => p.sourceName ?? p.name);
|
|
22439
22759
|
return childPropsObjectExpr(props, (prop) => componentInitPropValue(prop, ctx), {
|
|
22440
|
-
forwardCaller: knownSpreadProp !== undefined
|
|
22760
|
+
forwardCaller: knownSpreadProp !== undefined,
|
|
22761
|
+
restBag: `forwardProps(${PROPS_PARAM}, {}, ${codeSafeStringArray(consumedKeys)})`
|
|
22441
22762
|
});
|
|
22442
22763
|
}
|
|
22443
22764
|
function collectReactiveChildProps(node, ctx) {
|
|
22444
|
-
const spreadAt = lastPropsObjectSpreadIndex(node.props);
|
|
22445
22765
|
for (const [index, prop] of node.props.entries()) {
|
|
22446
22766
|
if (prop.name === "..." || prop.name.startsWith("..."))
|
|
22447
22767
|
continue;
|
|
@@ -22462,7 +22782,7 @@ function collectReactiveChildProps(node, ctx) {
|
|
|
22462
22782
|
slotId: node.slotId,
|
|
22463
22783
|
propName: prop.name,
|
|
22464
22784
|
attrName,
|
|
22465
|
-
expression:
|
|
22785
|
+
expression: mergedExplicitPropExpr(node.props, index, expandedValue, (spread) => expandDynamicPropValue(attrValueToString(spread.value), ctx)),
|
|
22466
22786
|
...pickAttrMetaFromIR(prop)
|
|
22467
22787
|
});
|
|
22468
22788
|
}
|
|
@@ -22626,7 +22946,6 @@ function collectElements(node, ctx, siblingOffsets, insideConditional = false) {
|
|
|
22626
22946
|
},
|
|
22627
22947
|
component: ({ node: c, descend, descendJsxChildren }) => {
|
|
22628
22948
|
if (c.slotId) {
|
|
22629
|
-
const spreadAt = lastPropsObjectSpreadIndex(c.props);
|
|
22630
22949
|
for (const [index, prop] of c.props.entries()) {
|
|
22631
22950
|
if (prop.value.kind === "jsx-children")
|
|
22632
22951
|
continue;
|
|
@@ -22643,7 +22962,7 @@ function collectElements(node, ctx, siblingOffsets, insideConditional = false) {
|
|
|
22643
22962
|
ctx.reactiveProps.push({
|
|
22644
22963
|
slotId: c.slotId,
|
|
22645
22964
|
propName: prop.name,
|
|
22646
|
-
expression:
|
|
22965
|
+
expression: mergedExplicitPropExpr(c.props, index, value, (spread) => expandDynamicPropValue(attrValueToString(spread.value), ctx)),
|
|
22647
22966
|
componentName: c.name
|
|
22648
22967
|
});
|
|
22649
22968
|
}
|
|
@@ -24103,7 +24422,7 @@ function buildDeclarationEmitPlan(decl, ctx, lookups) {
|
|
|
24103
24422
|
kind: "constant",
|
|
24104
24423
|
keyword: c.declarationKind ?? "const",
|
|
24105
24424
|
name: c.name,
|
|
24106
|
-
valueExpr: c.value !== undefined ? c.value : null
|
|
24425
|
+
valueExpr: bodyDestructureValue(c, ctx) ?? (c.value !== undefined ? c.value : null)
|
|
24107
24426
|
};
|
|
24108
24427
|
}
|
|
24109
24428
|
case "signal":
|
|
@@ -24167,12 +24486,26 @@ function resolveSignalInitialValue(signal, lookups) {
|
|
|
24167
24486
|
const controlled = lookups.controlledBySignal.get(signal);
|
|
24168
24487
|
if (controlled) {
|
|
24169
24488
|
const prop = lookups.propByName.get(controlled.propName);
|
|
24170
|
-
const
|
|
24171
|
-
|
|
24489
|
+
const defaultText = prop && propDefaultText(prop);
|
|
24490
|
+
const base = `${PROPS_PARAM}.${prop?.sourceName ?? controlled.propName}`;
|
|
24491
|
+
return composePropRead(base, defaultText ? { kind: "default", text: coalesceDefaultText(defaultText, prop.defaultContainsArrow) } : { kind: "guard", text: inferDefaultValue(signal.type) });
|
|
24172
24492
|
}
|
|
24173
24493
|
}
|
|
24174
24494
|
return signal.initialValue;
|
|
24175
24495
|
}
|
|
24496
|
+
function bodyDestructureValue(c, ctx) {
|
|
24497
|
+
const sourceKey = c.propsDestructure?.sourceKey;
|
|
24498
|
+
if (sourceKey === undefined || ctx.propsObjectName === null)
|
|
24499
|
+
return null;
|
|
24500
|
+
const param = ctx.propsParams.find((p) => p.name === c.name && (p.sourceName ?? p.name) === sourceKey);
|
|
24501
|
+
const defaultText = param?.defaultValue;
|
|
24502
|
+
if (!param || !defaultText)
|
|
24503
|
+
return null;
|
|
24504
|
+
return composePropRead(`${ctx.propsObjectName}.${sourceKey}`, {
|
|
24505
|
+
kind: "default",
|
|
24506
|
+
text: coalesceDefaultText(defaultText, param.defaultContainsArrow)
|
|
24507
|
+
});
|
|
24508
|
+
}
|
|
24176
24509
|
function buildControlledSignalEffect(signal, lookups) {
|
|
24177
24510
|
const controlled = lookups.controlledBySignal.get(signal);
|
|
24178
24511
|
if (!controlled)
|
|
@@ -24730,7 +25063,8 @@ function wrapAttrValueExpression(value, wrap) {
|
|
|
24730
25063
|
case "spread":
|
|
24731
25064
|
return {
|
|
24732
25065
|
...AttrValueOf.spread(wrap(value.expr), value.templateExpr ? wrap(value.templateExpr) : undefined),
|
|
24733
|
-
...value.propsObject && { propsObject: true }
|
|
25066
|
+
...value.propsObject && { propsObject: true },
|
|
25067
|
+
...value.callerBag !== undefined && { callerBag: value.callerBag }
|
|
24734
25068
|
};
|
|
24735
25069
|
}
|
|
24736
25070
|
}
|
|
@@ -25255,7 +25589,7 @@ function findImpureNode(root, primableNames) {
|
|
|
25255
25589
|
found = "function or class expression";
|
|
25256
25590
|
return;
|
|
25257
25591
|
}
|
|
25258
|
-
if (ts28.isBinaryExpression(node) &&
|
|
25592
|
+
if (ts28.isBinaryExpression(node) && isAssignmentOperator5(node.operatorToken.kind)) {
|
|
25259
25593
|
found = "assignment";
|
|
25260
25594
|
return;
|
|
25261
25595
|
}
|
|
@@ -25264,7 +25598,7 @@ function findImpureNode(root, primableNames) {
|
|
|
25264
25598
|
visit3(root);
|
|
25265
25599
|
return found;
|
|
25266
25600
|
}
|
|
25267
|
-
function
|
|
25601
|
+
function isAssignmentOperator5(kind) {
|
|
25268
25602
|
return kind >= ts28.SyntaxKind.FirstAssignment && kind <= ts28.SyntaxKind.LastAssignment;
|
|
25269
25603
|
}
|
|
25270
25604
|
|
|
@@ -25735,7 +26069,8 @@ function wrapAttrValueExpression2(value, wrap) {
|
|
|
25735
26069
|
case "spread":
|
|
25736
26070
|
return {
|
|
25737
26071
|
...AttrValueOf.spread(wrap(value.expr), value.templateExpr ? wrap(value.templateExpr) : undefined),
|
|
25738
|
-
...value.propsObject && { propsObject: true }
|
|
26072
|
+
...value.propsObject && { propsObject: true },
|
|
26073
|
+
...value.callerBag !== undefined && { callerBag: value.callerBag }
|
|
25739
26074
|
};
|
|
25740
26075
|
}
|
|
25741
26076
|
}
|
|
@@ -26396,7 +26731,7 @@ function emitPropsExtraction(lines, ctx, neededProps, propUsage) {
|
|
|
26396
26731
|
return;
|
|
26397
26732
|
const usedAsCondition = computePropsUsedAsConditions(ctx, neededProps).has(local);
|
|
26398
26733
|
const fallback = propReadFallback(prop, propUsage.get(local), usedAsCondition);
|
|
26399
|
-
const read = propReadBase(prop)
|
|
26734
|
+
const read = composePropRead(propReadBase(prop), fallback);
|
|
26400
26735
|
lines.push(` ${keepsDeclaredValue(prop) ? "const" : "let"} ${local} = ${read}`, "");
|
|
26401
26736
|
}
|
|
26402
26737
|
function emitWrittenPropLocals(lines, ctx, propUsage) {
|
|
@@ -26404,9 +26739,10 @@ function emitWrittenPropLocals(lines, ctx, propUsage) {
|
|
|
26404
26739
|
if (written.length === 0)
|
|
26405
26740
|
return;
|
|
26406
26741
|
const usedAsCondition = computePropsUsedAsConditions(ctx, new Set(written.map((p) => p.name)));
|
|
26742
|
+
const retained = retainedPropLocals(ctx);
|
|
26407
26743
|
for (const prop of written) {
|
|
26408
|
-
const fallback = propReadFallback(prop, propUsage.get(prop.name), usedAsCondition.has(prop.name));
|
|
26409
|
-
lines.push(` let ${prop.name} = ${propReadBase(prop)
|
|
26744
|
+
const fallback = propReadFallback(prop, propUsage.get(prop.name), usedAsCondition.has(prop.name), retained);
|
|
26745
|
+
lines.push(` let ${prop.name} = ${composePropRead(propReadBase(prop), fallback)}`);
|
|
26410
26746
|
}
|
|
26411
26747
|
lines.push("");
|
|
26412
26748
|
}
|
|
@@ -29195,12 +29531,27 @@ function bodyAliasDefaultParts(ctx, local, key) {
|
|
|
29195
29531
|
const param = ctx.propsParams.find((p) => !p.isRest && p.name === local && (p.sourceName ?? p.name) === key);
|
|
29196
29532
|
return param?.defaultParts ? { defaultParts: param.defaultParts } : {};
|
|
29197
29533
|
}
|
|
29534
|
+
function keepAliasesReadingRetainedLocals(aliases, ctx) {
|
|
29535
|
+
const retained = new Set(ctx.localConstants.filter((c) => c.propsDestructure && !c.isModule && !aliases.has(c.name)).map((c) => c.name));
|
|
29536
|
+
for (let changed = true;changed; ) {
|
|
29537
|
+
changed = false;
|
|
29538
|
+
for (const [local, alias] of aliases) {
|
|
29539
|
+
const parts = bodyAliasDefaultParts(ctx, local, alias.key).defaultParts ?? [];
|
|
29540
|
+
if (!parts.some((part) => part.kind === "param" && retained.has(part.param.name)))
|
|
29541
|
+
continue;
|
|
29542
|
+
aliases.delete(local);
|
|
29543
|
+
retained.add(local);
|
|
29544
|
+
changed = true;
|
|
29545
|
+
}
|
|
29546
|
+
}
|
|
29547
|
+
}
|
|
29198
29548
|
function rewriteBodyAliasReads(code, ctx) {
|
|
29199
29549
|
const aliases = resolveBodyPropAliases(ctx.localConstants, ctx.propsObjectName);
|
|
29200
29550
|
for (const [local, alias] of aliases) {
|
|
29201
29551
|
if (alias.key === "children")
|
|
29202
29552
|
aliases.delete(local);
|
|
29203
29553
|
}
|
|
29554
|
+
keepAliasesReadingRetainedLocals(aliases, ctx);
|
|
29204
29555
|
if (aliases.size === 0)
|
|
29205
29556
|
return code;
|
|
29206
29557
|
if (![...aliases.keys()].some((name) => identifierPattern(name).test(code)))
|
|
@@ -29233,6 +29584,7 @@ function rewriteBodyAliasReads(code, ctx) {
|
|
|
29233
29584
|
located.set(decl.name.text, {
|
|
29234
29585
|
key: alias.key,
|
|
29235
29586
|
defaultValue: parsedInit.fallback?.getText(sourceFile),
|
|
29587
|
+
coalescesNull: parsedInit.coalescesNull,
|
|
29236
29588
|
defaultContainsArrow: alias.defaultContainsArrow && !(parsedInit.fallback && ts30.isParenthesizedExpression(parsedInit.fallback)),
|
|
29237
29589
|
...bodyAliasDefaultParts(ctx, decl.name.text, alias.key)
|
|
29238
29590
|
});
|
|
@@ -29255,6 +29607,7 @@ function rewriteBodyAliasReads(code, ctx) {
|
|
|
29255
29607
|
sourceName: info.key,
|
|
29256
29608
|
defaultValue: info.defaultValue,
|
|
29257
29609
|
defaultContainsArrow: info.defaultContainsArrow,
|
|
29610
|
+
coalescesNull: info.coalescesNull,
|
|
29258
29611
|
...info.defaultParts && { defaultParts: info.defaultParts }
|
|
29259
29612
|
};
|
|
29260
29613
|
return livePropReadExpr(prop, undefined, false);
|
|
@@ -31859,7 +32212,12 @@ function operandFacts(expr, typing) {
|
|
|
31859
32212
|
}
|
|
31860
32213
|
}
|
|
31861
32214
|
function decide(op, proof, target, helper) {
|
|
31862
|
-
return
|
|
32215
|
+
return claimsNative(op, proof, target) ? { mode: "native", op, proof } : { mode: "helper", op, helper, proof };
|
|
32216
|
+
}
|
|
32217
|
+
function claimsNative(op, proof, target) {
|
|
32218
|
+
if (proof === "unproven")
|
|
32219
|
+
return false;
|
|
32220
|
+
return target[op]?.includes(proof) ?? false;
|
|
31863
32221
|
}
|
|
31864
32222
|
function pairProof(left, right) {
|
|
31865
32223
|
const l = provenPrimitive(left);
|
|
@@ -31881,6 +32239,21 @@ function isNilLiteralOperand(expr, typing) {
|
|
|
31881
32239
|
function isNullishTest(op, left, right, typing) {
|
|
31882
32240
|
return (op === "===" || op === "!==" || op === "==" || op === "!=") && (isNilLiteralOperand(left, typing) || isNilLiteralOperand(right, typing));
|
|
31883
32241
|
}
|
|
32242
|
+
function planNilTest(op, left, right, typing) {
|
|
32243
|
+
const nilTest = (helper) => ({ mode: "helper", op: "nil-test", helper, proof: "unproven" });
|
|
32244
|
+
if (op === "==" || op === "!=")
|
|
32245
|
+
return nilTest("is_nullish");
|
|
32246
|
+
const literal = nilTestOperand(left, right, typing) === left ? right : left;
|
|
32247
|
+
return nilTest(literal.kind === "literal" ? "is_null" : "is_undefined");
|
|
32248
|
+
}
|
|
32249
|
+
function nilTestOperand(left, right, typing) {
|
|
32250
|
+
return isNilLiteralOperand(right, typing) ? left : right;
|
|
32251
|
+
}
|
|
32252
|
+
function refuseUnspelledNilTest(plan) {
|
|
32253
|
+
if (plan?.op !== "nil-test" || plan.mode !== "helper")
|
|
32254
|
+
return;
|
|
32255
|
+
throw new Error(`[barefootjs] the primitive plan names the \`${plan.helper}\` nil test (a target that carries \`undefined\`), ` + "but this emitter has no spelling for it (spec/js-undefined-value.md)");
|
|
32256
|
+
}
|
|
31884
32257
|
var ELEMENT_READ_METHODS = new Set(["at", "find", "findLast"]);
|
|
31885
32258
|
function elementReadReceiver(expr) {
|
|
31886
32259
|
if (expr.kind === "index-access")
|
|
@@ -31903,6 +32276,7 @@ function mayHoldObject(expr, typing, isObjectTypeName = () => false) {
|
|
|
31903
32276
|
}
|
|
31904
32277
|
var NON_PRIMITIVE_EQUALITY_REASON = "non-primitive-strict-equality";
|
|
31905
32278
|
function strictEqSpelling(op, left, right, plan) {
|
|
32279
|
+
refuseUnspelledNilTest(plan);
|
|
31906
32280
|
if (op !== "===" && op !== "!==")
|
|
31907
32281
|
return null;
|
|
31908
32282
|
if (isNilLiteralOperand(left) || isNilLiteralOperand(right))
|
|
@@ -31949,14 +32323,14 @@ function planNumericBinary(op, left, right, target) {
|
|
|
31949
32323
|
}
|
|
31950
32324
|
function planBinary(expr, typing, target) {
|
|
31951
32325
|
const { op } = expr;
|
|
32326
|
+
if (isNullishTest(op, expr.left, expr.right, typing))
|
|
32327
|
+
return planNilTest(op, expr.left, expr.right, typing);
|
|
31952
32328
|
const isPrimitiveOp = op === "===" || op === "!==" || op === "+" || op in RELATIONAL_HELPERS || op === "-" || op === "*" || op === "/" || op === "%";
|
|
31953
32329
|
if (!isPrimitiveOp)
|
|
31954
32330
|
return null;
|
|
31955
32331
|
const left = operandFacts(expr.left, typing);
|
|
31956
32332
|
const right = operandFacts(expr.right, typing);
|
|
31957
32333
|
if (op === "===" || op === "!==") {
|
|
31958
|
-
if (isNullishTest(op, expr.left, expr.right, typing))
|
|
31959
|
-
return null;
|
|
31960
32334
|
if (mayHoldObject(expr.left, typing) || mayHoldObject(expr.right, typing)) {
|
|
31961
32335
|
return { mode: "refuse", op: "strict-eq", reason: NON_PRIMITIVE_EQUALITY_REASON };
|
|
31962
32336
|
}
|
|
@@ -32532,7 +32906,7 @@ function arithmeticOperandCoercion(op, operand, other, ctx, isShadowed = () => f
|
|
|
32532
32906
|
const seed = arithmeticOperandSeed(operand, ctx, isShadowed);
|
|
32533
32907
|
if (seed === "absent")
|
|
32534
32908
|
return "undefined";
|
|
32535
|
-
return seed === "either" ?
|
|
32909
|
+
return seed === "either" ? null : seed;
|
|
32536
32910
|
}
|
|
32537
32911
|
var RELATIONAL_OPS = new Set(["<", "<=", ">", ">="]);
|
|
32538
32912
|
function relationalOperandCoercion(operand, ctx, isShadowed) {
|
|
@@ -32543,77 +32917,6 @@ function relationalOperandCoercion(operand, ctx, isShadowed) {
|
|
|
32543
32917
|
return null;
|
|
32544
32918
|
return scalarPropRead(operand, ctx, isShadowed)?.nil === "undefined" ? "undefined-keep" : null;
|
|
32545
32919
|
}
|
|
32546
|
-
function arithmeticOperandNilIsAmbiguous(op, operand, other, ctx, isShadowed = () => false) {
|
|
32547
|
-
return ambiguousNilFamily(op, operand, other, ctx, isShadowed) !== null;
|
|
32548
|
-
}
|
|
32549
|
-
function ambiguousNilFamily(op, operand, other, ctx, isShadowed = () => false) {
|
|
32550
|
-
const relational = RELATIONAL_OPS.has(op);
|
|
32551
|
-
if (!relational && !isNumericArithmetic(op, other))
|
|
32552
|
-
return null;
|
|
32553
|
-
if (arithmeticOperandSeed(operand, ctx, isShadowed) === "either")
|
|
32554
|
-
return "number";
|
|
32555
|
-
if (!relational)
|
|
32556
|
-
return null;
|
|
32557
|
-
const scalar = scalarPropRead(operand, ctx, isShadowed);
|
|
32558
|
-
return scalar?.nil === "either" ? scalar.family : null;
|
|
32559
|
-
}
|
|
32560
|
-
function ambiguousNilArithmeticOperands(expr, ctx, scope = BindingScope.EMPTY) {
|
|
32561
|
-
return ambiguousNilOperands(expr, ctx, scope).map((found) => found.operand);
|
|
32562
|
-
}
|
|
32563
|
-
function ambiguousNilOperands(expr, ctx, scope = BindingScope.EMPTY) {
|
|
32564
|
-
const found = [];
|
|
32565
|
-
const visit3 = (e, at) => {
|
|
32566
|
-
if (e.kind === "arrow") {
|
|
32567
|
-
visit3(e.body, at.enterCallback(e.params));
|
|
32568
|
-
return;
|
|
32569
|
-
}
|
|
32570
|
-
for (const [op, operand, other] of arithmeticOperandsOf(e)) {
|
|
32571
|
-
const family = ambiguousNilFamily(op, operand, other, ctx, at.asShadowPredicate());
|
|
32572
|
-
if (family !== null)
|
|
32573
|
-
found.push({ operand, family });
|
|
32574
|
-
}
|
|
32575
|
-
for (const child of parsedExprChildren2(e))
|
|
32576
|
-
visit3(child, at);
|
|
32577
|
-
};
|
|
32578
|
-
if (!ctx.nullableNumberProps?.size && !ctx.nullableScalarProps?.size)
|
|
32579
|
-
return found;
|
|
32580
|
-
visit3(expr, scope);
|
|
32581
|
-
return found;
|
|
32582
|
-
}
|
|
32583
|
-
function arithmeticOperandsOf(e) {
|
|
32584
|
-
if (e.kind === "binary")
|
|
32585
|
-
return [[e.op, e.left, e.right], [e.op, e.right, e.left]];
|
|
32586
|
-
if (e.kind === "unary" && (e.op === "-" || e.op === "+"))
|
|
32587
|
-
return [[e.op, e.argument, undefined]];
|
|
32588
|
-
return [];
|
|
32589
|
-
}
|
|
32590
|
-
function parsedExprChildren2(e) {
|
|
32591
|
-
switch (e.kind) {
|
|
32592
|
-
case "call":
|
|
32593
|
-
return [e.callee, ...e.args];
|
|
32594
|
-
case "member":
|
|
32595
|
-
return [e.object];
|
|
32596
|
-
case "index-access":
|
|
32597
|
-
return [e.object, e.index];
|
|
32598
|
-
case "binary":
|
|
32599
|
-
case "logical":
|
|
32600
|
-
return [e.left, e.right];
|
|
32601
|
-
case "unary":
|
|
32602
|
-
return [e.argument];
|
|
32603
|
-
case "conditional":
|
|
32604
|
-
return [e.test, e.consequent, e.alternate];
|
|
32605
|
-
case "template-literal":
|
|
32606
|
-
return e.parts.flatMap((p) => p.type === "expression" ? [p.expr] : []);
|
|
32607
|
-
case "array-literal":
|
|
32608
|
-
return e.elements;
|
|
32609
|
-
case "array-method":
|
|
32610
|
-
return [e.object, ...e.args, ...e.method === "flat" && e.depthExpr ? [e.depthExpr] : []];
|
|
32611
|
-
case "object-literal":
|
|
32612
|
-
return e.properties.map((p) => p.kind === "spread" ? p.expr : p.value);
|
|
32613
|
-
default:
|
|
32614
|
-
return [];
|
|
32615
|
-
}
|
|
32616
|
-
}
|
|
32617
32920
|
function isNumericArithmetic(op, other) {
|
|
32618
32921
|
return NULL_COERCING_ARITHMETIC_OPS.has(op) || op === "+" && (other === undefined || isNumberLiteral(other));
|
|
32619
32922
|
}
|
|
@@ -32648,6 +32951,9 @@ function loopRowType(types, loop, scope) {
|
|
|
32648
32951
|
const type = valueType(types, loop.arrayParsed, scope);
|
|
32649
32952
|
return arrayElementType(type) ?? null;
|
|
32650
32953
|
}
|
|
32954
|
+
function declaredValueType(types, expr, scope) {
|
|
32955
|
+
return valueType(types, expr, scope);
|
|
32956
|
+
}
|
|
32651
32957
|
function valueType(types, expr, scope) {
|
|
32652
32958
|
switch (expr.kind) {
|
|
32653
32959
|
case "identifier": {
|
|
@@ -32817,46 +33123,6 @@ function isRootPropsObject(expr, isBound, propsObject) {
|
|
|
32817
33123
|
return expr.kind === "identifier" && expr.name === propsObject && !isBound(expr.name);
|
|
32818
33124
|
}
|
|
32819
33125
|
|
|
32820
|
-
// src/adapters/ambiguous-nil-arithmetic.ts
|
|
32821
|
-
function arithmeticCoercionOrRefuse(op, operand, other, ctx, isShadowed, sink) {
|
|
32822
|
-
const family = ambiguousNilFamily(op, operand, other, ctx, isShadowed);
|
|
32823
|
-
if (family !== null)
|
|
32824
|
-
recordAmbiguousNilArithmetic(exprToString(operand), family, sink);
|
|
32825
|
-
return arithmeticOperandCoercion(op, operand, other, ctx, isShadowed);
|
|
32826
|
-
}
|
|
32827
|
-
function refuseAmbiguousNilArithmetic(expr, ctx, scope, sink) {
|
|
32828
|
-
for (const { operand, family } of ambiguousNilOperands(expr, ctx, scope)) {
|
|
32829
|
-
recordAmbiguousNilArithmetic(exprToString(operand), family, sink);
|
|
32830
|
-
}
|
|
32831
|
-
}
|
|
32832
|
-
function refuseAmbiguousNilMemoArithmetic(memos, ctx, sink) {
|
|
32833
|
-
for (const memo of memos) {
|
|
32834
|
-
if (memo.parsed)
|
|
32835
|
-
refuseAmbiguousNilArithmetic(memo.parsed, ctx, BindingScope.EMPTY, sink);
|
|
32836
|
-
}
|
|
32837
|
-
}
|
|
32838
|
-
function recordAmbiguousNilArithmetic(operandText, family, sink) {
|
|
32839
|
-
const message = ambiguousNilMessage(operandText, family);
|
|
32840
|
-
if (sink.errors.some((e) => e.code === "BF101" && e.message === message))
|
|
32841
|
-
return;
|
|
32842
|
-
sink.errors.push({
|
|
32843
|
-
code: "BF101",
|
|
32844
|
-
severity: "error",
|
|
32845
|
-
message,
|
|
32846
|
-
loc: { file: `${sink.componentName}.tsx`, start: { line: 1, column: 0 }, end: { line: 1, column: 0 } },
|
|
32847
|
-
suggestion: {
|
|
32848
|
-
message: `Declare the prop as only optional (\`?: ${family}\`) or only nullable (\`: ${family} | null\`), or give it a default value.`,
|
|
32849
|
-
escape: [{ kind: "rewrite" }]
|
|
32850
|
-
}
|
|
32851
|
-
});
|
|
32852
|
-
}
|
|
32853
|
-
function ambiguousNilMessage(operandText, family) {
|
|
32854
|
-
if (family === "number") {
|
|
32855
|
-
return `Arithmetic over \`${operandText}\` reads a number prop declared both optional and nullable (\`?: number | null\`). JS reads it as \`undefined\` when the caller omits it (\`NaN\` in arithmetic) and as \`0\` when it is \`null\`, but a template engine holds both as the same nil, so the server render cannot tell which one it is.`;
|
|
32856
|
-
}
|
|
32857
|
-
return `A comparison over \`${operandText}\` reads a ${family} prop declared both optional and nullable (\`?: ${family} | null\`). JS reads it as \`undefined\` when the caller omits it (\`NaN\`, so the comparison is false) and as \`null\` when it is \`null\` (\`0\`), but a template engine holds both as the same nil, so the server render cannot tell which one it is.`;
|
|
32858
|
-
}
|
|
32859
|
-
|
|
32860
33126
|
// src/adapters/non-primitive-equality.ts
|
|
32861
33127
|
function refusedComparisons(expr, typing, isObjectTypeName) {
|
|
32862
33128
|
const found = [];
|
|
@@ -33112,108 +33378,6 @@ function escapeRe(s) {
|
|
|
33112
33378
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
33113
33379
|
}
|
|
33114
33380
|
|
|
33115
|
-
// src/static-literal.ts
|
|
33116
|
-
function evaluateStaticLiteral(expr, bindings) {
|
|
33117
|
-
switch (expr.kind) {
|
|
33118
|
-
case "literal":
|
|
33119
|
-
return { value: expr.value };
|
|
33120
|
-
case "template-literal": {
|
|
33121
|
-
let out = "";
|
|
33122
|
-
for (const part of expr.parts) {
|
|
33123
|
-
if (part.type === "string") {
|
|
33124
|
-
out += part.value;
|
|
33125
|
-
continue;
|
|
33126
|
-
}
|
|
33127
|
-
const resolved = evaluateStaticLiteral(part.expr, bindings);
|
|
33128
|
-
if (!resolved)
|
|
33129
|
-
return null;
|
|
33130
|
-
out += String(resolved.value);
|
|
33131
|
-
}
|
|
33132
|
-
return { value: out };
|
|
33133
|
-
}
|
|
33134
|
-
case "array-literal": {
|
|
33135
|
-
const values = [];
|
|
33136
|
-
for (const element of expr.elements) {
|
|
33137
|
-
const resolved = evaluateStaticLiteral(element, bindings);
|
|
33138
|
-
if (!resolved)
|
|
33139
|
-
return null;
|
|
33140
|
-
values.push(resolved.value);
|
|
33141
|
-
}
|
|
33142
|
-
return { value: values };
|
|
33143
|
-
}
|
|
33144
|
-
case "object-literal": {
|
|
33145
|
-
const out = {};
|
|
33146
|
-
for (const prop of expr.properties) {
|
|
33147
|
-
if (prop.kind === "spread") {
|
|
33148
|
-
const resolved2 = evaluateStaticLiteral(prop.expr, bindings);
|
|
33149
|
-
if (!resolved2)
|
|
33150
|
-
return null;
|
|
33151
|
-
if (resolved2.value === null || resolved2.value === undefined)
|
|
33152
|
-
continue;
|
|
33153
|
-
if (typeof resolved2.value !== "object" || Array.isArray(resolved2.value))
|
|
33154
|
-
return null;
|
|
33155
|
-
Object.assign(out, resolved2.value);
|
|
33156
|
-
continue;
|
|
33157
|
-
}
|
|
33158
|
-
const resolved = evaluateStaticLiteral(prop.value, bindings);
|
|
33159
|
-
if (!resolved)
|
|
33160
|
-
return null;
|
|
33161
|
-
out[prop.key] = resolved.value;
|
|
33162
|
-
}
|
|
33163
|
-
return { value: out };
|
|
33164
|
-
}
|
|
33165
|
-
case "unary": {
|
|
33166
|
-
const resolved = evaluateStaticLiteral(expr.argument, bindings);
|
|
33167
|
-
if (!resolved)
|
|
33168
|
-
return null;
|
|
33169
|
-
if (expr.op === "-")
|
|
33170
|
-
return typeof resolved.value === "number" ? { value: -resolved.value } : null;
|
|
33171
|
-
if (expr.op === "+")
|
|
33172
|
-
return typeof resolved.value === "number" ? { value: +resolved.value } : null;
|
|
33173
|
-
if (expr.op === "!")
|
|
33174
|
-
return { value: !resolved.value };
|
|
33175
|
-
return null;
|
|
33176
|
-
}
|
|
33177
|
-
case "identifier":
|
|
33178
|
-
return bindings?.has(expr.name) ? { value: bindings.get(expr.name) } : null;
|
|
33179
|
-
case "member": {
|
|
33180
|
-
const base = evaluateStaticLiteral(expr.object, bindings);
|
|
33181
|
-
if (!base || base.value === null || typeof base.value !== "object")
|
|
33182
|
-
return null;
|
|
33183
|
-
return { value: base.value[expr.property] };
|
|
33184
|
-
}
|
|
33185
|
-
case "index-access": {
|
|
33186
|
-
const base = evaluateStaticLiteral(expr.object, bindings);
|
|
33187
|
-
const index = evaluateStaticLiteral(expr.index, bindings);
|
|
33188
|
-
if (!base || !index || !Array.isArray(base.value) || typeof index.value !== "number")
|
|
33189
|
-
return null;
|
|
33190
|
-
return { value: base.value[index.value] };
|
|
33191
|
-
}
|
|
33192
|
-
default:
|
|
33193
|
-
return null;
|
|
33194
|
-
}
|
|
33195
|
-
}
|
|
33196
|
-
function isFullyStaticLiteral(expr) {
|
|
33197
|
-
return evaluateStaticLiteral(expr) !== null;
|
|
33198
|
-
}
|
|
33199
|
-
function resolveStaticLoopSource(arrayParsed, localConstants, opts) {
|
|
33200
|
-
if (!arrayParsed)
|
|
33201
|
-
return null;
|
|
33202
|
-
let target = arrayParsed;
|
|
33203
|
-
if (arrayParsed.kind === "identifier") {
|
|
33204
|
-
if (opts?.isNameShadowed?.(arrayParsed.name))
|
|
33205
|
-
return null;
|
|
33206
|
-
const local = localConstants?.find((c) => c.name === arrayParsed.name);
|
|
33207
|
-
if (!local?.parsed || local.mutatedAfterDeclaration)
|
|
33208
|
-
return null;
|
|
33209
|
-
target = local.parsed;
|
|
33210
|
-
}
|
|
33211
|
-
const resolved = evaluateStaticLiteral(target);
|
|
33212
|
-
if (!resolved || !Array.isArray(resolved.value))
|
|
33213
|
-
return null;
|
|
33214
|
-
return resolved.value;
|
|
33215
|
-
}
|
|
33216
|
-
|
|
33217
33381
|
// src/adapters/nil-reading.ts
|
|
33218
33382
|
var NUMERIC_BINARY_OPS2 = new Set(["-", "*", "/", "%", "**", "<", "<=", ">", ">="]);
|
|
33219
33383
|
var NAN_LITERAL = { kind: "literal", value: Number.NaN, literalType: "number", raw: "NaN" };
|
|
@@ -33252,9 +33416,9 @@ function numericOperand(operand, facts) {
|
|
|
33252
33416
|
}
|
|
33253
33417
|
function stringOperand(operand, facts) {
|
|
33254
33418
|
const reading = readingOf(facts);
|
|
33255
|
-
if (reading === null)
|
|
33419
|
+
if (reading === null || reading === "either")
|
|
33256
33420
|
return operand;
|
|
33257
|
-
return coalesce(operand, facts, stringLiteral2(reading
|
|
33421
|
+
return coalesce(operand, facts, stringLiteral2(reading));
|
|
33258
33422
|
}
|
|
33259
33423
|
var PRIMITIVE_TYPES = new Set(["number", "string", "boolean"]);
|
|
33260
33424
|
function isExactly2(facts, type) {
|
|
@@ -33432,8 +33596,8 @@ var PREDICATE_EVAL = {
|
|
|
33432
33596
|
function isPredicateMethod(method) {
|
|
33433
33597
|
return Object.hasOwn(PREDICATE_EVAL, method);
|
|
33434
33598
|
}
|
|
33435
|
-
function evalBody(body, bound, propsObject,
|
|
33436
|
-
const read =
|
|
33599
|
+
function evalBody(body, bound, propsObject, site) {
|
|
33600
|
+
const read = site ? rewriteNilReadingsDeep(body, site.typing.enterCallback([...bound])) : body;
|
|
33437
33601
|
const lifted = liftPropsReads(read, bound, propsObject);
|
|
33438
33602
|
const json = serializeParsedExpr(lifted.body);
|
|
33439
33603
|
if (json === null)
|
|
@@ -33815,10 +33979,17 @@ function collectBooleanTypedProps(ir) {
|
|
|
33815
33979
|
}
|
|
33816
33980
|
function collectNullableOptionalProps(ir) {
|
|
33817
33981
|
return new Set([
|
|
33818
|
-
...ir.metadata.propsParams.filter((p) => p.defaultValue === undefined
|
|
33982
|
+
...ir.metadata.propsParams.filter((p) => !p.isRest && (p.defaultValue === undefined ? p.type?.kind !== "primitive" || p.optional : admitsNull(p.declaredType ?? p.type))).map((p) => p.name),
|
|
33819
33983
|
...ir.metadata.restPropsExpandedKeys
|
|
33820
33984
|
]);
|
|
33821
33985
|
}
|
|
33986
|
+
function admitsNull(type) {
|
|
33987
|
+
if (!type)
|
|
33988
|
+
return false;
|
|
33989
|
+
if (type.kind === "primitive")
|
|
33990
|
+
return type.primitive === "null";
|
|
33991
|
+
return type.kind === "union" && (type.unionTypes ?? []).some(admitsNull);
|
|
33992
|
+
}
|
|
33822
33993
|
function isBooleanTypedPropRef(expr, ctx) {
|
|
33823
33994
|
let bare = expr.trim();
|
|
33824
33995
|
if (ctx.propsObjectName && bare.startsWith(`${ctx.propsObjectName}.`)) {
|
|
@@ -33976,12 +34147,9 @@ class DslTemplateAdapter extends BaseAdapter {
|
|
|
33976
34147
|
}
|
|
33977
34148
|
}
|
|
33978
34149
|
arithmeticCoercion(op, operand, other, isShadowed) {
|
|
33979
|
-
return
|
|
33980
|
-
}
|
|
33981
|
-
refuseAmbiguousNilArithmeticIn(expr, params) {
|
|
33982
|
-
refuseAmbiguousNilArithmetic(expr, this.nullishAttrCtx, this.scope.enterCallback(params), this.ambiguousNilSink());
|
|
34150
|
+
return arithmeticOperandCoercion(op, operand, other, this.nullishAttrCtx, isShadowed);
|
|
33983
34151
|
}
|
|
33984
|
-
|
|
34152
|
+
errorSink() {
|
|
33985
34153
|
return { errors: this.errors, componentName: this.componentName };
|
|
33986
34154
|
}
|
|
33987
34155
|
loopPlanFor(loop, spelling) {
|
|
@@ -34067,10 +34235,13 @@ ${children}` : children;
|
|
|
34067
34235
|
this.rootPropAliases = rootPropAliasNames(ir, this.propsParams.map((p) => p.name));
|
|
34068
34236
|
this.scope = BindingScope.forComponent(this.propsObjectName);
|
|
34069
34237
|
this.nullableOptionalProps = collectNullableOptionalProps(ir);
|
|
34070
|
-
this.nullableSignalGetters = collectNullableSignalGetters(ir);
|
|
34071
34238
|
this.nullishAttrCtx = collectNullishAttrContext(ir);
|
|
34072
34239
|
this.stringValueNames = this.stringValueNamesFor(ir);
|
|
34073
34240
|
this.declaredTypes = declaredValueTypes(ir);
|
|
34241
|
+
this.nullableSignalGetters = new Set([
|
|
34242
|
+
...collectNullableSignalGetters(ir),
|
|
34243
|
+
...memberSeededNilSignals(ir, this.declaredTypes, this.scope)
|
|
34244
|
+
]);
|
|
34074
34245
|
this.operandTyping = collectOperandTyping(ir.metadata, { namedFields: this.declaredTypes.namedFields });
|
|
34075
34246
|
this.moduleStringConsts = collectModuleStringConsts(ir.metadata.localConstants);
|
|
34076
34247
|
this._searchParamsLocals = searchParamsLocalNames(ir.metadata);
|
|
@@ -34091,10 +34262,12 @@ ${children}` : children;
|
|
|
34091
34262
|
if (!options?.siblingTemplatesRegistered) {
|
|
34092
34263
|
this.errors.push(...collectImportedLoopChildComponentErrors(ir, this.componentName, this.loopChildDiagnosticName));
|
|
34093
34264
|
}
|
|
34094
|
-
|
|
34095
|
-
refuseNonPrimitiveStrictEquality(ir, this.operandTyping, this.ambiguousNilSink());
|
|
34265
|
+
refuseNonPrimitiveStrictEquality(ir, this.operandTyping, this.errorSink());
|
|
34096
34266
|
}
|
|
34097
34267
|
}
|
|
34268
|
+
function memberSeededNilSignals(ir, types, scope) {
|
|
34269
|
+
return (ir.metadata.signals ?? []).filter((s) => s.parsed?.kind === "member" && factsOfType(declaredValueType(types, s.parsed, scope)).types.has("nil")).map((s) => s.getter);
|
|
34270
|
+
}
|
|
34098
34271
|
// src/adapters/jsx-adapter.ts
|
|
34099
34272
|
import { BF_SCOPE as BF_SCOPE4, BF_SLOT, BF_COND } from "@barefootjs/shared";
|
|
34100
34273
|
class JsxAdapter extends BaseAdapter {
|
|
@@ -34829,6 +35002,15 @@ function withNilReadings(expr, emitter) {
|
|
|
34829
35002
|
return expr;
|
|
34830
35003
|
return rewriteNilReadings(expr, emitter.primitives.typing());
|
|
34831
35004
|
}
|
|
35005
|
+
function dispatchBinary(expr, emitter, emit) {
|
|
35006
|
+
const plan = primitivePlanFor(expr, emitter);
|
|
35007
|
+
if (plan?.op === "nil-test" && plan.mode === "helper" && emitter.nilTest) {
|
|
35008
|
+
const operand = nilTestOperand(expr.left, expr.right, emitter.primitives.typing());
|
|
35009
|
+
return emitter.nilTest(plan.helper, expr.op === "!==" || expr.op === "!=", operand, emit);
|
|
35010
|
+
}
|
|
35011
|
+
refuseUnspelledNilTest(plan);
|
|
35012
|
+
return emitter.binary(expr.op, expr.left, expr.right, emit, plan);
|
|
35013
|
+
}
|
|
34832
35014
|
function withNilReadingBody(arrow, emitter) {
|
|
34833
35015
|
const body = rewriteNilReadingsDeep(arrow.body, emitter.primitives.typing().enterCallback(arrow.params));
|
|
34834
35016
|
return body === arrow.body ? arrow : { ...arrow, body };
|
|
@@ -34867,7 +35049,7 @@ function dispatchParsedExpr(original, emitter, sites) {
|
|
|
34867
35049
|
case "index-access":
|
|
34868
35050
|
return emitter.indexAccess(expr.object, expr.index, emit, primitivePlanFor(expr, emitter));
|
|
34869
35051
|
case "binary":
|
|
34870
|
-
return
|
|
35052
|
+
return dispatchBinary(expr, emitter, emit);
|
|
34871
35053
|
case "unary": {
|
|
34872
35054
|
const folded = foldNegatedNumberLiteral(expr);
|
|
34873
35055
|
if (folded)
|
|
@@ -34931,6 +35113,13 @@ function isNumberLiteralInitializer(expr) {
|
|
|
34931
35113
|
const literal = expr?.kind === "unary" && expr.op === "-" ? expr.argument : expr;
|
|
34932
35114
|
return literal?.kind === "literal" && literal.literalType === "number";
|
|
34933
35115
|
}
|
|
35116
|
+
var NUMBER_BUILTINS = new Set(["Number"]);
|
|
35117
|
+
var NUMBER_MATH_METHODS = new Set(["abs", "ceil", "floor", "max", "min", "round"]);
|
|
35118
|
+
function isNumberBuiltinCall(callee) {
|
|
35119
|
+
if (callee.kind === "identifier")
|
|
35120
|
+
return NUMBER_BUILTINS.has(callee.name);
|
|
35121
|
+
return callee.kind === "member" && !callee.computed && callee.object.kind === "identifier" && callee.object.name === "Math" && NUMBER_MATH_METHODS.has(callee.property);
|
|
35122
|
+
}
|
|
34934
35123
|
function isNumberValuedExpr(expr, isStringName, isNumberName) {
|
|
34935
35124
|
if (!expr)
|
|
34936
35125
|
return false;
|
|
@@ -34941,8 +35130,11 @@ function isNumberValuedExpr(expr, isStringName, isNumberName) {
|
|
|
34941
35130
|
if (expr.kind === "conditional") {
|
|
34942
35131
|
return isNumberValuedExpr(expr.consequent, isStringName, isNumberName) || isNumberValuedExpr(expr.alternate, isStringName, isNumberName);
|
|
34943
35132
|
}
|
|
34944
|
-
if (expr.kind === "call")
|
|
35133
|
+
if (expr.kind === "call") {
|
|
35134
|
+
if (isNumberBuiltinCall(expr.callee))
|
|
35135
|
+
return true;
|
|
34945
35136
|
return expr.callee.kind === "identifier" && expr.args.length === 0 && isNumberName(expr.callee.name);
|
|
35137
|
+
}
|
|
34946
35138
|
if (expr.kind === "member") {
|
|
34947
35139
|
return !expr.computed && expr.object.kind === "identifier" && expr.object.name === "props" && isNumberName(expr.property, true);
|
|
34948
35140
|
}
|
|
@@ -35189,6 +35381,12 @@ function planComponentProps(comp, options) {
|
|
|
35189
35381
|
push({ kind: "children", children });
|
|
35190
35382
|
return segments;
|
|
35191
35383
|
}
|
|
35384
|
+
function templatePropValue(value) {
|
|
35385
|
+
if (value.kind !== "expression" || !value.staticConstLiteral)
|
|
35386
|
+
return value;
|
|
35387
|
+
const { expr, parsed } = value.staticConstLiteral;
|
|
35388
|
+
return { kind: "expression", expr, parsed };
|
|
35389
|
+
}
|
|
35192
35390
|
function spellComponentProps(segments, spelling) {
|
|
35193
35391
|
return segments.map((segment) => {
|
|
35194
35392
|
if (segment.kind === "spread")
|
|
@@ -35197,7 +35395,7 @@ function spellComponentProps(segments, spelling) {
|
|
|
35197
35395
|
return { kind: "spread", expr: spelling.presentParam(segment.name) };
|
|
35198
35396
|
const parts = [];
|
|
35199
35397
|
for (const entry of segment.entries) {
|
|
35200
|
-
const part = spelling.entry(entry);
|
|
35398
|
+
const part = spelling.entry(entry.kind === "value" ? { ...entry, value: templatePropValue(entry.value) } : entry);
|
|
35201
35399
|
if (part)
|
|
35202
35400
|
parts.push(part);
|
|
35203
35401
|
}
|
|
@@ -38580,6 +38778,7 @@ export {
|
|
|
38580
38778
|
traceableNames,
|
|
38581
38779
|
traceUpdatePath,
|
|
38582
38780
|
testAdapter,
|
|
38781
|
+
templatePropValue,
|
|
38583
38782
|
templateNameCollisionErrors,
|
|
38584
38783
|
stringifyParsedExpr,
|
|
38585
38784
|
stringifyBooleanBranches,
|
|
@@ -38620,9 +38819,8 @@ export {
|
|
|
38620
38819
|
relationalHelper,
|
|
38621
38820
|
registerLoweringPlugin,
|
|
38622
38821
|
registerBuiltinLoweringPlugins,
|
|
38822
|
+
refuseUnspelledNilTest,
|
|
38623
38823
|
refuseNonPrimitiveStrictEquality,
|
|
38624
|
-
refuseAmbiguousNilMemoArithmetic,
|
|
38625
|
-
refuseAmbiguousNilArithmetic,
|
|
38626
38824
|
queryHrefPlugin,
|
|
38627
38825
|
queryHrefLocalNames,
|
|
38628
38826
|
queryHrefArgs,
|
|
@@ -38660,6 +38858,7 @@ export {
|
|
|
38660
38858
|
nullishChainParts,
|
|
38661
38859
|
nullableSignalAttrGetter,
|
|
38662
38860
|
nullablePropsYieldedBy,
|
|
38861
|
+
nilTestOperand,
|
|
38663
38862
|
nestedCallbackRefusal,
|
|
38664
38863
|
needsTypeBasedDetection,
|
|
38665
38864
|
needsToString,
|
|
@@ -38792,6 +38991,7 @@ export {
|
|
|
38792
38991
|
escapeBraceDelimiters,
|
|
38793
38992
|
envSignalReaderFor,
|
|
38794
38993
|
envSignalLocalNames,
|
|
38994
|
+
encodeUndefinedMembers,
|
|
38795
38995
|
enableCompilerInstrumentation,
|
|
38796
38996
|
emitParsedValue,
|
|
38797
38997
|
emitParsedExpr,
|
|
@@ -38805,6 +39005,7 @@ export {
|
|
|
38805
39005
|
describeFallback,
|
|
38806
39006
|
derivesScopeFromSlot,
|
|
38807
39007
|
deriveStashFromDefaults,
|
|
39008
|
+
decodeUndefinedMembers,
|
|
38808
39009
|
declaredValueTypes,
|
|
38809
39010
|
decideClientOnlyElision,
|
|
38810
39011
|
dangerousInnerHtmlMetacharViolation,
|
|
@@ -38861,22 +39062,20 @@ export {
|
|
|
38861
39062
|
attrValueMayBeNullish,
|
|
38862
39063
|
asCallbackMethodCall,
|
|
38863
39064
|
arrayElementType,
|
|
38864
|
-
arithmeticOperandNilIsAmbiguous,
|
|
38865
39065
|
arithmeticOperandIsUndefined,
|
|
38866
39066
|
arithmeticOperandIsNull,
|
|
38867
39067
|
arithmeticOperandCoercion,
|
|
38868
39068
|
arithmeticHelper,
|
|
38869
|
-
arithmeticCoercionOrRefuse,
|
|
38870
39069
|
applyCssLayerPrefix,
|
|
38871
39070
|
analyzeWastedReReruns,
|
|
38872
39071
|
analyzeHotSubscribers,
|
|
38873
39072
|
analyzeComponent,
|
|
38874
39073
|
analyzeClientNeeds,
|
|
38875
39074
|
analyzeBatchAdvisor,
|
|
38876
|
-
ambiguousNilArithmeticOperands,
|
|
38877
39075
|
__resetLoweringPluginsForTest,
|
|
38878
39076
|
USE_CLIENT_DIRECTIVE,
|
|
38879
39077
|
UNKNOWN_FACTS,
|
|
39078
|
+
UNDEFINED_SENTINEL,
|
|
38880
39079
|
TestAdapter,
|
|
38881
39080
|
SourceMapGenerator,
|
|
38882
39081
|
SORT_KEY_TYPES,
|