babel-plugin-react-compiler
Advanced tools
Comparing version
@@ -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'; | ||
@@ -27,3 +27,3 @@ interface Result<T, E> { | ||
declare class OkImpl<T> implements Result<T, never> { | ||
private val; | ||
#private; | ||
constructor(val: T); | ||
@@ -48,3 +48,3 @@ map<U>(fn: (val: T) => U): Result<U, never>; | ||
declare class ErrImpl<E> implements Result<never, E> { | ||
private val; | ||
#private; | ||
constructor(val: E); | ||
@@ -69,2 +69,90 @@ map<U>(_fn: (val: never) => U): Result<U, E>; | ||
type AliasingEffect = { | ||
kind: 'Freeze'; | ||
value: Place; | ||
reason: ValueReason; | ||
} | { | ||
kind: 'Mutate'; | ||
value: Place; | ||
reason?: MutationReason | null; | ||
} | { | ||
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 MutationReason = { | ||
kind: 'AssignCurrentProperty'; | ||
}; | ||
type AliasingSignature = { | ||
receiver: IdentifierId; | ||
params: Array<IdentifierId>; | ||
rest: IdentifierId | null; | ||
returns: IdentifierId; | ||
effects: Array<AliasingEffect>; | ||
temporaries: Array<Place>; | ||
}; | ||
type BuiltInType = PrimitiveType | FunctionType | ObjectType; | ||
@@ -116,3 +204,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 = { | ||
@@ -129,3 +217,5 @@ positionalParams: Array<Effect>; | ||
impure?: boolean; | ||
knownIncompatible?: string | null | undefined; | ||
canonicalName?: string; | ||
aliasing?: AliasingSignature | null | undefined; | ||
}; | ||
@@ -135,2 +225,117 @@ | ||
type ResolvedType = { | ||
kind: 'Concrete'; | ||
type: ConcreteType<ResolvedType>; | ||
platform: Platform; | ||
}; | ||
type ComponentType<T> = { | ||
kind: 'Component'; | ||
props: Map<string, T>; | ||
children: null | T; | ||
}; | ||
type ConcreteType<T> = { | ||
kind: 'Enum'; | ||
} | { | ||
kind: 'Mixed'; | ||
} | { | ||
kind: 'Number'; | ||
} | { | ||
kind: 'String'; | ||
} | { | ||
kind: 'Boolean'; | ||
} | { | ||
kind: 'Void'; | ||
} | { | ||
kind: 'Nullable'; | ||
type: T; | ||
} | { | ||
kind: 'Array'; | ||
element: T; | ||
} | { | ||
kind: 'Set'; | ||
element: T; | ||
} | { | ||
kind: 'Map'; | ||
key: T; | ||
value: T; | ||
} | { | ||
kind: 'Function'; | ||
typeParameters: null | Array<TypeParameter<T>>; | ||
params: Array<T>; | ||
returnType: T; | ||
} | ComponentType<T> | { | ||
kind: 'Generic'; | ||
id: TypeParameterId; | ||
bound: T; | ||
} | { | ||
kind: 'Object'; | ||
id: NominalId; | ||
members: Map<string, ResolvedType>; | ||
} | { | ||
kind: 'Tuple'; | ||
id: NominalId; | ||
members: Array<T>; | ||
} | { | ||
kind: 'Structural'; | ||
id: LinearId; | ||
} | { | ||
kind: 'Union'; | ||
members: Array<T>; | ||
} | { | ||
kind: 'Instance'; | ||
name: string; | ||
members: Map<string, ResolvedType>; | ||
}; | ||
type TypeParameter<T> = { | ||
name: string; | ||
id: TypeParameterId; | ||
bound: T; | ||
}; | ||
declare const opaqueLinearId: unique symbol; | ||
type LinearId = number & { | ||
[opaqueLinearId]: 'LinearId'; | ||
}; | ||
declare const opaqueTypeParameterId: unique symbol; | ||
type TypeParameterId = number & { | ||
[opaqueTypeParameterId]: 'TypeParameterId'; | ||
}; | ||
declare const opaqueNominalId: unique symbol; | ||
type NominalId = number & { | ||
[opaqueNominalId]: 'NominalId'; | ||
}; | ||
type Platform = 'client' | 'server' | 'shared'; | ||
interface ITypeEnv { | ||
popGeneric(name: string): void; | ||
getGeneric(name: string): null | TypeParameter<ResolvedType>; | ||
pushGeneric(name: string, binding: { | ||
name: string; | ||
id: TypeParameterId; | ||
bound: ResolvedType; | ||
}): void; | ||
getType(id: Identifier): ResolvedType; | ||
getTypeOrNull(id: Identifier): ResolvedType | null; | ||
setType(id: Identifier, type: ResolvedType): void; | ||
nextNominalId(): NominalId; | ||
nextTypeParameterId(): TypeParameterId; | ||
moduleEnv: Map<string, ResolvedType>; | ||
addBinding(bindingIdentifier: t.Identifier, type: ResolvedType): void; | ||
resolveBinding(bindingIdentifier: t.Identifier): ResolvedType | null; | ||
} | ||
declare class FlowTypeEnv implements ITypeEnv { | ||
#private; | ||
moduleEnv: Map<string, ResolvedType>; | ||
init(env: Environment, source: string): void; | ||
setType(identifier: Identifier, type: ResolvedType): void; | ||
getType(identifier: Identifier): ResolvedType; | ||
getTypeOrNull(identifier: Identifier): ResolvedType | null; | ||
getTypeByLoc(loc: SourceLocation): ResolvedType | null; | ||
nextNominalId(): NominalId; | ||
nextTypeParameterId(): TypeParameterId; | ||
addBinding(bindingIdentifier: t.Identifier, type: ResolvedType): void; | ||
resolveBinding(bindingIdentifier: t.Identifier): ResolvedType | null; | ||
pushGeneric(name: string, generic: TypeParameter<ResolvedType>): void; | ||
popGeneric(name: string): void; | ||
getGeneric(name: string): null | TypeParameter<ResolvedType>; | ||
} | ||
declare const ExternalFunctionSchema: z.ZodObject<{ | ||
@@ -205,2 +410,3 @@ source: z.ZodString; | ||
enableUseTypeAnnotations: z.ZodDefault<z.ZodBoolean>; | ||
flowTypeProvider: z.ZodDefault<z.ZodNullable<z.ZodFunction<z.ZodTuple<[z.ZodString], z.ZodUnknown>, z.ZodUnknown>>>; | ||
enableOptionalDependencies: z.ZodDefault<z.ZodBoolean>; | ||
@@ -219,3 +425,3 @@ enableFire: z.ZodDefault<z.ZodBoolean>; | ||
}>; | ||
numRequiredArgs: z.ZodNumber; | ||
autodepsIndex: z.ZodNumber; | ||
}, "strip", z.ZodTypeAny, { | ||
@@ -226,3 +432,3 @@ function: { | ||
}; | ||
numRequiredArgs: number; | ||
autodepsIndex: number; | ||
}, { | ||
@@ -233,3 +439,3 @@ function: { | ||
}; | ||
numRequiredArgs: number; | ||
autodepsIndex: number; | ||
}>, "many">>>; | ||
@@ -249,3 +455,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>; | ||
@@ -257,2 +464,3 @@ validateStaticComponents: z.ZodDefault<z.ZodBoolean>; | ||
validateNoImpureFunctionsInRender: z.ZodDefault<z.ZodBoolean>; | ||
validateNoFreezingKnownMutableFunctions: z.ZodDefault<z.ZodBoolean>; | ||
enableAssumeHooksFollowRulesOfReact: z.ZodDefault<z.ZodBoolean>; | ||
@@ -375,2 +583,4 @@ enableTransitivelyFreezeFunctionExpressions: z.ZodDefault<z.ZodBoolean>; | ||
}>>>; | ||
validateNoVoidUseMemo: z.ZodDefault<z.ZodBoolean>; | ||
validateNoDynamicallyCreatedComponentsOrHooks: z.ZodDefault<z.ZodBoolean>; | ||
}, "strip", z.ZodTypeAny, { | ||
@@ -396,2 +606,3 @@ customHooks: Map<string, { | ||
enableUseTypeAnnotations: boolean; | ||
flowTypeProvider: ((args_0: string, ...args_1: unknown[]) => unknown) | null; | ||
enableOptionalDependencies: boolean; | ||
@@ -404,3 +615,3 @@ enableFire: boolean; | ||
}; | ||
numRequiredArgs: number; | ||
autodepsIndex: number; | ||
}[] | null; | ||
@@ -414,3 +625,4 @@ inlineJsxTransform: { | ||
validateNoSetStateInRender: boolean; | ||
validateNoSetStateInPassiveEffects: boolean; | ||
validateNoSetStateInEffects: boolean; | ||
validateNoDerivedComputationsInEffects: boolean; | ||
validateNoJSXInTryStatements: boolean; | ||
@@ -422,2 +634,3 @@ validateStaticComponents: boolean; | ||
validateNoImpureFunctionsInRender: boolean; | ||
validateNoFreezingKnownMutableFunctions: boolean; | ||
enableAssumeHooksFollowRulesOfReact: boolean; | ||
@@ -464,2 +677,4 @@ enableTransitivelyFreezeFunctionExpressions: boolean; | ||
} | null; | ||
validateNoVoidUseMemo: boolean; | ||
validateNoDynamicallyCreatedComponentsOrHooks: boolean; | ||
}, { | ||
@@ -485,2 +700,3 @@ customHooks?: Map<string, { | ||
enableUseTypeAnnotations?: boolean | undefined; | ||
flowTypeProvider?: ((args_0: string, ...args_1: unknown[]) => unknown) | null | undefined; | ||
enableOptionalDependencies?: boolean | undefined; | ||
@@ -493,3 +709,3 @@ enableFire?: boolean | undefined; | ||
}; | ||
numRequiredArgs: number; | ||
autodepsIndex: number; | ||
}[] | null | undefined; | ||
@@ -503,3 +719,4 @@ inlineJsxTransform?: { | ||
validateNoSetStateInRender?: boolean | undefined; | ||
validateNoSetStateInPassiveEffects?: boolean | undefined; | ||
validateNoSetStateInEffects?: boolean | undefined; | ||
validateNoDerivedComputationsInEffects?: boolean | undefined; | ||
validateNoJSXInTryStatements?: boolean | undefined; | ||
@@ -511,2 +728,3 @@ validateStaticComponents?: boolean | undefined; | ||
validateNoImpureFunctionsInRender?: boolean | undefined; | ||
validateNoFreezingKnownMutableFunctions?: boolean | undefined; | ||
enableAssumeHooksFollowRulesOfReact?: boolean | undefined; | ||
@@ -553,7 +771,6 @@ enableTransitivelyFreezeFunctionExpressions?: boolean | undefined; | ||
} | null | undefined; | ||
validateNoVoidUseMemo?: boolean | undefined; | ||
validateNoDynamicallyCreatedComponentsOrHooks?: boolean | undefined; | ||
}>; | ||
type EnvironmentConfig = z.infer<typeof EnvironmentConfigSchema>; | ||
declare function parseConfigPragmaForTests(pragma: string, defaults: { | ||
compilationMode: CompilationMode; | ||
}): PluginOptions; | ||
type PartialEnvironmentConfig = Partial<EnvironmentConfig>; | ||
@@ -572,3 +789,6 @@ 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 typeContext(): FlowTypeEnv; | ||
get isInferredMemoEnabled(): boolean; | ||
@@ -637,2 +857,3 @@ get nextIdentifierId(): IdentifierId; | ||
value: ReactiveValue; | ||
effects?: Array<AliasingEffect> | null; | ||
loc: SourceLocation; | ||
@@ -774,5 +995,4 @@ }; | ||
returnTypeAnnotation: t.FlowType | t.TSType | null; | ||
returnType: Type; | ||
returns: Place; | ||
context: Array<Place>; | ||
effects: Array<FunctionEffect> | null; | ||
body: HIR; | ||
@@ -782,15 +1002,4 @@ generator: boolean; | ||
directives: Array<string>; | ||
aliasingEffects: Array<AliasingEffect> | null; | ||
}; | ||
type FunctionEffect = { | ||
kind: 'GlobalMutation'; | ||
error: CompilerErrorDetailOptions; | ||
} | { | ||
kind: 'ReactMutation'; | ||
error: CompilerErrorDetailOptions; | ||
} | { | ||
kind: 'ContextMutation'; | ||
places: ReadonlySet<Place>; | ||
effect: Effect; | ||
loc: SourceLocation; | ||
}; | ||
type HIR = { | ||
@@ -833,4 +1042,6 @@ entry: BlockId; | ||
}; | ||
type ReturnVariant = 'Void' | 'Implicit' | 'Explicit'; | ||
type ReturnTerminal = { | ||
kind: 'return'; | ||
returnVariant: ReturnVariant; | ||
loc: SourceLocation; | ||
@@ -840,2 +1051,3 @@ value: Place; | ||
fallthrough?: never; | ||
effects: Array<AliasingEffect> | null; | ||
}; | ||
@@ -977,2 +1189,3 @@ type GotoTerminal = { | ||
fallthrough?: never; | ||
effects: Array<AliasingEffect> | null; | ||
}; | ||
@@ -1000,2 +1213,3 @@ type ReactiveScopeTerminal = { | ||
loc: SourceLocation; | ||
effects: Array<AliasingEffect> | null; | ||
}; | ||
@@ -1141,3 +1355,3 @@ type LValue = { | ||
lvalue: { | ||
kind: InstructionKind.Reassign; | ||
kind: InstructionKind.Reassign | InstructionKind.Const | InstructionKind.Let | InstructionKind.Function; | ||
place: Place; | ||
@@ -1162,9 +1376,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'; | ||
@@ -1388,2 +1607,5 @@ properties: Array<ObjectProperty | SpreadPattern>; | ||
JsxCaptured = "jsx-captured", | ||
HookCaptured = "hook-captured", | ||
HookReturn = "hook-return", | ||
Effect = "effect", | ||
KnownReturnSignature = "known-return-signature", | ||
@@ -1444,2 +1666,3 @@ Context = "context", | ||
identifier: Identifier; | ||
reactive: boolean; | ||
path: DependencyPath; | ||
@@ -1476,8 +1699,26 @@ }; | ||
InvalidJS = "InvalidJS", | ||
UnsupportedJS = "UnsupportedJS", | ||
InvalidReact = "InvalidReact", | ||
InvalidConfig = "InvalidConfig", | ||
CannotPreserveMemoization = "CannotPreserveMemoization", | ||
IncompatibleLibrary = "IncompatibleLibrary", | ||
Todo = "Todo", | ||
Invariant = "Invariant" | ||
} | ||
type CompilerDiagnosticOptions = { | ||
category: ErrorCategory; | ||
severity: ErrorSeverity; | ||
reason: string; | ||
description: string; | ||
details: Array<CompilerDiagnosticDetail>; | ||
suggestions?: Array<CompilerSuggestion> | null | undefined; | ||
}; | ||
type CompilerDiagnosticDetail = { | ||
kind: 'error'; | ||
loc: SourceLocation | null; | ||
message: string; | ||
} | { | ||
kind: 'hint'; | ||
message: string; | ||
}; | ||
declare enum CompilerSuggestionOperation { | ||
@@ -1500,8 +1741,26 @@ InsertBefore = 0, | ||
type CompilerErrorDetailOptions = { | ||
category: ErrorCategory; | ||
severity: ErrorSeverity; | ||
reason: string; | ||
description?: string | null | undefined; | ||
severity: ErrorSeverity; | ||
loc: SourceLocation | null; | ||
suggestions?: Array<CompilerSuggestion> | null | undefined; | ||
}; | ||
type PrintErrorMessageOptions = { | ||
eslint: boolean; | ||
}; | ||
declare class CompilerDiagnostic { | ||
options: CompilerDiagnosticOptions; | ||
constructor(options: CompilerDiagnosticOptions); | ||
static create(options: Omit<CompilerDiagnosticOptions, 'details'>): CompilerDiagnostic; | ||
get reason(): CompilerDiagnosticOptions['reason']; | ||
get description(): CompilerDiagnosticOptions['description']; | ||
get severity(): CompilerDiagnosticOptions['severity']; | ||
get suggestions(): CompilerDiagnosticOptions['suggestions']; | ||
get category(): ErrorCategory; | ||
withDetail(detail: CompilerDiagnosticDetail): CompilerDiagnostic; | ||
primaryLocation(): SourceLocation | null; | ||
printErrorMessage(source: string, options: PrintErrorMessageOptions): string; | ||
toString(): string; | ||
} | ||
declare class CompilerErrorDetail { | ||
@@ -1515,12 +1774,16 @@ options: CompilerErrorDetailOptions; | ||
get suggestions(): CompilerErrorDetailOptions['suggestions']; | ||
printErrorMessage(): string; | ||
get category(): ErrorCategory; | ||
primaryLocation(): SourceLocation | null; | ||
printErrorMessage(source: string, options: PrintErrorMessageOptions): string; | ||
toString(): string; | ||
} | ||
declare class CompilerError extends Error { | ||
details: Array<CompilerErrorDetail>; | ||
static invariant(condition: unknown, options: Omit<CompilerErrorDetailOptions, 'severity'>): asserts condition; | ||
static throwTodo(options: Omit<CompilerErrorDetailOptions, 'severity'>): never; | ||
static throwInvalidJS(options: Omit<CompilerErrorDetailOptions, 'severity'>): never; | ||
details: Array<CompilerErrorDetail | CompilerDiagnostic>; | ||
printedMessage: string | null; | ||
static invariant(condition: unknown, options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>): asserts condition; | ||
static throwDiagnostic(options: CompilerDiagnosticOptions): never; | ||
static throwTodo(options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>): never; | ||
static throwInvalidJS(options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>): never; | ||
static throwInvalidReact(options: Omit<CompilerErrorDetailOptions, 'severity'>): never; | ||
static throwInvalidConfig(options: Omit<CompilerErrorDetailOptions, 'severity'>): never; | ||
static throwInvalidConfig(options: Omit<CompilerErrorDetailOptions, 'severity' | 'category'>): never; | ||
static throw(options: CompilerErrorDetailOptions): never; | ||
@@ -1531,2 +1794,6 @@ constructor(...args: Array<any>); | ||
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; | ||
@@ -1538,2 +1805,37 @@ pushErrorDetail(detail: CompilerErrorDetail): CompilerErrorDetail; | ||
} | ||
declare enum ErrorCategory { | ||
Hooks = "Hooks", | ||
CapitalizedCalls = "CapitalizedCalls", | ||
StaticComponents = "StaticComponents", | ||
UseMemo = "UseMemo", | ||
Factories = "Factories", | ||
PreserveManualMemo = "PreserveManualMemo", | ||
IncompatibleLibrary = "IncompatibleLibrary", | ||
Immutability = "Immutability", | ||
Globals = "Globals", | ||
Refs = "Refs", | ||
EffectDependencies = "EffectDependencies", | ||
EffectSetState = "EffectSetState", | ||
EffectDerivationsOfState = "EffectDerivationsOfState", | ||
ErrorBoundaries = "ErrorBoundaries", | ||
Purity = "Purity", | ||
RenderSetState = "RenderSetState", | ||
Invariant = "Invariant", | ||
Todo = "Todo", | ||
Syntax = "Syntax", | ||
UnsupportedSyntax = "UnsupportedSyntax", | ||
Config = "Config", | ||
Gating = "Gating", | ||
Suppression = "Suppression", | ||
AutomaticEffectDependencies = "AutomaticEffectDependencies", | ||
Fire = "Fire", | ||
FBT = "FBT" | ||
} | ||
type LintRule = { | ||
category: ErrorCategory; | ||
name: string; | ||
description: string; | ||
recommended: boolean; | ||
}; | ||
declare const LintRules: Array<LintRule>; | ||
@@ -1558,2 +1860,3 @@ type CodegenFunction = { | ||
hasInferredEffect: boolean; | ||
inferredEffectLocations: Set<SourceLocation>; | ||
hasFireRewrite: boolean; | ||
@@ -1586,2 +1889,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 = { | ||
@@ -1591,9 +1904,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; | ||
@@ -1615,7 +1930,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; | ||
}; | ||
@@ -1652,2 +1967,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 = { | ||
@@ -1659,18 +1984,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 = { | ||
@@ -1684,6 +1993,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<{ | ||
@@ -1693,7 +2002,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; | ||
@@ -1705,2 +2062,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, printFunctionWithOutlined, printHIR, printReactiveFunction, printReactiveFunctionWithOutlined, runBabelPluginReactCompiler, validateEnvironmentConfig }; | ||
export { CompilerDiagnostic, type CompilerDiagnosticDetail, type CompilerDiagnosticOptions, CompilerError, CompilerErrorDetail, type CompilerErrorDetailOptions, type CompilerPipelineValue, CompilerSuggestionOperation, Effect, type EnvironmentConfig, ErrorSeverity, type ExternalFunction, type Hook, type LintRule, LintRules, 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 }; |
{ | ||
"name": "babel-plugin-react-compiler", | ||
"version": "0.0.0-experimental-84c28d9-20250326", | ||
"version": "0.0.0-experimental-87d6db6-20250904", | ||
"description": "Babel plugin for React Compiler.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is too big to display
99903
3679.91%3507542
-33.31%