MCPcopy Index your code
hub / github.com/react/react / makePluginOptions

Function makePluginOptions

compiler/packages/snap/src/compiler.ts:48–100  ·  view source on GitHub ↗

* Parse react compiler plugin + environment options from test fixture. Note * that although this primarily uses `Environment:parseConfigPragma`, it also * has test fixture specific (i.e. not applicable to playground) parsing logic.

(
  firstLine: string,
  parseConfigPragmaFn: typeof ParseConfigPragma,
  debugIRLogger: (value: CompilerPipelineValue) => void,
  EffectEnum: typeof Effect,
  ValueKindEnum: typeof ValueKind,
  ValueReasonEnum: typeof ValueReason,
)

Source from the content-addressed store, hash-verified

46 * has test fixture specific (i.e. not applicable to playground) parsing logic.
47 */
48function makePluginOptions(
49 firstLine: string,
50 parseConfigPragmaFn: typeof ParseConfigPragma,
51 debugIRLogger: (value: CompilerPipelineValue) => void,
52 EffectEnum: typeof Effect,
53 ValueKindEnum: typeof ValueKind,
54 ValueReasonEnum: typeof ValueReason,
55): [PluginOptions, Array<{filename: string | null; event: LoggerEvent}>] {
56 // TODO(@mofeiZ) rewrite snap fixtures to @validatePreserveExistingMemo:false
57 let validatePreserveExistingMemoizationGuarantees = false;
58 let target: CompilerReactTarget = '19';
59
60 /**
61 * Snap currently runs all fixtures without `validatePreserveExistingMemo` as
62 * most fixtures are interested in compilation output, not whether the
63 * compiler was able to preserve existing memo.
64 *
65 * TODO: flip the default. `useMemo` is rare in test fixtures -- fixtures that
66 * use useMemo should be explicit about whether this flag is enabled
67 */
68 if (firstLine.includes('@validatePreserveExistingMemoizationGuarantees')) {
69 validatePreserveExistingMemoizationGuarantees = true;
70 }
71
72 const logs: Array<{filename: string | null; event: LoggerEvent}> = [];
73 const logger: Logger = {
74 logEvent: firstLine.includes('@loggerTestOnly')
75 ? (filename, event) => {
76 logs.push({filename, event});
77 }
78 : () => {},
79 debugLogIRs: debugIRLogger,
80 };
81
82 const config = parseConfigPragmaFn(firstLine, {compilationMode: 'all'});
83 const options = {
84 ...config,
85 environment: {
86 ...config.environment,
87 moduleTypeProvider: makeSharedRuntimeTypeProvider({
88 EffectEnum,
89 ValueKindEnum,
90 ValueReasonEnum,
91 }),
92 assertValidMutableRanges: true,
93 validatePreserveExistingMemoizationGuarantees,
94 },
95 logger,
96 enableReanimatedCheck: false,
97 target,
98 };
99 return [options, logs];
100}
101
102export function parseInput(
103 input: string,

Callers 1

transformFixtureInputFunction · 0.85

Calls 2

pushMethod · 0.65

Tested by

no test coverage detected