JS: Remove PathExprBase and PathExprInModule

This commit is contained in:
Asger Feldthaus
2020-05-13 16:34:28 +01:00
parent 2d88385ffb
commit 5f510878f3
8 changed files with 26 additions and 28 deletions

View File

@@ -192,7 +192,7 @@ private class AmdDependencyPath extends PathExprCandidate {
}
/** A constant path element appearing in an AMD dependency expression. */
private class ConstantAmdDependencyPathElement extends PathExprInModule, ConstantString {
private class ConstantAmdDependencyPathElement extends PathExpr, ConstantString {
ConstantAmdDependencyPathElement() { this = any(AmdDependencyPath amd).getAPart() }
override string getValue() { result = getStringValue() }

View File

@@ -53,7 +53,7 @@ class ES2015Module extends Module {
class ImportDeclaration extends Stmt, Import, @importdeclaration {
override ES2015Module getEnclosingModule() { result = getTopLevel() }
override PathExprInModule getImportedPath() { result = getChildExpr(-1) }
override PathExpr getImportedPath() { result = getChildExpr(-1) }
/** Gets the `i`th import specifier of this import declaration. */
ImportSpecifier getSpecifier(int i) { result = getChildExpr(i) }
@@ -82,7 +82,7 @@ class ImportDeclaration extends Stmt, Import, @importdeclaration {
}
/** A literal path expression appearing in an `import` declaration. */
private class LiteralImportPath extends PathExprInModule, ConstantString {
private class LiteralImportPath extends PathExpr, ConstantString {
LiteralImportPath() { exists(ImportDeclaration req | this = req.getChildExpr(-1)) }
override string getValue() { result = getStringValue() }
@@ -622,7 +622,7 @@ abstract class ReExportDeclaration extends ExportDeclaration {
}
/** A literal path expression appearing in a re-export declaration. */
private class LiteralReExportPath extends PathExprInModule, ConstantString {
private class LiteralReExportPath extends PathExpr, ConstantString {
LiteralReExportPath() { exists(ReExportDeclaration bred | this = bred.getImportedPath()) }
override string getValue() { result = getStringValue() }

View File

@@ -2614,7 +2614,7 @@ class DynamicImportExpr extends @dynamicimport, Expr, Import {
}
/** A literal path expression appearing in a dynamic import. */
private class LiteralDynamicImportPath extends PathExprInModule, ConstantString {
private class LiteralDynamicImportPath extends PathExpr, ConstantString {
LiteralDynamicImportPath() {
exists(DynamicImportExpr di | this.getParentExpr*() = di.getSource())
}

View File

@@ -187,10 +187,11 @@ abstract class Import extends ASTNode {
/**
* A path expression that appears in a module and is resolved relative to it.
*/
deprecated
abstract class PathExprInModule extends PathExpr {
PathExprInModule() { exists(getEnclosingModule()) }
override Folder getSearchRoot(int priority) {
getEnclosingModule().searchRoot(this, result, priority)
PathExprInModule() {
this.(Expr).getTopLevel() instanceof Module
or
this.(Comment).getTopLevel() instanceof Module
}
}

View File

@@ -266,14 +266,14 @@ private class RequirePath extends PathExprCandidate {
}
/** A constant path element appearing in a call to `require` or `require.resolve`. */
private class ConstantRequirePathElement extends PathExprInModule, ConstantString {
private class ConstantRequirePathElement extends PathExpr, ConstantString {
ConstantRequirePathElement() { this = any(RequirePath rp).getAPart() }
override string getValue() { result = getStringValue() }
}
/** A `__dirname` path expression. */
private class DirNamePath extends PathExprInModule, VarAccess {
private class DirNamePath extends PathExpr, VarAccess {
DirNamePath() {
getName() = "__dirname" and
getVariable().getScope() instanceof ModuleScope
@@ -283,7 +283,7 @@ private class DirNamePath extends PathExprInModule, VarAccess {
}
/** A `__filename` path expression. */
private class FileNamePath extends PathExprInModule, VarAccess {
private class FileNamePath extends PathExpr, VarAccess {
FileNamePath() {
getName() = "__filename" and
getVariable().getScope() instanceof ModuleScope
@@ -296,7 +296,7 @@ private class FileNamePath extends PathExprInModule, VarAccess {
* A path expression of the form `path.join(p, "...")` where
* `p` is also a path expression.
*/
private class JoinedPath extends PathExprInModule, @callexpr {
private class JoinedPath extends PathExpr, @callexpr {
JoinedPath() {
exists(MethodCallExpr call | call = this |
call.getReceiver().(VarAccess).getName() = "path" and

View File

@@ -174,17 +174,6 @@ abstract class PathString extends string {
Path resolve(Folder root) { result = resolveUpTo(getNumComponent(), root) }
}
/**
* Non-abstract base class for path expressions.
*/
private class PathExprBase extends Locatable {
// We must put getEnclosingModule here for it to be usable in the characteristic predicate of PathExprInModule
/** Gets the module containing this path expression, if any. */
Module getEnclosingModule() {
result = this.(Expr).getTopLevel() or result = this.(Comment).getTopLevel()
}
}
/**
* An expression whose value represents a (relative or absolute) file system path.
*
@@ -197,12 +186,15 @@ private class PathExprBase extends Locatable {
* as their highest-priority root, with default library paths as additional roots
* of lower priority.
*/
abstract class PathExpr extends PathExprBase {
abstract class PathExpr extends Locatable {
/** Gets the (unresolved) path represented by this expression. */
abstract string getValue();
/** Gets the root folder of priority `priority` associated with this path expression. */
abstract Folder getSearchRoot(int priority);
Folder getSearchRoot(int priority) {
// We default to the enclosing module's search root, though this may be overridden.
getEnclosingModule().searchRoot(this, result, priority)
}
/** Gets the `i`th component of this path. */
string getComponent(int i) { result = getValue().(PathString).getComponent(i) }
@@ -246,6 +238,11 @@ abstract class PathExpr extends PathExprBase {
/** Gets the file or folder that this path refers to. */
Container resolve() { result = resolveUpTo(getNumComponent()) }
/** Gets the module containing this path expression, if any. */
Module getEnclosingModule() {
result = this.(Expr).getTopLevel() or result = this.(Comment).getTopLevel()
}
}
/** A path string derived from a path expression. */

View File

@@ -213,7 +213,7 @@ class ExternalModuleReference extends Expr, Import, @externalmodulereference {
}
/** A literal path expression appearing in an external module reference. */
private class LiteralExternalModulePath extends PathExprInModule, ConstantString {
private class LiteralExternalModulePath extends PathExpr, ConstantString {
LiteralExternalModulePath() {
exists(ExternalModuleReference emr | this.getParentExpr*() = emr.getExpression())
}

View File

@@ -74,7 +74,7 @@ module LazyCache {
}
/** A constant path element appearing in a call to a lazy-cache object. */
private class LazyCachePathExpr extends PathExprInModule, ConstantString {
private class LazyCachePathExpr extends PathExpr, ConstantString {
LazyCachePathExpr() { this = any(LazyCacheImport rp).getArgument(0) }
override string getValue() { result = getStringValue() }