Skip to content

Commit

Permalink
Compact utils.fnToString
Browse files Browse the repository at this point in the history
  • Loading branch information
miripiruni committed Feb 16, 2017
1 parent a044604 commit 43a3cb7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/bemhtml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ BEMHTML.prototype.renderClose = function(prefix, context, tag, attrs, isBEM,
out = context._flush(out);
return out;
};

BEMHTML.prototype.renderAttrs = function(attrs) {
var out = '';

Expand Down
12 changes: 6 additions & 6 deletions lib/bemxjst/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,22 @@ exports.fnToString = function(code) {
return '';

if (typeof code === 'function') {
// Examples:
// Examples for regular function
// function () { … }
// function name() { … }
// function (a, b) { … }
// function name(a, b) { … }
var regularFunction = /^function\s*[^{]+{|}$/g;

// Examples:
//
// Examples for arrow function
// () => { … }
// (a, b) => { … }
// _ => { … }
var arrowFunction = /^(_|\(\w|[^=>]+\))\s=>\s{|}$/g;

code = code.toString();
code = code.replace(
code.indexOf('function') === 0 ? regularFunction : arrowFunction,
code.indexOf('function') === 0 ?
/^function\s*[^{]+{|}$/g :
/^(_|\(\w|[^=>]+\))\s=>\s{|}$/g,
'');
}

Expand Down

0 comments on commit 43a3cb7

Please sign in to comment.