From 0fdb1e5ac74e46ad4302c31a4334f7dd8dc8765f Mon Sep 17 00:00:00 2001 From: Lauren Tan Date: Thu, 15 Jun 2023 14:57:07 -0400 Subject: [PATCH] [eslint-plugin] Add test for invariants Turning off this flag makes only critical errors throw, so TODO errors will no longer be surfaced by the plugin. The previously failing test for unsupported syntax is now valid. --- .../__tests__/ReactForgetDiagnostics-test.ts | 27 ++++++++++++++++--- .../src/rules/ReactForgetDiagnostics.ts | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) 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 2f4b73cb10..cac6559e29 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 @@ -30,8 +30,6 @@ const tests: ForgetTestCases = { } `, }, - ], - invalid: [ { name: "Unsupported syntax", code: normalizeIndent` @@ -40,8 +38,31 @@ const tests: ForgetTestCases = { return y * x; } `, + }, + ], + invalid: [ + { + name: "[Invariant] Defined after use", + code: normalizeIndent` + function Component(props) { + let y = function () { + m(x); + }; + + let x = { a }; + m(x); + return y; + } + `, errors: [ - "[ReactForget] Todo: (BuildHIR::lowerStatement) Handle var kinds in VariableDeclaration (3:3)", + { + message: + "[ReactForget] Invariant: EnterSSA: Expected identifier to be defined before being used. Identifier x$2 is undefined (7:7)", + line: 7, + column: 3, + endColumn: 17, + endLine: 7, + }, ], }, ], 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 a3bf506f86..a0007379c2 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 @@ -34,7 +34,7 @@ const rule: Rule.RuleModule = { Program(prog) { try { compileProgram(prog, { - opts: parsePluginOptions(null), // use defaults for now + opts: parsePluginOptions({ panicOnBailout: false }), filename: context.filename, comments: babelAST.comments ?? [], });