Files
meteor/packages/coffeescript/package.js
Andrew Wilcox 6873c91424 Allow CoffeeScript to set global vars when using "use strict".
Ha.  Turns out that `.call(this)` is needed after all when a
CoffeeScript file is using "use strict".
(http://es5.github.io/#x15.3.4.4)

Thanks to pipedreambomb on stackoverflow for the bug report and to
user1737909 for the documentation reference.
2013-04-15 10:52:01 -07:00

41 lines
1.1 KiB
JavaScript

Package.describe({
summary: "Javascript dialect with fewer braces and semicolons"
});
Npm.depends({"coffee-script": "1.5.0"});
var coffeescript_handler = function(bundle, source_path, serve_path, where) {
var fs = Npm.require('fs');
var path = Npm.require('path');
var coffee = Npm.require('coffee-script');
serve_path = serve_path + '.js';
var contents = fs.readFileSync(source_path);
var options = {bare: true, filename: source_path, literate: path.extname(source_path) === '.litcoffee'};
try {
contents = coffee.compile(contents.toString('utf8'), options);
} catch (e) {
return bundle.error(e.message);
}
contents = new Buffer(contents);
bundle.add_resource({
type: "js",
path: serve_path,
data: contents,
where: where
});
}
Package.register_extension("coffee", coffeescript_handler);
Package.register_extension("litcoffee", coffeescript_handler);
Package.on_test(function (api) {
api.add_files([
'coffeescript_tests.coffee',
'coffeescript_strict_tests.coffee',
'litcoffeescript_tests.litcoffee',
'coffeescript_tests.js'
], ['client', 'server']);
});