Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added support of "with "statement.

Added spec test for the "with" node.
  • Loading branch information...
commit cf349aa5b10efa9cd87dfa49c90eca300a4626d5 1 parent e334a7e
@DmitrySoshnikov DmitrySoshnikov authored
Showing with 19 additions and 1 deletion.
  1. +10 −0 lib/jsgrep.js
  2. +9 −1 specs/matcher.spec.js
View
10 lib/jsgrep.js
@@ -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
10 specs/matcher.spec.js
@@ -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]);
}
});
+
Please sign in to comment.
Something went wrong with that request. Please try again.