@mui/internal-babel-plugin-minify-errors 2.0.8-canary.20 → 2.0.8-canary.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { PluginObj, PluginPass } from '@babel/core';
2
+
3
+ export interface Options {
4
+ errorCodesPath?: string;
5
+ runtimeModule?: string;
6
+ detection?: 'opt-in' | 'opt-out';
7
+ outExtension?: string;
8
+ collectErrors?: Set<string | Error>;
9
+ }
10
+
11
+ declare function plugin(
12
+ babel: { types: typeof import('@babel/core').types },
13
+ options: Options,
14
+ ): PluginObj<PluginPass>;
15
+
16
+ export default plugin;
package/index.js CHANGED
@@ -29,19 +29,14 @@ const COMMENT_OPT_OUT_MARKER = 'minify-error-disabled';
29
29
  const SUPPORTED_ERROR_CONSTRUCTORS = new Set(['Error', 'TypeError']);
30
30
 
31
31
  /**
32
- * @typedef {import('@babel/core')} babel
32
+ * @typedef {typeof import('@babel/core')} babel
33
+ * @typedef {typeof import('@babel/core').types} BabelTypes
33
34
  */
34
35
 
35
36
  /**
36
37
  * @typedef {'annotate' | 'throw' | 'write'} MissingError
37
- * @typedef {babel.PluginPass & {formatErrorMessageIdentifier?: babel.types.Identifier, processedNodes?: WeakSet<babel.types.Node>}} PluginState
38
- * @typedef {{
39
- * errorCodesPath?: string,
40
- * runtimeModule?: string,
41
- * detection?: 'opt-in' | 'opt-out',
42
- * outExtension?: string,
43
- * collectErrors?: Set<string | Error>
44
- * }} Options
38
+ * @typedef {import('@babel/core').PluginPass & {formatErrorMessageIdentifier?: import('@babel/core').types.Identifier, processedNodes?: WeakSet<import('@babel/core').types.Node>}} PluginState
39
+ * @typedef {import('./index.d.ts').Options} Options
45
40
  */
46
41
 
47
42
  /**
@@ -53,8 +48,8 @@ const SUPPORTED_ERROR_CONSTRUCTORS = new Set(['Error', 'TypeError']);
53
48
 
54
49
  /**
55
50
  * Checks if a node is `process.env.NODE_ENV` using Babel types.
56
- * @param {babel.types} t
57
- * @param {babel.types.Node} node
51
+ * @param {BabelTypes} t
52
+ * @param {import('@babel/core').types.Node} node
58
53
  * @returns {boolean}
59
54
  */
