Skip to content

Commit

Permalink
Prevent .toLowerCase() error and add new angular valid selector prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonvictor committed Oct 22, 2015
1 parent fe852ca commit 694c2f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/find-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ FindSelectors.prototype.parseFileContent = function() {

FindSelectors.prototype.eachNodeCheck = function(node, selectors) {
if (node.type == 'CallExpression' && node.callee.object &&
node.callee.object.name.toLowerCase() === 'by') {
node.callee.object.name && node.callee.object.name.toLowerCase() === 'by') {

This comment has been minimized.

Copy link
@ramonvictor

ramonvictor Oct 22, 2015

Author Owner

@stramel I had to add it here because I was getting an error saying it was trying to execute .toLowerCase() in undefined value.

This comment has been minimized.

Copy link
@stramel

stramel Oct 22, 2015

Contributor

hmmmm, strange since it didn't exist before. No issue with that though.

You could use lodash instead of underscore, and then use the fancy _.get(node, 'callee.object.name') to check if it exists lol

if (node.type == 'CallExpression' && _.get(node, 'callee.object.name') && node.callee.object.name.toLowerCase() === 'by') {
// ...
}
var lineInfo = node.arguments[0].loc.start;
var lineAndColumn = lineInfo.line + ':' + lineInfo.column;

Expand Down
16 changes: 12 additions & 4 deletions lib/find-view-matches.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,18 @@ function loopSelectors(selectors, content) {
}

function attrSelector(attr, value) {
return [
'[ng-', attr, '="', value, '"], ',
'[data-ng-', attr, '="', value, '"]'
].join('');
// 'ng:' excluded, since it's not a `cheerio` valid selector.
var ngPrefixes = [ 'ng-', 'ng_', 'data-ng-', 'x-ng-' ];
var output = [];

for (var i = 0; i < ngPrefixes.length; i++) {
output.push(
'[' + ngPrefixes[i] + attr + '="' + value+ '"]' +
(i === (ngPrefixes.length - 1) ? '' : ', ')
);
}

return output.join('');
}

function prefixSelector(prefix, value) {
Expand Down

0 comments on commit 694c2f7

Please sign in to comment.