JS: Add partial backwards compatibility with ASTNode

This commit is contained in:
Asger F
2019-04-16 13:46:15 +01:00
parent e295c3a224
commit 6eb8c692b1
3 changed files with 44 additions and 0 deletions

View File

@@ -42,6 +42,8 @@ abstract class Documentable extends ASTNode {
class JSDocTypeExprParent extends @jsdoc_type_expr_parent {
/** Gets a textual representation of this element. */
string toString() { none() }
JSDoc getJSDocComment() { none() }
}
/**
@@ -83,6 +85,10 @@ class JSDocTag extends @jsdoc_tag, JSDocTypeExprParent, Locatable {
/** Gets the toplevel in which this tag appears. */
TopLevel getTopLevel() { result = getParent().getComment().getTopLevel() }
override JSDoc getJSDocComment() {
result.getATag() = this
}
}
/**
@@ -123,6 +129,20 @@ class JSDocTypeExpr extends @jsdoc_type_expr, JSDocTypeExprParent, TypeAnnotatio
JSDocTypeExpr getChild(int i) { jsdoc_type_exprs(result, _, this, i, _) }
override string toString() { jsdoc_type_exprs(this, _, _, _, result) }
override JSDoc getJSDocComment() {
result = getParent().getJSDocComment()
}
override Stmt getEnclosingStmt() {
result.getDocumentation() = getJSDocComment()
}
override StmtContainer getContainer() { result = getEnclosingStmt().getContainer() }
override Function getEnclosingFunction() { result = getContainer() }
override TopLevel getTopLevel() { result = getEnclosingStmt().getTopLevel() }
}
/** An `any` type expression `*`. */

View File

@@ -85,4 +85,20 @@ class TypeAnnotation extends @type_annotation {
* Holds if this is a reference to the type exported from `moduleName` under the name `exportedName`.
*/
predicate hasQualifiedName(string moduleName, string exportedName) { none() }
/** Gets the statement in which this type appears. */
Stmt getEnclosingStmt() { none() }
/** Gets the function in which this type appears, if any. */
Function getEnclosingFunction() { none() }
/**
* Gets the statement container (function or toplevel) in which this type appears.
*/
StmtContainer getContainer() { none() }
/**
* Gets the top-level containing this type annotation.
*/
TopLevel getTopLevel() { none() }
}

View File

@@ -540,6 +540,14 @@ class TypeExpr extends ExprOrType, @typeexpr, TypeAnnotation {
* without type information.
*/
Type getType() { ast_node_type(this, result) }
override Stmt getEnclosingStmt() { result = ExprOrType.super.getEnclosingStmt() }
override Function getEnclosingFunction() { result = ExprOrType.super.getEnclosingFunction() }
override StmtContainer getContainer() { result = ExprOrType.super.getContainer() }
override TopLevel getTopLevel() { result = ExprOrType.super.getTopLevel() }
}
/**