Skip to content

Commit

Permalink
[fixed] substitutions in nested selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Sep 28, 2015
1 parent 1a52f76 commit e60bc99
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
12 changes: 9 additions & 3 deletions lib/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,21 @@ function findAll(root, test, getParent, includeSelf) {
}

function getTagComparer(rule, values) {
var isStr = function isStr(t) {
return typeof t === 'string';
};
var tagName = values[rule.tagName] || rule.tagName;

if (rule.tagName === '*') return function () {
return true;
};

if (typeof tagName === 'string') return function (root) {
return root.type.toUpperCase() === tagName.toUpperCase();
};
if (isStr(tagName)) {
tagName = tagName.toUpperCase();
return function (root) {
return isStr(root.type) && root.type.toUpperCase() === tagName;
};
}

return function (root) {
return root.type === tagName;
Expand Down
2 changes: 1 addition & 1 deletion src/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export function compileRule(rules, parent, values, ast){

if (rule.hasOwnProperty('nestingOperator') ){
let immediate = rule.nestingOperator === '>'
let nestedCompiled = compileRule(rules, rule, ast);
let nestedCompiled = compileRule(rules, rule, values, ast);

fns.push((root, parent) => {
let method = immediate ? directParent : anyParent
Expand Down
14 changes: 13 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,25 @@ describe('Element Selecting', ()=> {
match(s`div ${List}.foo`,
<div>
<span>
<a className='foo' show/>
<a className='foo' show />
</span>
<List className='foo'/>
</div>
).length.should.equal(1)
})

it('should match with nested tag substitutions', ()=>{
let List = ()=> <div/>;

match(s`${List}.foo > span`,
<div>
<List className='foo'>
<span/>
</List>
</div>
).length.should.equal(1)
})

it('should match with prop value substitions', ()=>{
let date = new Date();

Expand Down

0 comments on commit e60bc99

Please sign in to comment.