mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[babel] Add isDev flag and put logging behind it
This commit is contained in:
@@ -124,6 +124,7 @@ export async function compile(
|
||||
logger: null,
|
||||
gating,
|
||||
panicOnBailout,
|
||||
isDev: true,
|
||||
}).code;
|
||||
} catch (e) {
|
||||
error = e;
|
||||
|
||||
@@ -109,7 +109,9 @@ export default function ReactForgetBabelPlugin(
|
||||
) {
|
||||
throw err;
|
||||
} else {
|
||||
console.log(formatErrorsForConsole(err, pass.filename ?? null));
|
||||
if (pass.opts.isDev) {
|
||||
log(err, pass.filename ?? null);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
// We are generating a new FunctionDeclaration node, so we must skip over it or this
|
||||
@@ -150,7 +152,9 @@ export default function ReactForgetBabelPlugin(
|
||||
if (options.panicOnBailout || error.isCritical()) {
|
||||
throw error;
|
||||
} else {
|
||||
console.log(formatErrorsForConsole(error, pass.filename));
|
||||
if (pass.opts.isDev) {
|
||||
log(error, pass.filename);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -219,7 +223,9 @@ export default function ReactForgetBabelPlugin(
|
||||
if (options.panicOnBailout || error.isCritical()) {
|
||||
throw error;
|
||||
} else {
|
||||
console.log(formatErrorsForConsole(error, pass.filename ?? null));
|
||||
if (options.isDev) {
|
||||
log(error, pass.filename ?? null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -329,17 +335,16 @@ function shouldCompile(
|
||||
return true;
|
||||
}
|
||||
|
||||
function formatErrorsForConsole(
|
||||
error: CompilerError,
|
||||
filename: string | null
|
||||
): string {
|
||||
function log(error: CompilerError, filename: string | null): void {
|
||||
const filenameStr = filename ? `in ${filename}` : "";
|
||||
return error.details
|
||||
.map(
|
||||
(e) =>
|
||||
`[ReactForget] Skipping compilation of component ${filenameStr}: ${e.printErrorMessage()}`
|
||||
)
|
||||
.join("\n");
|
||||
console.log(
|
||||
error.details
|
||||
.map(
|
||||
(e) =>
|
||||
`[ReactForget] Skipping compilation of component ${filenameStr}: ${e.printErrorMessage()}`
|
||||
)
|
||||
.join("\n")
|
||||
);
|
||||
}
|
||||
|
||||
function makeError(
|
||||
|
||||
@@ -51,6 +51,8 @@ export type PluginOptions = {
|
||||
gating: GatingOptions | null;
|
||||
|
||||
panicOnBailout: boolean;
|
||||
|
||||
isDev: boolean;
|
||||
};
|
||||
|
||||
export type Logger = {
|
||||
@@ -63,6 +65,7 @@ export const defaultOptions: PluginOptions = {
|
||||
environment: null,
|
||||
logger: null,
|
||||
gating: null,
|
||||
isDev: false,
|
||||
} as const;
|
||||
|
||||
export function parsePluginOptions(obj: unknown): PluginOptions {
|
||||
|
||||
@@ -63,6 +63,7 @@ describe("React Forget", () => {
|
||||
logger: null,
|
||||
gating: options.gating,
|
||||
panicOnBailout: options.panicOnBailout,
|
||||
isDev: true,
|
||||
}).code,
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
@@ -141,6 +141,7 @@ export default function generateTestsFromFixtures(
|
||||
gating,
|
||||
language: parseLanguage(input),
|
||||
panicOnBailout,
|
||||
isDev: true,
|
||||
});
|
||||
} else {
|
||||
receivedOutput = "<<input deleted>>";
|
||||
|
||||
Reference in New Issue
Block a user