[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.
This commit is contained in:
Lauren Tan
2023-06-15 14:57:07 -04:00
parent 87a39e1995
commit 0fdb1e5ac7
2 changed files with 25 additions and 4 deletions
@@ -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,
},
],
},
],
@@ -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 ?? [],
});