(sourceRoot, sourceURL, sourceMapURL)
| 437 | * URL, and the source map's URL. |
| 438 | */ |
| 439 | export function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) { |
| 440 | sourceURL = sourceURL || ''; |
| 441 | |
| 442 | if (sourceRoot) { |
| 443 | // This follows what Chrome does. |
| 444 | if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') { |
| 445 | sourceRoot += '/'; |
| 446 | } |
| 447 | // The spec says: |
| 448 | // Line 4: An optional source root, useful for relocating source |
| 449 | // files on a server or removing repeated values in the |
| 450 | // “sources” entry. This value is prepended to the individual |
| 451 | // entries in the “source” field. |
| 452 | sourceURL = sourceRoot + sourceURL; |
| 453 | } |
| 454 | |
| 455 | // Historically, SourceMapConsumer did not take the sourceMapURL as |
| 456 | // a parameter. This mode is still somewhat supported, which is why |
| 457 | // this code block is conditional. However, it's preferable to pass |
| 458 | // the source map URL to SourceMapConsumer, so that this function |
| 459 | // can implement the source URL resolution algorithm as outlined in |
| 460 | // the spec. This block is basically the equivalent of: |
| 461 | // new URL(sourceURL, sourceMapURL).toString() |
| 462 | // ... except it avoids using URL, which wasn't available in the |
| 463 | // older releases of node still supported by this library. |
| 464 | // |
| 465 | // The spec says: |
| 466 | // If the sources are not absolute URLs after prepending of the |
| 467 | // “sourceRoot”, the sources are resolved relative to the |
| 468 | // SourceMap (like resolving script src in a html document). |
| 469 | if (sourceMapURL) { |
| 470 | var parsed = urlParse(sourceMapURL); |
| 471 | if (!parsed) { |
| 472 | throw new Error("sourceMapURL could not be parsed"); |
| 473 | } |
| 474 | if (parsed.path) { |
| 475 | // Strip the last path component, but keep the "/". |
| 476 | var index = parsed.path.lastIndexOf('/'); |
| 477 | if (index >= 0) { |
| 478 | parsed.path = parsed.path.substring(0, index + 1); |
| 479 | } |
| 480 | } |
| 481 | sourceURL = join(urlGenerate(parsed), sourceURL); |
| 482 | } |
| 483 | |
| 484 | return normalize(sourceURL); |
| 485 | } |
nothing calls this directly
no test coverage detected