* Populates the source map registry of a given module * Extracts the source map URL from the given code, parses the source map and build the SourceMapConsumer * This function will fail gracefully and not throw * * @param {string} text The JS code of the module * @param {stri
(text, uri, absoluteUri)
| 135 | * sourceMappingURL definition. This is only used for non-module files. |
| 136 | */ |
| 137 | populateSourceMap(text, uri, absoluteUri) { |
| 138 | if (!text) |
| 139 | return; |
| 140 | const sourceMapUrl = extractUrl(text); |
| 141 | if (!sourceMapUrl) |
| 142 | return; |
| 143 | |
| 144 | let jsonText = null; |
| 145 | try { |
| 146 | // check if we have an inlined data uri |
| 147 | if (sourceMapUrl?.startsWith(DATA_URI_PREFIX)) { |
| 148 | jsonText = atob(sourceMapUrl.substring(DATA_URI_PREFIX.length)); |
| 149 | } else { |
| 150 | // load the source map resource or file |
| 151 | // resolve the source map file relative to the source file |
| 152 | const sourceMapUri = resolveRelativeResourceOrFile(absoluteUri ?? uri, |
| 153 | `./${sourceMapUrl}`); |
| 154 | jsonText = this.loadURI(sourceMapUri); |
| 155 | } |
| 156 | } catch {} |
| 157 | |
| 158 | if (jsonText) { |
| 159 | try { |
| 160 | const sourceMapRegistry = getSourceMapRegistry(this.global); |
| 161 | const sourceMap = JSON.parse(jsonText); |
| 162 | const consumer = new SourceMapConsumer(sourceMap); |
| 163 | |
| 164 | sourceMapRegistry.set(uri, consumer); |
| 165 | } catch {} |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Resolves a module import with optional handling for relative imports. |
no test coverage detected