babel-plugin-react-compiler 0.0.0-experimental-d664a4c-20250313 → 0.0.0-experimental-3229e95-20250314
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.d.ts +14 -6
- package/dist/index.js +451 -178
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -77,6 +77,7 @@ declare const ExternalFunctionSchema: z.ZodObject<{
|
|
77
77
|
importSpecifierName: string;
|
78
78
|
}>;
|
79
79
|
type ExternalFunction = z.infer<typeof ExternalFunctionSchema>;
|
80
|
+
type CompilerMode = 'all_features' | 'no_inferred_memo';
|
80
81
|
declare const HookSchema: z.ZodObject<{
|
81
82
|
effectKind: z.ZodNativeEnum<typeof Effect>;
|
82
83
|
valueKind: z.ZodNativeEnum<typeof ValueKind>;
|
@@ -274,7 +275,6 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
|
|
274
275
|
throwUnknownException__testonly: z.ZodDefault<z.ZodBoolean>;
|
275
276
|
enableTreatFunctionDepsAsConditional: z.ZodDefault<z.ZodBoolean>;
|
276
277
|
disableMemoizationForDebugging: z.ZodDefault<z.ZodBoolean>;
|
277
|
-
enableMinimalTransformsForRetry: z.ZodDefault<z.ZodBoolean>;
|
278
278
|
enableChangeDetectionForDebugging: z.ZodDefault<z.ZodNullable<z.ZodObject<{
|
279
279
|
source: z.ZodString;
|
280
280
|
importSpecifierName: z.ZodString;
|
@@ -370,7 +370,6 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
|
|
370
370
|
throwUnknownException__testonly: boolean;
|
371
371
|
enableTreatFunctionDepsAsConditional: boolean;
|
372
372
|
disableMemoizationForDebugging: boolean;
|
373
|
-
enableMinimalTransformsForRetry: boolean;
|
374
373
|
enableChangeDetectionForDebugging: {
|
375
374
|
source: string;
|
376
375
|
importSpecifierName: string;
|
@@ -454,7 +453,6 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
|
|
454
453
|
throwUnknownException__testonly?: boolean | undefined;
|
455
454
|
enableTreatFunctionDepsAsConditional?: boolean | undefined;
|
456
455
|
disableMemoizationForDebugging?: boolean | undefined;
|
457
|
-
enableMinimalTransformsForRetry?: boolean | undefined;
|
458
456
|
enableChangeDetectionForDebugging?: {
|
459
457
|
source: string;
|
460
458
|
importSpecifierName: string;
|
@@ -480,10 +478,12 @@ declare class Environment {
|
|
480
478
|
code: string | null;
|
481
479
|
config: EnvironmentConfig;
|
482
480
|
fnType: ReactFunctionType;
|
481
|
+
compilerMode: CompilerMode;
|
483
482
|
useMemoCacheIdentifier: string;
|
484
483
|
hasLoweredContextAccess: boolean;
|
485
484
|
hasFireRewrite: boolean;
|
486
|
-
constructor(scope: Scope, fnType: ReactFunctionType, config: EnvironmentConfig, contextIdentifiers: Set<t.Identifier>, logger: Logger | null, filename: string | null, code: string | null, useMemoCacheIdentifier: string);
|
485
|
+
constructor(scope: Scope, fnType: ReactFunctionType, compilerMode: CompilerMode, config: EnvironmentConfig, contextIdentifiers: Set<t.Identifier>, logger: Logger | null, filename: string | null, code: string | null, useMemoCacheIdentifier: string);
|
486
|
+
get isInferredMemoEnabled(): boolean;
|
487
487
|
get nextIdentifierId(): IdentifierId;
|
488
488
|
get nextBlockId(): BlockId;
|
489
489
|
get nextScopeId(): ScopeId;
|
@@ -496,6 +496,7 @@ declare class Environment {
|
|
496
496
|
type: ReactFunctionType | null;
|
497
497
|
}>;
|
498
498
|
getGlobalDeclaration(binding: NonLocalBinding, loc: SourceLocation): Global | null;
|
499
|
+
static knownReactModules: ReadonlyArray<string>;
|
499
500
|
getFallthroughPropertyType(receiver: Type, _property: Type): BuiltInType | PolyType | null;
|
500
501
|
getPropertyType(receiver: Type, property: string | number): BuiltInType | PolyType | null;
|
501
502
|
getFunctionSignature(type: FunctionType): FunctionSignature | null;
|
@@ -1462,7 +1463,7 @@ type CompilerPipelineValue = {
|
|
1462
1463
|
name: string;
|
1463
1464
|
value: string;
|
1464
1465
|
};
|
1465
|
-
declare function compileFn(func: NodePath<t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression>, config: EnvironmentConfig, fnType: ReactFunctionType, useMemoCacheIdentifier: string, logger: Logger | null, filename: string | null, code: string | null): CodegenFunction;
|
1466
|
+
declare function compileFn(func: NodePath<t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression>, config: EnvironmentConfig, fnType: ReactFunctionType, mode: CompilerMode, useMemoCacheIdentifier: string, logger: Logger | null, filename: string | null, code: string | null): CodegenFunction;
|
1466
1467
|
|
1467
1468
|
declare const PanicThresholdOptionsSchema: z.ZodEnum<["all_errors", "critical_errors", "none"]>;
|
1468
1469
|
type PanicThresholdOptions = z.infer<typeof PanicThresholdOptionsSchema>;
|
@@ -1545,7 +1546,14 @@ declare const OPT_IN_DIRECTIVES: Set<string>;
|
|
1545
1546
|
declare const OPT_OUT_DIRECTIVES: Set<string>;
|
1546
1547
|
declare function findDirectiveEnablingMemoization(directives: Array<t.Directive>): Array<t.Directive>;
|
1547
1548
|
declare function findDirectiveDisablingMemoization(directives: Array<t.Directive>): Array<t.Directive>;
|
1548
|
-
|
1549
|
+
type BabelFn = NodePath$1<t.FunctionDeclaration> | NodePath$1<t.FunctionExpression> | NodePath$1<t.ArrowFunctionExpression>;
|
1550
|
+
type CompileProgramResult = {
|
1551
|
+
retryErrors: Array<{
|
1552
|
+
fn: BabelFn;
|
1553
|
+
error: CompilerError;
|
1554
|
+
}>;
|
1555
|
+
};
|
1556
|
+
declare function compileProgram(program: NodePath$1<t.Program>, pass: CompilerPass): CompileProgramResult | null;
|
1549
1557
|
|
1550
1558
|
declare function runBabelPluginReactCompiler(text: string, file: string, language: 'flow' | 'typescript', options: Partial<PluginOptions> | null, includeAst?: boolean): BabelCore.BabelFileResult;
|
1551
1559
|
|
package/dist/index.js
CHANGED
@@ -12103,9 +12103,9 @@ var require_inferer_reference = __commonJS({
|
|
12103
12103
|
}
|
12104
12104
|
}
|
12105
12105
|
function getConditionalAnnotation(binding, path, name) {
|
12106
|
-
const
|
12107
|
-
if (!
|
12108
|
-
const test =
|
12106
|
+
const ifStatement3 = getParentConditionalPath(binding, path, name);
|
12107
|
+
if (!ifStatement3) return;
|
12108
|
+
const test = ifStatement3.get("test");
|
12109
12109
|
const paths = [test];
|
12110
12110
|
const types = [];
|
12111
12111
|
for (let i = 0; i < paths.length; i++) {
|
@@ -12123,10 +12123,10 @@ var require_inferer_reference = __commonJS({
|
|
12123
12123
|
if (types.length) {
|
12124
12124
|
return {
|
12125
12125
|
typeAnnotation: (0, _util.createUnionType)(types),
|
12126
|
-
ifStatement:
|
12126
|
+
ifStatement: ifStatement3
|
12127
12127
|
};
|
12128
12128
|
}
|
12129
|
-
return getConditionalAnnotation(binding,
|
12129
|
+
return getConditionalAnnotation(binding, ifStatement3, name);
|
12130
12130
|
}
|
12131
12131
|
}
|
12132
12132
|
});
|
@@ -13265,7 +13265,7 @@ var require_modification = __commonJS({
|
|
13265
13265
|
arrowFunctionExpression: arrowFunctionExpression2,
|
13266
13266
|
assertExpression,
|
13267
13267
|
assignmentExpression: assignmentExpression2,
|
13268
|
-
blockStatement:
|
13268
|
+
blockStatement: blockStatement3,
|
13269
13269
|
callExpression: callExpression3,
|
13270
13270
|
cloneNode: cloneNode2,
|
13271
13271
|
expressionStatement: expressionStatement2,
|
@@ -13295,7 +13295,7 @@ var require_modification = __commonJS({
|
|
13295
13295
|
} else if (this.isStatementOrBlock()) {
|
13296
13296
|
const node = this.node;
|
13297
13297
|
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
|
13298
|
-
this.replaceWith(
|
13298
|
+
this.replaceWith(blockStatement3(shouldInsertCurrentNode ? [node] : []));
|
13299
13299
|
return this.unshiftContainer("body", nodes);
|
13300
13300
|
} else {
|
13301
13301
|
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
@@ -13396,7 +13396,7 @@ var require_modification = __commonJS({
|
|
13396
13396
|
} else if (this.isStatementOrBlock()) {
|
13397
13397
|
const node = this.node;
|
13398
13398
|
const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
|
13399
|
-
this.replaceWith(
|
13399
|
+
this.replaceWith(blockStatement3(shouldInsertCurrentNode ? [node] : []));
|
13400
13400
|
return this.pushContainer("body", nodes);
|
13401
13401
|
} else {
|
13402
13402
|
throw new Error("We don't know what to do with this node type. We were previously a Statement but we can't fit in here?");
|
@@ -27502,7 +27502,7 @@ var require_replacement = __commonJS({
|
|
27502
27502
|
arrowFunctionExpression: arrowFunctionExpression2,
|
27503
27503
|
assignmentExpression: assignmentExpression2,
|
27504
27504
|
awaitExpression: awaitExpression2,
|
27505
|
-
blockStatement:
|
27505
|
+
blockStatement: blockStatement3,
|
27506
27506
|
buildUndefinedNode,
|
27507
27507
|
callExpression: callExpression3,
|
27508
27508
|
cloneNode: cloneNode2,
|
@@ -27522,7 +27522,7 @@ var require_replacement = __commonJS({
|
|
27522
27522
|
isStatement: isStatement2,
|
27523
27523
|
isVariableDeclaration: isVariableDeclaration2,
|
27524
27524
|
removeComments,
|
27525
|
-
returnStatement:
|
27525
|
+
returnStatement: returnStatement3,
|
27526
27526
|
sequenceExpression: sequenceExpression2,
|
27527
27527
|
validate: validate2,
|
27528
27528
|
yieldExpression
|
@@ -27637,7 +27637,7 @@ var require_replacement = __commonJS({
|
|
27637
27637
|
const functionParent = this.getFunctionParent();
|
27638
27638
|
const isParentAsync = functionParent == null ? void 0 : functionParent.node.async;
|
27639
27639
|
const isParentGenerator = functionParent == null ? void 0 : functionParent.node.generator;
|
27640
|
-
const container = arrowFunctionExpression2([],
|
27640
|
+
const container = arrowFunctionExpression2([], blockStatement3(nodes));
|
27641
27641
|
this.replaceWith(callExpression3(container, []));
|
27642
27642
|
const callee = this.get("callee");
|
27643
27643
|
callee.get("body").scope.hoistVariables((id) => this.scope.push({
|
@@ -27651,14 +27651,14 @@ var require_replacement = __commonJS({
|
|
27651
27651
|
let uid = loop.getData("expressionReplacementReturnUid");
|
27652
27652
|
if (!uid) {
|
27653
27653
|
uid = callee.scope.generateDeclaredUidIdentifier("ret");
|
27654
|
-
callee.get("body").pushContainer("body",
|
27654
|
+
callee.get("body").pushContainer("body", returnStatement3(cloneNode2(uid)));
|
27655
27655
|
loop.setData("expressionReplacementReturnUid", uid);
|
27656
27656
|
} else {
|
27657
27657
|
uid = identifier4(uid.name);
|
27658
27658
|
}
|
27659
27659
|
path.get("expression").replaceWith(assignmentExpression2("=", cloneNode2(uid), path.node.expression));
|
27660
27660
|
} else {
|
27661
|
-
path.replaceWith(
|
27661
|
+
path.replaceWith(returnStatement3(path.node.expression));
|
27662
27662
|
}
|
27663
27663
|
}
|
27664
27664
|
callee.arrowFunctionToExpression();
|
@@ -28416,7 +28416,7 @@ var require_populate = __commonJS({
|
|
28416
28416
|
exports2.default = populatePlaceholders;
|
28417
28417
|
var _t = require("@babel/types");
|
28418
28418
|
var {
|
28419
|
-
blockStatement:
|
28419
|
+
blockStatement: blockStatement3,
|
28420
28420
|
cloneNode: cloneNode2,
|
28421
28421
|
emptyStatement: emptyStatement2,
|
28422
28422
|
expressionStatement: expressionStatement2,
|
@@ -28479,7 +28479,7 @@ var require_populate = __commonJS({
|
|
28479
28479
|
if (!replacement) {
|
28480
28480
|
replacement = emptyStatement2();
|
28481
28481
|
} else if (Array.isArray(replacement)) {
|
28482
|
-
replacement =
|
28482
|
+
replacement = blockStatement3(replacement);
|
28483
28483
|
} else if (typeof replacement === "string") {
|
28484
28484
|
replacement = expressionStatement2(identifier4(replacement));
|
28485
28485
|
} else if (!isStatement2(replacement)) {
|
@@ -28762,7 +28762,7 @@ var require_conversion = __commonJS({
|
|
28762
28762
|
arrowFunctionExpression: arrowFunctionExpression2,
|
28763
28763
|
assignmentExpression: assignmentExpression2,
|
28764
28764
|
binaryExpression: binaryExpression2,
|
28765
|
-
blockStatement:
|
28765
|
+
blockStatement: blockStatement3,
|
28766
28766
|
callExpression: callExpression3,
|
28767
28767
|
conditionalExpression: conditionalExpression3,
|
28768
28768
|
expressionStatement: expressionStatement2,
|
@@ -28775,10 +28775,10 @@ var require_conversion = __commonJS({
|
|
28775
28775
|
metaProperty: metaProperty2,
|
28776
28776
|
numericLiteral: numericLiteral2,
|
28777
28777
|
objectExpression: objectExpression2,
|
28778
|
-
restElement:
|
28779
|
-
returnStatement:
|
28778
|
+
restElement: restElement3,
|
28779
|
+
returnStatement: returnStatement3,
|
28780
28780
|
sequenceExpression: sequenceExpression2,
|
28781
|
-
spreadElement:
|
28781
|
+
spreadElement: spreadElement3,
|
28782
28782
|
stringLiteral: stringLiteral3,
|
28783
28783
|
super: _super,
|
28784
28784
|
thisExpression,
|
@@ -28834,13 +28834,13 @@ var require_conversion = __commonJS({
|
|
28834
28834
|
stringPath += ".body.0";
|
28835
28835
|
if (this.isFunction()) {
|
28836
28836
|
key2 = "argument";
|
28837
|
-
statements.push(
|
28837
|
+
statements.push(returnStatement3(body.node));
|
28838
28838
|
} else {
|
28839
28839
|
key2 = "expression";
|
28840
28840
|
statements.push(expressionStatement2(body.node));
|
28841
28841
|
}
|
28842
28842
|
}
|
28843
|
-
this.node.body =
|
28843
|
+
this.node.body = blockStatement3(statements);
|
28844
28844
|
const parentPath = this.get(stringPath);
|
28845
28845
|
_context3.setup.call(body, parentPath, listKey ? parentPath.node[listKey] : parentPath.node, listKey, key2);
|
28846
28846
|
return this.node;
|
@@ -29110,7 +29110,7 @@ var require_conversion = __commonJS({
|
|
29110
29110
|
function getSuperBinding(thisEnvFn) {
|
29111
29111
|
return getBinding(thisEnvFn, "supercall", () => {
|
29112
29112
|
const argsBinding = thisEnvFn.scope.generateUidIdentifier("args");
|
29113
|
-
return arrowFunctionExpression2([
|
29113
|
+
return arrowFunctionExpression2([restElement3(argsBinding)], callExpression3(_super(), [spreadElement3(identifier4(argsBinding.name))]));
|
29114
29114
|
});
|
29115
29115
|
}
|
29116
29116
|
function getSuperPropBinding(thisEnvFn, isAssignment, propName) {
|
@@ -47261,7 +47261,7 @@ var require_populate2 = __commonJS({
|
|
47261
47261
|
exports2.default = populatePlaceholders;
|
47262
47262
|
var _t = require("@babel/types");
|
47263
47263
|
var {
|
47264
|
-
blockStatement:
|
47264
|
+
blockStatement: blockStatement3,
|
47265
47265
|
cloneNode: cloneNode2,
|
47266
47266
|
emptyStatement: emptyStatement2,
|
47267
47267
|
expressionStatement: expressionStatement2,
|
@@ -47324,7 +47324,7 @@ var require_populate2 = __commonJS({
|
|
47324
47324
|
if (!replacement) {
|
47325
47325
|
replacement = emptyStatement2();
|
47326
47326
|
} else if (Array.isArray(replacement)) {
|
47327
|
-
replacement =
|
47327
|
+
replacement = blockStatement3(replacement);
|
47328
47328
|
} else if (typeof replacement === "string") {
|
47329
47329
|
replacement = expressionStatement2(identifier4(replacement));
|
47330
47330
|
} else if (!isStatement2(replacement)) {
|
@@ -57983,9 +57983,9 @@ var require_inferer_reference2 = __commonJS({
|
|
57983
57983
|
}
|
57984
57984
|
}
|
57985
57985
|
function getConditionalAnnotation(binding, path, name) {
|
57986
|
-
const
|
57987
|
-
if (!
|
57988
|
-
const test =
|
57986
|
+
const ifStatement3 = getParentConditionalPath(binding, path, name);
|
57987
|
+
if (!ifStatement3) return;
|
57988
|
+
const test = ifStatement3.get("test");
|
57989
57989
|
const paths = [test];
|
57990
57990
|
const types = [];
|
57991
57991
|
for (let i = 0; i < paths.length; i++) {
|
@@ -58003,10 +58003,10 @@ var require_inferer_reference2 = __commonJS({
|
|
58003
58003
|
if (types.length) {
|
58004
58004
|
return {
|
58005
58005
|
typeAnnotation: t5.createUnionTypeAnnotation(types),
|
58006
|
-
ifStatement:
|
58006
|
+
ifStatement: ifStatement3
|
58007
58007
|
};
|
58008
58008
|
}
|
58009
|
-
return getConditionalAnnotation(
|
58009
|
+
return getConditionalAnnotation(ifStatement3, name);
|
58010
58010
|
}
|
58011
58011
|
}
|
58012
58012
|
});
|
@@ -89611,7 +89611,7 @@ var require_populate3 = __commonJS({
|
|
89611
89611
|
exports2.default = populatePlaceholders;
|
89612
89612
|
var _t = require("@babel/types");
|
89613
89613
|
var {
|
89614
|
-
blockStatement:
|
89614
|
+
blockStatement: blockStatement3,
|
89615
89615
|
cloneNode: cloneNode2,
|
89616
89616
|
emptyStatement: emptyStatement2,
|
89617
89617
|
expressionStatement: expressionStatement2,
|
@@ -89674,7 +89674,7 @@ var require_populate3 = __commonJS({
|
|
89674
89674
|
if (!replacement) {
|
89675
89675
|
replacement = emptyStatement2();
|
89676
89676
|
} else if (Array.isArray(replacement)) {
|
89677
|
-
replacement =
|
89677
|
+
replacement = blockStatement3(replacement);
|
89678
89678
|
} else if (typeof replacement === "string") {
|
89679
89679
|
replacement = expressionStatement2(identifier4(replacement));
|
89680
89680
|
} else if (!isStatement2(replacement)) {
|
@@ -110447,54 +110447,6 @@ var import_invariant4 = __toESM(require_invariant());
|
|
110447
110447
|
|
110448
110448
|
// src/Entrypoint/Gating.ts
|
110449
110449
|
var t = __toESM(require("@babel/types"));
|
110450
|
-
function insertGatedFunctionDeclaration(fnPath, compiled, gating) {
|
110451
|
-
const gatingExpression = t.conditionalExpression(
|
110452
|
-
t.callExpression(t.identifier(gating.importSpecifierName), []),
|
110453
|
-
buildFunctionExpression(compiled),
|
110454
|
-
buildFunctionExpression(fnPath.node)
|
110455
|
-
);
|
110456
|
-
if (fnPath.parentPath.node.type !== "ExportDefaultDeclaration" && fnPath.node.type === "FunctionDeclaration" && fnPath.node.id != null) {
|
110457
|
-
fnPath.replaceWith(
|
110458
|
-
t.variableDeclaration("const", [
|
110459
|
-
t.variableDeclarator(fnPath.node.id, gatingExpression)
|
110460
|
-
])
|
110461
|
-
);
|
110462
|
-
} else if (fnPath.parentPath.node.type === "ExportDefaultDeclaration" && fnPath.node.type !== "ArrowFunctionExpression" && fnPath.node.id != null) {
|
110463
|
-
fnPath.insertAfter(
|
110464
|
-
t.exportDefaultDeclaration(t.identifier(fnPath.node.id.name))
|
110465
|
-
);
|
110466
|
-
fnPath.parentPath.replaceWith(
|
110467
|
-
t.variableDeclaration("const", [
|
110468
|
-
t.variableDeclarator(
|
110469
|
-
t.identifier(fnPath.node.id.name),
|
110470
|
-
gatingExpression
|
110471
|
-
)
|
110472
|
-
])
|
110473
|
-
);
|
110474
|
-
} else {
|
110475
|
-
fnPath.replaceWith(gatingExpression);
|
110476
|
-
}
|
110477
|
-
}
|
110478
|
-
function buildFunctionExpression(node) {
|
110479
|
-
var _a, _b;
|
110480
|
-
if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression") {
|
110481
|
-
return node;
|
110482
|
-
} else {
|
110483
|
-
const fn = {
|
110484
|
-
type: "FunctionExpression",
|
110485
|
-
async: node.async,
|
110486
|
-
generator: node.generator,
|
110487
|
-
loc: (_a = node.loc) != null ? _a : null,
|
110488
|
-
id: (_b = node.id) != null ? _b : null,
|
110489
|
-
params: node.params,
|
110490
|
-
body: node.body
|
110491
|
-
};
|
110492
|
-
return fn;
|
110493
|
-
}
|
110494
|
-
}
|
110495
|
-
|
110496
|
-
// src/Entrypoint/Imports.ts
|
110497
|
-
var t3 = __toESM(require("@babel/types"));
|
110498
110450
|
|
110499
110451
|
// src/Utils/utils.ts
|
110500
110452
|
function assertExhaustive(_, errorMsg) {
|
@@ -110753,6 +110705,135 @@ var CompilerError = class _CompilerError extends Error {
|
|
110753
110705
|
}
|
110754
110706
|
};
|
110755
110707
|
|
110708
|
+
// src/Entrypoint/Gating.ts
|
110709
|
+
function insertAdditionalFunctionDeclaration(fnPath, compiled, gating) {
|
110710
|
+
var _a, _b;
|
110711
|
+
const originalFnName = fnPath.node.id;
|
110712
|
+
const originalFnParams = fnPath.node.params;
|
110713
|
+
const compiledParams = fnPath.node.params;
|
110714
|
+
CompilerError.invariant(originalFnName != null && compiled.id != null, {
|
110715
|
+
reason: "Expected function declarations that are referenced elsewhere to have a named identifier",
|
110716
|
+
loc: (_a = fnPath.node.loc) != null ? _a : null
|
110717
|
+
});
|
110718
|
+
CompilerError.invariant(originalFnParams.length === compiledParams.length, {
|
110719
|
+
reason: "Expected React Compiler optimized function declarations to have the same number of parameters as source",
|
110720
|
+
loc: (_b = fnPath.node.loc) != null ? _b : null
|
110721
|
+
});
|
110722
|
+
const gatingCondition = fnPath.scope.generateUidIdentifier(
|
110723
|
+
`${gating.importSpecifierName}_result`
|
110724
|
+
);
|
110725
|
+
const unoptimizedFnName = fnPath.scope.generateUidIdentifier(
|
110726
|
+
`${originalFnName.name}_unoptimized`
|
110727
|
+
);
|
110728
|
+
const optimizedFnName = fnPath.scope.generateUidIdentifier(
|
110729
|
+
`${originalFnName.name}_optimized`
|
110730
|
+
);
|
110731
|
+
compiled.id.name = optimizedFnName.name;
|
110732
|
+
fnPath.get("id").replaceInline(unoptimizedFnName);
|
110733
|
+
const newParams = [];
|
110734
|
+
const genNewArgs = [];
|
110735
|
+
for (let i = 0; i < originalFnParams.length; i++) {
|
110736
|
+
const argName = `arg${i}`;
|
110737
|
+
if (originalFnParams[i].type === "RestElement") {
|
110738
|
+
newParams.push(t.restElement(t.identifier(argName)));
|
110739
|
+
genNewArgs.push(() => t.spreadElement(t.identifier(argName)));
|
110740
|
+
} else {
|
110741
|
+
newParams.push(t.identifier(argName));
|
110742
|
+
genNewArgs.push(() => t.identifier(argName));
|
110743
|
+
}
|
110744
|
+
}
|
110745
|
+
fnPath.insertAfter(
|
110746
|
+
t.functionDeclaration(
|
110747
|
+
originalFnName,
|
110748
|
+
newParams,
|
110749
|
+
t.blockStatement([
|
110750
|
+
t.ifStatement(
|
110751
|
+
gatingCondition,
|
110752
|
+
t.returnStatement(
|
110753
|
+
t.callExpression(
|
110754
|
+
compiled.id,
|
110755
|
+
genNewArgs.map((fn) => fn())
|
110756
|
+
)
|
110757
|
+
),
|
110758
|
+
t.returnStatement(
|
110759
|
+
t.callExpression(
|
110760
|
+
unoptimizedFnName,
|
110761
|
+
genNewArgs.map((fn) => fn())
|
110762
|
+
)
|
110763
|
+
)
|
110764
|
+
)
|
110765
|
+
])
|
110766
|
+
)
|
110767
|
+
);
|
110768
|
+
fnPath.insertBefore(
|
110769
|
+
t.variableDeclaration("const", [
|
110770
|
+
t.variableDeclarator(
|
110771
|
+
gatingCondition,
|
110772
|
+
t.callExpression(t.identifier(gating.importSpecifierName), [])
|
110773
|
+
)
|
110774
|
+
])
|
110775
|
+
);
|
110776
|
+
fnPath.insertBefore(compiled);
|
110777
|
+
}
|
110778
|
+
function insertGatedFunctionDeclaration(fnPath, compiled, gating, referencedBeforeDeclaration) {
|
110779
|
+
var _a;
|
110780
|
+
if (referencedBeforeDeclaration && fnPath.isFunctionDeclaration()) {
|
110781
|
+
CompilerError.invariant(compiled.type === "FunctionDeclaration", {
|
110782
|
+
reason: "Expected compiled node type to match input type",
|
110783
|
+
description: `Got ${compiled.type} but expected FunctionDeclaration`,
|
110784
|
+
loc: (_a = fnPath.node.loc) != null ? _a : null
|
110785
|
+
});
|
110786
|
+
insertAdditionalFunctionDeclaration(fnPath, compiled, gating);
|
110787
|
+
} else {
|
110788
|
+
const gatingExpression = t.conditionalExpression(
|
110789
|
+
t.callExpression(t.identifier(gating.importSpecifierName), []),
|
110790
|
+
buildFunctionExpression(compiled),
|
110791
|
+
buildFunctionExpression(fnPath.node)
|
110792
|
+
);
|
110793
|
+
if (fnPath.parentPath.node.type !== "ExportDefaultDeclaration" && fnPath.node.type === "FunctionDeclaration" && fnPath.node.id != null) {
|
110794
|
+
fnPath.replaceWith(
|
110795
|
+
t.variableDeclaration("const", [
|
110796
|
+
t.variableDeclarator(fnPath.node.id, gatingExpression)
|
110797
|
+
])
|
110798
|
+
);
|
110799
|
+
} else if (fnPath.parentPath.node.type === "ExportDefaultDeclaration" && fnPath.node.type !== "ArrowFunctionExpression" && fnPath.node.id != null) {
|
110800
|
+
fnPath.insertAfter(
|
110801
|
+
t.exportDefaultDeclaration(t.identifier(fnPath.node.id.name))
|
110802
|
+
);
|
110803
|
+
fnPath.parentPath.replaceWith(
|
110804
|
+
t.variableDeclaration("const", [
|
110805
|
+
t.variableDeclarator(
|
110806
|
+
t.identifier(fnPath.node.id.name),
|
110807
|
+
gatingExpression
|
110808
|
+
)
|
110809
|
+
])
|
110810
|
+
);
|
110811
|
+
} else {
|
110812
|
+
fnPath.replaceWith(gatingExpression);
|
110813
|
+
}
|
110814
|
+
}
|
110815
|
+
}
|
110816
|
+
function buildFunctionExpression(node) {
|
110817
|
+
var _a, _b;
|
110818
|
+
if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression") {
|
110819
|
+
return node;
|
110820
|
+
} else {
|
110821
|
+
const fn = {
|
110822
|
+
type: "FunctionExpression",
|
110823
|
+
async: node.async,
|
110824
|
+
generator: node.generator,
|
110825
|
+
loc: (_a = node.loc) != null ? _a : null,
|
110826
|
+
id: (_b = node.id) != null ? _b : null,
|
110827
|
+
params: node.params,
|
110828
|
+
body: node.body
|
110829
|
+
};
|
110830
|
+
return fn;
|
110831
|
+
}
|
110832
|
+
}
|
110833
|
+
|
110834
|
+
// src/Entrypoint/Imports.ts
|
110835
|
+
var t3 = __toESM(require("@babel/types"));
|
110836
|
+
|
110756
110837
|
// src/HIR/HIR.ts
|
110757
110838
|
var t2 = __toESM(require("@babel/types"));
|
110758
110839
|
|
@@ -123699,7 +123780,6 @@ var EnvironmentConfigSchema = z.object({
|
|
123699
123780
|
* original source will be disabled as well.
|
123700
123781
|
*/
|
123701
123782
|
disableMemoizationForDebugging: z.boolean().default(false),
|
123702
|
-
enableMinimalTransformsForRetry: z.boolean().default(false),
|
123703
123783
|
/**
|
123704
123784
|
* When true, rather using memoized values, the compiler will always re-compute
|
123705
123785
|
* values, and then use a heuristic to compare the memoized value to the newly
|
@@ -123766,17 +123846,6 @@ var EnvironmentConfigSchema = z.object({
|
|
123766
123846
|
*/
|
123767
123847
|
lowerContextAccess: ExternalFunctionSchema.nullable().default(null)
|
123768
123848
|
});
|
123769
|
-
var MINIMAL_RETRY_CONFIG = {
|
123770
|
-
validateHooksUsage: false,
|
123771
|
-
validateRefAccessDuringRender: false,
|
123772
|
-
validateNoSetStateInRender: false,
|
123773
|
-
validateNoSetStateInPassiveEffects: false,
|
123774
|
-
validateNoJSXInTryStatements: false,
|
123775
|
-
validateMemoizedEffectDependencies: false,
|
123776
|
-
validateNoCapitalizedCalls: null,
|
123777
|
-
validateBlocklistedImports: null,
|
123778
|
-
enableMinimalTransformsForRetry: true
|
123779
|
-
};
|
123780
123849
|
var testComplexConfigDefaults = {
|
123781
123850
|
validateNoCapitalizedCalls: [],
|
123782
123851
|
enableChangeDetectionForDebugging: {
|
@@ -123925,7 +123994,7 @@ function parseConfigPragmaForTests(pragma, defaults) {
|
|
123925
123994
|
}
|
123926
123995
|
var _globals, _shapes, _moduleTypes, _nextIdentifer, _nextBlock, _nextScope, _scope, _outlinedFunctions, _contextIdentifiers, _hoistedIdentifiers, _Environment_instances, resolveModuleType_fn, isKnownReactModule_fn, getCustomHookType_fn;
|
123927
123996
|
var Environment = class {
|
123928
|
-
constructor(scope, fnType, config, contextIdentifiers, logger, filename, code, useMemoCacheIdentifier) {
|
123997
|
+
constructor(scope, fnType, compilerMode, config, contextIdentifiers, logger, filename, code, useMemoCacheIdentifier) {
|
123929
123998
|
__privateAdd(this, _Environment_instances);
|
123930
123999
|
__privateAdd(this, _globals);
|
123931
124000
|
__privateAdd(this, _shapes);
|
@@ -123939,6 +124008,7 @@ var Environment = class {
|
|
123939
124008
|
__privateAdd(this, _hoistedIdentifiers);
|
123940
124009
|
__privateSet(this, _scope, scope);
|
123941
124010
|
this.fnType = fnType;
|
124011
|
+
this.compilerMode = compilerMode;
|
123942
124012
|
this.config = config;
|
123943
124013
|
this.filename = filename;
|
123944
124014
|
this.code = code;
|
@@ -123983,6 +124053,9 @@ var Environment = class {
|
|
123983
124053
|
__privateSet(this, _contextIdentifiers, contextIdentifiers);
|
123984
124054
|
__privateSet(this, _hoistedIdentifiers, /* @__PURE__ */ new Set());
|
123985
124055
|
}
|
124056
|
+
get isInferredMemoEnabled() {
|
124057
|
+
return this.compilerMode !== "no_inferred_memo";
|
124058
|
+
}
|
123986
124059
|
get nextIdentifierId() {
|
123987
124060
|
return makeIdentifierId(__privateWrapper(this, _nextIdentifer)._++);
|
123988
124061
|
}
|
@@ -124197,6 +124270,7 @@ getCustomHookType_fn = function() {
|
|
124197
124270
|
return DefaultMutatingHook;
|
124198
124271
|
}
|
124199
124272
|
};
|
124273
|
+
Environment.knownReactModules = ["react", "react-dom"];
|
124200
124274
|
var REANIMATED_MODULE_NAME = "react-native-reanimated";
|
124201
124275
|
function isHookName(name) {
|
124202
124276
|
return /^use[A-Z0-9]/.test(name);
|
@@ -125090,6 +125164,14 @@ function parsePluginOptions(obj) {
|
|
125090
125164
|
parsedOptions[key2] = parseTargetConfig(value);
|
125091
125165
|
break;
|
125092
125166
|
}
|
125167
|
+
case "gating": {
|
125168
|
+
if (value == null) {
|
125169
|
+
parsedOptions[key2] = null;
|
125170
|
+
} else {
|
125171
|
+
parsedOptions[key2] = tryParseExternalFunction(value);
|
125172
|
+
}
|
125173
|
+
break;
|
125174
|
+
}
|
125093
125175
|
default: {
|
125094
125176
|
parsedOptions[key2] = value;
|
125095
125177
|
}
|
@@ -132339,19 +132421,19 @@ function inferTerminalFunctionEffects(state, block) {
|
|
132339
132421
|
}
|
132340
132422
|
return functionEffects;
|
132341
132423
|
}
|
132342
|
-
function
|
132343
|
-
functionEffects.
|
132424
|
+
function transformFunctionEffectErrors(functionEffects) {
|
132425
|
+
return functionEffects.map((eff) => {
|
132344
132426
|
switch (eff.kind) {
|
132345
132427
|
case "ReactMutation":
|
132346
132428
|
case "GlobalMutation": {
|
132347
|
-
|
132429
|
+
return eff.error;
|
132348
132430
|
}
|
132349
132431
|
case "ContextMutation": {
|
132350
|
-
|
132432
|
+
return {
|
132351
132433
|
severity: "Invariant" /* Invariant */,
|
132352
132434
|
reason: `Unexpected ContextMutation in top-level function effects`,
|
132353
132435
|
loc: eff.loc
|
132354
|
-
}
|
132436
|
+
};
|
132355
132437
|
}
|
132356
132438
|
default:
|
132357
132439
|
assertExhaustive(
|
@@ -132501,8 +132583,9 @@ function inferReferenceEffects(fn, options = { isFunctionExpression: false }) {
|
|
132501
132583
|
}
|
132502
132584
|
if (options.isFunctionExpression) {
|
132503
132585
|
fn.effects = functionEffects;
|
132504
|
-
|
132505
|
-
|
132586
|
+
return [];
|
132587
|
+
} else {
|
132588
|
+
return transformFunctionEffectErrors(functionEffects);
|
132506
132589
|
}
|
132507
132590
|
}
|
132508
132591
|
var _env3, _values, _variables;
|
@@ -141794,12 +141877,13 @@ function validateNoImpureFunctionsInRender(fn) {
|
|
141794
141877
|
}
|
141795
141878
|
|
141796
141879
|
// src/Entrypoint/Pipeline.ts
|
141797
|
-
function run(func, config, fnType, useMemoCacheIdentifier, logger, filename, code) {
|
141880
|
+
function run(func, config, fnType, mode, useMemoCacheIdentifier, logger, filename, code) {
|
141798
141881
|
var _a, _b;
|
141799
141882
|
const contextIdentifiers = findContextIdentifiers(func);
|
141800
141883
|
const env = new Environment(
|
141801
141884
|
func.scope,
|
141802
141885
|
fnType,
|
141886
|
+
mode,
|
141803
141887
|
config,
|
141804
141888
|
contextIdentifiers,
|
141805
141889
|
logger,
|
@@ -141825,7 +141909,7 @@ function runWithEnvironment(func, env) {
|
|
141825
141909
|
log2({ kind: "hir", name: "PruneMaybeThrows", value: hir });
|
141826
141910
|
validateContextVariableLValues(hir);
|
141827
141911
|
validateUseMemo(hir);
|
141828
|
-
if (
|
141912
|
+
if (env.isInferredMemoEnabled && !env.config.enablePreserveExistingManualUseMemo && !env.config.disableMemoizationForDebugging && !env.config.enableChangeDetectionForDebugging) {
|
141829
141913
|
dropManualMemoization(hir);
|
141830
141914
|
log2({ kind: "hir", name: "DropManualMemoization", value: hir });
|
141831
141915
|
}
|
@@ -141848,16 +141932,18 @@ function runWithEnvironment(func, env) {
|
|
141848
141932
|
log2({ kind: "hir", name: "ConstantPropagation", value: hir });
|
141849
141933
|
inferTypes(hir);
|
141850
141934
|
log2({ kind: "hir", name: "InferTypes", value: hir });
|
141851
|
-
if (env.
|
141852
|
-
validateHooksUsage
|
141935
|
+
if (env.isInferredMemoEnabled) {
|
141936
|
+
if (env.config.validateHooksUsage) {
|
141937
|
+
validateHooksUsage(hir);
|
141938
|
+
}
|
141939
|
+
if (env.config.validateNoCapitalizedCalls) {
|
141940
|
+
validateNoCapitalizedCalls(hir);
|
141941
|
+
}
|
141853
141942
|
}
|
141854
141943
|
if (env.config.enableFire) {
|
141855
141944
|
transformFire(hir);
|
141856
141945
|
log2({ kind: "hir", name: "TransformFire", value: hir });
|
141857
141946
|
}
|
141858
|
-
if (env.config.validateNoCapitalizedCalls) {
|
141859
|
-
validateNoCapitalizedCalls(hir);
|
141860
|
-
}
|
141861
141947
|
if (env.config.lowerContextAccess) {
|
141862
141948
|
lowerContextAccess(hir, env.config.lowerContextAccess);
|
141863
141949
|
}
|
@@ -141865,7 +141951,12 @@ function runWithEnvironment(func, env) {
|
|
141865
141951
|
log2({ kind: "hir", name: "OptimizePropsMethodCalls", value: hir });
|
141866
141952
|
analyseFunctions(hir);
|
141867
141953
|
log2({ kind: "hir", name: "AnalyseFunctions", value: hir });
|
141868
|
-
inferReferenceEffects(hir);
|
141954
|
+
const fnEffectErrors = inferReferenceEffects(hir);
|
141955
|
+
if (env.isInferredMemoEnabled) {
|
141956
|
+
if (fnEffectErrors.length > 0) {
|
141957
|
+
CompilerError.throw(fnEffectErrors[0]);
|
141958
|
+
}
|
141959
|
+
}
|
141869
141960
|
log2({ kind: "hir", name: "InferReferenceEffects", value: hir });
|
141870
141961
|
validateLocalsNotReassignedAfterRender(hir);
|
141871
141962
|
deadCodeElimination(hir);
|
@@ -141878,23 +141969,25 @@ function runWithEnvironment(func, env) {
|
|
141878
141969
|
log2({ kind: "hir", name: "PruneMaybeThrows", value: hir });
|
141879
141970
|
inferMutableRanges(hir);
|
141880
141971
|
log2({ kind: "hir", name: "InferMutableRanges", value: hir });
|
141881
|
-
if (env.
|
141882
|
-
assertValidMutableRanges
|
141883
|
-
|
141884
|
-
|
141885
|
-
|
141886
|
-
|
141887
|
-
|
141888
|
-
validateNoSetStateInRender
|
141889
|
-
|
141890
|
-
|
141891
|
-
validateNoSetStateInPassiveEffects
|
141892
|
-
|
141893
|
-
|
141894
|
-
|
141895
|
-
|
141896
|
-
|
141897
|
-
validateNoImpureFunctionsInRender
|
141972
|
+
if (env.isInferredMemoEnabled) {
|
141973
|
+
if (env.config.assertValidMutableRanges) {
|
141974
|
+
assertValidMutableRanges(hir);
|
141975
|
+
}
|
141976
|
+
if (env.config.validateRefAccessDuringRender) {
|
141977
|
+
validateNoRefAccessInRender(hir);
|
141978
|
+
}
|
141979
|
+
if (env.config.validateNoSetStateInRender) {
|
141980
|
+
validateNoSetStateInRender(hir);
|
141981
|
+
}
|
141982
|
+
if (env.config.validateNoSetStateInPassiveEffects) {
|
141983
|
+
validateNoSetStateInPassiveEffects(hir);
|
141984
|
+
}
|
141985
|
+
if (env.config.validateNoJSXInTryStatements) {
|
141986
|
+
validateNoJSXInTryStatement(hir);
|
141987
|
+
}
|
141988
|
+
if (env.config.validateNoImpureFunctionsInRender) {
|
141989
|
+
validateNoImpureFunctionsInRender(hir);
|
141990
|
+
}
|
141898
141991
|
}
|
141899
141992
|
inferReactivePlaces(hir);
|
141900
141993
|
log2({ kind: "hir", name: "InferReactivePlaces", value: hir });
|
@@ -141910,7 +142003,7 @@ function runWithEnvironment(func, env) {
|
|
141910
142003
|
name: "PropagatePhiTypes",
|
141911
142004
|
value: hir
|
141912
142005
|
});
|
141913
|
-
if (
|
142006
|
+
if (env.isInferredMemoEnabled) {
|
141914
142007
|
inferReactiveScopeVariables(hir);
|
141915
142008
|
log2({ kind: "hir", name: "InferReactiveScopeVariables", value: hir });
|
141916
142009
|
}
|
@@ -142109,11 +142202,12 @@ function runWithEnvironment(func, env) {
|
|
142109
142202
|
}
|
142110
142203
|
return ast;
|
142111
142204
|
}
|
142112
|
-
function compileFn(func, config, fnType, useMemoCacheIdentifier, logger, filename, code) {
|
142205
|
+
function compileFn(func, config, fnType, mode, useMemoCacheIdentifier, logger, filename, code) {
|
142113
142206
|
return run(
|
142114
142207
|
func,
|
142115
142208
|
config,
|
142116
142209
|
fnType,
|
142210
|
+
mode,
|
142117
142211
|
useMemoCacheIdentifier,
|
142118
142212
|
logger,
|
142119
142213
|
filename,
|
@@ -142425,13 +142519,13 @@ function isFilePartOfSources(sources, filename) {
|
|
142425
142519
|
function compileProgram(program, pass) {
|
142426
142520
|
var _a, _b;
|
142427
142521
|
if (shouldSkipCompilation(program, pass)) {
|
142428
|
-
return;
|
142522
|
+
return null;
|
142429
142523
|
}
|
142430
142524
|
const environment = pass.opts.environment;
|
142431
142525
|
const restrictedImportsErr = validateRestrictedImports(program, environment);
|
142432
142526
|
if (restrictedImportsErr) {
|
142433
142527
|
handleError(restrictedImportsErr, pass, null);
|
142434
|
-
return;
|
142528
|
+
return null;
|
142435
142529
|
}
|
142436
142530
|
const useMemoCacheIdentifier = program.scope.generateUidIdentifier("c");
|
142437
142531
|
const suppressions = findProgramSuppressions(
|
@@ -142469,6 +142563,7 @@ function compileProgram(program, pass) {
|
|
142469
142563
|
filename: (_b = pass.filename) != null ? _b : null
|
142470
142564
|
})
|
142471
142565
|
);
|
142566
|
+
const retryErrors = [];
|
142472
142567
|
const processFn = (fn, fnType) => {
|
142473
142568
|
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
142474
142569
|
let optInDirectives = [];
|
@@ -142499,6 +142594,7 @@ function compileProgram(program, pass) {
|
|
142499
142594
|
fn,
|
142500
142595
|
environment,
|
142501
142596
|
fnType,
|
142597
|
+
"all_features",
|
142502
142598
|
useMemoCacheIdentifier.name,
|
142503
142599
|
pass.opts.logger,
|
142504
142600
|
pass.filename,
|
@@ -142509,14 +142605,23 @@ function compileProgram(program, pass) {
|
|
142509
142605
|
compileResult = { kind: "error", error: err };
|
142510
142606
|
}
|
142511
142607
|
}
|
142512
|
-
if (compileResult.kind === "error"
|
142608
|
+
if (compileResult.kind === "error") {
|
142609
|
+
if (optOutDirectives.length > 0) {
|
142610
|
+
logError(compileResult.error, pass, (_a2 = fn.node.loc) != null ? _a2 : null);
|
142611
|
+
} else {
|
142612
|
+
handleError(compileResult.error, pass, (_b2 = fn.node.loc) != null ? _b2 : null);
|
142613
|
+
}
|
142614
|
+
if (!(environment.enableFire || environment.inferEffectDependencies != null)) {
|
142615
|
+
return null;
|
142616
|
+
}
|
142513
142617
|
try {
|
142514
142618
|
compileResult = {
|
142515
142619
|
kind: "compile",
|
142516
142620
|
compiledFn: compileFn(
|
142517
142621
|
fn,
|
142518
|
-
|
142622
|
+
environment,
|
142519
142623
|
fnType,
|
142624
|
+
"no_inferred_memo",
|
142520
142625
|
useMemoCacheIdentifier.name,
|
142521
142626
|
pass.opts.logger,
|
142522
142627
|
pass.filename,
|
@@ -142524,16 +142629,11 @@ function compileProgram(program, pass) {
|
|
142524
142629
|
)
|
142525
142630
|
};
|
142526
142631
|
} catch (err) {
|
142527
|
-
|
142528
|
-
|
142529
|
-
|
142530
|
-
|
142531
|
-
if (optOutDirectives.length > 0) {
|
142532
|
-
logError(compileResult.error, pass, (_a2 = fn.node.loc) != null ? _a2 : null);
|
142533
|
-
} else {
|
142534
|
-
handleError(compileResult.error, pass, (_b2 = fn.node.loc) != null ? _b2 : null);
|
142632
|
+
if (err instanceof CompilerError) {
|
142633
|
+
retryErrors.push({ fn, error: err });
|
142634
|
+
}
|
142635
|
+
return null;
|
142535
142636
|
}
|
142536
|
-
return null;
|
142537
142637
|
}
|
142538
142638
|
(_f = pass.opts.logger) == null ? void 0 : _f.logEvent(pass.filename, {
|
142539
142639
|
kind: "CompileSuccess",
|
@@ -142602,29 +142702,22 @@ function compileProgram(program, pass) {
|
|
142602
142702
|
program.node.directives
|
142603
142703
|
);
|
142604
142704
|
if (moduleScopeOptOutDirectives.length > 0) {
|
142605
|
-
return;
|
142705
|
+
return null;
|
142606
142706
|
}
|
142707
|
+
let gating = null;
|
142607
142708
|
if (pass.opts.gating != null) {
|
142608
|
-
|
142609
|
-
|
142610
|
-
compiledFns
|
142611
|
-
|
142612
|
-
})
|
142613
|
-
);
|
142614
|
-
if (error) {
|
142615
|
-
handleError(error, pass, null);
|
142616
|
-
return;
|
142617
|
-
}
|
142709
|
+
gating = {
|
142710
|
+
gatingFn: pass.opts.gating,
|
142711
|
+
referencedBeforeDeclared: getFunctionReferencedBeforeDeclarationAtTopLevel(program, compiledFns)
|
142712
|
+
};
|
142618
142713
|
}
|
142619
142714
|
const hasLoweredContextAccess = compiledFns.some(
|
142620
142715
|
(c2) => c2.compiledFn.hasLoweredContextAccess
|
142621
142716
|
);
|
142622
142717
|
const externalFunctions = [];
|
142623
|
-
let gating = null;
|
142624
142718
|
try {
|
142625
|
-
if (
|
142626
|
-
gating
|
142627
|
-
externalFunctions.push(gating);
|
142719
|
+
if (gating != null) {
|
142720
|
+
externalFunctions.push(gating.gatingFn);
|
142628
142721
|
}
|
142629
142722
|
const lowerContextAccess2 = environment.lowerContextAccess;
|
142630
142723
|
if (lowerContextAccess2 && hasLoweredContextAccess) {
|
@@ -142655,13 +142748,18 @@ function compileProgram(program, pass) {
|
|
142655
142748
|
}
|
142656
142749
|
} catch (err) {
|
142657
142750
|
handleError(err, pass, null);
|
142658
|
-
return;
|
142751
|
+
return null;
|
142659
142752
|
}
|
142660
142753
|
for (const result of compiledFns) {
|
142661
142754
|
const { kind, originalFn, compiledFn } = result;
|
142662
142755
|
const transformedFn = createNewFunctionNode(originalFn, compiledFn);
|
142663
142756
|
if (gating != null && kind === "original") {
|
142664
|
-
insertGatedFunctionDeclaration(
|
142757
|
+
insertGatedFunctionDeclaration(
|
142758
|
+
originalFn,
|
142759
|
+
transformedFn,
|
142760
|
+
gating.gatingFn,
|
142761
|
+
gating.referencedBeforeDeclared.has(result)
|
142762
|
+
);
|
142665
142763
|
} else {
|
142666
142764
|
originalFn.replaceWith(transformedFn);
|
142667
142765
|
}
|
@@ -142683,6 +142781,7 @@ function compileProgram(program, pass) {
|
|
142683
142781
|
}
|
142684
142782
|
addImportsToProgram(program, externalFunctions);
|
142685
142783
|
}
|
142784
|
+
return { retryErrors };
|
142686
142785
|
}
|
142687
142786
|
function shouldSkipCompilation(program, pass) {
|
142688
142787
|
if (pass.opts.sources) {
|
@@ -142953,14 +143052,16 @@ function getFunctionName2(path) {
|
|
142953
143052
|
return null;
|
142954
143053
|
}
|
142955
143054
|
}
|
142956
|
-
function
|
142957
|
-
const
|
142958
|
-
fns.map((fn) =>
|
142959
|
-
(
|
142960
|
-
|
143055
|
+
function getFunctionReferencedBeforeDeclarationAtTopLevel(program, fns) {
|
143056
|
+
const fnNames = new Map(
|
143057
|
+
fns.map((fn) => [
|
143058
|
+
getFunctionName2(fn.originalFn),
|
143059
|
+
fn
|
143060
|
+
]).filter(
|
143061
|
+
(entry) => !!entry[0] && entry[0].isIdentifier()
|
143062
|
+
).map((entry) => [entry[0].node.name, { id: entry[0].node, fn: entry[1] }])
|
142961
143063
|
);
|
142962
|
-
const
|
142963
|
-
const errors = new CompilerError();
|
143064
|
+
const referencedBeforeDeclaration = /* @__PURE__ */ new Set();
|
142964
143065
|
program.traverse({
|
142965
143066
|
TypeAnnotation(path) {
|
142966
143067
|
path.skip();
|
@@ -142975,31 +143076,21 @@ function checkFunctionReferencedBeforeDeclarationAtTopLevel(program, fns) {
|
|
142975
143076
|
path.skip();
|
142976
143077
|
},
|
142977
143078
|
Identifier(id) {
|
142978
|
-
var _a;
|
142979
143079
|
const fn = fnNames.get(id.node.name);
|
142980
143080
|
if (!fn) {
|
142981
143081
|
return;
|
142982
143082
|
}
|
142983
|
-
if (
|
142984
|
-
fnIds.delete(id.node);
|
143083
|
+
if (id.node === fn.id) {
|
142985
143084
|
fnNames.delete(id.node.name);
|
142986
143085
|
return;
|
142987
143086
|
}
|
142988
143087
|
const scope = id.scope.getFunctionParent();
|
142989
143088
|
if (scope === null && id.isReferencedIdentifier()) {
|
142990
|
-
|
142991
|
-
new CompilerErrorDetail({
|
142992
|
-
reason: `Encountered a function used before its declaration, which breaks Forget's gating codegen due to hoisting`,
|
142993
|
-
description: `Rewrite the reference to ${fn.name} to not rely on hoisting to fix this issue`,
|
142994
|
-
loc: (_a = fn.loc) != null ? _a : null,
|
142995
|
-
suggestions: null,
|
142996
|
-
severity: "Invariant" /* Invariant */
|
142997
|
-
})
|
142998
|
-
);
|
143089
|
+
referencedBeforeDeclaration.add(fn.fn);
|
142999
143090
|
}
|
143000
143091
|
}
|
143001
143092
|
});
|
143002
|
-
return
|
143093
|
+
return referencedBeforeDeclaration;
|
143003
143094
|
}
|
143004
143095
|
function getReactCompilerRuntimeModule(opts) {
|
143005
143096
|
if (opts.target === "19") {
|
@@ -143055,6 +143146,181 @@ function injectReanimatedFlag(options) {
|
|
143055
143146
|
});
|
143056
143147
|
}
|
143057
143148
|
|
143149
|
+
// src/Entrypoint/ValidateNoUntransformedReferences.ts
|
143150
|
+
function throwInvalidReact(options, { logger, filename }) {
|
143151
|
+
const detail = __spreadProps(__spreadValues({}, options), {
|
143152
|
+
severity: "InvalidReact" /* InvalidReact */
|
143153
|
+
});
|
143154
|
+
logger == null ? void 0 : logger.logEvent(filename, {
|
143155
|
+
kind: "CompileError",
|
143156
|
+
fnLoc: null,
|
143157
|
+
detail
|
143158
|
+
});
|
143159
|
+
CompilerError.throw(detail);
|
143160
|
+
}
|
143161
|
+
function assertValidEffectImportReference(numArgs, paths, context) {
|
143162
|
+
var _a;
|
143163
|
+
for (const path of paths) {
|
143164
|
+
const parent = path.parentPath;
|
143165
|
+
if (parent != null && parent.isCallExpression()) {
|
143166
|
+
const args = parent.get("arguments");
|
143167
|
+
if (args.length === numArgs) {
|
143168
|
+
const maybeErrorDiagnostic = matchCompilerDiagnostic(
|
143169
|
+
path,
|
143170
|
+
context.transformErrors
|
143171
|
+
);
|
143172
|
+
throwInvalidReact(
|
143173
|
+
{
|
143174
|
+
reason: "[InferEffectDependencies] React Compiler is unable to infer dependencies of this effect. This will break your build! To resolve, either pass your own dependency array or fix reported compiler bailout diagnostics.",
|
143175
|
+
description: maybeErrorDiagnostic ? `(Bailout reason: ${maybeErrorDiagnostic})` : null,
|
143176
|
+
loc: (_a = parent.node.loc) != null ? _a : null
|
143177
|
+
},
|
143178
|
+
context
|
143179
|
+
);
|
143180
|
+
}
|
143181
|
+
}
|
143182
|
+
}
|
143183
|
+
}
|
143184
|
+
function assertValidFireImportReference(paths, context) {
|
143185
|
+
var _a;
|
143186
|
+
if (paths.length > 0) {
|
143187
|
+
const maybeErrorDiagnostic = matchCompilerDiagnostic(
|
143188
|
+
paths[0],
|
143189
|
+
context.transformErrors
|
143190
|
+
);
|
143191
|
+
throwInvalidReact(
|
143192
|
+
{
|
143193
|
+
reason: "[Fire] Untransformed reference to compiler-required feature. Either remove this `fire` call or ensure it is successfully transformed by the compiler",
|
143194
|
+
description: maybeErrorDiagnostic ? `(Bailout reason: ${maybeErrorDiagnostic})` : null,
|
143195
|
+
loc: (_a = paths[0].node.loc) != null ? _a : null
|
143196
|
+
},
|
143197
|
+
context
|
143198
|
+
);
|
143199
|
+
}
|
143200
|
+
}
|
143201
|
+
function validateNoUntransformedReferences(path, filename, logger, env, transformErrors) {
|
143202
|
+
const moduleLoadChecks = /* @__PURE__ */ new Map();
|
143203
|
+
if (env.enableFire) {
|
143204
|
+
for (const module2 of Environment.knownReactModules) {
|
143205
|
+
const react = getOrInsertWith(moduleLoadChecks, module2, () => /* @__PURE__ */ new Map());
|
143206
|
+
react.set("fire", assertValidFireImportReference);
|
143207
|
+
}
|
143208
|
+
}
|
143209
|
+
if (env.inferEffectDependencies) {
|
143210
|
+
for (const {
|
143211
|
+
function: { source: source2, importSpecifierName },
|
143212
|
+
numRequiredArgs
|
143213
|
+
} of env.inferEffectDependencies) {
|
143214
|
+
const module2 = getOrInsertWith(moduleLoadChecks, source2, () => /* @__PURE__ */ new Map());
|
143215
|
+
module2.set(
|
143216
|
+
importSpecifierName,
|
143217
|
+
assertValidEffectImportReference.bind(null, numRequiredArgs)
|
143218
|
+
);
|
143219
|
+
}
|
143220
|
+
}
|
143221
|
+
if (moduleLoadChecks.size > 0) {
|
143222
|
+
transformProgram(path, moduleLoadChecks, filename, logger, transformErrors);
|
143223
|
+
}
|
143224
|
+
}
|
143225
|
+
function validateImportSpecifier(specifier, importSpecifierChecks, state) {
|
143226
|
+
var _a;
|
143227
|
+
const imported = specifier.get("imported");
|
143228
|
+
const specifierName = imported.node.type === "Identifier" ? imported.node.name : imported.node.value;
|
143229
|
+
const checkFn = importSpecifierChecks.get(specifierName);
|
143230
|
+
if (checkFn == null) {
|
143231
|
+
return;
|
143232
|
+
}
|
143233
|
+
if (state.shouldInvalidateScopes) {
|
143234
|
+
state.shouldInvalidateScopes = false;
|
143235
|
+
state.program.scope.crawl();
|
143236
|
+
}
|
143237
|
+
const local = specifier.get("local");
|
143238
|
+
const binding = local.scope.getBinding(local.node.name);
|
143239
|
+
CompilerError.invariant(binding != null, {
|
143240
|
+
reason: "Expected binding to be found for import specifier",
|
143241
|
+
loc: (_a = local.node.loc) != null ? _a : null
|
143242
|
+
});
|
143243
|
+
checkFn(binding.referencePaths, state);
|
143244
|
+
}
|
143245
|
+
function validateNamespacedImport(specifier, importSpecifierChecks, state) {
|
143246
|
+
var _a;
|
143247
|
+
if (state.shouldInvalidateScopes) {
|
143248
|
+
state.shouldInvalidateScopes = false;
|
143249
|
+
state.program.scope.crawl();
|
143250
|
+
}
|
143251
|
+
const local = specifier.get("local");
|
143252
|
+
const binding = local.scope.getBinding(local.node.name);
|
143253
|
+
const defaultCheckFn = importSpecifierChecks.get(DEFAULT_EXPORT);
|
143254
|
+
CompilerError.invariant(binding != null, {
|
143255
|
+
reason: "Expected binding to be found for import specifier",
|
143256
|
+
loc: (_a = local.node.loc) != null ? _a : null
|
143257
|
+
});
|
143258
|
+
const filteredReferences = /* @__PURE__ */ new Map();
|
143259
|
+
for (const reference of binding.referencePaths) {
|
143260
|
+
if (defaultCheckFn != null) {
|
143261
|
+
getOrInsertWith(filteredReferences, defaultCheckFn, () => []).push(
|
143262
|
+
reference
|
143263
|
+
);
|
143264
|
+
}
|
143265
|
+
const parent = reference.parentPath;
|
143266
|
+
if (parent != null && parent.isMemberExpression() && parent.get("object") === reference) {
|
143267
|
+
if (parent.node.computed || parent.node.property.type !== "Identifier") {
|
143268
|
+
continue;
|
143269
|
+
}
|
143270
|
+
const checkFn = importSpecifierChecks.get(parent.node.property.name);
|
143271
|
+
if (checkFn != null) {
|
143272
|
+
getOrInsertWith(filteredReferences, checkFn, () => []).push(parent);
|
143273
|
+
}
|
143274
|
+
}
|
143275
|
+
}
|
143276
|
+
for (const [checkFn, references] of filteredReferences) {
|
143277
|
+
checkFn(references, state);
|
143278
|
+
}
|
143279
|
+
}
|
143280
|
+
function transformProgram(path, moduleLoadChecks, filename, logger, transformErrors) {
|
143281
|
+
const traversalState = {
|
143282
|
+
shouldInvalidateScopes: true,
|
143283
|
+
program: path,
|
143284
|
+
filename,
|
143285
|
+
logger,
|
143286
|
+
transformErrors
|
143287
|
+
};
|
143288
|
+
path.traverse({
|
143289
|
+
ImportDeclaration(path2) {
|
143290
|
+
const importSpecifierChecks = moduleLoadChecks.get(
|
143291
|
+
path2.node.source.value
|
143292
|
+
);
|
143293
|
+
if (importSpecifierChecks == null) {
|
143294
|
+
return;
|
143295
|
+
}
|
143296
|
+
const specifiers = path2.get("specifiers");
|
143297
|
+
for (const specifier of specifiers) {
|
143298
|
+
if (specifier.isImportSpecifier()) {
|
143299
|
+
validateImportSpecifier(
|
143300
|
+
specifier,
|
143301
|
+
importSpecifierChecks,
|
143302
|
+
traversalState
|
143303
|
+
);
|
143304
|
+
} else {
|
143305
|
+
validateNamespacedImport(
|
143306
|
+
specifier,
|
143307
|
+
importSpecifierChecks,
|
143308
|
+
traversalState
|
143309
|
+
);
|
143310
|
+
}
|
143311
|
+
}
|
143312
|
+
}
|
143313
|
+
});
|
143314
|
+
}
|
143315
|
+
function matchCompilerDiagnostic(badReference, transformErrors) {
|
143316
|
+
for (const { fn, error } of transformErrors) {
|
143317
|
+
if (fn.isAncestor(badReference)) {
|
143318
|
+
return error.toString();
|
143319
|
+
}
|
143320
|
+
}
|
143321
|
+
return null;
|
143322
|
+
}
|
143323
|
+
|
143058
143324
|
// src/Babel/BabelPlugin.ts
|
143059
143325
|
var ENABLE_REACT_COMPILER_TIMINGS = process.env["ENABLE_REACT_COMPILER_TIMINGS"] === "1";
|
143060
143326
|
function BabelPluginReactCompiler(_babel) {
|
@@ -143068,7 +143334,7 @@ function BabelPluginReactCompiler(_babel) {
|
|
143068
143334
|
*/
|
143069
143335
|
Program: {
|
143070
143336
|
enter(prog, pass) {
|
143071
|
-
var _a, _b, _c;
|
143337
|
+
var _a, _b, _c, _d, _e;
|
143072
143338
|
const filename = (_a = pass.filename) != null ? _a : "unknown";
|
143073
143339
|
if (ENABLE_REACT_COMPILER_TIMINGS === true) {
|
143074
143340
|
performance.mark(`${filename}:start`, {
|
@@ -143087,12 +143353,19 @@ function BabelPluginReactCompiler(_babel) {
|
|
143087
143353
|
})
|
143088
143354
|
});
|
143089
143355
|
}
|
143090
|
-
compileProgram(prog, {
|
143356
|
+
const result = compileProgram(prog, {
|
143091
143357
|
opts,
|
143092
143358
|
filename: (_b = pass.filename) != null ? _b : null,
|
143093
143359
|
comments: (_c = pass.file.ast.comments) != null ? _c : [],
|
143094
143360
|
code: pass.file.code
|
143095
143361
|
});
|
143362
|
+
validateNoUntransformedReferences(
|
143363
|
+
prog,
|
143364
|
+
(_d = pass.filename) != null ? _d : null,
|
143365
|
+
opts.logger,
|
143366
|
+
opts.environment,
|
143367
|
+
(_e = result == null ? void 0 : result.retryErrors) != null ? _e : []
|
143368
|
+
);
|
143096
143369
|
if (ENABLE_REACT_COMPILER_TIMINGS === true) {
|
143097
143370
|
performance.mark(`${filename}:end`, {
|
143098
143371
|
detail: "BabelPlugin:Program:end"
|
package/package.json
CHANGED