Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Code path analysis for class fields (fixes #14343) #14886

Merged
merged 8 commits into from Aug 26, 2021
Merged
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;
}
*/
nzakas marked this conversation as resolved.
Show resolved Hide resolved
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