babel-plugin-react-compiler 0.0.0-experimental-84c28d9-20250326 → 0.0.0-experimental-b6140c1-20250328
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 +11 -3
- package/dist/index.js +53 -14
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -545,6 +545,7 @@ declare class Environment {
|
|
545
545
|
programContext: ProgramContext;
|
546
546
|
hasFireRewrite: boolean;
|
547
547
|
hasInferredEffect: boolean;
|
548
|
+
inferredEffectLocations: Set<SourceLocation>;
|
548
549
|
constructor(scope: Scope, fnType: ReactFunctionType, compilerMode: CompilerMode, config: EnvironmentConfig, contextIdentifiers: Set<t.Identifier>, logger: Logger | null, filename: string | null, code: string | null, programContext: ProgramContext);
|
549
550
|
get isInferredMemoEnabled(): boolean;
|
550
551
|
get nextIdentifierId(): IdentifierId;
|
@@ -1126,13 +1127,18 @@ type InstructionValue = LoadLocal | LoadContext | {
|
|
1126
1127
|
operator: Exclude<t.UnaryExpression['operator'], 'throw' | 'delete'>;
|
1127
1128
|
value: Place;
|
1128
1129
|
loc: SourceLocation;
|
1129
|
-
} | {
|
1130
|
+
} | ({
|
1130
1131
|
kind: 'TypeCastExpression';
|
1131
1132
|
value: Place;
|
1132
|
-
typeAnnotation: t.FlowType | t.TSType;
|
1133
1133
|
type: Type;
|
1134
1134
|
loc: SourceLocation;
|
1135
|
-
}
|
1135
|
+
} & ({
|
1136
|
+
typeAnnotation: t.FlowType;
|
1137
|
+
typeAnnotationKind: 'cast';
|
1138
|
+
} | {
|
1139
|
+
typeAnnotation: t.TSType;
|
1140
|
+
typeAnnotationKind: 'as' | 'satisfies';
|
1141
|
+
})) | JsxExpression | {
|
1136
1142
|
kind: 'ObjectExpression';
|
1137
1143
|
properties: Array<ObjectProperty | SpreadPattern>;
|
1138
1144
|
loc: SourceLocation;
|
@@ -1514,6 +1520,7 @@ type CodegenFunction = {
|
|
1514
1520
|
type: ReactFunctionType | null;
|
1515
1521
|
}>;
|
1516
1522
|
hasInferredEffect: boolean;
|
1523
|
+
inferredEffectLocations: Set<SourceLocation>;
|
1517
1524
|
hasFireRewrite: boolean;
|
1518
1525
|
};
|
1519
1526
|
|
@@ -1642,6 +1649,7 @@ type CompileProgramResult = {
|
|
1642
1649
|
fn: BabelFn;
|
1643
1650
|
error: CompilerError;
|
1644
1651
|
}>;
|
1652
|
+
inferredEffectLocations: Set<t.SourceLocation>;
|
1645
1653
|
};
|
1646
1654
|
declare function compileProgram(program: NodePath$1<t.Program>, pass: CompilerPass): CompileProgramResult | null;
|
1647
1655
|
|
package/dist/index.js
CHANGED
@@ -121017,6 +121017,19 @@ function lowerExpression(builder, exprPath) {
|
|
121017
121017
|
kind: "TypeCastExpression",
|
121018
121018
|
value: lowerExpressionToTemporary(builder, expr.get("expression")),
|
121019
121019
|
typeAnnotation: typeAnnotation2.node,
|
121020
|
+
typeAnnotationKind: "cast",
|
121021
|
+
type: lowerType(typeAnnotation2.node),
|
121022
|
+
loc: exprLoc
|
121023
|
+
};
|
121024
|
+
}
|
121025
|
+
case "TSSatisfiesExpression": {
|
121026
|
+
let expr = exprPath;
|
121027
|
+
const typeAnnotation2 = expr.get("typeAnnotation");
|
121028
|
+
return {
|
121029
|
+
kind: "TypeCastExpression",
|
121030
|
+
value: lowerExpressionToTemporary(builder, expr.get("expression")),
|
121031
|
+
typeAnnotation: typeAnnotation2.node,
|
121032
|
+
typeAnnotationKind: "satisfies",
|
121020
121033
|
type: lowerType(typeAnnotation2.node),
|
121021
121034
|
loc: exprLoc
|
121022
121035
|
};
|
@@ -121028,6 +121041,7 @@ function lowerExpression(builder, exprPath) {
|
|
121028
121041
|
kind: "TypeCastExpression",
|
121029
121042
|
value: lowerExpressionToTemporary(builder, expr.get("expression")),
|
121030
121043
|
typeAnnotation: typeAnnotation2.node,
|
121044
|
+
typeAnnotationKind: "as",
|
121031
121045
|
type: lowerType(typeAnnotation2.node),
|
121032
121046
|
loc: exprLoc
|
121033
121047
|
};
|
@@ -124436,6 +124450,7 @@ function parseConfigPragmaForTests(pragma, defaults) {
|
|
124436
124450
|
const environment = parseConfigPragmaEnvironmentForTest(pragma);
|
124437
124451
|
let compilationMode = defaults.compilationMode;
|
124438
124452
|
let panicThreshold = "all_errors";
|
124453
|
+
let noEmit = defaultOptions.noEmit;
|
124439
124454
|
for (const token2 of pragma.split(" ")) {
|
124440
124455
|
if (!token2.startsWith("@")) {
|
124441
124456
|
continue;
|
@@ -124461,12 +124476,17 @@ function parseConfigPragmaForTests(pragma, defaults) {
|
|
124461
124476
|
panicThreshold = "none";
|
124462
124477
|
break;
|
124463
124478
|
}
|
124479
|
+
case "@noEmit": {
|
124480
|
+
noEmit = true;
|
124481
|
+
break;
|
124482
|
+
}
|
124464
124483
|
}
|
124465
124484
|
}
|
124466
124485
|
return parsePluginOptions({
|
124467
124486
|
environment,
|
124468
124487
|
compilationMode,
|
124469
|
-
panicThreshold
|
124488
|
+
panicThreshold,
|
124489
|
+
noEmit
|
124470
124490
|
});
|
124471
124491
|
}
|
124472
124492
|
var _globals, _shapes, _moduleTypes, _nextIdentifer, _nextBlock, _nextScope, _scope, _outlinedFunctions, _contextIdentifiers, _hoistedIdentifiers, _Environment_instances, resolveModuleType_fn, isKnownReactModule_fn, getCustomHookType_fn;
|
@@ -124481,6 +124501,7 @@ var Environment = class {
|
|
124481
124501
|
__privateAdd(this, _nextScope, 0);
|
124482
124502
|
__privateAdd(this, _scope);
|
124483
124503
|
__privateAdd(this, _outlinedFunctions, []);
|
124504
|
+
this.inferredEffectLocations = /* @__PURE__ */ new Set();
|
124484
124505
|
__privateAdd(this, _contextIdentifiers);
|
124485
124506
|
__privateAdd(this, _hoistedIdentifiers);
|
124486
124507
|
__privateSet(this, _scope, scope);
|
@@ -129609,7 +129630,8 @@ function codegenReactiveFunction(cx, fn) {
|
|
129609
129630
|
prunedMemoValues: countMemoBlockVisitor.prunedMemoValues,
|
129610
129631
|
outlined: [],
|
129611
129632
|
hasFireRewrite: fn.env.hasFireRewrite,
|
129612
|
-
hasInferredEffect: fn.env.hasInferredEffect
|
129633
|
+
hasInferredEffect: fn.env.hasInferredEffect,
|
129634
|
+
inferredEffectLocations: fn.env.inferredEffectLocations
|
129613
129635
|
});
|
129614
129636
|
}
|
129615
129637
|
var CountMemoBlockVisitor = class extends ReactiveFunctionVisitor {
|
@@ -131098,10 +131120,17 @@ function codegenInstructionValue(cx, instrValue) {
|
|
131098
131120
|
}
|
131099
131121
|
case "TypeCastExpression": {
|
131100
131122
|
if (t3.isTSType(instrValue.typeAnnotation)) {
|
131101
|
-
|
131102
|
-
|
131103
|
-
|
131104
|
-
|
131123
|
+
if (instrValue.typeAnnotationKind === "satisfies") {
|
131124
|
+
value = t3.tsSatisfiesExpression(
|
131125
|
+
codegenPlaceToExpression(cx, instrValue.value),
|
131126
|
+
instrValue.typeAnnotation
|
131127
|
+
);
|
131128
|
+
} else {
|
131129
|
+
value = t3.tsAsExpression(
|
131130
|
+
codegenPlaceToExpression(cx, instrValue.value),
|
131131
|
+
instrValue.typeAnnotation
|
131132
|
+
);
|
131133
|
+
}
|
131105
131134
|
} else {
|
131106
131135
|
value = t3.typeCastExpression(
|
131107
131136
|
codegenPlaceToExpression(cx, instrValue.value),
|
@@ -136477,6 +136506,7 @@ function inferEffectDependencies(fn) {
|
|
136477
136506
|
});
|
136478
136507
|
value.args.push(__spreadProps(__spreadValues({}, depsPlace), { effect: "freeze" /* Freeze */ }));
|
136479
136508
|
rewriteInstrs.set(instr.id, newInstructions);
|
136509
|
+
fn.env.inferredEffectLocations.add(callee.loc);
|
136480
136510
|
} else if (loadGlobals.has(value.args[0].identifier.id)) {
|
136481
136511
|
newInstructions.push({
|
136482
136512
|
id: makeInstructionId(0),
|
@@ -136486,6 +136516,7 @@ function inferEffectDependencies(fn) {
|
|
136486
136516
|
});
|
136487
136517
|
value.args.push(__spreadProps(__spreadValues({}, depsPlace), { effect: "freeze" /* Freeze */ }));
|
136488
136518
|
rewriteInstrs.set(instr.id, newInstructions);
|
136519
|
+
fn.env.inferredEffectLocations.add(callee.loc);
|
136489
136520
|
}
|
136490
136521
|
}
|
136491
136522
|
}
|
@@ -143047,6 +143078,7 @@ function compileProgram(program, pass) {
|
|
143047
143078
|
})
|
143048
143079
|
);
|
143049
143080
|
const retryErrors = [];
|
143081
|
+
const inferredEffectLocations = /* @__PURE__ */ new Set();
|
143050
143082
|
const processFn = (fn, fnType) => {
|
143051
143083
|
var _a2, _b2, _c, _d, _e, _f, _g, _h, _i;
|
143052
143084
|
let optInDirectives = [];
|
@@ -143150,6 +143182,9 @@ function compileProgram(program, pass) {
|
|
143150
143182
|
if (!pass.opts.noEmit) {
|
143151
143183
|
return compileResult.compiledFn;
|
143152
143184
|
}
|
143185
|
+
for (const loc of compileResult.compiledFn.inferredEffectLocations) {
|
143186
|
+
if (loc !== GeneratedSource) inferredEffectLocations.add(loc);
|
143187
|
+
}
|
143153
143188
|
return null;
|
143154
143189
|
};
|
143155
143190
|
while (queue.length !== 0) {
|
@@ -143213,7 +143248,7 @@ function compileProgram(program, pass) {
|
|
143213
143248
|
if (compiledFns.length > 0) {
|
143214
143249
|
addImportsToProgram(program, programContext);
|
143215
143250
|
}
|
143216
|
-
return { retryErrors };
|
143251
|
+
return { retryErrors, inferredEffectLocations };
|
143217
143252
|
}
|
143218
143253
|
function shouldSkipCompilation(program, pass) {
|
143219
143254
|
if (pass.opts.sources) {
|
@@ -143907,7 +143942,9 @@ function assertValidEffectImportReference(numArgs, paths, context) {
|
|
143907
143942
|
const parent = path.parentPath;
|
143908
143943
|
if (parent != null && parent.isCallExpression()) {
|
143909
143944
|
const args = parent.get("arguments");
|
143910
|
-
|
143945
|
+
const maybeCalleeLoc = path.node.loc;
|
143946
|
+
const hasInferredEffect = maybeCalleeLoc != null && context.inferredEffectLocations.has(maybeCalleeLoc);
|
143947
|
+
if (args.length === numArgs && !hasInferredEffect) {
|
143911
143948
|
const maybeErrorDiagnostic = matchCompilerDiagnostic(
|
143912
143949
|
path,
|
143913
143950
|
context.transformErrors
|
@@ -143941,7 +143978,7 @@ function assertValidFireImportReference(paths, context) {
|
|
143941
143978
|
);
|
143942
143979
|
}
|
143943
143980
|
}
|
143944
|
-
function validateNoUntransformedReferences(path, filename, logger, env,
|
143981
|
+
function validateNoUntransformedReferences(path, filename, logger, env, compileResult) {
|
143945
143982
|
const moduleLoadChecks = /* @__PURE__ */ new Map();
|
143946
143983
|
if (env.enableFire) {
|
143947
143984
|
for (const module2 of Environment.knownReactModules) {
|
@@ -143962,7 +143999,7 @@ function validateNoUntransformedReferences(path, filename, logger, env, transfor
|
|
143962
143999
|
}
|
143963
144000
|
}
|
143964
144001
|
if (moduleLoadChecks.size > 0) {
|
143965
|
-
transformProgram(path, moduleLoadChecks, filename, logger,
|
144002
|
+
transformProgram(path, moduleLoadChecks, filename, logger, compileResult);
|
143966
144003
|
}
|
143967
144004
|
}
|
143968
144005
|
function validateImportSpecifier(specifier, importSpecifierChecks, state) {
|
@@ -144020,13 +144057,15 @@ function validateNamespacedImport(specifier, importSpecifierChecks, state) {
|
|
144020
144057
|
checkFn(references, state);
|
144021
144058
|
}
|
144022
144059
|
}
|
144023
|
-
function transformProgram(path, moduleLoadChecks, filename, logger,
|
144060
|
+
function transformProgram(path, moduleLoadChecks, filename, logger, compileResult) {
|
144061
|
+
var _a, _b;
|
144024
144062
|
const traversalState = {
|
144025
144063
|
shouldInvalidateScopes: true,
|
144026
144064
|
program: path,
|
144027
144065
|
filename,
|
144028
144066
|
logger,
|
144029
|
-
transformErrors
|
144067
|
+
transformErrors: (_a = compileResult == null ? void 0 : compileResult.retryErrors) != null ? _a : [],
|
144068
|
+
inferredEffectLocations: (_b = compileResult == null ? void 0 : compileResult.inferredEffectLocations) != null ? _b : /* @__PURE__ */ new Set()
|
144030
144069
|
};
|
144031
144070
|
path.traverse({
|
144032
144071
|
ImportDeclaration(path2) {
|
@@ -144077,7 +144116,7 @@ function BabelPluginReactCompiler(_babel) {
|
|
144077
144116
|
*/
|
144078
144117
|
Program: {
|
144079
144118
|
enter(prog, pass) {
|
144080
|
-
var _a, _b, _c, _d
|
144119
|
+
var _a, _b, _c, _d;
|
144081
144120
|
const filename = (_a = pass.filename) != null ? _a : "unknown";
|
144082
144121
|
if (ENABLE_REACT_COMPILER_TIMINGS === true) {
|
144083
144122
|
performance.mark(`${filename}:start`, {
|
@@ -144107,7 +144146,7 @@ function BabelPluginReactCompiler(_babel) {
|
|
144107
144146
|
(_d = pass.filename) != null ? _d : null,
|
144108
144147
|
opts.logger,
|
144109
144148
|
opts.environment,
|
144110
|
-
|
144149
|
+
result
|
144111
144150
|
);
|
144112
144151
|
if (ENABLE_REACT_COMPILER_TIMINGS === true) {
|
144113
144152
|
performance.mark(`${filename}:end`, {
|
package/package.json
CHANGED