@@ -6,9 +6,8 @@ import unassertjs from 'unassert';
6
6
import convert from 'convert-source-map' ;
7
7
import { transfer } from 'multi-stage-sourcemap' ;
8
8
9
- // The following utility functions are adapted from
10
- // https://github.com/unassert-js/unassertify/blob/master/index.js
11
- // by Takuto Wada (which is under MIT license)
9
+ // Adapted from https://github.com/unassert-js/unassertify/blob/master/index.js
10
+ // by Takuto Wada (MIT-licensed)
12
11
13
12
function handleIncomingSourceMap ( originalCode ) {
14
13
const commented = convert . fromSource ( originalCode ) ;
@@ -43,7 +42,6 @@ function mergeSourceMap(incomingSourceMap, outgoingSourceMap) {
43
42
}
44
43
45
44
export default function unassert ( options = { } ) {
46
-
47
45
if ( options . sourcemap === undefined ) {
48
46
options . sourcemap = true ;
49
47
}
@@ -58,35 +56,24 @@ export default function unassert(options = {}) {
58
56
if ( ! filter ( id ) ) { return null ; }
59
57
60
58
return new Promise ( ( resolve ) => {
61
-
62
- // The following piece of code is adapted from
63
- // https://github.com/unassert-js/unassertify/blob/master/index.js
64
- // by Takuto Wada (which is under MIT license)
65
59
const ast = acorn . parse ( code , { sourceType : 'module' , locations : true } ) ;
66
-
67
- const inMap = options . sourcemap && handleIncomingSourceMap ( code ) ;
68
60
const unassertedAst = escodegen . generate ( unassertjs ( ast ) , {
69
61
sourceMap : id ,
70
62
sourceContent : code ,
71
63
sourceMapWithCode : true
72
64
} ) ;
73
- const outMap = convert . fromJSON ( unassertedAst . map . toString ( ) ) ;
74
65
66
+ const inMap = options . sourcemap && handleIncomingSourceMap ( code ) ;
67
+ let outMap = convert . fromJSON ( unassertedAst . map . toString ( ) ) ;
75
68
if ( inMap ) {
76
- const reMap = reconnectSourceMap ( inMap , outMap ) ;
77
- resolve ( {
78
- code : unassertedAst . code ,
79
- map : reMap . toObject ( )
80
- } ) ;
81
- } else {
82
- resolve ( {
83
- code : unassertedAst . code ,
84
- map : outMap . toObject ( )
85
- } ) ;
69
+ outMap = reconnectSourceMap ( inMap , outMap ) ;
86
70
}
87
71
72
+ resolve ( {
73
+ code : unassertedAst . code ,
74
+ map : outMap . toObject ( )
75
+ } ) ;
88
76
} ) ;
89
-
90
77
}
91
78
} ;
92
79
}
0 commit comments