Files
react/compiler/forget/src/PassManager.ts
T
Lauren Tan e939cacf97 Don't console.error in dev
Previously the PassManager would console.error if an unexpected error was 
thrown, to help with debugging jest. However because we now capture all 
invariants in compiler passes as bailouts, these are already captured in fixture 
tests. 

Additionally, we also already console.error if we find an unexpected bailout in 
a fixture test. So this is purely redundant and removing reduces some noise when 
running tests.
2022-10-14 12:10:58 -04:00

56 lines
1.4 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type { NodePath } from "@babel/traverse";
import type { Program } from "@babel/types";
import { CompilerContext } from "./CompilerContext";
import { Pass, PassName, runPass } from "./Pass";
export class PassManager {
program: NodePath<Program>;
context: CompilerContext;
passes: Pass[];
constructor(program: NodePath<Program>, context: CompilerContext) {
this.program = program;
this.context = context;
this.passes = [];
}
addPass(pass: Pass) {
this.passes.push(pass);
}
runAll() {
let hasMutatedBabelAST = false;
for (const pass of this.passes) {
if (pass.mutatesBabelAST) {
hasMutatedBabelAST = true;
}
if (pass.name === PassName.JSGen && this.context.hasBailedOut()) {
break;
}
try {
runPass(pass, this.program, this.context);
} catch (e) {
this.context.bailoutWithoutDiagnostic(`UnexpectedError: ${e}`);
if (hasMutatedBabelAST) {
// The AST has been mutated, we can't bail out anymore.
throw e;
} else {
this.context.logger.error(e.toString());
return;
}
}
// check if this is the stopPass
if (pass.name === this.context.opts.stopPass) {
break;
}
}
}
}