babel-plugin-react-compiler 19.0.0-beta-21e868a-20250216 → 19.0.0-beta-e1e972c-20250221
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/index.js +198 -471
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -6719,7 +6719,7 @@ var require_parentheses = __commonJS({
|
|
6719
6719
|
exports2.DoExpression = DoExpression;
|
6720
6720
|
exports2.FunctionExpression = FunctionExpression6;
|
6721
6721
|
exports2.FunctionTypeAnnotation = FunctionTypeAnnotation;
|
6722
|
-
exports2.Identifier =
|
6722
|
+
exports2.Identifier = Identifier27;
|
6723
6723
|
exports2.LogicalExpression = LogicalExpression;
|
6724
6724
|
exports2.NullableTypeAnnotation = NullableTypeAnnotation;
|
6725
6725
|
exports2.ObjectExpression = ObjectExpression;
|
@@ -6897,7 +6897,7 @@ var require_parentheses = __commonJS({
|
|
6897
6897
|
return parent.operator !== "??";
|
6898
6898
|
}
|
6899
6899
|
}
|
6900
|
-
function
|
6900
|
+
function Identifier27(node, parent, tokenContext, _inForInit, getRawIdentifier) {
|
6901
6901
|
var _node$extra;
|
6902
6902
|
const parentType = parent.type;
|
6903
6903
|
if ((_node$extra = node.extra) != null && _node$extra.parenthesized && parentType === "AssignmentExpression" && parent.left === node) {
|
@@ -8853,7 +8853,7 @@ var require_types = __commonJS({
|
|
8853
8853
|
exports2.BigIntLiteral = BigIntLiteral;
|
8854
8854
|
exports2.BooleanLiteral = BooleanLiteral;
|
8855
8855
|
exports2.DecimalLiteral = DecimalLiteral;
|
8856
|
-
exports2.Identifier =
|
8856
|
+
exports2.Identifier = Identifier27;
|
8857
8857
|
exports2.NullLiteral = NullLiteral;
|
8858
8858
|
exports2.NumericLiteral = NumericLiteral;
|
8859
8859
|
exports2.ObjectPattern = exports2.ObjectExpression = ObjectExpression;
|
@@ -8890,7 +8890,7 @@ var require_types = __commonJS({
|
|
8890
8890
|
}
|
8891
8891
|
return lastRawIdentResult = node.name;
|
8892
8892
|
}
|
8893
|
-
function
|
8893
|
+
function Identifier27(node) {
|
8894
8894
|
var _node$loc;
|
8895
8895
|
this.sourceIdentifierName(((_node$loc = node.loc) == null ? void 0 : _node$loc.identifierName) || node.name);
|
8896
8896
|
this.word(this.tokenMap ? this._getRawIdentifier(node) : node.name);
|
@@ -52492,7 +52492,7 @@ var require_parentheses2 = __commonJS({
|
|
52492
52492
|
exports2.DoExpression = DoExpression;
|
52493
52493
|
exports2.FunctionExpression = FunctionExpression6;
|
52494
52494
|
exports2.FunctionTypeAnnotation = FunctionTypeAnnotation;
|
52495
|
-
exports2.Identifier =
|
52495
|
+
exports2.Identifier = Identifier27;
|
52496
52496
|
exports2.LogicalExpression = LogicalExpression;
|
52497
52497
|
exports2.NullableTypeAnnotation = NullableTypeAnnotation;
|
52498
52498
|
exports2.ObjectExpression = ObjectExpression;
|
@@ -52670,7 +52670,7 @@ var require_parentheses2 = __commonJS({
|
|
52670
52670
|
return parent.operator !== "??";
|
52671
52671
|
}
|
52672
52672
|
}
|
52673
|
-
function
|
52673
|
+
function Identifier27(node, parent, tokenContext, _inForInit, getRawIdentifier) {
|
52674
52674
|
var _node$extra;
|
52675
52675
|
const parentType = parent.type;
|
52676
52676
|
if ((_node$extra = node.extra) != null && _node$extra.parenthesized && parentType === "AssignmentExpression" && parent.left === node) {
|
@@ -54626,7 +54626,7 @@ var require_types2 = __commonJS({
|
|
54626
54626
|
exports2.BigIntLiteral = BigIntLiteral;
|
54627
54627
|
exports2.BooleanLiteral = BooleanLiteral;
|
54628
54628
|
exports2.DecimalLiteral = DecimalLiteral;
|
54629
|
-
exports2.Identifier =
|
54629
|
+
exports2.Identifier = Identifier27;
|
54630
54630
|
exports2.NullLiteral = NullLiteral;
|
54631
54631
|
exports2.NumericLiteral = NumericLiteral;
|
54632
54632
|
exports2.ObjectPattern = exports2.ObjectExpression = ObjectExpression;
|
@@ -54663,7 +54663,7 @@ var require_types2 = __commonJS({
|
|
54663
54663
|
}
|
54664
54664
|
return lastRawIdentResult = node.name;
|
54665
54665
|
}
|
54666
|
-
function
|
54666
|
+
function Identifier27(node) {
|
54667
54667
|
var _node$loc;
|
54668
54668
|
this.sourceIdentifierName(((_node$loc = node.loc) == null ? void 0 : _node$loc.identifierName) || node.name);
|
54669
54669
|
this.word(this.tokenMap ? this._getRawIdentifier(node) : node.name);
|
@@ -98137,7 +98137,7 @@ var require_types3 = __commonJS({
|
|
98137
98137
|
Object.defineProperty(exports2, "__esModule", {
|
98138
98138
|
value: true
|
98139
98139
|
});
|
98140
|
-
exports2.Identifier =
|
98140
|
+
exports2.Identifier = Identifier27;
|
98141
98141
|
exports2.SpreadElement = exports2.RestElement = RestElement;
|
98142
98142
|
exports2.ObjectPattern = exports2.ObjectExpression = ObjectExpression;
|
98143
98143
|
exports2.ObjectMethod = ObjectMethod3;
|
@@ -98187,7 +98187,7 @@ var require_types3 = __commonJS({
|
|
98187
98187
|
return newObj;
|
98188
98188
|
}
|
98189
98189
|
}
|
98190
|
-
function
|
98190
|
+
function Identifier27(node) {
|
98191
98191
|
this.exactSource(node.loc, () => {
|
98192
98192
|
this.word(node.name);
|
98193
98193
|
});
|
@@ -117642,6 +117642,10 @@ function isMutableEffect(effect, location) {
|
|
117642
117642
|
}
|
117643
117643
|
}
|
117644
117644
|
}
|
117645
|
+
var opaquePropertyLiteral = Symbol();
|
117646
|
+
function makePropertyLiteral(value) {
|
117647
|
+
return value;
|
117648
|
+
}
|
117645
117649
|
function areEqualPaths(a, b) {
|
117646
117650
|
return a.length === b.length && a.every(
|
117647
117651
|
(item, ix) => item.property === b[ix].property && item.optional === b[ix].optional
|
@@ -118562,7 +118566,6 @@ function printInstructionValue(instrValue) {
|
|
118562
118566
|
const kind = instrValue.kind === "FunctionExpression" ? "Function" : "ObjectMethod";
|
118563
118567
|
const name2 = getFunctionName(instrValue, "");
|
118564
118568
|
const fn = printFunction(instrValue.loweredFunc.func).split("\n").map((line) => ` ${line}`).join("\n");
|
118565
|
-
const deps = instrValue.loweredFunc.dependencies.map((dep) => printPlace(dep)).join(",");
|
118566
118569
|
const context = instrValue.loweredFunc.func.context.map((dep) => printPlace(dep)).join(",");
|
118567
118570
|
const effects = instrValue.loweredFunc.func.effects?.map((effect) => {
|
118568
118571
|
if (effect.kind === "ContextMutation") {
|
@@ -118572,7 +118575,7 @@ function printInstructionValue(instrValue) {
|
|
118572
118575
|
}
|
118573
118576
|
}).join(", ") ?? "";
|
118574
118577
|
const type = printType(instrValue.loweredFunc.func.returnType).trim();
|
118575
|
-
value = `${kind} ${name2} @
|
118578
|
+
value = `${kind} ${name2} @context[${context}] @effects[${effects}]${type !== "" ? ` return${type}` : ""}:
|
118576
118579
|
${fn}`;
|
118577
118580
|
break;
|
118578
118581
|
}
|
@@ -118713,10 +118716,6 @@ ${fn}`;
|
|
118713
118716
|
value = `FinishMemoize decl=${printPlace(instrValue.decl)}`;
|
118714
118717
|
break;
|
118715
118718
|
}
|
118716
|
-
case "ReactiveFunctionValue": {
|
118717
|
-
value = `FunctionValue ${printReactiveFunction(instrValue.fn)}`;
|
118718
|
-
break;
|
118719
|
-
}
|
118720
118719
|
default: {
|
118721
118720
|
assertExhaustive(
|
118722
118721
|
instrValue,
|
@@ -119013,7 +119012,7 @@ function* eachInstructionValueOperand(instrValue) {
|
|
119013
119012
|
}
|
119014
119013
|
case "ObjectMethod":
|
119015
119014
|
case "FunctionExpression": {
|
119016
|
-
yield* instrValue.loweredFunc.
|
119015
|
+
yield* instrValue.loweredFunc.func.context;
|
119017
119016
|
break;
|
119018
119017
|
}
|
119019
119018
|
case "TaggedTemplateExpression": {
|
@@ -119317,7 +119316,7 @@ function mapInstructionValueOperands(instrValue, fn) {
|
|
119317
119316
|
}
|
119318
119317
|
case "ObjectMethod":
|
119319
119318
|
case "FunctionExpression": {
|
119320
|
-
instrValue.loweredFunc.
|
119319
|
+
instrValue.loweredFunc.func.context = instrValue.loweredFunc.func.context.map((d) => fn(d));
|
119321
119320
|
break;
|
119322
119321
|
}
|
119323
119322
|
case "TaggedTemplateExpression": {
|
@@ -123201,11 +123200,11 @@ function lowerExpression(builder, exprPath) {
|
|
123201
123200
|
right: lowerExpressionToTemporary(builder, expr.get("right")),
|
123202
123201
|
loc: leftExpr.node.loc ?? GeneratedSource
|
123203
123202
|
});
|
123204
|
-
if (typeof property === "string") {
|
123203
|
+
if (typeof property === "string" || typeof property === "number") {
|
123205
123204
|
return {
|
123206
123205
|
kind: "PropertyStore",
|
123207
123206
|
object: { ...object },
|
123208
|
-
property,
|
123207
|
+
property: makePropertyLiteral(property),
|
123209
123208
|
value: { ...newValuePlace },
|
123210
123209
|
loc: leftExpr.node.loc ?? GeneratedSource
|
123211
123210
|
};
|
@@ -123470,11 +123469,11 @@ function lowerExpression(builder, exprPath) {
|
|
123470
123469
|
const argument = expr.get("argument");
|
123471
123470
|
if (argument.isMemberExpression()) {
|
123472
123471
|
const { object, property } = lowerMemberExpression(builder, argument);
|
123473
|
-
if (typeof property === "string") {
|
123472
|
+
if (typeof property === "string" || typeof property === "number") {
|
123474
123473
|
return {
|
123475
123474
|
kind: "PropertyDelete",
|
123476
123475
|
object,
|
123477
|
-
property,
|
123476
|
+
property: makePropertyLiteral(property),
|
123478
123477
|
loc: exprLoc
|
123479
123478
|
};
|
123480
123479
|
} else {
|
@@ -123576,11 +123575,11 @@ function lowerExpression(builder, exprPath) {
|
|
123576
123575
|
loc: leftExpr.node.loc ?? GeneratedSource
|
123577
123576
|
});
|
123578
123577
|
let newValuePlace;
|
123579
|
-
if (typeof property === "string") {
|
123578
|
+
if (typeof property === "string" || typeof property === "number") {
|
123580
123579
|
newValuePlace = lowerValueToTemporary(builder, {
|
123581
123580
|
kind: "PropertyStore",
|
123582
123581
|
object: { ...object },
|
123583
|
-
property,
|
123582
|
+
property: makePropertyLiteral(property),
|
123584
123583
|
value: { ...updatedValue },
|
123585
123584
|
loc: leftExpr.node.loc ?? GeneratedSource
|
123586
123585
|
});
|
@@ -124084,8 +124083,13 @@ function lowerMemberExpression(builder, expr, loweredObject = null) {
|
|
124084
124083
|
const objectNode = expr.get("object");
|
124085
124084
|
const propertyNode = expr.get("property");
|
124086
124085
|
const object = loweredObject ?? lowerExpressionToTemporary(builder, objectNode);
|
124087
|
-
if (!expr.node.computed) {
|
124088
|
-
|
124086
|
+
if (!expr.node.computed || expr.node.property.type === "NumericLiteral") {
|
124087
|
+
let property;
|
124088
|
+
if (propertyNode.isIdentifier()) {
|
124089
|
+
property = makePropertyLiteral(propertyNode.node.name);
|
124090
|
+
} else if (propertyNode.isNumericLiteral()) {
|
124091
|
+
property = makePropertyLiteral(propertyNode.node.value);
|
124092
|
+
} else {
|
124089
124093
|
builder.errors.push({
|
124090
124094
|
reason: `(BuildHIR::lowerMemberExpression) Handle ${propertyNode.type} property`,
|
124091
124095
|
severity: "Todo" /* Todo */,
|
@@ -124101,10 +124105,10 @@ function lowerMemberExpression(builder, expr, loweredObject = null) {
|
|
124101
124105
|
const value = {
|
124102
124106
|
kind: "PropertyLoad",
|
124103
124107
|
object: { ...object },
|
124104
|
-
property
|
124108
|
+
property,
|
124105
124109
|
loc: exprLoc
|
124106
124110
|
};
|
124107
|
-
return { object, property
|
124111
|
+
return { object, property, value };
|
124108
124112
|
} else {
|
124109
124113
|
if (!propertyNode.isExpression()) {
|
124110
124114
|
builder.errors.push({
|
@@ -124211,7 +124215,7 @@ function lowerJsxMemberExpression(builder, exprPath) {
|
|
124211
124215
|
return lowerValueToTemporary(builder, {
|
124212
124216
|
kind: "PropertyLoad",
|
124213
124217
|
object: objectPlace,
|
124214
|
-
property,
|
124218
|
+
property: makePropertyLiteral(property),
|
124215
124219
|
loc
|
124216
124220
|
});
|
124217
124221
|
}
|
@@ -124319,12 +124323,12 @@ function lowerFunctionToValue(builder, expr) {
|
|
124319
124323
|
}
|
124320
124324
|
function lowerFunction(builder, expr) {
|
124321
124325
|
const componentScope = builder.parentFunction.scope;
|
124322
|
-
const
|
124326
|
+
const capturedContext = gatherCapturedContext(expr, componentScope);
|
124323
124327
|
const lowering = lower(
|
124324
124328
|
expr,
|
124325
124329
|
builder.environment,
|
124326
124330
|
builder.bindings,
|
124327
|
-
[...builder.context, ...
|
124331
|
+
[...builder.context, ...capturedContext],
|
124328
124332
|
builder.parentFunction
|
124329
124333
|
);
|
124330
124334
|
let loweredFunc;
|
@@ -124334,8 +124338,7 @@ function lowerFunction(builder, expr) {
|
|
124334
124338
|
}
|
124335
124339
|
loweredFunc = lowering.unwrap();
|
124336
124340
|
return {
|
124337
|
-
func: loweredFunc
|
124338
|
-
dependencies: captured.refs
|
124341
|
+
func: loweredFunc
|
124339
124342
|
};
|
124340
124343
|
}
|
124341
124344
|
function lowerExpressionToTemporary(builder, exprPath) {
|
@@ -124511,8 +124514,25 @@ function lowerAssignment(builder, loc, kind, lvaluePath, value, assignmentKind)
|
|
124511
124514
|
const lvalue = lvaluePath;
|
124512
124515
|
const property = lvalue.get("property");
|
124513
124516
|
const object = lowerExpressionToTemporary(builder, lvalue.get("object"));
|
124514
|
-
if (!lvalue.node.computed) {
|
124515
|
-
|
124517
|
+
if (!lvalue.node.computed || lvalue.get("property").isNumericLiteral()) {
|
124518
|
+
let temporary;
|
124519
|
+
if (property.isIdentifier()) {
|
124520
|
+
temporary = lowerValueToTemporary(builder, {
|
124521
|
+
kind: "PropertyStore",
|
124522
|
+
object,
|
124523
|
+
property: makePropertyLiteral(property.node.name),
|
124524
|
+
value,
|
124525
|
+
loc
|
124526
|
+
});
|
124527
|
+
} else if (property.isNumericLiteral()) {
|
124528
|
+
temporary = lowerValueToTemporary(builder, {
|
124529
|
+
kind: "PropertyStore",
|
124530
|
+
object,
|
124531
|
+
property: makePropertyLiteral(property.node.value),
|
124532
|
+
value,
|
124533
|
+
loc
|
124534
|
+
});
|
124535
|
+
} else {
|
124516
124536
|
builder.errors.push({
|
124517
124537
|
reason: `(BuildHIR::lowerAssignment) Handle ${property.type} properties in MemberExpression`,
|
124518
124538
|
severity: "Todo" /* Todo */,
|
@@ -124521,13 +124541,6 @@ function lowerAssignment(builder, loc, kind, lvaluePath, value, assignmentKind)
|
|
124521
124541
|
});
|
124522
124542
|
return { kind: "UnsupportedNode", node: lvalueNode, loc };
|
124523
124543
|
}
|
124524
|
-
const temporary = lowerValueToTemporary(builder, {
|
124525
|
-
kind: "PropertyStore",
|
124526
|
-
object,
|
124527
|
-
property: property.node.name,
|
124528
|
-
value,
|
124529
|
-
loc
|
124530
|
-
});
|
124531
124544
|
return { kind: "LoadLocal", place: temporary, loc: temporary.loc };
|
124532
124545
|
} else {
|
124533
124546
|
if (!property.isExpression()) {
|
@@ -124901,10 +124914,6 @@ function lowerAssignment(builder, loc, kind, lvaluePath, value, assignmentKind)
|
|
124901
124914
|
}
|
124902
124915
|
}
|
124903
124916
|
}
|
124904
|
-
function isValidDependency(path) {
|
124905
|
-
const parent = path.parentPath;
|
124906
|
-
return !path.node.computed && !(parent.isCallExpression() && parent.get("callee") === path);
|
124907
|
-
}
|
124908
124917
|
function captureScopes({ from, to }) {
|
124909
124918
|
let scopes = /* @__PURE__ */ new Set();
|
124910
124919
|
while (from) {
|
@@ -124916,26 +124925,14 @@ function captureScopes({ from, to }) {
|
|
124916
124925
|
}
|
124917
124926
|
return scopes;
|
124918
124927
|
}
|
124919
|
-
function
|
124920
|
-
const capturedIds = /* @__PURE__ */ new
|
124921
|
-
const capturedRefs = /* @__PURE__ */ new Set();
|
124922
|
-
const seenPaths = /* @__PURE__ */ new Set();
|
124928
|
+
function gatherCapturedContext(fn, componentScope) {
|
124929
|
+
const capturedIds = /* @__PURE__ */ new Set();
|
124923
124930
|
const pureScopes = captureScopes({
|
124924
124931
|
from: fn.scope.parent,
|
124925
124932
|
to: componentScope
|
124926
124933
|
});
|
124927
|
-
function addCapturedId(bindingIdentifier) {
|
124928
|
-
if (!capturedIds.has(bindingIdentifier)) {
|
124929
|
-
const index = capturedIds.size;
|
124930
|
-
capturedIds.set(bindingIdentifier, index);
|
124931
|
-
return index;
|
124932
|
-
} else {
|
124933
|
-
return capturedIds.get(bindingIdentifier);
|
124934
|
-
}
|
124935
|
-
}
|
124936
124934
|
function handleMaybeDependency(path) {
|
124937
124935
|
let baseIdentifier;
|
124938
|
-
let dependency;
|
124939
124936
|
if (path.isJSXOpeningElement()) {
|
124940
124937
|
const name2 = path.get("name");
|
124941
124938
|
if (!(name2.isJSXMemberExpression() || name2.isJSXIdentifier())) {
|
@@ -124950,79 +124947,13 @@ function gatherCapturedDeps(builder, fn, componentScope) {
|
|
124950
124947
|
"Invalid logic in gatherCapturedDeps"
|
124951
124948
|
);
|
124952
124949
|
baseIdentifier = current;
|
124953
|
-
let currentDep = baseIdentifier;
|
124954
|
-
while (true) {
|
124955
|
-
const nextDep = currentDep.parentPath;
|
124956
|
-
if (nextDep && nextDep.isJSXMemberExpression()) {
|
124957
|
-
currentDep = nextDep;
|
124958
|
-
} else {
|
124959
|
-
break;
|
124960
|
-
}
|
124961
|
-
}
|
124962
|
-
dependency = currentDep;
|
124963
|
-
} else if (path.isMemberExpression()) {
|
124964
|
-
let currentId = path;
|
124965
|
-
while (currentId.isMemberExpression()) {
|
124966
|
-
currentId = currentId.get("object");
|
124967
|
-
}
|
124968
|
-
if (!currentId.isIdentifier()) {
|
124969
|
-
return;
|
124970
|
-
}
|
124971
|
-
baseIdentifier = currentId;
|
124972
|
-
let currentDep = baseIdentifier;
|
124973
|
-
while (true) {
|
124974
|
-
const nextDep = currentDep.parentPath;
|
124975
|
-
if (nextDep && nextDep.isMemberExpression() && isValidDependency(nextDep)) {
|
124976
|
-
currentDep = nextDep;
|
124977
|
-
} else {
|
124978
|
-
break;
|
124979
|
-
}
|
124980
|
-
}
|
124981
|
-
dependency = currentDep;
|
124982
124950
|
} else {
|
124983
124951
|
baseIdentifier = path;
|
124984
|
-
dependency = path;
|
124985
124952
|
}
|
124986
|
-
|
124953
|
+
path.skip();
|
124987
124954
|
const binding = baseIdentifier.scope.getBinding(baseIdentifier.node.name);
|
124988
|
-
if (binding
|
124989
|
-
|
124990
|
-
}
|
124991
|
-
const idKey = String(addCapturedId(binding.identifier));
|
124992
|
-
let exprKey = idKey;
|
124993
|
-
if (dependency.isMemberExpression()) {
|
124994
|
-
let pathTokens = [];
|
124995
|
-
let current = dependency;
|
124996
|
-
while (current.isMemberExpression()) {
|
124997
|
-
const property = current.get("property");
|
124998
|
-
pathTokens.push(property.node.name);
|
124999
|
-
current = current.get("object");
|
125000
|
-
}
|
125001
|
-
exprKey += "." + pathTokens.reverse().join(".");
|
125002
|
-
} else if (dependency.isJSXMemberExpression()) {
|
125003
|
-
let pathTokens = [];
|
125004
|
-
let current = dependency;
|
125005
|
-
while (current.isJSXMemberExpression()) {
|
125006
|
-
const property = current.get("property");
|
125007
|
-
pathTokens.push(property.node.name);
|
125008
|
-
current = current.get("object");
|
125009
|
-
}
|
125010
|
-
}
|
125011
|
-
if (!seenPaths.has(exprKey)) {
|
125012
|
-
let loweredDep;
|
125013
|
-
if (dependency.isJSXIdentifier()) {
|
125014
|
-
loweredDep = lowerValueToTemporary(builder, {
|
125015
|
-
kind: "LoadLocal",
|
125016
|
-
place: lowerIdentifier(builder, dependency),
|
125017
|
-
loc: path.node.loc ?? GeneratedSource
|
125018
|
-
});
|
125019
|
-
} else if (dependency.isJSXMemberExpression()) {
|
125020
|
-
loweredDep = lowerJsxMemberExpression(builder, dependency);
|
125021
|
-
} else {
|
125022
|
-
loweredDep = lowerExpressionToTemporary(builder, dependency);
|
125023
|
-
}
|
125024
|
-
capturedRefs.add(loweredDep);
|
125025
|
-
seenPaths.add(exprKey);
|
124955
|
+
if (binding !== void 0 && pureScopes.has(binding.scope)) {
|
124956
|
+
capturedIds.add(binding.identifier);
|
125026
124957
|
}
|
125027
124958
|
}
|
125028
124959
|
fn.traverse({
|
@@ -125047,12 +124978,12 @@ function gatherCapturedDeps(builder, fn, componentScope) {
|
|
125047
124978
|
return;
|
125048
124979
|
} else if (path.isJSXElement()) {
|
125049
124980
|
handleMaybeDependency(path.get("openingElement"));
|
125050
|
-
} else if (path.
|
124981
|
+
} else if (path.isIdentifier()) {
|
125051
124982
|
handleMaybeDependency(path);
|
125052
124983
|
}
|
125053
124984
|
}
|
125054
124985
|
});
|
125055
|
-
return
|
124986
|
+
return [...capturedIds.keys()];
|
125056
124987
|
}
|
125057
124988
|
function notNull(value) {
|
125058
124989
|
return value !== null;
|
@@ -126322,7 +126253,6 @@ var EnvironmentConfigSchema = z.object({
|
|
126322
126253
|
* enables trusting user type annotations.
|
126323
126254
|
*/
|
126324
126255
|
enableUseTypeAnnotations: z.boolean().default(false),
|
126325
|
-
enableFunctionDependencyRewrite: z.boolean().default(true),
|
126326
126256
|
/**
|
126327
126257
|
* Enables inference of optional dependency chains. Without this flag
|
126328
126258
|
* a property chain such as `props?.items?.foo` will infer as a dep on
|
@@ -127518,6 +127448,11 @@ function findDisjointMutableValues(fn) {
|
|
127518
127448
|
* TODO: improve handling of module-scoped variables and globals
|
127519
127449
|
*/
|
127520
127450
|
operand.identifier.mutableRange.start > 0) {
|
127451
|
+
if (instr.value.kind === "FunctionExpression" || instr.value.kind === "ObjectMethod") {
|
127452
|
+
if (operand.identifier.type.kind === "Primitive") {
|
127453
|
+
continue;
|
127454
|
+
}
|
127455
|
+
}
|
127521
127456
|
operands.push(operand.identifier);
|
127522
127457
|
}
|
127523
127458
|
}
|
@@ -127637,6 +127572,9 @@ function getOverlappingReactiveScopes(fn, context) {
|
|
127637
127572
|
for (const instr of block.instructions) {
|
127638
127573
|
visitInstructionId(instr.id, context, state);
|
127639
127574
|
for (const place of eachInstructionOperand(instr)) {
|
127575
|
+
if ((instr.value.kind === "FunctionExpression" || instr.value.kind === "ObjectMethod") && place.identifier.type.kind === "Primitive") {
|
127576
|
+
continue;
|
127577
|
+
}
|
127640
127578
|
visitPlace(instr.id, place, state);
|
127641
127579
|
}
|
127642
127580
|
for (const place of eachInstructionLValue(instr)) {
|
@@ -128122,6 +128060,7 @@ function nonNull(t5) {
|
|
128122
128060
|
var import_types2 = require("@babel/types");
|
128123
128061
|
|
128124
128062
|
// src/SSA/EliminateRedundantPhi.ts
|
128063
|
+
var DEBUG = false;
|
128125
128064
|
function eliminateRedundantPhi(fn, sharedRewrites) {
|
128126
128065
|
const ir = fn.body;
|
128127
128066
|
const rewrites = sharedRewrites != null ? sharedRewrites : /* @__PURE__ */ new Map();
|
@@ -128181,6 +128120,22 @@ function eliminateRedundantPhi(fn, sharedRewrites) {
|
|
128181
128120
|
}
|
128182
128121
|
}
|
128183
128122
|
} while (rewrites.size > size && hasBackEdge2);
|
128123
|
+
if (DEBUG) {
|
128124
|
+
for (const [, block] of ir.blocks) {
|
128125
|
+
for (const phi of block.phis) {
|
128126
|
+
CompilerError.invariant(!rewrites.has(phi.place.identifier), {
|
128127
|
+
reason: "[EliminateRedundantPhis]: rewrite not complete",
|
128128
|
+
loc: phi.place.loc
|
128129
|
+
});
|
128130
|
+
for (const [, operand] of phi.operands) {
|
128131
|
+
CompilerError.invariant(!rewrites.has(operand.identifier), {
|
128132
|
+
reason: "[EliminateRedundantPhis]: rewrite not complete",
|
128133
|
+
loc: phi.place.loc
|
128134
|
+
});
|
128135
|
+
}
|
128136
|
+
}
|
128137
|
+
}
|
128138
|
+
}
|
128184
128139
|
}
|
128185
128140
|
function rewritePlace(place, rewrites) {
|
128186
128141
|
const rewrite = rewrites.get(place.identifier);
|
@@ -128398,9 +128353,6 @@ function enterSSAImpl(func, builder, rootEntry) {
|
|
128398
128353
|
entry.preds.add(blockId);
|
128399
128354
|
builder.defineFunction(loweredFunc);
|
128400
128355
|
builder.enter(() => {
|
128401
|
-
loweredFunc.context = loweredFunc.context.map(
|
128402
|
-
(p) => builder.getPlace(p)
|
128403
|
-
);
|
128404
128356
|
loweredFunc.params = loweredFunc.params.map((param) => {
|
128405
128357
|
if (param.kind === "Identifier") {
|
128406
128358
|
return builder.definePlace(param);
|
@@ -128706,11 +128658,11 @@ function evaluateInstruction(constants, instr) {
|
|
128706
128658
|
}
|
128707
128659
|
case "ComputedLoad": {
|
128708
128660
|
const property = read(constants, value.property);
|
128709
|
-
if (property !== null && property.kind === "Primitive" && typeof property.value === "string" && (0, import_types2.isValidIdentifier)(property.value)) {
|
128661
|
+
if (property !== null && property.kind === "Primitive" && (typeof property.value === "string" && (0, import_types2.isValidIdentifier)(property.value) || typeof property.value === "number")) {
|
128710
128662
|
const nextValue = {
|
128711
128663
|
kind: "PropertyLoad",
|
128712
128664
|
loc: value.loc,
|
128713
|
-
property: property.value,
|
128665
|
+
property: makePropertyLiteral(property.value),
|
128714
128666
|
object: value.object
|
128715
128667
|
};
|
128716
128668
|
instr.value = nextValue;
|
@@ -128719,11 +128671,11 @@ function evaluateInstruction(constants, instr) {
|
|
128719
128671
|
}
|
128720
128672
|
case "ComputedStore": {
|
128721
128673
|
const property = read(constants, value.property);
|
128722
|
-
if (property !== null && property.kind === "Primitive" && typeof property.value === "string" && (0, import_types2.isValidIdentifier)(property.value)) {
|
128674
|
+
if (property !== null && property.kind === "Primitive" && (typeof property.value === "string" && (0, import_types2.isValidIdentifier)(property.value) || typeof property.value === "number")) {
|
128723
128675
|
const nextValue = {
|
128724
128676
|
kind: "PropertyStore",
|
128725
128677
|
loc: value.loc,
|
128726
|
-
property: property.value,
|
128678
|
+
property: makePropertyLiteral(property.value),
|
128727
128679
|
object: value.object,
|
128728
128680
|
value: value.value
|
128729
128681
|
};
|
@@ -129615,7 +129567,7 @@ function createSymbolProperty(fn, instr, nextInstructions, propertyName, symbolN
|
|
129615
129567
|
value: {
|
129616
129568
|
kind: "PropertyLoad",
|
129617
129569
|
object: { ...symbolInstruction.lvalue },
|
129618
|
-
property: "for",
|
129570
|
+
property: makePropertyLiteral("for"),
|
129619
129571
|
loc: instr.value.loc
|
129620
129572
|
},
|
129621
129573
|
loc: instr.loc
|
@@ -129990,15 +129942,6 @@ var ReactiveFunctionVisitor = class {
|
|
129990
129942
|
this.visitValue(value.id, value.value, state);
|
129991
129943
|
break;
|
129992
129944
|
}
|
129993
|
-
case "ReactiveFunctionValue": {
|
129994
|
-
this.visitReactiveFunctionValue(
|
129995
|
-
id,
|
129996
|
-
value.dependencies,
|
129997
|
-
value.fn,
|
129998
|
-
state
|
129999
|
-
);
|
130000
|
-
break;
|
130001
|
-
}
|
130002
129945
|
default: {
|
130003
129946
|
for (const place of eachInstructionValueOperand(value)) {
|
130004
129947
|
this.visitPlace(id, place, state);
|
@@ -130294,18 +130237,6 @@ var ReactiveFunctionTransform = class extends ReactiveFunctionVisitor {
|
|
130294
130237
|
}
|
130295
130238
|
break;
|
130296
130239
|
}
|
130297
|
-
case "ReactiveFunctionValue": {
|
130298
|
-
const nextValue = this.transformReactiveFunctionValue(
|
130299
|
-
id,
|
130300
|
-
value.dependencies,
|
130301
|
-
value.fn,
|
130302
|
-
state
|
130303
|
-
);
|
130304
|
-
if (nextValue.kind === "replace") {
|
130305
|
-
value.fn = nextValue.value;
|
130306
|
-
}
|
130307
|
-
break;
|
130308
|
-
}
|
130309
130240
|
default: {
|
130310
130241
|
for (const place of eachInstructionValueOperand(value)) {
|
130311
130242
|
this.visitPlace(id, place, state);
|
@@ -130468,10 +130399,6 @@ function* eachReactiveValueOperand(instrValue) {
|
|
130468
130399
|
yield* eachReactiveValueOperand(instrValue.alternate);
|
130469
130400
|
break;
|
130470
130401
|
}
|
130471
|
-
case "ReactiveFunctionValue": {
|
130472
|
-
yield* instrValue.dependencies;
|
130473
|
-
break;
|
130474
|
-
}
|
130475
130402
|
default: {
|
130476
130403
|
yield* eachInstructionValueOperand(instrValue);
|
130477
130404
|
}
|
@@ -133061,15 +132988,17 @@ function codegenDependency(cx, dependency) {
|
|
133061
132988
|
if (dependency.path.length !== 0) {
|
133062
132989
|
const hasOptional = dependency.path.some((path) => path.optional);
|
133063
132990
|
for (const path of dependency.path) {
|
132991
|
+
const property = typeof path.property === "string" ? t4.identifier(path.property) : t4.numericLiteral(path.property);
|
132992
|
+
const isComputed = typeof path.property !== "string";
|
133064
132993
|
if (hasOptional) {
|
133065
132994
|
object = t4.optionalMemberExpression(
|
133066
132995
|
object,
|
133067
|
-
|
133068
|
-
|
132996
|
+
property,
|
132997
|
+
isComputed,
|
133069
132998
|
path.optional
|
133070
132999
|
);
|
133071
133000
|
} else {
|
133072
|
-
object = t4.memberExpression(object,
|
133001
|
+
object = t4.memberExpression(object, property, isComputed);
|
133073
133002
|
}
|
133074
133003
|
}
|
133075
133004
|
}
|
@@ -133481,34 +133410,33 @@ function codegenInstructionValue(cx, instrValue) {
|
|
133481
133410
|
value = node;
|
133482
133411
|
break;
|
133483
133412
|
}
|
133484
|
-
case "PropertyStore":
|
133485
|
-
|
133486
|
-
"=",
|
133487
|
-
t4.memberExpression(
|
133488
|
-
codegenPlaceToExpression(cx, instrValue.object),
|
133489
|
-
t4.identifier(instrValue.property)
|
133490
|
-
),
|
133491
|
-
codegenPlaceToExpression(cx, instrValue.value)
|
133492
|
-
);
|
133493
|
-
break;
|
133494
|
-
}
|
133495
|
-
case "PropertyLoad": {
|
133496
|
-
const object = codegenPlaceToExpression(cx, instrValue.object);
|
133497
|
-
value = t4.memberExpression(
|
133498
|
-
object,
|
133499
|
-
t4.identifier(instrValue.property),
|
133500
|
-
void 0
|
133501
|
-
);
|
133502
|
-
break;
|
133503
|
-
}
|
133413
|
+
case "PropertyStore":
|
133414
|
+
case "PropertyLoad":
|
133504
133415
|
case "PropertyDelete": {
|
133505
|
-
|
133506
|
-
|
133507
|
-
t4.memberExpression(
|
133416
|
+
let memberExpr;
|
133417
|
+
if (typeof instrValue.property === "string") {
|
133418
|
+
memberExpr = t4.memberExpression(
|
133508
133419
|
codegenPlaceToExpression(cx, instrValue.object),
|
133509
133420
|
t4.identifier(instrValue.property)
|
133510
|
-
)
|
133511
|
-
|
133421
|
+
);
|
133422
|
+
} else {
|
133423
|
+
memberExpr = t4.memberExpression(
|
133424
|
+
codegenPlaceToExpression(cx, instrValue.object),
|
133425
|
+
t4.numericLiteral(instrValue.property),
|
133426
|
+
true
|
133427
|
+
);
|
133428
|
+
}
|
133429
|
+
if (instrValue.kind === "PropertyStore") {
|
133430
|
+
value = t4.assignmentExpression(
|
133431
|
+
"=",
|
133432
|
+
memberExpr,
|
133433
|
+
codegenPlaceToExpression(cx, instrValue.value)
|
133434
|
+
);
|
133435
|
+
} else if (instrValue.kind === "PropertyLoad") {
|
133436
|
+
value = memberExpr;
|
133437
|
+
} else {
|
133438
|
+
value = t4.unaryExpression("delete", memberExpr);
|
133439
|
+
}
|
133512
133440
|
break;
|
133513
133441
|
}
|
133514
133442
|
case "ComputedStore": {
|
@@ -133743,7 +133671,6 @@ function codegenInstructionValue(cx, instrValue) {
|
|
133743
133671
|
);
|
133744
133672
|
break;
|
133745
133673
|
}
|
133746
|
-
case "ReactiveFunctionValue":
|
133747
133674
|
case "StartMemoize":
|
133748
133675
|
case "FinishMemoize":
|
133749
133676
|
case "Debugger":
|
@@ -134133,9 +134060,9 @@ function mergeReactiveScopesThatInvalidateTogether(fn) {
|
|
134133
134060
|
visitReactiveFunction(fn, lastUsageVisitor, void 0);
|
134134
134061
|
visitReactiveFunction(fn, new Transform(lastUsageVisitor.lastUsage), null);
|
134135
134062
|
}
|
134136
|
-
var
|
134063
|
+
var DEBUG2 = false;
|
134137
134064
|
function log(msg) {
|
134138
|
-
if (
|
134065
|
+
if (DEBUG2) {
|
134139
134066
|
console.log(msg);
|
134140
134067
|
}
|
134141
134068
|
}
|
@@ -134802,7 +134729,7 @@ var Transform2 = class extends ReactiveFunctionTransform {
|
|
134802
134729
|
value: {
|
134803
134730
|
kind: "PropertyLoad",
|
134804
134731
|
object: { ...symbolTemp },
|
134805
|
-
property: "for",
|
134732
|
+
property: makePropertyLiteral("for"),
|
134806
134733
|
loc
|
134807
134734
|
}
|
134808
134735
|
}
|
@@ -135454,20 +135381,19 @@ var InferenceState = class _InferenceState {
|
|
135454
135381
|
}
|
135455
135382
|
freezeValues(values, reason) {
|
135456
135383
|
for (const value of values) {
|
135384
|
+
if (value.kind === "DeclareContext") {
|
135385
|
+
continue;
|
135386
|
+
}
|
135457
135387
|
this.#values.set(value, {
|
135458
135388
|
kind: "frozen" /* Frozen */,
|
135459
135389
|
reason,
|
135460
135390
|
context: /* @__PURE__ */ new Set()
|
135461
135391
|
});
|
135462
|
-
if (value.kind === "FunctionExpression") {
|
135463
|
-
|
135464
|
-
|
135465
|
-
|
135466
|
-
|
135467
|
-
if (operandValues !== void 0) {
|
135468
|
-
this.freezeValues(operandValues, reason);
|
135469
|
-
}
|
135470
|
-
}
|
135392
|
+
if (value.kind === "FunctionExpression" && (this.#env.config.enablePreserveExistingMemoizationGuarantees || this.#env.config.enableTransitivelyFreezeFunctionExpressions)) {
|
135393
|
+
for (const operand of value.loweredFunc.func.context) {
|
135394
|
+
const operandValues = this.#variables.get(operand.identifier.id);
|
135395
|
+
if (operandValues !== void 0) {
|
135396
|
+
this.freezeValues(operandValues, reason);
|
135471
135397
|
}
|
135472
135398
|
}
|
135473
135399
|
}
|
@@ -136025,17 +135951,17 @@ function inferBlock(env, state, block, functionEffects) {
|
|
136025
135951
|
case "ObjectMethod":
|
136026
135952
|
case "FunctionExpression": {
|
136027
135953
|
let hasMutableOperand = false;
|
136028
|
-
const mutableOperands = [];
|
136029
135954
|
for (const operand of eachInstructionOperand(instr)) {
|
135955
|
+
CompilerError.invariant(operand.effect !== "<unknown>" /* Unknown */, {
|
135956
|
+
reason: "Expected fn effects to be populated",
|
135957
|
+
loc: operand.loc
|
135958
|
+
});
|
136030
135959
|
state.referenceAndRecordEffects(
|
136031
135960
|
freezeActions,
|
136032
135961
|
operand,
|
136033
|
-
operand.effect
|
135962
|
+
operand.effect,
|
136034
135963
|
"other" /* Other */
|
136035
135964
|
);
|
136036
|
-
if (isMutableEffect(operand.effect, operand.loc)) {
|
136037
|
-
mutableOperands.push(operand);
|
136038
|
-
}
|
136039
135965
|
hasMutableOperand ||= isMutableEffect(operand.effect, operand.loc);
|
136040
135966
|
}
|
136041
135967
|
state.initialize(instrValue, {
|
@@ -136411,13 +136337,6 @@ function inferBlock(env, state, block, functionEffects) {
|
|
136411
136337
|
}
|
136412
136338
|
case "LoadLocal": {
|
136413
136339
|
const lvalue = instr.lvalue;
|
136414
|
-
CompilerError.invariant(
|
136415
|
-
!(state.isDefined(lvalue) && state.kind(lvalue).kind === "context" /* Context */),
|
136416
|
-
{
|
136417
|
-
reason: "[InferReferenceEffects] Unexpected LoadLocal with context kind",
|
136418
|
-
loc: lvalue.loc
|
136419
|
-
}
|
136420
|
-
);
|
136421
136340
|
state.referenceAndRecordEffects(
|
136422
136341
|
freezeActions,
|
136423
136342
|
instrValue.place,
|
@@ -137212,14 +137131,6 @@ function computeMemoizationInputs(env, value, lvalue, options) {
|
|
137212
137131
|
rvalues: operands
|
137213
137132
|
};
|
137214
137133
|
}
|
137215
|
-
case "ReactiveFunctionValue": {
|
137216
|
-
CompilerError.invariant(false, {
|
137217
|
-
reason: `Unexpected ReactiveFunctionValue node`,
|
137218
|
-
description: null,
|
137219
|
-
loc: value.loc,
|
137220
|
-
suggestions: null
|
137221
|
-
});
|
137222
|
-
}
|
137223
137134
|
case "UnsupportedNode": {
|
137224
137135
|
CompilerError.invariant(false, {
|
137225
137136
|
reason: `Unexpected unsupported node`,
|
@@ -137810,56 +137721,6 @@ var RewriteBlockIds = class extends ReactiveFunctionVisitor {
|
|
137810
137721
|
}
|
137811
137722
|
};
|
137812
137723
|
|
137813
|
-
// src/Inference/InferMutableContextVariables.ts
|
137814
|
-
function inferMutableContextVariables(fn) {
|
137815
|
-
const state = new IdentifierState();
|
137816
|
-
const knownMutatedIdentifiers = /* @__PURE__ */ new Set();
|
137817
|
-
for (const [, block] of fn.body.blocks) {
|
137818
|
-
for (const instr of block.instructions) {
|
137819
|
-
switch (instr.value.kind) {
|
137820
|
-
case "PropertyLoad": {
|
137821
|
-
state.declareProperty(
|
137822
|
-
instr.lvalue,
|
137823
|
-
instr.value.object,
|
137824
|
-
instr.value.property
|
137825
|
-
);
|
137826
|
-
break;
|
137827
|
-
}
|
137828
|
-
case "ComputedLoad": {
|
137829
|
-
state.declareProperty(instr.lvalue, instr.value.object, "");
|
137830
|
-
break;
|
137831
|
-
}
|
137832
|
-
case "LoadLocal":
|
137833
|
-
case "LoadContext": {
|
137834
|
-
if (instr.lvalue.identifier.name === null) {
|
137835
|
-
state.declareTemporary(instr.lvalue, instr.value.place);
|
137836
|
-
}
|
137837
|
-
break;
|
137838
|
-
}
|
137839
|
-
default: {
|
137840
|
-
for (const operand of eachInstructionValueOperand(instr.value)) {
|
137841
|
-
visitOperand(state, knownMutatedIdentifiers, operand);
|
137842
|
-
}
|
137843
|
-
}
|
137844
|
-
}
|
137845
|
-
}
|
137846
|
-
for (const operand of eachTerminalOperand(block.terminal)) {
|
137847
|
-
visitOperand(state, knownMutatedIdentifiers, operand);
|
137848
|
-
}
|
137849
|
-
}
|
137850
|
-
for (const operand of fn.context) {
|
137851
|
-
if (knownMutatedIdentifiers.has(operand.identifier)) {
|
137852
|
-
operand.effect = "mutate" /* Mutate */;
|
137853
|
-
}
|
137854
|
-
}
|
137855
|
-
}
|
137856
|
-
function visitOperand(state, knownMutatedIdentifiers, operand) {
|
137857
|
-
const resolved = state.resolve(operand.identifier);
|
137858
|
-
if (operand.effect === "mutate" /* Mutate */ || operand.effect === "store" /* Store */) {
|
137859
|
-
knownMutatedIdentifiers.add(resolved);
|
137860
|
-
}
|
137861
|
-
}
|
137862
|
-
|
137863
137724
|
// src/Inference/InferAlias.ts
|
137864
137725
|
function inferAliases(func) {
|
137865
137726
|
const aliases = new DisjointSet();
|
@@ -138123,65 +137984,18 @@ function areEqualMaps(a, b) {
|
|
138123
137984
|
}
|
138124
137985
|
|
138125
137986
|
// src/Inference/AnalyseFunctions.ts
|
138126
|
-
var IdentifierState = class {
|
138127
|
-
constructor() {
|
138128
|
-
this.properties = /* @__PURE__ */ new Map();
|
138129
|
-
}
|
138130
|
-
resolve(identifier4) {
|
138131
|
-
const resolved = this.properties.get(identifier4);
|
138132
|
-
if (resolved !== void 0) {
|
138133
|
-
return resolved.identifier;
|
138134
|
-
}
|
138135
|
-
return identifier4;
|
138136
|
-
}
|
138137
|
-
declareProperty(lvalue, object, property) {
|
138138
|
-
const objectDependency = this.properties.get(object.identifier);
|
138139
|
-
let nextDependency;
|
138140
|
-
if (objectDependency === void 0) {
|
138141
|
-
nextDependency = { identifier: object.identifier, path: [property] };
|
138142
|
-
} else {
|
138143
|
-
nextDependency = {
|
138144
|
-
identifier: objectDependency.identifier,
|
138145
|
-
path: [...objectDependency.path, property]
|
138146
|
-
};
|
138147
|
-
}
|
138148
|
-
this.properties.set(lvalue.identifier, nextDependency);
|
138149
|
-
}
|
138150
|
-
declareTemporary(lvalue, value) {
|
138151
|
-
const resolved = this.properties.get(value.identifier) ?? {
|
138152
|
-
identifier: value.identifier,
|
138153
|
-
path: []
|
138154
|
-
};
|
138155
|
-
this.properties.set(lvalue.identifier, resolved);
|
138156
|
-
}
|
138157
|
-
};
|
138158
137987
|
function analyseFunctions(func) {
|
138159
|
-
const state = new IdentifierState();
|
138160
137988
|
for (const [_, block] of func.body.blocks) {
|
138161
137989
|
for (const instr of block.instructions) {
|
138162
137990
|
switch (instr.value.kind) {
|
138163
137991
|
case "ObjectMethod":
|
138164
137992
|
case "FunctionExpression": {
|
138165
137993
|
lower2(instr.value.loweredFunc.func);
|
138166
|
-
infer2(instr.value.loweredFunc
|
138167
|
-
|
138168
|
-
|
138169
|
-
|
138170
|
-
|
138171
|
-
instr.lvalue,
|
138172
|
-
instr.value.object,
|
138173
|
-
instr.value.property
|
138174
|
-
);
|
138175
|
-
break;
|
138176
|
-
}
|
138177
|
-
case "ComputedLoad": {
|
138178
|
-
state.declareProperty(instr.lvalue, instr.value.object, "");
|
138179
|
-
break;
|
138180
|
-
}
|
138181
|
-
case "LoadLocal":
|
138182
|
-
case "LoadContext": {
|
138183
|
-
if (instr.lvalue.identifier.name === null) {
|
138184
|
-
state.declareTemporary(instr.lvalue, instr.value.place);
|
137994
|
+
infer2(instr.value.loweredFunc);
|
137995
|
+
for (const operand of instr.value.loweredFunc.func.context) {
|
137996
|
+
operand.identifier.mutableRange.start = makeInstructionId(0);
|
137997
|
+
operand.identifier.mutableRange.end = makeInstructionId(0);
|
137998
|
+
operand.identifier.scope = null;
|
138185
137999
|
}
|
138186
138000
|
break;
|
138187
138001
|
}
|
@@ -138196,55 +138010,27 @@ function lower2(func) {
|
|
138196
138010
|
inferMutableRanges(func);
|
138197
138011
|
rewriteInstructionKindsBasedOnReassignment(func);
|
138198
138012
|
inferReactiveScopeVariables(func);
|
138199
|
-
inferMutableContextVariables(func);
|
138200
138013
|
func.env.logger?.debugLogIRs?.({
|
138201
138014
|
kind: "hir",
|
138202
138015
|
name: "AnalyseFunction (inner)",
|
138203
138016
|
value: func
|
138204
138017
|
});
|
138205
138018
|
}
|
138206
|
-
function infer2(loweredFunc
|
138207
|
-
const mutations = /* @__PURE__ */ new Map();
|
138019
|
+
function infer2(loweredFunc) {
|
138208
138020
|
for (const operand of loweredFunc.func.context) {
|
138209
|
-
|
138210
|
-
|
138211
|
-
|
138212
|
-
|
138213
|
-
|
138214
|
-
|
138215
|
-
|
138216
|
-
|
138217
|
-
|
138021
|
+
const identifier4 = operand.identifier;
|
138022
|
+
CompilerError.invariant(operand.effect === "<unknown>" /* Unknown */, {
|
138023
|
+
reason: "[AnalyseFunctions] Expected Function context effects to not have been set",
|
138024
|
+
loc: operand.loc
|
138025
|
+
});
|
138026
|
+
if (isRefOrRefValue(identifier4)) {
|
138027
|
+
operand.effect = "capture" /* Capture */;
|
138028
|
+
} else if (isMutatedOrReassigned(identifier4)) {
|
138029
|
+
operand.effect = "capture" /* Capture */;
|
138218
138030
|
} else {
|
138219
|
-
|
138220
|
-
}
|
138221
|
-
if (isRefOrRefValue(dep.identifier)) {
|
138222
|
-
dep.effect = "capture" /* Capture */;
|
138223
|
-
} else if (name2 !== null) {
|
138224
|
-
const effect = mutations.get(name2.value);
|
138225
|
-
if (effect !== void 0) {
|
138226
|
-
dep.effect = effect === "<unknown>" /* Unknown */ ? "capture" /* Capture */ : effect;
|
138227
|
-
}
|
138031
|
+
operand.effect = "read" /* Read */;
|
138228
138032
|
}
|
138229
138033
|
}
|
138230
|
-
for (const place of context) {
|
138231
|
-
CompilerError.invariant(place.identifier.name !== null, {
|
138232
|
-
reason: "context refs should always have a name",
|
138233
|
-
description: null,
|
138234
|
-
loc: place.loc,
|
138235
|
-
suggestions: null
|
138236
|
-
});
|
138237
|
-
const effect = mutations.get(place.identifier.name.value);
|
138238
|
-
if (effect !== void 0) {
|
138239
|
-
place.effect = effect === "<unknown>" /* Unknown */ ? "capture" /* Capture */ : effect;
|
138240
|
-
loweredFunc.dependencies.push(place);
|
138241
|
-
}
|
138242
|
-
}
|
138243
|
-
for (const operand of loweredFunc.func.context) {
|
138244
|
-
operand.identifier.mutableRange.start = makeInstructionId(0);
|
138245
|
-
operand.identifier.mutableRange.end = makeInstructionId(0);
|
138246
|
-
operand.identifier.scope = null;
|
138247
|
-
}
|
138248
138034
|
}
|
138249
138035
|
function isMutatedOrReassigned(id) {
|
138250
138036
|
return id.mutableRange.end > id.mutableRange.start;
|
@@ -138328,9 +138114,10 @@ function collectTemporaries(instr, env, sidemap) {
|
|
138328
138114
|
}
|
138329
138115
|
case "PropertyLoad": {
|
138330
138116
|
if (sidemap.react.has(value.object.identifier.id)) {
|
138331
|
-
|
138117
|
+
const property = value.property;
|
138118
|
+
if (property === "useMemo" || property === "useCallback") {
|
138332
138119
|
sidemap.manualMemos.set(instr.lvalue.identifier.id, {
|
138333
|
-
kind:
|
138120
|
+
kind: property,
|
138334
138121
|
loadInstr: instr
|
138335
138122
|
});
|
138336
138123
|
}
|
@@ -139102,7 +138889,7 @@ function instructionReordering(fn) {
|
|
139102
138889
|
});
|
139103
138890
|
markInstructionIds(fn.body);
|
139104
138891
|
}
|
139105
|
-
var
|
138892
|
+
var DEBUG3 = false;
|
139106
138893
|
function findReferencedRangeOfTemporaries(fn) {
|
139107
138894
|
const singleUseIdentifiers = /* @__PURE__ */ new Map();
|
139108
138895
|
const lastAssignments = /* @__PURE__ */ new Map();
|
@@ -139204,16 +138991,16 @@ function reorderBlock(env, block, shared, references) {
|
|
139204
138991
|
}
|
139205
138992
|
const nextInstructions = [];
|
139206
138993
|
const seen = /* @__PURE__ */ new Set();
|
139207
|
-
|
138994
|
+
DEBUG3 && console.log(`bb${block.id}`);
|
139208
138995
|
if (isExpressionBlockKind(block.kind)) {
|
139209
138996
|
if (previous !== null) {
|
139210
|
-
|
139211
|
-
|
138997
|
+
DEBUG3 && console.log(`(last non-reorderable instruction)`);
|
138998
|
+
DEBUG3 && print(env, locals, shared, seen, previous);
|
139212
138999
|
emit(env, locals, shared, nextInstructions, previous);
|
139213
139000
|
}
|
139214
139001
|
if (block.instructions.length !== 0) {
|
139215
|
-
|
139216
|
-
|
139002
|
+
DEBUG3 && console.log(`(block value)`);
|
139003
|
+
DEBUG3 && print(
|
139217
139004
|
env,
|
139218
139005
|
locals,
|
139219
139006
|
shared,
|
@@ -139229,8 +139016,8 @@ function reorderBlock(env, block, shared, references) {
|
|
139229
139016
|
);
|
139230
139017
|
}
|
139231
139018
|
for (const operand of eachTerminalOperand(block.terminal)) {
|
139232
|
-
|
139233
|
-
|
139019
|
+
DEBUG3 && console.log(`(terminal operand)`);
|
139020
|
+
DEBUG3 && print(env, locals, shared, seen, operand.identifier.id);
|
139234
139021
|
emit(env, locals, shared, nextInstructions, operand.identifier.id);
|
139235
139022
|
}
|
139236
139023
|
for (const [id, node] of locals) {
|
@@ -139245,13 +139032,13 @@ function reorderBlock(env, block, shared, references) {
|
|
139245
139032
|
description: node.instruction != null ? `Instruction [${node.instruction.id}] was not emitted yet but is not reorderable` : `Lvalue $${id} was not emitted yet but is not reorderable`
|
139246
139033
|
}
|
139247
139034
|
);
|
139248
|
-
|
139035
|
+
DEBUG3 && console.log(`save shared: $${id}`);
|
139249
139036
|
shared.set(id, node);
|
139250
139037
|
}
|
139251
139038
|
} else {
|
139252
139039
|
for (const operand of eachTerminalOperand(block.terminal)) {
|
139253
|
-
|
139254
|
-
|
139040
|
+
DEBUG3 && console.log(`(terminal operand)`);
|
139041
|
+
DEBUG3 && print(env, locals, shared, seen, operand.identifier.id);
|
139255
139042
|
emit(env, locals, shared, nextInstructions, operand.identifier.id);
|
139256
139043
|
}
|
139257
139044
|
for (const id of Array.from(locals.keys()).reverse()) {
|
@@ -139260,17 +139047,17 @@ function reorderBlock(env, block, shared, references) {
|
|
139260
139047
|
continue;
|
139261
139048
|
}
|
139262
139049
|
if (node.reorderability === 0 /* Reorderable */) {
|
139263
|
-
|
139050
|
+
DEBUG3 && console.log(`save shared: $${id}`);
|
139264
139051
|
shared.set(id, node);
|
139265
139052
|
} else {
|
139266
|
-
|
139267
|
-
|
139053
|
+
DEBUG3 && console.log("leftover");
|
139054
|
+
DEBUG3 && print(env, locals, shared, seen, id);
|
139268
139055
|
emit(env, locals, shared, nextInstructions, id);
|
139269
139056
|
}
|
139270
139057
|
}
|
139271
139058
|
}
|
139272
139059
|
block.instructions = nextInstructions;
|
139273
|
-
|
139060
|
+
DEBUG3 && console.log();
|
139274
139061
|
}
|
139275
139062
|
function getDepth(env, nodes, id) {
|
139276
139063
|
const node = nodes.get(id);
|
@@ -139290,7 +139077,7 @@ function getDepth(env, nodes, id) {
|
|
139290
139077
|
}
|
139291
139078
|
function print(env, locals, shared, seen, id, depth = 0) {
|
139292
139079
|
if (seen.has(id)) {
|
139293
|
-
|
139080
|
+
DEBUG3 && console.log(`${"| ".repeat(depth)}$${id} <skipped>`);
|
139294
139081
|
return;
|
139295
139082
|
}
|
139296
139083
|
seen.add(id);
|
@@ -139307,7 +139094,7 @@ function print(env, locals, shared, seen, id, depth = 0) {
|
|
139307
139094
|
for (const dep of deps) {
|
139308
139095
|
print(env, locals, shared, seen, dep, depth + 1);
|
139309
139096
|
}
|
139310
|
-
|
139097
|
+
DEBUG3 && console.log(
|
139311
139098
|
`${"| ".repeat(depth)}$${id} ${printNode(node)} deps=[${deps.map((x) => `$${x}`).join(", ")}] depth=${node.depth}`
|
139312
139099
|
);
|
139313
139100
|
}
|
@@ -140148,7 +139935,7 @@ function* generateInstructionTypes(env, names, instr) {
|
|
140148
139935
|
kind: "Property",
|
140149
139936
|
objectType: value.value.identifier.type,
|
140150
139937
|
objectName: getName(names, value.value.identifier.id),
|
140151
|
-
propertyName
|
139938
|
+
propertyName: makePropertyLiteral(propertyName)
|
140152
139939
|
});
|
140153
139940
|
} else {
|
140154
139941
|
break;
|
@@ -140162,7 +139949,7 @@ function* generateInstructionTypes(env, names, instr) {
|
|
140162
139949
|
kind: "Property",
|
140163
139950
|
objectType: value.value.identifier.type,
|
140164
139951
|
objectName: getName(names, value.value.identifier.id),
|
140165
|
-
propertyName: property.key.name
|
139952
|
+
propertyName: makePropertyLiteral(property.key.name)
|
140166
139953
|
});
|
140167
139954
|
}
|
140168
139955
|
}
|
@@ -140249,10 +140036,12 @@ var Unifier = class {
|
|
140249
140036
|
return;
|
140250
140037
|
}
|
140251
140038
|
const objectType2 = this.get(tB.objectType);
|
140252
|
-
|
140253
|
-
|
140254
|
-
|
140255
|
-
|
140039
|
+
let propertyType;
|
140040
|
+
if (typeof tB.propertyName === "number") {
|
140041
|
+
propertyType = null;
|
140042
|
+
} else {
|
140043
|
+
propertyType = this.env.getPropertyType(objectType2, tB.propertyName);
|
140044
|
+
}
|
140256
140045
|
if (propertyType !== null) {
|
140257
140046
|
this.unify(tA, propertyType);
|
140258
140047
|
}
|
@@ -140687,7 +140476,7 @@ function validateHooksUsage(fn) {
|
|
140687
140476
|
}
|
140688
140477
|
case "PropertyLoad": {
|
140689
140478
|
const objectKind = getKindForPlace(instr.value.object);
|
140690
|
-
const isHookProperty = isHookName(instr.value.property);
|
140479
|
+
const isHookProperty = typeof instr.value.property === "string" && isHookName(instr.value.property);
|
140691
140480
|
let kind;
|
140692
140481
|
switch (objectKind) {
|
140693
140482
|
case "Error" /* Error */: {
|
@@ -140939,7 +140728,7 @@ function validateNoCapitalizedCalls(fn) {
|
|
140939
140728
|
break;
|
140940
140729
|
}
|
140941
140730
|
case "PropertyLoad": {
|
140942
|
-
if (/^[A-Z]/.test(value.property)) {
|
140731
|
+
if (typeof value.property === "string" && /^[A-Z]/.test(value.property)) {
|
140943
140732
|
capitalizedProperties.set(lvalue.identifier.id, value.property);
|
140944
140733
|
}
|
140945
140734
|
break;
|
@@ -141147,7 +140936,7 @@ function validateNoRefAccessInRenderImpl(fn, env) {
|
|
141147
140936
|
}
|
141148
140937
|
case "ComputedLoad":
|
141149
140938
|
case "PropertyLoad": {
|
141150
|
-
if (
|
140939
|
+
if (instr.value.kind === "ComputedLoad") {
|
141151
140940
|
validateNoDirectRefValueAccess(errors, instr.value.property, env);
|
141152
140941
|
}
|
141153
140942
|
const objType = env.get(instr.value.object.identifier.id);
|
@@ -141553,7 +141342,7 @@ function validatePreservedManualMemoization(fn) {
|
|
141553
141342
|
throw state.errors;
|
141554
141343
|
}
|
141555
141344
|
}
|
141556
|
-
var
|
141345
|
+
var DEBUG4 = false;
|
141557
141346
|
function prettyPrintScopeDependency(val) {
|
141558
141347
|
let rootStr;
|
141559
141348
|
if (val.identifier.name?.kind === "named") {
|
@@ -141652,7 +141441,7 @@ function validateInferredDep(dep, temporaries, declsWithinMemoBlock, validDepsIn
|
|
141652
141441
|
errorState.push({
|
141653
141442
|
severity: "CannotPreserveMemoization" /* CannotPreserveMemoization */,
|
141654
141443
|
reason: "React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. The inferred dependencies did not match the manually specified dependencies, which could cause the value to change more or less frequently than expected",
|
141655
|
-
description:
|
141444
|
+
description: DEBUG4 ? `The inferred dependency was \`${prettyPrintScopeDependency(
|
141656
141445
|
dep
|
141657
141446
|
)}\`, but the source dependencies were [${validDepsInMemoBlock.map((dep2) => printManualMemoDependency(dep2, true)).join(", ")}]. Detail: ${errorDiagnostic ? getCompareDependencyResultDescription(errorDiagnostic) : "none"}` : null,
|
141658
141447
|
loc: memoLocation,
|
@@ -141692,12 +141481,6 @@ var Visitor11 = class extends ReactiveFunctionVisitor {
|
|
141692
141481
|
case "OptionalExpression": {
|
141693
141482
|
return this.recordDepsInValue(value.value, state);
|
141694
141483
|
}
|
141695
|
-
case "ReactiveFunctionValue": {
|
141696
|
-
CompilerError.throwTodo({
|
141697
|
-
reason: "Handle ReactiveFunctionValue in ValidatePreserveManualMemoization",
|
141698
|
-
loc: value.loc
|
141699
|
-
});
|
141700
|
-
}
|
141701
141484
|
case "ConditionalExpression": {
|
141702
141485
|
this.recordDepsInValue(value.test, state);
|
141703
141486
|
this.recordDepsInValue(value.consequent, state);
|
@@ -141854,7 +141637,7 @@ var Visitor11 = class extends ReactiveFunctionVisitor {
|
|
141854
141637
|
if (isUnmemoized2(identifier5, this.scopes)) {
|
141855
141638
|
state.errors.push({
|
141856
141639
|
reason: "React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved. This value was memoized in source but not in compilation output.",
|
141857
|
-
description:
|
141640
|
+
description: DEBUG4 ? `${printIdentifier(identifier5)} was not memoized` : null,
|
141858
141641
|
severity: "CannotPreserveMemoization" /* CannotPreserveMemoization */,
|
141859
141642
|
loc,
|
141860
141643
|
suggestions: null
|
@@ -142105,7 +141888,7 @@ function outlineFunctions(fn, fbtOperands) {
|
|
142105
141888
|
if (value.kind === "FunctionExpression" || value.kind === "ObjectMethod") {
|
142106
141889
|
outlineFunctions(value.loweredFunc.func, fbtOperands);
|
142107
141890
|
}
|
142108
|
-
if (value.kind === "FunctionExpression" && value.loweredFunc.
|
141891
|
+
if (value.kind === "FunctionExpression" && value.loweredFunc.func.context.length === 0 && // TODO: handle outlining named functions
|
142109
141892
|
value.loweredFunc.func.id === null && !fbtOperands.has(lvalue.identifier.id)) {
|
142110
141893
|
const loweredFunc = value.loweredFunc.func;
|
142111
141894
|
const id = fn.env.generateGloballyUniqueIdentifierName(loweredFunc.id);
|
@@ -142277,7 +142060,7 @@ function emitPropertyLoad(env, obj, property) {
|
|
142277
142060
|
const loadProp = {
|
142278
142061
|
kind: "PropertyLoad",
|
142279
142062
|
object,
|
142280
|
-
property,
|
142063
|
+
property: makePropertyLiteral(property),
|
142281
142064
|
loc: GeneratedSource
|
142282
142065
|
};
|
142283
142066
|
const element = createTemporaryPlace(env, GeneratedSource);
|
@@ -142345,8 +142128,7 @@ function emitSelectorFn(env, keys) {
|
|
142345
142128
|
kind: "FunctionExpression",
|
142346
142129
|
name: null,
|
142347
142130
|
loweredFunc: {
|
142348
|
-
func: fn
|
142349
|
-
dependencies: []
|
142131
|
+
func: fn
|
142350
142132
|
},
|
142351
142133
|
type: "ArrowFunctionExpression",
|
142352
142134
|
loc: GeneratedSource
|
@@ -142535,14 +142317,7 @@ function collectHoistablePropertyLoads(fn, temporaries, hoistableFromOptionals)
|
|
142535
142317
|
});
|
142536
142318
|
}
|
142537
142319
|
function collectHoistablePropertyLoadsImpl(fn, context) {
|
142538
|
-
const
|
142539
|
-
const actuallyEvaluatedTemporaries = new Map(
|
142540
|
-
[...context.temporaries].filter(([id]) => !functionExpressionLoads.has(id))
|
142541
|
-
);
|
142542
|
-
const nodes = collectNonNullsInBlocks(fn, {
|
142543
|
-
...context,
|
142544
|
-
temporaries: actuallyEvaluatedTemporaries
|
142545
|
-
});
|
142320
|
+
const nodes = collectNonNullsInBlocks(fn, context);
|
142546
142321
|
propagateNonNull(fn, nodes, context.registry);
|
142547
142322
|
if (DEBUG_PRINT) {
|
142548
142323
|
console.log("(printing hoistable nodes in blocks)");
|
@@ -142818,26 +142593,6 @@ function reduceMaybeOptionalChains(nodes, registry) {
|
|
142818
142593
|
}
|
142819
142594
|
} while (changed);
|
142820
142595
|
}
|
142821
|
-
function collectFunctionExpressionFakeLoads(fn) {
|
142822
|
-
const sources = /* @__PURE__ */ new Map();
|
142823
|
-
const functionExpressionReferences = /* @__PURE__ */ new Set();
|
142824
|
-
for (const [_, block] of fn.body.blocks) {
|
142825
|
-
for (const { lvalue, value } of block.instructions) {
|
142826
|
-
if (value.kind === "FunctionExpression" || value.kind === "ObjectMethod") {
|
142827
|
-
for (const reference of value.loweredFunc.dependencies) {
|
142828
|
-
let curr = reference.identifier.id;
|
142829
|
-
while (curr != null) {
|
142830
|
-
functionExpressionReferences.add(curr);
|
142831
|
-
curr = sources.get(curr);
|
142832
|
-
}
|
142833
|
-
}
|
142834
|
-
} else if (value.kind === "PropertyLoad") {
|
142835
|
-
sources.set(lvalue.identifier.id, value.object.identifier.id);
|
142836
|
-
}
|
142837
|
-
}
|
142838
|
-
}
|
142839
|
-
return functionExpressionReferences;
|
142840
|
-
}
|
142841
142596
|
|
142842
142597
|
// src/Utils/Stack.ts
|
142843
142598
|
function empty() {
|
@@ -143706,7 +143461,7 @@ function collectDependencies(fn, usedOutsideDeclaringScope, temporaries, process
|
|
143706
143461
|
}
|
143707
143462
|
}
|
143708
143463
|
for (const instr of block.instructions) {
|
143709
|
-
if (
|
143464
|
+
if (instr.value.kind === "FunctionExpression" || instr.value.kind === "ObjectMethod") {
|
143710
143465
|
context.declare(instr.lvalue.identifier, {
|
143711
143466
|
id: instr.id,
|
143712
143467
|
scope: context.currentScope
|
@@ -144337,43 +144092,15 @@ function visitFunctionExpressionAndPropagateFireDependencies(fnExpr, context, en
|
|
144337
144092
|
const calleesCapturedByFnExpression = withScope(
|
144338
144093
|
() => replaceFireFunctions(fnExpr.loweredFunc.func, context)
|
144339
144094
|
);
|
144340
|
-
const loadLocalsToDepLoads = /* @__PURE__ */ new Map();
|
144341
|
-
for (const dep of fnExpr.loweredFunc.dependencies) {
|
144342
|
-
const loadLocal = context.getLoadLocalInstr(dep.identifier.id);
|
144343
|
-
if (loadLocal != null) {
|
144344
|
-
loadLocalsToDepLoads.set(loadLocal.place.identifier.id, loadLocal);
|
144345
|
-
}
|
144346
|
-
}
|
144347
|
-
const replacedCallees = /* @__PURE__ */ new Map();
|
144348
|
-
for (const [
|
144349
|
-
calleeIdentifierId,
|
144350
|
-
loadedFireFunctionBindingPlace
|
144351
|
-
] of calleesCapturedByFnExpression.entries()) {
|
144352
|
-
const loadLocal = loadLocalsToDepLoads.get(calleeIdentifierId);
|
144353
|
-
if (loadLocal == null) {
|
144354
|
-
context.pushError({
|
144355
|
-
loc: fnExpr.loc,
|
144356
|
-
description: null,
|
144357
|
-
severity: "Invariant" /* Invariant */,
|
144358
|
-
reason: "[InsertFire] No loadLocal found for fire call argument for lambda",
|
144359
|
-
suggestions: null
|
144360
|
-
});
|
144361
|
-
continue;
|
144362
|
-
}
|
144363
|
-
const oldPlaceId = loadLocal.place.identifier.id;
|
144364
|
-
loadLocal.place = {
|
144365
|
-
...loadedFireFunctionBindingPlace.fireFunctionBinding
|
144366
|
-
};
|
144367
|
-
replacedCallees.set(
|
144368
|
-
oldPlaceId,
|
144369
|
-
loadedFireFunctionBindingPlace.fireFunctionBinding
|
144370
|
-
);
|
144371
|
-
}
|
144372
144095
|
for (let contextIdx = 0; contextIdx < fnExpr.loweredFunc.func.context.length; contextIdx++) {
|
144373
144096
|
const contextItem = fnExpr.loweredFunc.func.context[contextIdx];
|
144374
|
-
const replacedCallee =
|
144097
|
+
const replacedCallee = calleesCapturedByFnExpression.get(
|
144098
|
+
contextItem.identifier.id
|
144099
|
+
);
|
144375
144100
|
if (replacedCallee != null) {
|
144376
|
-
fnExpr.loweredFunc.func.context[contextIdx] =
|
144101
|
+
fnExpr.loweredFunc.func.context[contextIdx] = {
|
144102
|
+
...replacedCallee.fireFunctionBinding
|
144103
|
+
};
|
144377
144104
|
}
|
144378
144105
|
}
|
144379
144106
|
context.mergeCalleesFromInnerScope(calleesCapturedByFnExpression);
|