/** * Provides a predicate for identifying uses of features introduced in ECMAScript 2015 * and later. */ import javascript /** * Holds if `nd` is a use of a feature introduced in ECMAScript `version` * from the given category. * * Categories are taken from Kangax' [ECMAScript 6 compatibility table] * (https://kangax.github.io/compat-table/es6/) and [ECMAScript next compatibility table] * (https://kangax.github.io/compat-table/esnext/). */ predicate isES20xxFeature(AstNode nd, int version, string category) { version = 2015 and ( exists(nd.(Parameter).getDefault()) and category = "default function parameters" or exists(Expr e | e = nd and // synthetic constructors use rest/spread/super, but we don't want to count those not e.getEnclosingFunction() instanceof SyntheticConstructor | nd.(Parameter).isRestParameter() and category = "rest parameters" or nd instanceof SpreadElement and // spread properties are an ES2018 feature, see below not nd = any(SpreadProperty sp).getInit() and category = "spread (...) operator" or nd instanceof SuperExpr and category = "super" ) or exists(Property prop | prop = nd | prop.getName() = "__proto__" or prop.isShorthand() or prop.isMethod() or prop.isComputed() ) and category = "object literal extensions" or nd instanceof ForOfStmt and category = "for..of loops" or nd.(Literal).getRawValue().regexpMatch("^0[bo].*") and category = "octal and binary literals" or nd instanceof TemplateLiteral and category = "template literals" or exists(RegExpLiteral rel | rel = nd | rel.getFlags().regexpMatch(".*[yu].*") and category = "RegExp \"y\" and \"u\" flags" ) or exists(VariableDeclarator vd | vd = nd | vd.getBindingPattern() instanceof DestructuringPattern and category = "destructuring declarations" ) or exists(AssignExpr assgn | assgn = nd | assgn.getLhs().stripParens() instanceof DestructuringPattern and category = "destructuring assignment" ) or nd.(Parameter) instanceof DestructuringPattern and category = "destructuring parameters" or exists(StringLiteral sl | sl = nd | sl.getRawValue().regexpMatch(".*(?