Socket
Book a DemoInstallSign in
Socket

babel-plugin-react-compiler

Package Overview
Dependencies
Maintainers
2
Versions
298
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-react-compiler - npm Package Compare versions

Comparing version

to
0.0.0-experimental-3edd82f-20250804

297

dist/index.d.ts

@@ -5,3 +5,3 @@ import * as BabelCore from '@babel/core';

import { z } from 'zod';
import { Scope, NodePath } from '@babel/traverse';
import { NodePath, Scope } from '@babel/traverse';

@@ -67,2 +67,86 @@ interface Result<T, E> {

type AliasingEffect = {
kind: 'Freeze';
value: Place;
reason: ValueReason;
} | {
kind: 'Mutate';
value: Place;
} | {
kind: 'MutateConditionally';
value: Place;
} | {
kind: 'MutateTransitive';
value: Place;
} | {
kind: 'MutateTransitiveConditionally';
value: Place;
} | {
kind: 'Capture';
from: Place;
into: Place;
} | {
kind: 'Alias';
from: Place;
into: Place;
} | {
kind: 'MaybeAlias';
from: Place;
into: Place;
} | {
kind: 'Assign';
from: Place;
into: Place;
} | {
kind: 'Create';
into: Place;
value: ValueKind;
reason: ValueReason;
} | {
kind: 'CreateFrom';
from: Place;
into: Place;
} | {
kind: 'ImmutableCapture';
from: Place;
into: Place;
} | {
kind: 'Apply';
receiver: Place;
function: Place;
mutatesFunction: boolean;
args: Array<Place | SpreadPattern | Hole>;
into: Place;
signature: FunctionSignature | null;
loc: SourceLocation;
} | {
kind: 'CreateFunction';
captures: Array<Place>;
function: FunctionExpression | ObjectMethod;
into: Place;
} | {
kind: 'MutateFrozen';
place: Place;
error: CompilerDiagnostic;
} | {
kind: 'MutateGlobal';
place: Place;
error: CompilerDiagnostic;
} | {
kind: 'Impure';
place: Place;
error: CompilerDiagnostic;
} | {
kind: 'Render';
place: Place;
};
type AliasingSignature = {
receiver: IdentifierId;
params: Array<IdentifierId>;
rest: IdentifierId | null;
returns: IdentifierId;
effects: Array<AliasingEffect>;
temporaries: Array<Place>;
};
type BuiltInType = PrimitiveType | FunctionType | ObjectType;

@@ -114,3 +198,3 @@ type Type = BuiltInType | PhiType | TypeVar | PolyType | PropType | ObjectMethod$1;

type HookKind = 'useContext' | 'useState' | 'useActionState' | 'useReducer' | 'useRef' | 'useEffect' | 'useLayoutEffect' | 'useInsertionEffect' | 'useMemo' | 'useCallback' | 'useTransition' | 'useImperativeHandle' | 'Custom';
type HookKind = 'useContext' | 'useState' | 'useActionState' | 'useReducer' | 'useRef' | 'useEffect' | 'useLayoutEffect' | 'useInsertionEffect' | 'useMemo' | 'useCallback' | 'useTransition' | 'useImperativeHandle' | 'useEffectEvent' | 'Custom';
type FunctionSignature = {

@@ -128,2 +212,3 @@ positionalParams: Array<Effect>;

canonicalName?: string;
aliasing?: AliasingSignature | null | undefined;
};

@@ -202,2 +287,3 @@

enableUseTypeAnnotations: z.ZodDefault<z.ZodBoolean>;
enableNewMutationAliasingModel: z.ZodDefault<z.ZodBoolean>;
enableOptionalDependencies: z.ZodDefault<z.ZodBoolean>;

@@ -216,3 +302,3 @@ enableFire: z.ZodDefault<z.ZodBoolean>;

}>;
numRequiredArgs: z.ZodNumber;
autodepsIndex: z.ZodNumber;
}, "strip", z.ZodTypeAny, {

@@ -223,3 +309,3 @@ function: {

};
numRequiredArgs: number;
autodepsIndex: number;
}, {

@@ -230,3 +316,3 @@ function: {

};
numRequiredArgs: number;
autodepsIndex: number;
}>, "many">>>;

