Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/content/api/normalmodulefactory-hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ Called before a request with scheme (URI) is resolved.

- Callback Parameters: `resourceData` `resolveData`

## resolveInScheme

`HookMap<AsyncSeriesBailHook>`

<Badge text="5.49.0+" />

Called to resolve a request made from inside a resource that itself has a scheme, when the request carries no scheme of its own — the relative case of [`resolveForScheme`](#resolveforscheme). The map is keyed by the scheme of the importing resource. Return `true` to report the request as resolved; anything else lets webpack fall back to its normal resolution.

- Hook Parameters: `scheme`

- Callback Parameters: `resourceData` `resolveData`

## afterResolve

`AsyncSeriesBailHook`
Expand Down Expand Up @@ -103,6 +115,16 @@ Called after a `NormalModule` instance is created.

- Callback Parameters: `module` `createData` `resolveData`

## prepareModuleType

`HookMap<AsyncSeriesHook>`

<Badge text="5.110.0+" />

Called once for a module type before webpack needs that type's parser or generator, so a plugin can asynchronously load whatever its synchronous [`createParser`](#createparser) or [`createGenerator`](#creategenerator) tap then uses. A type nothing taps, or one already prepared, continues without waiting.

- Hook Parameters: `type`

## createParser

`HookMap<SyncBailHook>`
Expand Down
128 changes: 128 additions & 0 deletions src/content/api/parser.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,28 @@ Called when evaluating an identifier that is a defined variable.
- Hook Parameters: `identifier`
- Callback Parameters: `expression`

### evaluateNewExpression

`SyncBailHook`

<Badge text="5.73.0+" />

Called when evaluating a `new` expression, keyed by the name of the constructor being called.

- Hook Parameters: `identifier`
- Callback Parameters: `expression`

### evaluateCallExpression

`SyncBailHook`

<Badge text="5.73.0+" />

Called when evaluating a call whose callee is a plain identifier, keyed by that identifier's name.

- Hook Parameters: `identifier`
- Callback Parameters: `expression`

### evaluateCallExpressionMember

`SyncBailHook`
Expand Down Expand Up @@ -179,8 +201,19 @@ parser.hooks.evaluateCallExpressionMember.for("myFunc").tap(
);
```

### isPure

`SyncBailHook`

Called to decide whether a node is free of side effects, keyed by the node's type. Returning `false` marks it impure, which keeps webpack from dropping it.

- Hook Parameters: `type`
- Callback Parameters: `expression` `commentsStartPosition`

### statement

`SyncBailHook`### statement

`SyncBailHook`

General purpose hook that is called for every parsed statement in a code fragment.
Expand Down Expand Up @@ -225,6 +258,17 @@ Called for every statement during the pre-walk, before any statement of the bloc

- Callback Parameters: `statement`

### preStatementByType

`SyncBailHook`

<Badge text="5.109.0+" />

The per-type form of [`preStatement`](#prestatement), keyed by the statement's node type. It runs only when no `preStatement` tap has already bailed.

- Hook Parameters: `type`
- Callback Parameters: `statement`

### blockPreStatement

`SyncBailHook`
Expand All @@ -233,6 +277,17 @@ Same as [`preStatement`](#prestatement), but for the block pre-walk, which only

- Callback Parameters: `statement`

### blockPreStatementByType

`SyncBailHook`

<Badge text="5.109.0+" />

The per-type form of [`blockPreStatement`](#blockprestatement), keyed by the declaration's node type, and run on the same terms as [`preStatementByType`](#prestatementbytype).

- Hook Parameters: `type`
- Callback Parameters: `declaration`

### unusedStatement

`SyncBailHook`
Expand Down Expand Up @@ -433,6 +488,17 @@ Called when parsing a variable declaration defined using `const`
- Hook Parameters: `identifier`
- Callback Parameters: `identifier`

### varDeclarationUsing

`SyncBailHook`

<Badge text="5.100.0+" />

Called for a variable declared with `using` or `await using`, keyed by the declared name, alongside the [`let`](#vardeclarationlet), [`const`](#vardeclarationconst) and [`var`](#vardeclarationvar) forms.

- Hook Parameters: `identifier`
- Callback Parameters: `declaration`

### varDeclarationVar

`HookMap<SyncBailHook>`
Expand All @@ -442,6 +508,15 @@ Called when parsing a variable declaration defined using `var`
- Hook Parameters: `identifier`
- Callback Parameters: `identifier`

### pattern

`SyncBailHook`

Called for each identifier a destructuring pattern binds, keyed by that name.

- Hook Parameters: `identifier`
- Callback Parameters: `pattern`

### canRename

`SyncBailHook`
Expand Down Expand Up @@ -494,6 +569,15 @@ parser.hooks.assign.for("a").tap("MyPlugin", (expression) => {
});
```

### assignMemberChain

`SyncBailHook`

Called when a member chain is assigned to, keyed by the name the chain starts from.

- Hook Parameters: `identifier`
- Callback Parameters: `expression` `members`

### typeof

`SyncBailHook`
Expand Down Expand Up @@ -537,6 +621,24 @@ parser.hooks.callMemberChain
.tap("MyPlugin", (expression, properties) => {});
```

### memberChainOfCallMemberChain

`SyncBailHook`

Called for a member chain read off the result of a call that was itself made on a member chain, keyed by the name the chain starts from.

- Hook Parameters: `identifier`
- Callback Parameters: `expression` `calleeMembers` `callExpression` `members` `memberRanges`

### callMemberChainOfCallMemberChain

`SyncBailHook`

The same as [`memberChainOfCallMemberChain`](#memberchainofcallmemberchain), for when that outer member chain is itself called.

- Hook Parameters: `identifier`
- Callback Parameters: `expression` `calleeMembers` `callExpression` `members` `memberRanges`

### new

`SyncBailHook`
Expand Down Expand Up @@ -567,6 +669,24 @@ const a = this;
parser.hooks.expression.for("this").tap("MyPlugin", (expression) => {});
```

### expressionMemberChain

`SyncBailHook`

Called for a member chain read as an expression, keyed by the name the chain starts from.

- Hook Parameters: `identifier`
- Callback Parameters: `expression` `members` `membersOptionals` `memberRanges`

### unhandledExpressionMemberChain

`SyncBailHook`

Called for a member chain that [`expressionMemberChain`](#expressionmemberchain) left unhandled, keyed by the name the chain starts from.

- Hook Parameters: `identifier`
- Callback Parameters: `expression` `members`

### expressionConditionalOperator

`SyncBailHook`
Expand Down Expand Up @@ -657,6 +777,14 @@ Called with the test of a conditional expression to collect the guards it implie

- Callback Parameters: `expression`

### finish

`SyncBailHook`

Called after the whole program has been walked, with the parsed AST and its comments.

- Callback Parameters: `ast` `comments`

### program

`SyncBailHook`
Expand Down
Loading