* Compute the URL of a source given the the source root, the source's * URL, and the source map's URL.
(sourceRoot, sourceURL, sourceMapURL)
| 2771 | * URL, and the source map's URL. |
| 2772 | */ |
| 2773 | function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) { |
| 2774 | // The source map spec states that "sourceRoot" and "sources" entries are to be appended. While |
| 2775 | // that is a little vague, implementations have generally interpreted that as joining the |
| 2776 | // URLs with a `/` between then, assuming the "sourceRoot" doesn't already end with one. |
| 2777 | // For example, |
| 2778 | // |
| 2779 | // sourceRoot: "some-dir", |
| 2780 | // sources: ["/some-path.js"] |
| 2781 | // |
| 2782 | // and |
| 2783 | // |
| 2784 | // sourceRoot: "some-dir/", |
| 2785 | // sources: ["/some-path.js"] |
| 2786 | // |
| 2787 | // must behave as "some-dir/some-path.js". |
| 2788 | // |
| 2789 | // With this library's the transition to a more URL-focused implementation, that behavior is |
| 2790 | // preserved here. To acheive that, we trim the "/" from absolute-path when a sourceRoot value |
| 2791 | // is present in order to make the sources entries behave as if they are relative to the |
| 2792 | // "sourceRoot", as they would have if the two strings were simply concated. |
| 2793 | if (sourceRoot && getURLType(sourceURL) === "path-absolute") { |
| 2794 | sourceURL = sourceURL.replace(/^\//, ""); |
| 2795 | } |
| 2796 | |
| 2797 | let url = normalize(sourceURL || ""); |
| 2798 | |
| 2799 | // Parsing URLs can be expensive, so we only perform these joins when needed. |
| 2800 | if (sourceRoot) url = join(sourceRoot, url); |
| 2801 | if (sourceMapURL) url = join(trimFilename(sourceMapURL), url); |
| 2802 | return url; |
| 2803 | } |
| 2804 | exports.computeSourceURL = computeSourceURL; |
| 2805 | |
| 2806 |
nothing calls this directly
no test coverage detected
searching dependent graphs…