-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (29 loc) · 966 Bytes
/
index.js
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
var jsxlate = require('jsxlate');
var cache = jsxlate.cache;
module.exports = function(src) {
this.cacheable();
var cacheKey = this.resource;
var resourceMtime = cache.mtime(this.resource);
try {
var result;
var cached = cache.cache[cacheKey];
if (cached && cached.mtime === resourceMtime) {
result = cached;
} else {
result = {
mtime: resourceMtime,
transformed: jsxlate.translator.transformMessageNodes(src)
};
cache.cache[cacheKey] = result;
cache.save()
}
return result.transformed;
} catch(e) {
var message = "Error transforming " + this.resource;
console.error(message);
console.error(e.toString());
var originalMessage = e.toString();
e.toString = function() { return message + " (Original exception: " + originalMessage + ")"; };
throw e;
}
};