-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtricks.js
77 lines (77 loc) · 1.18 KB
/
tricks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const tricks = [
{
name: "for->while",
match: `
(for_statement
initializer:(_)@init
condition:(_)@cond
update:(_)@inc
(_)@body
)@match
`,
replace: `
{@init
while(@cond){
@body
@inc;
}}`},
{
name: "less -> greater",
match: `
(binary_expression
left: (_)@left
operator: "<"
right: (_)@right
)@match
`,
replace: `
@right > @left
`},
{
name: "greater -> less",
match: `
(binary_expression
left: (_)@left
operator: ">"
right: (_)@right
)@match
`,
replace: `
@right < @left
`},
{
name: "++ -> +=1",
match: `(update_expression operator:"++"@op)@match`,
replace: { op: ' += 1' }
},
{
name: "-- -> -=1",
match: `(update_expression operator:"--"@op)@match`,
replace: { op: ' -= 1' }
}, {
name: "swap if-else",
match: `
(if_statement
condition: (_)@cond
consequence: (_)@cons
alternative: (_)@alt
)@match`,
replace: `if (!@cond) @alt else @cons`
}, {
name: "((x)) -> (x)",
match: `
(parenthesized_expression
(parenthesized_expression)@p1
)@match`,
replace: `@p1`
},
{
name: "unary op(x) -> unary op x",
match: `
(unary_expression
operator: _@op
argument: (parenthesized_expression(_)@x)
)@match`,
replace: `@op@x`
}
]