( fileName: string, minified: string, compiledPath: string, sourceMapUrl: string, )
| 11 | import { LineColumn } from '../adapter/breakpoints/breakpointBase'; |
| 12 | |
| 13 | export async function prettyPrintAsSourceMap( |
| 14 | fileName: string, |
| 15 | minified: string, |
| 16 | compiledPath: string, |
| 17 | sourceMapUrl: string, |
| 18 | ): Promise<SourceMap | undefined> { |
| 19 | const source = beautify(minified); |
| 20 | const from = generatePositions(source); |
| 21 | const to = generatePositions(minified); |
| 22 | if (from.length !== to.length) return Promise.resolve(undefined); |
| 23 | |
| 24 | const generator = new sourceMap.SourceMapGenerator(); |
| 25 | generator.setSourceContent(fileName, source); |
| 26 | |
| 27 | // We know that AST for both sources is the same, so we can |
| 28 | // walk them together to generate mapping. |
| 29 | for (let i = 0; i < from.length; i += 2) { |
| 30 | generator.addMapping({ |
| 31 | source: fileName, |
| 32 | original: { line: from[i], column: from[i + 1] }, |
| 33 | generated: { line: to[i], column: to[i + 1] }, |
| 34 | }); |
| 35 | } |
| 36 | return new SourceMap( |
| 37 | await sourceMap.SourceMapConsumer.fromSourceMap(generator), |
| 38 | { |
| 39 | sourceMapUrl, |
| 40 | compiledPath, |
| 41 | }, |
| 42 | '', |
| 43 | [fileName], |
| 44 | ); |
| 45 | } |
| 46 | |
| 47 | function generatePositions(text: string) { |
| 48 | const sourceFile = ts.createSourceFile( |
no test coverage detected