Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function compile(file, data, callback) {
var compiled;
try {
compiled = coffee.compile(cjsx(data), { // compile cjsx to coffee, then coffee to js
sourceMap: true,
generatedFile: file,
inline: true,
bare: true,
literate: false
});
} catch (e) {
var error = e;
if (e.location) {
error = new ParseError(e, data, file);
}
callback(error);
return;
}
var map = convert.fromJSON(compiled.v3SourceMap);
function extension_js(type, module, filename)
{
var is_hotswap_file = false;
var content = get_file_contents(filename);
delete fscache[filename];
var iscompiled = false;
fs.stat(filename, function(err, stats) {
hotswap[filename] = stats.mtime;
});
if (type == 'coffee') {
var compiled = require('coffee-script').compile(content, {
filename: filename
});
module._compile(compiled, filename);
} else {
module._compile(content, filename);
}
var oldmodule = loaded_mods[filename];
var newmodule = require.cache[filename];
// require('repl').start() resets require.cache?
if (typeof(newmodule) !== 'object') return;
is_hotswap_file = !!newmodule.change_code;
if (!is_hotswap_file) return;
if (typeof(newmodule.exports) != 'object' && typeof(newmodule.exports) != 'function') {
this.customResolver = path => {
const coffeescriptSrc = readFileSync(path, 'utf8');
const javascriptSrc = coffeescript.compile(coffeescriptSrc);
const Module = module.constructor;
const m = new Module(path, module.parent);
m.filename = path;
m.paths = Module._nodeModulePaths(dirname(path));
m._compile(javascriptSrc, path);
return m.exports;
};
fs.readFile(file, 'utf8', function(err, str) {
var js = coffeeScript.compile(str);
var jsFile = file.replace(".coffee", ".js");
fs.writeFile(jsFile, js, function(err) {
console.log("Created: "+jsFile);
cb2();
});
});
};
function requireFile(file) {
switch (key) {
case 'views':
return path.normalize(file);
case 'controllers':
if (file.match(/_controller/)) {
var src = fs.readFileSync(file).toString();
return file.match(/\.coffee$/) ? cs.compile(src) : src;
} else {
return require(file);
}
default:
return require(file);
}
}
};
exports.compileFile = function (file, filename) {
const extname = pathUtils.extname(filename);
switch (extname) {
case '.coffee':
return CoffeeScript.compile(file);
case '.litcoffee':
return CoffeeScript.compile(file, {literate: true});
case '.js':
BABEL_OPTIONS.filename = filename;
return babel.transform(file, BABEL_OPTIONS).code;
case '.yaml':
case '.yml': {
const object = yaml.safeLoad(file, { filename: filename, json: true });
return JSON.stringify(object);
}
case '.nml': {
const bundle = require('src/nml-parser').bundle({ nml: file, path: filename }).bundle;
return CoffeeScript.compile(bundle);
}
default:
return file;
parseCoffeeScriptSync: function(content, options) {
var coffee = require('coffee-script');
return coffee.compile(content);
},
SourceFileName: params.sourceFileName,
TargetFileName: params.targetFileName,
MapFileName: params.mapFileName,
Remarks: "CoffeeScript: Error reading input file.",
Details: err,
Errors: [{
Message: "CoffeeScript: " + err,
FileName: params.sourceFileName
}]
}));
writer.end();
return;
}
try {
var compiled = coffeescript.compile(data, options);
var map = JSON.parse(compiled.v3SourceMap);
map.file = path.basename(params.targetFileName);
delete map.sourceRoot;
var js = compiled.js;
if (params.sourceMapURL !== undefined)
js += "\n//# sourceMappingURL=" + path.basename(params.targetFileName) + ".map\n";
writer.write(JSON.stringify({
Success: true,
SourceFileName: params.sourceFileName,
TargetFileName: params.targetFileName,
MapFileName: params.mapFileName,
Remarks: "Successful!",
Content: js,
var md = component.md.replace(reg_block, function(codeblock) {
var code = codeblock.replace(reg_start, '').replace(reg_end, '');
code = Coffee.compile(code, {bare: true});
return codeblock + "\n\n";
});
component.md = md;
coffeescript: function(str){
var js = require('coffee-script').compile(str).replace(/\\/g, '\\\\').replace(/\n/g, '\\n');
return '';
}
};