Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions javascript/ql/src/semmle/javascript/Expr.qll
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,27 @@ class ExprOrType extends @exprortype, Documentable {
result = getOwnDocumentation()
or
// if there is no JSDoc for the expression itself, check the enclosing property or statement
not exists(getOwnDocumentation()) and
(
not exists(getOwnDocumentation()) and
if getParent() instanceof Property
then result = getParent().(Property).getDocumentation()
else
if getParent() instanceof MethodDeclaration
then result = getParent().(MethodDeclaration).getDocumentation()
else result = getEnclosingStmt().getDocumentation()
exists(Property prop | prop = getParent() |
result = prop.getDocumentation()
)
or
exists(MethodDeclaration decl | decl = getParent() |
result = decl.getDocumentation()
)
or
exists(VariableDeclarator decl | decl = getParent() |
result = decl.getDocumentation()
)
or
exists(DeclStmt stmt | this = stmt.getDecl(0) |
result = stmt.getDocumentation()
)
or
exists(DotExpr dot | this = dot.getProperty() |
result = dot.getDocumentation()
)
)
}

Expand All @@ -50,7 +63,7 @@ class ExprOrType extends @exprortype, Documentable {
exists(Token tk | tk = result.getComment().getNextToken() |
tk = this.getFirstToken()
or
exists(Expr p | p.stripParens() = this | tk = p.getFirstToken())
exists(Expr p | p.getUnderlyingValue() = this | tk = p.getFirstToken())
)
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

19 changes: 19 additions & 0 deletions javascript/ql/test/library-tests/JSDoc/getDocumentation.qll
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import javascript

query predicate test_AssignExpr_getDocumentation(AssignExpr assgn, JSDoc res) {
res = assgn.getDocumentation()
}

query predicate test_Function_getDocumentation(Function f, JSDoc res) { res = f.getDocumentation() }

query predicate test_VarDeclStmt_getDocumentation(VarDeclStmt vds, JSDoc res) {
res = vds.getDocumentation()
}

query predicate test_OtherExpr_getDocumentation(Expr e, JSDoc res) {
res = e.getDocumentation() and
(
not e instanceof AssignExpr and
not e instanceof Function
)
}
312 changes: 248 additions & 64 deletions javascript/ql/test/library-tests/JSDoc/tests.expected

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions javascript/ql/test/library-tests/JSDoc/tests.ql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import JSDocUnionTypeExpr
import JSDocArrayTypeExpr
import Parameter_getDocumentation
import JSDocRestParameterTypeExpr
import AssignExpr_getDocumentation
import getDocumentation
import JSDocRecordTypeExpr
import JSDoc
import JSDocTag
Expand All @@ -11,10 +11,8 @@ import JSDocFunctionTypeExpr
import JSDocNullableTypeExpr
import next_token
import JSDocTypeExpr
import Function_getDocumentation
import JSDocOptionalParameterTypeExpr
import getParameterTag
import VarDeclStmt_getDocumentation
import JSDocAppliedTypeExpr
import JSDocNonNullableTypeExpr
import ParExpr_getDocumentation
2 changes: 1 addition & 1 deletion javascript/ql/test/library-tests/JSDoc/tst.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function foo(/** number */ a, /** number */ b) {
* @type {Function[]}
* @private
*/
this.handlers_ = [];
this.handlers_ = [1,2,3];

/**
* Sets the component's root element to the given element.
Expand Down