Files
meteor/packages/coffeescript/compile-coffeescript.js
Geoffrey Booth 13fb390bc7 Move coffeescript and coffeescript-test-helper packages back into core. (#8960)
They depend on core packages like caching-compiler, but coffeescript-compiler
can remain in non-core, so it can update more frequently as npm coffeescript
gets updated.
2017-08-15 10:21:18 +00:00

49 lines
1.3 KiB
JavaScript

Plugin.registerCompiler({
extensions: ['coffee', 'litcoffee', 'coffee.md']
}, () => new CachedCoffeeScriptCompiler());
// The CompileResult for this CachingCompiler is a {source, sourceMap} object.
class CachedCoffeeScriptCompiler extends CachingCompiler {
constructor() {
super({
compilerName: 'coffeescript',
defaultCacheSize: 1024*1024*10,
});
this.coffeeScriptCompiler = new CoffeeScriptCompiler();
}
getCacheKey(inputFile) {
return [
inputFile.getSourceHash(),
inputFile.getDeclaredExports(),
this.coffeeScriptCompiler.getCompileOptions(inputFile),
];
}
setDiskCacheDirectory(cacheDir) {
this.coffeeScriptCompiler.babelCompiler.setDiskCacheDirectory(cacheDir);
return super.setDiskCacheDirectory(cacheDir);
}
compileOneFile(inputFile) {
return this.coffeeScriptCompiler.compileOneFile(inputFile);
}
addCompileResult(inputFile, sourceWithMap) {
inputFile.addJavaScript({
path: this.coffeeScriptCompiler.outputFilePath(inputFile),
sourcePath: inputFile.getPathInPackage(),
data: sourceWithMap.source,
sourceMap: sourceWithMap.sourceMap,
bare: inputFile.getFileOptions().bare
});
}
compileResultSize(sourceWithMap) {
return sourceWithMap.source.length +
this.sourceMapSize(sourceWithMap.sourceMap);
}
}