JavaScript: Teach Function.isGenerator to check for yield.

This commit is contained in:
Max Schaefer
2019-03-13 14:56:32 +00:00
parent 6baf52614e
commit 69c63110c1
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) }