60
55
  function isProcessEnvNodeEnv(t, node) {
@@ -70,8 +65,8 @@ function isProcessEnvNodeEnv(t, node) {
70
65
  /**
71
66
  * Checks if a binary expression compares `process.env.NODE_ENV` with a value using the given operator.
72
67
  * Handles both `process.env.NODE_ENV op value` and `value op process.env.NODE_ENV`.
73
- * @param {babel.types} t
74
- * @param {babel.types.BinaryExpression} node
68
+ * @param {BabelTypes} t
69
+ * @param {import('@babel/core').types.BinaryExpression} node
75
70
  * @param {string} operator
76
71
  * @param {string} value
77
72
  * @returns {boolean}
@@ -91,8 +86,8 @@ function isNodeEnvComparison(t, node, operator, value) {
91
86
  * (e.g. `if (process.env.NODE_ENV !== 'production') { ... }`).
92
87
  * Errors inside such branches are already stripped in production,
93
88
  * so minification is unnecessary.
94
- * @param {babel.types} t
95
- * @param {babel.NodePath} path
89
+ * @param {BabelTypes} t
90
+ * @param {import('@babel/core').NodePath} path
96
91
  * @returns {boolean}
97
92
  */
98
93
  function isInsideDevOnlyBranch(t, path) {
@@ -115,13 +110,13 @@ function isInsideDevOnlyBranch(t, path) {
115
110
  }
116
111
 
117
112
  /**
118
- * @typedef {{ path: babel.NodePath<babel.types.Expression>, message: string, expressions: babel.types.Expression[] }} ExtractedMessage
113
+ * @typedef {{ path: import('@babel/core').NodePath<import('@babel/core').types.Expression>, message: string, expressions: import('@babel/core').types.Expression[] }} ExtractedMessage
119
114
  */
120
115
 
121
116
  /**
122
117
  * Extracts the message and expressions from a path.
123
- * @param {babel.types} t
124
- * @param {babel.NodePath<babel.types.ArgumentPlaceholder | babel.types.SpreadElement | babel.types.Expression>} path
118
+ * @param {BabelTypes} t
119
+ * @param {import('@babel/core').NodePath<import('@babel/core').types.ArgumentPlaceholder | import('@babel/core').types.SpreadElement | import('@babel/core').types.Expression>} path
125
120
  * @returns {ExtractedMessage | null}
126
121
  */
127
122
  function extractMessage(t, path) {
@@ -162,10 +157,10 @@ function extractMessage(t, path) {
162
157
  }
163
158
 
164
159
  /**
165
- * @param {babel.types} t
166
- * @param {babel.NodePath<babel.types.NewExpression>} newExpressionPath
160
+ * @param {BabelTypes} t
161
+ * @param {import('@babel/core').NodePath<import('@babel/core').types.NewExpression>} newExpressionPath
167
162
  * @param {'opt-in' | 'opt-out'} detection
168
- * @returns {null | babel.NodePath<babel.types.ArgumentPlaceholder | babel.types.SpreadElement | babel.types.Expression>}
163
+ * @returns {null | import('@babel/core').NodePath<import('@babel/core').types.ArgumentPlaceholder | import('@babel/core').types.SpreadElement | import('@babel/core').types.Expression>}
169
164
  */
170
165
  function findMessageNode(t, newExpressionPath, detection) {
171
166
  const callee = newExpressionPath.get('callee');
@@ -211,13 +206,13 @@ function findMessageNode(t, newExpressionPath, detection) {
211
206
 
212
207
  /**
213
208
  * Transforms the error message node.
214
- * @param {babel.types} t
209
+ * @param {BabelTypes} t
215
210
  * @param {ExtractedMessage} extracted
216
211
  * @param {number} errorCode
217
212
  * @param {PluginState} state
218
213
  * @param {string} runtimeModule
219
214
  * @param {string} outExtension
220
- * @returns {babel.types.Expression}
215
+ * @returns {import('@babel/core').types.Expression}
221
216
  */
222
217
  function transformMessage(t, extracted, errorCode, state, runtimeModule, outExtension) {
223
218
  if (!state.formatErrorMessageIdentifier) {
@@ -299,9 +294,9 @@ function transformExtension(importSpecifier, outExtension = '.js') {
299
294
  }
300
295
 
301
296
  /**
302
- * @param {babel} file
297
+ * @param {{ types: BabelTypes }} file
303
298
  * @param {Options} options
304
- * @returns {babel.PluginObj<PluginState>}
299
+ * @returns {import('@babel/core').PluginObj<PluginState>}
305
300
  */
306
301
  module.exports = function plugin(
307
302
  { types: t },
@@ -327,7 +322,10 @@ module.exports = function plugin(
327
322
  const errorCodes = JSON.parse(errorCodesContent);
328
323
 
329
324
  errorCodesLookup = new Map(
330
- Object.entries(errorCodes).map(([key, value]) => [value, Number(key)]),
325
+ Object.entries(/** @type {Record<string, string>} */ (errorCodes)).map(([key, value]) => [
326
+ value,
327
+ Number(key),
328
+ ]),
331
329
  );
332
330
  }
333
331
 
package/index.test.js CHANGED
@@ -168,14 +168,14 @@ describe('collectErrors', () => {
168
168
  babelrc: false,
169
169
  });
170
170
 
171
- const collected = Array.from(errors);
171
+ const collected = /** @type {(string | Error)[]} */ (Array.from(errors));
172
172
  expect(collected).toHaveLength(2);
173
173
  expect(collected[0]).toBeInstanceOf(Error);
174
- expect(collected[0].message).toMatch(
174
+ expect(/** @type {Error} */ (collected[0]).message).toMatch(
175
175
  /Unminifyable error. You can only use literal strings and template strings as error messages./,
176
176
  );
177
177
  expect(collected[1]).toBeInstanceOf(Error);
178
- expect(collected[1].message).toMatch(
178
+ expect(/** @type {Error} */ (collected[1]).message).toMatch(
179
179
  /Unminifyable error. You can only use literal strings and template strings as error messages./,
180
180
  );
181
181
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-babel-plugin-minify-errors",
3
- "version": "2.0.8-canary.20",
3
+ "version": "2.0.8-canary.21",
4
4
  "author": "MUI Team",
5
5
  "description": "This is an internal package not meant for general use.",
6
6
  "repository": {
@@ -33,6 +33,7 @@
33
33
  "sideEffects": false,
34
34
  "type": "commonjs",
35
35
  "main": "./index.js",
36
+ "types": "./index.d.ts",
36
37
  "exports": {
37
38
  ".": "./index.js"
38
39
  },
@@ -42,6 +43,6 @@
42
43
  "publishConfig": {
43
44
  "access": "public"
44
45
  },
45
- "gitSha": "2836960cc7e128ab529942129c49aeffb8a0b76d",
46
+ "gitSha": "9e1c4e0467156c00cf964caeff1af4ca7f6d2412",
46
47
  "scripts": {}
47
48
  }
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2022",
4
- "module": "ESNext",
4
+ "module": "commonjs",
5
5
  "moduleResolution": "node",
6
6
  "allowJs": true,
7
7
  "checkJs": true,