* 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, )
| 46 | * has test fixture specific (i.e. not applicable to playground) parsing logic. |
| 47 | */ |
| 48 | function 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 | |
| 102 | export function parseInput( |
| 103 | input: string, |
no test coverage detected