Skip to content

Commit 1b0cfc9

Browse files
authored
Merge pull request github#4015 from erik-krogh/nonAbstract
Approved by asgerf
2 parents 0ba5921 + 67c4320 commit 1b0cfc9

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

javascript/ql/src/LanguageFeatures/NonLinearPattern.ql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
import javascript
1616

17-
class RootDestructuringPattern extends BindingPattern {
17+
class RootDestructuringPattern extends DestructuringPattern {
1818
RootDestructuringPattern() {
19-
this instanceof DestructuringPattern and
2019
not this = any(PropertyPattern p).getValuePattern() and
2120
not this = any(ArrayPattern p).getAnElement()
2221
}

javascript/ql/src/semmle/javascript/Expr.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,11 @@ class AssignExpr extends @assignexpr, Assignment {
18481848
override Expr getUnderlyingValue() { result = getRhs().getUnderlyingValue() }
18491849
}
18501850

1851+
private class TCompoundAssignExpr =
1852+
@assignaddexpr or @assignsubexpr or @assignmulexpr or @assigndivexpr or @assignmodexpr or
1853+
@assignexpexpr or @assignlshiftexpr or @assignrshiftexpr or @assignurshiftexpr or
1854+
@assignorexpr or @assignxorexpr or @assignandexpr;
1855+
18511856
/**
18521857
* A compound assign expression.
18531858
*
@@ -1858,7 +1863,7 @@ class AssignExpr extends @assignexpr, Assignment {
18581863
* x /= 2
18591864
* ```
18601865
*/
1861-
abstract class CompoundAssignExpr extends Assignment { }
1866+
class CompoundAssignExpr extends TCompoundAssignExpr, Assignment { }
18621867

18631868
/**
18641869
* A compound add-assign expression.

javascript/ql/src/semmle/javascript/Stmt.qll

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ class Stmt extends @stmt, ExprOrStmt, Documentable {
6464
}
6565
}
6666

67+
private class TControlStmt =
68+
TLoopStmt or @ifstmt or @withstmt or @switchstmt or @trystmt or @catchclause;
69+
70+
private class TLoopStmt = TEnhancedForLoop or @whilestmt or @dowhilestmt or @forstmt;
71+
72+
private class TEnhancedForLoop = @forinstmt or @foreachstmt or @forofstmt;
73+
6774
/**
6875
* A control statement, that is, is a loop, an if statement, a switch statement,
6976
* a with statement, a try statement, or a catch clause.
@@ -82,7 +89,7 @@ class Stmt extends @stmt, ExprOrStmt, Documentable {
8289
* }
8390
* ```
8491
*/
85-
abstract class ControlStmt extends Stmt {
92+
class ControlStmt extends TControlStmt, Stmt {
8693
/** Gets a statement controlled by this control statement. */
8794
abstract Stmt getAControlledStmt();
8895
}
@@ -102,7 +109,7 @@ abstract class ControlStmt extends Stmt {
102109
* } while(++i < lines.length);
103110
* ```
104111
*/
105-
abstract class LoopStmt extends ControlStmt {
112+
class LoopStmt extends TLoopStmt, ControlStmt {
106113
/** Gets the body of this loop. */
107114
abstract Stmt getBody();
108115

@@ -450,6 +457,10 @@ class LabeledStmt extends @labeledstmt, Stmt {
450457
Stmt getStmt() { result = getChildStmt(1) }
451458
}
452459

460+
private class TJumpStmt = TBreakOrContinueStmt or @returnstmt or @throwstmt;
461+
462+
private class TBreakOrContinueStmt = @breakstmt or @continuestmt;
463+
453464
/**
454465
* A statement that disrupts structured control flow, that is, a `continue` statement,
455466
* a `break` statement, a `throw` statement, or a `return` statement.
@@ -463,7 +474,7 @@ class LabeledStmt extends @labeledstmt, Stmt {
463474
* return -1;
464475
* ```
465476
*/
466-
abstract class JumpStmt extends Stmt {
477+
class JumpStmt extends TJumpStmt, Stmt {
467478
/**
468479
* Gets the target of this jump.
469480
*
@@ -490,7 +501,7 @@ abstract class JumpStmt extends Stmt {
490501
* break;
491502
* ```
492503
*/
493-
abstract class BreakOrContinueStmt extends JumpStmt {
504+
class BreakOrContinueStmt extends TBreakOrContinueStmt, JumpStmt {
494505
/** Gets the label this statement refers to, if any. */
495506
string getTargetLabel() { result = getChildExpr(0).(Identifier).getName() }
496507

@@ -801,7 +812,7 @@ class ForStmt extends @forstmt, LoopStmt {
801812
* }
802813
* ```
803814
*/
804-
abstract class EnhancedForLoop extends LoopStmt {
815+
class EnhancedForLoop extends TEnhancedForLoop, LoopStmt {
805816
/**
806817
* Gets the iterator of this `for`-`in` or `for`-`of` loop; this can be either a
807818
* pattern, a property reference, or a variable declaration statement.

javascript/ql/src/semmle/javascript/Variables.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ class BindingPattern extends @pattern, Expr {
406406
}
407407
}
408408

409+
private class TDestructuringPattern = @arraypattern or @objectpattern;
410+
409411
/**
410412
* A destructuring pattern, that is, either an array pattern or an object pattern.
411413
*
@@ -418,9 +420,9 @@ class BindingPattern extends @pattern, Expr {
418420
* }
419421
* ```
420422
*/
421-
abstract class DestructuringPattern extends BindingPattern {
423+
class DestructuringPattern extends TDestructuringPattern, BindingPattern {
422424
/** Gets the rest pattern of this destructuring pattern, if any. */
423-
abstract Expr getRest();
425+
Expr getRest() { none() } // Overridden in subtypes.
424426
}
425427

426428
/**

0 commit comments

Comments
 (0)