(getModule?: GetModuleFn)
| 51 | |
| 52 | /** Node Stack line parser */ |
| 53 | export function node(getModule?: GetModuleFn): StackLineParserFn { |
| 54 | const FILENAME_MATCH = /^\s*[-]{4,}$/; |
| 55 | const FULL_MATCH = /at (?:async )?(?:(.+?)\s+\()?(?:(.+):(\d+):(\d+)?|([^)]+))\)?/; |
| 56 | const DATA_URI_MATCH = /at (?:async )?(.+?) \(data:(.*?),/; |
| 57 | |
| 58 | return (line: string) => { |
| 59 | const dataUriMatch = line.match(DATA_URI_MATCH); |
| 60 | if (dataUriMatch) { |
| 61 | return { |
| 62 | filename: `<data:${dataUriMatch[2]}>`, |
| 63 | function: dataUriMatch[1], |
| 64 | }; |
| 65 | } |
| 66 | |
| 67 | const lineMatch = line.match(FULL_MATCH); |
| 68 | |
| 69 | if (lineMatch) { |
| 70 | let object: string | undefined; |
| 71 | let method: string | undefined; |
| 72 | let functionName: string | undefined; |
| 73 | let typeName: string | undefined; |
| 74 | let methodName: string | undefined; |
| 75 | |
| 76 | if (lineMatch[1]) { |
| 77 | functionName = lineMatch[1]; |
| 78 | |
| 79 | let methodStart = functionName.lastIndexOf('.'); |
| 80 | if (functionName[methodStart - 1] === '.') { |
| 81 | methodStart--; |
| 82 | } |
| 83 | |
| 84 | if (methodStart > 0) { |
| 85 | object = functionName.slice(0, methodStart); |
| 86 | method = functionName.slice(methodStart + 1); |
| 87 | const objectEnd = object.indexOf('.Module'); |
| 88 | if (objectEnd > 0) { |
| 89 | functionName = functionName.slice(objectEnd + 1); |
| 90 | object = object.slice(0, objectEnd); |
| 91 | } |
| 92 | } |
| 93 | typeName = undefined; |
| 94 | } |
| 95 | |
| 96 | if (method) { |
| 97 | typeName = object; |
| 98 | methodName = method; |
| 99 | } |
| 100 | |
| 101 | if (method === '<anonymous>') { |
| 102 | methodName = undefined; |
| 103 | functionName = undefined; |
| 104 | } |
| 105 | |
| 106 | if (functionName === undefined) { |
| 107 | methodName = methodName || UNKNOWN_FUNCTION; |
| 108 | functionName = typeName ? `${typeName}.${methodName}` : methodName; |
| 109 | } |
| 110 |
no test coverage detected