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

Function transformFixtureInput

compiler/packages/snap/src/compiler.ts:215–369  ·  view source on GitHub ↗
(
  input: string,
  fixturePath: string,
  parseConfigPragmaFn: typeof ParseConfigPragma,
  plugin: BabelCore.PluginObj,
  includeEvaluator: boolean,
  debugIRLogger: (value: CompilerPipelineValue) => void,
  EffectEnum: typeof Effect,
  ValueKindEnum: typeof ValueKind,
  ValueReasonEnum: typeof ValueReason,
)

Source from the content-addressed store, hash-verified

213};
214
215export async function transformFixtureInput(
216 input: string,
217 fixturePath: string,
218 parseConfigPragmaFn: typeof ParseConfigPragma,
219 plugin: BabelCore.PluginObj,
220 includeEvaluator: boolean,
221 debugIRLogger: (value: CompilerPipelineValue) => void,
222 EffectEnum: typeof Effect,
223 ValueKindEnum: typeof ValueKind,
224 ValueReasonEnum: typeof ValueReason,
225): Promise<{kind: 'ok'; value: TransformResult} | {kind: 'err'; msg: string}> {
226 // Extract the first line to quickly check for custom test directives
227 const firstLine = input.substring(0, input.indexOf('\n'));
228
229 const language = parseLanguage(firstLine);
230 const sourceType = parseSourceType(firstLine);
231 // Preserve file extension as it determines typescript's babel transform
232 // mode (e.g. stripping types, parsing rules for brackets)
233 const filename =
234 path.basename(fixturePath) + (language === 'typescript' ? '.ts' : '');
235 const inputAst = parseInput(input, filename, language, sourceType);
236 // Give babel transforms an absolute path as relative paths get prefixed
237 // with `cwd`, which is different across machines
238 const virtualFilepath = '/' + filename;
239
240 const presets =
241 language === 'typescript'
242 ? TypescriptEvaluatorPresets
243 : FlowEvaluatorPresets;
244
245 /**
246 * Get Forget compiled code
247 */
248 const [options, logs] = makePluginOptions(
249 firstLine,
250 parseConfigPragmaFn,
251 debugIRLogger,
252 EffectEnum,
253 ValueKindEnum,
254 ValueReasonEnum,
255 );
256 const forgetResult = transformFromAstSync(inputAst, input, {
257 filename: virtualFilepath,
258 highlightCode: false,
259 retainLines: true,
260 compact: true,
261 plugins: [
262 [plugin, options],
263 'babel-plugin-fbt',
264 'babel-plugin-fbt-runtime',
265 'babel-plugin-idx',
266 ],
267 sourceType: 'module',
268 ast: includeEvaluator,
269 cloneInputAst: includeEvaluator,
270 configFile: false,
271 babelrc: false,
272 });

Callers 1

compileFunction · 0.90

Calls 9

isExpectErrorFunction · 0.90
parseLanguageFunction · 0.85
parseSourceTypeFunction · 0.85
makePluginOptionsFunction · 0.85
joinMethod · 0.80
parseInputFunction · 0.70
formatFunction · 0.70
hasMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected