Add a noEmit compiler option
Defaults to false, ie it runs the codegen pass. When enabled it will simply run all passes up to codegen and then skip over it. Naming of this option is copied from [TypeScript](https://www.typescriptlang.org/tsconfig#noEmit) which has the same named option that makes the compiler only perform typechecking. I'm adding this option primarily to get around some issues running the eslint plugin on Meta code. The plugin would error because Forget would report duplicate Babel AST nodes, which I presume would only occur during codegen. It should also make it a tiny bit faster to not run codegen, which is a nice plus.
Lauren Tan committed
Jun 20, 2023 at 12:30 UTC
98633d10a6dd15e59269e9fe444329525c61707e
3 files changed
+14
compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Options.ts
+9
@@ -79,6 +79,14 @@ export type PluginOptions = {
79
panicOnBailout: boolean;
80
81
isDev: boolean;
82
+
83
+ /**
84
+ * When enabled, Forget will continue statically analyzing and linting code, but skip over codegen
85
+ * passes.
86
+ *
87
+ * Defaults to false
88
+ */
89
+ noEmit: boolean;
90
};
91
92
export type Logger = {
@@ -93,6 +101,7 @@ export const defaultOptions: PluginOptions = {
101
gating: null,
102
isDev: false,
103
instrumentForget: null,
104
+ noEmit: false,
105
} as const;
106
107
export function parsePluginOptions(obj: unknown): PluginOptions {
compiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Program.ts
+4
@@ -49,6 +49,10 @@ export function compileProgram(
49
): void {
50
try {
51
const compiled = compileFn(fn, pass.opts.environment);
52
+ if (pass.opts.noEmit === true) {
53
+ return;
54
+ }
55
+
56
if (fn.node.id == null) {
57
CompilerError.invariant(
58
"FunctionDeclaration must have a name",
compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts
+1
@@ -27,6 +27,7 @@ const rule: Rule.RuleModule = {
27
const filename = context.filename ?? context.getFilename();
28
29
const opts: Partial<PluginOptions> = {
30
+ noEmit: true,
31
enableOnlyOnUseForgetDirective: true,
32
panicOnBailout: false,
33
environment: {