* Compute the URL of a source given the the source root, the source's * URL, and the source map's URL.
(sourceRoot, sourceURL, sourceMapURL)
| 411 | * URL, and the source map's URL. |
| 412 | */ |
| 413 | function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) { |
| 414 | // The source map spec states that "sourceRoot" and "sources" entries are to be appended. While |
| 415 | // that is a little vague, implementations have generally interpreted that as joining the |
| 416 | // URLs with a `/` between then, assuming the "sourceRoot" doesn't already end with one. |
| 417 | // For example, |
| 418 | // |
| 419 | // sourceRoot: "some-dir", |
| 420 | // sources: ["/some-path.js"] |
| 421 | // |
| 422 | // and |
| 423 | // |
| 424 | // sourceRoot: "some-dir/", |
| 425 | // sources: ["/some-path.js"] |
| 426 | // |
| 427 | // must behave as "some-dir/some-path.js". |
| 428 | // |
| 429 | // With this library's the transition to a more URL-focused implementation, that behavior is |
| 430 | // preserved here. To acheive that, we trim the "/" from absolute-path when a sourceRoot value |
| 431 | // is present in order to make the sources entries behave as if they are relative to the |
| 432 | // "sourceRoot", as they would have if the two strings were simply concated. |
| 433 | if (sourceRoot && getURLType(sourceURL) === "path-absolute") { |
| 434 | sourceURL = sourceURL.replace(/^\//, ""); |
| 435 | } |
| 436 | |
| 437 | let url = normalize(sourceURL || ""); |
| 438 | |
| 439 | // Parsing URLs can be expensive, so we only perform these joins when needed. |
| 440 | if (sourceRoot) url = join(sourceRoot, url); |
| 441 | if (sourceMapURL) url = join(trimFilename(sourceMapURL), url); |
| 442 | return url; |
| 443 | } |
| 444 | exports.computeSourceURL = computeSourceURL; |
nothing calls this directly
no test coverage detected
searching dependent graphs…