* Applies the mappings of a sub-source-map for a specific source file to the * source map being generated. Each mapping to the supplied source file is * rewritten using the supplied source map. Note: The resolution for the * resulting mappings is the minimium of this map and the supplied ma
(aSourceMapConsumer, aSourceFile, aSourceMapPath)
| 174 | * relative to the SourceMapGenerator. |
| 175 | */ |
| 176 | applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { |
| 177 | let sourceFile = aSourceFile; |
| 178 | // If aSourceFile is omitted, we will use the file property of the SourceMap |
| 179 | if (aSourceFile == null) { |
| 180 | if (aSourceMapConsumer.file == null) { |
| 181 | throw new Error( |
| 182 | "SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, " + |
| 183 | 'or the source map\'s "file" property. Both were omitted.' |
| 184 | ); |
| 185 | } |
| 186 | sourceFile = aSourceMapConsumer.file; |
| 187 | } |
| 188 | const sourceRoot = this._sourceRoot; |
| 189 | // Make "sourceFile" relative if an absolute Url is passed. |
| 190 | if (sourceRoot != null) { |
| 191 | sourceFile = util.relative(sourceRoot, sourceFile); |
| 192 | } |
| 193 | // Applying the SourceMap can add and remove items from the sources and |
| 194 | // the names array. |
| 195 | const newSources = |
| 196 | this._mappings.toArray().length > 0 ? new ArraySet() : this._sources; |
| 197 | const newNames = new ArraySet(); |
| 198 | |
| 199 | // Find mappings for the "sourceFile" |
| 200 | this._mappings.unsortedForEach(function (mapping) { |
| 201 | if (mapping.source === sourceFile && mapping.originalLine != null) { |
| 202 | // Check if it can be mapped by the source map, then update the mapping. |
| 203 | const original = aSourceMapConsumer.originalPositionFor({ |
| 204 | line: mapping.originalLine, |
| 205 | column: mapping.originalColumn, |
| 206 | }); |
| 207 | if (original.source != null) { |
| 208 | // Copy mapping |
| 209 | mapping.source = original.source; |
| 210 | if (aSourceMapPath != null) { |
| 211 | mapping.source = util.join(aSourceMapPath, mapping.source); |
| 212 | } |
| 213 | if (sourceRoot != null) { |
| 214 | mapping.source = util.relative(sourceRoot, mapping.source); |
| 215 | } |
| 216 | mapping.originalLine = original.line; |
| 217 | mapping.originalColumn = original.column; |
| 218 | if (original.name != null) { |
| 219 | mapping.name = original.name; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | const source = mapping.source; |
| 225 | if (source != null && !newSources.has(source)) { |
| 226 | newSources.add(source); |
| 227 | } |
| 228 | |
| 229 | const name = mapping.name; |
| 230 | if (name != null && !newNames.has(name)) { |
| 231 | newNames.add(name); |
| 232 | } |
| 233 | }, this); |
no test coverage detected