Skip to content

Commit

Permalink
refactoring for templates function reuse detection
Browse files Browse the repository at this point in the history
  • Loading branch information
veged committed Nov 2, 2015
1 parent 3935205 commit cf8aea8
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/bemhtml/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,10 @@ BEMHTML.prototype.recompileInput = function recompileInput(code) {
var out = code.toString();

var args = BEMHTML.locals;
if (typeof code === 'function') {
var start = out.match(/^function\s*\(([^{]+)\)\s*{/);

// Reuse function if it already has right arguments
if (start !== null && start[1].split(/,\s*/).length === args.length)
return code;
}
// Reuse function if it already has right arguments
if (typeof code === 'function' && code.length === args.length)
return code;

// Strip the function
out = out.replace(/^function[^{]+{|}$/g, '');
Expand Down

0 comments on commit cf8aea8

Please sign in to comment.