Skip to content

Commit

Permalink
Fix: Code path analysis for class fields (fixes #14343)
Browse files Browse the repository at this point in the history
  • Loading branch information
nzakas committed Aug 6, 2021
1 parent f7b4a3f commit ace502f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
20 changes: 20 additions & 0 deletions tests/fixtures/code-path-analysis/class-field--conditional.js
@@ -0,0 +1,20 @@
/*expected
initial->s1_1->s1_2->s1_4;
s1_1->s1_3->s1_4->final;
*/

class x { a = b ? c : d }

/*DOT
digraph {
node[shape=box,style="rounded,filled",fillcolor=white];
initial[label="",shape=circle,style=filled,fillcolor=black,width=0.25,height=0.25];
final[label="",shape=doublecircle,style=filled,fillcolor=black,width=0.25,height=0.25];
s1_1[label="Program:enter\nClassDeclaration:enter\nIdentifier (x)\nClassBody:enter\nPropertyDefinition:enter\nIdentifier (a)\nConditionalExpression:enter\nIdentifier (b)"];
s1_2[label="Identifier (c)"];
s1_4[label="ConditionalExpression:exit\nPropertyDefinition:exit\nClassBody:exit\nClassDeclaration:exit\nProgram:exit"];
s1_3[label="Identifier (d)"];
initial->s1_1->s1_2->s1_4;
s1_1->s1_3->s1_4->final;
}
*/
20 changes: 20 additions & 0 deletions tests/fixtures/code-path-analysis/object-literal--conditional.js
@@ -0,0 +1,20 @@
/*expected
initial->s1_1->s1_2->s1_4;
s1_1->s1_3->s1_4->final;
*/

x = { a: b ? c : d }

/*DOT
digraph {
node[shape=box,style="rounded,filled",fillcolor=white];
initial[label="",shape=circle,style=filled,fillcolor=black,width=0.25,height=0.25];
final[label="",shape=doublecircle,style=filled,fillcolor=black,width=0.25,height=0.25];
s1_1[label="Program:enter\nExpressionStatement:enter\nAssignmentExpression:enter\nIdentifier (x)\nObjectExpression:enter\nProperty:enter\nIdentifier (a)\nConditionalExpression:enter\nIdentifier
(b)"];
s1_2[label="Identifier (c)"];
s1_4[label="ConditionalExpression:exit\nProperty:exit\nObjectExpression:exit\nAssignmentExpression:exit\nExpressionStatement:exit\nProgram:exit"];
s1_3[label="Identifier (d)"];
initial->s1_1->s1_2->s1_4;
s1_1->s1_3->s1_4->final;
}*/
4 changes: 2 additions & 2 deletions tests/lib/linter/code-path-analysis/code-path-analyzer.js
Expand Up @@ -561,11 +561,11 @@ describe("CodePathAnalyzer", () => {
}
}));
const messages = linter.verify(source, {
parserOptions: { ecmaVersion: 2021 },
parserOptions: { ecmaVersion: 2022 },
rules: { test: 2 }
});

assert.strictEqual(messages.length, 0);
assert.strictEqual(messages.length, 0, "Unexpected linting error in code.");
assert.strictEqual(actual.length, expected.length, "a count of code paths is wrong.");

for (let i = 0; i < actual.length; ++i) {
Expand Down

0 comments on commit ace502f

Please sign in to comment.