Skip to content

Commit

Permalink
feat: Set compiled function name
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Oct 20, 2019
1 parent c600a78 commit 92f3314
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/ejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,15 +666,10 @@ Template.prototype = {
throw e;
}

if (opts.client) {
fn.dependencies = this.dependencies;
return fn;
}

// Return a callable function which will execute the function
// created by the source-code, with the passed data as locals
// Adds a local `include` function which allows full recursive include
var returnedFn = function (data) {
var returnedFn = opts.client ? fn : function anonymous(data) {
var include = function (path, includeData) {
var d = utils.shallowCopy({}, data);
if (includeData) {
Expand All @@ -685,6 +680,18 @@ Template.prototype = {
return fn.apply(opts.context, [data || {}, escapeFn, include, rethrow]);
};
returnedFn.dependencies = this.dependencies;
if (opts.filename && typeof Object.defineProperty === 'function') {
var filename = opts.filename;
var basename = path.basename(filename, path.extname(filename));
try {
Object.defineProperty(returnedFn, 'name', {
value: basename,
writable: false,
enumerable: false,
configurable: true
});
} catch (e) {/* ignore */}
}
return returnedFn;
},

Expand Down

0 comments on commit 92f3314

Please sign in to comment.