|
14 | 14 |
|
15 | 15 | import javascript
|
16 | 16 |
|
17 |
| -from BindingPattern p, string n, VarDecl v, VarDecl w |
| 17 | +class RootDestructuringPattern extends BindingPattern { |
| 18 | + RootDestructuringPattern() { |
| 19 | + this instanceof DestructuringPattern and |
| 20 | + not this = any(PropertyPattern p).getValuePattern() and |
| 21 | + not this = any(ArrayPattern p).getAnElement() |
| 22 | + } |
| 23 | + |
| 24 | + /** Holds if this pattern has multiple bindings for `name`. */ |
| 25 | + predicate hasConflictingBindings(string name) { |
| 26 | + exists(VarRef v, VarRef w | |
| 27 | + v = getABindingVarRef() and |
| 28 | + w = getABindingVarRef() and |
| 29 | + name = v.getName() and |
| 30 | + name = w.getName() and |
| 31 | + v != w |
| 32 | + ) |
| 33 | + } |
| 34 | + |
| 35 | + /** Gets the first occurrence of the conflicting binding `name`. */ |
| 36 | + VarDecl getFirstClobberedVarDecl(string name) { |
| 37 | + hasConflictingBindings(name) and |
| 38 | + result = min(VarDecl decl | decl = getABindingVarRef() and decl.getName() = name | decl order by decl.getLocation().getStartLine(), decl.getLocation().getStartColumn()) |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +from RootDestructuringPattern p, string n, VarDecl v, VarDecl w |
18 | 43 | where
|
19 |
| - v = p.getABindingVarRef() and |
| 44 | + v = p.getFirstClobberedVarDecl(n) and |
20 | 45 | w = p.getABindingVarRef() and
|
21 |
| - v.getName() = n and |
22 | 46 | w.getName() = n and
|
23 |
| - v != w and |
24 |
| - v.getLocation().startsBefore(w.getLocation()) |
| 47 | + v != w |
25 | 48 | select w, "Repeated binding of pattern variable '" + n + "' previously bound $@.", v, "here"
|
0 commit comments