mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
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);
|
|
}
|
|
}
|
|
};
|
|
}); |