babel-plugin-react-compiler 0.0.0-experimental-bc310bf-20250507 → 0.0.0-experimental-c134c19-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 +186 -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
|
}
|
@@ -97322,7 +97183,7 @@ function compileProgram(program, pass) {
|
|
97322
97183
|
handleError(restrictedImportsErr, pass, null);
|
97323
97184
|
return null;
|
97324
97185
|
}
|
97325
|
-
const programContext = new
|
97186
|
+
const programContext = new ProgramContext(
|
97326
97187
|
program,
|
97327
97188
|
pass.opts.target,
|
97328
97189
|
environment.hookPattern
|
@@ -97895,7 +97756,7 @@ function validateRestrictedImports(path, { validateBlocklistedImports }) {
|
|
97895
97756
|
return null;
|
97896
97757
|
}
|
97897
97758
|
}
|
97898
|
-
var
|
97759
|
+
var ProgramContext = class {
|
97899
97760
|
constructor(program, reactRuntimeModule, hookPattern) {
|
97900
97761
|
// known generated or referenced identifiers in the program
|
97901
97762
|
this.knownReferencedNames = /* @__PURE__ */ new Set();
|
@@ -98490,6 +98351,176 @@ function runBabelPluginReactCompiler(text, file, language, options, includeAst =
|
|
98490
98351
|
return result;
|
98491
98352
|
}
|
98492
98353
|
|
98354
|
+
// src/Utils/TestUtils.ts
|
98355
|
+
function tryParseTestPragmaValue(val) {
|
98356
|
+
try {
|
98357
|
+
let parsedVal;
|
98358
|
+
const stringMatch = /^"([^"]*)"$/.exec(val);
|
98359
|
+
if (stringMatch && stringMatch.length > 1) {
|
98360
|
+
parsedVal = stringMatch[1];
|
98361
|
+
} else {
|
98362
|
+
parsedVal = JSON.parse(val);
|
98363
|
+
}
|
98364
|
+
return Ok(parsedVal);
|
98365
|
+
} catch (e) {
|
98366
|
+
return Err(e);
|
98367
|
+
}
|
98368
|
+
}
|
98369
|
+
var testComplexConfigDefaults = {
|
98370
|
+
validateNoCapitalizedCalls: [],
|
98371
|
+
enableChangeDetectionForDebugging: {
|
98372
|
+
source: "react-compiler-runtime",
|
98373
|
+
importSpecifierName: "$structuralCheck"
|
98374
|
+
},
|
98375
|
+
enableEmitFreeze: {
|
98376
|
+
source: "react-compiler-runtime",
|
98377
|
+
importSpecifierName: "makeReadOnly"
|
98378
|
+
},
|
98379
|
+
enableEmitInstrumentForget: {
|
98380
|
+
fn: {
|
98381
|
+
source: "react-compiler-runtime",
|
98382
|
+
importSpecifierName: "useRenderCounter"
|
98383
|
+
},
|
98384
|
+
gating: {
|
98385
|
+
source: "react-compiler-runtime",
|
98386
|
+
importSpecifierName: "shouldInstrument"
|
98387
|
+
},
|
98388
|
+
globalGating: "DEV"
|
98389
|
+
},
|
98390
|
+
enableEmitHookGuards: {
|
98391
|
+
source: "react-compiler-runtime",
|
98392
|
+
importSpecifierName: "$dispatcherGuard"
|
98393
|
+
},
|
98394
|
+
inlineJsxTransform: {
|
98395
|
+
elementSymbol: "react.transitional.element",
|
98396
|
+
globalDevVar: "DEV"
|
98397
|
+
},
|
98398
|
+
lowerContextAccess: {
|
98399
|
+
source: "react-compiler-runtime",
|
98400
|
+
importSpecifierName: "useContext_withSelector"
|
98401
|
+
},
|
98402
|
+
inferEffectDependencies: [
|
98403
|
+
{
|
98404
|
+
function: {
|
98405
|
+
source: "react",
|
98406
|
+
importSpecifierName: "useEffect"
|
98407
|
+
},
|
98408
|
+
numRequiredArgs: 1
|
98409
|
+
},
|
98410
|
+
{
|
98411
|
+
function: {
|
98412
|
+
source: "shared-runtime",
|
98413
|
+
importSpecifierName: "useSpecialEffect"
|
98414
|
+
},
|
98415
|
+
numRequiredArgs: 2
|
98416
|
+
},
|
98417
|
+
{
|
98418
|
+
function: {
|
98419
|
+
source: "useEffectWrapper",
|
98420
|
+
importSpecifierName: "default"
|
98421
|
+
},
|
98422
|
+
numRequiredArgs: 1
|
98423
|
+
}
|
98424
|
+
]
|
98425
|
+
};
|
98426
|
+
function parseConfigPragmaEnvironmentForTest(pragma) {
|
98427
|
+
const maybeConfig = {};
|
98428
|
+
for (const token2 of pragma.split(" ")) {
|
98429
|
+
if (!token2.startsWith("@")) {
|
98430
|
+
continue;
|
98431
|
+
}
|
98432
|
+
const keyVal = token2.slice(1);
|
98433
|
+
const valIdx = keyVal.indexOf(":");
|
98434
|
+
const key2 = valIdx === -1 ? keyVal : keyVal.slice(0, valIdx);
|
98435
|
+
const val = valIdx === -1 ? void 0 : keyVal.slice(valIdx + 1);
|
98436
|
+
const isSet = val === void 0 || val === "true";
|
98437
|
+
if (!hasOwnProperty2(EnvironmentConfigSchema.shape, key2)) {
|
98438
|
+
continue;
|
98439
|
+
}
|
98440
|
+
if (isSet && key2 in testComplexConfigDefaults) {
|
98441
|
+
maybeConfig[key2] = testComplexConfigDefaults[key2];
|
98442
|
+
} else if (isSet) {
|
98443
|
+
maybeConfig[key2] = true;
|
98444
|
+
} else if (val === "false") {
|
98445
|
+
maybeConfig[key2] = false;
|
98446
|
+
} else if (val) {
|
98447
|
+
const parsedVal = tryParseTestPragmaValue(val).unwrap();
|
98448
|
+
if (key2 === "customMacros" && typeof parsedVal === "string") {
|
98449
|
+
const valSplit = parsedVal.split(".");
|
98450
|
+
const props = [];
|
98451
|
+
for (const elt of valSplit.slice(1)) {
|
98452
|
+
if (elt === "*") {
|
98453
|
+
props.push({ type: "wildcard" });
|
98454
|
+
} else if (elt.length > 0) {
|
98455
|
+
props.push({ type: "name", name: elt });
|
98456
|
+
}
|
98457
|
+
}
|
98458
|
+
maybeConfig[key2] = [[valSplit[0], props]];
|
98459
|
+
continue;
|
98460
|
+
}
|
98461
|
+
maybeConfig[key2] = parsedVal;
|
98462
|
+
}
|
98463
|
+
}
|
98464
|
+
const config = EnvironmentConfigSchema.safeParse(maybeConfig);
|
98465
|
+
if (config.success) {
|
98466
|
+
if (config.data.enableResetCacheOnSourceFileChanges == null) {
|
98467
|
+
config.data.enableResetCacheOnSourceFileChanges = false;
|
98468
|
+
}
|
98469
|
+
return config.data;
|
98470
|
+
}
|
98471
|
+
CompilerError.invariant(false, {
|
98472
|
+
reason: "Internal error, could not parse config from pragma string",
|
98473
|
+
description: `${fromZodError(config.error)}`,
|
98474
|
+
loc: null,
|
98475
|
+
suggestions: null
|
98476
|
+
});
|
98477
|
+
}
|
98478
|
+
var testComplexPluginOptionDefaults = {
|
98479
|
+
gating: {
|
98480
|
+
source: "ReactForgetFeatureFlag",
|
98481
|
+
importSpecifierName: "isForgetEnabled_Fixtures"
|
98482
|
+
}
|
98483
|
+
};
|
98484
|
+
function parseConfigPragmaForTests(pragma, defaults) {
|
98485
|
+
const environment = parseConfigPragmaEnvironmentForTest(pragma);
|
98486
|
+
const options = __spreadProps(__spreadValues({}, defaultOptions), {
|
98487
|
+
panicThreshold: "all_errors",
|
98488
|
+
compilationMode: defaults.compilationMode,
|
98489
|
+
environment
|
98490
|
+
});
|
98491
|
+
for (const token2 of pragma.split(" ")) {
|
98492
|
+
if (!token2.startsWith("@")) {
|
98493
|
+
continue;
|
98494
|
+
}
|
98495
|
+
const keyVal = token2.slice(1);
|
98496
|
+
const idx = keyVal.indexOf(":");
|
98497
|
+
const key2 = idx === -1 ? keyVal : keyVal.slice(0, idx);
|
98498
|
+
const val = idx === -1 ? void 0 : keyVal.slice(idx + 1);
|
98499
|
+
if (!hasOwnProperty2(defaultOptions, key2)) {
|
98500
|
+
continue;
|
98501
|
+
}
|
98502
|
+
const isSet = val === void 0 || val === "true";
|
98503
|
+
if (isSet && key2 in testComplexPluginOptionDefaults) {
|
98504
|
+
options[key2] = testComplexPluginOptionDefaults[key2];
|
98505
|
+
} else if (isSet) {
|
98506
|
+
options[key2] = true;
|
98507
|
+
} else if (val === "false") {
|
98508
|
+
options[key2] = false;
|
98509
|
+
} else if (val != null) {
|
98510
|
+
const parsedVal = tryParseTestPragmaValue(val).unwrap();
|
98511
|
+
if (key2 === "target" && parsedVal === "donotuse_meta_internal") {
|
98512
|
+
options[key2] = {
|
98513
|
+
kind: parsedVal,
|
98514
|
+
runtimeModule: "react"
|
98515
|
+
};
|
98516
|
+
} else {
|
98517
|
+
options[key2] = parsedVal;
|
98518
|
+
}
|
98519
|
+
}
|
98520
|
+
}
|
98521
|
+
return parsePluginOptions(options);
|
98522
|
+
}
|
98523
|
+
|
98493
98524
|
// src/index.ts
|
98494
98525
|
var index_default = BabelPluginReactCompiler;
|
98495
98526
|
// Annotate the CommonJS export names for ESM import in node:
|
package/package.json
CHANGED