diff --git a/compiler/forget/packages/eslint-plugin-react-forget/__tests__/ReactForgetDiagnostics-test.ts b/compiler/forget/packages/eslint-plugin-react-forget/__tests__/ReactForgetDiagnostics-test.ts index a0001469f4..2f4b73cb10 100644 --- a/compiler/forget/packages/eslint-plugin-react-forget/__tests__/ReactForgetDiagnostics-test.ts +++ b/compiler/forget/packages/eslint-plugin-react-forget/__tests__/ReactForgetDiagnostics-test.ts @@ -12,7 +12,12 @@ function normalizeIndent(strings: TemplateStringsArray): string { return codeLines.map((line) => line.slice(leftPadding.length)).join("\n"); } -const tests = { +type ForgetTestCases = { + valid: ESLintTester.ValidTestCase[]; + invalid: ESLintTester.InvalidTestCase[]; +}; + +const tests: ForgetTestCases = { valid: [ { name: "Basic example", @@ -26,7 +31,20 @@ const tests = { `, }, ], - invalid: [], + invalid: [ + { + name: "Unsupported syntax", + code: normalizeIndent` + function foo(x) { + var y = 1; + return y * x; + } + `, + errors: [ + "[ReactForget] Todo: (BuildHIR::lowerStatement) Handle var kinds in VariableDeclaration (3:3)", + ], + }, + ], }; const eslintTester = new ESLintTester({ diff --git a/compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts b/compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts index ff1ef90cf2..ef8e570d0f 100644 --- a/compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts +++ b/compiler/forget/packages/eslint-plugin-react-forget/src/rules/ReactForgetDiagnostics.ts @@ -7,7 +7,11 @@ import * as parser from "@babel/parser"; import traverse from "@babel/traverse"; -import { compileProgram, parsePluginOptions } from "babel-plugin-react-forget"; +import { + CompilerError, + compileProgram, + parsePluginOptions, +} from "babel-plugin-react-forget"; import type { Rule } from "eslint"; const rule: Rule.RuleModule = { @@ -23,11 +27,24 @@ const rule: Rule.RuleModule = { if (babelAST != null) { traverse(babelAST, { Program(prog) { - compileProgram(prog, { - opts: parsePluginOptions(null), // use defaults for now - filename: context.filename, - comments: babelAST.comments ?? [], - }); + try { + compileProgram(prog, { + opts: parsePluginOptions(null), // use defaults for now + filename: context.filename, + comments: babelAST.comments ?? [], + }); + } catch (err) { + if (err instanceof CompilerError) { + for (const detail of err.details) { + if (detail.loc != null) { + context.report({ + message: detail.toString(), + loc: detail.loc, + }); + } + } + } + } }, }); }