Skip to content

Commit 6eb8c69

Browse files
committed
JS: Add partial backwards compatibility with ASTNode
1 parent e295c3a commit 6eb8c69

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

javascript/ql/src/semmle/javascript/JSDoc.qll

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ abstract class Documentable extends ASTNode {
4242
class JSDocTypeExprParent extends @jsdoc_type_expr_parent {
4343
/** Gets a textual representation of this element. */
4444
string toString() { none() }
45+
46+
JSDoc getJSDocComment() { none() }
4547
}
4648

4749
/**
@@ -83,6 +85,10 @@ class JSDocTag extends @jsdoc_tag, JSDocTypeExprParent, Locatable {
8385

8486
/** Gets the toplevel in which this tag appears. */
8587
TopLevel getTopLevel() { result = getParent().getComment().getTopLevel() }
88+
89+
override JSDoc getJSDocComment() {
90+
result.getATag() = this
91+
}
8692
}
8793

8894
/**
@@ -123,6 +129,20 @@ class JSDocTypeExpr extends @jsdoc_type_expr, JSDocTypeExprParent, TypeAnnotatio
123129
JSDocTypeExpr getChild(int i) { jsdoc_type_exprs(result, _, this, i, _) }
124130

125131
override string toString() { jsdoc_type_exprs(this, _, _, _, result) }
132+
133+
override JSDoc getJSDocComment() {
134+
result = getParent().getJSDocComment()
135+
}
136+
137+
override Stmt getEnclosingStmt() {
138+
result.getDocumentation() = getJSDocComment()
139+
}
140+
141+
override StmtContainer getContainer() { result = getEnclosingStmt().getContainer() }
142+
143+
override Function getEnclosingFunction() { result = getContainer() }
144+
145+
override TopLevel getTopLevel() { result = getEnclosingStmt().getTopLevel() }
126146
}
127147

128148
/** An `any` type expression `*`. */

javascript/ql/src/semmle/javascript/TypeAnnotations.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,20 @@ class TypeAnnotation extends @type_annotation {
8585
* Holds if this is a reference to the type exported from `moduleName` under the name `exportedName`.
8686
*/
8787
predicate hasQualifiedName(string moduleName, string exportedName) { none() }
88+
89+
/** Gets the statement in which this type appears. */
90+
Stmt getEnclosingStmt() { none() }
91+
92+
/** Gets the function in which this type appears, if any. */
93+
Function getEnclosingFunction() { none() }
94+
95+
/**
96+
* Gets the statement container (function or toplevel) in which this type appears.
97+
*/
98+
StmtContainer getContainer() { none() }
99+
100+
/**
101+
* Gets the top-level containing this type annotation.
102+
*/
103+
TopLevel getTopLevel() { none() }
88104
}

javascript/ql/src/semmle/javascript/TypeScript.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,14 @@ class TypeExpr extends ExprOrType, @typeexpr, TypeAnnotation {
540540
* without type information.
541541
*/
542542
Type getType() { ast_node_type(this, result) }
543+
544+
override Stmt getEnclosingStmt() { result = ExprOrType.super.getEnclosingStmt() }
545+
546+
override Function getEnclosingFunction() { result = ExprOrType.super.getEnclosingFunction() }
547+
548+
override StmtContainer getContainer() { result = ExprOrType.super.getContainer() }
549+
550+
override TopLevel getTopLevel() { result = ExprOrType.super.getTopLevel() }
543551
}
544552

545553
/**

0 commit comments

Comments
 (0)