babel-plugin-react-compiler 0.0.0-experimental-938cd9a-20240601 → 0.0.0-experimental-696af53-20240625
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 +1356 -417
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -135799,21 +135799,37 @@ function insertGatedFunctionDeclaration(fnPath, compiled, gating) {
|
|
135799
135799
|
buildFunctionExpression(compiled),
|
135800
135800
|
buildFunctionExpression(fnPath.node)
|
135801
135801
|
);
|
135802
|
-
let compiledFn;
|
135803
135802
|
if (
|
135804
135803
|
fnPath.parentPath.node.type !== "ExportDefaultDeclaration" &&
|
135805
135804
|
fnPath.node.type === "FunctionDeclaration" &&
|
135806
135805
|
fnPath.node.id != null
|
135807
135806
|
) {
|
135808
|
-
|
135807
|
+
fnPath.replaceWith(
|
135809
135808
|
t__namespace.variableDeclaration("const", [
|
135810
135809
|
t__namespace.variableDeclarator(fnPath.node.id, gatingExpression),
|
135811
135810
|
])
|
135812
|
-
)
|
135811
|
+
);
|
135812
|
+
} else if (
|
135813
|
+
fnPath.parentPath.node.type === "ExportDefaultDeclaration" &&
|
135814
|
+
fnPath.node.type !== "ArrowFunctionExpression" &&
|
135815
|
+
fnPath.node.id != null
|
135816
|
+
) {
|
135817
|
+
fnPath.insertAfter(
|
135818
|
+
t__namespace.exportDefaultDeclaration(
|
135819
|
+
t__namespace.identifier(fnPath.node.id.name)
|
135820
|
+
)
|
135821
|
+
);
|
135822
|
+
fnPath.parentPath.replaceWith(
|
135823
|
+
t__namespace.variableDeclaration("const", [
|
135824
|
+
t__namespace.variableDeclarator(
|
135825
|
+
t__namespace.identifier(fnPath.node.id.name),
|
135826
|
+
gatingExpression
|
135827
|
+
),
|
135828
|
+
])
|
135829
|
+
);
|
135813
135830
|
} else {
|
135814
|
-
|
135831
|
+
fnPath.replaceWith(gatingExpression);
|
135815
135832
|
}
|
135816
|
-
return compiledFn;
|
135817
135833
|
}
|
135818
135834
|
function buildFunctionExpression(node) {
|
135819
135835
|
var _a, _b;
|
@@ -135848,6 +135864,15 @@ function retainWhere(array, predicate) {
|
|
135848
135864
|
}
|
135849
135865
|
array.length = writeIndex;
|
135850
135866
|
}
|
135867
|
+
function getOrInsertWith(m, key, makeDefault) {
|
135868
|
+
if (m.has(key)) {
|
135869
|
+
return m.get(key);
|
135870
|
+
} else {
|
135871
|
+
const defaultValue = makeDefault();
|
135872
|
+
m.set(key, defaultValue);
|
135873
|
+
return defaultValue;
|
135874
|
+
}
|
135875
|
+
}
|
135851
135876
|
function getOrInsertDefault(m, key, defaultValue) {
|
135852
135877
|
if (m.has(key)) {
|
135853
135878
|
return m.get(key);
|
@@ -136071,10 +136096,12 @@ function objectMethodTypeEquals(tA, tB) {
|
|
136071
136096
|
}
|
136072
136097
|
function propTypeEquals(tA, tB) {
|
136073
136098
|
if (tA.kind === "Property" && tB.kind === "Property") {
|
136074
|
-
if (!typeEquals(tA.
|
136099
|
+
if (!typeEquals(tA.objectType, tB.objectType)) {
|
136075
136100
|
return false;
|
136076
136101
|
}
|
136077
|
-
return
|
136102
|
+
return (
|
136103
|
+
tA.propertyName === tB.propertyName && tA.objectName === tB.objectName
|
136104
|
+
);
|
136078
136105
|
}
|
136079
136106
|
return false;
|
136080
136107
|
}
|
@@ -136111,6 +136138,12 @@ function phiTypeEquals(tA, tB) {
|
|
136111
136138
|
return false;
|
136112
136139
|
}
|
136113
136140
|
const GeneratedSource = Symbol();
|
136141
|
+
function isStatementBlockKind(kind) {
|
136142
|
+
return kind === "block" || kind === "catch";
|
136143
|
+
}
|
136144
|
+
function isExpressionBlockKind(kind) {
|
136145
|
+
return !isStatementBlockKind(kind);
|
136146
|
+
}
|
136114
136147
|
var GotoVariant;
|
136115
136148
|
(function (GotoVariant) {
|
136116
136149
|
GotoVariant["Break"] = "Break";
|
@@ -136165,6 +136198,7 @@ var ValueReason;
|
|
136165
136198
|
ValueReason["KnownReturnSignature"] = "known-return-signature";
|
136166
136199
|
ValueReason["Context"] = "context";
|
136167
136200
|
ValueReason["State"] = "state";
|
136201
|
+
ValueReason["ReducerState"] = "reducer-state";
|
136168
136202
|
ValueReason["ReactiveFunctionArgument"] = "reactive-function-argument";
|
136169
136203
|
ValueReason["Other"] = "other";
|
136170
136204
|
})(ValueReason || (ValueReason = {}));
|
@@ -136272,6 +136306,17 @@ function isUseStateType(id) {
|
|
136272
136306
|
function isSetStateType(id) {
|
136273
136307
|
return id.type.kind === "Function" && id.type.shapeId === "BuiltInSetState";
|
136274
136308
|
}
|
136309
|
+
function isSetActionStateType(id) {
|
136310
|
+
return (
|
136311
|
+
id.type.kind === "Function" && id.type.shapeId === "BuiltInSetActionState"
|
136312
|
+
);
|
136313
|
+
}
|
136314
|
+
function isDispatcherType(id) {
|
136315
|
+
return id.type.kind === "Function" && id.type.shapeId === "BuiltInDispatch";
|
136316
|
+
}
|
136317
|
+
function isStableType(id) {
|
136318
|
+
return isSetStateType(id) || isSetActionStateType(id) || isDispatcherType(id);
|
136319
|
+
}
|
136275
136320
|
function isUseEffectHookType(id) {
|
136276
136321
|
return (
|
136277
136322
|
id.type.kind === "Function" && id.type.shapeId === "BuiltInUseEffectHook"
|
@@ -136404,6 +136449,11 @@ function writeReactiveBlock(writer, block) {
|
|
136404
136449
|
writeReactiveInstructions(writer, block.instructions);
|
136405
136450
|
writer.writeLine("}");
|
136406
136451
|
}
|
136452
|
+
function writePrunedScope(writer, block) {
|
136453
|
+
writer.writeLine(`<pruned> ${printReactiveScopeSummary(block.scope)} {`);
|
136454
|
+
writeReactiveInstructions(writer, block.instructions);
|
136455
|
+
writer.writeLine("}");
|
136456
|
+
}
|
136407
136457
|
function printDependency(dependency) {
|
136408
136458
|
const identifier =
|
136409
136459
|
printIdentifier(dependency.identifier) +
|
@@ -136437,6 +136487,10 @@ function writeReactiveInstruction(writer, instr) {
|
|
136437
136487
|
writeReactiveBlock(writer, instr);
|
136438
136488
|
break;
|
136439
136489
|
}
|
136490
|
+
case "pruned-scope": {
|
136491
|
+
writePrunedScope(writer, instr);
|
136492
|
+
break;
|
136493
|
+
}
|
136440
136494
|
case "terminal": {
|
136441
136495
|
if (instr.label !== null) {
|
136442
136496
|
writer.write(`bb${instr.label.id}: `);
|
@@ -136826,7 +136880,8 @@ function printMixedHIR(value) {
|
|
136826
136880
|
case "do-while":
|
136827
136881
|
case "for-in":
|
136828
136882
|
case "for-of":
|
136829
|
-
case "scope":
|
136883
|
+
case "scope":
|
136884
|
+
case "pruned-scope": {
|
136830
136885
|
const terminal = printTerminal(value);
|
136831
136886
|
if (Array.isArray(terminal)) {
|
136832
136887
|
return terminal.join("; ");
|
@@ -136956,6 +137011,10 @@ function printTerminal(terminal) {
|
|
136956
137011
|
value = `Scope ${printReactiveScopeSummary(terminal.scope)} block=bb${terminal.block} fallthrough=bb${terminal.fallthrough}`;
|
136957
137012
|
break;
|
136958
137013
|
}
|
137014
|
+
case "pruned-scope": {
|
137015
|
+
value = `<pruned> Scope ${printReactiveScopeSummary(terminal.scope)} block=bb${terminal.block} fallthrough=bb${terminal.fallthrough}`;
|
137016
|
+
break;
|
137017
|
+
}
|
136959
137018
|
case "try": {
|
136960
137019
|
value = `Try block=bb${terminal.block} handler=bb${terminal.handler}${terminal.handlerBinding !== null ? ` handlerBinding=(${printPlace(terminal.handlerBinding)})` : ""} fallthrough=${terminal.fallthrough != null ? `bb${terminal.fallthrough}` : ""}`;
|
136961
137020
|
break;
|
@@ -137256,6 +137315,10 @@ function printInstructionValue(instrValue) {
|
|
137256
137315
|
value = `RegExp /${instrValue.pattern}/${instrValue.flags}`;
|
137257
137316
|
break;
|
137258
137317
|
}
|
137318
|
+
case "MetaProperty": {
|
137319
|
+
value = `MetaProperty ${instrValue.meta}.${instrValue.property}`;
|
137320
|
+
break;
|
137321
|
+
}
|
137259
137322
|
case "Await": {
|
137260
137323
|
value = `Await ${printPlace(instrValue.value)}`;
|
137261
137324
|
break;
|
@@ -137654,6 +137717,7 @@ function* eachInstructionValueOperand(instrValue) {
|
|
137654
137717
|
}
|
137655
137718
|
case "Debugger":
|
137656
137719
|
case "RegExpLiteral":
|
137720
|
+
case "MetaProperty":
|
137657
137721
|
case "LoadGlobal":
|
137658
137722
|
case "UnsupportedNode":
|
137659
137723
|
case "Primitive":
|
@@ -137952,6 +138016,7 @@ function mapInstructionValueOperands(instrValue, fn) {
|
|
137952
138016
|
}
|
137953
138017
|
case "Debugger":
|
137954
138018
|
case "RegExpLiteral":
|
138019
|
+
case "MetaProperty":
|
137955
138020
|
case "LoadGlobal":
|
137956
138021
|
case "UnsupportedNode":
|
137957
138022
|
case "Primitive":
|
@@ -138216,11 +138281,12 @@ function mapTerminalSuccessors(terminal, fn) {
|
|
138216
138281
|
loc: terminal.loc,
|
138217
138282
|
};
|
138218
138283
|
}
|
138219
|
-
case "scope":
|
138284
|
+
case "scope":
|
138285
|
+
case "pruned-scope": {
|
138220
138286
|
const block = fn(terminal.block);
|
138221
138287
|
const fallthrough = fn(terminal.fallthrough);
|
138222
138288
|
return {
|
138223
|
-
kind:
|
138289
|
+
kind: terminal.kind,
|
138224
138290
|
scope: terminal.scope,
|
138225
138291
|
block: block,
|
138226
138292
|
fallthrough: fallthrough,
|
@@ -138265,7 +138331,8 @@ function terminalHasFallthrough(terminal) {
|
|
138265
138331
|
case "switch":
|
138266
138332
|
case "ternary":
|
138267
138333
|
case "while":
|
138268
|
-
case "scope":
|
138334
|
+
case "scope":
|
138335
|
+
case "pruned-scope": {
|
138269
138336
|
terminal.fallthrough;
|
138270
138337
|
return true;
|
138271
138338
|
}
|
@@ -138355,7 +138422,8 @@ function* eachTerminalSuccessor(terminal) {
|
|
138355
138422
|
yield terminal.block;
|
138356
138423
|
break;
|
138357
138424
|
}
|
138358
|
-
case "scope":
|
138425
|
+
case "scope":
|
138426
|
+
case "pruned-scope": {
|
138359
138427
|
yield terminal.block;
|
138360
138428
|
break;
|
138361
138429
|
}
|
@@ -138417,7 +138485,8 @@ function mapTerminalOperands(terminal, fn) {
|
|
138417
138485
|
case "goto":
|
138418
138486
|
case "unreachable":
|
138419
138487
|
case "unsupported":
|
138420
|
-
case "scope":
|
138488
|
+
case "scope":
|
138489
|
+
case "pruned-scope": {
|
138421
138490
|
break;
|
138422
138491
|
}
|
138423
138492
|
default: {
|
@@ -138473,7 +138542,8 @@ function* eachTerminalOperand(terminal) {
|
|
138473
138542
|
case "goto":
|
138474
138543
|
case "unreachable":
|
138475
138544
|
case "unsupported":
|
138476
|
-
case "scope":
|
138545
|
+
case "scope":
|
138546
|
+
case "pruned-scope": {
|
138477
138547
|
break;
|
138478
138548
|
}
|
138479
138549
|
default: {
|
@@ -139494,12 +139564,15 @@ function addShape(registry, id, properties, functionType) {
|
|
139494
139564
|
registry.set(id, shape);
|
139495
139565
|
return shape;
|
139496
139566
|
}
|
139567
|
+
const BuiltInPropsId = "BuiltInProps";
|
139497
139568
|
const BuiltInArrayId = "BuiltInArray";
|
139498
139569
|
const BuiltInFunctionId = "BuiltInFunction";
|
139499
139570
|
const BuiltInJsxId = "BuiltInJsx";
|
139500
139571
|
const BuiltInObjectId = "BuiltInObject";
|
139501
139572
|
const BuiltInUseStateId = "BuiltInUseState";
|
139502
139573
|
const BuiltInSetStateId = "BuiltInSetState";
|
139574
|
+
const BuiltInUseActionStateId = "BuiltInUseActionState";
|
139575
|
+
const BuiltInSetActionStateId = "BuiltInSetActionState";
|
139503
139576
|
const BuiltInUseRefId = "BuiltInUseRefId";
|
139504
139577
|
const BuiltInRefValueId = "BuiltInRefValue";
|
139505
139578
|
const BuiltInMixedReadonlyId = "BuiltInMixedReadonly";
|
@@ -139507,7 +139580,12 @@ const BuiltInUseEffectHookId = "BuiltInUseEffectHook";
|
|
139507
139580
|
const BuiltInUseLayoutEffectHookId = "BuiltInUseLayoutEffectHook";
|
139508
139581
|
const BuiltInUseInsertionEffectHookId = "BuiltInUseInsertionEffectHook";
|
139509
139582
|
const BuiltInUseOperatorId = "BuiltInUseOperator";
|
139583
|
+
const BuiltInUseReducerId = "BuiltInUseReducer";
|
139584
|
+
const BuiltInDispatchId = "BuiltInDispatch";
|
139510
139585
|
const BUILTIN_SHAPES = new Map();
|
139586
|
+
addObject(BUILTIN_SHAPES, BuiltInPropsId, [
|
139587
|
+
["ref", { kind: "Object", shapeId: BuiltInUseRefId }],
|
139588
|
+
]);
|
139511
139589
|
addObject(BUILTIN_SHAPES, BuiltInArrayId, [
|
139512
139590
|
[
|
139513
139591
|
"at",
|
@@ -139653,6 +139731,42 @@ addObject(BUILTIN_SHAPES, BuiltInUseStateId, [
|
|
139653
139731
|
),
|
139654
139732
|
],
|
139655
139733
|
]);
|
139734
|
+
addObject(BUILTIN_SHAPES, BuiltInUseActionStateId, [
|
139735
|
+
["0", { kind: "Poly" }],
|
139736
|
+
[
|
139737
|
+
"1",
|
139738
|
+
addFunction(
|
139739
|
+
BUILTIN_SHAPES,
|
139740
|
+
[],
|
139741
|
+
{
|
139742
|
+
positionalParams: [],
|
139743
|
+
restParam: exports.Effect.Freeze,
|
139744
|
+
returnType: PRIMITIVE_TYPE,
|
139745
|
+
calleeEffect: exports.Effect.Read,
|
139746
|
+
returnValueKind: exports.ValueKind.Primitive,
|
139747
|
+
},
|
139748
|
+
BuiltInSetActionStateId
|
139749
|
+
),
|
139750
|
+
],
|
139751
|
+
]);
|
139752
|
+
addObject(BUILTIN_SHAPES, BuiltInUseReducerId, [
|
139753
|
+
["0", { kind: "Poly" }],
|
139754
|
+
[
|
139755
|
+
"1",
|
139756
|
+
addFunction(
|
139757
|
+
BUILTIN_SHAPES,
|
139758
|
+
[],
|
139759
|
+
{
|
139760
|
+
positionalParams: [],
|
139761
|
+
restParam: exports.Effect.Freeze,
|
139762
|
+
returnType: PRIMITIVE_TYPE,
|
139763
|
+
calleeEffect: exports.Effect.Read,
|
139764
|
+
returnValueKind: exports.ValueKind.Primitive,
|
139765
|
+
},
|
139766
|
+
BuiltInDispatchId
|
139767
|
+
),
|
139768
|
+
],
|
139769
|
+
]);
|
139656
139770
|
addObject(BUILTIN_SHAPES, BuiltInUseRefId, [
|
139657
139771
|
["current", { kind: "Object", shapeId: BuiltInRefValueId }],
|
139658
139772
|
]);
|
@@ -141190,7 +141304,11 @@ function lowerExpression(builder, exprPath) {
|
|
141190
141304
|
_13,
|
141191
141305
|
_14,
|
141192
141306
|
_15,
|
141193
|
-
_16
|
141307
|
+
_16,
|
141308
|
+
_17,
|
141309
|
+
_18,
|
141310
|
+
_19,
|
141311
|
+
_20;
|
141194
141312
|
const exprNode = exprPath.node;
|
141195
141313
|
const exprLoc =
|
141196
141314
|
(_a = exprNode.loc) !== null && _a !== void 0 ? _a : GeneratedSource;
|
@@ -141386,6 +141504,15 @@ function lowerExpression(builder, exprPath) {
|
|
141386
141504
|
const left = lowerExpressionToTemporary(builder, leftPath);
|
141387
141505
|
const right = lowerExpressionToTemporary(builder, expr.get("right"));
|
141388
141506
|
const operator = expr.node.operator;
|
141507
|
+
if (operator === "|>") {
|
141508
|
+
builder.errors.push({
|
141509
|
+
reason: `(BuildHIR::lowerExpression) Pipe operator not supported`,
|
141510
|
+
severity: exports.ErrorSeverity.Todo,
|
141511
|
+
loc: (_j = leftPath.node.loc) !== null && _j !== void 0 ? _j : null,
|
141512
|
+
suggestions: null,
|
141513
|
+
});
|
141514
|
+
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
|
141515
|
+
}
|
141389
141516
|
return {
|
141390
141517
|
kind: "BinaryExpression",
|
141391
141518
|
operator: operator,
|
@@ -141397,7 +141524,7 @@ function lowerExpression(builder, exprPath) {
|
|
141397
141524
|
case "SequenceExpression": {
|
141398
141525
|
const expr = exprPath;
|
141399
141526
|
const exprLoc =
|
141400
|
-
(
|
141527
|
+
(_k = expr.node.loc) !== null && _k !== void 0 ? _k : GeneratedSource;
|
141401
141528
|
const continuationBlock = builder.reserve(builder.currentBlockKind());
|
141402
141529
|
const place = buildTemporaryPlace(builder, exprLoc);
|
141403
141530
|
const sequenceBlock = builder.enter("sequence", (_) => {
|
@@ -141448,7 +141575,7 @@ function lowerExpression(builder, exprPath) {
|
|
141448
141575
|
case "ConditionalExpression": {
|
141449
141576
|
const expr = exprPath;
|
141450
141577
|
const exprLoc =
|
141451
|
-
(
|
141578
|
+
(_l = expr.node.loc) !== null && _l !== void 0 ? _l : GeneratedSource;
|
141452
141579
|
const continuationBlock = builder.reserve(builder.currentBlockKind());
|
141453
141580
|
const testBlock = builder.reserve("value");
|
141454
141581
|
const place = buildTemporaryPlace(builder, exprLoc);
|
@@ -141529,14 +141656,14 @@ function lowerExpression(builder, exprPath) {
|
|
141529
141656
|
case "LogicalExpression": {
|
141530
141657
|
const expr = exprPath;
|
141531
141658
|
const exprLoc =
|
141532
|
-
(
|
141659
|
+
(_m = expr.node.loc) !== null && _m !== void 0 ? _m : GeneratedSource;
|
141533
141660
|
const continuationBlock = builder.reserve(builder.currentBlockKind());
|
141534
141661
|
const testBlock = builder.reserve("value");
|
141535
141662
|
const place = buildTemporaryPlace(builder, exprLoc);
|
141536
141663
|
const leftPlace = buildTemporaryPlace(
|
141537
141664
|
builder,
|
141538
|
-
(
|
141539
|
-
?
|
141665
|
+
(_o = expr.get("left").node.loc) !== null && _o !== void 0
|
141666
|
+
? _o
|
141540
141667
|
: GeneratedSource
|
141541
141668
|
);
|
141542
141669
|
const consequent = builder.enter("value", () => {
|
@@ -141616,7 +141743,7 @@ function lowerExpression(builder, exprPath) {
|
|
141616
141743
|
const left = expr.get("left");
|
141617
141744
|
return lowerAssignment(
|
141618
141745
|
builder,
|
141619
|
-
(
|
141746
|
+
(_p = left.node.loc) !== null && _p !== void 0 ? _p : GeneratedSource,
|
141620
141747
|
InstructionKind.Reassign,
|
141621
141748
|
left,
|
141622
141749
|
lowerExpressionToTemporary(builder, expr.get("right")),
|
@@ -141644,7 +141771,7 @@ function lowerExpression(builder, exprPath) {
|
|
141644
141771
|
builder.errors.push({
|
141645
141772
|
reason: `(BuildHIR::lowerExpression) Handle ${operator} operators in AssignmentExpression`,
|
141646
141773
|
severity: exports.ErrorSeverity.Todo,
|
141647
|
-
loc: (
|
141774
|
+
loc: (_q = expr.node.loc) !== null && _q !== void 0 ? _q : null,
|
141648
141775
|
suggestions: null,
|
141649
141776
|
});
|
141650
141777
|
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
|
@@ -141704,8 +141831,8 @@ function lowerExpression(builder, exprPath) {
|
|
141704
141831
|
left: Object.assign({}, previousValuePlace),
|
141705
141832
|
right: lowerExpressionToTemporary(builder, expr.get("right")),
|
141706
141833
|
loc:
|
141707
|
-
(
|
141708
|
-
?
|
141834
|
+
(_r = leftExpr.node.loc) !== null && _r !== void 0
|
141835
|
+
? _r
|
141709
141836
|
: GeneratedSource,
|
141710
141837
|
});
|
141711
141838
|
if (typeof property === "string") {
|
@@ -141715,8 +141842,8 @@ function lowerExpression(builder, exprPath) {
|
|
141715
141842
|
property: property,
|
141716
141843
|
value: Object.assign({}, newValuePlace),
|
141717
141844
|
loc:
|
141718
|
-
(
|
141719
|
-
?
|
141845
|
+
(_s = leftExpr.node.loc) !== null && _s !== void 0
|
141846
|
+
? _s
|
141720
141847
|
: GeneratedSource,
|
141721
141848
|
};
|
141722
141849
|
} else {
|
@@ -141726,8 +141853,8 @@ function lowerExpression(builder, exprPath) {
|
|
141726
141853
|
property: Object.assign({}, property),
|
141727
141854
|
value: Object.assign({}, newValuePlace),
|
141728
141855
|
loc:
|
141729
|
-
(
|
141730
|
-
?
|
141856
|
+
(_t = leftExpr.node.loc) !== null && _t !== void 0
|
141857
|
+
? _t
|
141731
141858
|
: GeneratedSource,
|
141732
141859
|
};
|
141733
141860
|
}
|
@@ -141736,7 +141863,7 @@ function lowerExpression(builder, exprPath) {
|
|
141736
141863
|
builder.errors.push({
|
141737
141864
|
reason: `(BuildHIR::lowerExpression) Expected Identifier or MemberExpression, got ${expr.type} lval in AssignmentExpression`,
|
141738
141865
|
severity: exports.ErrorSeverity.Todo,
|
141739
|
-
loc: (
|
141866
|
+
loc: (_u = expr.node.loc) !== null && _u !== void 0 ? _u : null,
|
141740
141867
|
suggestions: null,
|
141741
141868
|
});
|
141742
141869
|
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
|
@@ -141762,8 +141889,8 @@ function lowerExpression(builder, exprPath) {
|
|
141762
141889
|
const expr = exprPath;
|
141763
141890
|
const opening = expr.get("openingElement");
|
141764
141891
|
const openingLoc =
|
141765
|
-
(
|
141766
|
-
?
|
141892
|
+
(_v = opening.node.loc) !== null && _v !== void 0
|
141893
|
+
? _v
|
141767
141894
|
: GeneratedSource;
|
141768
141895
|
const tag = lowerJsxElementName(builder, opening.get("name"));
|
141769
141896
|
const props = [];
|
@@ -141781,7 +141908,7 @@ function lowerExpression(builder, exprPath) {
|
|
141781
141908
|
reason: `(BuildHIR::lowerExpression) Handle ${attribute.type} attributes in JSXElement`,
|
141782
141909
|
severity: exports.ErrorSeverity.Todo,
|
141783
141910
|
loc:
|
141784
|
-
(
|
141911
|
+
(_w = attribute.node.loc) !== null && _w !== void 0 ? _w : null,
|
141785
141912
|
suggestions: null,
|
141786
141913
|
});
|
141787
141914
|
continue;
|
@@ -141795,7 +141922,7 @@ function lowerExpression(builder, exprPath) {
|
|
141795
141922
|
reason: `(BuildHIR::lowerExpression) Unexpected colon in attribute name \`${name}\``,
|
141796
141923
|
severity: exports.ErrorSeverity.Todo,
|
141797
141924
|
loc:
|
141798
|
-
(
|
141925
|
+
(_x = namePath.node.loc) !== null && _x !== void 0 ? _x : null,
|
141799
141926
|
suggestions: null,
|
141800
141927
|
});
|
141801
141928
|
}
|
@@ -141803,7 +141930,7 @@ function lowerExpression(builder, exprPath) {
|
|
141803
141930
|
CompilerError.invariant(namePath.isJSXNamespacedName(), {
|
141804
141931
|
reason: "Refinement",
|
141805
141932
|
description: null,
|
141806
|
-
loc: (
|
141933
|
+
loc: (_y = namePath.node.loc) !== null && _y !== void 0 ? _y : null,
|
141807
141934
|
suggestions: null,
|
141808
141935
|
});
|
141809
141936
|
const namespace = namePath.node.namespace.name;
|
@@ -141819,8 +141946,8 @@ function lowerExpression(builder, exprPath) {
|
|
141819
141946
|
kind: "Primitive",
|
141820
141947
|
value: true,
|
141821
141948
|
loc:
|
141822
|
-
(
|
141823
|
-
?
|
141949
|
+
(_z = attribute.node.loc) !== null && _z !== void 0
|
141950
|
+
? _z
|
141824
141951
|
: GeneratedSource,
|
141825
141952
|
});
|
141826
141953
|
} else {
|
@@ -141829,11 +141956,11 @@ function lowerExpression(builder, exprPath) {
|
|
141829
141956
|
reason: `(BuildHIR::lowerExpression) Handle ${valueExpr.type} attribute values in JSXElement`,
|
141830
141957
|
severity: exports.ErrorSeverity.Todo,
|
141831
141958
|
loc:
|
141832
|
-
(
|
141833
|
-
(
|
141959
|
+
(_1 =
|
141960
|
+
(_0 = valueExpr.node) === null || _0 === void 0
|
141834
141961
|
? void 0
|
141835
|
-
:
|
141836
|
-
?
|
141962
|
+
: _0.loc) !== null && _1 !== void 0
|
141963
|
+
? _1
|
141837
141964
|
: null,
|
141838
141965
|
suggestions: null,
|
141839
141966
|
});
|
@@ -141845,7 +141972,7 @@ function lowerExpression(builder, exprPath) {
|
|
141845
141972
|
reason: `(BuildHIR::lowerExpression) Handle ${expression.type} expressions in JSXExpressionContainer within JSXElement`,
|
141846
141973
|
severity: exports.ErrorSeverity.Todo,
|
141847
141974
|
loc:
|
141848
|
-
(
|
141975
|
+
(_2 = valueExpr.node.loc) !== null && _2 !== void 0 ? _2 : null,
|
141849
141976
|
suggestions: null,
|
141850
141977
|
});
|
141851
141978
|
continue;
|
@@ -141867,8 +141994,8 @@ function lowerExpression(builder, exprPath) {
|
|
141867
141994
|
CompilerError.throwTodo({
|
141868
141995
|
reason: `Support <${tagName}> tags where '${tagName}' is a local variable instead of a global`,
|
141869
141996
|
loc:
|
141870
|
-
(
|
141871
|
-
?
|
141997
|
+
(_3 = openingIdentifier.node.loc) !== null && _3 !== void 0
|
141998
|
+
? _3
|
141872
141999
|
: GeneratedSource,
|
141873
142000
|
description: null,
|
141874
142001
|
suggestions: null,
|
@@ -141894,8 +142021,8 @@ function lowerExpression(builder, exprPath) {
|
|
141894
142021
|
CompilerError.throwTodo({
|
141895
142022
|
reason: `Support <${tagName}> tags with multiple <${tagName}:enum> values`,
|
141896
142023
|
loc:
|
141897
|
-
(
|
141898
|
-
?
|
142024
|
+
(_4 = fbtEnumLocations.at(-1)) !== null && _4 !== void 0
|
142025
|
+
? _4
|
141899
142026
|
: GeneratedSource,
|
141900
142027
|
description: null,
|
141901
142028
|
suggestions: null,
|
@@ -141939,11 +142066,11 @@ function lowerExpression(builder, exprPath) {
|
|
141939
142066
|
loc: exprLoc,
|
141940
142067
|
openingLoc: openingLoc,
|
141941
142068
|
closingLoc:
|
141942
|
-
(
|
141943
|
-
(
|
142069
|
+
(_6 =
|
142070
|
+
(_5 = expr.get("closingElement").node) === null || _5 === void 0
|
141944
142071
|
? void 0
|
141945
|
-
:
|
141946
|
-
?
|
142072
|
+
: _5.loc) !== null && _6 !== void 0
|
142073
|
+
? _6
|
141947
142074
|
: GeneratedSource,
|
141948
142075
|
};
|
141949
142076
|
}
|
@@ -141967,7 +142094,7 @@ function lowerExpression(builder, exprPath) {
|
|
141967
142094
|
reason:
|
141968
142095
|
"(BuildHIR::lowerExpression) Handle tagged template with interpolations",
|
141969
142096
|
severity: exports.ErrorSeverity.Todo,
|
141970
|
-
loc: (
|
142097
|
+
loc: (_7 = exprPath.node.loc) !== null && _7 !== void 0 ? _7 : null,
|
141971
142098
|
suggestions: null,
|
141972
142099
|
});
|
141973
142100
|
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
|
@@ -141976,7 +142103,7 @@ function lowerExpression(builder, exprPath) {
|
|
141976
142103
|
reason:
|
141977
142104
|
"there should be only one quasi as we don't support interpolations yet",
|
141978
142105
|
description: null,
|
141979
|
-
loc: (
|
142106
|
+
loc: (_8 = expr.node.loc) !== null && _8 !== void 0 ? _8 : null,
|
141980
142107
|
suggestions: null,
|
141981
142108
|
});
|
141982
142109
|
const value = expr.get("quasi").get("quasis").at(0).node.value;
|
@@ -141985,7 +142112,7 @@ function lowerExpression(builder, exprPath) {
|
|
141985
142112
|
reason:
|
141986
142113
|
"(BuildHIR::lowerExpression) Handle tagged template where cooked value is different from raw value",
|
141987
142114
|
severity: exports.ErrorSeverity.Todo,
|
141988
|
-
loc: (
|
142115
|
+
loc: (_9 = exprPath.node.loc) !== null && _9 !== void 0 ? _9 : null,
|
141989
142116
|
suggestions: null,
|
141990
142117
|
});
|
141991
142118
|
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
|
@@ -142005,7 +142132,8 @@ function lowerExpression(builder, exprPath) {
|
|
142005
142132
|
builder.errors.push({
|
142006
142133
|
reason: `Unexpected quasi and subexpression lengths in template literal`,
|
142007
142134
|
severity: exports.ErrorSeverity.InvalidJS,
|
142008
|
-
loc:
|
142135
|
+
loc:
|
142136
|
+
(_10 = exprPath.node.loc) !== null && _10 !== void 0 ? _10 : null,
|
142009
142137
|
suggestions: null,
|
142010
142138
|
});
|
142011
142139
|
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
|
@@ -142015,7 +142143,7 @@ function lowerExpression(builder, exprPath) {
|
|
142015
142143
|
reason: `(BuildHIR::lowerAssignment) Handle TSType in TemplateLiteral.`,
|
142016
142144
|
severity: exports.ErrorSeverity.Todo,
|
142017
142145
|
loc:
|
142018
|
-
(
|
142146
|
+
(_11 = exprPath.node.loc) !== null && _11 !== void 0 ? _11 : null,
|
142019
142147
|
suggestions: null,
|
142020
142148
|
});
|
142021
142149
|
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
|
@@ -142058,7 +142186,7 @@ function lowerExpression(builder, exprPath) {
|
|
142058
142186
|
builder.errors.push({
|
142059
142187
|
reason: `Only object properties can be deleted`,
|
142060
142188
|
severity: exports.ErrorSeverity.InvalidJS,
|
142061
|
-
loc: (
|
142189
|
+
loc: (_12 = expr.node.loc) !== null && _12 !== void 0 ? _12 : null,
|
142062
142190
|
suggestions: [
|
142063
142191
|
{
|
142064
142192
|
description: "Remove this line",
|
@@ -142069,6 +142197,20 @@ function lowerExpression(builder, exprPath) {
|
|
142069
142197
|
});
|
142070
142198
|
return { kind: "UnsupportedNode", node: expr.node, loc: exprLoc };
|
142071
142199
|
}
|
142200
|
+
} else if (expr.node.operator === "throw") {
|
142201
|
+
builder.errors.push({
|
142202
|
+
reason: `Throw expressions are not supported`,
|
142203
|
+
severity: exports.ErrorSeverity.InvalidJS,
|
142204
|
+
loc: (_13 = expr.node.loc) !== null && _13 !== void 0 ? _13 : null,
|
142205
|
+
suggestions: [
|
142206
|
+
{
|
142207
|
+
description: "Remove this line",
|
142208
|
+
range: [expr.node.start, expr.node.end],
|
142209
|
+
op: exports.CompilerSuggestionOperation.Remove,
|
142210
|
+
},
|
142211
|
+
],
|
142212
|
+
});
|
142213
|
+
return { kind: "UnsupportedNode", node: expr.node, loc: exprLoc };
|
142072
142214
|
} else {
|
142073
142215
|
return {
|
142074
142216
|
kind: "UnaryExpression",
|
@@ -142116,7 +142258,7 @@ function lowerExpression(builder, exprPath) {
|
|
142116
142258
|
reason: `(BuildHIR::lowerExpression) Handle UpdateExpression with ${argument.type} argument`,
|
142117
142259
|
severity: exports.ErrorSeverity.Todo,
|
142118
142260
|
loc:
|
142119
|
-
(
|
142261
|
+
(_14 = exprPath.node.loc) !== null && _14 !== void 0 ? _14 : null,
|
142120
142262
|
suggestions: null,
|
142121
142263
|
});
|
142122
142264
|
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
|
@@ -142125,15 +142267,15 @@ function lowerExpression(builder, exprPath) {
|
|
142125
142267
|
reason: `(BuildHIR::lowerExpression) Handle UpdateExpression to variables captured within lambdas.`,
|
142126
142268
|
severity: exports.ErrorSeverity.Todo,
|
142127
142269
|
loc:
|
142128
|
-
(
|
142270
|
+
(_15 = exprPath.node.loc) !== null && _15 !== void 0 ? _15 : null,
|
142129
142271
|
suggestions: null,
|
142130
142272
|
});
|
142131
142273
|
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
|
142132
142274
|
}
|
142133
142275
|
const lvalue = lowerIdentifierForAssignment(
|
142134
142276
|
builder,
|
142135
|
-
(
|
142136
|
-
?
|
142277
|
+
(_16 = argument.node.loc) !== null && _16 !== void 0
|
142278
|
+
? _16
|
142137
142279
|
: GeneratedSource,
|
142138
142280
|
InstructionKind.Reassign,
|
142139
142281
|
argument
|
@@ -142183,8 +142325,8 @@ function lowerExpression(builder, exprPath) {
|
|
142183
142325
|
pattern: expr.node.pattern,
|
142184
142326
|
flags: expr.node.flags,
|
142185
142327
|
loc:
|
142186
|
-
(
|
142187
|
-
?
|
142328
|
+
(_17 = expr.node.loc) !== null && _17 !== void 0
|
142329
|
+
? _17
|
142188
142330
|
: GeneratedSource,
|
142189
142331
|
};
|
142190
142332
|
}
|
@@ -142192,11 +142334,35 @@ function lowerExpression(builder, exprPath) {
|
|
142192
142334
|
let expr = exprPath;
|
142193
142335
|
return lowerExpression(builder, expr.get("expression"));
|
142194
142336
|
}
|
142337
|
+
case "MetaProperty": {
|
142338
|
+
let expr = exprPath;
|
142339
|
+
if (
|
142340
|
+
expr.node.meta.name === "import" &&
|
142341
|
+
expr.node.property.name === "meta"
|
142342
|
+
) {
|
142343
|
+
return {
|
142344
|
+
kind: "MetaProperty",
|
142345
|
+
meta: expr.node.meta.name,
|
142346
|
+
property: expr.node.property.name,
|
142347
|
+
loc:
|
142348
|
+
(_18 = expr.node.loc) !== null && _18 !== void 0
|
142349
|
+
? _18
|
142350
|
+
: GeneratedSource,
|
142351
|
+
};
|
142352
|
+
}
|
142353
|
+
builder.errors.push({
|
142354
|
+
reason: `(BuildHIR::lowerExpression) Handle MetaProperty expressions other than import.meta`,
|
142355
|
+
severity: exports.ErrorSeverity.Todo,
|
142356
|
+
loc: (_19 = exprPath.node.loc) !== null && _19 !== void 0 ? _19 : null,
|
142357
|
+
suggestions: null,
|
142358
|
+
});
|
142359
|
+
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
|
142360
|
+
}
|
142195
142361
|
default: {
|
142196
142362
|
builder.errors.push({
|
142197
142363
|
reason: `(BuildHIR::lowerExpression) Handle ${exprPath.type} expressions`,
|
142198
142364
|
severity: exports.ErrorSeverity.Todo,
|
142199
|
-
loc: (
|
142365
|
+
loc: (_20 = exprPath.node.loc) !== null && _20 !== void 0 ? _20 : null,
|
142200
142366
|
suggestions: null,
|
142201
142367
|
});
|
142202
142368
|
return { kind: "UnsupportedNode", node: exprNode, loc: exprLoc };
|
@@ -149705,6 +149871,30 @@ const REACT_APIS = [
|
|
149705
149871
|
returnValueReason: ValueReason.State,
|
149706
149872
|
}),
|
149707
149873
|
],
|
149874
|
+
[
|
149875
|
+
"useActionState",
|
149876
|
+
addHook(DEFAULT_SHAPES, {
|
149877
|
+
positionalParams: [],
|
149878
|
+
restParam: exports.Effect.Freeze,
|
149879
|
+
returnType: { kind: "Object", shapeId: BuiltInUseActionStateId },
|
149880
|
+
calleeEffect: exports.Effect.Read,
|
149881
|
+
hookKind: "useActionState",
|
149882
|
+
returnValueKind: exports.ValueKind.Frozen,
|
149883
|
+
returnValueReason: ValueReason.State,
|
149884
|
+
}),
|
149885
|
+
],
|
149886
|
+
[
|
149887
|
+
"useReducer",
|
149888
|
+
addHook(DEFAULT_SHAPES, {
|
149889
|
+
positionalParams: [],
|
149890
|
+
restParam: exports.Effect.Freeze,
|
149891
|
+
returnType: { kind: "Object", shapeId: BuiltInUseReducerId },
|
149892
|
+
calleeEffect: exports.Effect.Read,
|
149893
|
+
hookKind: "useReducer",
|
149894
|
+
returnValueKind: exports.ValueKind.Frozen,
|
149895
|
+
returnValueReason: ValueReason.ReducerState,
|
149896
|
+
}),
|
149897
|
+
],
|
149708
149898
|
[
|
149709
149899
|
"useRef",
|
149710
149900
|
addHook(DEFAULT_SHAPES, {
|
@@ -149951,6 +150141,7 @@ const HookSchema = z.object({
|
|
149951
150141
|
});
|
149952
150142
|
const EnvironmentConfigSchema = z.object({
|
149953
150143
|
customHooks: z.map(z.string(), HookSchema).optional().default(new Map()),
|
150144
|
+
customMacros: z.nullable(z.array(z.string())).default(null),
|
149954
150145
|
enableResetCacheOnSourceFileChanges: z.boolean().default(false),
|
149955
150146
|
enablePreserveExistingMemoizationGuarantees: z.boolean().default(false),
|
149956
150147
|
validatePreserveExistingMemoizationGuarantees: z.boolean().default(true),
|
@@ -149967,6 +150158,7 @@ const EnvironmentConfigSchema = z.object({
|
|
149967
150158
|
enableTransitivelyFreezeFunctionExpressions: z.boolean().default(true),
|
149968
150159
|
enableEmitFreeze: ExternalFunctionSchema.nullish(),
|
149969
150160
|
enableEmitHookGuards: ExternalFunctionSchema.nullish(),
|
150161
|
+
enableInstructionReordering: z.boolean().default(false),
|
149970
150162
|
enableEmitInstrumentForget: InstrumentationSchema.nullish(),
|
149971
150163
|
assertValidMutableRanges: z.boolean().default(false),
|
149972
150164
|
enableChangeVariableCodegen: z.boolean().default(false),
|
@@ -149978,6 +150170,7 @@ const EnvironmentConfigSchema = z.object({
|
|
149978
150170
|
enableChangeDetectionForDebugging: ExternalFunctionSchema.nullish(),
|
149979
150171
|
enableCustomTypeDefinitionForReanimated: z.boolean().default(false),
|
149980
150172
|
hookPattern: z.string().nullable().default(null),
|
150173
|
+
enableTreatRefLikeIdentifiersAsRefs: z.boolean().nullable().default(false),
|
149981
150174
|
});
|
149982
150175
|
function parseConfigPragma(pragma) {
|
149983
150176
|
const maybeConfig = {};
|
@@ -149992,6 +150185,16 @@ function parseConfigPragma(pragma) {
|
|
149992
150185
|
maybeConfig[key] = [];
|
149993
150186
|
continue;
|
149994
150187
|
}
|
150188
|
+
if (
|
150189
|
+
key === "enableChangeDetectionForDebugging" &&
|
150190
|
+
(val === undefined || val === "true")
|
150191
|
+
) {
|
150192
|
+
maybeConfig[key] = {
|
150193
|
+
source: "react-compiler-runtime",
|
150194
|
+
importSpecifierName: "$structuralCheck",
|
150195
|
+
};
|
150196
|
+
continue;
|
150197
|
+
}
|
149995
150198
|
if (typeof defaultConfig[key] !== "boolean") {
|
149996
150199
|
continue;
|
149997
150200
|
}
|
@@ -150673,6 +150876,12 @@ class ReactiveFunctionVisitor {
|
|
150673
150876
|
traverseScope(scope, state) {
|
150674
150877
|
this.visitBlock(scope.instructions, state);
|
150675
150878
|
}
|
150879
|
+
visitPrunedScope(scopeBlock, state) {
|
150880
|
+
this.traversePrunedScope(scopeBlock, state);
|
150881
|
+
}
|
150882
|
+
traversePrunedScope(scopeBlock, state) {
|
150883
|
+
this.visitBlock(scopeBlock.instructions, state);
|
150884
|
+
}
|
150676
150885
|
visitBlock(block, state) {
|
150677
150886
|
this.traverseBlock(block, state);
|
150678
150887
|
}
|
@@ -150687,6 +150896,10 @@ class ReactiveFunctionVisitor {
|
|
150687
150896
|
this.visitScope(instr, state);
|
150688
150897
|
break;
|
150689
150898
|
}
|
150899
|
+
case "pruned-scope": {
|
150900
|
+
this.visitPrunedScope(instr, state);
|
150901
|
+
break;
|
150902
|
+
}
|
150690
150903
|
case "terminal": {
|
150691
150904
|
this.visitTerminal(instr, state);
|
150692
150905
|
break;
|
@@ -150736,6 +150949,10 @@ class ReactiveFunctionTransform extends ReactiveFunctionVisitor {
|
|
150736
150949
|
transformed = this.transformScope(instr, state);
|
150737
150950
|
break;
|
150738
150951
|
}
|
150952
|
+
case "pruned-scope": {
|
150953
|
+
transformed = this.transformPrunedScope(instr, state);
|
150954
|
+
break;
|
150955
|
+
}
|
150739
150956
|
case "terminal": {
|
150740
150957
|
transformed = this.transformTerminal(instr, state);
|
150741
150958
|
break;
|
@@ -150793,6 +151010,10 @@ class ReactiveFunctionTransform extends ReactiveFunctionVisitor {
|
|
150793
151010
|
this.visitScope(scope, state);
|
150794
151011
|
return { kind: "keep" };
|
150795
151012
|
}
|
151013
|
+
transformPrunedScope(scope, state) {
|
151014
|
+
this.visitPrunedScope(scope, state);
|
151015
|
+
return { kind: "keep" };
|
151016
|
+
}
|
150796
151017
|
transformValue(id, value, state) {
|
150797
151018
|
this.visitValue(id, value, state);
|
150798
151019
|
return { kind: "keep" };
|
@@ -151233,6 +151454,7 @@ function visitBlock(context, block) {
|
|
151233
151454
|
context.append(stmt, stmt.label);
|
151234
151455
|
break;
|
151235
151456
|
}
|
151457
|
+
case "pruned-scope":
|
151236
151458
|
case "scope": {
|
151237
151459
|
CompilerError.invariant(false, {
|
151238
151460
|
reason: "Expected the function to not have scopes already assigned",
|
@@ -153939,6 +154161,7 @@ class Driver {
|
|
153939
154161
|
}
|
153940
154162
|
break;
|
153941
154163
|
}
|
154164
|
+
case "pruned-scope":
|
153942
154165
|
case "scope": {
|
153943
154166
|
const fallthroughId = !this.cx.isScheduled(terminal.fallthrough)
|
153944
154167
|
? terminal.fallthrough
|
@@ -153959,7 +154182,7 @@ class Driver {
|
|
153959
154182
|
}
|
153960
154183
|
this.cx.unscheduleAll(scheduleIds);
|
153961
154184
|
blockValue.push({
|
153962
|
-
kind:
|
154185
|
+
kind: terminal.kind,
|
153963
154186
|
instructions: block,
|
153964
154187
|
scope: terminal.scope,
|
153965
154188
|
});
|
@@ -154047,12 +154270,15 @@ class Driver {
|
|
154047
154270
|
const instr = defaultBlock.instructions[0];
|
154048
154271
|
let place = instr.lvalue;
|
154049
154272
|
let value = instr.value;
|
154050
|
-
if (
|
154051
|
-
|
154273
|
+
if (
|
154274
|
+
value.kind === "StoreLocal" &&
|
154275
|
+
value.lvalue.place.identifier.name === null
|
154276
|
+
) {
|
154277
|
+
place = value.lvalue.place;
|
154052
154278
|
value = {
|
154053
154279
|
kind: "LoadLocal",
|
154054
|
-
place:
|
154055
|
-
loc:
|
154280
|
+
place: value.value,
|
154281
|
+
loc: value.value.loc,
|
154056
154282
|
};
|
154057
154283
|
}
|
154058
154284
|
return {
|
@@ -154065,12 +154291,15 @@ class Driver {
|
|
154065
154291
|
const instr = defaultBlock.instructions.at(-1);
|
154066
154292
|
let place = instr.lvalue;
|
154067
154293
|
let value = instr.value;
|
154068
|
-
if (
|
154069
|
-
|
154294
|
+
if (
|
154295
|
+
value.kind === "StoreLocal" &&
|
154296
|
+
value.lvalue.place.identifier.name === null
|
154297
|
+
) {
|
154298
|
+
place = value.lvalue.place;
|
154070
154299
|
value = {
|
154071
154300
|
kind: "LoadLocal",
|
154072
|
-
place:
|
154073
|
-
loc:
|
154301
|
+
place: value.value,
|
154302
|
+
loc: value.value.loc,
|
154074
154303
|
};
|
154075
154304
|
}
|
154076
154305
|
const sequence = {
|
@@ -154538,11 +154767,16 @@ var GuardKind;
|
|
154538
154767
|
GuardKind[(GuardKind["AllowHook"] = 2)] = "AllowHook";
|
154539
154768
|
GuardKind[(GuardKind["DisallowHook"] = 3)] = "DisallowHook";
|
154540
154769
|
})(GuardKind || (GuardKind = {}));
|
154541
|
-
function
|
154770
|
+
function memoizeFbtAndMacroOperandsInSameScope(fn) {
|
154771
|
+
var _a;
|
154772
|
+
const fbtMacroTags = new Set([
|
154773
|
+
...FBT_TAGS,
|
154774
|
+
...((_a = fn.env.config.customMacros) !== null && _a !== void 0 ? _a : []),
|
154775
|
+
]);
|
154542
154776
|
const fbtValues = new Set();
|
154543
154777
|
while (true) {
|
154544
154778
|
let size = fbtValues.size;
|
154545
|
-
visit$1(fn, fbtValues);
|
154779
|
+
visit$1(fn, fbtMacroTags, fbtValues);
|
154546
154780
|
if (size === fbtValues.size) {
|
154547
154781
|
break;
|
154548
154782
|
}
|
@@ -154550,28 +154784,28 @@ function memoizeFbtOperandsInSameScope(fn) {
|
|
154550
154784
|
}
|
154551
154785
|
const FBT_TAGS = new Set(["fbt", "fbt:param", "fbs", "fbs:param"]);
|
154552
154786
|
const SINGLE_CHILD_FBT_TAGS = new Set(["fbt:param", "fbs:param"]);
|
154553
|
-
function visit$1(fn, fbtValues) {
|
154787
|
+
function visit$1(fn, fbtMacroTags, fbtValues) {
|
154554
154788
|
for (const [, block] of fn.body.blocks) {
|
154555
154789
|
for (const instruction of block.instructions) {
|
154556
154790
|
const { lvalue: lvalue, value: value } = instruction;
|
154557
154791
|
if (lvalue === null) {
|
154558
|
-
|
154792
|
+
continue;
|
154559
154793
|
}
|
154560
154794
|
if (
|
154561
154795
|
value.kind === "Primitive" &&
|
154562
154796
|
typeof value.value === "string" &&
|
154563
|
-
|
154797
|
+
fbtMacroTags.has(value.value)
|
154564
154798
|
) {
|
154565
154799
|
fbtValues.add(lvalue.identifier.id);
|
154566
154800
|
} else if (
|
154567
154801
|
value.kind === "LoadGlobal" &&
|
154568
|
-
|
154802
|
+
fbtMacroTags.has(value.binding.name)
|
154569
154803
|
) {
|
154570
154804
|
fbtValues.add(lvalue.identifier.id);
|
154571
154805
|
} else if (isFbtCallExpression(fbtValues, value)) {
|
154572
154806
|
const fbtScope = lvalue.identifier.scope;
|
154573
154807
|
if (fbtScope === null) {
|
154574
|
-
|
154808
|
+
continue;
|
154575
154809
|
}
|
154576
154810
|
for (const operand of eachReactiveValueOperand(value)) {
|
154577
154811
|
operand.identifier.scope = fbtScope;
|
@@ -154581,14 +154815,15 @@ function visit$1(fn, fbtValues) {
|
|
154581
154815
|
operand.identifier.mutableRange.start
|
154582
154816
|
)
|
154583
154817
|
);
|
154818
|
+
fbtValues.add(operand.identifier.id);
|
154584
154819
|
}
|
154585
154820
|
} else if (
|
154586
|
-
isFbtJsxExpression(fbtValues, value) ||
|
154821
|
+
isFbtJsxExpression(fbtMacroTags, fbtValues, value) ||
|
154587
154822
|
isFbtJsxChild(fbtValues, lvalue, value)
|
154588
154823
|
) {
|
154589
154824
|
const fbtScope = lvalue.identifier.scope;
|
154590
154825
|
if (fbtScope === null) {
|
154591
|
-
|
154826
|
+
continue;
|
154592
154827
|
}
|
154593
154828
|
for (const operand of eachReactiveValueOperand(value)) {
|
154594
154829
|
operand.identifier.scope = fbtScope;
|
@@ -154600,6 +154835,26 @@ function visit$1(fn, fbtValues) {
|
|
154600
154835
|
);
|
154601
154836
|
fbtValues.add(operand.identifier.id);
|
154602
154837
|
}
|
154838
|
+
} else if (fbtValues.has(lvalue.identifier.id)) {
|
154839
|
+
const fbtScope = lvalue.identifier.scope;
|
154840
|
+
if (fbtScope === null) {
|
154841
|
+
return;
|
154842
|
+
}
|
154843
|
+
for (const operand of eachReactiveValueOperand(value)) {
|
154844
|
+
if (
|
154845
|
+
operand.identifier.name !== null &&
|
154846
|
+
operand.identifier.name.kind === "named"
|
154847
|
+
) {
|
154848
|
+
continue;
|
154849
|
+
}
|
154850
|
+
operand.identifier.scope = fbtScope;
|
154851
|
+
fbtScope.range.start = makeInstructionId(
|
154852
|
+
Math.min(
|
154853
|
+
fbtScope.range.start,
|
154854
|
+
operand.identifier.mutableRange.start
|
154855
|
+
)
|
154856
|
+
);
|
154857
|
+
}
|
154603
154858
|
}
|
154604
154859
|
}
|
154605
154860
|
}
|
@@ -154609,12 +154864,12 @@ function isFbtCallExpression(fbtValues, value) {
|
|
154609
154864
|
value.kind === "CallExpression" && fbtValues.has(value.callee.identifier.id)
|
154610
154865
|
);
|
154611
154866
|
}
|
154612
|
-
function isFbtJsxExpression(fbtValues, value) {
|
154867
|
+
function isFbtJsxExpression(fbtMacroTags, fbtValues, value) {
|
154613
154868
|
return (
|
154614
154869
|
value.kind === "JsxExpression" &&
|
154615
154870
|
((value.tag.kind === "Identifier" &&
|
154616
154871
|
fbtValues.has(value.tag.identifier.id)) ||
|
154617
|
-
(value.tag.kind === "BuiltinTag" &&
|
154872
|
+
(value.tag.kind === "BuiltinTag" && fbtMacroTags.has(value.tag.name)))
|
154618
154873
|
);
|
154619
154874
|
}
|
154620
154875
|
function isFbtJsxChild(fbtValues, lvalue, value) {
|
@@ -154807,7 +155062,7 @@ function codegenReactiveFunction(cx, fn) {
|
|
154807
155062
|
if (cx.errors.hasErrors()) {
|
154808
155063
|
return Err(cx.errors);
|
154809
155064
|
}
|
154810
|
-
const countMemoBlockVisitor = new CountMemoBlockVisitor();
|
155065
|
+
const countMemoBlockVisitor = new CountMemoBlockVisitor(fn.env);
|
154811
155066
|
visitReactiveFunction(fn, countMemoBlockVisitor, undefined);
|
154812
155067
|
return Ok({
|
154813
155068
|
type: "CodegenFunction",
|
@@ -154818,17 +155073,30 @@ function codegenReactiveFunction(cx, fn) {
|
|
154818
155073
|
generator: fn.generator,
|
154819
155074
|
async: fn.async,
|
154820
155075
|
memoSlotsUsed: cx.nextCacheIndex,
|
154821
|
-
memoBlocks: countMemoBlockVisitor.
|
155076
|
+
memoBlocks: countMemoBlockVisitor.memoBlocks,
|
155077
|
+
memoValues: countMemoBlockVisitor.memoValues,
|
155078
|
+
prunedMemoBlocks: countMemoBlockVisitor.prunedMemoBlocks,
|
155079
|
+
prunedMemoValues: countMemoBlockVisitor.prunedMemoValues,
|
154822
155080
|
});
|
154823
155081
|
}
|
154824
155082
|
class CountMemoBlockVisitor extends ReactiveFunctionVisitor {
|
154825
|
-
constructor() {
|
154826
|
-
super(
|
154827
|
-
this.
|
155083
|
+
constructor(env) {
|
155084
|
+
super();
|
155085
|
+
this.memoBlocks = 0;
|
155086
|
+
this.memoValues = 0;
|
155087
|
+
this.prunedMemoBlocks = 0;
|
155088
|
+
this.prunedMemoValues = 0;
|
155089
|
+
this.env = env;
|
154828
155090
|
}
|
154829
|
-
visitScope(
|
154830
|
-
this.
|
154831
|
-
this.
|
155091
|
+
visitScope(scopeBlock, state) {
|
155092
|
+
this.memoBlocks += 1;
|
155093
|
+
this.memoValues += scopeBlock.scope.declarations.size;
|
155094
|
+
this.traverseScope(scopeBlock, state);
|
155095
|
+
}
|
155096
|
+
visitPrunedScope(scopeBlock, state) {
|
155097
|
+
this.prunedMemoBlocks += 1;
|
155098
|
+
this.prunedMemoValues += scopeBlock.scope.declarations.size;
|
155099
|
+
this.traversePrunedScope(scopeBlock, state);
|
154832
155100
|
}
|
154833
155101
|
}
|
154834
155102
|
function convertParameter(param) {
|
@@ -154919,6 +155187,11 @@ function codegenBlockNoReset(cx, block) {
|
|
154919
155187
|
}
|
154920
155188
|
break;
|
154921
155189
|
}
|
155190
|
+
case "pruned-scope": {
|
155191
|
+
const scopeBlock = codegenBlockNoReset(cx, item.instructions);
|
155192
|
+
statements.push(...scopeBlock.body);
|
155193
|
+
break;
|
155194
|
+
}
|
154922
155195
|
case "scope": {
|
154923
155196
|
const temp = new Map(cx.temp);
|
154924
155197
|
codegenReactiveScope(cx, statements, item.scope, item.instructions);
|
@@ -155024,8 +155297,8 @@ function codegenReactiveScope(cx, statements, scope, block) {
|
|
155024
155297
|
firstOutputIndex = index;
|
155025
155298
|
}
|
155026
155299
|
CompilerError.invariant(identifier.name != null, {
|
155027
|
-
reason: `Expected
|
155028
|
-
description:
|
155300
|
+
reason: `Expected scope declaration identifier to be named`,
|
155301
|
+
description: `Declaration \`${printIdentifier(identifier)}\` is unnamed in scope @${scope.id}`,
|
155029
155302
|
loc: null,
|
155030
155303
|
suggestions: null,
|
155031
155304
|
});
|
@@ -156470,6 +156743,13 @@ function codegenInstructionValue(cx, instrValue) {
|
|
156470
156743
|
value = t__namespace.regExpLiteral(instrValue.pattern, instrValue.flags);
|
156471
156744
|
break;
|
156472
156745
|
}
|
156746
|
+
case "MetaProperty": {
|
156747
|
+
value = t__namespace.metaProperty(
|
156748
|
+
t__namespace.identifier(instrValue.meta),
|
156749
|
+
t__namespace.identifier(instrValue.property)
|
156750
|
+
);
|
156751
|
+
break;
|
156752
|
+
}
|
156473
156753
|
case "Await": {
|
156474
156754
|
value = t__namespace.awaitExpression(
|
156475
156755
|
codegenPlaceToExpression(cx, instrValue.value)
|
@@ -156554,7 +156834,8 @@ function codegenInstructionValue(cx, instrValue) {
|
|
156554
156834
|
}
|
156555
156835
|
return value;
|
156556
156836
|
}
|
156557
|
-
const STRING_REQUIRES_EXPR_CONTAINER_PATTERN =
|
156837
|
+
const STRING_REQUIRES_EXPR_CONTAINER_PATTERN =
|
156838
|
+
/[\u{0000}-\u{001F}|\u{007F}|\u{0080}-\u{FFFF}]|"/u;
|
156558
156839
|
function codegenJsxAttribute(cx, attribute) {
|
156559
156840
|
switch (attribute.kind) {
|
156560
156841
|
case "JsxAttribute": {
|
@@ -156883,7 +157164,14 @@ let Transform$6 = class Transform extends ReactiveFunctionTransform {
|
|
156883
157164
|
transformScope(scope, isWithinLoop) {
|
156884
157165
|
this.visitScope(scope, isWithinLoop);
|
156885
157166
|
if (isWithinLoop) {
|
156886
|
-
return {
|
157167
|
+
return {
|
157168
|
+
kind: "replace",
|
157169
|
+
value: {
|
157170
|
+
kind: "pruned-scope",
|
157171
|
+
scope: scope.scope,
|
157172
|
+
instructions: scope.instructions,
|
157173
|
+
},
|
157174
|
+
};
|
156887
157175
|
} else {
|
156888
157176
|
return { kind: "keep" };
|
156889
157177
|
}
|
@@ -156927,7 +157215,17 @@ let Transform$5 = class Transform extends ReactiveFunctionTransform {
|
|
156927
157215
|
this.visitScope(scope, innerState);
|
156928
157216
|
outerState.hasHook || (outerState.hasHook = innerState.hasHook);
|
156929
157217
|
if (innerState.hasHook) {
|
156930
|
-
|
157218
|
+
if (scope.instructions.length === 1) {
|
157219
|
+
return { kind: "replace-many", value: scope.instructions };
|
157220
|
+
}
|
157221
|
+
return {
|
157222
|
+
kind: "replace",
|
157223
|
+
value: {
|
157224
|
+
kind: "pruned-scope",
|
157225
|
+
scope: scope.scope,
|
157226
|
+
instructions: scope.instructions,
|
157227
|
+
},
|
157228
|
+
};
|
156931
157229
|
} else {
|
156932
157230
|
return { kind: "keep" };
|
156933
157231
|
}
|
@@ -157153,13 +157451,26 @@ let Transform$4 = class Transform extends ReactiveFunctionTransform {
|
|
157153
157451
|
}
|
157154
157452
|
break;
|
157155
157453
|
}
|
157454
|
+
case "pruned-scope": {
|
157455
|
+
if (current !== null) {
|
157456
|
+
log$1(
|
157457
|
+
`Reset scope @${current.block.scope.id} from pruned scope @${instr.scope.id}`
|
157458
|
+
);
|
157459
|
+
reset();
|
157460
|
+
}
|
157461
|
+
break;
|
157462
|
+
}
|
157156
157463
|
case "instruction": {
|
157157
157464
|
switch (instr.instruction.value.kind) {
|
157465
|
+
case "BinaryExpression":
|
157158
157466
|
case "ComputedLoad":
|
157159
157467
|
case "JSXText":
|
157468
|
+
case "LoadGlobal":
|
157160
157469
|
case "LoadLocal":
|
157161
157470
|
case "Primitive":
|
157162
|
-
case "PropertyLoad":
|
157471
|
+
case "PropertyLoad":
|
157472
|
+
case "TemplateLiteral":
|
157473
|
+
case "UnaryExpression": {
|
157163
157474
|
if (current !== null && instr.instruction.lvalue !== null) {
|
157164
157475
|
current.lvalues.add(instr.instruction.lvalue.identifier.id);
|
157165
157476
|
}
|
@@ -157401,20 +157712,35 @@ function scopeIsEligibleForMerging(scopeBlock) {
|
|
157401
157712
|
);
|
157402
157713
|
}
|
157403
157714
|
let Visitor$9 = class Visitor extends ReactiveFunctionVisitor {
|
157404
|
-
visitScope(
|
157405
|
-
this.traverseScope(
|
157406
|
-
for (const dep of
|
157715
|
+
visitScope(scopeBlock, state) {
|
157716
|
+
this.traverseScope(scopeBlock, state);
|
157717
|
+
for (const dep of scopeBlock.scope.dependencies) {
|
157407
157718
|
const { identifier: identifier } = dep;
|
157408
157719
|
if (identifier.name == null) {
|
157409
157720
|
promoteIdentifier(identifier, state);
|
157410
157721
|
}
|
157411
157722
|
}
|
157412
|
-
for (const [, declaration] of
|
157723
|
+
for (const [, declaration] of scopeBlock.scope.declarations) {
|
157413
157724
|
if (declaration.identifier.name == null) {
|
157414
157725
|
promoteIdentifier(declaration.identifier, state);
|
157415
157726
|
}
|
157416
157727
|
}
|
157417
157728
|
}
|
157729
|
+
visitPrunedScope(scopeBlock, state) {
|
157730
|
+
var _a;
|
157731
|
+
this.traversePrunedScope(scopeBlock, state);
|
157732
|
+
for (const [, declaration] of scopeBlock.scope.declarations) {
|
157733
|
+
if (
|
157734
|
+
declaration.identifier.name == null &&
|
157735
|
+
((_a = state.pruned.get(declaration.identifier.id)) === null ||
|
157736
|
+
_a === void 0
|
157737
|
+
? void 0
|
157738
|
+
: _a.usedOutsideScope) === true
|
157739
|
+
) {
|
157740
|
+
promoteIdentifier(declaration.identifier, state);
|
157741
|
+
}
|
157742
|
+
}
|
157743
|
+
}
|
157418
157744
|
visitParam(place, state) {
|
157419
157745
|
if (place.identifier.name === null) {
|
157420
157746
|
promoteIdentifier(place.identifier, state);
|
@@ -157436,18 +157762,45 @@ let Visitor$9 = class Visitor extends ReactiveFunctionVisitor {
|
|
157436
157762
|
visitReactiveFunction(fn, this, state);
|
157437
157763
|
}
|
157438
157764
|
};
|
157439
|
-
class
|
157765
|
+
class CollectPromotableTemporaries extends ReactiveFunctionVisitor {
|
157766
|
+
constructor() {
|
157767
|
+
super(...arguments);
|
157768
|
+
this.activeScopes = [];
|
157769
|
+
}
|
157770
|
+
visitPlace(_id, place, state) {
|
157771
|
+
if (
|
157772
|
+
this.activeScopes.length !== 0 &&
|
157773
|
+
state.pruned.has(place.identifier.id)
|
157774
|
+
) {
|
157775
|
+
const prunedPlace = state.pruned.get(place.identifier.id);
|
157776
|
+
if (prunedPlace.activeScopes.indexOf(this.activeScopes.at(-1)) === -1) {
|
157777
|
+
prunedPlace.usedOutsideScope = true;
|
157778
|
+
}
|
157779
|
+
}
|
157780
|
+
}
|
157440
157781
|
visitValue(id, value, state) {
|
157441
157782
|
this.traverseValue(id, value, state);
|
157442
157783
|
if (value.kind === "JsxExpression" && value.tag.kind === "Identifier") {
|
157443
|
-
state.add(value.tag.identifier.id);
|
157784
|
+
state.tags.add(value.tag.identifier.id);
|
157444
157785
|
}
|
157445
157786
|
}
|
157787
|
+
visitPrunedScope(scopeBlock, state) {
|
157788
|
+
for (const [id] of scopeBlock.scope.declarations) {
|
157789
|
+
state.pruned.set(id, {
|
157790
|
+
activeScopes: [...this.activeScopes],
|
157791
|
+
usedOutsideScope: false,
|
157792
|
+
});
|
157793
|
+
}
|
157794
|
+
}
|
157795
|
+
visitScope(scopeBlock, state) {
|
157796
|
+
this.activeScopes.push(scopeBlock.scope.id);
|
157797
|
+
this.traverseScope(scopeBlock, state);
|
157798
|
+
this.activeScopes.pop();
|
157799
|
+
}
|
157446
157800
|
}
|
157447
157801
|
function promoteUsedTemporaries(fn) {
|
157448
|
-
const
|
157449
|
-
visitReactiveFunction(fn, new
|
157450
|
-
const state = { tags: tags };
|
157802
|
+
const state = { tags: new Set(), pruned: new Map() };
|
157803
|
+
visitReactiveFunction(fn, new CollectPromotableTemporaries(), state);
|
157451
157804
|
for (const operand of fn.params) {
|
157452
157805
|
const place = operand.kind === "Identifier" ? operand : operand.place;
|
157453
157806
|
if (place.identifier.name === null) {
|
@@ -158734,6 +159087,11 @@ class PropagationVisitor extends ReactiveFunctionVisitor {
|
|
158734
159087
|
});
|
158735
159088
|
scope.scope.dependencies = scopeDependencies;
|
158736
159089
|
}
|
159090
|
+
visitPrunedScope(scopeBlock, context) {
|
159091
|
+
context.enter(scopeBlock.scope, () => {
|
159092
|
+
this.visitBlock(scopeBlock.instructions, context);
|
159093
|
+
});
|
159094
|
+
}
|
158737
159095
|
visitInstruction(instruction, context) {
|
158738
159096
|
const { id: id, value: value, lvalue: lvalue } = instruction;
|
158739
159097
|
this.visitInstructionValue(context, id, value, lvalue);
|
@@ -159209,7 +159567,9 @@ function inferReferenceEffects(fn, options = { isFunctionExpression: false }) {
|
|
159209
159567
|
let queuedState = queuedStates.get(blockId);
|
159210
159568
|
if (queuedState != null) {
|
159211
159569
|
state =
|
159212
|
-
(_a = queuedState.merge(state)) !== null && _a !== void 0
|
159570
|
+
(_a = queuedState.merge(state)) !== null && _a !== void 0
|
159571
|
+
? _a
|
159572
|
+
: queuedState;
|
159213
159573
|
queuedStates.set(blockId, state);
|
159214
159574
|
} else {
|
159215
159575
|
const prevState = statesByBlock.get(blockId);
|
@@ -159494,7 +159854,8 @@ class InferenceState {
|
|
159494
159854
|
break;
|
159495
159855
|
}
|
159496
159856
|
case exports.Effect.Mutate: {
|
159497
|
-
if (
|
159857
|
+
if (isRefValueType(place.identifier) || isUseRefType(place.identifier));
|
159858
|
+
else if (valueKind.kind === exports.ValueKind.Context) {
|
159498
159859
|
functionEffect = {
|
159499
159860
|
kind: "ContextMutation",
|
159500
159861
|
loc: place.loc,
|
@@ -159532,7 +159893,8 @@ class InferenceState {
|
|
159532
159893
|
break;
|
159533
159894
|
}
|
159534
159895
|
case exports.Effect.Store: {
|
159535
|
-
if (
|
159896
|
+
if (isRefValueType(place.identifier) || isUseRefType(place.identifier));
|
159897
|
+
else if (valueKind.kind === exports.ValueKind.Context) {
|
159536
159898
|
functionEffect = {
|
159537
159899
|
kind: "ContextMutation",
|
159538
159900
|
loc: place.loc,
|
@@ -159750,7 +160112,7 @@ class InferenceState {
|
|
159750
160112
|
_InferenceState_variables,
|
159751
160113
|
"f"
|
159752
160114
|
)) {
|
159753
|
-
result.variables[variable] = [...values].map(identify);
|
160115
|
+
result.variables[`$${variable}`] = [...values].map(identify);
|
159754
160116
|
}
|
159755
160117
|
return result;
|
159756
160118
|
}
|
@@ -160091,17 +160453,28 @@ function inferBlock(env, functionEffects, state, block) {
|
|
160091
160453
|
};
|
160092
160454
|
break;
|
160093
160455
|
}
|
160094
|
-
case "
|
160456
|
+
case "MetaProperty": {
|
160457
|
+
if (instrValue.meta !== "import" || instrValue.property !== "meta") {
|
160458
|
+
continue;
|
160459
|
+
}
|
160095
160460
|
valueKind = {
|
160096
160461
|
kind: exports.ValueKind.Global,
|
160097
160462
|
reason: new Set([ValueReason.Global]),
|
160098
160463
|
context: new Set(),
|
160099
160464
|
};
|
160100
160465
|
break;
|
160101
|
-
|
160102
|
-
case "
|
160103
|
-
|
160104
|
-
|
160466
|
+
}
|
160467
|
+
case "LoadGlobal":
|
160468
|
+
valueKind = {
|
160469
|
+
kind: exports.ValueKind.Global,
|
160470
|
+
reason: new Set([ValueReason.Global]),
|
160471
|
+
context: new Set(),
|
160472
|
+
};
|
160473
|
+
break;
|
160474
|
+
case "Debugger":
|
160475
|
+
case "JSXText":
|
160476
|
+
case "Primitive": {
|
160477
|
+
valueKind = {
|
160105
160478
|
kind: exports.ValueKind.Primitive,
|
160106
160479
|
reason: new Set([ValueReason.Other]),
|
160107
160480
|
context: new Set(),
|
@@ -160843,6 +161216,8 @@ function getWriteErrorReason(abstractValue) {
|
|
160843
161216
|
return "Mutating component props or hook arguments is not allowed. Consider using a local variable instead";
|
160844
161217
|
} else if (abstractValue.reason.has(ValueReason.State)) {
|
160845
161218
|
return "Mutating a value returned from 'useState()', which should not be mutated. Use the setter function to update instead";
|
161219
|
+
} else if (abstractValue.reason.has(ValueReason.ReducerState)) {
|
161220
|
+
return "Mutating a value returned from 'useReducer()', which should not be mutated. Use the dispatch function to update instead";
|
160846
161221
|
} else {
|
160847
161222
|
return "This mutates a variable that React considers immutable";
|
160848
161223
|
}
|
@@ -161061,6 +161436,7 @@ function computeMemoizationInputs(env, value, lvalue, options) {
|
|
161061
161436
|
case "ComputedDelete":
|
161062
161437
|
case "PropertyDelete":
|
161063
161438
|
case "LoadGlobal":
|
161439
|
+
case "MetaProperty":
|
161064
161440
|
case "TemplateLiteral":
|
161065
161441
|
case "Primitive":
|
161066
161442
|
case "JSXText":
|
@@ -161475,6 +161851,14 @@ let Visitor$6 = class Visitor extends ReactiveFunctionVisitor {
|
|
161475
161851
|
state.add(place.identifier.id);
|
161476
161852
|
}
|
161477
161853
|
}
|
161854
|
+
visitPrunedScope(scopeBlock, state) {
|
161855
|
+
this.traversePrunedScope(scopeBlock, state);
|
161856
|
+
for (const [id, decl] of scopeBlock.scope.declarations) {
|
161857
|
+
if (!isPrimitiveType(decl.identifier)) {
|
161858
|
+
state.add(id);
|
161859
|
+
}
|
161860
|
+
}
|
161861
|
+
}
|
161478
161862
|
};
|
161479
161863
|
function collectReactiveIdentifiers(fn) {
|
161480
161864
|
const visitor = new Visitor$6();
|
@@ -161509,7 +161893,7 @@ let Visitor$5 = class Visitor extends ReactiveFunctionVisitor {
|
|
161509
161893
|
case "Destructure": {
|
161510
161894
|
if (state.has(value.value.identifier.id)) {
|
161511
161895
|
for (const lvalue of eachPatternOperand(value.lvalue.pattern)) {
|
161512
|
-
if (
|
161896
|
+
if (isStableType(lvalue.identifier)) {
|
161513
161897
|
continue;
|
161514
161898
|
}
|
161515
161899
|
state.add(lvalue.identifier.id);
|
@@ -161524,7 +161908,7 @@ let Visitor$5 = class Visitor extends ReactiveFunctionVisitor {
|
|
161524
161908
|
if (
|
161525
161909
|
lvalue !== null &&
|
161526
161910
|
state.has(value.object.identifier.id) &&
|
161527
|
-
!
|
161911
|
+
!isStableType(lvalue.identifier)
|
161528
161912
|
) {
|
161529
161913
|
state.add(lvalue.identifier.id);
|
161530
161914
|
}
|
@@ -161635,7 +162019,14 @@ let Transform$1 = class Transform extends ReactiveFunctionTransform {
|
|
161635
162019
|
(scopeBlock.scope.declarations.size === 0 ||
|
161636
162020
|
!hasOwnDeclaration(scopeBlock))
|
161637
162021
|
) {
|
161638
|
-
return {
|
162022
|
+
return {
|
162023
|
+
kind: "replace",
|
162024
|
+
value: {
|
162025
|
+
kind: "pruned-scope",
|
162026
|
+
scope: scopeBlock.scope,
|
162027
|
+
instructions: scopeBlock.instructions,
|
162028
|
+
},
|
162029
|
+
};
|
161639
162030
|
} else {
|
161640
162031
|
return { kind: "keep" };
|
161641
162032
|
}
|
@@ -161705,6 +162096,9 @@ let Visitor$2 = class Visitor extends ReactiveFunctionVisitor {
|
|
161705
162096
|
this.traverseBlock(block, state);
|
161706
162097
|
});
|
161707
162098
|
}
|
162099
|
+
visitPrunedScope(scopeBlock, state) {
|
162100
|
+
this.traverseBlock(scopeBlock.instructions, state);
|
162101
|
+
}
|
161708
162102
|
visitScope(scope, state) {
|
161709
162103
|
for (const [_, declaration] of scope.scope.declarations) {
|
161710
162104
|
state.visit(declaration.identifier);
|
@@ -161954,6 +162348,7 @@ function mayAllocate(env, instruction) {
|
|
161954
162348
|
case "DeclareContext":
|
161955
162349
|
case "StoreLocal":
|
161956
162350
|
case "LoadGlobal":
|
162351
|
+
case "MetaProperty":
|
161957
162352
|
case "TypeCastExpression":
|
161958
162353
|
case "LoadLocal":
|
161959
162354
|
case "LoadContext":
|
@@ -162406,7 +162801,7 @@ function addMemoCacheFunctionImportDeclaration(program, moduleName, localName) {
|
|
162406
162801
|
);
|
162407
162802
|
}
|
162408
162803
|
z.enum(["all_errors", "critical_errors", "none"]);
|
162409
|
-
z.enum(["infer", "annotation", "all"]);
|
162804
|
+
z.enum(["infer", "syntax", "annotation", "all"]);
|
162410
162805
|
const defaultOptions = {
|
162411
162806
|
compilationMode: "infer",
|
162412
162807
|
panicThreshold: "none",
|
@@ -162419,6 +162814,7 @@ const defaultOptions = {
|
|
162419
162814
|
flowSuppressions: false,
|
162420
162815
|
ignoreUseNoForget: false,
|
162421
162816
|
sources: (filename) => filename.indexOf("node_modules") === -1,
|
162817
|
+
enableReanimatedCheck: true,
|
162422
162818
|
};
|
162423
162819
|
function parsePluginOptions(obj) {
|
162424
162820
|
if (obj == null || typeof obj !== "object") {
|
@@ -163910,6 +164306,7 @@ function pruneableValue(value, state) {
|
|
163910
164306
|
return false;
|
163911
164307
|
}
|
163912
164308
|
case "RegExpLiteral":
|
164309
|
+
case "MetaProperty":
|
163913
164310
|
case "LoadGlobal":
|
163914
164311
|
case "ArrayExpression":
|
163915
164312
|
case "BinaryExpression":
|
@@ -164836,7 +165233,7 @@ function inferReactivePlaces(fn) {
|
|
164836
165233
|
}
|
164837
165234
|
if (hasReactiveInput) {
|
164838
165235
|
for (const lvalue of eachInstructionLValue(instruction)) {
|
164839
|
-
if (
|
165236
|
+
if (isStableType(lvalue.identifier)) {
|
164840
165237
|
continue;
|
164841
165238
|
}
|
164842
165239
|
reactiveIdentifiers.markReactive(lvalue);
|
@@ -165150,6 +165547,268 @@ function declareTemporary(env, block, result) {
|
|
165150
165547
|
},
|
165151
165548
|
});
|
165152
165549
|
}
|
165550
|
+
function instructionReordering(fn) {
|
165551
|
+
var _a;
|
165552
|
+
const shared = new Map();
|
165553
|
+
const references = findReferencedRangeOfTemporaries(fn);
|
165554
|
+
for (const [, block] of fn.body.blocks) {
|
165555
|
+
reorderBlock(fn.env, block, shared, references);
|
165556
|
+
}
|
165557
|
+
CompilerError.invariant(shared.size === 0, {
|
165558
|
+
reason: `InstructionReordering: expected all reorderable nodes to have been emitted`,
|
165559
|
+
loc:
|
165560
|
+
(_a = [...shared.values()]
|
165561
|
+
.map((node) => {
|
165562
|
+
var _a;
|
165563
|
+
return (_a = node.instruction) === null || _a === void 0
|
165564
|
+
? void 0
|
165565
|
+
: _a.loc;
|
165566
|
+
})
|
165567
|
+
.filter((loc) => loc != null)[0]) !== null && _a !== void 0
|
165568
|
+
? _a
|
165569
|
+
: GeneratedSource,
|
165570
|
+
});
|
165571
|
+
markInstructionIds(fn.body);
|
165572
|
+
}
|
165573
|
+
var ReferenceKind;
|
165574
|
+
(function (ReferenceKind) {
|
165575
|
+
ReferenceKind[(ReferenceKind["Read"] = 0)] = "Read";
|
165576
|
+
ReferenceKind[(ReferenceKind["Write"] = 1)] = "Write";
|
165577
|
+
})(ReferenceKind || (ReferenceKind = {}));
|
165578
|
+
function findReferencedRangeOfTemporaries(fn) {
|
165579
|
+
const singleUseIdentifiers = new Map();
|
165580
|
+
const lastAssignments = new Map();
|
165581
|
+
function reference(instr, place, kind) {
|
165582
|
+
var _a;
|
165583
|
+
if (
|
165584
|
+
place.identifier.name !== null &&
|
165585
|
+
place.identifier.name.kind === "named"
|
165586
|
+
) {
|
165587
|
+
if (kind === ReferenceKind.Write) {
|
165588
|
+
const name = place.identifier.name.value;
|
165589
|
+
const previous = lastAssignments.get(name);
|
165590
|
+
if (previous === undefined) {
|
165591
|
+
lastAssignments.set(name, instr);
|
165592
|
+
} else {
|
165593
|
+
lastAssignments.set(
|
165594
|
+
name,
|
165595
|
+
makeInstructionId(Math.max(previous, instr))
|
165596
|
+
);
|
165597
|
+
}
|
165598
|
+
}
|
165599
|
+
return;
|
165600
|
+
} else if (kind === ReferenceKind.Read) {
|
165601
|
+
const previousCount =
|
165602
|
+
(_a = singleUseIdentifiers.get(place.identifier.id)) !== null &&
|
165603
|
+
_a !== void 0
|
165604
|
+
? _a
|
165605
|
+
: 0;
|
165606
|
+
singleUseIdentifiers.set(place.identifier.id, previousCount + 1);
|
165607
|
+
}
|
165608
|
+
}
|
165609
|
+
for (const [, block] of fn.body.blocks) {
|
165610
|
+
for (const instr of block.instructions) {
|
165611
|
+
for (const operand of eachInstructionValueLValue(instr.value)) {
|
165612
|
+
reference(instr.id, operand, ReferenceKind.Read);
|
165613
|
+
}
|
165614
|
+
for (const lvalue of eachInstructionLValue(instr)) {
|
165615
|
+
reference(instr.id, lvalue, ReferenceKind.Write);
|
165616
|
+
}
|
165617
|
+
}
|
165618
|
+
for (const operand of eachTerminalOperand(block.terminal)) {
|
165619
|
+
reference(block.terminal.id, operand, ReferenceKind.Read);
|
165620
|
+
}
|
165621
|
+
}
|
165622
|
+
return {
|
165623
|
+
singleUseIdentifiers: new Set(
|
165624
|
+
[...singleUseIdentifiers]
|
165625
|
+
.filter(([, count]) => count === 1)
|
165626
|
+
.map(([id]) => id)
|
165627
|
+
),
|
165628
|
+
lastAssignments: lastAssignments,
|
165629
|
+
};
|
165630
|
+
}
|
165631
|
+
function reorderBlock(env, block, shared, references) {
|
165632
|
+
var _a, _b;
|
165633
|
+
const locals = new Map();
|
165634
|
+
const named = new Map();
|
165635
|
+
let previous = null;
|
165636
|
+
for (const instr of block.instructions) {
|
165637
|
+
const { lvalue: lvalue, value: value } = instr;
|
165638
|
+
const reorderability = getReorderability(instr, references);
|
165639
|
+
const node = getOrInsertWith(locals, lvalue.identifier.id, () => ({
|
165640
|
+
instruction: instr,
|
165641
|
+
dependencies: new Set(),
|
165642
|
+
reorderability: reorderability,
|
165643
|
+
depth: null,
|
165644
|
+
}));
|
165645
|
+
if (reorderability === Reorderability.Nonreorderable) {
|
165646
|
+
if (previous !== null) {
|
165647
|
+
node.dependencies.add(previous);
|
165648
|
+
}
|
165649
|
+
previous = lvalue.identifier.id;
|
165650
|
+
}
|
165651
|
+
for (const operand of eachInstructionValueOperand(value)) {
|
165652
|
+
const { name: name, id: id } = operand.identifier;
|
165653
|
+
if (name !== null && name.kind === "named") {
|
165654
|
+
const previous = named.get(name.value);
|
165655
|
+
if (previous !== undefined) {
|
165656
|
+
node.dependencies.add(previous);
|
165657
|
+
}
|
165658
|
+
named.set(name.value, lvalue.identifier.id);
|
165659
|
+
} else if (locals.has(id) || shared.has(id)) {
|
165660
|
+
node.dependencies.add(id);
|
165661
|
+
}
|
165662
|
+
}
|
165663
|
+
for (const lvalueOperand of eachInstructionValueLValue(value)) {
|
165664
|
+
const lvalueNode = getOrInsertWith(
|
165665
|
+
locals,
|
165666
|
+
lvalueOperand.identifier.id,
|
165667
|
+
() => ({ instruction: null, dependencies: new Set(), depth: null })
|
165668
|
+
);
|
165669
|
+
lvalueNode.dependencies.add(lvalue.identifier.id);
|
165670
|
+
const name = lvalueOperand.identifier.name;
|
165671
|
+
if (name !== null && name.kind === "named") {
|
165672
|
+
const previous = named.get(name.value);
|
165673
|
+
if (previous !== undefined) {
|
165674
|
+
node.dependencies.add(previous);
|
165675
|
+
}
|
165676
|
+
named.set(name.value, lvalue.identifier.id);
|
165677
|
+
}
|
165678
|
+
}
|
165679
|
+
}
|
165680
|
+
const nextInstructions = [];
|
165681
|
+
if (isExpressionBlockKind(block.kind)) {
|
165682
|
+
if (previous !== null) {
|
165683
|
+
emit(env, locals, shared, nextInstructions, previous);
|
165684
|
+
}
|
165685
|
+
if (block.instructions.length !== 0) {
|
165686
|
+
emit(
|
165687
|
+
env,
|
165688
|
+
locals,
|
165689
|
+
shared,
|
165690
|
+
nextInstructions,
|
165691
|
+
block.instructions.at(-1).lvalue.identifier.id
|
165692
|
+
);
|
165693
|
+
}
|
165694
|
+
for (const operand of eachTerminalOperand(block.terminal)) {
|
165695
|
+
emit(env, locals, shared, nextInstructions, operand.identifier.id);
|
165696
|
+
}
|
165697
|
+
for (const [id, node] of locals) {
|
165698
|
+
if (node.instruction == null) {
|
165699
|
+
continue;
|
165700
|
+
}
|
165701
|
+
CompilerError.invariant(
|
165702
|
+
node.reorderability === Reorderability.Reorderable,
|
165703
|
+
{
|
165704
|
+
reason: `Expected all remaining instructions to be reorderable`,
|
165705
|
+
loc:
|
165706
|
+
(_b =
|
165707
|
+
(_a = node.instruction) === null || _a === void 0
|
165708
|
+
? void 0
|
165709
|
+
: _a.loc) !== null && _b !== void 0
|
165710
|
+
? _b
|
165711
|
+
: block.terminal.loc,
|
165712
|
+
description:
|
165713
|
+
node.instruction != null
|
165714
|
+
? `Instruction [${node.instruction.id}] was not emitted yet but is not reorderable`
|
165715
|
+
: `Lvalue $${id} was not emitted yet but is not reorderable`,
|
165716
|
+
}
|
165717
|
+
);
|
165718
|
+
shared.set(id, node);
|
165719
|
+
}
|
165720
|
+
} else {
|
165721
|
+
for (const operand of eachTerminalOperand(block.terminal)) {
|
165722
|
+
emit(env, locals, shared, nextInstructions, operand.identifier.id);
|
165723
|
+
}
|
165724
|
+
for (const id of Array.from(locals.keys()).reverse()) {
|
165725
|
+
const node = locals.get(id);
|
165726
|
+
if (node === undefined) {
|
165727
|
+
continue;
|
165728
|
+
}
|
165729
|
+
if (node.reorderability === Reorderability.Reorderable) {
|
165730
|
+
shared.set(id, node);
|
165731
|
+
} else {
|
165732
|
+
emit(env, locals, shared, nextInstructions, id);
|
165733
|
+
}
|
165734
|
+
}
|
165735
|
+
}
|
165736
|
+
block.instructions = nextInstructions;
|
165737
|
+
}
|
165738
|
+
function getDepth(env, nodes, id) {
|
165739
|
+
const node = nodes.get(id);
|
165740
|
+
if (node == null) {
|
165741
|
+
return 0;
|
165742
|
+
}
|
165743
|
+
if (node.depth != null) {
|
165744
|
+
return node.depth;
|
165745
|
+
}
|
165746
|
+
node.depth = 0;
|
165747
|
+
let depth = node.reorderability === Reorderability.Reorderable ? 1 : 10;
|
165748
|
+
for (const dep of node.dependencies) {
|
165749
|
+
depth += getDepth(env, nodes, dep);
|
165750
|
+
}
|
165751
|
+
node.depth = depth;
|
165752
|
+
return depth;
|
165753
|
+
}
|
165754
|
+
function emit(env, locals, shared, instructions, id) {
|
165755
|
+
var _a;
|
165756
|
+
const node =
|
165757
|
+
(_a = locals.get(id)) !== null && _a !== void 0 ? _a : shared.get(id);
|
165758
|
+
if (node == null) {
|
165759
|
+
return;
|
165760
|
+
}
|
165761
|
+
locals.delete(id);
|
165762
|
+
shared.delete(id);
|
165763
|
+
const deps = [...node.dependencies];
|
165764
|
+
deps.sort((a, b) => {
|
165765
|
+
const aDepth = getDepth(env, locals, a);
|
165766
|
+
const bDepth = getDepth(env, locals, b);
|
165767
|
+
return bDepth - aDepth;
|
165768
|
+
});
|
165769
|
+
for (const dep of deps) {
|
165770
|
+
emit(env, locals, shared, instructions, dep);
|
165771
|
+
}
|
165772
|
+
if (node.instruction !== null) {
|
165773
|
+
instructions.push(node.instruction);
|
165774
|
+
}
|
165775
|
+
}
|
165776
|
+
var Reorderability;
|
165777
|
+
(function (Reorderability) {
|
165778
|
+
Reorderability[(Reorderability["Reorderable"] = 0)] = "Reorderable";
|
165779
|
+
Reorderability[(Reorderability["Nonreorderable"] = 1)] = "Nonreorderable";
|
165780
|
+
})(Reorderability || (Reorderability = {}));
|
165781
|
+
function getReorderability(instr, references) {
|
165782
|
+
switch (instr.value.kind) {
|
165783
|
+
case "JsxExpression":
|
165784
|
+
case "JsxFragment":
|
165785
|
+
case "JSXText":
|
165786
|
+
case "LoadGlobal":
|
165787
|
+
case "Primitive":
|
165788
|
+
case "TemplateLiteral":
|
165789
|
+
case "BinaryExpression":
|
165790
|
+
case "UnaryExpression": {
|
165791
|
+
return Reorderability.Reorderable;
|
165792
|
+
}
|
165793
|
+
case "LoadLocal": {
|
165794
|
+
const name = instr.value.place.identifier.name;
|
165795
|
+
if (name !== null && name.kind === "named") {
|
165796
|
+
const lastAssignment = references.lastAssignments.get(name.value);
|
165797
|
+
if (
|
165798
|
+
lastAssignment !== undefined &&
|
165799
|
+
lastAssignment < instr.id &&
|
165800
|
+
references.singleUseIdentifiers.has(instr.lvalue.identifier.id)
|
165801
|
+
) {
|
165802
|
+
return Reorderability.Reorderable;
|
165803
|
+
}
|
165804
|
+
}
|
165805
|
+
return Reorderability.Nonreorderable;
|
165806
|
+
}
|
165807
|
+
default: {
|
165808
|
+
return Reorderability.Nonreorderable;
|
165809
|
+
}
|
165810
|
+
}
|
165811
|
+
}
|
165153
165812
|
function alignMethodCallScopes(fn) {
|
165154
165813
|
const scopeMapping = new Map();
|
165155
165814
|
const mergedScopes = new DisjointSet();
|
@@ -165338,6 +165997,127 @@ function alignReactiveScopesToBlockScopesHIR(fn) {
|
|
165338
165997
|
});
|
165339
165998
|
}
|
165340
165999
|
}
|
166000
|
+
function flattenReactiveLoopsHIR(fn) {
|
166001
|
+
const activeLoops = Array();
|
166002
|
+
for (const [, block] of fn.body.blocks) {
|
166003
|
+
retainWhere(activeLoops, (id) => id !== block.id);
|
166004
|
+
const { terminal: terminal } = block;
|
166005
|
+
switch (terminal.kind) {
|
166006
|
+
case "do-while":
|
166007
|
+
case "for":
|
166008
|
+
case "for-in":
|
166009
|
+
case "for-of":
|
166010
|
+
case "while": {
|
166011
|
+
activeLoops.push(terminal.fallthrough);
|
166012
|
+
break;
|
166013
|
+
}
|
166014
|
+
case "scope": {
|
166015
|
+
if (activeLoops.length !== 0) {
|
166016
|
+
block.terminal = {
|
166017
|
+
kind: "pruned-scope",
|
166018
|
+
block: terminal.block,
|
166019
|
+
fallthrough: terminal.fallthrough,
|
166020
|
+
id: terminal.id,
|
166021
|
+
loc: terminal.loc,
|
166022
|
+
scope: terminal.scope,
|
166023
|
+
};
|
166024
|
+
}
|
166025
|
+
break;
|
166026
|
+
}
|
166027
|
+
case "branch":
|
166028
|
+
case "goto":
|
166029
|
+
case "if":
|
166030
|
+
case "label":
|
166031
|
+
case "logical":
|
166032
|
+
case "maybe-throw":
|
166033
|
+
case "optional":
|
166034
|
+
case "pruned-scope":
|
166035
|
+
case "return":
|
166036
|
+
case "sequence":
|
166037
|
+
case "switch":
|
166038
|
+
case "ternary":
|
166039
|
+
case "throw":
|
166040
|
+
case "try":
|
166041
|
+
case "unreachable":
|
166042
|
+
case "unsupported": {
|
166043
|
+
break;
|
166044
|
+
}
|
166045
|
+
default: {
|
166046
|
+
assertExhaustive(
|
166047
|
+
terminal,
|
166048
|
+
`Unexpected terminal kind \`${terminal.kind}\``
|
166049
|
+
);
|
166050
|
+
}
|
166051
|
+
}
|
166052
|
+
}
|
166053
|
+
}
|
166054
|
+
function flattenScopesWithHooksOrUseHIR(fn) {
|
166055
|
+
var _a, _b;
|
166056
|
+
const activeScopes = [];
|
166057
|
+
const prune = [];
|
166058
|
+
for (const [, block] of fn.body.blocks) {
|
166059
|
+
const firstId =
|
166060
|
+
(_b =
|
166061
|
+
(_a = block.instructions[0]) === null || _a === void 0
|
166062
|
+
? void 0
|
166063
|
+
: _a.id) !== null && _b !== void 0
|
166064
|
+
? _b
|
166065
|
+
: block.terminal.id;
|
166066
|
+
retainWhere(activeScopes, (current) => current.scope.range.end > firstId);
|
166067
|
+
for (const instr of block.instructions) {
|
166068
|
+
const { value: value } = instr;
|
166069
|
+
switch (value.kind) {
|
166070
|
+
case "MethodCall":
|
166071
|
+
case "CallExpression": {
|
166072
|
+
const callee =
|
166073
|
+
value.kind === "MethodCall" ? value.property : value.callee;
|
166074
|
+
if (
|
166075
|
+
getHookKind(fn.env, callee.identifier) != null ||
|
166076
|
+
isUseOperator(callee.identifier)
|
166077
|
+
) {
|
166078
|
+
prune.push(...activeScopes.map((entry) => entry.block));
|
166079
|
+
activeScopes.length = 0;
|
166080
|
+
}
|
166081
|
+
}
|
166082
|
+
}
|
166083
|
+
}
|
166084
|
+
if (block.terminal.kind === "scope") {
|
166085
|
+
activeScopes.push({ block: block.id, scope: block.terminal.scope });
|
166086
|
+
}
|
166087
|
+
}
|
166088
|
+
for (const id of prune) {
|
166089
|
+
const block = fn.body.blocks.get(id);
|
166090
|
+
const terminal = block.terminal;
|
166091
|
+
CompilerError.invariant(terminal.kind === "scope", {
|
166092
|
+
reason: `Expected block to have a scope terminal`,
|
166093
|
+
description: `Expected block bb${block.id} to end in a scope terminal`,
|
166094
|
+
loc: terminal.loc,
|
166095
|
+
});
|
166096
|
+
const body = fn.body.blocks.get(terminal.block);
|
166097
|
+
if (
|
166098
|
+
body.instructions.length === 1 &&
|
166099
|
+
body.terminal.kind === "goto" &&
|
166100
|
+
body.terminal.block === terminal.fallthrough
|
166101
|
+
) {
|
166102
|
+
block.terminal = {
|
166103
|
+
kind: "label",
|
166104
|
+
block: terminal.block,
|
166105
|
+
fallthrough: terminal.fallthrough,
|
166106
|
+
id: terminal.id,
|
166107
|
+
loc: terminal.loc,
|
166108
|
+
};
|
166109
|
+
continue;
|
166110
|
+
}
|
166111
|
+
block.terminal = {
|
166112
|
+
kind: "pruned-scope",
|
166113
|
+
block: terminal.block,
|
166114
|
+
fallthrough: terminal.fallthrough,
|
166115
|
+
id: terminal.id,
|
166116
|
+
loc: terminal.loc,
|
166117
|
+
scope: terminal.scope,
|
166118
|
+
};
|
166119
|
+
}
|
166120
|
+
}
|
165341
166121
|
function pruneAlwaysInvalidatingScopes(fn) {
|
165342
166122
|
visitReactiveFunction(fn, new Transform(), false);
|
165343
166123
|
}
|
@@ -165405,41 +166185,258 @@ class Transform extends ReactiveFunctionTransform {
|
|
165405
166185
|
this.unmemoizedValues.add(identifier);
|
165406
166186
|
}
|
165407
166187
|
}
|
165408
|
-
return {
|
166188
|
+
return {
|
166189
|
+
kind: "replace",
|
166190
|
+
value: {
|
166191
|
+
kind: "pruned-scope",
|
166192
|
+
scope: scopeBlock.scope,
|
166193
|
+
instructions: scopeBlock.instructions,
|
166194
|
+
},
|
166195
|
+
};
|
165409
166196
|
}
|
165410
166197
|
}
|
165411
166198
|
return { kind: "keep" };
|
165412
166199
|
}
|
165413
166200
|
}
|
165414
|
-
|
165415
|
-
|
165416
|
-
|
165417
|
-
|
165418
|
-
|
165419
|
-
|
165420
|
-
|
165421
|
-
case "**":
|
165422
|
-
case "&":
|
165423
|
-
case "|":
|
165424
|
-
case ">>":
|
165425
|
-
case "<<":
|
165426
|
-
case "^":
|
165427
|
-
case ">":
|
165428
|
-
case "<":
|
165429
|
-
case ">=":
|
165430
|
-
case "<=":
|
165431
|
-
case "|>":
|
165432
|
-
return true;
|
165433
|
-
default:
|
165434
|
-
return false;
|
166201
|
+
let Visitor$1 = class Visitor extends ReactiveFunctionVisitor {
|
166202
|
+
constructor(env, aliases, paths) {
|
166203
|
+
super();
|
166204
|
+
this.map = new Map();
|
166205
|
+
this.aliases = aliases;
|
166206
|
+
this.paths = paths;
|
166207
|
+
this.env = env;
|
165435
166208
|
}
|
165436
|
-
|
165437
|
-
function
|
165438
|
-
|
165439
|
-
|
165440
|
-
|
166209
|
+
join(values) {
|
166210
|
+
function join2(l, r) {
|
166211
|
+
if (l === "Update" || r === "Update") {
|
166212
|
+
return "Update";
|
166213
|
+
} else if (l === "Create" || r === "Create") {
|
166214
|
+
return "Create";
|
166215
|
+
} else if (l === "Unknown" || r === "Unknown") {
|
166216
|
+
return "Unknown";
|
166217
|
+
}
|
166218
|
+
assertExhaustive(r, `Unhandled variable kind ${r}`);
|
166219
|
+
}
|
166220
|
+
return values.reduce(join2, "Unknown");
|
165441
166221
|
}
|
165442
|
-
|
166222
|
+
isCreateOnlyHook(id) {
|
166223
|
+
return isUseStateType(id) || isUseRefType(id);
|
166224
|
+
}
|
166225
|
+
visitPlace(_, place, state) {
|
166226
|
+
var _a;
|
166227
|
+
this.map.set(
|
166228
|
+
place.identifier.id,
|
166229
|
+
this.join([
|
166230
|
+
state,
|
166231
|
+
(_a = this.map.get(place.identifier.id)) !== null && _a !== void 0
|
166232
|
+
? _a
|
166233
|
+
: "Unknown",
|
166234
|
+
])
|
166235
|
+
);
|
166236
|
+
}
|
166237
|
+
visitBlock(block, state) {
|
166238
|
+
super.visitBlock([...block].reverse(), state);
|
166239
|
+
}
|
166240
|
+
visitInstruction(instruction) {
|
166241
|
+
const state = this.join(
|
166242
|
+
[...eachInstructionLValue(instruction)].map((operand) => {
|
166243
|
+
var _a;
|
166244
|
+
return (_a = this.map.get(operand.identifier.id)) !== null &&
|
166245
|
+
_a !== void 0
|
166246
|
+
? _a
|
166247
|
+
: "Unknown";
|
166248
|
+
})
|
166249
|
+
);
|
166250
|
+
const visitCallOrMethodNonArgs = () => {
|
166251
|
+
switch (instruction.value.kind) {
|
166252
|
+
case "CallExpression": {
|
166253
|
+
this.visitPlace(instruction.id, instruction.value.callee, state);
|
166254
|
+
break;
|
166255
|
+
}
|
166256
|
+
case "MethodCall": {
|
166257
|
+
this.visitPlace(instruction.id, instruction.value.property, state);
|
166258
|
+
this.visitPlace(instruction.id, instruction.value.receiver, state);
|
166259
|
+
break;
|
166260
|
+
}
|
166261
|
+
}
|
166262
|
+
};
|
166263
|
+
const isHook = () => {
|
166264
|
+
let callee = null;
|
166265
|
+
switch (instruction.value.kind) {
|
166266
|
+
case "CallExpression": {
|
166267
|
+
callee = instruction.value.callee.identifier;
|
166268
|
+
break;
|
166269
|
+
}
|
166270
|
+
case "MethodCall": {
|
166271
|
+
callee = instruction.value.property.identifier;
|
166272
|
+
break;
|
166273
|
+
}
|
166274
|
+
}
|
166275
|
+
return callee != null && getHookKind(this.env, callee) != null;
|
166276
|
+
};
|
166277
|
+
switch (instruction.value.kind) {
|
166278
|
+
case "CallExpression":
|
166279
|
+
case "MethodCall": {
|
166280
|
+
if (
|
166281
|
+
instruction.lvalue &&
|
166282
|
+
this.isCreateOnlyHook(instruction.lvalue.identifier)
|
166283
|
+
) {
|
166284
|
+
[...eachCallArgument(instruction.value.args)].forEach((operand) =>
|
166285
|
+
this.visitPlace(instruction.id, operand, "Create")
|
166286
|
+
);
|
166287
|
+
visitCallOrMethodNonArgs();
|
166288
|
+
} else {
|
166289
|
+
this.traverseInstruction(instruction, isHook() ? "Update" : state);
|
166290
|
+
}
|
166291
|
+
break;
|
166292
|
+
}
|
166293
|
+
default: {
|
166294
|
+
this.traverseInstruction(instruction, state);
|
166295
|
+
}
|
166296
|
+
}
|
166297
|
+
}
|
166298
|
+
visitScope(scope) {
|
166299
|
+
const state = this.join(
|
166300
|
+
[
|
166301
|
+
...scope.scope.declarations.keys(),
|
166302
|
+
...[...scope.scope.reassignments.values()].map((ident) => ident.id),
|
166303
|
+
].map((id) => {
|
166304
|
+
var _a;
|
166305
|
+
return (_a = this.map.get(id)) !== null && _a !== void 0
|
166306
|
+
? _a
|
166307
|
+
: "Unknown";
|
166308
|
+
})
|
166309
|
+
);
|
166310
|
+
super.visitScope(scope, state);
|
166311
|
+
[...scope.scope.dependencies].forEach((ident) => {
|
166312
|
+
var _a;
|
166313
|
+
let target =
|
166314
|
+
(_a = this.aliases.find(ident.identifier.id)) !== null && _a !== void 0
|
166315
|
+
? _a
|
166316
|
+
: ident.identifier.id;
|
166317
|
+
ident.path.forEach((key) => {
|
166318
|
+
var _a;
|
166319
|
+
target &&
|
166320
|
+
(target =
|
166321
|
+
(_a = this.paths.get(target)) === null || _a === void 0
|
166322
|
+
? void 0
|
166323
|
+
: _a.get(key));
|
166324
|
+
});
|
166325
|
+
if (target && this.map.get(target) === "Create") {
|
166326
|
+
scope.scope.dependencies.delete(ident);
|
166327
|
+
}
|
166328
|
+
});
|
166329
|
+
}
|
166330
|
+
visitTerminal(stmt, state) {
|
166331
|
+
CompilerError.invariant(state !== "Create", {
|
166332
|
+
reason: "Visiting a terminal statement with state 'Create'",
|
166333
|
+
loc: stmt.terminal.loc,
|
166334
|
+
});
|
166335
|
+
super.visitTerminal(stmt, state);
|
166336
|
+
}
|
166337
|
+
visitReactiveFunctionValue(_id, _dependencies, fn, state) {
|
166338
|
+
visitReactiveFunction(fn, this, state);
|
166339
|
+
}
|
166340
|
+
};
|
166341
|
+
function pruneInitializationDependencies(fn) {
|
166342
|
+
const [aliases, paths] = getAliases(fn);
|
166343
|
+
visitReactiveFunction(fn, new Visitor$1(fn.env, aliases, paths), "Update");
|
166344
|
+
}
|
166345
|
+
function update(map, key, path, value) {
|
166346
|
+
var _a;
|
166347
|
+
const inner = (_a = map.get(key)) !== null && _a !== void 0 ? _a : new Map();
|
166348
|
+
inner.set(path, value);
|
166349
|
+
map.set(key, inner);
|
166350
|
+
}
|
166351
|
+
class AliasVisitor extends ReactiveFunctionVisitor {
|
166352
|
+
constructor() {
|
166353
|
+
super(...arguments);
|
166354
|
+
this.scopeIdentifiers = new DisjointSet();
|
166355
|
+
this.scopePaths = new Map();
|
166356
|
+
}
|
166357
|
+
visitInstruction(instr) {
|
166358
|
+
if (
|
166359
|
+
instr.value.kind === "StoreLocal" ||
|
166360
|
+
instr.value.kind === "StoreContext"
|
166361
|
+
) {
|
166362
|
+
this.scopeIdentifiers.union([
|
166363
|
+
instr.value.lvalue.place.identifier.id,
|
166364
|
+
instr.value.value.identifier.id,
|
166365
|
+
]);
|
166366
|
+
} else if (
|
166367
|
+
instr.value.kind === "LoadLocal" ||
|
166368
|
+
instr.value.kind === "LoadContext"
|
166369
|
+
) {
|
166370
|
+
instr.lvalue &&
|
166371
|
+
this.scopeIdentifiers.union([
|
166372
|
+
instr.lvalue.identifier.id,
|
166373
|
+
instr.value.place.identifier.id,
|
166374
|
+
]);
|
166375
|
+
} else if (instr.value.kind === "PropertyLoad") {
|
166376
|
+
instr.lvalue &&
|
166377
|
+
update(
|
166378
|
+
this.scopePaths,
|
166379
|
+
instr.value.object.identifier.id,
|
166380
|
+
instr.value.property,
|
166381
|
+
instr.lvalue.identifier.id
|
166382
|
+
);
|
166383
|
+
} else if (instr.value.kind === "PropertyStore") {
|
166384
|
+
update(
|
166385
|
+
this.scopePaths,
|
166386
|
+
instr.value.object.identifier.id,
|
166387
|
+
instr.value.property,
|
166388
|
+
instr.value.value.identifier.id
|
166389
|
+
);
|
166390
|
+
}
|
166391
|
+
}
|
166392
|
+
}
|
166393
|
+
function getAliases(fn) {
|
166394
|
+
var _a, _b;
|
166395
|
+
const visitor = new AliasVisitor();
|
166396
|
+
visitReactiveFunction(fn, visitor, null);
|
166397
|
+
let disjoint = visitor.scopeIdentifiers;
|
166398
|
+
let scopePaths = new Map();
|
166399
|
+
for (const [key, value] of visitor.scopePaths) {
|
166400
|
+
for (const [path, id] of value) {
|
166401
|
+
update(
|
166402
|
+
scopePaths,
|
166403
|
+
(_a = disjoint.find(key)) !== null && _a !== void 0 ? _a : key,
|
166404
|
+
path,
|
166405
|
+
(_b = disjoint.find(id)) !== null && _b !== void 0 ? _b : id
|
166406
|
+
);
|
166407
|
+
}
|
166408
|
+
}
|
166409
|
+
return [disjoint, scopePaths];
|
166410
|
+
}
|
166411
|
+
function isPrimitiveBinaryOp(op) {
|
166412
|
+
switch (op) {
|
166413
|
+
case "+":
|
166414
|
+
case "-":
|
166415
|
+
case "/":
|
166416
|
+
case "%":
|
166417
|
+
case "*":
|
166418
|
+
case "**":
|
166419
|
+
case "&":
|
166420
|
+
case "|":
|
166421
|
+
case ">>":
|
166422
|
+
case "<<":
|
166423
|
+
case "^":
|
166424
|
+
case ">":
|
166425
|
+
case "<":
|
166426
|
+
case ">=":
|
166427
|
+
case "<=":
|
166428
|
+
case "|>":
|
166429
|
+
return true;
|
166430
|
+
default:
|
166431
|
+
return false;
|
166432
|
+
}
|
166433
|
+
}
|
166434
|
+
function inferTypes(func) {
|
166435
|
+
const unifier = new Unifier(func.env);
|
166436
|
+
for (const e of generate(func)) {
|
166437
|
+
unifier.unify(e.left, e.right);
|
166438
|
+
}
|
166439
|
+
apply(func, unifier);
|
165443
166440
|
}
|
165444
166441
|
function apply(func, unifier) {
|
165445
166442
|
for (const [_, block] of func.body.blocks) {
|
@@ -165469,7 +166466,13 @@ function equation(left, right) {
|
|
165469
166466
|
}
|
165470
166467
|
function* generate(func) {
|
165471
166468
|
if (func.env.fnType === "Component") {
|
165472
|
-
const [
|
166469
|
+
const [props, ref] = func.params;
|
166470
|
+
if (props && props.kind === "Identifier") {
|
166471
|
+
yield equation(props.identifier.type, {
|
166472
|
+
kind: "Object",
|
166473
|
+
shapeId: BuiltInPropsId,
|
166474
|
+
});
|
166475
|
+
}
|
165473
166476
|
if (ref && ref.kind === "Identifier") {
|
165474
166477
|
yield equation(ref.identifier.type, {
|
165475
166478
|
kind: "Object",
|
@@ -165477,6 +166480,7 @@ function* generate(func) {
|
|
165477
166480
|
});
|
165478
166481
|
}
|
165479
166482
|
}
|
166483
|
+
const names = new Map();
|
165480
166484
|
for (const [_, block] of func.body.blocks) {
|
165481
166485
|
for (const phi of block.phis) {
|
165482
166486
|
yield equation(phi.type, {
|
@@ -165485,11 +166489,23 @@ function* generate(func) {
|
|
165485
166489
|
});
|
165486
166490
|
}
|
165487
166491
|
for (const instr of block.instructions) {
|
165488
|
-
yield* generateInstructionTypes(func.env, instr);
|
166492
|
+
yield* generateInstructionTypes(func.env, names, instr);
|
165489
166493
|
}
|
165490
166494
|
}
|
165491
166495
|
}
|
165492
|
-
function
|
166496
|
+
function setName(names, id, name) {
|
166497
|
+
var _a;
|
166498
|
+
if (
|
166499
|
+
((_a = name.name) === null || _a === void 0 ? void 0 : _a.kind) === "named"
|
166500
|
+
) {
|
166501
|
+
names.set(id, name.name.value);
|
166502
|
+
}
|
166503
|
+
}
|
166504
|
+
function getName(names, id) {
|
166505
|
+
var _a;
|
166506
|
+
return (_a = names.get(id)) !== null && _a !== void 0 ? _a : "";
|
166507
|
+
}
|
166508
|
+
function* generateInstructionTypes(env, names, instr) {
|
165493
166509
|
const { lvalue: lvalue, value: value } = instr;
|
165494
166510
|
const left = lvalue.identifier.type;
|
165495
166511
|
switch (value.kind) {
|
@@ -165504,6 +166520,7 @@ function* generateInstructionTypes(env, instr) {
|
|
165504
166520
|
break;
|
165505
166521
|
}
|
165506
166522
|
case "LoadLocal": {
|
166523
|
+
setName(names, lvalue.identifier.id, value.place.identifier);
|
165507
166524
|
yield equation(left, value.place.identifier.type);
|
165508
166525
|
break;
|
165509
166526
|
}
|
@@ -165586,7 +166603,8 @@ function* generateInstructionTypes(env, instr) {
|
|
165586
166603
|
case "PropertyLoad": {
|
165587
166604
|
yield equation(left, {
|
165588
166605
|
kind: "Property",
|
165589
|
-
|
166606
|
+
objectType: value.object.identifier.type,
|
166607
|
+
objectName: getName(names, value.object.identifier.id),
|
165590
166608
|
propertyName: value.property,
|
165591
166609
|
});
|
165592
166610
|
break;
|
@@ -165610,7 +166628,8 @@ function* generateInstructionTypes(env, instr) {
|
|
165610
166628
|
const propertyName = String(i);
|
165611
166629
|
yield equation(item.identifier.type, {
|
165612
166630
|
kind: "Property",
|
165613
|
-
|
166631
|
+
objectType: value.value.identifier.type,
|
166632
|
+
objectName: getName(names, value.value.identifier.id),
|
165614
166633
|
propertyName: propertyName,
|
165615
166634
|
});
|
165616
166635
|
} else {
|
@@ -165626,7 +166645,8 @@ function* generateInstructionTypes(env, instr) {
|
|
165626
166645
|
) {
|
165627
166646
|
yield equation(property.place.identifier.type, {
|
165628
166647
|
kind: "Property",
|
165629
|
-
|
166648
|
+
objectType: value.value.identifier.type,
|
166649
|
+
objectName: getName(names, value.value.identifier.id),
|
165630
166650
|
propertyName: property.key.name,
|
165631
166651
|
});
|
165632
166652
|
}
|
@@ -165668,10 +166688,11 @@ function* generateInstructionTypes(env, instr) {
|
|
165668
166688
|
yield equation(left, { kind: "Object", shapeId: BuiltInJsxId });
|
165669
166689
|
break;
|
165670
166690
|
}
|
166691
|
+
case "PropertyStore":
|
165671
166692
|
case "DeclareLocal":
|
165672
166693
|
case "NewExpression":
|
165673
166694
|
case "RegExpLiteral":
|
165674
|
-
case "
|
166695
|
+
case "MetaProperty":
|
165675
166696
|
case "ComputedStore":
|
165676
166697
|
case "ComputedLoad":
|
165677
166698
|
case "TaggedTemplateExpression":
|
@@ -165695,7 +166716,15 @@ class Unifier {
|
|
165695
166716
|
}
|
165696
166717
|
unify(tA, tB) {
|
165697
166718
|
if (tB.kind === "Property") {
|
165698
|
-
|
166719
|
+
if (
|
166720
|
+
this.env.config.enableTreatRefLikeIdentifiersAsRefs &&
|
166721
|
+
isRefLikeName(tB)
|
166722
|
+
) {
|
166723
|
+
this.unify(tB.objectType, { kind: "Object", shapeId: BuiltInUseRefId });
|
166724
|
+
this.unify(tA, { kind: "Object", shapeId: BuiltInRefValueId });
|
166725
|
+
return;
|
166726
|
+
}
|
166727
|
+
const objectType = this.get(tB.objectType);
|
165699
166728
|
const propertyType = this.env.getPropertyType(
|
165700
166729
|
objectType,
|
165701
166730
|
tB.propertyName
|
@@ -165777,6 +166806,10 @@ class Unifier {
|
|
165777
166806
|
return type;
|
165778
166807
|
}
|
165779
166808
|
}
|
166809
|
+
const RefLikeNameRE = /^(?:[a-zA-Z$_][a-zA-Z$_0-9]*)Ref$|^ref$/;
|
166810
|
+
function isRefLikeName(t) {
|
166811
|
+
return RefLikeNameRE.test(t.objectName) && t.propertyName === "current";
|
166812
|
+
}
|
165780
166813
|
function validateContextVariableLValues(fn) {
|
165781
166814
|
const identifierKinds = new Map();
|
165782
166815
|
validateContextVariableLValuesImpl(fn, identifierKinds);
|
@@ -166547,7 +167580,7 @@ function validateNonSetState(errors, unconditionalSetStateFunctions, operand) {
|
|
166547
167580
|
}
|
166548
167581
|
function validatePreservedManualMemoization(fn) {
|
166549
167582
|
const state = { errors: new CompilerError(), manualMemoState: null };
|
166550
|
-
visitReactiveFunction(fn, new Visitor
|
167583
|
+
visitReactiveFunction(fn, new Visitor(), state);
|
166551
167584
|
if (state.errors.hasErrors()) {
|
166552
167585
|
throw state.errors;
|
166553
167586
|
}
|
@@ -166669,7 +167702,7 @@ function validateInferredDep(
|
|
166669
167702
|
suggestions: null,
|
166670
167703
|
});
|
166671
167704
|
}
|
166672
|
-
|
167705
|
+
class Visitor extends ReactiveFunctionVisitor {
|
166673
167706
|
constructor() {
|
166674
167707
|
super(...arguments);
|
166675
167708
|
this.scopes = new Set();
|
@@ -166838,7 +167871,7 @@ let Visitor$1 = class Visitor extends ReactiveFunctionVisitor {
|
|
166838
167871
|
}
|
166839
167872
|
}
|
166840
167873
|
}
|
166841
|
-
}
|
167874
|
+
}
|
166842
167875
|
function isUnmemoized(operand, scopes) {
|
166843
167876
|
return operand.scope != null && !scopes.has(operand.scope.id);
|
166844
167877
|
}
|
@@ -166910,216 +167943,6 @@ function validateUseMemo(fn) {
|
|
166910
167943
|
}
|
166911
167944
|
}
|
166912
167945
|
}
|
166913
|
-
class Visitor extends ReactiveFunctionVisitor {
|
166914
|
-
constructor(env, aliases, paths) {
|
166915
|
-
super();
|
166916
|
-
this.map = new Map();
|
166917
|
-
this.aliases = aliases;
|
166918
|
-
this.paths = paths;
|
166919
|
-
this.env = env;
|
166920
|
-
}
|
166921
|
-
join(values) {
|
166922
|
-
function join2(l, r) {
|
166923
|
-
if (l === "Update" || r === "Update") {
|
166924
|
-
return "Update";
|
166925
|
-
} else if (l === "Create" || r === "Create") {
|
166926
|
-
return "Create";
|
166927
|
-
} else if (l === "Unknown" || r === "Unknown") {
|
166928
|
-
return "Unknown";
|
166929
|
-
}
|
166930
|
-
assertExhaustive(r, `Unhandled variable kind ${r}`);
|
166931
|
-
}
|
166932
|
-
return values.reduce(join2, "Unknown");
|
166933
|
-
}
|
166934
|
-
isCreateOnlyHook(id) {
|
166935
|
-
return isUseStateType(id) || isUseRefType(id);
|
166936
|
-
}
|
166937
|
-
visitPlace(_, place, state) {
|
166938
|
-
var _a;
|
166939
|
-
this.map.set(
|
166940
|
-
place.identifier.id,
|
166941
|
-
this.join([
|
166942
|
-
state,
|
166943
|
-
(_a = this.map.get(place.identifier.id)) !== null && _a !== void 0
|
166944
|
-
? _a
|
166945
|
-
: "Unknown",
|
166946
|
-
])
|
166947
|
-
);
|
166948
|
-
}
|
166949
|
-
visitBlock(block, state) {
|
166950
|
-
super.visitBlock([...block].reverse(), state);
|
166951
|
-
}
|
166952
|
-
visitInstruction(instruction) {
|
166953
|
-
const state = this.join(
|
166954
|
-
[...eachInstructionLValue(instruction)].map((operand) => {
|
166955
|
-
var _a;
|
166956
|
-
return (_a = this.map.get(operand.identifier.id)) !== null &&
|
166957
|
-
_a !== void 0
|
166958
|
-
? _a
|
166959
|
-
: "Unknown";
|
166960
|
-
})
|
166961
|
-
);
|
166962
|
-
const visitCallOrMethodNonArgs = () => {
|
166963
|
-
switch (instruction.value.kind) {
|
166964
|
-
case "CallExpression": {
|
166965
|
-
this.visitPlace(instruction.id, instruction.value.callee, state);
|
166966
|
-
break;
|
166967
|
-
}
|
166968
|
-
case "MethodCall": {
|
166969
|
-
this.visitPlace(instruction.id, instruction.value.property, state);
|
166970
|
-
this.visitPlace(instruction.id, instruction.value.receiver, state);
|
166971
|
-
break;
|
166972
|
-
}
|
166973
|
-
}
|
166974
|
-
};
|
166975
|
-
const isHook = () => {
|
166976
|
-
let callee = null;
|
166977
|
-
switch (instruction.value.kind) {
|
166978
|
-
case "CallExpression": {
|
166979
|
-
callee = instruction.value.callee.identifier;
|
166980
|
-
break;
|
166981
|
-
}
|
166982
|
-
case "MethodCall": {
|
166983
|
-
callee = instruction.value.property.identifier;
|
166984
|
-
break;
|
166985
|
-
}
|
166986
|
-
}
|
166987
|
-
return callee != null && getHookKind(this.env, callee) != null;
|
166988
|
-
};
|
166989
|
-
switch (instruction.value.kind) {
|
166990
|
-
case "CallExpression":
|
166991
|
-
case "MethodCall": {
|
166992
|
-
if (
|
166993
|
-
instruction.lvalue &&
|
166994
|
-
this.isCreateOnlyHook(instruction.lvalue.identifier)
|
166995
|
-
) {
|
166996
|
-
[...eachCallArgument(instruction.value.args)].forEach((operand) =>
|
166997
|
-
this.visitPlace(instruction.id, operand, "Create")
|
166998
|
-
);
|
166999
|
-
visitCallOrMethodNonArgs();
|
167000
|
-
} else {
|
167001
|
-
this.traverseInstruction(instruction, isHook() ? "Update" : state);
|
167002
|
-
}
|
167003
|
-
break;
|
167004
|
-
}
|
167005
|
-
default: {
|
167006
|
-
this.traverseInstruction(instruction, state);
|
167007
|
-
}
|
167008
|
-
}
|
167009
|
-
}
|
167010
|
-
visitScope(scope) {
|
167011
|
-
const state = this.join(
|
167012
|
-
[
|
167013
|
-
...scope.scope.declarations.keys(),
|
167014
|
-
...[...scope.scope.reassignments.values()].map((ident) => ident.id),
|
167015
|
-
].map((id) => {
|
167016
|
-
var _a;
|
167017
|
-
return (_a = this.map.get(id)) !== null && _a !== void 0
|
167018
|
-
? _a
|
167019
|
-
: "Unknown";
|
167020
|
-
})
|
167021
|
-
);
|
167022
|
-
super.visitScope(scope, state);
|
167023
|
-
[...scope.scope.dependencies].forEach((ident) => {
|
167024
|
-
var _a;
|
167025
|
-
let target =
|
167026
|
-
(_a = this.aliases.find(ident.identifier.id)) !== null && _a !== void 0
|
167027
|
-
? _a
|
167028
|
-
: ident.identifier.id;
|
167029
|
-
ident.path.forEach((key) => {
|
167030
|
-
var _a;
|
167031
|
-
target &&
|
167032
|
-
(target =
|
167033
|
-
(_a = this.paths.get(target)) === null || _a === void 0
|
167034
|
-
? void 0
|
167035
|
-
: _a.get(key));
|
167036
|
-
});
|
167037
|
-
if (target && this.map.get(target) === "Create") {
|
167038
|
-
scope.scope.dependencies.delete(ident);
|
167039
|
-
}
|
167040
|
-
});
|
167041
|
-
}
|
167042
|
-
visitTerminal(stmt, state) {
|
167043
|
-
CompilerError.invariant(state !== "Create", {
|
167044
|
-
reason: "Visiting a terminal statement with state 'Create'",
|
167045
|
-
loc: stmt.terminal.loc,
|
167046
|
-
});
|
167047
|
-
super.visitTerminal(stmt, state);
|
167048
|
-
}
|
167049
|
-
visitReactiveFunctionValue(_id, _dependencies, fn, state) {
|
167050
|
-
visitReactiveFunction(fn, this, state);
|
167051
|
-
}
|
167052
|
-
}
|
167053
|
-
function pruneInitializationDependencies(fn) {
|
167054
|
-
const [aliases, paths] = getAliases(fn);
|
167055
|
-
visitReactiveFunction(fn, new Visitor(fn.env, aliases, paths), "Update");
|
167056
|
-
}
|
167057
|
-
function update(map, key, path, value) {
|
167058
|
-
var _a;
|
167059
|
-
const inner = (_a = map.get(key)) !== null && _a !== void 0 ? _a : new Map();
|
167060
|
-
inner.set(path, value);
|
167061
|
-
map.set(key, inner);
|
167062
|
-
}
|
167063
|
-
class AliasVisitor extends ReactiveFunctionVisitor {
|
167064
|
-
constructor() {
|
167065
|
-
super(...arguments);
|
167066
|
-
this.scopeIdentifiers = new DisjointSet();
|
167067
|
-
this.scopePaths = new Map();
|
167068
|
-
}
|
167069
|
-
visitInstruction(instr) {
|
167070
|
-
if (
|
167071
|
-
instr.value.kind === "StoreLocal" ||
|
167072
|
-
instr.value.kind === "StoreContext"
|
167073
|
-
) {
|
167074
|
-
this.scopeIdentifiers.union([
|
167075
|
-
instr.value.lvalue.place.identifier.id,
|
167076
|
-
instr.value.value.identifier.id,
|
167077
|
-
]);
|
167078
|
-
} else if (
|
167079
|
-
instr.value.kind === "LoadLocal" ||
|
167080
|
-
instr.value.kind === "LoadContext"
|
167081
|
-
) {
|
167082
|
-
instr.lvalue &&
|
167083
|
-
this.scopeIdentifiers.union([
|
167084
|
-
instr.lvalue.identifier.id,
|
167085
|
-
instr.value.place.identifier.id,
|
167086
|
-
]);
|
167087
|
-
} else if (instr.value.kind === "PropertyLoad") {
|
167088
|
-
instr.lvalue &&
|
167089
|
-
update(
|
167090
|
-
this.scopePaths,
|
167091
|
-
instr.value.object.identifier.id,
|
167092
|
-
instr.value.property,
|
167093
|
-
instr.lvalue.identifier.id
|
167094
|
-
);
|
167095
|
-
} else if (instr.value.kind === "PropertyStore") {
|
167096
|
-
update(
|
167097
|
-
this.scopePaths,
|
167098
|
-
instr.value.object.identifier.id,
|
167099
|
-
instr.value.property,
|
167100
|
-
instr.value.value.identifier.id
|
167101
|
-
);
|
167102
|
-
}
|
167103
|
-
}
|
167104
|
-
}
|
167105
|
-
function getAliases(fn) {
|
167106
|
-
var _a, _b;
|
167107
|
-
const visitor = new AliasVisitor();
|
167108
|
-
visitReactiveFunction(fn, visitor, null);
|
167109
|
-
let disjoint = visitor.scopeIdentifiers;
|
167110
|
-
let scopePaths = new Map();
|
167111
|
-
for (const [key, value] of visitor.scopePaths) {
|
167112
|
-
for (const [path, id] of value) {
|
167113
|
-
update(
|
167114
|
-
scopePaths,
|
167115
|
-
(_a = disjoint.find(key)) !== null && _a !== void 0 ? _a : key,
|
167116
|
-
path,
|
167117
|
-
(_b = disjoint.find(id)) !== null && _b !== void 0 ? _b : id
|
167118
|
-
);
|
167119
|
-
}
|
167120
|
-
}
|
167121
|
-
return [disjoint, scopePaths];
|
167122
|
-
}
|
167123
167946
|
function* run(
|
167124
167947
|
func,
|
167125
167948
|
config,
|
@@ -167193,6 +168016,10 @@ function* runWithEnvironment(func, env) {
|
|
167193
168016
|
yield log({ kind: "hir", name: "InferReferenceEffects", value: hir });
|
167194
168017
|
deadCodeElimination(hir);
|
167195
168018
|
yield log({ kind: "hir", name: "DeadCodeElimination", value: hir });
|
168019
|
+
if (env.config.enableInstructionReordering) {
|
168020
|
+
instructionReordering(hir);
|
168021
|
+
yield log({ kind: "hir", name: "InstructionReordering", value: hir });
|
168022
|
+
}
|
167196
168023
|
pruneMaybeThrows(hir);
|
167197
168024
|
yield log({ kind: "hir", name: "PruneMaybeThrows", value: hir });
|
167198
168025
|
inferMutableRanges(hir);
|
@@ -167216,8 +168043,12 @@ function* runWithEnvironment(func, env) {
|
|
167216
168043
|
yield log({ kind: "hir", name: "AlignMethodCallScopes", value: hir });
|
167217
168044
|
alignObjectMethodScopes(hir);
|
167218
168045
|
yield log({ kind: "hir", name: "AlignObjectMethodScopes", value: hir });
|
167219
|
-
|
167220
|
-
yield log({
|
168046
|
+
memoizeFbtAndMacroOperandsInSameScope(hir);
|
168047
|
+
yield log({
|
168048
|
+
kind: "hir",
|
168049
|
+
name: "MemoizeFbtAndMacroOperandsInSameScope",
|
168050
|
+
value: hir,
|
168051
|
+
});
|
167221
168052
|
if (env.config.enableReactiveScopesInHIR) {
|
167222
168053
|
pruneUnusedLabelsHIR(hir);
|
167223
168054
|
yield log({ kind: "hir", name: "PruneUnusedLabelsHIR", value: hir });
|
@@ -167241,6 +168072,14 @@ function* runWithEnvironment(func, env) {
|
|
167241
168072
|
value: hir,
|
167242
168073
|
});
|
167243
168074
|
assertValidBlockNesting(hir);
|
168075
|
+
flattenReactiveLoopsHIR(hir);
|
168076
|
+
yield log({ kind: "hir", name: "FlattenReactiveLoopsHIR", value: hir });
|
168077
|
+
flattenScopesWithHooksOrUseHIR(hir);
|
168078
|
+
yield log({
|
168079
|
+
kind: "hir",
|
168080
|
+
name: "FlattenScopesWithHooksOrUseHIR",
|
168081
|
+
value: hir,
|
168082
|
+
});
|
167244
168083
|
}
|
167245
168084
|
const reactiveFunction = buildReactiveFunction(hir);
|
167246
168085
|
yield log({
|
@@ -167274,20 +168113,20 @@ function* runWithEnvironment(func, env) {
|
|
167274
168113
|
name: "BuildReactiveBlocks",
|
167275
168114
|
value: reactiveFunction,
|
167276
168115
|
});
|
168116
|
+
flattenReactiveLoops(reactiveFunction);
|
168117
|
+
yield log({
|
168118
|
+
kind: "reactive",
|
168119
|
+
name: "FlattenReactiveLoops",
|
168120
|
+
value: reactiveFunction,
|
168121
|
+
});
|
168122
|
+
flattenScopesWithHooksOrUse(reactiveFunction);
|
168123
|
+
yield log({
|
168124
|
+
kind: "reactive",
|
168125
|
+
name: "FlattenScopesWithHooks",
|
168126
|
+
value: reactiveFunction,
|
168127
|
+
});
|
167277
168128
|
}
|
167278
|
-
flattenReactiveLoops(reactiveFunction);
|
167279
|
-
yield log({
|
167280
|
-
kind: "reactive",
|
167281
|
-
name: "FlattenReactiveLoops",
|
167282
|
-
value: reactiveFunction,
|
167283
|
-
});
|
167284
168129
|
assertScopeInstructionsWithinScopes(reactiveFunction);
|
167285
|
-
flattenScopesWithHooksOrUse(reactiveFunction);
|
167286
|
-
yield log({
|
167287
|
-
kind: "reactive",
|
167288
|
-
name: "FlattenScopesWithHooks",
|
167289
|
-
value: reactiveFunction,
|
167290
|
-
});
|
167291
168130
|
propagateScopeDependencies(reactiveFunction);
|
167292
168131
|
yield log({
|
167293
168132
|
kind: "reactive",
|
@@ -167721,8 +168560,7 @@ function isFilePartOfSources(sources, filename) {
|
|
167721
168560
|
}
|
167722
168561
|
function compileProgram(program, pass) {
|
167723
168562
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
167724
|
-
|
167725
|
-
if (options.sources) {
|
168563
|
+
if (pass.opts.sources) {
|
167726
168564
|
if (pass.filename === null) {
|
167727
168565
|
const error = new CompilerError();
|
167728
168566
|
error.pushErrorDetail(
|
@@ -167737,12 +168575,13 @@ function compileProgram(program, pass) {
|
|
167737
168575
|
handleError(error, pass, null);
|
167738
168576
|
return;
|
167739
168577
|
}
|
167740
|
-
if (!isFilePartOfSources(
|
168578
|
+
if (!isFilePartOfSources(pass.opts.sources, pass.filename)) {
|
167741
168579
|
return;
|
167742
168580
|
}
|
167743
168581
|
}
|
167744
168582
|
if (
|
167745
|
-
findDirectiveDisablingMemoization(program.node.directives,
|
168583
|
+
findDirectiveDisablingMemoization(program.node.directives, pass.opts) !=
|
168584
|
+
null
|
167746
168585
|
) {
|
167747
168586
|
return;
|
167748
168587
|
}
|
@@ -167751,7 +168590,7 @@ function compileProgram(program, pass) {
|
|
167751
168590
|
);
|
167752
168591
|
const useMemoCacheIdentifier = program.scope.generateUidIdentifier("c");
|
167753
168592
|
const moduleName =
|
167754
|
-
(_b =
|
168593
|
+
(_b = pass.opts.runtimeModule) !== null && _b !== void 0
|
167755
168594
|
? _b
|
167756
168595
|
: "react/compiler-runtime";
|
167757
168596
|
if (hasMemoCacheFunctionImport(program, moduleName)) {
|
@@ -167759,10 +168598,10 @@ function compileProgram(program, pass) {
|
|
167759
168598
|
}
|
167760
168599
|
const suppressions = findProgramSuppressions(
|
167761
168600
|
pass.comments,
|
167762
|
-
(_c =
|
168601
|
+
(_c = pass.opts.eslintSuppressionRules) !== null && _c !== void 0
|
167763
168602
|
? _c
|
167764
168603
|
: DEFAULT_ESLINT_SUPPRESSIONS,
|
167765
|
-
|
168604
|
+
pass.opts.flowSuppressions
|
167766
168605
|
);
|
167767
168606
|
const lintError = suppressionsToCompilerError(suppressions);
|
167768
168607
|
let hasCriticalError = lintError != null;
|
@@ -167805,11 +168644,11 @@ function compileProgram(program, pass) {
|
|
167805
168644
|
config,
|
167806
168645
|
fnType,
|
167807
168646
|
useMemoCacheIdentifier.name,
|
167808
|
-
|
168647
|
+
pass.opts.logger,
|
167809
168648
|
pass.filename,
|
167810
168649
|
pass.code
|
167811
168650
|
);
|
167812
|
-
(_b =
|
168651
|
+
(_b = pass.opts.logger) === null || _b === void 0
|
167813
168652
|
? void 0
|
167814
168653
|
: _b.logEvent(pass.filename, {
|
167815
168654
|
kind: "CompileSuccess",
|
@@ -167823,6 +168662,9 @@ function compileProgram(program, pass) {
|
|
167823
168662
|
: null,
|
167824
168663
|
memoSlots: compiledFn.memoSlotsUsed,
|
167825
168664
|
memoBlocks: compiledFn.memoBlocks,
|
168665
|
+
memoValues: compiledFn.memoValues,
|
168666
|
+
prunedMemoBlocks: compiledFn.prunedMemoBlocks,
|
168667
|
+
prunedMemoValues: compiledFn.prunedMemoValues,
|
167826
168668
|
});
|
167827
168669
|
} catch (err) {
|
167828
168670
|
hasCriticalError || (hasCriticalError = isCriticalError(err));
|
@@ -167852,11 +168694,11 @@ function compileProgram(program, pass) {
|
|
167852
168694
|
ArrowFunctionExpression: traverseFunction,
|
167853
168695
|
},
|
167854
168696
|
Object.assign(Object.assign({}, pass), {
|
167855
|
-
opts: Object.assign(Object.assign({}, pass.opts),
|
168697
|
+
opts: Object.assign(Object.assign({}, pass.opts), pass.opts),
|
167856
168698
|
filename: (_d = pass.filename) !== null && _d !== void 0 ? _d : null,
|
167857
168699
|
})
|
167858
168700
|
);
|
167859
|
-
if (
|
168701
|
+
if (pass.opts.gating != null) {
|
167860
168702
|
const error = checkFunctionReferencedBeforeDeclarationAtTopLevel(
|
167861
168703
|
program,
|
167862
168704
|
compiledFns.map(({ originalFn: originalFn }) => originalFn)
|
@@ -167869,12 +168711,12 @@ function compileProgram(program, pass) {
|
|
167869
168711
|
const externalFunctions = [];
|
167870
168712
|
let gating = null;
|
167871
168713
|
try {
|
167872
|
-
if (
|
167873
|
-
gating = tryParseExternalFunction(
|
168714
|
+
if (pass.opts.gating != null) {
|
168715
|
+
gating = tryParseExternalFunction(pass.opts.gating);
|
167874
168716
|
externalFunctions.push(gating);
|
167875
168717
|
}
|
167876
168718
|
const enableEmitInstrumentForget =
|
167877
|
-
(_e =
|
168719
|
+
(_e = pass.opts.environment) === null || _e === void 0
|
167878
168720
|
? void 0
|
167879
168721
|
: _e.enableEmitInstrumentForget;
|
167880
168722
|
if (enableEmitInstrumentForget != null) {
|
@@ -167888,32 +168730,32 @@ function compileProgram(program, pass) {
|
|
167888
168730
|
}
|
167889
168731
|
}
|
167890
168732
|
if (
|
167891
|
-
((_f =
|
168733
|
+
((_f = pass.opts.environment) === null || _f === void 0
|
167892
168734
|
? void 0
|
167893
168735
|
: _f.enableEmitFreeze) != null
|
167894
168736
|
) {
|
167895
168737
|
const enableEmitFreeze = tryParseExternalFunction(
|
167896
|
-
|
168738
|
+
pass.opts.environment.enableEmitFreeze
|
167897
168739
|
);
|
167898
168740
|
externalFunctions.push(enableEmitFreeze);
|
167899
168741
|
}
|
167900
168742
|
if (
|
167901
|
-
((_g =
|
168743
|
+
((_g = pass.opts.environment) === null || _g === void 0
|
167902
168744
|
? void 0
|
167903
168745
|
: _g.enableEmitHookGuards) != null
|
167904
168746
|
) {
|
167905
168747
|
const enableEmitHookGuards = tryParseExternalFunction(
|
167906
|
-
|
168748
|
+
pass.opts.environment.enableEmitHookGuards
|
167907
168749
|
);
|
167908
168750
|
externalFunctions.push(enableEmitHookGuards);
|
167909
168751
|
}
|
167910
168752
|
if (
|
167911
|
-
((_h =
|
168753
|
+
((_h = pass.opts.environment) === null || _h === void 0
|
167912
168754
|
? void 0
|
167913
168755
|
: _h.enableChangeDetectionForDebugging) != null
|
167914
168756
|
) {
|
167915
168757
|
const enableChangeDetectionForDebugging = tryParseExternalFunction(
|
167916
|
-
|
168758
|
+
pass.opts.environment.enableChangeDetectionForDebugging
|
167917
168759
|
);
|
167918
168760
|
externalFunctions.push(enableChangeDetectionForDebugging);
|
167919
168761
|
}
|
@@ -167987,19 +168829,25 @@ function getReactFunctionType(fn, pass) {
|
|
167987
168829
|
: "Other";
|
167988
168830
|
}
|
167989
168831
|
}
|
168832
|
+
let componentSyntaxType = null;
|
168833
|
+
if (fn.isFunctionDeclaration()) {
|
168834
|
+
if (isComponentDeclaration(fn.node)) {
|
168835
|
+
componentSyntaxType = "Component";
|
168836
|
+
} else if (isHookDeclaration(fn.node)) {
|
168837
|
+
componentSyntaxType = "Hook";
|
168838
|
+
}
|
168839
|
+
}
|
167990
168840
|
switch (pass.opts.compilationMode) {
|
167991
168841
|
case "annotation": {
|
167992
168842
|
return null;
|
167993
168843
|
}
|
167994
168844
|
case "infer": {
|
167995
|
-
|
167996
|
-
|
167997
|
-
|
167998
|
-
|
167999
|
-
|
168000
|
-
|
168001
|
-
}
|
168002
|
-
return getComponentOrHookLike(fn, hookPattern);
|
168845
|
+
return componentSyntaxType !== null && componentSyntaxType !== void 0
|
168846
|
+
? componentSyntaxType
|
168847
|
+
: getComponentOrHookLike(fn, hookPattern);
|
168848
|
+
}
|
168849
|
+
case "syntax": {
|
168850
|
+
return componentSyntaxType;
|
168003
168851
|
}
|
168004
168852
|
case "all": {
|
168005
168853
|
if (fn.scope.getProgramParent() !== fn.scope.parent) {
|
@@ -168089,15 +168937,62 @@ function isMemoCallback(path) {
|
|
168089
168937
|
isReactAPI(path.parentPath.get("callee"), "memo")
|
168090
168938
|
);
|
168091
168939
|
}
|
168940
|
+
function isValidPropsAnnotation(annot) {
|
168941
|
+
if (annot == null) {
|
168942
|
+
return true;
|
168943
|
+
} else if (annot.type === "TSTypeAnnotation") {
|
168944
|
+
switch (annot.typeAnnotation.type) {
|
168945
|
+
case "TSArrayType":
|
168946
|
+
case "TSBigIntKeyword":
|
168947
|
+
case "TSBooleanKeyword":
|
168948
|
+
case "TSConstructorType":
|
168949
|
+
case "TSFunctionType":
|
168950
|
+
case "TSLiteralType":
|
168951
|
+
case "TSNeverKeyword":
|
168952
|
+
case "TSNumberKeyword":
|
168953
|
+
case "TSStringKeyword":
|
168954
|
+
case "TSSymbolKeyword":
|
168955
|
+
case "TSTupleType":
|
168956
|
+
return false;
|
168957
|
+
}
|
168958
|
+
return true;
|
168959
|
+
} else if (annot.type === "TypeAnnotation") {
|
168960
|
+
switch (annot.typeAnnotation.type) {
|
168961
|
+
case "ArrayTypeAnnotation":
|
168962
|
+
case "BooleanLiteralTypeAnnotation":
|
168963
|
+
case "BooleanTypeAnnotation":
|
168964
|
+
case "EmptyTypeAnnotation":
|
168965
|
+
case "FunctionTypeAnnotation":
|
168966
|
+
case "NumberLiteralTypeAnnotation":
|
168967
|
+
case "NumberTypeAnnotation":
|
168968
|
+
case "StringLiteralTypeAnnotation":
|
168969
|
+
case "StringTypeAnnotation":
|
168970
|
+
case "SymbolTypeAnnotation":
|
168971
|
+
case "ThisTypeAnnotation":
|
168972
|
+
case "TupleTypeAnnotation":
|
168973
|
+
return false;
|
168974
|
+
}
|
168975
|
+
return true;
|
168976
|
+
} else if (annot.type === "Noop") {
|
168977
|
+
return true;
|
168978
|
+
} else {
|
168979
|
+
assertExhaustive(annot, `Unexpected annotation node \`${annot}\``);
|
168980
|
+
}
|
168981
|
+
}
|
168092
168982
|
function isValidComponentParams(params) {
|
168093
168983
|
if (params.length === 0) {
|
168094
168984
|
return true;
|
168095
|
-
} else if (params.length
|
168096
|
-
|
168097
|
-
|
168098
|
-
|
168985
|
+
} else if (params.length > 0 && params.length <= 2) {
|
168986
|
+
if (!isValidPropsAnnotation(params[0].node.typeAnnotation)) {
|
168987
|
+
return false;
|
168988
|
+
}
|
168989
|
+
if (params.length === 1) {
|
168990
|
+
return !params[0].isRestElement();
|
168991
|
+
} else if (params[1].isIdentifier()) {
|
168099
168992
|
const { name: name } = params[1].node;
|
168100
168993
|
return name.includes("ref") || name.includes("Ref");
|
168994
|
+
} else {
|
168995
|
+
return false;
|
168101
168996
|
}
|
168102
168997
|
}
|
168103
168998
|
return false;
|
@@ -168107,7 +169002,8 @@ function getComponentOrHookLike(node, hookPattern) {
|
|
168107
169002
|
if (functionName !== null && isComponentName(functionName)) {
|
168108
169003
|
let isComponent =
|
168109
169004
|
callsHooksOrCreatesJsx(node, hookPattern) &&
|
168110
|
-
isValidComponentParams(node.get("params"))
|
169005
|
+
isValidComponentParams(node.get("params")) &&
|
169006
|
+
!returnsNonNode(node);
|
168111
169007
|
return isComponent ? "Component" : null;
|
168112
169008
|
} else if (functionName !== null && isHook(functionName, hookPattern)) {
|
168113
169009
|
return callsHooksOrCreatesJsx(node, hookPattern) ? "Hook" : null;
|
@@ -168119,6 +169015,13 @@ function getComponentOrHookLike(node, hookPattern) {
|
|
168119
169015
|
}
|
168120
169016
|
return null;
|
168121
169017
|
}
|
169018
|
+
function skipNestedFunctions(node) {
|
169019
|
+
return (fn) => {
|
169020
|
+
if (fn.node !== node.node) {
|
169021
|
+
fn.skip();
|
169022
|
+
}
|
169023
|
+
};
|
169024
|
+
}
|
168122
169025
|
function callsHooksOrCreatesJsx(node, hookPattern) {
|
168123
169026
|
let invokesHooks = false;
|
168124
169027
|
let createsJsx = false;
|
@@ -168132,9 +169035,39 @@ function callsHooksOrCreatesJsx(node, hookPattern) {
|
|
168132
169035
|
invokesHooks = true;
|
168133
169036
|
}
|
168134
169037
|
},
|
169038
|
+
ArrowFunctionExpression: skipNestedFunctions(node),
|
169039
|
+
FunctionExpression: skipNestedFunctions(node),
|
169040
|
+
FunctionDeclaration: skipNestedFunctions(node),
|
168135
169041
|
});
|
168136
169042
|
return invokesHooks || createsJsx;
|
168137
169043
|
}
|
169044
|
+
function returnsNonNode(node) {
|
169045
|
+
let hasReturn = false;
|
169046
|
+
let returnsNonNode = false;
|
169047
|
+
node.traverse({
|
169048
|
+
ReturnStatement(ret) {
|
169049
|
+
hasReturn = true;
|
169050
|
+
const argument = ret.node.argument;
|
169051
|
+
if (argument == null) {
|
169052
|
+
returnsNonNode = true;
|
169053
|
+
} else {
|
169054
|
+
switch (argument.type) {
|
169055
|
+
case "ObjectExpression":
|
169056
|
+
case "ArrowFunctionExpression":
|
169057
|
+
case "FunctionExpression":
|
169058
|
+
case "BigIntLiteral":
|
169059
|
+
case "ClassExpression":
|
169060
|
+
case "NewExpression":
|
169061
|
+
returnsNonNode = true;
|
169062
|
+
}
|
169063
|
+
}
|
169064
|
+
},
|
169065
|
+
ArrowFunctionExpression: skipNestedFunctions(node),
|
169066
|
+
FunctionExpression: skipNestedFunctions(node),
|
169067
|
+
FunctionDeclaration: skipNestedFunctions(node),
|
169068
|
+
});
|
169069
|
+
return !hasReturn || returnsNonNode;
|
169070
|
+
}
|
168138
169071
|
function getFunctionName(path) {
|
168139
169072
|
if (path.isFunctionDeclaration()) {
|
168140
169073
|
const id = path.get("id");
|
@@ -168265,10 +169198,16 @@ function BabelPluginReactCompiler(_babel) {
|
|
168265
169198
|
Program(prog, pass) {
|
168266
169199
|
var _a, _b;
|
168267
169200
|
let opts = parsePluginOptions(pass.opts);
|
168268
|
-
|
169201
|
+
const isDev =
|
169202
|
+
(typeof __DEV__ !== "undefined" && __DEV__ === true) ||
|
169203
|
+
process.env["NODE_ENV"] === "development";
|
169204
|
+
if (
|
169205
|
+
opts.enableReanimatedCheck === true &&
|
169206
|
+
pipelineUsesReanimatedPlugin(pass.file.opts.plugins)
|
169207
|
+
) {
|
168269
169208
|
opts = injectReanimatedFlag(opts);
|
168270
169209
|
}
|
168271
|
-
if (
|
169210
|
+
if (isDev) {
|
168272
169211
|
opts = Object.assign(Object.assign({}, opts), {
|
168273
169212
|
environment: Object.assign(Object.assign({}, opts.environment), {
|
168274
169213
|
enableResetCacheOnSourceFileChanges: true,
|