diff --git a/lib/internal/source_map/source_map_cache.js b/lib/internal/source_map/source_map_cache.js index 60852a4f439037..7fd3d3bc06bfec 100644 --- a/lib/internal/source_map/source_map_cache.js +++ b/lib/internal/source_map/source_map_cache.js @@ -41,8 +41,8 @@ const esmSourceMapCache = new SafeMap(); // The generated sources is not mutable, so we can use a Map without memory concerns: const generatedSourceMapCache = new SafeMap(); const kLeadingProtocol = /^\w+:\/\//; -const kSourceMappingURLMagicComment = /\/[*/]#\s+sourceMappingURL=(?[^\s]+)/; -const kSourceURLMagicComment = /\/[*/]#\s+sourceURL=(?[^\s]+)/; +const kSourceMappingURLMagicComment = /\/[*/]#\s+sourceMappingURL=(?[^\s]+)(?:\s*\*\/)?\s*$/; +const kSourceURLMagicComment = /\/[*/]#\s+sourceURL=(?[^\s]+)(?:\s*\*\/)?\s*$/; const { fileURLToPath, pathToFileURL, URL } = require('internal/url'); let SourceMap; diff --git a/test/fixtures/source-map/typescript-sourcemapping_url_string.js b/test/fixtures/source-map/typescript-sourcemapping_url_string.js new file mode 100644 index 00000000000000..4fd62da9424ac3 --- /dev/null +++ b/test/fixtures/source-map/typescript-sourcemapping_url_string.js @@ -0,0 +1,4 @@ +"use strict"; +const content = '/*# sourceMappingURL='; +throw new Error('an exception.'); +//# sourceMappingURL=typescript-sourcemapping_url_string.js.map diff --git a/test/fixtures/source-map/typescript-sourcemapping_url_string.js.map b/test/fixtures/source-map/typescript-sourcemapping_url_string.js.map new file mode 100644 index 00000000000000..cbb2d46f169df2 --- /dev/null +++ b/test/fixtures/source-map/typescript-sourcemapping_url_string.js.map @@ -0,0 +1 @@ +{"version":3,"file":"typescript-sourcemapping_url_string.js","sourceRoot":"","sources":["typescript-sourcemapping_url_string.ts"],"names":[],"mappings":";AAAA,MAAM,OAAO,GAAG,uBAAuB,CAAC;AAExC,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC"} diff --git a/test/message/source_map_sourcemapping_url_string.js b/test/message/source_map_sourcemapping_url_string.js new file mode 100644 index 00000000000000..254d18bd080e53 --- /dev/null +++ b/test/message/source_map_sourcemapping_url_string.js @@ -0,0 +1,13 @@ +// Flags: --enable-source-maps + +'use strict'; +require('../common'); +Error.stackTraceLimit = 2; + +try { + require('../fixtures/source-map/typescript-sourcemapping_url_string'); +} catch (err) { + setTimeout(() => { + console.info(err); + }, 10); +} diff --git a/test/message/source_map_sourcemapping_url_string.out b/test/message/source_map_sourcemapping_url_string.out new file mode 100644 index 00000000000000..0978f773b4001d --- /dev/null +++ b/test/message/source_map_sourcemapping_url_string.out @@ -0,0 +1,3 @@ +reachable +Error: an exception + at *typescript-sourcemapping_url_string.ts:3:7*