Skip to content

Commit 69012b9

Browse files
committed
Ensure source snippets also output URLs/paths in the correct format, matching stack frame
1 parent 2b315b8 commit 69012b9

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

source-map-support.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,12 +617,12 @@ function getErrorSource(error) {
617617
// Support the inline sourceContents inside the source map
618618
var contents = getFileContentsCache(source);
619619

620-
source = tryFileURLToPath(source);
620+
const sourceAsPath = tryFileURLToPath(source);
621621

622622
// Support files on disk
623-
if (!contents && fs && fs.existsSync(source)) {
623+
if (!contents && fs && fs.existsSync(sourceAsPath)) {
624624
try {
625-
contents = fs.readFileSync(source, 'utf8');
625+
contents = fs.readFileSync(sourceAsPath, 'utf8');
626626
} catch (er) {
627627
contents = '';
628628
}

test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ it('native function', async function() {
446446
'[1].map(function(x) { throw new Error(x); });'
447447
], [
448448
'Error: 1',
449-
re`[/\\].original-${id}.js`,
449+
re`${stackFramePathStartsWith()}(?:.*[/\\])?.original-${id}.js`,
450450
/at Array\.map \((native|<anonymous>)\)/
451451
]);
452452
});
@@ -475,7 +475,7 @@ it('throw in Timeout with empty source map', function(done) {
475475
' throw new Error("this is the error")',
476476
'})'
477477
], [
478-
re`[/\\].generated-${id}.${extension}:3$`,
478+
re`${stackFramePathStartsWith()}(?:.*[/\\])?.generated-${id}.${extension}:3$`,
479479
' throw new Error("this is the error")',
480480
/^ \^$/,
481481
'Error: this is the error',
@@ -544,7 +544,7 @@ it('default options', function(done) {
544544
'process.nextTick(foo);',
545545
'process.nextTick(function() { process.exit(1); });'
546546
], [
547-
re`[/\\].original-${id}\.js:1$`,
547+
re`${stackFramePathStartsWith()}(?:.*[/\\])?.original-${id}\.js:1$`,
548548
'this is the original code',
549549
'^',
550550
'Error: this is the error',
@@ -559,7 +559,7 @@ it('handleUncaughtExceptions is true', function(done) {
559559
'require("./source-map-support").install({ handleUncaughtExceptions: true });',
560560
'process.nextTick(foo);'
561561
], [
562-
re`[/\\].original-${id}\.js:1$`,
562+
re`${stackFramePathStartsWith()}(?:.*[/\\])?.original-${id}\.js:1$`,
563563
'this is the original code',
564564
'^',
565565
'Error: this is the error',
@@ -574,7 +574,7 @@ it('handleUncaughtExceptions is false', function(done) {
574574
'require("./source-map-support").install({ handleUncaughtExceptions: false });',
575575
'process.nextTick(foo);'
576576
], [
577-
re`[/\\].generated-${id}.${extension}:2$`,
577+
re`${stackFramePathStartsWith()}(?:.*[/\\])?.generated-${id}.${extension}:2$`,
578578
'function foo() { throw new Error("this is the error"); }',
579579

580580
' ^',
@@ -591,7 +591,7 @@ it('default options with empty source map', function(done) {
591591
'require("./source-map-support").install();',
592592
'process.nextTick(foo);'
593593
], [
594-
re`[/\\].generated-${id}.${extension}:2$`,
594+
re`${stackFramePathStartsWith()}(?:.*[/\\])?.generated-${id}.${extension}:2$`,
595595
'function foo() { throw new Error("this is the error"); }',
596596
' ^',
597597
'Error: this is the error',
@@ -606,7 +606,7 @@ it('default options with source map with gap', function(done) {
606606
'require("./source-map-support").install();',
607607
'process.nextTick(foo);'
608608
], [
609-
re`[/\\].generated-${id}.${extension}:2$`,
609+
re`${stackFramePathStartsWith()}(?:.*[/\\])?.generated-${id}.${extension}:2$`,
610610
'function foo() { throw new Error("this is the error"); }',
611611
' ^',
612612
'Error: this is the error',
@@ -637,7 +637,7 @@ it('sourcesContent', function(done) {
637637
'process.nextTick(foo);',
638638
'process.nextTick(function() { process.exit(1); });'
639639
], [
640-
re`[/\\]original-${id}\.js:1002$`,
640+
re`${stackFramePathStartsWith()}(?:.*[/\\])?original-${id}\.js:1002$`,
641641
' line 2',
642642
' ^',
643643
'Error: this is the error',
@@ -851,7 +851,7 @@ it('supports multiple instances', function(done) {
851851
' process.nextTick(function() { process.exit(1); });',
852852
'})();'
853853
], [
854-
re`[/\\].original2-${id}\.js:1$`,
854+
re`${stackFramePathStartsWith()}(?:.*[/\\])?.original2-${id}\.js:1$`,
855855
'this is some other original code',
856856
'^',
857857
'Error: this is the error',

0 commit comments

Comments
 (0)