babel-plugin-react-compiler 0.0.0-experimental-bc310bf-20250507 → 0.0.0-experimental-ec81157-20250508
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 +6 -5
- package/dist/index.js +229 -155
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -532,9 +532,6 @@ declare const EnvironmentConfigSchema: z.ZodObject<{
|
|
532
532
|
} | null | undefined;
|
533
533
|
}>;
|
534
534
|
type EnvironmentConfig = z.infer<typeof EnvironmentConfigSchema>;
|
535
|
-
declare function parseConfigPragmaForTests(pragma: string, defaults: {
|
536
|
-
compilationMode: CompilationMode;
|
537
|
-
}): PluginOptions;
|
538
535
|
type PartialEnvironmentConfig = Partial<EnvironmentConfig>;
|
539
536
|
type ReactFunctionType = 'Component' | 'Hook' | 'Other';
|
540
537
|
declare class Environment {
|
@@ -1558,10 +1555,10 @@ type PluginOptions = {
|
|
1558
1555
|
panicThreshold: PanicThresholdOptions;
|
1559
1556
|
noEmit: boolean;
|
1560
1557
|
compilationMode: CompilationMode;
|
1561
|
-
eslintSuppressionRules
|
1558
|
+
eslintSuppressionRules: Array<string> | null | undefined;
|
1562
1559
|
flowSuppressions: boolean;
|
1563
1560
|
ignoreUseNoForget: boolean;
|
1564
|
-
sources
|
1561
|
+
sources: Array<string> | ((filename: string) => boolean) | null;
|
1565
1562
|
enableReanimatedCheck: boolean;
|
1566
1563
|
target: CompilerReactTarget;
|
1567
1564
|
};
|
@@ -1668,6 +1665,10 @@ declare function compileProgram(program: NodePath$1<t.Program>, pass: CompilerPa
|
|
1668
1665
|
|
1669
1666
|
declare function runBabelPluginReactCompiler(text: string, file: string, language: 'flow' | 'typescript', options: Partial<PluginOptions> | null, includeAst?: boolean): BabelCore.BabelFileResult;
|
1670
1667
|
|
1668
|
+
declare function parseConfigPragmaForTests(pragma: string, defaults: {
|
1669
|
+
compilationMode: CompilationMode;
|
1670
|
+
}): PluginOptions;
|
1671
|
+
|
1671
1672
|
declare function BabelPluginReactCompiler(_babel: typeof BabelCore): BabelCore.PluginObj;
|
1672
1673
|
|
1673
1674
|
declare global {
|
package/dist/index.js
CHANGED
@@ -63752,7 +63752,7 @@ __export(index_exports, {
|
|
63752
63752
|
ErrorSeverity: () => ErrorSeverity,
|
63753
63753
|
OPT_IN_DIRECTIVES: () => OPT_IN_DIRECTIVES,
|
63754
63754
|
OPT_OUT_DIRECTIVES: () => OPT_OUT_DIRECTIVES,
|
63755
|
-
ProgramContext: () =>
|
63755
|
+
ProgramContext: () => ProgramContext,
|
63756
63756
|
ValueKind: () => ValueKind,
|
63757
63757
|
compile: () => compileFn,
|
63758
63758
|
compileProgram: () => compileProgram,
|
@@ -78177,158 +78177,6 @@ var EnvironmentConfigSchema = z.object({
|
|
78177
78177
|
*/
|
78178
78178
|
lowerContextAccess: ExternalFunctionSchema.nullable().default(null)
|
78179
78179
|
});
|
78180
|
-
var testComplexConfigDefaults = {
|
78181
|
-
validateNoCapitalizedCalls: [],
|
78182
|
-
enableChangeDetectionForDebugging: {
|
78183
|
-
source: "react-compiler-runtime",
|
78184
|
-
importSpecifierName: "$structuralCheck"
|
78185
|
-
},
|
78186
|
-
enableEmitFreeze: {
|
78187
|
-
source: "react-compiler-runtime",
|
78188
|
-
importSpecifierName: "makeReadOnly"
|
78189
|
-
},
|
78190
|
-
enableEmitInstrumentForget: {
|
78191
|
-
fn: {
|
78192
|
-
source: "react-compiler-runtime",
|
78193
|
-
importSpecifierName: "useRenderCounter"
|
78194
|
-
},
|
78195
|
-
gating: {
|
78196
|
-
source: "react-compiler-runtime",
|
78197
|
-
importSpecifierName: "shouldInstrument"
|
78198
|
-
},
|
78199
|
-
globalGating: "DEV"
|
78200
|
-
},
|
78201
|
-
enableEmitHookGuards: {
|
78202
|
-
source: "react-compiler-runtime",
|
78203
|
-
importSpecifierName: "$dispatcherGuard"
|
78204
|
-
},
|
78205
|
-
inlineJsxTransform: {
|
78206
|
-
elementSymbol: "react.transitional.element",
|
78207
|
-
globalDevVar: "DEV"
|
78208
|
-
},
|
78209
|
-
lowerContextAccess: {
|
78210
|
-
source: "react-compiler-runtime",
|
78211
|
-
importSpecifierName: "useContext_withSelector"
|
78212
|
-
},
|
78213
|
-
inferEffectDependencies: [
|
78214
|
-
{
|
78215
|
-
function: {
|
78216
|
-
source: "react",
|
78217
|
-
importSpecifierName: "useEffect"
|
78218
|
-
},
|
78219
|
-
numRequiredArgs: 1
|
78220
|
-
},
|
78221
|
-
{
|
78222
|
-
function: {
|
78223
|
-
source: "shared-runtime",
|
78224
|
-
importSpecifierName: "useSpecialEffect"
|
78225
|
-
},
|
78226
|
-
numRequiredArgs: 2
|
78227
|
-
},
|
78228
|
-
{
|
78229
|
-
function: {
|
78230
|
-
source: "useEffectWrapper",
|
78231
|
-
importSpecifierName: "default"
|
78232
|
-
},
|
78233
|
-
numRequiredArgs: 1
|
78234
|
-
}
|
78235
|
-
]
|
78236
|
-
};
|
78237
|
-
function parseConfigPragmaEnvironmentForTest(pragma) {
|
78238
|
-
const maybeConfig = {};
|
78239
|
-
const defaultConfig = EnvironmentConfigSchema.parse({});
|
78240
|
-
for (const token2 of pragma.split(" ")) {
|
78241
|
-
if (!token2.startsWith("@")) {
|
78242
|
-
continue;
|
78243
|
-
}
|
78244
|
-
const keyVal = token2.slice(1);
|
78245
|
-
let [key2, val = void 0] = keyVal.split(":");
|
78246
|
-
const isSet = val === void 0 || val === "true";
|
78247
|
-
if (isSet && key2 in testComplexConfigDefaults) {
|
78248
|
-
maybeConfig[key2] = testComplexConfigDefaults[key2];
|
78249
|
-
continue;
|
78250
|
-
}
|
78251
|
-
if (key2 === "customMacros" && val) {
|
78252
|
-
const valSplit = val.split(".");
|
78253
|
-
if (valSplit.length > 0) {
|
78254
|
-
const props = [];
|
78255
|
-
for (const elt of valSplit.slice(1)) {
|
78256
|
-
if (elt === "*") {
|
78257
|
-
props.push({ type: "wildcard" });
|
78258
|
-
} else if (elt.length > 0) {
|
78259
|
-
props.push({ type: "name", name: elt });
|
78260
|
-
}
|
78261
|
-
}
|
78262
|
-
maybeConfig[key2] = [[valSplit[0], props]];
|
78263
|
-
}
|
78264
|
-
continue;
|
78265
|
-
}
|
78266
|
-
if (key2 !== "enableResetCacheOnSourceFileChanges" && typeof defaultConfig[key2] !== "boolean") {
|
78267
|
-
continue;
|
78268
|
-
}
|
78269
|
-
if (val === void 0 || val === "true") {
|
78270
|
-
maybeConfig[key2] = true;
|
78271
|
-
} else {
|
78272
|
-
maybeConfig[key2] = false;
|
78273
|
-
}
|
78274
|
-
}
|
78275
|
-
const config = EnvironmentConfigSchema.safeParse(maybeConfig);
|
78276
|
-
if (config.success) {
|
78277
|
-
if (config.data.enableResetCacheOnSourceFileChanges == null) {
|
78278
|
-
config.data.enableResetCacheOnSourceFileChanges = false;
|
78279
|
-
}
|
78280
|
-
return config.data;
|
78281
|
-
}
|
78282
|
-
CompilerError.invariant(false, {
|
78283
|
-
reason: "Internal error, could not parse config from pragma string",
|
78284
|
-
description: `${fromZodError(config.error)}`,
|
78285
|
-
loc: null,
|
78286
|
-
suggestions: null
|
78287
|
-
});
|
78288
|
-
}
|
78289
|
-
function parseConfigPragmaForTests(pragma, defaults) {
|
78290
|
-
const environment = parseConfigPragmaEnvironmentForTest(pragma);
|
78291
|
-
let compilationMode = defaults.compilationMode;
|
78292
|
-
let panicThreshold = "all_errors";
|
78293
|
-
let noEmit = defaultOptions.noEmit;
|
78294
|
-
for (const token2 of pragma.split(" ")) {
|
78295
|
-
if (!token2.startsWith("@")) {
|
78296
|
-
continue;
|
78297
|
-
}
|
78298
|
-
switch (token2) {
|
78299
|
-
case "@compilationMode(annotation)": {
|
78300
|
-
compilationMode = "annotation";
|
78301
|
-
break;
|
78302
|
-
}
|
78303
|
-
case "@compilationMode(infer)": {
|
78304
|
-
compilationMode = "infer";
|
78305
|
-
break;
|
78306
|
-
}
|
78307
|
-
case "@compilationMode(all)": {
|
78308
|
-
compilationMode = "all";
|
78309
|
-
break;
|
78310
|
-
}
|
78311
|
-
case "@compilationMode(syntax)": {
|
78312
|
-
compilationMode = "syntax";
|
78313
|
-
break;
|
78314
|
-
}
|
78315
|
-
case "@panicThreshold(none)": {
|
78316
|
-
panicThreshold = "none";
|
78317
|
-
break;
|
78318
|
-
}
|
78319
|
-
case "@noEmit": {
|
78320
|
-
noEmit = true;
|
78321
|
-
break;
|
78322
|
-
}
|
78323
|
-
}
|
78324
|
-
}
|
78325
|
-
return parsePluginOptions({
|
78326
|
-
environment,
|
78327
|
-
compilationMode,
|
78328
|
-
panicThreshold,
|
78329
|
-
noEmit
|
78330
|
-
});
|
78331
|
-
}
|
78332
78180
|
var _globals, _shapes, _moduleTypes, _nextIdentifer, _nextBlock, _nextScope, _scope, _outlinedFunctions, _contextIdentifiers, _hoistedIdentifiers, _Environment_instances, resolveModuleType_fn, isKnownReactModule_fn, getCustomHookType_fn;
|
78333
78181
|
var Environment = class {
|
78334
78182
|
constructor(scope, fnType, compilerMode, config, contextIdentifiers, logger, filename, code, programContext) {
|
@@ -80141,6 +79989,19 @@ function evaluateInstruction(constants, instr) {
|
|
80141
79989
|
}
|
80142
79990
|
return null;
|
80143
79991
|
}
|
79992
|
+
case "-": {
|
79993
|
+
const operand = read2(constants, value.value);
|
79994
|
+
if (operand !== null && operand.kind === "Primitive" && typeof operand.value === "number") {
|
79995
|
+
const result = {
|
79996
|
+
kind: "Primitive",
|
79997
|
+
value: operand.value * -1,
|
79998
|
+
loc: value.loc
|
79999
|
+
};
|
80000
|
+
instr.value = result;
|
80001
|
+
return result;
|
80002
|
+
}
|
80003
|
+
return null;
|
80004
|
+
}
|
80144
80005
|
default:
|
80145
80006
|
return null;
|
80146
80007
|
}
|
@@ -80297,6 +80158,49 @@ function evaluateInstruction(constants, instr) {
|
|
80297
80158
|
}
|
80298
80159
|
return null;
|
80299
80160
|
}
|
80161
|
+
case "TemplateLiteral": {
|
80162
|
+
if (value.subexprs.length === 0) {
|
80163
|
+
const result2 = {
|
80164
|
+
kind: "Primitive",
|
80165
|
+
value: value.quasis.map((q) => q.cooked).join(""),
|
80166
|
+
loc: value.loc
|
80167
|
+
};
|
80168
|
+
instr.value = result2;
|
80169
|
+
return result2;
|
80170
|
+
}
|
80171
|
+
if (value.subexprs.length !== value.quasis.length - 1) {
|
80172
|
+
return null;
|
80173
|
+
}
|
80174
|
+
if (value.quasis.some((q) => q.cooked === void 0)) {
|
80175
|
+
return null;
|
80176
|
+
}
|
80177
|
+
let quasiIndex = 0;
|
80178
|
+
let resultString = value.quasis[quasiIndex].cooked;
|
80179
|
+
++quasiIndex;
|
80180
|
+
for (const subExpr of value.subexprs) {
|
80181
|
+
const subExprValue = read2(constants, subExpr);
|
80182
|
+
if (!subExprValue || subExprValue.kind !== "Primitive") {
|
80183
|
+
return null;
|
80184
|
+
}
|
80185
|
+
const expressionValue = subExprValue.value;
|
80186
|
+
if (typeof expressionValue !== "number" && typeof expressionValue !== "string" && typeof expressionValue !== "boolean" && !(typeof expressionValue === "object" && expressionValue === null)) {
|
80187
|
+
return null;
|
80188
|
+
}
|
80189
|
+
const suffix = value.quasis[quasiIndex].cooked;
|
80190
|
+
++quasiIndex;
|
80191
|
+
if (suffix === void 0) {
|
80192
|
+
return null;
|
80193
|
+
}
|
80194
|
+
resultString = resultString.concat(expressionValue, suffix);
|
80195
|
+
}
|
80196
|
+
const result = {
|
80197
|
+
kind: "Primitive",
|
80198
|
+
value: resultString,
|
80199
|
+
loc: value.loc
|
80200
|
+
};
|
80201
|
+
instr.value = result;
|
80202
|
+
return result;
|
80203
|
+
}
|
80300
80204
|
case "LoadLocal": {
|
80301
80205
|
const placeValue = read2(constants, value.place);
|
80302
80206
|
if (placeValue !== null) {
|
@@ -97322,7 +97226,7 @@ function compileProgram(program, pass) {
|
|
97322
97226
|
handleError(restrictedImportsErr, pass, null);
|
97323
97227
|
return null;
|
97324
97228
|
}
|
97325
|
-
const programContext = new
|
97229
|
+
const programContext = new ProgramContext(
|
97326
97230
|
program,
|
97327
97231
|
pass.opts.target,
|
97328
97232
|
environment.hookPattern
|
@@ -97895,7 +97799,7 @@ function validateRestrictedImports(path, { validateBlocklistedImports }) {
|
|
97895
97799
|
return null;
|
97896
97800
|
}
|
97897
97801
|
}
|
97898
|
-
var
|
97802
|
+
var ProgramContext = class {
|
97899
97803
|
constructor(program, reactRuntimeModule, hookPattern) {
|
97900
97804
|
// known generated or referenced identifiers in the program
|
97901
97805
|
this.knownReferencedNames = /* @__PURE__ */ new Set();
|
@@ -98490,6 +98394,176 @@ function runBabelPluginReactCompiler(text, file, language, options, includeAst =
|
|
98490
98394
|
return result;
|
98491
98395
|
}
|
98492
98396
|
|
98397
|
+
// src/Utils/TestUtils.ts
|
98398
|
+
function tryParseTestPragmaValue(val) {
|
98399
|
+
try {
|
98400
|
+
let parsedVal;
|
98401
|
+
const stringMatch = /^"([^"]*)"$/.exec(val);
|
98402
|
+
if (stringMatch && stringMatch.length > 1) {
|
98403
|
+
parsedVal = stringMatch[1];
|
98404
|
+
} else {
|
98405
|
+
parsedVal = JSON.parse(val);
|
98406
|
+
}
|
98407
|
+
return Ok(parsedVal);
|
98408
|
+
} catch (e) {
|
98409
|
+
return Err(e);
|
98410
|
+
}
|
98411
|
+
}
|
98412
|
+
var testComplexConfigDefaults = {
|
98413
|
+
validateNoCapitalizedCalls: [],
|
98414
|
+
enableChangeDetectionForDebugging: {
|
98415
|
+
source: "react-compiler-runtime",
|
98416
|
+
importSpecifierName: "$structuralCheck"
|
98417
|
+
},
|
98418
|
+
enableEmitFreeze: {
|
98419
|
+
source: "react-compiler-runtime",
|
98420
|
+
importSpecifierName: "makeReadOnly"
|
98421
|
+
},
|
98422
|
+
enableEmitInstrumentForget: {
|
98423
|
+
fn: {
|
98424
|
+
source: "react-compiler-runtime",
|
98425
|
+
importSpecifierName: "useRenderCounter"
|
98426
|
+
},
|
98427
|
+
gating: {
|
98428
|
+
source: "react-compiler-runtime",
|
98429
|
+
importSpecifierName: "shouldInstrument"
|
98430
|
+
},
|
98431
|
+
globalGating: "DEV"
|
98432
|
+
},
|
98433
|
+
enableEmitHookGuards: {
|
98434
|
+
source: "react-compiler-runtime",
|
98435
|
+
importSpecifierName: "$dispatcherGuard"
|
98436
|
+
},
|
98437
|
+
inlineJsxTransform: {
|
98438
|
+
elementSymbol: "react.transitional.element",
|
98439
|
+
globalDevVar: "DEV"
|
98440
|
+
},
|
98441
|
+
lowerContextAccess: {
|
98442
|
+
source: "react-compiler-runtime",
|
98443
|
+
importSpecifierName: "useContext_withSelector"
|
98444
|
+
},
|
98445
|
+
inferEffectDependencies: [
|
98446
|
+
{
|
98447
|
+
function: {
|
98448
|
+
source: "react",
|
98449
|
+
importSpecifierName: "useEffect"
|
98450
|
+
},
|
98451
|
+
numRequiredArgs: 1
|
98452
|
+
},
|
98453
|
+
{
|
98454
|
+
function: {
|
98455
|
+
source: "shared-runtime",
|
98456
|
+
importSpecifierName: "useSpecialEffect"
|
98457
|
+
},
|
98458
|
+
numRequiredArgs: 2
|
98459
|
+
},
|
98460
|
+
{
|
98461
|
+
function: {
|
98462
|
+
source: "useEffectWrapper",
|
98463
|
+
importSpecifierName: "default"
|
98464
|
+
},
|
98465
|
+
numRequiredArgs: 1
|
98466
|
+
}
|
98467
|
+
]
|
98468
|
+
};
|
98469
|
+
function parseConfigPragmaEnvironmentForTest(pragma) {
|
98470
|
+
const maybeConfig = {};
|
98471
|
+
for (const token2 of pragma.split(" ")) {
|
98472
|
+
if (!token2.startsWith("@")) {
|
98473
|
+
continue;
|
98474
|
+
}
|
98475
|
+
const keyVal = token2.slice(1);
|
98476
|
+
const valIdx = keyVal.indexOf(":");
|
98477
|
+
const key2 = valIdx === -1 ? keyVal : keyVal.slice(0, valIdx);
|
98478
|
+
const val = valIdx === -1 ? void 0 : keyVal.slice(valIdx + 1);
|
98479
|
+
const isSet = val === void 0 || val === "true";
|
98480
|
+
if (!hasOwnProperty2(EnvironmentConfigSchema.shape, key2)) {
|
98481
|
+
continue;
|
98482
|
+
}
|
98483
|
+
if (isSet && key2 in testComplexConfigDefaults) {
|
98484
|
+
maybeConfig[key2] = testComplexConfigDefaults[key2];
|
98485
|
+
} else if (isSet) {
|
98486
|
+
maybeConfig[key2] = true;
|
98487
|
+
} else if (val === "false") {
|
98488
|
+
maybeConfig[key2] = false;
|
98489
|
+
} else if (val) {
|
98490
|
+
const parsedVal = tryParseTestPragmaValue(val).unwrap();
|
98491
|
+
if (key2 === "customMacros" && typeof parsedVal === "string") {
|
98492
|
+
const valSplit = parsedVal.split(".");
|
98493
|
+
const props = [];
|
98494
|
+
for (const elt of valSplit.slice(1)) {
|
98495
|
+
if (elt === "*") {
|
98496
|
+
props.push({ type: "wildcard" });
|
98497
|
+
} else if (elt.length > 0) {
|
98498
|
+
props.push({ type: "name", name: elt });
|
98499
|
+
}
|
98500
|
+
}
|
98501
|
+
maybeConfig[key2] = [[valSplit[0], props]];
|
98502
|
+
continue;
|
98503
|
+
}
|
98504
|
+
maybeConfig[key2] = parsedVal;
|
98505
|
+
}
|
98506
|
+
}
|
98507
|
+
const config = EnvironmentConfigSchema.safeParse(maybeConfig);
|
98508
|
+
if (config.success) {
|
98509
|
+
if (config.data.enableResetCacheOnSourceFileChanges == null) {
|
98510
|
+
config.data.enableResetCacheOnSourceFileChanges = false;
|
98511
|
+
}
|
98512
|
+
return config.data;
|
98513
|
+
}
|
98514
|
+
CompilerError.invariant(false, {
|
98515
|
+
reason: "Internal error, could not parse config from pragma string",
|
98516
|
+
description: `${fromZodError(config.error)}`,
|
98517
|
+
loc: null,
|
98518
|
+
suggestions: null
|
98519
|
+
});
|
98520
|
+
}
|
98521
|
+
var testComplexPluginOptionDefaults = {
|
98522
|
+
gating: {
|
98523
|
+
source: "ReactForgetFeatureFlag",
|
98524
|
+
importSpecifierName: "isForgetEnabled_Fixtures"
|
98525
|
+
}
|
98526
|
+
};
|
98527
|
+
function parseConfigPragmaForTests(pragma, defaults) {
|
98528
|
+
const environment = parseConfigPragmaEnvironmentForTest(pragma);
|
98529
|
+
const options = __spreadProps(__spreadValues({}, defaultOptions), {
|
98530
|
+
panicThreshold: "all_errors",
|
98531
|
+
compilationMode: defaults.compilationMode,
|
98532
|
+
environment
|
98533
|
+
});
|
98534
|
+
for (const token2 of pragma.split(" ")) {
|
98535
|
+
if (!token2.startsWith("@")) {
|
98536
|
+
continue;
|
98537
|
+
}
|
98538
|
+
const keyVal = token2.slice(1);
|
98539
|
+
const idx = keyVal.indexOf(":");
|
98540
|
+
const key2 = idx === -1 ? keyVal : keyVal.slice(0, idx);
|
98541
|
+
const val = idx === -1 ? void 0 : keyVal.slice(idx + 1);
|
98542
|
+
if (!hasOwnProperty2(defaultOptions, key2)) {
|
98543
|
+
continue;
|
98544
|
+
}
|
98545
|
+
const isSet = val === void 0 || val === "true";
|
98546
|
+
if (isSet && key2 in testComplexPluginOptionDefaults) {
|
98547
|
+
options[key2] = testComplexPluginOptionDefaults[key2];
|
98548
|
+
} else if (isSet) {
|
98549
|
+
options[key2] = true;
|
98550
|
+
} else if (val === "false") {
|
98551
|
+
options[key2] = false;
|
98552
|
+
} else if (val != null) {
|
98553
|
+
const parsedVal = tryParseTestPragmaValue(val).unwrap();
|
98554
|
+
if (key2 === "target" && parsedVal === "donotuse_meta_internal") {
|
98555
|
+
options[key2] = {
|
98556
|
+
kind: parsedVal,
|
98557
|
+
runtimeModule: "react"
|
98558
|
+
};
|
98559
|
+
} else {
|
98560
|
+
options[key2] = parsedVal;
|
98561
|
+
}
|
98562
|
+
}
|
98563
|
+
}
|
98564
|
+
return parsePluginOptions(options);
|
98565
|
+
}
|
98566
|
+
|
98493
98567
|
// src/index.ts
|
98494
98568
|
var index_default = BabelPluginReactCompiler;
|
98495
98569
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED