* Return a snippet of code from where the exception was originally thrown * above the stack trace. This called from GetErrorSource in node_errors.cc. * @param {import('internal/source_map/source_map').SourceMap} sourceMap - the source map to be used * @param {string} originalSourcePath - path or
( sourceMap, originalSourcePath, originalLine, originalColumn, )
| 147 | * @returns {string | undefined} - the exact line in the source content or undefined if file not found |
| 148 | */ |
| 149 | function getErrorSource( |
| 150 | sourceMap, |
| 151 | originalSourcePath, |
| 152 | originalLine, |
| 153 | originalColumn, |
| 154 | ) { |
| 155 | const line = getSourceLine(sourceMap, originalSourcePath, originalLine); |
| 156 | if (!line) { |
| 157 | return; |
| 158 | } |
| 159 | const originalSourcePathNoScheme = |
| 160 | StringPrototypeStartsWith(originalSourcePath, 'file://') ? |
| 161 | fileURLToPath(originalSourcePath) : originalSourcePath; |
| 162 | |
| 163 | // Display ^ in appropriate position, regardless of whether tabs or |
| 164 | // spaces are used: |
| 165 | let prefix = ''; |
| 166 | for (const character of new SafeStringIterator( |
| 167 | StringPrototypeSlice(line, 0, originalColumn + 1))) { |
| 168 | prefix += character === '\t' ? '\t' : |
| 169 | StringPrototypeRepeat(' ', getStringWidth(character)); |
| 170 | } |
| 171 | prefix = StringPrototypeSlice(prefix, 0, -1); // The last character is '^'. |
| 172 | |
| 173 | const exceptionLine = |
| 174 | `${originalSourcePathNoScheme}:${originalLine + 1}\n${line}\n${prefix}^\n`; |
| 175 | return exceptionLine; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Retrieve exact line in the original source code from the source map's `sources` list or disk. |
no test coverage detected
searching dependent graphs…