File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed
javascript/ql/lib/semmle/javascript/internal/paths Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change 66private import javascript
77private import semmle.javascript.TSConfig
88
9+ /**
10+ * Holds if `path` is relative, in the sense that it should be resolved relative to its enclosing folder.
11+ */
12+ bindingset [ path]
13+ pragma [ inline_late]
14+ predicate isRelativePath ( string path ) { path .regexpMatch ( "\\.\\.?(?:[/\\\\].*)?" ) }
15+
16+ /**
17+ * Gets the NPM package name from the beginning of the given import path, e.g.
18+ * gets `foo` from `foo/bar`, and `@example/foo` from `@example/foo/bar`.
19+ */
20+ bindingset [ path]
21+ string getPackagePrefixFromString ( string path ) {
22+ result = path .regexpFind ( "^(@[^/\\\\]+[/\\\\])?[^@./\\\\][^/\\\\]*" , _, _)
23+ }
24+
925/**
1026 * Gets a folder name that is a common source folder name.
1127 */
Original file line number Diff line number Diff line change @@ -88,20 +88,13 @@ module ResolveExpr<exprSig/1 shouldResolveExpr> {
8888 result .getAnAffectedFile ( ) = expr .getFile ( )
8989 }
9090
91- /**
92- * Holds if `path` is relative, in the sense that it should be resolved relative to its enclosing folder.
93- */
94- bindingset [ path]
95- pragma [ inline_late]
96- predicate isRelativePath ( string path ) { path .regexpMatch ( "\\.\\.?(?:[/\\\\].*)?" ) }
97-
9891 /**
9992 * Gets the NPM package name from the beginning of the given import path, e.g.
10093 * gets `foo` from `foo/bar`, and `@example/foo` from `@example/foo/bar`.
10194 */
10295 pragma [ nomagic]
10396 private string getPackagePrefixFromPathExpr ( RelevantExpr expr ) {
104- result = expr .getValue ( ) . regexpFind ( "^(@[^/\\\\]+[/\\\\])?[^@./\\\\][^/\\\\]*" , _ , _ )
97+ result = getPackagePrefixFromString ( expr .getValue ( ) )
10598 }
10699
107100 /**
You can’t perform that action at this time.
0 commit comments