Merge pull request #2418 from max-schaefer/js/file-locatable

JavaScript: Make `File` not extend `Locatable` anymore.
This commit is contained in:
Asger F
2019-12-02 16:15:14 +00:00
committed by GitHub
6 changed files with 111 additions and 34 deletions

View File

@@ -198,8 +198,13 @@ class Folder extends Container, @folder {
}
/** A file. */
class File extends Container, @file, Locatable {
override Location getLocation() { hasLocation(this, result) }
class File extends Container, @file {
/**
* Gets the location of this file.
*
* Note that files have special locations starting and ending at line zero, column zero.
*/
Location getLocation() { hasLocation(this, result) }
override string getAbsolutePath() { files(this, result, _, _, _) }

View File

@@ -74,6 +74,7 @@ abstract class Documentable extends ASTNode {
class JSDocTypeExprParent extends @jsdoc_type_expr_parent, Locatable {
override Location getLocation() { hasLocation(this, result) }
/** Gets the JSDoc comment to which this element belongs. */
JSDoc getJSDocComment() { none() }
}

View File

@@ -132,3 +132,15 @@ class Locatable extends @locatable {
none()
}
}
/**
* A `File`, considered as a `Locatable`.
*
* For reasons of backwards compatibility, @file is a subtype of @locatable. This class exists to
* provide an override of `Locatable.getLocation()` for @files, since it would otherwise default
* to `none()`, which is unhelpful.
*/
private class FileLocatable extends File, Locatable {
override Location getLocation() { result = File.super.getLocation() }
override string toString() { result = File.super.toString() }
}

View File

@@ -194,7 +194,8 @@ abstract class ScriptDependency extends Dependency {
abstract Expr getAnApiUse();
override Locatable getAUse(string kind) {
kind = "import" and result.(HTML::HtmlFile) = this.getFile()
kind = "import" and
result = this.getFile().(HTML::HtmlFile).getATopLevel()
or
kind = "use" and result = getAnApiUse()
}