@samitouri / QOS-React-2 / commits / 46fa83d854

[eslint-plugin] Disambiguate compiler errors without instanceof

Babel re-emits errors from plugins so the `instanceof` check was no longer working

Lauren Tan committed Jun 20, 2023 at 12:30 UTC 46fa83d854c1332f45d1ba4b3cf11969023e4289
2 files changed +7 -2
compiler/forget/packages/babel-plugin-react-forget/src/CompilerError.ts
+1
@@ -182,6 +182,7 @@ export class CompilerError extends Error {
182
183 constructor(...args: any[]) {
184 super(...args);
185 + this.name = "ReactForgetCompilerError";
186 }
187
188 override get message(): string {
compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts
+6 -2
@@ -13,6 +13,10 @@ import ReactForgetBabelPlugin, {
13 import type { Rule } from "eslint";
14 import * as HermesParser from "hermes-parser";
15
16 +function isReactForgetCompilerError(err: Error): err is CompilerError {
17 + return err.name === "ReactForgetCompilerError";
18 +}
19 +
20 const rule: Rule.RuleModule = {
21 meta: {
22 type: "problem",
@@ -55,7 +59,7 @@ const rule: Rule.RuleModule = {
59 sourceType: "module",
60 });
61 } catch (err) {
58 - if (err instanceof CompilerError) {
62 + if (isReactForgetCompilerError(err) && Array.isArray(err.details)) {
63 for (const detail of err.details) {
64 if (detail.loc != null) {
65 context.report({
@@ -65,7 +69,7 @@ const rule: Rule.RuleModule = {
69 }
70 }
71 } else {
68 - throw new Error(err);
72 + throw err;
73 }
74 }
75 }