Skip to content

Commit

Permalink
runtime: fix list indexes for non-BEM entities
Browse files Browse the repository at this point in the history
Fix: #99
  • Loading branch information
indutny committed Sep 4, 2015
1 parent 4a058d4 commit fd19a48
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/bemhtml/runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ BEMHTML.prototype.render = function render(context,
else
isBEM = ctx.bem;
}
isBEM = !!isBEM;

if (cls === undefined)
cls = ctx.cls;
Expand Down Expand Up @@ -668,10 +669,8 @@ BEMHTML.prototype.renderContent = function renderContent(content, isBEM) {

var res = this._run(content);

if (isBEM) {
context.position = oldPos;
context._listLength = oldListLength;
}
context.position = oldPos;
context._listLength = oldListLength;
context._notNewList = oldNotNewList;

return res;
Expand Down
31 changes: 31 additions & 0 deletions test/runtime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,37 @@ describe('BEMHTML compiler/Runtime', function() {
}
});
});

it('should support `.getLast()`', function() {
test(function() {
block('b1')(
match(function() { return this.isLast(); })
.mix()({ elemMods: { position: 'last' } })
);
}, [
{
tag: 'table',
content: {
block: 'b1',
tag: 'tr',
content: [
{ content: '', tag: 'td' },
{ content: '', tag: 'td' }
]
}
},
{
block: 'b1',
content: 'first'
},
{
block: 'b1',
content: 'last'
}
], '<table><tr class="b1"><td></td><td></td></tr></table>' +
'<div class="b1">first</div>' +
'<div class="b1 b1_position_last">last</div>');
});
});

describe('attrs in BEMJSON', function() {
Expand Down

0 comments on commit fd19a48

Please sign in to comment.