/*** @name Non-linear pattern* @description If the same pattern variable appears twice in an array or object pattern,* the second binding will silently overwrite the first binding, which is probably* unintentional.* @kind problem* @problem.severity error* @id js/non-linear-pattern* @tags reliability* correctness* language-features* @precision very-high*/import javascriptclass RootDestructuringPattern extends DestructuringPattern {RootDestructuringPattern() {not this = any(PropertyPattern p).getValuePattern() andnot this = any(ArrayPattern p).getAnElement()}/** Holds if this pattern has multiple bindings for `name`. */predicate hasConflictingBindings(string name) {exists(VarRef v, VarRef w |v = this.getABindingVarRef() andw = this.getABindingVarRef() andname = v.getName() andname = w.getName() andv != w)}/** Gets the first occurrence of the conflicting binding `name`. */VarDecl getFirstClobberedVarDecl(string name) {this.hasConflictingBindings(name) andresult =min(VarDecl decl |decl = this.getABindingVarRef() and decl.getName() = name|decl order by decl.getLocation().getStartLine(), decl.getLocation().getStartColumn())}/** Holds if variables in this pattern may resemble type annotations. */predicate resemblesTypeAnnotation() {this.hasConflictingBindings(_) and // Restrict size of predicate.this instanceof Parameter andthis instanceof ObjectPattern andnot exists(this.getTypeAnnotation()) andthis.getFile().getFileType().isTypeScript()}}from RootDestructuringPattern p, string n, VarDecl v, VarDecl w, string messagewherev = p.getFirstClobberedVarDecl(n) andw = p.getABindingVarRef() andw.getName() = n andv != w andif p.resemblesTypeAnnotation()then message = "The pattern variable '" + n + "' appears to be a type, but is a variable $@."else message = "Repeated binding of pattern variable '" + n + "' $@."select w, message, v, "previously bound"
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。