@@ -4,92 +4,315 @@ group: Plugins
4
4
sort : 4
5
5
---
6
6
7
- The parser instance takes a String and callback and will return an expression when there's a match.
7
+ The ` parser ` instance, found in the ` compiler ` , is used to parse each module
8
+ being processed by webpack. The ` parser ` is yet another webpack class that
9
+ extends ` tapable ` and provides a variety of ` tapable ` hooks that can be used by
10
+ plugin authors to customize the parsing process.
11
+
12
+ The ` parser ` is found within [ module factories] ( ) and therefore takes little
13
+ more work to access:
8
14
9
15
``` js
10
- compiler .parser . plugin ( " var rewire " , function ( expr ) {
11
- // if you original module has 'var rewire'
12
- // you now have a handle on the expresssion object
13
- return true ;
14
- });
16
+ compiler .hooks . normalModuleFactory . tap ( factory => {
17
+ factory . hooks . parser . tap (( parser , options ) => {
18
+ parser . hooks . someHook . tap ( ... )
19
+ })
20
+ })
15
21
```
16
22
23
+ As with the ` compiler ` , ` tapAsync ` and ` tapPromise ` may also be available
24
+ depending on the type of hook.
25
+
17
26
18
- ## ` program(ast) ` bailing
27
+ ## Hooks
19
28
20
- General purpose plugin interface for the AST of a code fragment.
29
+ The following lifecycle hooks are exposed by the ` parser ` and can be accessed
30
+ as such:
21
31
22
32
23
- ## ` statement(statement: Statement) ` bailing
33
+ ### evaluateTypeof
24
34
25
- General purpose plugin interface for the statements of the code fragment.
35
+ ` SyncBailHook `
26
36
37
+ Evaluate the type of an identifier.
27
38
28
- ## ` call <identifier>(expr: Expression) ` bailing
39
+ Parameters: ` expression `
29
40
30
- ` abc(1) ` => ` call abc `
31
41
32
- ` a.b.c(1) ` => ` call a.b.c `
42
+ ### evaluate
33
43
44
+ ` SyncBailHook `
34
45
35
- ## ` expression <identifier>(expr: Expression) ` bailing
46
+ Evaluate an expression.
36
47
37
- ` abc ` => ` expression abc `
48
+ Parameters: ` expression `
38
49
39
- ` a.b.c ` => ` expression a.b.c `
40
50
51
+ ### evaluateIdentifier
41
52
42
- ## ` expression ?:(expr: Expression) ` bailing
53
+ ` SyncBailHook `
43
54
44
- ` (abc ? 1 : 2) ` => ` expression ?! `
55
+ Evaluate an identifier that is a free variable.
45
56
46
- Return a boolean value to omit parsing of the wrong path.
57
+ Parameters: ` expression `
47
58
48
59
49
- ## ` typeof <identifier>(expr: Expression) ` bailing
60
+ ### evaluateDefinedIdentifier
50
61
51
- ` typeof a.b.c ` => ` typeof a.b.c `
62
+ ` SyncBailHook `
52
63
64
+ Evaluate an identifier that is a defined variable.
53
65
54
- ## ` statement if(statement: Statement) ` bailing
66
+ Parameters: ` expression `
55
67
56
- ` if(abc) {} ` => ` statement if `
57
68
58
- Return a boolean value to omit parsing of the wrong path.
69
+ ### evaluateCallExpressionMember
59
70
71
+ ` SyncBailHook `
60
72
61
- ## ` label <labelname>(statement: Statement) ` bailing
73
+ Evaluate a call to a member function of a successfully evaluated expression.
62
74
63
- ` xyz: abc ` => ` label xyz `
75
+ Parameters: ` expression ` ` param `
64
76
65
77
66
- ## ` var <name>( statement: Statement) ` bailing
78
+ ### statement
67
79
68
- ` var abc, def ` => ` var abc ` + ` var def `
80
+ ` SyncBailHook `
69
81
70
- Return ` false ` to not add the variable to the known definitions .
82
+ General purpose hook that is called when parsing statements in a code fragment .
71
83
84
+ Parameters: ` statement `
72
85
73
- ## ` evaluate <expression type>(expr: Expression) ` bailing
74
86
75
- Evaluate an expression.
87
+ ### statementIf
76
88
89
+ ` SyncBailHook `
77
90
78
- ## ` evaluate typeof <identifier>(expr: Expression) ` bailing
91
+ ...
79
92
80
- Evaluate the type of an identifier.
93
+ Parameters: ` statement `
81
94
82
95
83
- ## ` evaluate Identifier <identifier>(expr: Expression) ` bailing
96
+ ### label
84
97
85
- Evaluate a identifier that is a free var.
98
+ ` SyncBailHook `
86
99
100
+ ...
87
101
88
- ## ` evaluate defined Identifier <identifier>(expr: Expression) ` bailing
102
+ Parameters: ` statement `
89
103
90
- Evaluate a identifier that is a defined var.
91
104
105
+ ### import
92
106
93
- ## ` evaluate CallExpression .<property>(expr: Expression) ` bailing
107
+ ` SyncBailHook `
94
108
95
- Evaluate a call to a member function of a successfully evaluated expression.
109
+ ...
110
+
111
+ Parameters: ` statement ` ` source `
112
+
113
+
114
+ ### importSpecifier
115
+
116
+ ` SyncBailHook `
117
+
118
+ ...
119
+
120
+ Parameters: ` statement ` ` source ` ` exportName ` ` identifierName `
121
+
122
+
123
+ ### export
124
+
125
+ ` SyncBailHook `
126
+
127
+ ...
128
+
129
+ Parameters: ` statement `
130
+
131
+
132
+ ### exportImport
133
+
134
+ ` SyncBailHook `
135
+
136
+ ...
137
+
138
+ Parameters: ` statement ` ` source `
139
+
140
+
141
+ ### exportDeclaration
142
+
143
+ ` SyncBailHook `
144
+
145
+ ...
146
+
147
+ Parameters: ` statement ` ` declaration `
148
+
149
+
150
+ ### exportExpression
151
+
152
+ ` SyncBailHook `
153
+
154
+ ...
155
+
156
+ Parameters: ` statement ` ` declaration `
157
+
158
+
159
+ ### exportSpecifier
160
+
161
+ ` SyncBailHook `
162
+
163
+ ...
164
+
165
+ Parameters: ` statement ` ` identifierName ` ` exportName ` ` index `
166
+
167
+
168
+ ### exportImportSpecifier
169
+
170
+ ` SyncBailHook `
171
+
172
+ ...
173
+
174
+ Parameters: ` statement ` ` source ` ` identifierName ` ` exportName ` ` index `
175
+
176
+
177
+ ### varDeclaration
178
+
179
+ ` SyncBailHook `
180
+
181
+ ...
182
+
183
+ Parameters: ` declaration `
184
+
185
+
186
+ ### varDeclarationLet
187
+
188
+ ` SyncBailHook `
189
+
190
+ ...
191
+
192
+ Parameters: ` declaration `
193
+
194
+
195
+ ### varDeclarationConst
196
+
197
+ ` SyncBailHook `
198
+
199
+ ...
200
+
201
+ Parameters: ` declaration `
202
+
203
+
204
+ ### varDeclarationVar
205
+
206
+ ` SyncBailHook `
207
+
208
+ ...
209
+
210
+ Parameters: ` declaration `
211
+
212
+
213
+ ### canRename
214
+
215
+ ` SyncBailHook `
216
+
217
+ ...
218
+
219
+ Parameters: ` initExpression `
220
+
221
+
222
+ ### rename
223
+
224
+ ` SyncBailHook `
225
+
226
+ ...
227
+
228
+ Parameters: ` initExpression `
229
+
230
+
231
+ ### assigned
232
+
233
+ ` SyncBailHook `
234
+
235
+ ...
236
+
237
+ Parameters: ` expression `
238
+
239
+
240
+ ### assign
241
+
242
+ ` SyncBailHook `
243
+
244
+ ...
245
+
246
+ Parameters: ` expression `
247
+
248
+
249
+ ### typeof
250
+
251
+ ` SyncBailHook `
252
+
253
+ ...
254
+
255
+ Parameters: ` expression `
256
+
257
+
258
+ ### call
259
+
260
+ ` SyncBailHook `
261
+
262
+ ...
263
+
264
+ Parameters: ` expression `
265
+
266
+
267
+ ### callAnyMember
268
+
269
+ ` SyncBailHook `
270
+
271
+ ...
272
+
273
+ Parameters: ` expression `
274
+
275
+
276
+ ### new
277
+
278
+ ` SyncBailHook `
279
+
280
+ ...
281
+
282
+ Parameters: ` expression `
283
+
284
+
285
+ ### expression
286
+
287
+ ` SyncBailHook `
288
+
289
+ ...
290
+
291
+ Parameters: ` expression `
292
+
293
+
294
+ ### expressionAnyMember
295
+
296
+ ` SyncBailHook `
297
+
298
+ ...
299
+
300
+ Parameters: ` expression `
301
+
302
+
303
+ ### expressionConditionalOperator
304
+
305
+ ` SyncBailHook `
306
+
307
+ ...
308
+
309
+ Parameters: ` expression `
310
+
311
+
312
+ ### program
313
+
314
+ ` SyncBailHook `
315
+
316
+ Get access to the abstract syntax tree (AST) of a code fragment
317
+
318
+ Parameters: ` ast ` ` comments `
0 commit comments