@@ -246,3 +332,4 @@ inlineJsxTransform: z.ZodDefault<z.ZodNullable<z.ZodObject<{

validateNoSetStateInRender: z.ZodDefault<z.ZodBoolean>;
validateNoSetStateInPassiveEffects: z.ZodDefault<z.ZodBoolean>;
validateNoSetStateInEffects: z.ZodDefault<z.ZodBoolean>;
validateNoDerivedComputationsInEffects: z.ZodDefault<z.ZodBoolean>;
validateNoJSXInTryStatements: z.ZodDefault<z.ZodBoolean>;

@@ -254,2 +341,3 @@ validateStaticComponents: z.ZodDefault<z.ZodBoolean>;

validateNoImpureFunctionsInRender: z.ZodDefault<z.ZodBoolean>;
validateNoFreezingKnownMutableFunctions: z.ZodDefault<z.ZodBoolean>;
enableAssumeHooksFollowRulesOfReact: z.ZodDefault<z.ZodBoolean>;

@@ -372,2 +460,3 @@ enableTransitivelyFreezeFunctionExpressions: z.ZodDefault<z.ZodBoolean>;

}>>>;
validateNoVoidUseMemo: z.ZodDefault<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {

@@ -393,2 +482,3 @@ customHooks: Map<string, {

enableUseTypeAnnotations: boolean;
enableNewMutationAliasingModel: boolean;
enableOptionalDependencies: boolean;

@@ -401,3 +491,3 @@ enableFire: boolean;

};
numRequiredArgs: number;
autodepsIndex: number;
}[] | null;

@@ -411,3 +501,4 @@ inlineJsxTransform: {

validateNoSetStateInRender: boolean;
validateNoSetStateInPassiveEffects: boolean;
validateNoSetStateInEffects: boolean;
validateNoDerivedComputationsInEffects: boolean;
validateNoJSXInTryStatements: boolean;

@@ -419,2 +510,3 @@ validateStaticComponents: boolean;

validateNoImpureFunctionsInRender: boolean;
validateNoFreezingKnownMutableFunctions: boolean;
enableAssumeHooksFollowRulesOfReact: boolean;

@@ -461,2 +553,3 @@ enableTransitivelyFreezeFunctionExpressions: boolean;

} | null;
validateNoVoidUseMemo: boolean;
}, {

@@ -482,2 +575,3 @@ customHooks?: Map<string, {

enableUseTypeAnnotations?: boolean | undefined;
enableNewMutationAliasingModel?: boolean | undefined;
enableOptionalDependencies?: boolean | undefined;

@@ -490,3 +584,3 @@ enableFire?: boolean | undefined;

};
numRequiredArgs: number;
autodepsIndex: number;
}[] | null | undefined;

@@ -500,3 +594,4 @@ inlineJsxTransform?: {

validateNoSetStateInRender?: boolean | undefined;
validateNoSetStateInPassiveEffects?: boolean | undefined;
validateNoSetStateInEffects?: boolean | undefined;
validateNoDerivedComputationsInEffects?: boolean | undefined;
validateNoJSXInTryStatements?: boolean | undefined;

@@ -508,2 +603,3 @@ validateStaticComponents?: boolean | undefined;

validateNoImpureFunctionsInRender?: boolean | undefined;
validateNoFreezingKnownMutableFunctions?: boolean | undefined;
enableAssumeHooksFollowRulesOfReact?: boolean | undefined;

@@ -550,7 +646,5 @@ enableTransitivelyFreezeFunctionExpressions?: boolean | undefined;

} | null | undefined;
validateNoVoidUseMemo?: boolean | undefined;
}>;
type EnvironmentConfig = z.infer<typeof EnvironmentConfigSchema>;
declare function parseConfigPragmaForTests(pragma: string, defaults: {
compilationMode: CompilationMode;
}): PluginOptions;
type PartialEnvironmentConfig = Partial<EnvironmentConfig>;

