Files
eslint/tests/fixtures/code-path-analysis/try-catch-finally-identifier-reference.js
72b0a4e98f fix: false positive for reference in finally block (#20655)
* fix: ref in finally block

* resumption of CallExpression path in catch block

* fix CI errors

* update paths for other expressions

* update id reference path in catch and add tests

* merge try and catch function and ad test

* Update lib/linter/code-path-analysis/code-path-state.js

Co-authored-by: Francesco Trotta <[email protected]>

* update function name

---------

Co-authored-by: Francesco Trotta <[email protected]>
2026-05-22 14:32:50 +02:00

42 lines
1.9 KiB
JavaScript

/*expected
initial->s1_1->s1_2->s1_3->s1_4->s1_6;
s1_1->s1_3;
s1_2->s1_6;
s1_3->s1_7;
s1_4->s1_7;
s1_6->final;
s1_7->thrown;
*/
let foo;
try {
foo = "Hello";
} catch (err) {
foo = "World";
} finally {
console.log("Done");
}
/*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];
thrown[label="✘",shape=circle,width=0.3,height=0.3,fixedsize=true];
s1_1[label="Program:enter\nVariableDeclaration:enter\nVariableDeclarator:enter\nIdentifier (foo)\nVariableDeclarator:exit\nVariableDeclaration:exit\nTryStatement:enter\nBlockStatement:enter\nExpressionStatement:enter\nAssignmentExpression:enter\nIdentifier (foo)"];
s1_2[label="Literal (Hello)\nAssignmentExpression:exit\nExpressionStatement:exit\nBlockStatement:exit"];
s1_3[label="CatchClause:enter\nIdentifier (err)\nBlockStatement:enter\nExpressionStatement:enter\nAssignmentExpression:enter\nIdentifier (foo)"];
s1_4[label="Literal (World)\nAssignmentExpression:exit\nExpressionStatement:exit\nBlockStatement:exit\nCatchClause:exit"];
s1_6[label="BlockStatement:enter\nExpressionStatement:enter\nCallExpression:enter\nMemberExpression:enter\nIdentifier (console)\nIdentifier (log)\nMemberExpression:exit\nLiteral (Done)\nCallExpression:exit\nExpressionStatement:exit\nBlockStatement:exit\nTryStatement:exit\nProgram:exit"];
s1_7[label="BlockStatement:enter\nExpressionStatement:enter\nCallExpression:enter\nMemberExpression:enter\nIdentifier (console)\nIdentifier (log)\nMemberExpression:exit\nLiteral (Done)\nCallExpression:exit\nExpressionStatement:exit\nBlockStatement:exit"];
initial->s1_1->s1_2->s1_3->s1_4->s1_6;
s1_1->s1_3;
s1_2->s1_6;
s1_3->s1_7;
s1_4->s1_7;
s1_6->final;
s1_7->thrown;
}
*/