Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix: Code path analysis for class fields (fixes #14343) * PropertyDefinition code paths * Add test and comments * Reverse order of code path closing * Added CodePath#origin * Update tests/lib/linter/code-path-analysis/code-path.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update lib/linter/code-path-analysis/code-path.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
- Loading branch information
1 parent
db15183
commit 05ca24c
Showing
11 changed files
with
353 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/fixtures/code-path-analysis/class-fields-init--arrow-function.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/*expected | ||
initial->s3_1->final; | ||
*/ | ||
/*expected | ||
initial->s2_1->final; | ||
*/ | ||
/*expected | ||
initial->s1_1->final; | ||
*/ | ||
|
||
class Foo { a = () => b } | ||
|
||
/*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]; | ||
s3_1[label="ArrowFunctionExpression:enter\nIdentifier (b)\nArrowFunctionExpression:exit"]; | ||
initial->s3_1->final; | ||
} | ||
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]; | ||
s2_1[label="ArrowFunctionExpression"]; | ||
initial->s2_1->final; | ||
} | ||
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 (Foo)\nClassBody:enter\nPropertyDefinition:enter\nIdentifier (a)\nArrowFunctionExpression\nPropertyDefinition:exit\nClassBody:exit\nClassDeclaration:exit\nProgram:exit"]; | ||
initial->s1_1->final; | ||
} | ||
*/ |
26 changes: 26 additions & 0 deletions
26
tests/fixtures/code-path-analysis/class-fields-init--call-expression.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*expected | ||
initial->s2_1->final; | ||
*/ | ||
/*expected | ||
initial->s1_1->final; | ||
*/ | ||
|
||
class Foo { a = b() } | ||
|
||
/*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]; | ||
s2_1[label="CallExpression:enter\nIdentifier (b)\nCallExpression:exit"]; | ||
initial->s2_1->final; | ||
} | ||
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 (Foo)\nClassBody:enter\nPropertyDefinition:enter\nIdentifier (a)\nCallExpression\nPropertyDefinition:exit\nClassBody:exit\nClassDeclaration:exit\nProgram:exit"]; | ||
initial->s1_1->final; | ||
} | ||
*/ |
32 changes: 32 additions & 0 deletions
32
tests/fixtures/code-path-analysis/class-fields-init--conditional.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*expected | ||
initial->s2_1->s2_2->s2_4; | ||
s2_1->s2_3->s2_4->final; | ||
*/ | ||
/*expected | ||
initial->s1_1->final; | ||
*/ | ||
|
||
|
||
class Foo { 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]; | ||
s2_1[label="ConditionalExpression:enter\nIdentifier (b)"]; | ||
s2_2[label="Identifier (c)"]; | ||
s2_4[label="ConditionalExpression:exit"]; | ||
s2_3[label="Identifier (d)"]; | ||
initial->s2_1->s2_2->s2_4; | ||
s2_1->s2_3->s2_4->final; | ||
} | ||
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 (Foo)\nClassBody:enter\nPropertyDefinition:enter\nIdentifier (a)\nConditionalExpression\nPropertyDefinition:exit\nClassBody:exit\nClassDeclaration:exit\nProgram:exit"]; | ||
initial->s1_1->final; | ||
} | ||
*/ |
28 changes: 28 additions & 0 deletions
28
tests/fixtures/code-path-analysis/class-fields-init--simple.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/*expected | ||
initial->s2_1->final; | ||
*/ | ||
/*expected | ||
initial->s1_1->final; | ||
*/ | ||
|
||
class Foo { | ||
a = b; | ||
} | ||
|
||
/*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]; | ||
s2_1[label="Identifier (b)"]; | ||
initial->s2_1->final; | ||
} | ||
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 (Foo)\nClassBody:enter\nPropertyDefinition:enter\nIdentifier (a)\nIdentifier (b)\nPropertyDefinition:exit\nClassBody:exit\nClassDeclaration:exit\nProgram:exit"]; | ||
initial->s1_1->final; | ||
} | ||
*/ |
Oops, something went wrong.