@@ -20,10 +20,12 @@ export interface MangleErrorsPluginOptions {
20
20
}
21
21
22
22
/**
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.
24
25
*
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.
27
29
*/
28
30
const evalToString = (
29
31
ast : Node | { type : 'Literal' ; value : string } ,
@@ -52,27 +54,49 @@ const evalToString = (
52
54
}
53
55
54
56
/**
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.
57
60
*
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.
59
64
*
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.
63
71
*
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>
68
74
*
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
+ * ```
72
81
*
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
+ * ```
76
100
*/
77
101
export const mangleErrorsPlugin = (
78
102
babel : Babel ,
0 commit comments