(context, sourceMap, associatedObjectForCache)
| 652 | * @returns {string | RawSourceMap} new source map |
| 653 | */ |
| 654 | const contextifySourceMap = (context, sourceMap, associatedObjectForCache) => { |
| 655 | if (typeof sourceMap === "string" || !Array.isArray(sourceMap.sources)) { |
| 656 | return sourceMap; |
| 657 | } |
| 658 | const { sourceRoot } = sourceMap; |
| 659 | /** @type {(source: string) => string} */ |
| 660 | const mapper = !sourceRoot |
| 661 | ? (source) => source |
| 662 | : sourceRoot.endsWith("/") |
| 663 | ? (source) => |
| 664 | source.startsWith("/") |
| 665 | ? `${sourceRoot.slice(0, -1)}${source}` |
| 666 | : `${sourceRoot}${source}` |
| 667 | : (source) => |
| 668 | source.startsWith("/") |
| 669 | ? `${sourceRoot}${source}` |
| 670 | : `${sourceRoot}/${source}`; |
| 671 | const newSources = sourceMap.sources.map((source) => |
| 672 | contextifySourceUrl(context, mapper(source), associatedObjectForCache) |
| 673 | ); |
| 674 | return { |
| 675 | ...sourceMap, |
| 676 | file: "x", |
| 677 | sourceRoot: undefined, |
| 678 | sources: newSources |
| 679 | }; |
| 680 | }; |
| 681 | |
| 682 | /** |
| 683 | * @param {string | Buffer} input the input |
no test coverage detected