Skip to content

Commit f0c50c6

Browse files
committed
Add rewritePathSegment to Folder::Resolve
1 parent c852c62 commit f0c50c6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

shared/util/codeql/util/FileSystem.qll

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,15 @@ module Make<InputSig Input> {
267267
* - Complex patterns like `foo-*.txt` are also supported
268268
*/
269269
default predicate allowGlobs() { none() }
270+
271+
/**
272+
* Gets an alternative path segment to try if `segment` did not match a child.
273+
*
274+
* The motivating use-case is to map compiler-generated file names back to their sources files,
275+
* for example, `foo.min.js` could be mapped to `foo.ts`.
276+
*/
277+
bindingset[segment]
278+
default string rewritePathSegment(string segment) { none() }
270279
}
271280

272281
/**
@@ -317,9 +326,13 @@ module Make<InputSig Input> {
317326
segment = ".." and
318327
result = current.getParentContainer()
319328
or
320-
isOptionalPathComponent(segment) and
321329
not exists(getChild(current, segment)) and
322-
result = current
330+
(
331+
isOptionalPathComponent(segment) and
332+
result = current
333+
or
334+
result = getChild(current, rewritePathSegment(segment))
335+
)
323336
or
324337
allowGlobs() and
325338
(

0 commit comments

Comments
 (0)