diff --git a/.gitignore b/.gitignore index c1e2b47e..b5dfb494 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ lib/bem*/bundle.js /node_modules/ npm-debug.log +/.idea/ +/coverage/ +/bench/bem-xjst-*/ +/bench/dat-*/ diff --git a/lib/bemhtml/index.js b/lib/bemhtml/index.js index 5446d387..1398bd22 100644 --- a/lib/bemhtml/index.js +++ b/lib/bemhtml/index.js @@ -279,13 +279,31 @@ BEMHTML.prototype.renderAttrs = function(attrs, ctx) { return out; }; +var BEMHTMLSet = typeof Set !== 'undefined' ? + Set : + (function() { + var MiniSet = function() { + this._storage = {}; + }; + + MiniSet.prototype.add = function(item) { + this._storage[item] = true; + }; + + MiniSet.prototype.has = function(item) { + return this._storage[item] || false; + }; + + return MiniSet; + })(); + BEMHTML.prototype.renderMix = function(entity, mix, jsParams, addJSInitClass) { - var visited = {}; + var visited = new BEMHTMLSet(); var context = this.context; var js = jsParams; var addInit = addJSInitClass; - visited[entity.jsClass] = true; + visited.add(entity.jsClass); // Transform mix to the single-item array if it's not array if (!Array.isArray(mix)) @@ -335,11 +353,11 @@ BEMHTML.prototype.renderMix = function(entity, mix, jsParams, addJSInitClass) { addInit = block && !item.elem; } - // Process nested mixes - if (!hasItem || visited[key]) + // Process nested mixes from templates + if (!hasItem || visited.has(key)) continue; - visited[key] = true; + visited.add(key); var nestedEntity = this.entities[key]; if (!nestedEntity) continue; @@ -360,7 +378,7 @@ BEMHTML.prototype.renderMix = function(entity, mix, jsParams, addJSInitClass) { if (!nestedItem.block && !nestedItem.elem || - !visited[classBuilder.build(nestedItem.block, nestedItem.elem)]) { + !visited.has(classBuilder.build(nestedItem.block, nestedItem.elem))) { if (nestedItem.block) continue; nestedItem._block = block;