* Pretty-prints the source. Generates a beauitified source map if possible * and it hasn't already been done, and returns the created map and created * ephemeral source. Returns undefined if the source can't be beautified.
()
| 206 | * ephemeral source. Returns undefined if the source can't be beautified. |
| 207 | */ |
| 208 | public async prettyPrint(): Promise<{ map: SourceMap; source: Source } | undefined> { |
| 209 | if (!this._container || !this.canPrettyPrint()) { |
| 210 | return undefined; |
| 211 | } |
| 212 | |
| 213 | if (isSourceWithMap(this) && this.sourceMap.url.endsWith('-pretty.map')) { |
| 214 | const map = this._container._sourceMaps.get(this.sourceMap?.url)?.map; |
| 215 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 216 | return map && { map, source: [...this.sourceMap.sourceByUrl!.values()][0] }; |
| 217 | } |
| 218 | |
| 219 | const content = await this.content(); |
| 220 | if (!content) { |
| 221 | return undefined; |
| 222 | } |
| 223 | |
| 224 | const sourceMapUrl = this.url + '-pretty.map'; |
| 225 | const basename = this.url.split(/[\/\\]/).pop() as string; |
| 226 | const fileName = basename + '-pretty.js'; |
| 227 | const map = await prettyPrintAsSourceMap(fileName, content, this.url, sourceMapUrl); |
| 228 | if (!map) { |
| 229 | return undefined; |
| 230 | } |
| 231 | |
| 232 | // Note: this overwrites existing source map. |
| 233 | this.setSourceMapUrl(sourceMapUrl); |
| 234 | const asCompiled = this as ISourceWithMap; |
| 235 | const sourceMap: SourceMapData = { |
| 236 | compiled: new Set([asCompiled]), |
| 237 | map, |
| 238 | loaded: Promise.resolve(), |
| 239 | }; |
| 240 | this._container._sourceMaps.set(sourceMapUrl, sourceMap); |
| 241 | await this._container._addSourceMapSources(asCompiled, map); |
| 242 | // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 243 | return { map, source: [...asCompiled.sourceMap.sourceByUrl.values()][0] }; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Returns a DAP representation of the source. |
no test coverage detected