babel-plugin-react-compiler 19.0.0-beta-e552027-20250112 → 19.0.0-beta-decd7b8-20250118
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 +98 -2
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -125468,6 +125468,48 @@ var TYPED_GLOBALS = [
|
|
125468
125468
|
]
|
125469
125469
|
])
|
125470
125470
|
],
|
125471
|
+
[
|
125472
|
+
"performance",
|
125473
|
+
addObject(DEFAULT_SHAPES, "performance", [
|
125474
|
+
// Static methods (TODO)
|
125475
|
+
[
|
125476
|
+
"now",
|
125477
|
+
// Date.now()
|
125478
|
+
addFunction(DEFAULT_SHAPES, [], {
|
125479
|
+
positionalParams: [],
|
125480
|
+
restParam: "read" /* Read */,
|
125481
|
+
returnType: { kind: "Poly" },
|
125482
|
+
// TODO: could be Primitive, but that would change existing compilation
|
125483
|
+
calleeEffect: "read" /* Read */,
|
125484
|
+
returnValueKind: "mutable" /* Mutable */,
|
125485
|
+
// same here
|
125486
|
+
impure: true,
|
125487
|
+
canonicalName: "performance.now"
|
125488
|
+
})
|
125489
|
+
]
|
125490
|
+
])
|
125491
|
+
],
|
125492
|
+
[
|
125493
|
+
"Date",
|
125494
|
+
addObject(DEFAULT_SHAPES, "Date", [
|
125495
|
+
// Static methods (TODO)
|
125496
|
+
[
|
125497
|
+
"now",
|
125498
|
+
// Date.now()
|
125499
|
+
addFunction(DEFAULT_SHAPES, [], {
|
125500
|
+
positionalParams: [],
|
125501
|
+
restParam: "read" /* Read */,
|
125502
|
+
returnType: { kind: "Poly" },
|
125503
|
+
// TODO: could be Primitive, but that would change existing compilation
|
125504
|
+
calleeEffect: "read" /* Read */,
|
125505
|
+
returnValueKind: "mutable" /* Mutable */,
|
125506
|
+
// same here
|
125507
|
+
impure: true,
|
125508
|
+
canonicalName: "Date.now"
|
125509
|
+
})
|
125510
|
+
]
|
125511
|
+
])
|
125512
|
+
],
|
125471
125513
|
[
|
125472
125514
|
"Math",
|
125473
125515
|
addObject(DEFAULT_SHAPES, "Math", [
|
@@ -125535,6 +125577,20 @@ var TYPED_GLOBALS = [
|
|
125535
125577
|
calleeEffect: "read" /* Read */,
|
125536
125578
|
returnValueKind: "primitive" /* Primitive */
|
125537
125579
|
})
|
125580
|
+
],
|
125581
|
+
[
|
125582
|
+
"random",
|
125583
|
+
addFunction(DEFAULT_SHAPES, [], {
|
125584
|
+
positionalParams: [],
|
125585
|
+
restParam: "read" /* Read */,
|
125586
|
+
returnType: { kind: "Poly" },
|
125587
|
+
// TODO: could be Primitive, but that would change existing compilation
|
125588
|
+
calleeEffect: "read" /* Read */,
|
125589
|
+
returnValueKind: "mutable" /* Mutable */,
|
125590
|
+
// same here
|
125591
|
+
impure: true,
|
125592
|
+
canonicalName: "Math.random"
|
125593
|
+
})
|
125538
125594
|
]
|
125539
125595
|
])
|
125540
125596
|
],
|
@@ -126073,7 +126129,9 @@ var FunctionTypeSchema = z.object({
|
|
126073
126129
|
returnType: z.lazy(() => TypeSchema),
|
126074
126130
|
returnValueKind: ValueKindSchema,
|
126075
126131
|
noAlias: z.boolean().nullable().optional(),
|
126076
|
-
mutableOnlyIfOperandsAreMutable: z.boolean().nullable().optional()
|
126132
|
+
mutableOnlyIfOperandsAreMutable: z.boolean().nullable().optional(),
|
126133
|
+
impure: z.boolean().nullable().optional(),
|
126134
|
+
canonicalName: z.string().nullable().optional()
|
126077
126135
|
});
|
126078
126136
|
var HookTypeSchema = z.object({
|
126079
126137
|
kind: z.literal("hook"),
|
@@ -126346,6 +126404,10 @@ var EnvironmentConfigSchema = z.object({
|
|
126346
126404
|
*/
|
126347
126405
|
validateNoCapitalizedCalls: z.nullable(z.array(z.string())).default(null),
|
126348
126406
|
validateBlocklistedImports: z.nullable(z.array(z.string())).default(null),
|
126407
|
+
/**
|
126408
|
+
* Validate against impure functions called during render
|
126409
|
+
*/
|
126410
|
+
validateNoImpureFunctionsInRender: z.boolean().default(false),
|
126349
126411
|
/*
|
126350
126412
|
* When enabled, the compiler assumes that hooks follow the Rules of React:
|
126351
126413
|
* - Hooks may memoize computation based on any of their parameters, thus
|
@@ -144552,6 +144614,35 @@ function rewriteInstructions(rewriteInstrs, instructions) {
|
|
144552
144614
|
return instructions;
|
144553
144615
|
}
|
144554
144616
|
|
144617
|
+
// src/Validation/ValiateNoImpureFunctionsInRender.ts
|
144618
|
+
function validateNoImpureFunctionsInRender(fn) {
|
144619
|
+
const errors = new CompilerError();
|
144620
|
+
for (const [, block] of fn.body.blocks) {
|
144621
|
+
for (const instr of block.instructions) {
|
144622
|
+
const value = instr.value;
|
144623
|
+
if (value.kind === "MethodCall" || value.kind == "CallExpression") {
|
144624
|
+
const callee = value.kind === "MethodCall" ? value.property : value.callee;
|
144625
|
+
const signature = getFunctionCallSignature(
|
144626
|
+
fn.env,
|
144627
|
+
callee.identifier.type
|
144628
|
+
);
|
144629
|
+
if (signature != null && signature.impure === true) {
|
144630
|
+
errors.push({
|
144631
|
+
reason: "Calling an impure function can produce unstable results. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent)",
|
144632
|
+
description: signature.canonicalName != null ? `\`${signature.canonicalName}\` is an impure function whose results may change on every call` : null,
|
144633
|
+
severity: "InvalidReact" /* InvalidReact */,
|
144634
|
+
loc: callee.loc,
|
144635
|
+
suggestions: null
|
144636
|
+
});
|
144637
|
+
}
|
144638
|
+
}
|
144639
|
+
}
|
144640
|
+
}
|
144641
|
+
if (errors.hasErrors()) {
|
144642
|
+
throw errors;
|
144643
|
+
}
|
144644
|
+
}
|
144645
|
+
|
144555
144646
|
// src/Entrypoint/Pipeline.ts
|
144556
144647
|
function run(func, config, fnType, useMemoCacheIdentifier, logger, filename, code) {
|
144557
144648
|
const contextIdentifiers = findContextIdentifiers(func);
|
@@ -144650,6 +144741,9 @@ function runWithEnvironment(func, env) {
|
|
144650
144741
|
if (env.config.validateNoJSXInTryStatements) {
|
144651
144742
|
validateNoJSXInTryStatement(hir);
|
144652
144743
|
}
|
144744
|
+
if (env.config.validateNoImpureFunctionsInRender) {
|
144745
|
+
validateNoImpureFunctionsInRender(hir);
|
144746
|
+
}
|
144653
144747
|
inferReactivePlaces(hir);
|
144654
144748
|
log2({ kind: "hir", name: "InferReactivePlaces", value: hir });
|
144655
144749
|
rewriteInstructionKindsBasedOnReassignment(hir);
|
@@ -145646,9 +145740,11 @@ function returnsNonNode(node) {
|
|
145646
145740
|
}
|
145647
145741
|
}
|
145648
145742
|
},
|
145743
|
+
// Skip traversing all nested functions and their return statements
|
145649
145744
|
ArrowFunctionExpression: skipNestedFunctions(node),
|
145650
145745
|
FunctionExpression: skipNestedFunctions(node),
|
145651
|
-
FunctionDeclaration: skipNestedFunctions(node)
|
145746
|
+
FunctionDeclaration: skipNestedFunctions(node),
|
145747
|
+
ObjectMethod: (node2) => node2.skip()
|
145652
145748
|
});
|
145653
145749
|
return !hasReturn || returnsNonNode2;
|
145654
145750
|
}
|