Files
codeql/javascript/ql/lib/semmle/javascript/SourceMaps.qll
2024-09-03 20:30:58 +02:00

27 lines
883 B
Plaintext

/** Provides a class for representing source maps. */
import javascript
/**
* A source mapping comment associating a source map with a file.
*/
class SourceMappingComment extends Comment {
/** The `url` is a `sourceMappingURL` embedded in this comment. */
string url;
SourceMappingComment() {
exists(string sourceMappingUrlRegex |
sourceMappingUrlRegex = "[@#]\\s*sourceMappingURL\\s*=\\s*(.*)\\s*"
|
// either a line comment whose entire text matches the regex...
url = this.(SlashSlashComment).getText().regexpCapture(sourceMappingUrlRegex, 1)
or
// ...or a block comment one of whose lines matches the regex
url = this.(SlashStarComment).getLine(_).regexpCapture("//" + sourceMappingUrlRegex, 1)
)
}
/** Gets the URL of the source map referenced by this comment. */
string getSourceMappingUrl() { result = url }
}