@@ -569,3 +663,5 @@ type ReactFunctionType = 'Component' | 'Hook' | 'Other';

hasInferredEffect: boolean;
constructor(scope: Scope, fnType: ReactFunctionType, compilerMode: CompilerMode, config: EnvironmentConfig, contextIdentifiers: Set<t.Identifier>, logger: Logger | null, filename: string | null, code: string | null, programContext: ProgramContext);
inferredEffectLocations: Set<SourceLocation>;
parentFunction: NodePath<t.Function>;
constructor(scope: Scope, fnType: ReactFunctionType, compilerMode: CompilerMode, config: EnvironmentConfig, contextIdentifiers: Set<t.Identifier>, parentFunction: NodePath<t.Function>, logger: Logger | null, filename: string | null, code: string | null, programContext: ProgramContext);
get isInferredMemoEnabled(): boolean;

@@ -634,2 +730,3 @@ get nextIdentifierId(): IdentifierId;

value: ReactiveValue;
effects?: Array<AliasingEffect> | null;
loc: SourceLocation;

@@ -771,3 +868,3 @@ };

returnTypeAnnotation: t.FlowType | t.TSType | null;
returnType: Type;
returns: Place;
context: Array<Place>;

@@ -779,2 +876,3 @@ effects: Array<FunctionEffect> | null;

directives: Array<string>;
aliasingEffects?: Array<AliasingEffect> | null;
};

@@ -830,4 +928,6 @@ type FunctionEffect = {

};
type ReturnVariant = 'Void' | 'Implicit' | 'Explicit';
type ReturnTerminal = {
kind: 'return';
returnVariant: ReturnVariant;
loc: SourceLocation;

@@ -837,2 +937,3 @@ value: Place;

fallthrough?: never;
effects: Array<AliasingEffect> | null;
};

@@ -974,2 +1075,3 @@ type GotoTerminal = {

fallthrough?: never;
effects: Array<AliasingEffect> | null;
};

@@ -997,2 +1099,3 @@ type ReactiveScopeTerminal = {

loc: SourceLocation;
effects: Array<AliasingEffect> | null;
};

@@ -1138,3 +1241,3 @@ type LValue = {

lvalue: {
kind: InstructionKind.Reassign;
kind: InstructionKind.Reassign | InstructionKind.Const | InstructionKind.Let | InstructionKind.Function;
place: Place;

@@ -1159,9 +1262,14 @@ };

loc: SourceLocation;
} | {
} | ({
kind: 'TypeCastExpression';
value: Place;
typeAnnotation: t.FlowType | t.TSType;
type: Type;
loc: SourceLocation;
} | JsxExpression | {
} & ({
typeAnnotation: t.FlowType;
typeAnnotationKind: 'cast';
} | {
typeAnnotation: t.TSType;
typeAnnotationKind: 'as' | 'satisfies';
})) | JsxExpression | {
kind: 'ObjectExpression';

@@ -1385,2 +1493,5 @@ properties: Array<ObjectProperty | SpreadPattern>;

JsxCaptured = "jsx-captured",
HookCaptured = "hook-captured",
HookReturn = "hook-return",
Effect = "effect",
KnownReturnSignature = "known-return-signature",

@@ -1441,2 +1552,3 @@ Context = "context",

identifier: Identifier;
reactive: boolean;
path: DependencyPath;

@@ -1468,2 +1580,3 @@ };

};
declare function printFunctionWithOutlined(fn: HIRFunction): string;
declare function printHIR(ir: HIR, options?: Options | null): string;

@@ -1473,2 +1586,3 @@

InvalidJS = "InvalidJS",
UnsupportedJS = "UnsupportedJS",
InvalidReact = "InvalidReact",

