Skip to content

Commit 558f963

Browse files
moshams272pranjalisr
authored andcommitted
docs(parser): provide practical example for parser hooks usage (webpack#7933)
1 parent b6a0a0a commit 558f963

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/content/api/parser.mdx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ contributors:
99
- EugeneHlushko
1010
- chenxsan
1111
- snitin315
12+
- moshams272
1213
---
1314

1415
The `parser` instance, found in the `compiler`, is used to parse each module
@@ -24,9 +25,17 @@ compiler.hooks.normalModuleFactory.tap("MyPlugin", (factory) => {
2425
factory.hooks.parser
2526
.for("javascript/auto")
2627
.tap("MyPlugin", (parser, options) => {
27-
parser.hooks.someHook.tap("MyPlugin", (data) => {
28-
// ...
29-
});
28+
// The `parser` provides many hooks, which are explained in detail below.
29+
// Here is a practical example using the `call` hook to detect and warn
30+
// about a deprecated API function when a developer calls it
31+
// (e.g., `myCustomApiFunction()`):
32+
parser.hooks.call
33+
.for("myCustomApiFunction")
34+
.tap("MyPlugin", (expression) => {
35+
console.warn(
36+
`Warning: 'myCustomApiFunction' is deprecated. Found call at line ${expression.loc.start.line}.`,
37+
);
38+
});
3039
});
3140
});
3241
```

0 commit comments

Comments
 (0)