forked from atom/atom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoffee-script.js
45 lines (37 loc) · 1.13 KB
/
coffee-script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict'
var crypto = require('crypto')
var path = require('path')
var CoffeeScript = null
exports.shouldCompile = function () {
return true
}
exports.getCachePath = function (sourceCode) {
return path.join(
'coffee',
crypto
.createHash('sha1')
.update(sourceCode, 'utf8')
.digest('hex') + '.js'
)
}
exports.compile = function (sourceCode, filePath) {
if (!CoffeeScript) {
var previousPrepareStackTrace = Error.prepareStackTrace
CoffeeScript = require('coffee-script')
// When it loads, coffee-script reassigns Error.prepareStackTrace. We have
// already reassigned it via the 'source-map-support' module, so we need
// to set it back.
Error.prepareStackTrace = previousPrepareStackTrace
}
if (process.platform === 'win32') {
filePath = 'file:///' + path.resolve(filePath).replace(/\\/g, '/')
}
var output = CoffeeScript.compile(sourceCode, {
filename: filePath,
sourceFiles: [filePath],
inlineMap: true
})
// Strip sourceURL from output so there wouldn't be duplicate entries
// in devtools.
return output.replace(/\/\/# sourceURL=[^'"\n]+\s*$/, '')
}