@@ -29,6 +29,15 @@ import {
2929import type { RawSourceMap } from 'source-map' ;
3030import { SourceMapConsumer , SourceMapGenerator } from 'source-map' ;
3131
32+ /**
33+ * we can only use SourceMapConsumer if the version available has a destroy method
34+ * see https://github.com/mozilla/source-map/blob/master/CHANGELOG.md#070
35+ */
36+ const canUseSourceMapConsumer =
37+ typeof SourceMapConsumer === 'function' &&
38+ typeof SourceMapConsumer . prototype === 'object' &&
39+ typeof SourceMapConsumer . prototype . destroy === 'function' ;
40+
3241const loaderOptionsCache : LoaderOptionsCache = { } ;
3342
3443/**
@@ -140,14 +149,15 @@ function makeSourceMapAndFinish(
140149
141150 setModuleMeta ( loaderContext , instance , fileVersion ) ;
142151
143- // there are two cases where we don't need to perform input source map mapping:
152+ // there are three cases where we don't need to perform input source map mapping:
144153 // - either the ts-compiler did not generate a source map (tsconfig had `sourceMap` set to false)
145154 // - or we did not get an input source map
155+ // - or the version of source-map available does not have a destroy method
146156 //
147157 // in the first case, we simply return undefined.
148- // in the second case we only need to return the newly generated source map
158+ // in the second / third cases we only need to return the newly generated source map
149159 // this avoids that we have to make a possibly expensive call to the source-map lib
150- if ( sourceMap === undefined || ! inputSourceMap ) {
160+ if ( sourceMap === undefined || ! inputSourceMap || ! canUseSourceMapConsumer ) {
151161 callback ( null , output , sourceMap ) ;
152162 return ;
153163 }
0 commit comments