8
8
var coffee = require ( 'coffee-script' ) ,
9
9
originalCompileFile = coffee . _compileFile ,
10
10
minimatch = require ( 'minimatch' ) ,
11
+ extend = require ( 'xtend' ) ,
12
+ convert = require ( 'convert-source-map' ) ,
11
13
espowerSource = require ( 'espower-source' ) ;
12
14
13
15
function espowerCoffee ( options ) {
@@ -17,15 +19,18 @@ function espowerCoffee (options) {
17
19
pattern = options . cwd + separator + options . pattern ;
18
20
19
21
coffee . _compileFile = function ( filepath , sourceMap ) {
20
- var answer = originalCompileFile ( filepath , sourceMap ) ;
22
+ var withMap = originalCompileFile ( filepath , true ) ; // enable sourcemaps
21
23
if ( minimatch ( filepath , pattern ) ) {
22
- if ( sourceMap ) {
23
- answer . js = espowerSource ( answer . js , filepath , options . espowerOptions ) ;
24
- } else {
25
- answer = espowerSource ( answer , filepath , options . espowerOptions ) ;
26
- }
24
+ var conv = convert . fromJSON ( withMap . v3SourceMap ) ;
25
+ // restore filepath since coffeescript compiler drops it
26
+ conv . setProperty ( 'sources' , [ filepath ] ) ;
27
+ withMap . js = espowerSource (
28
+ withMap . js ,
29
+ filepath ,
30
+ extend ( options . espowerOptions , { sourceMap : conv . toObject ( ) } )
31
+ ) ;
27
32
}
28
- return answer ;
33
+ return sourceMap ? withMap : withMap . js ;
29
34
} ;
30
35
31
36
coffee . register ( ) ;
0 commit comments