babel-plugin-react-compiler 0.0.0-experimental-22c6e49-20241220 → 0.0.0-experimental-b2e8e9c-20241220
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 +678 -32
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -127070,6 +127070,13 @@ function printSourceLocation(loc) {
|
|
127070
127070
|
return `${loc.start.line}:${loc.start.column}:${loc.end.line}:${loc.end.column}`;
|
127071
127071
|
}
|
127072
127072
|
}
|
127073
|
+
function printSourceLocationLine(loc) {
|
127074
|
+
if (typeof loc === 'symbol') {
|
127075
|
+
return 'generated';
|
127076
|
+
} else {
|
127077
|
+
return `${loc.start.line}:${loc.end.line}`;
|
127078
|
+
}
|
127079
|
+
}
|
127073
127080
|
function getFunctionName$1(instrValue, defaultValue) {
|
127074
127081
|
var _a;
|
127075
127082
|
switch (instrValue.kind) {
|
@@ -136948,6 +136955,7 @@ class Environment {
|
|
136948
136955
|
'f'
|
136949
136956
|
);
|
136950
136957
|
this.hasLoweredContextAccess = false;
|
136958
|
+
this.hasFireRewrite = false;
|
136951
136959
|
if (
|
136952
136960
|
config.disableMemoizationForDebugging &&
|
136953
136961
|
config.enableChangeDetectionForDebugging != null
|
@@ -141031,7 +141039,7 @@ var _Context_nextScheduleId,
|
|
141031
141039
|
_Context_catchHandlers,
|
141032
141040
|
_Context_controlFlowStack;
|
141033
141041
|
function buildReactiveFunction(fn) {
|
141034
|
-
const cx = new Context$
|
141042
|
+
const cx = new Context$3(fn.body);
|
141035
141043
|
const driver = new Driver(cx);
|
141036
141044
|
const body = driver.traverseBlock(cx.block(fn.body.entry));
|
141037
141045
|
return {
|
@@ -142079,7 +142087,7 @@ class Driver {
|
|
142079
142087
|
};
|
142080
142088
|
}
|
142081
142089
|
}
|
142082
|
-
let Context$
|
142090
|
+
let Context$3 = class Context {
|
142083
142091
|
constructor(ir) {
|
142084
142092
|
_Context_nextScheduleId.set(this, 0);
|
142085
142093
|
this.emitted = new Set();
|
@@ -142467,7 +142475,7 @@ function codegenFunction(
|
|
142467
142475
|
{uniqueIdentifiers: uniqueIdentifiers, fbtOperands: fbtOperands}
|
142468
142476
|
) {
|
142469
142477
|
var _a, _b, _c;
|
142470
|
-
const cx = new Context$
|
142478
|
+
const cx = new Context$2(
|
142471
142479
|
fn.env,
|
142472
142480
|
(_a = fn.id) !== null && _a !== void 0 ? _a : '[[ anonymous ]]',
|
142473
142481
|
uniqueIdentifiers,
|
@@ -142632,7 +142640,7 @@ function codegenFunction(
|
|
142632
142640
|
pruneHoistedContexts(reactiveFunction);
|
142633
142641
|
const identifiers = renameVariables(reactiveFunction);
|
142634
142642
|
const codegen = codegenReactiveFunction(
|
142635
|
-
new Context$
|
142643
|
+
new Context$2(
|
142636
142644
|
cx.env,
|
142637
142645
|
(_c = reactiveFunction.id) !== null && _c !== void 0
|
142638
142646
|
? _c
|
@@ -142690,6 +142698,7 @@ function codegenReactiveFunction(cx, fn) {
|
|
142690
142698
|
prunedMemoValues: countMemoBlockVisitor.prunedMemoValues,
|
142691
142699
|
outlined: [],
|
142692
142700
|
hasLoweredContextAccess: fn.env.hasLoweredContextAccess,
|
142701
|
+
hasFireRewrite: fn.env.hasFireRewrite,
|
142693
142702
|
});
|
142694
142703
|
}
|
142695
142704
|
class CountMemoBlockVisitor extends ReactiveFunctionVisitor {
|
@@ -142719,7 +142728,7 @@ function convertParameter(param) {
|
|
142719
142728
|
return t__namespace.restElement(convertIdentifier(param.place.identifier));
|
142720
142729
|
}
|
142721
142730
|
}
|
142722
|
-
let Context$
|
142731
|
+
let Context$2 = class Context {
|
142723
142732
|
constructor(env, fnName, uniqueIdentifiers, fbtOperands, temporaries = null) {
|
142724
142733
|
_Context_nextCacheIndex.set(this, 0);
|
142725
142734
|
_Context_declarations$1.set(this, new Set());
|
@@ -144054,7 +144063,7 @@ function codegenInstructionValue(cx, instrValue) {
|
|
144054
144063
|
pruneUnusedLabels(reactiveFunction);
|
144055
144064
|
pruneUnusedLValues(reactiveFunction);
|
144056
144065
|
const fn = codegenReactiveFunction(
|
144057
|
-
new Context$
|
144066
|
+
new Context$2(
|
144058
144067
|
cx.env,
|
144059
144068
|
(_e = reactiveFunction.id) !== null && _e !== void 0
|
144060
144069
|
? _e
|
@@ -144253,7 +144262,7 @@ function codegenInstructionValue(cx, instrValue) {
|
|
144253
144262
|
pruneUnusedLValues(reactiveFunction);
|
144254
144263
|
pruneHoistedContexts(reactiveFunction);
|
144255
144264
|
const fn = codegenReactiveFunction(
|
144256
|
-
new Context$
|
144265
|
+
new Context$2(
|
144257
144266
|
cx.env,
|
144258
144267
|
(_g = reactiveFunction.id) !== null && _g !== void 0
|
144259
144268
|
? _g
|
@@ -152307,7 +152316,7 @@ function joinRefAccessTypes(...types) {
|
|
152307
152316
|
);
|
152308
152317
|
}
|
152309
152318
|
function validateNoRefAccessInRenderImpl(fn, env) {
|
152310
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
152319
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
152311
152320
|
let returnValues = [];
|
152312
152321
|
let place;
|
152313
152322
|
for (const param of fn.params) {
|
@@ -152380,31 +152389,41 @@ function validateNoRefAccessInRenderImpl(fn, env) {
|
|
152380
152389
|
);
|
152381
152390
|
break;
|
152382
152391
|
}
|
152383
|
-
case '
|
152384
|
-
case 'LoadLocal': {
|
152392
|
+
case 'TypeCastExpression': {
|
152385
152393
|
env.set(
|
152386
152394
|
instr.lvalue.identifier.id,
|
152387
|
-
(_a = env.get(instr.value.
|
152395
|
+
(_a = env.get(instr.value.value.identifier.id)) !== null &&
|
152388
152396
|
_a !== void 0
|
152389
152397
|
? _a
|
152390
152398
|
: refTypeOfType(instr.lvalue)
|
152391
152399
|
);
|
152392
152400
|
break;
|
152393
152401
|
}
|
152394
|
-
case '
|
152395
|
-
case '
|
152402
|
+
case 'LoadContext':
|
152403
|
+
case 'LoadLocal': {
|
152396
152404
|
env.set(
|
152397
|
-
instr.
|
152398
|
-
(_b = env.get(instr.value.
|
152405
|
+
instr.lvalue.identifier.id,
|
152406
|
+
(_b = env.get(instr.value.place.identifier.id)) !== null &&
|
152399
152407
|
_b !== void 0
|
152400
152408
|
? _b
|
152401
|
-
: refTypeOfType(instr.
|
152409
|
+
: refTypeOfType(instr.lvalue)
|
152402
152410
|
);
|
152411
|
+
break;
|
152412
|
+
}
|
152413
|
+
case 'StoreContext':
|
152414
|
+
case 'StoreLocal': {
|
152403
152415
|
env.set(
|
152404
|
-
instr.lvalue.identifier.id,
|
152416
|
+
instr.value.lvalue.place.identifier.id,
|
152405
152417
|
(_c = env.get(instr.value.value.identifier.id)) !== null &&
|
152406
152418
|
_c !== void 0
|
152407
152419
|
? _c
|
152420
|
+
: refTypeOfType(instr.value.lvalue.place)
|
152421
|
+
);
|
152422
|
+
env.set(
|
152423
|
+
instr.lvalue.identifier.id,
|
152424
|
+
(_d = env.get(instr.value.value.identifier.id)) !== null &&
|
152425
|
+
_d !== void 0
|
152426
|
+
? _d
|
152408
152427
|
: refTypeOfType(instr.lvalue)
|
152409
152428
|
);
|
152410
152429
|
break;
|
@@ -152501,8 +152520,8 @@ function validateNoRefAccessInRenderImpl(fn, env) {
|
|
152501
152520
|
for (const operand of eachInstructionValueOperand(instr.value)) {
|
152502
152521
|
validateNoDirectRefValueAccess(errors, operand, env);
|
152503
152522
|
types.push(
|
152504
|
-
(
|
152505
|
-
?
|
152523
|
+
(_e = env.get(operand.identifier.id)) !== null && _e !== void 0
|
152524
|
+
? _e
|
152506
152525
|
: {kind: 'None'}
|
152507
152526
|
);
|
152508
152527
|
}
|
@@ -152609,16 +152628,16 @@ function validateNoRefAccessInRenderImpl(fn, env) {
|
|
152609
152628
|
}
|
152610
152629
|
if (
|
152611
152630
|
isUseRefType(instr.lvalue.identifier) &&
|
152612
|
-
((
|
152631
|
+
((_f = env.get(instr.lvalue.identifier.id)) === null || _f === void 0
|
152613
152632
|
? void 0
|
152614
|
-
:
|
152633
|
+
: _f.kind) !== 'Ref'
|
152615
152634
|
) {
|
152616
152635
|
env.set(
|
152617
152636
|
instr.lvalue.identifier.id,
|
152618
152637
|
joinRefAccessTypes(
|
152619
|
-
(
|
152620
|
-
|
152621
|
-
?
|
152638
|
+
(_g = env.get(instr.lvalue.identifier.id)) !== null &&
|
152639
|
+
_g !== void 0
|
152640
|
+
? _g
|
152622
152641
|
: {kind: 'None'},
|
152623
152642
|
{kind: 'Ref', refId: nextRefId()}
|
152624
152643
|
)
|
@@ -152626,16 +152645,16 @@ function validateNoRefAccessInRenderImpl(fn, env) {
|
|
152626
152645
|
}
|
152627
152646
|
if (
|
152628
152647
|
isRefValueType(instr.lvalue.identifier) &&
|
152629
|
-
((
|
152648
|
+
((_h = env.get(instr.lvalue.identifier.id)) === null || _h === void 0
|
152630
152649
|
? void 0
|
152631
|
-
:
|
152650
|
+
: _h.kind) !== 'RefValue'
|
152632
152651
|
) {
|
152633
152652
|
env.set(
|
152634
152653
|
instr.lvalue.identifier.id,
|
152635
152654
|
joinRefAccessTypes(
|
152636
|
-
(
|
152637
|
-
|
152638
|
-
?
|
152655
|
+
(_j = env.get(instr.lvalue.identifier.id)) !== null &&
|
152656
|
+
_j !== void 0
|
152657
|
+
? _j
|
152639
152658
|
: {kind: 'None'},
|
152640
152659
|
{kind: 'RefValue', loc: instr.loc}
|
152641
152660
|
)
|
@@ -155008,7 +155027,7 @@ function getProperty(object, propertyName, optional, temporaries) {
|
|
155008
155027
|
}
|
155009
155028
|
return property;
|
155010
155029
|
}
|
155011
|
-
class Context {
|
155030
|
+
let Context$1 = class Context {
|
155012
155031
|
constructor(
|
155013
155032
|
temporariesUsedOutsideScope,
|
155014
155033
|
temporaries,
|
@@ -155248,7 +155267,7 @@ class Context {
|
|
155248
155267
|
))
|
155249
155268
|
);
|
155250
155269
|
}
|
155251
|
-
}
|
155270
|
+
};
|
155252
155271
|
(_Context_declarations = new WeakMap()),
|
155253
155272
|
(_Context_reassignments = new WeakMap()),
|
155254
155273
|
(_Context_scopes = new WeakMap()),
|
@@ -155341,7 +155360,7 @@ function collectDependencies(
|
|
155341
155360
|
temporaries,
|
155342
155361
|
processedInstrsInOptional
|
155343
155362
|
) {
|
155344
|
-
const context = new Context(
|
155363
|
+
const context = new Context$1(
|
155345
155364
|
usedOutsideDeclaringScope,
|
155346
155365
|
temporaries,
|
155347
155366
|
processedInstrsInOptional
|
@@ -155796,6 +155815,622 @@ function optimizePropsMethodCalls(fn) {
|
|
155796
155815
|
}
|
155797
155816
|
}
|
155798
155817
|
}
|
155818
|
+
var _Context_env,
|
155819
|
+
_Context_errors,
|
155820
|
+
_Context_callExpressions,
|
155821
|
+
_Context_functionExpressions,
|
155822
|
+
_Context_loadLocals,
|
155823
|
+
_Context_fireCalleesToFireFunctions,
|
155824
|
+
_Context_calleesWithInsertedFire,
|
155825
|
+
_Context_capturedCalleeIdentifierIds,
|
155826
|
+
_Context_inUseEffectLambda,
|
155827
|
+
_Context_loadGlobalInstructionIds,
|
155828
|
+
_Context_arrayExpressions;
|
155829
|
+
const CANNOT_COMPILE_FIRE = 'Cannot compile `fire`';
|
155830
|
+
function transformFire(fn) {
|
155831
|
+
const context = new Context(fn.env);
|
155832
|
+
replaceFireFunctions(fn, context);
|
155833
|
+
if (!context.hasErrors()) {
|
155834
|
+
ensureNoMoreFireUses(fn, context);
|
155835
|
+
}
|
155836
|
+
context.throwIfErrorsFound();
|
155837
|
+
}
|
155838
|
+
function replaceFireFunctions(fn, context) {
|
155839
|
+
let hasRewrite = false;
|
155840
|
+
for (const [, block] of fn.body.blocks) {
|
155841
|
+
const rewriteInstrs = new Map();
|
155842
|
+
const deleteInstrs = new Set();
|
155843
|
+
for (const instr of block.instructions) {
|
155844
|
+
const {value: value, lvalue: lvalue} = instr;
|
155845
|
+
if (
|
155846
|
+
value.kind === 'CallExpression' &&
|
155847
|
+
isUseEffectHookType(value.callee.identifier) &&
|
155848
|
+
value.args.length > 0 &&
|
155849
|
+
value.args[0].kind === 'Identifier'
|
155850
|
+
) {
|
155851
|
+
const lambda = context.getFunctionExpression(
|
155852
|
+
value.args[0].identifier.id
|
155853
|
+
);
|
155854
|
+
if (lambda != null) {
|
155855
|
+
const capturedCallees =
|
155856
|
+
visitFunctionExpressionAndPropagateFireDependencies(
|
155857
|
+
lambda,
|
155858
|
+
context,
|
155859
|
+
true
|
155860
|
+
);
|
155861
|
+
const newInstrs = [];
|
155862
|
+
for (const [
|
155863
|
+
fireCalleePlace,
|
155864
|
+
fireCalleeInfo,
|
155865
|
+
] of capturedCallees.entries()) {
|
155866
|
+
if (!context.hasCalleeWithInsertedFire(fireCalleePlace)) {
|
155867
|
+
context.addCalleeWithInsertedFire(fireCalleePlace);
|
155868
|
+
const loadUseFireInstr = makeLoadUseFireInstruction(fn.env);
|
155869
|
+
const loadFireCalleeInstr = makeLoadFireCalleeInstruction(
|
155870
|
+
fn.env,
|
155871
|
+
fireCalleeInfo.capturedCalleeIdentifier
|
155872
|
+
);
|
155873
|
+
const callUseFireInstr = makeCallUseFireInstruction(
|
155874
|
+
fn.env,
|
155875
|
+
loadUseFireInstr.lvalue,
|
155876
|
+
loadFireCalleeInstr.lvalue
|
155877
|
+
);
|
155878
|
+
const storeUseFireInstr = makeStoreUseFireInstruction(
|
155879
|
+
fn.env,
|
155880
|
+
callUseFireInstr.lvalue,
|
155881
|
+
fireCalleeInfo.fireFunctionBinding
|
155882
|
+
);
|
155883
|
+
newInstrs.push(
|
155884
|
+
loadUseFireInstr,
|
155885
|
+
loadFireCalleeInstr,
|
155886
|
+
callUseFireInstr,
|
155887
|
+
storeUseFireInstr
|
155888
|
+
);
|
155889
|
+
const loadUseEffectInstrId = context.getLoadGlobalInstrId(
|
155890
|
+
value.callee.identifier.id
|
155891
|
+
);
|
155892
|
+
if (loadUseEffectInstrId == null) {
|
155893
|
+
context.pushError({
|
155894
|
+
loc: value.loc,
|
155895
|
+
description: null,
|
155896
|
+
severity: exports.ErrorSeverity.Invariant,
|
155897
|
+
reason: '[InsertFire] No LoadGlobal found for useEffect call',
|
155898
|
+
suggestions: null,
|
155899
|
+
});
|
155900
|
+
continue;
|
155901
|
+
}
|
155902
|
+
rewriteInstrs.set(loadUseEffectInstrId, newInstrs);
|
155903
|
+
}
|
155904
|
+
}
|
155905
|
+
ensureNoRemainingCalleeCaptures(
|
155906
|
+
lambda.loweredFunc.func,
|
155907
|
+
context,
|
155908
|
+
capturedCallees
|
155909
|
+
);
|
155910
|
+
if (
|
155911
|
+
value.args.length > 1 &&
|
155912
|
+
value.args[1] != null &&
|
155913
|
+
value.args[1].kind === 'Identifier'
|
155914
|
+
) {
|
155915
|
+
const depArray = value.args[1];
|
155916
|
+
const depArrayExpression = context.getArrayExpression(
|
155917
|
+
depArray.identifier.id
|
155918
|
+
);
|
155919
|
+
if (depArrayExpression != null) {
|
155920
|
+
for (const dependency of depArrayExpression.elements) {
|
155921
|
+
if (dependency.kind === 'Identifier') {
|
155922
|
+
const loadOfDependency = context.getLoadLocalInstr(
|
155923
|
+
dependency.identifier.id
|
155924
|
+
);
|
155925
|
+
if (loadOfDependency != null) {
|
155926
|
+
const replacedDepArrayItem = capturedCallees.get(
|
155927
|
+
loadOfDependency.place.identifier.id
|
155928
|
+
);
|
155929
|
+
if (replacedDepArrayItem != null) {
|
155930
|
+
loadOfDependency.place =
|
155931
|
+
replacedDepArrayItem.fireFunctionBinding;
|
155932
|
+
}
|
155933
|
+
}
|
155934
|
+
}
|
155935
|
+
}
|
155936
|
+
} else {
|
155937
|
+
context.pushError({
|
155938
|
+
loc: value.args[1].loc,
|
155939
|
+
description:
|
155940
|
+
'You must use an array literal for an effect dependency array when that effect uses `fire()`',
|
155941
|
+
severity: exports.ErrorSeverity.Invariant,
|
155942
|
+
reason: CANNOT_COMPILE_FIRE,
|
155943
|
+
suggestions: null,
|
155944
|
+
});
|
155945
|
+
}
|
155946
|
+
} else if (value.args.length > 1 && value.args[1].kind === 'Spread') {
|
155947
|
+
context.pushError({
|
155948
|
+
loc: value.args[1].place.loc,
|
155949
|
+
description:
|
155950
|
+
'You must use an array literal for an effect dependency array when that effect uses `fire()`',
|
155951
|
+
severity: exports.ErrorSeverity.Invariant,
|
155952
|
+
reason: CANNOT_COMPILE_FIRE,
|
155953
|
+
suggestions: null,
|
155954
|
+
});
|
155955
|
+
}
|
155956
|
+
}
|
155957
|
+
} else if (
|
155958
|
+
value.kind === 'CallExpression' &&
|
155959
|
+
value.callee.identifier.type.kind === 'Function' &&
|
155960
|
+
value.callee.identifier.type.shapeId === BuiltInFireId &&
|
155961
|
+
context.inUseEffectLambda()
|
155962
|
+
) {
|
155963
|
+
if (value.args.length === 1 && value.args[0].kind === 'Identifier') {
|
155964
|
+
const callExpr = context.getCallExpression(
|
155965
|
+
value.args[0].identifier.id
|
155966
|
+
);
|
155967
|
+
if (callExpr != null) {
|
155968
|
+
const calleeId = callExpr.callee.identifier.id;
|
155969
|
+
const loadLocal = context.getLoadLocalInstr(calleeId);
|
155970
|
+
if (loadLocal == null) {
|
155971
|
+
context.pushError({
|
155972
|
+
loc: value.loc,
|
155973
|
+
description: null,
|
155974
|
+
severity: exports.ErrorSeverity.Invariant,
|
155975
|
+
reason:
|
155976
|
+
'[InsertFire] No loadLocal found for fire call argument',
|
155977
|
+
suggestions: null,
|
155978
|
+
});
|
155979
|
+
continue;
|
155980
|
+
}
|
155981
|
+
const fireFunctionBinding =
|
155982
|
+
context.getOrGenerateFireFunctionBinding(
|
155983
|
+
loadLocal.place,
|
155984
|
+
value.loc
|
155985
|
+
);
|
155986
|
+
loadLocal.place = Object.assign({}, fireFunctionBinding);
|
155987
|
+
deleteInstrs.add(instr.id);
|
155988
|
+
} else {
|
155989
|
+
context.pushError({
|
155990
|
+
loc: value.loc,
|
155991
|
+
description:
|
155992
|
+
'`fire()` can only receive a function call such as `fire(fn(a,b)). Method calls and other expressions are not allowed',
|
155993
|
+
severity: exports.ErrorSeverity.InvalidReact,
|
155994
|
+
reason: CANNOT_COMPILE_FIRE,
|
155995
|
+
suggestions: null,
|
155996
|
+
});
|
155997
|
+
}
|
155998
|
+
} else {
|
155999
|
+
let description =
|
156000
|
+
'fire() can only take in a single call expression as an argument';
|
156001
|
+
if (value.args.length === 0) {
|
156002
|
+
description += ' but received none';
|
156003
|
+
} else if (value.args.length > 1) {
|
156004
|
+
description += ' but received multiple arguments';
|
156005
|
+
} else if (value.args[0].kind === 'Spread') {
|
156006
|
+
description += ' but received a spread argument';
|
156007
|
+
}
|
156008
|
+
context.pushError({
|
156009
|
+
loc: value.loc,
|
156010
|
+
description: description,
|
156011
|
+
severity: exports.ErrorSeverity.InvalidReact,
|
156012
|
+
reason: CANNOT_COMPILE_FIRE,
|
156013
|
+
suggestions: null,
|
156014
|
+
});
|
156015
|
+
}
|
156016
|
+
} else if (value.kind === 'CallExpression') {
|
156017
|
+
context.addCallExpression(lvalue.identifier.id, value);
|
156018
|
+
} else if (
|
156019
|
+
value.kind === 'FunctionExpression' &&
|
156020
|
+
context.inUseEffectLambda()
|
156021
|
+
) {
|
156022
|
+
visitFunctionExpressionAndPropagateFireDependencies(
|
156023
|
+
value,
|
156024
|
+
context,
|
156025
|
+
false
|
156026
|
+
);
|
156027
|
+
} else if (value.kind === 'FunctionExpression') {
|
156028
|
+
context.addFunctionExpression(lvalue.identifier.id, value);
|
156029
|
+
} else if (value.kind === 'LoadLocal') {
|
156030
|
+
context.addLoadLocalInstr(lvalue.identifier.id, value);
|
156031
|
+
} else if (
|
156032
|
+
value.kind === 'LoadGlobal' &&
|
156033
|
+
value.binding.kind === 'ImportSpecifier' &&
|
156034
|
+
value.binding.module === 'react' &&
|
156035
|
+
value.binding.imported === 'fire' &&
|
156036
|
+
context.inUseEffectLambda()
|
156037
|
+
) {
|
156038
|
+
deleteInstrs.add(instr.id);
|
156039
|
+
} else if (value.kind === 'LoadGlobal') {
|
156040
|
+
context.addLoadGlobalInstrId(lvalue.identifier.id, instr.id);
|
156041
|
+
} else if (value.kind === 'ArrayExpression') {
|
156042
|
+
context.addArrayExpression(lvalue.identifier.id, value);
|
156043
|
+
}
|
156044
|
+
}
|
156045
|
+
block.instructions = rewriteInstructions(rewriteInstrs, block.instructions);
|
156046
|
+
block.instructions = deleteInstructions(deleteInstrs, block.instructions);
|
156047
|
+
if (rewriteInstrs.size > 0 || deleteInstrs.size > 0) {
|
156048
|
+
hasRewrite = true;
|
156049
|
+
fn.env.hasFireRewrite = true;
|
156050
|
+
}
|
156051
|
+
}
|
156052
|
+
if (hasRewrite) {
|
156053
|
+
markInstructionIds(fn.body);
|
156054
|
+
}
|
156055
|
+
}
|
156056
|
+
function visitFunctionExpressionAndPropagateFireDependencies(
|
156057
|
+
fnExpr,
|
156058
|
+
context,
|
156059
|
+
enteringUseEffect
|
156060
|
+
) {
|
156061
|
+
let withScope = enteringUseEffect
|
156062
|
+
? context.withUseEffectLambdaScope.bind(context)
|
156063
|
+
: context.withFunctionScope.bind(context);
|
156064
|
+
const calleesCapturedByFnExpression = withScope(() =>
|
156065
|
+
replaceFireFunctions(fnExpr.loweredFunc.func, context)
|
156066
|
+
);
|
156067
|
+
const loadLocalsToDepLoads = new Map();
|
156068
|
+
for (const dep of fnExpr.loweredFunc.dependencies) {
|
156069
|
+
const loadLocal = context.getLoadLocalInstr(dep.identifier.id);
|
156070
|
+
if (loadLocal != null) {
|
156071
|
+
loadLocalsToDepLoads.set(loadLocal.place.identifier.id, loadLocal);
|
156072
|
+
}
|
156073
|
+
}
|
156074
|
+
const replacedCallees = new Map();
|
156075
|
+
for (const [
|
156076
|
+
calleeIdentifierId,
|
156077
|
+
loadedFireFunctionBindingPlace,
|
156078
|
+
] of calleesCapturedByFnExpression.entries()) {
|
156079
|
+
const loadLocal = loadLocalsToDepLoads.get(calleeIdentifierId);
|
156080
|
+
if (loadLocal == null) {
|
156081
|
+
context.pushError({
|
156082
|
+
loc: fnExpr.loc,
|
156083
|
+
description: null,
|
156084
|
+
severity: exports.ErrorSeverity.Invariant,
|
156085
|
+
reason:
|
156086
|
+
'[InsertFire] No loadLocal found for fire call argument for lambda',
|
156087
|
+
suggestions: null,
|
156088
|
+
});
|
156089
|
+
continue;
|
156090
|
+
}
|
156091
|
+
const oldPlaceId = loadLocal.place.identifier.id;
|
156092
|
+
loadLocal.place = Object.assign(
|
156093
|
+
{},
|
156094
|
+
loadedFireFunctionBindingPlace.fireFunctionBinding
|
156095
|
+
);
|
156096
|
+
replacedCallees.set(
|
156097
|
+
oldPlaceId,
|
156098
|
+
loadedFireFunctionBindingPlace.fireFunctionBinding
|
156099
|
+
);
|
156100
|
+
}
|
156101
|
+
for (
|
156102
|
+
let contextIdx = 0;
|
156103
|
+
contextIdx < fnExpr.loweredFunc.func.context.length;
|
156104
|
+
contextIdx++
|
156105
|
+
) {
|
156106
|
+
const contextItem = fnExpr.loweredFunc.func.context[contextIdx];
|
156107
|
+
const replacedCallee = replacedCallees.get(contextItem.identifier.id);
|
156108
|
+
if (replacedCallee != null) {
|
156109
|
+
fnExpr.loweredFunc.func.context[contextIdx] = replacedCallee;
|
156110
|
+
}
|
156111
|
+
}
|
156112
|
+
context.mergeCalleesFromInnerScope(calleesCapturedByFnExpression);
|
156113
|
+
return calleesCapturedByFnExpression;
|
156114
|
+
}
|
156115
|
+
function* eachReachablePlace(fn) {
|
156116
|
+
for (const [, block] of fn.body.blocks) {
|
156117
|
+
for (const instr of block.instructions) {
|
156118
|
+
if (
|
156119
|
+
instr.value.kind === 'FunctionExpression' ||
|
156120
|
+
instr.value.kind === 'ObjectMethod'
|
156121
|
+
) {
|
156122
|
+
yield* eachReachablePlace(instr.value.loweredFunc.func);
|
156123
|
+
} else {
|
156124
|
+
yield* eachInstructionOperand(instr);
|
156125
|
+
}
|
156126
|
+
}
|
156127
|
+
}
|
156128
|
+
}
|
156129
|
+
function ensureNoRemainingCalleeCaptures(fn, context, capturedCallees) {
|
156130
|
+
var _a;
|
156131
|
+
for (const place of eachReachablePlace(fn)) {
|
156132
|
+
const calleeInfo = capturedCallees.get(place.identifier.id);
|
156133
|
+
if (calleeInfo != null) {
|
156134
|
+
const calleeName =
|
156135
|
+
((_a = calleeInfo.capturedCalleeIdentifier.name) === null ||
|
156136
|
+
_a === void 0
|
156137
|
+
? void 0
|
156138
|
+
: _a.kind) === 'named'
|
156139
|
+
? calleeInfo.capturedCalleeIdentifier.name.value
|
156140
|
+
: '<unknown>';
|
156141
|
+
context.pushError({
|
156142
|
+
loc: place.loc,
|
156143
|
+
description: `All uses of ${calleeName} must be either used with a fire() call in this effect or not used with a fire() call at all. ${calleeName} was used with fire() on line ${printSourceLocationLine(calleeInfo.fireLoc)} in this effect`,
|
156144
|
+
severity: exports.ErrorSeverity.InvalidReact,
|
156145
|
+
reason: CANNOT_COMPILE_FIRE,
|
156146
|
+
suggestions: null,
|
156147
|
+
});
|
156148
|
+
}
|
156149
|
+
}
|
156150
|
+
}
|
156151
|
+
function ensureNoMoreFireUses(fn, context) {
|
156152
|
+
for (const place of eachReachablePlace(fn)) {
|
156153
|
+
if (
|
156154
|
+
place.identifier.type.kind === 'Function' &&
|
156155
|
+
place.identifier.type.shapeId === BuiltInFireId
|
156156
|
+
) {
|
156157
|
+
context.pushError({
|
156158
|
+
loc: place.identifier.loc,
|
156159
|
+
description: 'Cannot use `fire` outside of a useEffect function',
|
156160
|
+
severity: exports.ErrorSeverity.Invariant,
|
156161
|
+
reason: CANNOT_COMPILE_FIRE,
|
156162
|
+
suggestions: null,
|
156163
|
+
});
|
156164
|
+
}
|
156165
|
+
}
|
156166
|
+
}
|
156167
|
+
function makeLoadUseFireInstruction(env) {
|
156168
|
+
const useFirePlace = createTemporaryPlace(env, GeneratedSource);
|
156169
|
+
useFirePlace.effect = exports.Effect.Read;
|
156170
|
+
useFirePlace.identifier.type = DefaultNonmutatingHook;
|
156171
|
+
const instrValue = {
|
156172
|
+
kind: 'LoadGlobal',
|
156173
|
+
binding: {
|
156174
|
+
kind: 'ImportSpecifier',
|
156175
|
+
name: 'useFire',
|
156176
|
+
module: 'react',
|
156177
|
+
imported: 'useFire',
|
156178
|
+
},
|
156179
|
+
loc: GeneratedSource,
|
156180
|
+
};
|
156181
|
+
return {
|
156182
|
+
id: makeInstructionId(0),
|
156183
|
+
value: instrValue,
|
156184
|
+
lvalue: Object.assign({}, useFirePlace),
|
156185
|
+
loc: GeneratedSource,
|
156186
|
+
};
|
156187
|
+
}
|
156188
|
+
function makeLoadFireCalleeInstruction(env, fireCalleeIdentifier) {
|
156189
|
+
const loadedFireCallee = createTemporaryPlace(env, GeneratedSource);
|
156190
|
+
const fireCallee = {
|
156191
|
+
kind: 'Identifier',
|
156192
|
+
identifier: fireCalleeIdentifier,
|
156193
|
+
reactive: false,
|
156194
|
+
effect: exports.Effect.Unknown,
|
156195
|
+
loc: fireCalleeIdentifier.loc,
|
156196
|
+
};
|
156197
|
+
return {
|
156198
|
+
id: makeInstructionId(0),
|
156199
|
+
value: {
|
156200
|
+
kind: 'LoadLocal',
|
156201
|
+
loc: GeneratedSource,
|
156202
|
+
place: Object.assign({}, fireCallee),
|
156203
|
+
},
|
156204
|
+
lvalue: Object.assign({}, loadedFireCallee),
|
156205
|
+
loc: GeneratedSource,
|
156206
|
+
};
|
156207
|
+
}
|
156208
|
+
function makeCallUseFireInstruction(env, useFirePlace, argPlace) {
|
156209
|
+
const useFireCallResultPlace = createTemporaryPlace(env, GeneratedSource);
|
156210
|
+
useFireCallResultPlace.effect = exports.Effect.Read;
|
156211
|
+
const useFireCall = {
|
156212
|
+
kind: 'CallExpression',
|
156213
|
+
callee: Object.assign({}, useFirePlace),
|
156214
|
+
args: [argPlace],
|
156215
|
+
loc: GeneratedSource,
|
156216
|
+
};
|
156217
|
+
return {
|
156218
|
+
id: makeInstructionId(0),
|
156219
|
+
value: useFireCall,
|
156220
|
+
lvalue: Object.assign({}, useFireCallResultPlace),
|
156221
|
+
loc: GeneratedSource,
|
156222
|
+
};
|
156223
|
+
}
|
156224
|
+
function makeStoreUseFireInstruction(
|
156225
|
+
env,
|
156226
|
+
useFireCallResultPlace,
|
156227
|
+
fireFunctionBindingPlace
|
156228
|
+
) {
|
156229
|
+
promoteTemporary(fireFunctionBindingPlace.identifier);
|
156230
|
+
const fireFunctionBindingLValuePlace = createTemporaryPlace(
|
156231
|
+
env,
|
156232
|
+
GeneratedSource
|
156233
|
+
);
|
156234
|
+
return {
|
156235
|
+
id: makeInstructionId(0),
|
156236
|
+
value: {
|
156237
|
+
kind: 'StoreLocal',
|
156238
|
+
lvalue: {
|
156239
|
+
kind: InstructionKind.Const,
|
156240
|
+
place: Object.assign({}, fireFunctionBindingPlace),
|
156241
|
+
},
|
156242
|
+
value: Object.assign({}, useFireCallResultPlace),
|
156243
|
+
type: null,
|
156244
|
+
loc: GeneratedSource,
|
156245
|
+
},
|
156246
|
+
lvalue: fireFunctionBindingLValuePlace,
|
156247
|
+
loc: GeneratedSource,
|
156248
|
+
};
|
156249
|
+
}
|
156250
|
+
class Context {
|
156251
|
+
constructor(env) {
|
156252
|
+
_Context_env.set(this, void 0);
|
156253
|
+
_Context_errors.set(this, new CompilerError());
|
156254
|
+
_Context_callExpressions.set(this, new Map());
|
156255
|
+
_Context_functionExpressions.set(this, new Map());
|
156256
|
+
_Context_loadLocals.set(this, new Map());
|
156257
|
+
_Context_fireCalleesToFireFunctions.set(this, new Map());
|
156258
|
+
_Context_calleesWithInsertedFire.set(this, new Set());
|
156259
|
+
_Context_capturedCalleeIdentifierIds.set(this, new Map());
|
156260
|
+
_Context_inUseEffectLambda.set(this, false);
|
156261
|
+
_Context_loadGlobalInstructionIds.set(this, new Map());
|
156262
|
+
_Context_arrayExpressions.set(this, new Map());
|
156263
|
+
__classPrivateFieldSet(this, _Context_env, env, 'f');
|
156264
|
+
}
|
156265
|
+
pushError(error) {
|
156266
|
+
__classPrivateFieldGet(this, _Context_errors, 'f').push(error);
|
156267
|
+
}
|
156268
|
+
withFunctionScope(fn) {
|
156269
|
+
fn();
|
156270
|
+
return __classPrivateFieldGet(
|
156271
|
+
this,
|
156272
|
+
_Context_capturedCalleeIdentifierIds,
|
156273
|
+
'f'
|
156274
|
+
);
|
156275
|
+
}
|
156276
|
+
withUseEffectLambdaScope(fn) {
|
156277
|
+
const capturedCalleeIdentifierIds = __classPrivateFieldGet(
|
156278
|
+
this,
|
156279
|
+
_Context_capturedCalleeIdentifierIds,
|
156280
|
+
'f'
|
156281
|
+
);
|
156282
|
+
const inUseEffectLambda = __classPrivateFieldGet(
|
156283
|
+
this,
|
156284
|
+
_Context_inUseEffectLambda,
|
156285
|
+
'f'
|
156286
|
+
);
|
156287
|
+
__classPrivateFieldSet(
|
156288
|
+
this,
|
156289
|
+
_Context_capturedCalleeIdentifierIds,
|
156290
|
+
new Map(),
|
156291
|
+
'f'
|
156292
|
+
);
|
156293
|
+
__classPrivateFieldSet(this, _Context_inUseEffectLambda, true, 'f');
|
156294
|
+
const resultCapturedCalleeIdentifierIds = this.withFunctionScope(fn);
|
156295
|
+
__classPrivateFieldSet(
|
156296
|
+
this,
|
156297
|
+
_Context_capturedCalleeIdentifierIds,
|
156298
|
+
capturedCalleeIdentifierIds,
|
156299
|
+
'f'
|
156300
|
+
);
|
156301
|
+
__classPrivateFieldSet(
|
156302
|
+
this,
|
156303
|
+
_Context_inUseEffectLambda,
|
156304
|
+
inUseEffectLambda,
|
156305
|
+
'f'
|
156306
|
+
);
|
156307
|
+
return resultCapturedCalleeIdentifierIds;
|
156308
|
+
}
|
156309
|
+
addCallExpression(id, callExpr) {
|
156310
|
+
__classPrivateFieldGet(this, _Context_callExpressions, 'f').set(
|
156311
|
+
id,
|
156312
|
+
callExpr
|
156313
|
+
);
|
156314
|
+
}
|
156315
|
+
getCallExpression(id) {
|
156316
|
+
return __classPrivateFieldGet(this, _Context_callExpressions, 'f').get(id);
|
156317
|
+
}
|
156318
|
+
addLoadLocalInstr(id, loadLocal) {
|
156319
|
+
__classPrivateFieldGet(this, _Context_loadLocals, 'f').set(id, loadLocal);
|
156320
|
+
}
|
156321
|
+
getLoadLocalInstr(id) {
|
156322
|
+
return __classPrivateFieldGet(this, _Context_loadLocals, 'f').get(id);
|
156323
|
+
}
|
156324
|
+
getOrGenerateFireFunctionBinding(callee, fireLoc) {
|
156325
|
+
const fireFunctionBinding = getOrInsertWith(
|
156326
|
+
__classPrivateFieldGet(this, _Context_fireCalleesToFireFunctions, 'f'),
|
156327
|
+
callee.identifier.id,
|
156328
|
+
() =>
|
156329
|
+
createTemporaryPlace(
|
156330
|
+
__classPrivateFieldGet(this, _Context_env, 'f'),
|
156331
|
+
GeneratedSource
|
156332
|
+
)
|
156333
|
+
);
|
156334
|
+
__classPrivateFieldGet(this, _Context_capturedCalleeIdentifierIds, 'f').set(
|
156335
|
+
callee.identifier.id,
|
156336
|
+
{
|
156337
|
+
fireFunctionBinding: fireFunctionBinding,
|
156338
|
+
capturedCalleeIdentifier: callee.identifier,
|
156339
|
+
fireLoc: fireLoc,
|
156340
|
+
}
|
156341
|
+
);
|
156342
|
+
return fireFunctionBinding;
|
156343
|
+
}
|
156344
|
+
mergeCalleesFromInnerScope(innerCallees) {
|
156345
|
+
for (const [id, calleeInfo] of innerCallees.entries()) {
|
156346
|
+
__classPrivateFieldGet(
|
156347
|
+
this,
|
156348
|
+
_Context_capturedCalleeIdentifierIds,
|
156349
|
+
'f'
|
156350
|
+
).set(id, calleeInfo);
|
156351
|
+
}
|
156352
|
+
}
|
156353
|
+
addCalleeWithInsertedFire(id) {
|
156354
|
+
__classPrivateFieldGet(this, _Context_calleesWithInsertedFire, 'f').add(id);
|
156355
|
+
}
|
156356
|
+
hasCalleeWithInsertedFire(id) {
|
156357
|
+
return __classPrivateFieldGet(
|
156358
|
+
this,
|
156359
|
+
_Context_calleesWithInsertedFire,
|
156360
|
+
'f'
|
156361
|
+
).has(id);
|
156362
|
+
}
|
156363
|
+
inUseEffectLambda() {
|
156364
|
+
return __classPrivateFieldGet(this, _Context_inUseEffectLambda, 'f');
|
156365
|
+
}
|
156366
|
+
addFunctionExpression(id, fn) {
|
156367
|
+
__classPrivateFieldGet(this, _Context_functionExpressions, 'f').set(id, fn);
|
156368
|
+
}
|
156369
|
+
getFunctionExpression(id) {
|
156370
|
+
return __classPrivateFieldGet(this, _Context_functionExpressions, 'f').get(
|
156371
|
+
id
|
156372
|
+
);
|
156373
|
+
}
|
156374
|
+
addLoadGlobalInstrId(id, instrId) {
|
156375
|
+
__classPrivateFieldGet(this, _Context_loadGlobalInstructionIds, 'f').set(
|
156376
|
+
id,
|
156377
|
+
instrId
|
156378
|
+
);
|
156379
|
+
}
|
156380
|
+
getLoadGlobalInstrId(id) {
|
156381
|
+
return __classPrivateFieldGet(
|
156382
|
+
this,
|
156383
|
+
_Context_loadGlobalInstructionIds,
|
156384
|
+
'f'
|
156385
|
+
).get(id);
|
156386
|
+
}
|
156387
|
+
addArrayExpression(id, array) {
|
156388
|
+
__classPrivateFieldGet(this, _Context_arrayExpressions, 'f').set(id, array);
|
156389
|
+
}
|
156390
|
+
getArrayExpression(id) {
|
156391
|
+
return __classPrivateFieldGet(this, _Context_arrayExpressions, 'f').get(id);
|
156392
|
+
}
|
156393
|
+
hasErrors() {
|
156394
|
+
return __classPrivateFieldGet(this, _Context_errors, 'f').hasErrors();
|
156395
|
+
}
|
156396
|
+
throwIfErrorsFound() {
|
156397
|
+
if (this.hasErrors())
|
156398
|
+
throw __classPrivateFieldGet(this, _Context_errors, 'f');
|
156399
|
+
}
|
156400
|
+
}
|
156401
|
+
(_Context_env = new WeakMap()),
|
156402
|
+
(_Context_errors = new WeakMap()),
|
156403
|
+
(_Context_callExpressions = new WeakMap()),
|
156404
|
+
(_Context_functionExpressions = new WeakMap()),
|
156405
|
+
(_Context_loadLocals = new WeakMap()),
|
156406
|
+
(_Context_fireCalleesToFireFunctions = new WeakMap()),
|
156407
|
+
(_Context_calleesWithInsertedFire = new WeakMap()),
|
156408
|
+
(_Context_capturedCalleeIdentifierIds = new WeakMap()),
|
156409
|
+
(_Context_inUseEffectLambda = new WeakMap()),
|
156410
|
+
(_Context_loadGlobalInstructionIds = new WeakMap()),
|
156411
|
+
(_Context_arrayExpressions = new WeakMap());
|
156412
|
+
function deleteInstructions(deleteInstrs, instructions) {
|
156413
|
+
if (deleteInstrs.size > 0) {
|
156414
|
+
const newInstrs = instructions.filter(instr => !deleteInstrs.has(instr.id));
|
156415
|
+
return newInstrs;
|
156416
|
+
}
|
156417
|
+
return instructions;
|
156418
|
+
}
|
156419
|
+
function rewriteInstructions(rewriteInstrs, instructions) {
|
156420
|
+
if (rewriteInstrs.size > 0) {
|
156421
|
+
const newInstrs = [];
|
156422
|
+
for (const instr of instructions) {
|
156423
|
+
const newInstrsAtId = rewriteInstrs.get(instr.id);
|
156424
|
+
if (newInstrsAtId != null) {
|
156425
|
+
newInstrs.push(...newInstrsAtId, instr);
|
156426
|
+
} else {
|
156427
|
+
newInstrs.push(instr);
|
156428
|
+
}
|
156429
|
+
}
|
156430
|
+
return newInstrs;
|
156431
|
+
}
|
156432
|
+
return instructions;
|
156433
|
+
}
|
155799
156434
|
function run(
|
155800
156435
|
func,
|
155801
156436
|
config,
|
@@ -155873,6 +156508,10 @@ function runWithEnvironment(func, env) {
|
|
155873
156508
|
if (env.config.validateHooksUsage) {
|
155874
156509
|
validateHooksUsage(hir);
|
155875
156510
|
}
|
156511
|
+
if (env.config.enableFire) {
|
156512
|
+
transformFire(hir);
|
156513
|
+
log({kind: 'hir', name: 'TransformFire', value: hir});
|
156514
|
+
}
|
155876
156515
|
if (env.config.validateNoCapitalizedCalls) {
|
155877
156516
|
validateNoCapitalizedCalls(hir);
|
155878
156517
|
}
|
@@ -156624,6 +157263,13 @@ function compileProgram(program, pass) {
|
|
156624
157263
|
if (environment.enableChangeDetectionForDebugging != null) {
|
156625
157264
|
externalFunctions.push(environment.enableChangeDetectionForDebugging);
|
156626
157265
|
}
|
157266
|
+
const hasFireRewrite = compiledFns.some(c => c.compiledFn.hasFireRewrite);
|
157267
|
+
if (environment.enableFire && hasFireRewrite) {
|
157268
|
+
externalFunctions.push({
|
157269
|
+
source: getReactCompilerRuntimeModule(pass.opts),
|
157270
|
+
importSpecifierName: 'useFire',
|
157271
|
+
});
|
157272
|
+
}
|
156627
157273
|
} catch (err) {
|
156628
157274
|
handleError(err, pass, null);
|
156629
157275
|
return;
|
package/package.json
CHANGED