Merge branch 'main' into shared-http-client-request

This commit is contained in:
Rasmus Wriedt Larsen
2022-08-22 12:05:37 +02:00
committed by GitHub
192 changed files with 10953 additions and 1801 deletions

View File

@@ -234,8 +234,6 @@ class File extends Container, @file {
/** Gets a toplevel piece of JavaScript code in this file. */
TopLevel getATopLevel() { result.getFile() = this }
override string toString() { result = Container.super.toString() }
/** Gets the URL of this file. */
override string getURL() { result = "file://" + this.getAbsolutePath() + ":0:0:0:0" }

View File

@@ -147,30 +147,22 @@ private string getASrcFolderName() { result = ["ts", "js", "src", "lib"] }
*/
class MainModulePath extends PathExpr, @json_string {
PackageJson pkg;
string relativePath;
MainModulePath() {
relativePath = "." and
this = pkg.getPropValue(["main", "module"])
or
// { "exports": "path" } is sugar for { "exports": { ".": "path" }}
relativePath = "." and
this = pkg.getPropValue("exports")
or
exists(JsonValue val | val = pkg.getPropValue("exports").getPropValue(relativePath) |
// Either specified directly as a string: { "./path": "./path.js" }
this = val
or
// Or by module type: { "./path": { "require": "./path.cjs", ... }}
this = val.getPropValue(_)
)
this = getAPartOfExportsSection(pkg)
}
/** Gets the `package.json` file in which this path occurs. */
PackageJson getPackageJson() { result = pkg }
/** Gets the relative path under which this is exported, usually starting with a `.`. */
string getRelativePath() { result = relativePath }
string getRelativePath() {
result = getExportRelativePath(this)
or
not exists(getExportRelativePath(this)) and result = "."
}
/** DEPRECATED: Alias for getPackageJson */
deprecated PackageJSON getPackageJSON() { result = getPackageJson() }
@@ -183,6 +175,29 @@ class MainModulePath extends PathExpr, @json_string {
}
}
private JsonValue getAPartOfExportsSection(PackageJson pkg) {
result = pkg.getPropValue("exports")
or
result = getAPartOfExportsSection(pkg).getPropValue(_)
}
/** Gets the text of one of the conditions or paths enclosing the given `part` of an `exports` section. */
private string getAnEnclosingExportProperty(JsonValue part) {
exists(JsonObject parent, string prop |
parent = getAPartOfExportsSection(_) and
part = parent.getPropValue(prop)
|
result = prop
or
result = getAnEnclosingExportProperty(parent)
)
}
private string getExportRelativePath(JsonValue part) {
result = getAnEnclosingExportProperty(part) and
result.matches(".%")
}
module MainModulePath {
/** Gets the path to the main entry point of `pkg`. */
MainModulePath of(PackageJson pkg) { result = of(pkg, ".") }

View File

@@ -43,8 +43,6 @@ abstract private class BracketedListOfExpressions extends Expr {
* An array expression viewed as a bracketed list of expressions.
*/
private class ArrayExprIsABracketedListOfExpressions extends ArrayExpr, BracketedListOfExpressions {
override predicate isImpure() { ArrayExpr.super.isImpure() }
/** Gets the `i`th element of this array literal. */
override Expr getElement(int i) { result = ArrayExpr.super.getElement(i) }
}

View File

@@ -17,4 +17,4 @@
"peerDependencies": {
"tea": "2.x"
}
}
}

View File

@@ -2,8 +2,6 @@ import semmle.javascript.frameworks.Testing
class MyTest extends Test, CallExpr {
MyTest() { getCallee().(VarAccess).getName() = "mytest" }
override string toString() { result = CallExpr.super.toString() }
}
from Test t