File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,13 @@ export default function mergeSourceMap(
3838 if ( typeof inputMap . sourceRoot === "string" ) {
3939 result . sourceRoot = inputMap . sourceRoot ;
4040 }
41- return result ;
41+
42+ // remapping returns a SourceMap class type, but this breaks code downstream in
43+ // @babel /traverse and @babel /types that relies on data being plain objects.
44+ // When it encounters the sourcemap type it outputs a "don't know how to turn
45+ // this value into a node" error. As a result, we are converting the merged
46+ // sourcemap to a plain js object.
47+ return { ...result } ;
4248}
4349
4450function rootless ( map : SourceMap ) : SourceMap {
Original file line number Diff line number Diff line change 1+ import _mergeSourceMap from "../lib/transformation/file/merge-map.js" ;
2+ const mergeSourceMap = _mergeSourceMap . default ;
3+
4+ describe ( "merge-map" , ( ) => {
5+ it ( "returns a plain js object" , ( ) => {
6+ const inputMap = {
7+ file : "file.js" ,
8+ mappings : [ ] ,
9+ names : [ ] ,
10+ sources : [ "file.ts" ] ,
11+ version : 3 ,
12+ } ;
13+
14+ const outputMap = {
15+ file : "file.transpiled.js" ,
16+ mappings : [ ] ,
17+ names : [ ] ,
18+ sources : [ "file.js" ] ,
19+ version : 3 ,
20+ } ;
21+
22+ const map = mergeSourceMap ( inputMap , outputMap , "file.transpiled.js" ) ;
23+ expect ( typeof map ) . toBe ( "object" ) ;
24+ expect ( Object . prototype . toString . call ( map ) ) . toBe ( "[object Object]" ) ;
25+ expect ( Object . getPrototypeOf ( map ) ) . toBe ( Object . prototype ) ;
26+ } ) ;
27+ } ) ;
You can’t perform that action at this time.
0 commit comments