Skip to content
Newer
Older
100644 59 lines (39 sloc) 2.01 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
2cf1d47 Add support for ...
Ryan Patterson authored
49 * Consider support for --where/--eval and/or not-patterns
50 * Support for -l -L -n -h -H
4c6b655 Add support for loose object matching
Ryan Patterson authored
51 * Support for most statements in patterns
58384b5 Updated README
Ryan Patterson authored
52
53 ## Contributors
54
55 Jsgrep was written by Ryan Patterson at Facebook. Inspiration for this project
56 draws heavily from pfff, a source code analyzer written at Facebook.
57
58 * pfff - https://github.com/facebook/pfff
Something went wrong with that request. Please try again.