Permalink
Browse files

Added support of "with "statement.

Added spec test for the "with" node.
  • Loading branch information...
DmitrySoshnikov committed Mar 13, 2012
1 parent e334a7e commit cf349aa5b10efa9cd87dfa49c90eca300a4626d5
Showing with 19 additions and 1 deletion.
  1. +10 −0 lib/jsgrep.js
  2. +9 −1 specs/matcher.spec.js
View
@@ -972,6 +972,11 @@ var astIsEqual = exports.astIsEqual = function(node, pattern, config) {
return astIsEqual(node.exception, pattern.exception, config);
break;
+ case tokens.WITH:
+ return astIsEqual(node.object, pattern.object, config) &&
+ astIsEqual(node.body, pattern.body, config);
+ break;
+
default:
throw new JsgrepError(
"Pattern type is not yet supported: " + tokenString(node.type));
@@ -1150,6 +1155,11 @@ var forEachNode = exports.forEachNode = function(node, callback) {
}
break;
+ case tokens.WITH:
+ forEachNode(node.object, callback);
+ forEachNode(node.body, callback);
+ break;
+
case tokens.TRY:
forEachNode(node.tryBlock, callback);
_.each(node.catchClauses, function(child) {
View
@@ -7,7 +7,7 @@ var fs = require('fs');
// These tests are pretty weak, they just run some random queries and check the
// count of the results in a known corpus.
-xdescribe('Matcher.find', function() {
+describe('Matcher.find', function() {
const fileName = path.resolve(path.join(__dirname, '../tests/jquery.js'));
var source = fs.readFileSync(fileName);
var sourceAst = Narcissus.parser.parse(source, fileName, 1);
@@ -53,6 +53,13 @@ xdescribe('Matcher.find', function() {
});
expect(results.length).toBe(0);
});
+
+ it ('for "with" keyword', function() {
+ var matcher = new jsgrep.Matcher('with ({x: 10}) { console.log(x); }');
+ var results = matcher.find('with (A) { ... }');
+ expect(results.length).toBe(1);
+ });
+
});
describe('Matcher offsets', function() {
@@ -89,3 +96,4 @@ describe('Matcher offsets', function() {
runTest(tests[i]);
}
});
+

0 comments on commit cf349aa

Please sign in to comment.