raptor
Version:
RaptorJS provides an AMD module loader that works in Node, Rhino and the web browser. It also includes various sub-modules to support building optimized web applications.
38 lines (32 loc) • 1.33 kB
JavaScript
var nodeRequire = require;
define.extend('raptor/templating/compiler/TemplateCompiler', function(require, target) {
"use strict";
var vm = require('vm'),
raptor = require('raptor');
return {
_eval: function(compiledSrc, resource) {
var filePath;
if (resource) {
if (typeof resource === 'string') {
filePath = resource;
}
else if (require('raptor/resources').isResource(resource)) {
filePath = resource.isFileResource() ? resource.getFilePath() : resource.getURL();
}
}
try
{
if (filePath && require('raptor/files').exists(filePath)) { //This is a hack, but line numbers for SyntaxErrors are getting lost if we don't use require
delete nodeRequire.cache[filePath];
nodeRequire(filePath);
}
else {
vm.runInThisContext(compiledSrc, filePath || null);
}
}
catch(e) {
throw raptor.createError(new Error('Unable to load compile templated at path "' + filePath + '". Exception: ' + e), e);
}
}
};
});