@@ -1480,2 +1594,14 @@ InvalidConfig = "InvalidConfig",

}
type CompilerDiagnosticOptions = {
severity: ErrorSeverity;
category: string;
description: string;
details: Array<CompilerDiagnosticDetail>;
suggestions?: Array<CompilerSuggestion> | null | undefined;
};
type CompilerDiagnosticDetail = {
kind: 'error';
loc: SourceLocation | null;
message: string;
};
declare enum CompilerSuggestionOperation {

@@ -1504,2 +1630,18 @@ InsertBefore = 0,

};
type PrintErrorMessageOptions = {
eslint: boolean;
};
declare class CompilerDiagnostic {
options: CompilerDiagnosticOptions;
constructor(options: CompilerDiagnosticOptions);
static create(options: Omit<CompilerDiagnosticOptions, 'details'>): CompilerDiagnostic;
get category(): CompilerDiagnosticOptions['category'];
get description(): CompilerDiagnosticOptions['description'];
get severity(): CompilerDiagnosticOptions['severity'];
get suggestions(): CompilerDiagnosticOptions['suggestions'];
withDetail(detail: CompilerDiagnosticDetail): CompilerDiagnostic;
primaryLocation(): SourceLocation | null;
printErrorMessage(source: string, options: PrintErrorMessageOptions): string;
toString(): string;
}
declare class CompilerErrorDetail {

@@ -1513,8 +1655,11 @@ options: CompilerErrorDetailOptions;

get suggestions(): CompilerErrorDetailOptions['suggestions'];
printErrorMessage(): string;
primaryLocation(): SourceLocation | null;
printErrorMessage(source: string, options: PrintErrorMessageOptions): string;
toString(): string;
}
declare class CompilerError extends Error {
details: Array<CompilerErrorDetail>;
details: Array<CompilerErrorDetail | CompilerDiagnostic>;
printedMessage: string | null;
static invariant(condition: unknown, options: Omit<CompilerErrorDetailOptions, 'severity'>): asserts condition;
static throwDiagnostic(options: CompilerDiagnosticOptions): never;
static throwTodo(options: Omit<CompilerErrorDetailOptions, 'severity'>): never;

@@ -1529,2 +1674,6 @@ static throwInvalidJS(options: Omit<CompilerErrorDetailOptions, 'severity'>): never;

toString(): string;
withPrintedMessage(source: string, options: PrintErrorMessageOptions): CompilerError;
printErrorMessage(source: string, options: PrintErrorMessageOptions): string;
merge(other: CompilerError): void;
pushDiagnostic(diagnostic: CompilerDiagnostic): void;
push(options: CompilerErrorDetailOptions): CompilerErrorDetail;

@@ -1555,5 +1704,7 @@ pushErrorDetail(detail: CompilerErrorDetail): CompilerErrorDetail;

hasInferredEffect: boolean;
inferredEffectLocations: Set<SourceLocation>;
hasFireRewrite: boolean;
};
declare function printReactiveFunctionWithOutlined(fn: ReactiveFunction): string;
declare function printReactiveFunction(fn: ReactiveFunction): string;

@@ -1582,2 +1733,12 @@

