diff options
| author | bcoe <bencoe@google.com> | 2020-05-24 16:00:46 -0700 |
|---|---|---|
| committer | Benjamin Coe <bencoe@google.com> | 2020-05-24 22:03:34 -0700 |
| commit | 458677f5ef2bd35da920246bb266502ea76bb66c (patch) | |
| tree | e1809f38c6bbbf898287513a062ad588ba32e43d /lib/internal/source_map/source_map_cache.js | |
| parent | 8f10bb2da5bcf166fa1b414055f03352bbdb8126 (diff) | |
| download | node-new-458677f5ef2bd35da920246bb266502ea76bb66c.tar.gz | |
errors: print original exception context
When --enable-source-maps is set, the error context displayed
above the stack trace now shows original source rather than
transpiled.
PR-URL: https://github.com/nodejs/node/pull/33491
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'lib/internal/source_map/source_map_cache.js')
| -rw-r--r-- | lib/internal/source_map/source_map_cache.js | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/internal/source_map/source_map_cache.js b/lib/internal/source_map/source_map_cache.js index 06b1a2a5f5..04926acfc1 100644 --- a/lib/internal/source_map/source_map_cache.js +++ b/lib/internal/source_map/source_map_cache.js @@ -39,12 +39,28 @@ const { fileURLToPath, URL } = require('url'); let Module; let SourceMap; -let experimentalSourceMaps; -function maybeCacheSourceMap(filename, content, cjsModuleInstance) { - if (experimentalSourceMaps === undefined) { - experimentalSourceMaps = getOptionValue('--enable-source-maps'); +let sourceMapsEnabled; +function getSourceMapsEnabled() { + if (sourceMapsEnabled === undefined) { + sourceMapsEnabled = getOptionValue('--enable-source-maps'); + if (sourceMapsEnabled) { + const { + enableSourceMaps, + setPrepareStackTraceCallback + } = internalBinding('errors'); + const { + prepareStackTrace + } = require('internal/source_map/prepare_stack_trace'); + setPrepareStackTraceCallback(prepareStackTrace); + enableSourceMaps(); + } } - if (!(process.env.NODE_V8_COVERAGE || experimentalSourceMaps)) return; + return sourceMapsEnabled; +} + +function maybeCacheSourceMap(filename, content, cjsModuleInstance) { + const sourceMapsEnabled = getSourceMapsEnabled(); + if (!(process.env.NODE_V8_COVERAGE || sourceMapsEnabled)) return; let basePath; try { filename = normalizeReferrerURL(filename); @@ -248,6 +264,7 @@ function findSourceMap(uri, error) { module.exports = { findSourceMap, + getSourceMapsEnabled, maybeCacheSourceMap, rekeySourceMap, sourceMapCacheToObject, |
