Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 60 lines (40 sloc) 2.119 kb
b676cbf Added a README file.
Ryan Patterson authored
1 # jsgrep: a syntactically-aware grep for JavaScript
2
4c6b655 Add support for loose object matching
Ryan Patterson authored
3 Jsgrep is program that searches for a particular JavaScript pattern using the
4 abstract syntax tree (AST) of the program. This enables matching expressions
5 based on their JavaScript meaning, rather than based on simple strings.
b676cbf Added a README file.
Ryan Patterson authored
6
58384b5 Updated README
Ryan Patterson authored
7 ## Examples
b676cbf Added a README file.
Ryan Patterson authored
8
9 **Find calls to window.setTimeout with a 0 timeout**
10
8beed8e Swap out option parser
Ryan Patterson authored
11 $ jsgrep 'setTimeout(A, 0)' tests/*.js
b676cbf Added a README file.
Ryan Patterson authored
12 tests/jquery.js: setTimeout( function() {
13 tests/jquery.js: setTimeout( clearFxNow, 0 );
14
4c6b655 Add support for loose object matching
Ryan Patterson authored
15 Jsgrep uses metavariables as wildcards. Metavariables match any valid JavaScript
16 chunk, so in this case, the first match was an entire inline function. In both
17 cases, the second parameter to setTimeout was a literal value of 0.
8beed8e Swap out option parser
Ryan Patterson authored
18
19 **Find value defaulting**
20
4c6b655 Add support for loose object matching
Ryan Patterson authored
21 $ jsgrep "A = A || B;" tests/*.js
8beed8e Swap out option parser
Ryan Patterson authored
22 tests/jquery.js: args = args || [];
23 tests/jquery.js: dataType = dataType || options.dataTypes[ 0 ];
24
25 When the pattern references the same metavariable multiple times, jsgrep ensures
26 that the value of the metavariable is the same throughout the match.
27
2cf1d47 Add support for ...
Ryan Patterson authored
28 **Find the names of all invoked events**
29
30 $ ./jsgrep -p B "A.fire(B, ...)" tests/*.j
31 tests/connect.js: 'auth.logout'
32 tests/connect.js: 'auth.login'
33
34 The `...` operator matches 0 or more expressions in function calls and array
35 initializers.
36
4c6b655 Add support for loose object matching
Ryan Patterson authored
37 **Find classes that have a 'path' property**
38
39 $ jsgrep -p C "JX.install(C, { properties: { path: X } })" tests/*.js
40 tests/javelin.js: 'Event'
41 tests/javelin.js: 'URI'
42
43 Jsgrep allows you to search object initializations partially, which enables
44 easily drilling into the structure of JavaScript classes. This example also uses
45 the `-p` flag to print only a particular matched variable.
46
58384b5 Updated README
Ryan Patterson authored
47 ## TODO
48
8bb3d60 Add some protection to metavars
Ryan Patterson authored
49 * Consider a metavar that matches but doesn't save, to prevent ambiguities.
2cf1d47 Add support for ...
Ryan Patterson authored
50 * Consider support for --where/--eval and/or not-patterns
4c6b655 Add support for loose object matching
Ryan Patterson authored
51 * Support for most statements in patterns
8bb3d60 Add some protection to metavars
Ryan Patterson authored
52 * Testing
58384b5 Updated README
Ryan Patterson authored
53
54 ## Contributors
55
56 Jsgrep was written by Ryan Patterson at Facebook. Inspiration for this project
57 draws heavily from pfff, a source code analyzer written at Facebook.
58
59 * pfff - https://github.com/facebook/pfff
Something went wrong with that request. Please try again.