Skip to content

Commit e3ad922

Browse files
committed
Improve on the docs
1 parent f0b37d3 commit e3ad922

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

packages/toolkit/scripts/mangleErrors.mts

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ export interface MangleErrorsPluginOptions {
2020
}
2121

2222
/**
23-
* Converts an AST type into a JavaScript string so that it can be added to the error message lookup.
23+
* Converts an AST type into a JavaScript string so that it can be added to
24+
* the error message lookup.
2425
*
25-
* Adapted from React (https://github.com/facebook/react/blob/master/scripts/shared/evalToString.js) with some
26-
* adjustments.
26+
* Adapted from React
27+
* {@linkcode https://github.com/facebook/react/blob/master/scripts/shared/evalToString.js | evalToString}
28+
* with some adjustments.
2729
*/
2830
const evalToString = (
2931
ast: Node | { type: 'Literal'; value: string },
@@ -52,27 +54,49 @@ const evalToString = (
5254
}
5355

5456
/**
55-
* Transforms a `throw new Error` statement based on the `minify` argument, resulting in a smaller bundle size
56-
* for consumers in production.
57+
* Transforms a `throw new Error` statement based on the
58+
* {@linkcode MangleErrorsPluginOptions.minify | minify} argument,
59+
* resulting in a smaller bundle size for consumers in production.
5760
*
58-
* If `minify` is enabled, the error message will be replaced with an index that maps to an object lookup.
61+
* If {@linkcode MangleErrorsPluginOptions.minify | minify} is enabled,
62+
* the error message will be replaced with an index that maps to
63+
* an object lookup.
5964
*
60-
* If `minify` is disabled, a conditional statement will be added to check `process.env.NODE_ENV`, which will output
61-
* an error number index in production or the actual error message in development. This allows consumers using Webpack
62-
* or another build tool to have these messages in development but only the error index in production.
65+
* If {@linkcode MangleErrorsPluginOptions.minify | minify} is disabled,
66+
* a conditional statement will be added to check `process.env.NODE_ENV`,
67+
* which will output an error number index in production or the actual
68+
* error message in development. This allows consumers using Webpack or
69+
* another build tool to have these messages in development but only the
70+
* error index in production.
6371
*
64-
* E.g.
65-
* Before:
66-
* throw new Error("This is my error message.");
67-
* throw new Error("This is a second error message.");
72+
* @example
73+
* <caption>__Before:__</caption>
6874
*
69-
* After (with minify):
70-
* throw new Error(0);
71-
* throw new Error(1);
75+
* ```ts
76+
* throw new Error('each middleware provided to configureStore must be a function');
77+
* throw new Error(
78+
* '`reducer` is a required argument, and must be a function or an object of functions that can be passed to combineReducers',
79+
* )
80+
* ```
7281
*
73-
* After (without minify):
74-
* throw new Error(process.env.NODE_ENV === 'production' ? 0 : "This is my error message.");
75-
* throw new Error(process.env.NODE_ENV === 'production' ? 1 : "This is a second error message.");
82+
* @example
83+
* <caption>__After (with minify):__</caption>
84+
*
85+
* ```ts
86+
* throw new Error(formatProdErrorMessage(0));
87+
* throw new Error(formatProdErrorMessage(1));
88+
* ```
89+
*
90+
* @example
91+
* <caption>__After (without minify):__</caption>
92+
*
93+
* ```ts
94+
* throw new Error(
95+
* process.env.NODE_ENV === 'production'
96+
* ? formatProdErrorMessage(4)
97+
* : 'each middleware provided to configureStore must be a function',
98+
* )
99+
* ```
76100
*/
77101
export const mangleErrorsPlugin = (
78102
babel: Babel,

0 commit comments

Comments
 (0)