-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
302 lines (255 loc) · 11.1 KB
/
index.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
const find = require('./src/find')
const each = require('./src/each')
const first = require('./src/first')
const last = require('./src/last')
const count = require('./src/count')
const equal = require('./src/equal')
const has = require('./src/has')
const remove = require('./src/remove')
const prepend = require('./src/prepend')
const append = require('./src/append')
const replace = require('./src/replace')
const walk = require('./src/walk')
const traverse = require('./src/traverse')
const generate = require('./src/generate')
const parse = require('./src/parse')
const reduce = require('./src/reduce')
const template = require('./src/template')
const match = require('./src/match')
const serialize = require('./src/serialize')
const sourcemap = require('./src/sourcemap')
const mark = require('./src/mark')
const program = require('./src/program')
const iife = require('./src/iife')
class AbstractSyntaxTree {
static find (tree, selector) {
return find(tree, selector)
}
static each (tree, selector, callback) {
return each(tree, selector, callback)
}
static first (tree, selector) {
return first(tree, selector)
}
static last (tree, selector) {
return last(tree, selector)
}
static count (tree, selector) {
return count(tree, selector)
}
static has (tree, selector) {
return has(tree, selector)
}
static remove (tree, target, options) {
return remove(tree, target, options)
}
static prepend (tree, node) {
return prepend(tree, node)
}
static append (tree, node) {
return append(tree, node)
}
static equal (node1, node2) {
return equal(node1, node2)
}
static match (node, selector) {
return match(node, selector)
}
static generate (tree, options) {
return generate(tree, options)
}
static parse (source, options) {
return parse(source, options)
}
static walk (tree, callback) {
return walk(tree, callback)
}
static serialize (node) {
return serialize(node)
}
static traverse (tree, callback) {
return traverse(tree, callback)
}
static replace (tree, callback) {
return replace(tree, callback)
}
static template (source, options) {
return template(source, options)
}
static reduce (tree, callback, accumulator) {
return reduce(tree, callback, accumulator)
}
static program (body, options) {
return program(body, options)
}
static iife (body) {
return iife(body)
}
constructor (source = '', options = {}) {
if (typeof source === 'string') {
this._tree = parse(source, { loc: true, ...options })
} else {
this._tree = source
}
}
get type () {
return this._tree.type
}
get body () {
return this._tree.body
}
get source () {
return generate(this._tree)
}
get map () {
return sourcemap(this._tree).map
}
set body (body) {
this._tree.body = body
}
find (selector) {
return find(this._tree, selector)
}
each (selector, callback) {
return each(this._tree, selector, callback)
}
first (selector) {
return first(this._tree, selector)
}
last (selector) {
return last(this._tree, selector)
}
count (selector) {
return count(this._tree, selector)
}
has (selector) {
return has(this._tree, selector)
}
remove (target, options) {
return remove(this._tree, target, options)
}
walk (callback) {
return walk(this._tree, callback)
}
traverse (options) {
return traverse(this._tree, options)
}
replace (options) {
return replace(this._tree, options)
}
reduce (callback, accumulator) {
return reduce(this._tree, callback, accumulator)
}
prepend (node) {
return prepend(this._tree, node)
}
append (node) {
return append(this._tree, node)
}
wrap (callback) {
this._tree.body = callback(this._tree.body)
}
unwrap () {
this._tree.body = first(this._tree, 'BlockStatement').body
}
mark () {
return mark(this._tree)
}
}
AbstractSyntaxTree.Node = require('./src/nodes/Node')
AbstractSyntaxTree.SourceLocation = require('./src/nodes/SourceLocation')
AbstractSyntaxTree.Position = require('./src/nodes/Position')
AbstractSyntaxTree.Identifier = require('./src/nodes/Identifier')
AbstractSyntaxTree.Literal = require('./src/nodes/Literal')
AbstractSyntaxTree.RegExpLiteral = require('./src/nodes/RegExpLiteral')
AbstractSyntaxTree.Program = require('./src/nodes/Program')
AbstractSyntaxTree.Function = require('./src/nodes/Function')
AbstractSyntaxTree.Statement = require('./src/nodes/Statement')
AbstractSyntaxTree.ExpressionStatement = require('./src/nodes/ExpressionStatement')
AbstractSyntaxTree.Directive = require('./src/nodes/Directive')
AbstractSyntaxTree.BlockStatement = require('./src/nodes/BlockStatement')
AbstractSyntaxTree.FunctionBody = require('./src/nodes/FunctionBody')
AbstractSyntaxTree.EmptyStatement = require('./src/nodes/EmptyStatement')
AbstractSyntaxTree.DebuggerStatement = require('./src/nodes/DebuggerStatement')
AbstractSyntaxTree.WithStatement = require('./src/nodes/WithStatement')
AbstractSyntaxTree.ReturnStatement = require('./src/nodes/ReturnStatement')
AbstractSyntaxTree.LabeledStatement = require('./src/nodes/LabeledStatement')
AbstractSyntaxTree.BreakStatement = require('./src/nodes/BreakStatement')
AbstractSyntaxTree.ContinueStatement = require('./src/nodes/ContinueStatement')
AbstractSyntaxTree.IfStatement = require('./src/nodes/IfStatement')
AbstractSyntaxTree.SwitchStatement = require('./src/nodes/SwitchStatement')
AbstractSyntaxTree.SwitchCase = require('./src/nodes/SwitchCase')
AbstractSyntaxTree.ThrowStatement = require('./src/nodes/ThrowStatement')
AbstractSyntaxTree.TryStatement = require('./src/nodes/TryStatement')
AbstractSyntaxTree.CatchClause = require('./src/nodes/CatchClause')
AbstractSyntaxTree.WhileStatement = require('./src/nodes/WhileStatement')
AbstractSyntaxTree.DoWhileStatement = require('./src/nodes/DoWhileStatement')
AbstractSyntaxTree.ForStatement = require('./src/nodes/ForStatement')
AbstractSyntaxTree.ForInStatement = require('./src/nodes/ForInStatement')
AbstractSyntaxTree.Declaration = require('./src/nodes/Declaration')
AbstractSyntaxTree.FunctionDeclaration = require('./src/nodes/FunctionDeclaration')
AbstractSyntaxTree.VariableDeclaration = require('./src/nodes/VariableDeclaration')
AbstractSyntaxTree.VariableDeclarator = require('./src/nodes/VariableDeclarator')
AbstractSyntaxTree.Expression = require('./src/nodes/Expression')
AbstractSyntaxTree.ThisExpression = require('./src/nodes/ThisExpression')
AbstractSyntaxTree.ArrayExpression = require('./src/nodes/ArrayExpression')
AbstractSyntaxTree.ObjectExpression = require('./src/nodes/ObjectExpression')
AbstractSyntaxTree.Property = require('./src/nodes/Property')
AbstractSyntaxTree.FunctionExpression = require('./src/nodes/FunctionExpression')
AbstractSyntaxTree.UnaryExpression = require('./src/nodes/UnaryExpression')
AbstractSyntaxTree.UnaryOperator = require('./src/nodes/UnaryOperator')
AbstractSyntaxTree.UpdateExpression = require('./src/nodes/UpdateExpression')
AbstractSyntaxTree.UpdateOperator = require('./src/nodes/UpdateOperator')
AbstractSyntaxTree.BinaryExpression = require('./src/nodes/BinaryExpression')
AbstractSyntaxTree.BinaryOperator = require('./src/nodes/BinaryOperator')
AbstractSyntaxTree.AssignmentExpression = require('./src/nodes/AssignmentExpression')
AbstractSyntaxTree.AssignmentOperator = require('./src/nodes/AssignmentOperator')
AbstractSyntaxTree.LogicalExpression = require('./src/nodes/LogicalExpression')
AbstractSyntaxTree.LogicalOperator = require('./src/nodes/LogicalOperator')
AbstractSyntaxTree.MemberExpression = require('./src/nodes/MemberExpression')
AbstractSyntaxTree.ConditionalExpression = require('./src/nodes/ConditionalExpression')
AbstractSyntaxTree.CallExpression = require('./src/nodes/CallExpression')
AbstractSyntaxTree.NewExpression = require('./src/nodes/NewExpression')
AbstractSyntaxTree.SequenceExpression = require('./src/nodes/SequenceExpression')
AbstractSyntaxTree.Pattern = require('./src/nodes/Pattern')
AbstractSyntaxTree.ForOfStatement = require('./src/nodes/ForOfStatement')
AbstractSyntaxTree.Super = require('./src/nodes/Super')
AbstractSyntaxTree.SpreadElement = require('./src/nodes/SpreadElement')
AbstractSyntaxTree.YieldExpression = require('./src/nodes/YieldExpression')
AbstractSyntaxTree.TemplateLiteral = require('./src/nodes/TemplateLiteral')
AbstractSyntaxTree.TaggedTemplateExpression = require('./src/nodes/TaggedTemplateExpression')
AbstractSyntaxTree.TemplateElement = require('./src/nodes/TemplateElement')
AbstractSyntaxTree.ObjectPattern = require('./src/nodes/ObjectPattern')
AbstractSyntaxTree.ArrayPattern = require('./src/nodes/ArrayPattern')
AbstractSyntaxTree.RestElement = require('./src/nodes/RestElement')
AbstractSyntaxTree.AssignmentPattern = require('./src/nodes/AssignmentPattern')
AbstractSyntaxTree.Class = require('./src/nodes/Class')
AbstractSyntaxTree.ClassBody = require('./src/nodes/ClassBody')
AbstractSyntaxTree.MethodDefinition = require('./src/nodes/MethodDefinition')
AbstractSyntaxTree.ClassDeclaration = require('./src/nodes/ClassDeclaration')
AbstractSyntaxTree.ClassExpression = require('./src/nodes/ClassExpression')
AbstractSyntaxTree.MetaProperty = require('./src/nodes/MetaProperty')
AbstractSyntaxTree.ModuleDeclaration = require('./src/nodes/ModuleDeclaration')
AbstractSyntaxTree.ModuleSpecifier = require('./src/nodes/ModuleSpecifier')
AbstractSyntaxTree.ImportDeclaration = require('./src/nodes/ImportDeclaration')
AbstractSyntaxTree.ImportSpecifier = require('./src/nodes/ImportSpecifier')
AbstractSyntaxTree.ImportDefaultSpecifier = require('./src/nodes/ImportDefaultSpecifier')
AbstractSyntaxTree.ImportNamespaceSpecifier = require('./src/nodes/ImportNamespaceSpecifier')
AbstractSyntaxTree.ExportNamedDeclaration = require('./src/nodes/ExportNamedDeclaration')
AbstractSyntaxTree.ExportSpecifier = require('./src/nodes/ExportSpecifier')
AbstractSyntaxTree.ExportDefaultDeclaration = require('./src/nodes/ExportDefaultDeclaration')
AbstractSyntaxTree.ExportAllDeclaration = require('./src/nodes/ExportAllDeclaration')
AbstractSyntaxTree.AwaitExpression = require('./src/nodes/AwaitExpression')
AbstractSyntaxTree.BigIntLiteral = require('./src/nodes/BigIntLiteral')
AbstractSyntaxTree.ChainExpression = require('./src/nodes/ChainExpression')
AbstractSyntaxTree.ChainElement = require('./src/nodes/ChainElement')
AbstractSyntaxTree.ImportExpression = require('./src/nodes/ImportExpression')
AbstractSyntaxTree.toBinaryExpression = require('./src/transform/toBinaryExpression')
AbstractSyntaxTree.binaryExpressionReduction = require('./src/optimize/binaryExpressionReduction')
AbstractSyntaxTree.ifStatementRemoval = require('./src/optimize/ifStatementRemoval')
AbstractSyntaxTree.logicalExpressionReduction = require('./src/optimize/logicalExpressionReduction')
AbstractSyntaxTree.memberExpressionReduction = require('./src/optimize/memberExpressionReduction')
AbstractSyntaxTree.negationOperatorRemoval = require('./src/optimize/negationOperatorRemoval')
AbstractSyntaxTree.ternaryOperatorReduction = require('./src/optimize/ternaryOperatorReduction')
AbstractSyntaxTree.typeofOperatorReduction = require('./src/optimize/typeofOperatorReduction')
module.exports = AbstractSyntaxTree