Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12713 from Ingramz/copy-src
Browse files Browse the repository at this point in the history
Use inline source maps when transpiling coffee-script
  • Loading branch information
Max Brunsfeld committed Oct 1, 2016
2 parents 1e78cf9 + fd1e060 commit f58d70a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion spec/compile-cache-spec.coffee
Expand Up @@ -17,7 +17,7 @@ describe 'CompileCache', ->
CompileCache.resetCacheStats()

spyOn(Babel, 'transform').andReturn {code: 'the-babel-code'}
spyOn(CoffeeScript, 'compile').andReturn {js: 'the-coffee-code', v3SourceMap: "{}"}
spyOn(CoffeeScript, 'compile').andReturn 'the-coffee-code'
spyOn(TypeScriptSimple::, 'compile').andReturn 'the-typescript-code'

afterEach ->
Expand Down
11 changes: 4 additions & 7 deletions src/coffee-script.js
Expand Up @@ -36,13 +36,10 @@ exports.compile = function (sourceCode, filePath) {
var output = CoffeeScript.compile(sourceCode, {
filename: filePath,
sourceFiles: [filePath],
sourceMap: true
inlineMap: true
})

var js = output.js
js += '\n'
js += '//# sourceMappingURL=data:application/json;base64,'
js += new Buffer(output.v3SourceMap).toString('base64')
js += '\n'
return js
// Strip sourceURL from output so there wouldn't be duplicate entries
// in devtools.
return output.replace(/\/\/# sourceURL=[^'"\n]+\s*$/, '')
}
9 changes: 1 addition & 8 deletions src/compile-cache.js
Expand Up @@ -74,7 +74,7 @@ function compileFileAtPath (compiler, filePath, extension) {
cacheStats[extension].hits++
} else {
cacheStats[extension].misses++
compiledCode = addSourceURL(compiler.compile(sourceCode, filePath), filePath)
compiledCode = compiler.compile(sourceCode, filePath)
writeCachedJavascript(cachePath, compiledCode)
}
return compiledCode
Expand All @@ -97,13 +97,6 @@ function writeCachedJavascript (relativeCachePath, code) {
fs.writeFileSync(cachePath, code, 'utf8')
}

function addSourceURL (jsCode, filePath) {
if (process.platform === 'win32') {
filePath = '/' + path.resolve(filePath).replace(/\\/g, '/')
}
return jsCode + '\n' + '//# sourceURL=' + encodeURI(filePath) + '\n'
}

var INLINE_SOURCE_MAP_REGEXP = /\/\/[#@]\s*sourceMappingURL=([^'"\n]+)\s*$/mg

require('source-map-support').install({
Expand Down

0 comments on commit f58d70a

Please sign in to comment.