Merge pull request #1110 from xiemaisi/js/yield-in-non-generator

Approved by asger-semmle
This commit is contained in:
semmle-qlci
2019-03-14 11:59:43 +00:00
committed by GitHub
3 changed files with 15 additions and 2 deletions

View File

@@ -15,6 +15,6 @@ import javascript
from YieldExpr yield, Function f
where
f = yield.getEnclosingFunction() and
not f.isGenerator()
not isGenerator(f)
select yield, "This yield expression is contained in $@ which is not marked as a generator.",
f.getFirstToken(), f.describe()

View File

@@ -79,7 +79,12 @@ class Function extends @function, Parameterized, TypeParameterized, StmtContaine
TypeExpr getReturnTypeAnnotation() { typeexprs(result, _, this, -3, _) }
/** Holds if this function is a generator function. */
predicate isGenerator() { isGenerator(this) }
predicate isGenerator() {
isGenerator(this)
or
// we also support `yield` in non-generator functions
exists(YieldExpr yield | this = yield.getEnclosingFunction())
}
/** Holds if the last parameter of this function is a rest parameter. */
predicate hasRestParameter() { hasRestParameter(this) }