Skip to content

Commit aaec7b7

Browse files
committed
Avoid throwing JSON parsing errors for non-JSON source maps
1 parent 233fb26 commit aaec7b7

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

lib/previous-map.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class PreviousMap {
3030

3131
consumer() {
3232
if (!this.consumerCache) {
33-
this.consumerCache = new SourceMapConsumer(this.text)
33+
this.consumerCache = new SourceMapConsumer(this.json ?? this.text)
3434
}
3535
return this.consumerCache
3636
}
@@ -124,7 +124,15 @@ class PreviousMap {
124124
} else if (this.annotation) {
125125
let map = this.annotation
126126
if (file) map = join(dirname(file), map)
127-
return this.loadFile(map)
127+
let unknown = this.loadFile(map)
128+
if (unknown) {
129+
try {
130+
this.json = JSON.parse(unknown.replace(/^\)]}'[^\n]*\n/, ''))
131+
} catch (e) {
132+
return undefined
133+
}
134+
}
135+
return unknown
128136
}
129137
}
130138

0 commit comments

Comments
 (0)