type PanicThresholdOptions = z.infer<typeof PanicThresholdOptionsSchema>;
declare const DynamicGatingOptionsSchema: z.ZodObject<{
source: z.ZodString;
}, "strip", z.ZodTypeAny, {
source: string;
}, {
source: string;
}>;
type DynamicGatingOptions = z.infer<typeof DynamicGatingOptionsSchema>;
declare const CustomOptOutDirectiveSchema: z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>;
type CustomOptOutDirective = z.infer<typeof CustomOptOutDirectiveSchema>;
type PluginOptions = {

@@ -1587,9 +1748,11 @@ environment: EnvironmentConfig;

gating: ExternalFunction | null;
dynamicGating: DynamicGatingOptions | null;
panicThreshold: PanicThresholdOptions;
noEmit: boolean;
compilationMode: CompilationMode;
eslintSuppressionRules?: Array<string> | null | undefined;
eslintSuppressionRules: Array<string> | null | undefined;
flowSuppressions: boolean;
ignoreUseNoForget: boolean;
sources?: Array<string> | ((filename: string) => boolean) | null;
customOptOutDirectives: CustomOptOutDirective;
sources: Array<string> | ((filename: string) => boolean) | null;
enableReanimatedCheck: boolean;

@@ -1611,7 +1774,7 @@ target: CompilerReactTarget;

type CompilationMode = z.infer<typeof CompilationModeSchema>;
type LoggerEvent = CompileSuccessEvent | CompileErrorEvent | CompileDiagnosticEvent | CompileSkipEvent | PipelineErrorEvent | TimingEvent;
type LoggerEvent = CompileSuccessEvent | CompileErrorEvent | CompileDiagnosticEvent | CompileSkipEvent | PipelineErrorEvent | TimingEvent | AutoDepsDecorationsEvent | AutoDepsEligibleEvent;
type CompileErrorEvent = {
kind: 'CompileError';
fnLoc: t.SourceLocation | null;
detail: CompilerErrorDetailOptions;
detail: CompilerErrorDetail | CompilerDiagnostic;
};

@@ -1648,2 +1811,12 @@ type CompileDiagnosticEvent = {

};
type AutoDepsDecorationsEvent = {
kind: 'AutoDepsDecorations';
fnLoc: t.SourceLocation;
decorations: Array<t.SourceLocation>;
};
type AutoDepsEligibleEvent = {
kind: 'AutoDepsEligible';
fnLoc: t.SourceLocation;
depArrayLoc: t.SourceLocation;
};
type Logger = {

@@ -1655,18 +1828,2 @@ logEvent: (filename: string | null, event: LoggerEvent) => void;

declare class ProgramContext {
scope: Scope;
reactRuntimeModule: string;
hookPattern: string | null;
knownReferencedNames: Set<string>;
imports: Map<string, Map<string, NonLocalImportSpecifier>>;
constructor(program: NodePath$1<t.Program>, reactRuntimeModule: CompilerReactTarget, hookPattern: string | null);
isHookName(name: string): boolean;
hasReference(name: string): boolean;
newUid(name: string): string;
addMemoCacheImport(): NonLocalImportSpecifier;
addImportSpecifier({ source: module, importSpecifierName: specifier }: ExternalFunction, nameHint?: string): NonLocalImportSpecifier;
addNewReference(name: string): void;
assertGlobalBinding(name: string, localScope?: Scope): Result<void, CompilerError>;
}
type CompilerPass = {

@@ -1680,6 +1837,6 @@ opts: PluginOptions;

declare const OPT_OUT_DIRECTIVES: Set<string>;
declare function findDirectiveEnablingMemoization(directives: Array<t.Directive>): Array<t.Directive>;
declare function findDirectiveDisablingMemoization(directives: Array<t.Directive>): Array<t.Directive>;
declare function tryFindDirectiveEnablingMemoization(directives: Array<t.Directive>, opts: PluginOptions): Result<t.Directive | null, CompilerError>;
declare function findDirectiveDisablingMemoization(directives: Array<t.Directive>, { customOptOutDirectives }: PluginOptions): t.Directive | null;
type BabelFn = NodePath$1<t.FunctionDeclaration> | NodePath$1<t.FunctionExpression> | NodePath$1<t.ArrowFunctionExpression>;
type CompileProgramResult = {
type CompileProgramMetadata = {
retryErrors: Array<{

@@ -1689,7 +1846,55 @@ fn: BabelFn;

}>;
inferredEffectLocations: Set<t.SourceLocation>;
};
declare function compileProgram(program: NodePath$1<t.Program>, pass: CompilerPass): CompileProgramResult | null;
declare function compileProgram(program: NodePath$1<t.Program>, pass: CompilerPass): CompileProgramMetadata | null;
type SuppressionRange = {
disableComment: t.Comment;
enableComment: t.Comment | null;
source: SuppressionSource;
};
type SuppressionSource = 'Eslint' | 'Flow';
type ProgramContextOptions = {
program: NodePath$1<t.Program>;
suppressions: Array<SuppressionRange>;
opts: PluginOptions;
filename: string | null;
code: string | null;
hasModuleScopeOptOut: boolean;
};
declare class ProgramContext {
scope: Scope;
opts: PluginOptions;
filename: string | null;
code: string | null;
reactRuntimeModule: string;
suppressions: Array<SuppressionRange>;
hasModuleScopeOptOut: boolean;
alreadyCompiled: WeakSet<object> | Set<object>;
knownReferencedNames: Set<string>;
imports: Map<string, Map<string, NonLocalImportSpecifier>>;
retryErrors: Array<{
fn: BabelFn;
error: CompilerError;
}>;
inferredEffectLocations: Set<t.SourceLocation>;
constructor({ program, suppressions, opts, filename, code, hasModuleScopeOptOut, }: ProgramContextOptions);
isHookName(name: string): boolean;
hasReference(name: string): boolean;
newUid(name: string): string;
addMemoCacheImport(): NonLocalImportSpecifier;
addImportSpecifier({ source: module, importSpecifierName: specifier }: ExternalFunction, nameHint?: string): NonLocalImportSpecifier;
addNewReference(name: string): void;
assertGlobalBinding(name: string, localScope?: Scope): Result<void, CompilerError>;
logEvent(event: LoggerEvent): void;
}
declare function runBabelPluginReactCompiler(text: string, file: string, language: 'flow' | 'typescript', options: Partial<PluginOptions> | null, includeAst?: boolean): BabelCore.BabelFileResult;
declare function parseConfigPragmaForTests(pragma: string, defaults: {
compilationMode: CompilationMode;
environment?: PartialEnvironmentConfig;
}): PluginOptions;
declare function BabelPluginReactCompiler(_babel: typeof BabelCore): BabelCore.PluginObj;

@@ -1701,2 +1906,2 @@

export { CompilerError, CompilerErrorDetail, type CompilerErrorDetailOptions, type CompilerPipelineValue, CompilerSuggestionOperation, Effect, type EnvironmentConfig, ErrorSeverity, type ExternalFunction, type Hook, type Logger, type LoggerEvent, OPT_IN_DIRECTIVES, OPT_OUT_DIRECTIVES, type PluginOptions, ProgramContext, type SourceLocation, ValueKind, compileFn as compile, compileProgram, BabelPluginReactCompiler as default, findDirectiveDisablingMemoization, findDirectiveEnablingMemoization, parseConfigPragmaForTests, parsePluginOptions, printHIR, printReactiveFunction, runBabelPluginReactCompiler, validateEnvironmentConfig };
export { CompilerDiagnostic, type CompilerDiagnosticDetail, type CompilerDiagnosticOptions, CompilerError, CompilerErrorDetail, type CompilerErrorDetailOptions, type CompilerPipelineValue, CompilerSuggestionOperation, Effect, type EnvironmentConfig, ErrorSeverity, type ExternalFunction, type Hook, type Logger, type LoggerEvent, OPT_IN_DIRECTIVES, OPT_OUT_DIRECTIVES, type PluginOptions, ProgramContext, type SourceLocation, ValueKind, ValueReason, compileFn as compile, compileProgram, BabelPluginReactCompiler as default, findDirectiveDisablingMemoization, tryFindDirectiveEnablingMemoization as findDirectiveEnablingMemoization, parseConfigPragmaForTests, parsePluginOptions, printFunctionWithOutlined, printHIR, printReactiveFunction, printReactiveFunctionWithOutlined, runBabelPluginReactCompiler, validateEnvironmentConfig };

6

package.json
{
"name": "babel-plugin-react-compiler",
"version": "0.0.0-experimental-3cea1f4-20250324",
"version": "0.0.0-experimental-3edd82f-20250804",
"description": "Babel plugin for React Compiler.",

@@ -15,3 +15,3 @@ "main": "dist/index.js",

"jest": "yarn build && ts-node node_modules/.bin/jest",
"snap": "node ../snap/dist/main.js",
"snap": "yarn workspace snap run snap",
"snap:build": "yarn workspace snap run build",

@@ -21,3 +21,3 @@ "snap:ci": "yarn snap:build && yarn snap",

"lint": "yarn eslint src",
"watch": "yarn build --watch"
"watch": "yarn build --dts --watch"
},

@@ -24,0 +24,0 @@ "dependencies": {

Sorry, the diff of this file is too big to display