UNPKG

11.4 kBSource Map (JSON)View Raw
1{"version":3,"file":"ErrorFormatter.js","sourceRoot":"","sources":["../../../../src/lib/node/ErrorFormatter.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA,yBAAkC;IAClC,6BAAwD;IACxD,yCAA4D;IAE5D,oFAAsD;IACtD,+BAAuC;IAGvC;QAAgD,8CAAc;QAM5D,4BAAY,QAAc;YAA1B,YACE,kBAAM,QAAQ,CAAC,SAChB;YALO,oBAAc,GAA0C,EAAE,CAAC;YAC3D,iBAAW,GAA+B,EAAE,CAAC;;QAIrD,CAAC;QAKS,uCAAU,GAApB,UAAqB,SAAiB;YACpC,IAAI,SAAS,KAAK,aAAa,EAAE;gBAC/B,OAAO,WAAW,CAAC;aACpB;YAED,IAAI,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;YAClD,OAAO,UAAU,KAAK,SAAS,EAAE;gBAC/B,SAAS,GAAG,UAAU,CAAC;gBACvB,UAAU,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;aAC/C;YAED,OAAO,SAAS,CAAC;QACnB,CAAC;QAEO,6CAAgB,GAAxB,UAAyB,SAAiB;YACxC,IAAI,KAA8B,CAAC;YACnC,IAAI,MAA0B,CAAC;YAC/B,IAAI,IAAY,CAAC;YACjB,IAAI,GAAkB,CAAC;YACvB,IAAI,GAAkC,CAAC;YACvC,IAAI,WAIH,CAAC;YACF,IAAI,MAAc,CAAC;YAEnB,IAAI,CAAC,CAAC,KAAK,GAAG,sBAAsB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE;gBAErD,OAAO,SAAS,CAAC;aAClB;YAED,SAAS,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACrB,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACxB,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,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AO,CAAC,CAAC;oBAChD,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;iBACnC;gBAED,IAAM,MAAM,GAAG,oBAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;gBAC7C,IAAI,MAAM,EAAE;oBACV,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,GAAG,IAAI,8BAAiB,CAAC,MAAM,CAAC,CAAC;oBAC9D,OAAO,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;iBACtC;aACF;YAAC,OAAO,KAAK,EAAE;aAEf;QACH,CAAC;QACH,yBAAC;IAAD,CAAC,AA7ND,CAAgD,wBAAc,GA6N7D","sourcesContent":["import { readFileSync } from 'fs';\nimport { dirname, join, relative, resolve } from 'path';\nimport { MappingItem, SourceMapConsumer } from 'source-map';\n\nimport ErrorFormatter from '../common/ErrorFormatter';\nimport { readSourceMap } from './util';\nimport Node from '../executors/Node';\n\nexport default class NodeErrorFormatter extends ErrorFormatter {\n readonly executor!: Node;\n\n private fileSourceMaps: { [path: string]: SourceMapConsumer } = {};\n private fileSources: { [path: string]: string } = {};\n\n constructor(executor: Node) {\n super(executor);\n }\n\n /**\n * Dereference the source from a traceline.\n */\n protected _getSource(tracepath: string) {\n if (tracepath === '<anonymous>') {\n return 'anonymous';\n }\n\n let sourcepath = this._getSourceHelper(tracepath);\n while (sourcepath !== tracepath) {\n tracepath = sourcepath;\n sourcepath = this._getSourceHelper(tracepath);\n }\n\n return tracepath;\n }\n\n private _getSourceHelper(tracepath: string) {\n let match: RegExpMatchArray | null;\n let source: string | undefined;\n let line: number;\n let col: number | null;\n let map: SourceMapConsumer | undefined;\n let originalPos: {\n source?: string | null;\n line: number | null;\n column: number | null;\n };\n let result: string;\n\n if (!(match = /^(.*?):(\\d+)(:\\d+)?$/.exec(tracepath))) {\n // no line or column data\n return tracepath;\n }\n\n tracepath = match[1];\n line = Number(match[2]);\n col = match[3] ? Number(match[3].substring(1)) : null;\n\n // If the tracepath starts with the server URL, resolve it to something\n // local\n if (tracepath.indexOf(this.executor.config.serverUrl) === 0) {\n tracepath = tracepath.slice(this.executor.config.serverUrl.length);\n tracepath = tracepath.replace(\n /^__intern\\//,\n this.executor.config.internPath\n );\n }\n\n // Make the tracepath absolute since that's how it will be stored in map\n // stores\n tracepath = resolve(tracepath);\n\n const instrumentedStore = this.executor.instrumentedMapStore;\n\n // first, check for an instrumentation source map\n if (tracepath in instrumentedStore.data) {\n map = new SourceMapConsumer(instrumentedStore.data[tracepath].data);\n originalPos = this.getOriginalPosition(map, line, col);\n line = originalPos.line!;\n col = originalPos.column;\n if (originalPos.source) {\n source = originalPos.source;\n }\n }\n\n source = source || tracepath;\n\n // next, check for original source map\n const sourceMapStore = this.executor.sourceMapStore;\n if (source in sourceMapStore.data) {\n map = new SourceMapConsumer(sourceMapStore.data[source].data);\n } else {\n map = this.getSourceMap(source);\n }\n\n source = relative('.', source);\n\n if (map) {\n originalPos = this.getOriginalPosition(map, line, col);\n line = originalPos.line!;\n col = originalPos.column;\n if (originalPos.source) {\n // If original source starts with ./ or ../, or is just a bare\n // filename, assume it's relative to the current source\n if (\n originalPos.source.indexOf('/') === -1 ||\n /\\.\\.?\\//.test(originalPos.source)\n ) {\n source = join(dirname(source), originalPos.source);\n } else {\n // If not, assume its relative to the project root\n source = originalPos.source;\n }\n }\n }\n\n // Source should be relative, because that's what we want the user to\n // see\n source = relative('.', source);\n\n result = source + ':' + line;\n if (col !== null) {\n result += ':' + col;\n }\n return result;\n }\n\n /**\n * Get the original position of line:column based on map.\n *\n * Assumes mappings are is in order by generatedLine, then by\n * generatedColumn; maps created with SourceMapConsumer.eachMapping should\n * be in this order by default.\n */\n private getOriginalPosition(\n map: SourceMapConsumer,\n line: number,\n column: number | null\n ): { line: number | null; column: number | null; source?: string | null } {\n const originalPosition = map.originalPositionFor({\n line: line,\n column: column!,\n });\n\n // if the SourceMapConsumer was able to find a location, return it\n if (originalPosition.line != null) {\n return originalPosition;\n }\n\n const entries: MappingItem[] = [];\n\n // find all map entries that apply to the given line in the generated\n // output\n map.eachMapping(\n (entry) => {\n if (entry.generatedLine === line) {\n entries.push(entry);\n }\n },\n null,\n SourceMapConsumer.GENERATED_ORDER\n );\n\n if (entries.length === 0) {\n // no valid mappings exist -- return the line and column arguments\n return { line: line, column: column };\n }\n\n let position = entries[0];\n\n // Chrome/Node.js column is at the start of the term that generated the\n // exception IE column is at the beginning of the expression/line with\n // the exceptional term\n //\n // Safari column number is just after the exceptional term\n // - need to go back one element in the mapping\n //\n // Firefox, PhantomJS have no column number\n // - for no col number, find the largest original line number for the\n // generated line\n\n if (column != null) {\n // find the most likely mapping for the given generated line and\n // column\n let entry: MappingItem;\n for (let i = 1; i < entries.length; i++) {\n entry = entries[i];\n if (\n column > position.generatedColumn &&\n column >= entry.generatedColumn\n ) {\n position = entry;\n }\n }\n }\n\n return {\n line: position.originalLine,\n column: position.originalColumn,\n source: position.source,\n };\n }\n\n /**\n * Load and process the source map for a given file.\n */\n private getSourceMap(filepath: string) {\n if (filepath in this.fileSourceMaps) {\n return this.fileSourceMaps[filepath];\n }\n\n try {\n let data: string;\n\n if (filepath in this.fileSources) {\n data = this.fileSources[filepath];\n } else {\n data = readFileSync(filepath).toString('utf-8');\n this.fileSources[filepath] = data;\n }\n\n const rawMap = readSourceMap(filepath, data);\n if (rawMap) {\n this.fileSourceMaps[filepath] = new SourceMapConsumer(rawMap);\n return this.fileSourceMaps[filepath];\n }\n } catch (error) {\n // this is normal for files like node.js -- just return null\n }\n }\n}\n"]}
\No newline at end of file