Skip to content

Commit

Permalink
lib: don't match sourceMappingURL in strings
Browse files Browse the repository at this point in the history
Prior to this change `sourceMappingURL` in string where being matched
by the RegExp which caused sourcemaps not be loaded when using the
`--enable-source-maps` flag. This commit changes the RegExp to match
the last occurrence.

Fixes: #44654
  • Loading branch information
alan-agius4 committed Sep 15, 2022
1 parent aa64ff6 commit 51f24d5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/internal/source_map/source_map_cache.js
Expand Up @@ -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=(?<sourceMappingURL>[^\s]+)/;
const kSourceURLMagicComment = /\/[*/]#\s+sourceURL=(?<sourceURL>[^\s]+)/;
const kSourceMappingURLMagicComment = /\/[*/]#\s+sourceMappingURL=(?<sourceMappingURL>[^\s]+)[\s]*$/;
const kSourceURLMagicComment = /\/[*/]#\s+sourceURL=(?<sourceURL>[^\s]+)[\s]*$/;

const { fileURLToPath, pathToFileURL, URL } = require('internal/url');
let SourceMap;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions 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);
}
3 changes: 3 additions & 0 deletions test/message/source_map_sourcemapping_url_string.out
@@ -0,0 +1,3 @@
reachable
Error: an exception
at *typescript-sourcemapping_url_string.ts:3:7*

0 comments on commit 51f24d5

Please sign in to comment.