File size: 1,129 Bytes
5893f8f | 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 | // Generated by CoffeeScript 2.0.0-beta9-dev
var CoffeeScript, compile, eachCode;
CoffeeScript = require('./module');
eachCode = require('pegjs-each-code');
compile = function (csCode, options) {
var csAST, jsAST;
if (null == options)
options = {};
csAST = CoffeeScript.parse('-> ' + csCode.trimRight());
if (csAST.body.statements.length > 1)
throw new Error('inconsistent base indentation');
jsAST = CoffeeScript.compile(csAST, {
bare: true,
inScope: options.inScope
});
jsAST.leadingComments = [];
jsAST.body = jsAST.body[0].expression.body.body.concat(jsAST.body.slice(1));
return CoffeeScript.js(jsAST);
};
exports.use = function (config) {
return config.passes.transform.unshift(function (ast) {
ast.initializer.code = CoffeeScript.cs2js(ast.initializer.code, { bare: true });
return eachCode(ast, function (node, labels, ruleName) {
var error;
try {
return node.code = compile(node.code, { inScope: labels });
} catch (e$) {
error = e$;
throw new Error("In the '" + ruleName + "' rule:\n" + error.message + '');
}
});
});
};
|