From 898d46f5707376905a66e094181912aec2156443 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Fri, 27 Sep 2024 18:36:27 +0200 Subject: [PATCH 01/26] [code-infra] Move MuiError babel macros to babel plugin --- babel.config.js | 7 + .../babel-plugin-minify-errors/index.mjs | 202 ++++++++++++++++++ .../babel-plugin-minify-errors/package.json | 37 ++++ .../mui-material/src/InputBase/InputBase.js | 8 +- packages/mui-utils/src/muiErrorMsg/index.ts | 1 + .../mui-utils/src/muiErrorMsg/muiErrorMsg.ts | 5 + pnpm-lock.yaml | 18 ++ 7 files changed, 273 insertions(+), 5 deletions(-) create mode 100644 packages-internal/babel-plugin-minify-errors/index.mjs create mode 100644 packages-internal/babel-plugin-minify-errors/package.json create mode 100644 packages/mui-utils/src/muiErrorMsg/index.ts create mode 100644 packages/mui-utils/src/muiErrorMsg/muiErrorMsg.ts diff --git a/babel.config.js b/babel.config.js index cbadb0c6a75a97..e5045952938ca1 100644 --- a/babel.config.js +++ b/babel.config.js @@ -114,6 +114,13 @@ module.exports = function getBabelConfig(api) { ], }, ], + [ + '@mui/internal-babel-plugin-minify-errors', + { + missingError, + errorCodesPath, + }, + ], ...(useESModules ? [ [ diff --git a/packages-internal/babel-plugin-minify-errors/index.mjs b/packages-internal/babel-plugin-minify-errors/index.mjs new file mode 100644 index 00000000000000..a70cddba4dd156 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/index.mjs @@ -0,0 +1,202 @@ +// @ts-check + +import * as helperModuleImports from '@babel/helper-module-imports'; +import * as fs from 'fs'; + +/** + * @typedef {import('@babel/core')} babel + */ + +/** + * @typedef {{updatedErrorCodes?: boolean}} PluginState + * @typedef {'annotate' | 'throw' | 'write'} MissingError + * @typedef {{ errorCodesPath: string, missingError: MissingError }} Options + */ + +/** + * + * @param {babel.types} t + * @param {babel.NodePath} path + * @param {PluginState} state + * @param {{ + * localName: string, + * missingError: MissingError, + * errorCodesLookup: Map + * formatMuiErrorMessageIdentifier: babel.types.Identifier + * }} config + */ +function replaceTaggedTemplates( + t, + path, + state, + { localName, missingError, errorCodesLookup, formatMuiErrorMessageIdentifier }, +) { + path.traverse({ + TaggedTemplateExpression(taggedTemplatePath) { + if (!taggedTemplatePath.get('tag').isIdentifier({ name: localName })) { + return; + } + + // Input: + // `A message with ${interpolation}` + // Output: + // 'A message with %s', + const msg = taggedTemplatePath.node.quasi.quasis + .map((quasi) => quasi.value.cooked) + .join('%s'); + const expressions = taggedTemplatePath.node.quasi.expressions.map((expression) => { + if (t.isExpression(expression)) { + return expression; + } + throw new Error('Can only evaluate expressions.'); + }); + + let errorCode = errorCodesLookup.get(msg); + if (errorCode === undefined) { + switch (missingError) { + case 'annotate': { + // Outputs: + // /* FIXME (minify-errors-in-prod): Unminified error message in production build! */ + // throw new Error(muiErrorMsg`A message with ${interpolation}`) + taggedTemplatePath.addComment( + 'leading', + ' FIXME (minify-errors-in-prod): Unminified error message in production build! ', + ); + return; + } + case 'throw': { + throw new Error( + `Missing error code for message '${msg}'. Did you forget to run \`pnpm extract-error-codes\` first?`, + ); + } + case 'write': { + errorCode = errorCodesLookup.size + 1; + errorCodesLookup.set(msg, errorCode); + state.updatedErrorCodes = true; + break; + } + default: { + throw new Error(`Unknown missingError option: ${missingError}`); + } + } + } + + if (!formatMuiErrorMessageIdentifier) { + // Outputs: + // import { formatMuiErrorMessage } from '@mui/utils'; + formatMuiErrorMessageIdentifier = helperModuleImports.addDefault( + taggedTemplatePath, + '@mui/utils/formatMuiErrorMessage', + { nameHint: '_formatMuiErrorMessage' }, + ); + } + + // Outputs: + // `A ${adj} message that contains ${noun}`; + const devMessage = taggedTemplatePath.get('quasi').node; + + // Outputs: + // formatMuiErrorMessage(ERROR_CODE, adj, noun) + const prodMessage = t.callExpression(t.cloneNode(formatMuiErrorMessageIdentifier, true), [ + t.numericLiteral(errorCode), + ...expressions, + ]); + + // Outputs: + // new Error( + // process.env.NODE_ENV !== "production" + // ? `A message with ${interpolation}` + // : formatProdError('A message with %s', interpolation) + // ) + taggedTemplatePath.replaceWith( + t.conditionalExpression( + t.binaryExpression( + '!==', + t.memberExpression( + t.memberExpression(t.identifier('process'), t.identifier('env')), + t.identifier('NODE_ENV'), + ), + t.stringLiteral('production'), + ), + devMessage, + prodMessage, + ), + ); + }, + }); +} + +/** + * @param {babel} file + * @param {Options} options + * @returns {babel.PluginObj} + */ +export default function plugin({ types: t }, { errorCodesPath, missingError = 'annotate' }) { + if (!errorCodesPath) { + throw new Error('errorCodesPath is required.'); + } + + const errorCodesContent = fs.readFileSync(errorCodesPath, 'utf8'); + const errorCodes = JSON.parse(errorCodesContent); + + const errorCodesLookup = new Map( + Object.entries(errorCodes).map(([key, value]) => [value, Number(key)]), + ); + + return { + visitor: { + Program(path, state) { + for (const statement of path.get('body')) { + if (!statement.isImportDeclaration()) { + continue; + } + + if (statement.node.source.value !== '@mui/utils/muiErrorMsg') { + continue; + } + + const importSpecifiers = statement.get('specifiers'); + const defaultSpecifier = importSpecifiers.find((specifier) => + specifier.isImportDefaultSpecifier(), + ); + + if (!defaultSpecifier) { + return; + } + + const localName = defaultSpecifier.node.local.name; + + // TODO: safer to just keep this around and let minifiers remove it? + if (importSpecifiers.length === 1) { + statement.remove(); + } else { + defaultSpecifier.remove(); + } + + // Outputs: + // import { formatMuiErrorMessage } from '@mui/utils'; + const formatMuiErrorMessageIdentifier = helperModuleImports.addDefault( + path, + '@mui/utils/formatMuiErrorMessage', + { nameHint: '_formatMuiErrorMessage' }, + ); + + replaceTaggedTemplates(t, path, state, { + localName, + errorCodesLookup, + missingError, + formatMuiErrorMessageIdentifier, + }); + } + }, + }, + post() { + if (missingError === 'write' && this.updatedErrorCodes) { + const invertedErrorCodes = Object.fromEntries( + Array.from(errorCodesLookup, ([key, value]) => [value, key]), + ); + fs.writeFileSync(errorCodesPath, JSON.stringify(invertedErrorCodes, null, 2)); + } + }, + }; +} diff --git a/packages-internal/babel-plugin-minify-errors/package.json b/packages-internal/babel-plugin-minify-errors/package.json new file mode 100644 index 00000000000000..4bdb7857262168 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/package.json @@ -0,0 +1,37 @@ +{ + "name": "@mui/internal-babel-plugin-minify-errors", + "version": "1.0.9", + "author": "MUI Team", + "description": "This is an internal package not meant for general use.", + "repository": { + "type": "git", + "url": "git+https://github.com/mui/material-ui.git", + "directory": "packages/mui-babel-plugin-minify-errors" + }, + "license": "MIT", + "bugs": { + "url": "https://github.com/mui/material-ui/issues" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mui-org" + }, + "scripts": {}, + "dependencies": { + "@babel/helper-module-imports": "^7.24.7" + }, + "devDependencies": { + "@types/babel__helper-module-imports": "^7.18.3" + }, + "sideEffects": false, + "type": "module", + "exports": { + ".": "./index.mjs" + }, + "engines": { + "node": ">=14.0.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/mui-material/src/InputBase/InputBase.js b/packages/mui-material/src/InputBase/InputBase.js index 7333c1c4f32cf5..2cae9dab8d4ac7 100644 --- a/packages/mui-material/src/InputBase/InputBase.js +++ b/packages/mui-material/src/InputBase/InputBase.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'; import clsx from 'clsx'; import elementTypeAcceptingRef from '@mui/utils/elementTypeAcceptingRef'; import refType from '@mui/utils/refType'; -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; +import muiErrorMsg from '@mui/utils/muiErrorMsg'; import composeClasses from '@mui/utils/composeClasses'; import TextareaAutosize from '../TextareaAutosize'; import isHostComponent from '../utils/isHostComponent'; @@ -425,10 +425,8 @@ const InputBase = React.forwardRef(function InputBase(inProps, ref) { if (!isControlled) { const element = event.target || inputRef.current; if (element == null) { - throw new MuiError( - 'MUI: Expected valid input target. ' + - 'Did you use a custom `inputComponent` and forget to forward refs? ' + - 'See https://mui.com/r/input-component-ref-interface for more info.', + throw new Error( + muiErrorMsg`MUI: Expected valid input target. Did you use a custom \`inputComponent\` and forget to forward refs? See https://mui.com/r/input-component-ref-interface for more info.`, ); } diff --git a/packages/mui-utils/src/muiErrorMsg/index.ts b/packages/mui-utils/src/muiErrorMsg/index.ts new file mode 100644 index 00000000000000..98e4a8bf4ec8e2 --- /dev/null +++ b/packages/mui-utils/src/muiErrorMsg/index.ts @@ -0,0 +1 @@ +export { default } from './muiErrorMsg'; diff --git a/packages/mui-utils/src/muiErrorMsg/muiErrorMsg.ts b/packages/mui-utils/src/muiErrorMsg/muiErrorMsg.ts new file mode 100644 index 00000000000000..a2b3f2815cbf06 --- /dev/null +++ b/packages/mui-utils/src/muiErrorMsg/muiErrorMsg.ts @@ -0,0 +1,5 @@ +export default function muiErrorMsg(strings: TemplateStringsArray, ...args: unknown[]) { + return strings.reduce((prev, current, i) => { + return prev + current + (args[i] || ''); + }, ''); +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a45e0a4babf3d7..256f5082a48c1a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -910,6 +910,16 @@ importers: specifier: ^17.7.2 version: 17.7.2 + packages-internal/babel-plugin-minify-errors: + dependencies: + '@babel/helper-module-imports': + specifier: ^7.24.7 + version: 7.24.7 + devDependencies: + '@types/babel__helper-module-imports': + specifier: ^7.18.3 + version: 7.18.3 + packages-internal/babel-plugin-resolve-imports: dependencies: '@babel/core': @@ -5374,6 +5384,9 @@ packages: '@types/babel__generator@7.6.4': resolution: {integrity: sha512-tFkciB9j2K755yrTALxD44McOrk+gfpIpvC3sxHjRawj6PfnQxrse4Clq5y/Rq+G3mrBurMax/lG8Qn2t9mSsg==} + '@types/babel__helper-module-imports@7.18.3': + resolution: {integrity: sha512-2pyr9Vlriessj2KI85SEF7qma8vA3vzquQMw3wn6kL5lsfjH/YxJ1Noytk4/FJElpYybUbyaC37CVfEgfyme9A==} + '@types/babel__template@7.4.1': resolution: {integrity: sha512-azBFKemX6kMg5Io+/rdGT0dkGreboUVR0Cdm3fz9QJWpaQGJRQXl7C+6hOTCZcMll7KFyEQpgbYI2lHdsS4U7g==} @@ -16680,6 +16693,11 @@ snapshots: dependencies: '@babel/types': 7.25.6 + '@types/babel__helper-module-imports@7.18.3': + dependencies: + '@types/babel__core': 7.20.5 + '@types/babel__traverse': 7.20.6 + '@types/babel__template@7.4.1': dependencies: '@babel/parser': 7.25.6 From 0e4f0ce57f947ad1f3cfd4c7d7de74a1843b9695 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Fri, 27 Sep 2024 23:07:26 +0200 Subject: [PATCH 02/26] Update babel.config.js --- babel.config.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/babel.config.js b/babel.config.js index e5045952938ca1..f91fa21b08b313 100644 --- a/babel.config.js +++ b/babel.config.js @@ -114,13 +114,17 @@ module.exports = function getBabelConfig(api) { ], }, ], - [ - '@mui/internal-babel-plugin-minify-errors', - { - missingError, - errorCodesPath, - }, - ], + ...(process.env.DANGER + ? [] + : [ + [ + '@mui/internal-babel-plugin-minify-errors', + { + missingError, + errorCodesPath, + }, + ], + ]), ...(useESModules ? [ [ From 815a5858073f4a0b7323ffe47173dfbbf33695cd Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Fri, 27 Sep 2024 23:07:32 +0200 Subject: [PATCH 03/26] Update config.yml --- .circleci/config.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9bd42f2bc52a5a..93aa1faee67b3d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -457,7 +457,7 @@ jobs: command: xvfb-run pnpm test:regressions - run: name: Build packages for fixtures - command: xvfb-run pnpm release:build + command: pnpm release:build - run: name: Run visual regression tests using Pigment CSS command: xvfb-run pnpm test:regressions-pigment-css @@ -667,6 +667,7 @@ jobs: name: prepare danger on PRs command: pnpm danger ci environment: + DANGER: '1' DANGER_COMMAND: prepareBundleSizeReport - run: name: build @mui packages @@ -736,6 +737,7 @@ jobs: name: Run danger on PRs command: pnpm danger ci --fail-on-errors environment: + DANGER: '1' DANGER_COMMAND: reportBundleSize test_benchmark: <<: *default-job From 7073b26ffc56d21770086df949d6408352c2df1b Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Fri, 27 Sep 2024 23:38:49 +0200 Subject: [PATCH 04/26] dwef --- .circleci/config.yml | 2 -- babel.config.js | 18 +++++++----------- .../{index.mjs => index.js} | 8 ++++---- .../babel-plugin-minify-errors/package.json | 4 ++-- 4 files changed, 13 insertions(+), 19 deletions(-) rename packages-internal/babel-plugin-minify-errors/{index.mjs => index.js} (96%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 93aa1faee67b3d..2484c807efb285 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -667,7 +667,6 @@ jobs: name: prepare danger on PRs command: pnpm danger ci environment: - DANGER: '1' DANGER_COMMAND: prepareBundleSizeReport - run: name: build @mui packages @@ -737,7 +736,6 @@ jobs: name: Run danger on PRs command: pnpm danger ci --fail-on-errors environment: - DANGER: '1' DANGER_COMMAND: reportBundleSize test_benchmark: <<: *default-job diff --git a/babel.config.js b/babel.config.js index f91fa21b08b313..e5045952938ca1 100644 --- a/babel.config.js +++ b/babel.config.js @@ -114,17 +114,13 @@ module.exports = function getBabelConfig(api) { ], }, ], - ...(process.env.DANGER - ? [] - : [ - [ - '@mui/internal-babel-plugin-minify-errors', - { - missingError, - errorCodesPath, - }, - ], - ]), + [ + '@mui/internal-babel-plugin-minify-errors', + { + missingError, + errorCodesPath, + }, + ], ...(useESModules ? [ [ diff --git a/packages-internal/babel-plugin-minify-errors/index.mjs b/packages-internal/babel-plugin-minify-errors/index.js similarity index 96% rename from packages-internal/babel-plugin-minify-errors/index.mjs rename to packages-internal/babel-plugin-minify-errors/index.js index a70cddba4dd156..81f78b0d5ea36c 100644 --- a/packages-internal/babel-plugin-minify-errors/index.mjs +++ b/packages-internal/babel-plugin-minify-errors/index.js @@ -1,7 +1,7 @@ // @ts-check -import * as helperModuleImports from '@babel/helper-module-imports'; -import * as fs from 'fs'; +const helperModuleImports = require('@babel/helper-module-imports'); +const fs = require('fs'); /** * @typedef {import('@babel/core')} babel @@ -131,7 +131,7 @@ function replaceTaggedTemplates( * @param {Options} options * @returns {babel.PluginObj} */ -export default function plugin({ types: t }, { errorCodesPath, missingError = 'annotate' }) { +module.exports = function plugin({ types: t }, { errorCodesPath, missingError = 'annotate' }) { if (!errorCodesPath) { throw new Error('errorCodesPath is required.'); } @@ -199,4 +199,4 @@ export default function plugin({ types: t }, { errorCodesPath, missingError = 'a } }, }; -} +}; diff --git a/packages-internal/babel-plugin-minify-errors/package.json b/packages-internal/babel-plugin-minify-errors/package.json index 4bdb7857262168..be02390bc0a974 100644 --- a/packages-internal/babel-plugin-minify-errors/package.json +++ b/packages-internal/babel-plugin-minify-errors/package.json @@ -24,9 +24,9 @@ "@types/babel__helper-module-imports": "^7.18.3" }, "sideEffects": false, - "type": "module", + "type": "commonjs", "exports": { - ".": "./index.mjs" + ".": "./index.js" }, "engines": { "node": ">=14.0.0" From 9fb40f51fc20bab75c81288e6c025fba5b372fe3 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 28 Sep 2024 08:28:20 +0200 Subject: [PATCH 05/26] wip --- dangerfile.ts => dangerFileContent.ts | 13 +++++-------- dangerfile.js | 12 ++++++++++++ 2 files changed, 17 insertions(+), 8 deletions(-) rename dangerfile.ts => dangerFileContent.ts (97%) create mode 100644 dangerfile.js diff --git a/dangerfile.ts b/dangerFileContent.ts similarity index 97% rename from dangerfile.ts rename to dangerFileContent.ts index 3b17317e6ba195..6c6adb67767a27 100644 --- a/dangerfile.ts +++ b/dangerFileContent.ts @@ -1,9 +1,11 @@ -// danger has to be the first thing required! -import { danger, markdown } from 'danger'; import { exec } from 'child_process'; +import type { DangerDSLType, MarkdownString } from 'danger'; import { loadComparison } from './scripts/sizeSnapshot'; import replaceUrl from './packages/api-docs-builder/utils/replaceUrl'; +declare const danger: DangerDSLType; +declare function markdown(message: MarkdownString, file?: string, line?: number): void; + const circleCIBuildNumber = process.env.CIRCLE_BUILD_NUM; const circleCIBuildUrl = `https://app.circleci.com/pipelines/github/mui/material-ui/jobs/${circleCIBuildNumber}`; const dangerCommand = process.env.DANGER_COMMAND; @@ -237,7 +239,7 @@ ${ `); } -async function run() { +export default async function run() { addDeployPreviewUrls(); switch (dangerCommand) { @@ -255,8 +257,3 @@ async function run() { throw new TypeError(`Unrecognized danger command '${dangerCommand}'`); } } - -run().catch((error) => { - console.error(error); - process.exit(1); -}); diff --git a/dangerfile.js b/dangerfile.js new file mode 100644 index 00000000000000..191c2e854ceac4 --- /dev/null +++ b/dangerfile.js @@ -0,0 +1,12 @@ +// danger uses babelify under the hood. The implementation is buggy and fails on our +// custom plugins in our codebase. We just disable it and do our own compilation +require('@babel/register')({ + extensions: ['.js', '.ts', '.tsx'], +}); + +const run = require('./dangerFileContent'); + +run.default().catch((error) => { + console.error(error); + process.exit(1); +}); From 1a04819b2254490e0dd848cda8252c1acfb8ce2d Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 28 Sep 2024 08:32:02 +0200 Subject: [PATCH 06/26] clean p --- .circleci/config.yml | 1 + dangerFileContent.ts | 5 +++++ dangerfile.js | 11 +++-------- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2484c807efb285..2220c39651fb39 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -42,6 +42,7 @@ default-job: &default-job TEST_GATE: << parameters.test-gate >> AWS_REGION_ARTIFACTS: eu-central-1 COREPACK_ENABLE_DOWNLOAD_PROMPT: '0' + DANGER_DISABLE_TRANSPILATION: 'true' working_directory: /tmp/material-ui docker: - image: cimg/node:20.17 diff --git a/dangerFileContent.ts b/dangerFileContent.ts index 6c6adb67767a27..584e7f9920f3ff 100644 --- a/dangerFileContent.ts +++ b/dangerFileContent.ts @@ -257,3 +257,8 @@ export default async function run() { throw new TypeError(`Unrecognized danger command '${dangerCommand}'`); } } + +run().catch((error) => { + console.error(error); + process.exit(1); +}); diff --git a/dangerfile.js b/dangerfile.js index 191c2e854ceac4..5862e174a8ab7a 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -1,12 +1,7 @@ // danger uses babelify under the hood. The implementation is buggy and fails on our -// custom plugins in our codebase. We just disable it and do our own compilation +// custom plugins in our codebase. We'll just disable it and do our own compilation. +// Danger must always be run with envirnonent variable `DANGER_DISABLE_TRANSPILATION="true"`. require('@babel/register')({ extensions: ['.js', '.ts', '.tsx'], }); - -const run = require('./dangerFileContent'); - -run.default().catch((error) => { - console.error(error); - process.exit(1); -}); +require('./dangerFileContent'); From 7fcc5ce927186df4b894263af29b531a5629eed2 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 28 Sep 2024 08:36:09 +0200 Subject: [PATCH 07/26] Update dangerFileContent.ts --- dangerFileContent.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dangerFileContent.ts b/dangerFileContent.ts index 584e7f9920f3ff..2f22472d48b178 100644 --- a/dangerFileContent.ts +++ b/dangerFileContent.ts @@ -1,10 +1,10 @@ import { exec } from 'child_process'; -import type { DangerDSLType, MarkdownString } from 'danger'; +import type * as dangerModule from 'danger'; import { loadComparison } from './scripts/sizeSnapshot'; import replaceUrl from './packages/api-docs-builder/utils/replaceUrl'; -declare const danger: DangerDSLType; -declare function markdown(message: MarkdownString, file?: string, line?: number): void; +declare const danger: (typeof dangerModule)['danger']; +declare const markdown: (typeof dangerModule)['markdown']; const circleCIBuildNumber = process.env.CIRCLE_BUILD_NUM; const circleCIBuildUrl = `https://app.circleci.com/pipelines/github/mui/material-ui/jobs/${circleCIBuildNumber}`; From b70569545f0c27e3116a2ee8afcf6e8f5613837a Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 28 Sep 2024 10:02:36 +0200 Subject: [PATCH 08/26] Update dangerFileContent.ts --- dangerFileContent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dangerFileContent.ts b/dangerFileContent.ts index 2f22472d48b178..ee34fafdc9d622 100644 --- a/dangerFileContent.ts +++ b/dangerFileContent.ts @@ -239,7 +239,7 @@ ${ `); } -export default async function run() { +async function run() { addDeployPreviewUrls(); switch (dangerCommand) { From 53f24ad41f344606e13f6412f9b77520de1ae05b Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Mon, 30 Sep 2024 14:43:10 +0200 Subject: [PATCH 09/26] All errors --- .../babel-plugin-minify-errors/index.js | 272 +++++++++--------- .../mui-material/src/InputBase/InputBase.js | 5 +- packages/mui-utils/src/muiErrorMsg/index.ts | 1 - .../mui-utils/src/muiErrorMsg/muiErrorMsg.ts | 5 - 4 files changed, 142 insertions(+), 141 deletions(-) delete mode 100644 packages/mui-utils/src/muiErrorMsg/index.ts delete mode 100644 packages/mui-utils/src/muiErrorMsg/muiErrorMsg.ts diff --git a/packages-internal/babel-plugin-minify-errors/index.js b/packages-internal/babel-plugin-minify-errors/index.js index 81f78b0d5ea36c..d96756ce15ad0f 100644 --- a/packages-internal/babel-plugin-minify-errors/index.js +++ b/packages-internal/babel-plugin-minify-errors/index.js @@ -8,7 +8,7 @@ const fs = require('fs'); */ /** - * @typedef {{updatedErrorCodes?: boolean}} PluginState + * @typedef {{updatedErrorCodes?: boolean, formatMuiErrorMessageIdentifier?: babel.types.Identifier}} PluginState * @typedef {'annotate' | 'throw' | 'write'} MissingError * @typedef {{ errorCodesPath: string, missingError: MissingError }} Options */ @@ -16,114 +16,70 @@ const fs = require('fs'); /** * * @param {babel.types} t - * @param {babel.NodePath} path - * @param {PluginState} state - * @param {{ - * localName: string, - * missingError: MissingError, - * errorCodesLookup: Map - * formatMuiErrorMessageIdentifier: babel.types.Identifier - * }} config + * @param {babel.types.Node} node + * @returns {{ message: string, expressions: babel.types.Expression[] } | null} */ -function replaceTaggedTemplates( - t, - path, - state, - { localName, missingError, errorCodesLookup, formatMuiErrorMessageIdentifier }, -) { - path.traverse({ - TaggedTemplateExpression(taggedTemplatePath) { - if (!taggedTemplatePath.get('tag').isIdentifier({ name: localName })) { - return; - } - - // Input: - // `A message with ${interpolation}` - // Output: - // 'A message with %s', - const msg = taggedTemplatePath.node.quasi.quasis - .map((quasi) => quasi.value.cooked) - .join('%s'); - const expressions = taggedTemplatePath.node.quasi.expressions.map((expression) => { +function extractMessageFromExpression(t, node) { + if (t.isTemplateLiteral(node)) { + return { + message: node.quasis.map((quasi) => quasi.value.cooked).join('%s'), + expressions: node.expressions.map((expression) => { if (t.isExpression(expression)) { return expression; } - throw new Error('Can only evaluate expressions.'); - }); - - let errorCode = errorCodesLookup.get(msg); - if (errorCode === undefined) { - switch (missingError) { - case 'annotate': { - // Outputs: - // /* FIXME (minify-errors-in-prod): Unminified error message in production build! */ - // throw new Error(muiErrorMsg`A message with ${interpolation}`) - taggedTemplatePath.addComment( - 'leading', - ' FIXME (minify-errors-in-prod): Unminified error message in production build! ', - ); - return; - } - case 'throw': { - throw new Error( - `Missing error code for message '${msg}'. Did you forget to run \`pnpm extract-error-codes\` first?`, - ); - } - case 'write': { - errorCode = errorCodesLookup.size + 1; - errorCodesLookup.set(msg, errorCode); - state.updatedErrorCodes = true; - break; - } - default: { - throw new Error(`Unknown missingError option: ${missingError}`); - } - } - } - - if (!formatMuiErrorMessageIdentifier) { - // Outputs: - // import { formatMuiErrorMessage } from '@mui/utils'; - formatMuiErrorMessageIdentifier = helperModuleImports.addDefault( - taggedTemplatePath, - '@mui/utils/formatMuiErrorMessage', - { nameHint: '_formatMuiErrorMessage' }, - ); - } - - // Outputs: - // `A ${adj} message that contains ${noun}`; - const devMessage = taggedTemplatePath.get('quasi').node; - - // Outputs: - // formatMuiErrorMessage(ERROR_CODE, adj, noun) - const prodMessage = t.callExpression(t.cloneNode(formatMuiErrorMessageIdentifier, true), [ - t.numericLiteral(errorCode), - ...expressions, - ]); + throw new Error('Can only evaluate javascript template literals.'); + }), + }; + } + if (t.isStringLiteral(node)) { + return { message: node.value, expressions: [] }; + } + if (t.isBinaryExpression(node) && node.operator === '+') { + if (t.isPrivateName(node.left)) { + // This is only psossible with `in` expressions, e.g. `#foo in {}` + throw new Error('Unreachable'); + } + const left = extractMessageFromExpression(t, node.left); + const right = extractMessageFromExpression(t, node.right); + if (!left || !right) { + return null; + } + return { + message: left.message + right.message, + expressions: [...left.expressions, ...right.expressions], + }; + } + return null; +} +/** + * + * @param {MissingError} missingError + * @param {babel.NodePath} path + * @returns + */ +function handleUnminifyable(missingError, path) { + switch (missingError) { + case 'annotate': { // Outputs: - // new Error( - // process.env.NODE_ENV !== "production" - // ? `A message with ${interpolation}` - // : formatProdError('A message with %s', interpolation) - // ) - taggedTemplatePath.replaceWith( - t.conditionalExpression( - t.binaryExpression( - '!==', - t.memberExpression( - t.memberExpression(t.identifier('process'), t.identifier('env')), - t.identifier('NODE_ENV'), - ), - t.stringLiteral('production'), - ), - devMessage, - prodMessage, - ), + // /* FIXME (minify-errors-in-prod): Unminified error message in production build! */ + // throw new Error(foo) + path.addComment( + 'leading', + ' FIXME (minify-errors-in-prod): Unminifyable error in production! ', ); - }, - }); + return; + } + case 'throw': { + throw new Error(`Unminifyable error.`); + } + case 'write': { + return; + } + default: { + throw new Error(`Unknown missingError option: ${missingError}`); + } + } } /** @@ -145,49 +101,99 @@ module.exports = function plugin({ types: t }, { errorCodesPath, missingError = return { visitor: { - Program(path, state) { - for (const statement of path.get('body')) { - if (!statement.isImportDeclaration()) { - continue; - } - - if (statement.node.source.value !== '@mui/utils/muiErrorMsg') { - continue; - } + NewExpression(newExpressionPath, state) { + if (!newExpressionPath.get('callee').isIdentifier({ name: 'Error' })) { + return; + } + const messagePath = newExpressionPath.get('arguments')[0]; + if (!messagePath) { + return; + } - const importSpecifiers = statement.get('specifiers'); - const defaultSpecifier = importSpecifiers.find((specifier) => - specifier.isImportDefaultSpecifier(), - ); + const messageNode = messagePath.node; + if (t.isSpreadElement(messageNode) || t.isArgumentPlaceholder(messageNode)) { + handleUnminifyable(missingError, newExpressionPath); + return; + } - if (!defaultSpecifier) { - return; - } + const message = extractMessageFromExpression(t, messageNode); - const localName = defaultSpecifier.node.local.name; + if (!message) { + handleUnminifyable(missingError, newExpressionPath); + return; + } - // TODO: safer to just keep this around and let minifiers remove it? - if (importSpecifiers.length === 1) { - statement.remove(); - } else { - defaultSpecifier.remove(); + let errorCode = errorCodesLookup.get(message.message); + if (errorCode === undefined) { + switch (missingError) { + case 'annotate': { + // Outputs: + // /* FIXME (minify-errors-in-prod): Unminified error message in production build! */ + // throw new Error(`A message with ${interpolation}`) + newExpressionPath.addComment( + 'leading', + ' FIXME (minify-errors-in-prod): Unminified error message in production build! ', + ); + return; + } + case 'throw': { + throw new Error( + `Missing error code for message '${message.message}'. Did you forget to run \`pnpm extract-error-codes\` first?`, + ); + } + case 'write': { + errorCode = errorCodesLookup.size + 1; + errorCodesLookup.set(message.message, errorCode); + state.updatedErrorCodes = true; + break; + } + default: { + throw new Error(`Unknown missingError option: ${missingError}`); + } } + } + if (!state.formatMuiErrorMessageIdentifier) { // Outputs: // import { formatMuiErrorMessage } from '@mui/utils'; - const formatMuiErrorMessageIdentifier = helperModuleImports.addDefault( - path, + state.formatMuiErrorMessageIdentifier = helperModuleImports.addDefault( + newExpressionPath, '@mui/utils/formatMuiErrorMessage', { nameHint: '_formatMuiErrorMessage' }, ); - - replaceTaggedTemplates(t, path, state, { - localName, - errorCodesLookup, - missingError, - formatMuiErrorMessageIdentifier, - }); } + + // Outputs: + // `A ${adj} message that contains ${noun}`; + const devMessage = messageNode; + + // Outputs: + // formatMuiErrorMessage(ERROR_CODE, adj, noun) + const prodMessage = t.callExpression( + t.cloneNode(state.formatMuiErrorMessageIdentifier, true), + [t.numericLiteral(errorCode), ...message.expressions], + ); + + // Outputs: + // new Error( + // process.env.NODE_ENV !== "production" + // ? `A message with ${interpolation}` + // : formatProdError('A message with %s', interpolation) + // ) + messagePath.replaceWith( + t.conditionalExpression( + t.binaryExpression( + '!==', + t.memberExpression( + t.memberExpression(t.identifier('process'), t.identifier('env')), + t.identifier('NODE_ENV'), + ), + t.stringLiteral('production'), + ), + devMessage, + prodMessage, + ), + ); }, }, post() { diff --git a/packages/mui-material/src/InputBase/InputBase.js b/packages/mui-material/src/InputBase/InputBase.js index 2cae9dab8d4ac7..c3fe3d3d1ffdfa 100644 --- a/packages/mui-material/src/InputBase/InputBase.js +++ b/packages/mui-material/src/InputBase/InputBase.js @@ -4,7 +4,6 @@ import PropTypes from 'prop-types'; import clsx from 'clsx'; import elementTypeAcceptingRef from '@mui/utils/elementTypeAcceptingRef'; import refType from '@mui/utils/refType'; -import muiErrorMsg from '@mui/utils/muiErrorMsg'; import composeClasses from '@mui/utils/composeClasses'; import TextareaAutosize from '../TextareaAutosize'; import isHostComponent from '../utils/isHostComponent'; @@ -426,7 +425,9 @@ const InputBase = React.forwardRef(function InputBase(inProps, ref) { const element = event.target || inputRef.current; if (element == null) { throw new Error( - muiErrorMsg`MUI: Expected valid input target. Did you use a custom \`inputComponent\` and forget to forward refs? See https://mui.com/r/input-component-ref-interface for more info.`, + 'MUI: Expected valid input target. ' + + 'Did you use a custom `inputComponent` and forget to forward refs? ' + + 'See https://mui.com/r/input-component-ref-interface for more info.', ); } diff --git a/packages/mui-utils/src/muiErrorMsg/index.ts b/packages/mui-utils/src/muiErrorMsg/index.ts deleted file mode 100644 index 98e4a8bf4ec8e2..00000000000000 --- a/packages/mui-utils/src/muiErrorMsg/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { default } from './muiErrorMsg'; diff --git a/packages/mui-utils/src/muiErrorMsg/muiErrorMsg.ts b/packages/mui-utils/src/muiErrorMsg/muiErrorMsg.ts deleted file mode 100644 index a2b3f2815cbf06..00000000000000 --- a/packages/mui-utils/src/muiErrorMsg/muiErrorMsg.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default function muiErrorMsg(strings: TemplateStringsArray, ...args: unknown[]) { - return strings.reduce((prev, current, i) => { - return prev + current + (args[i] || ''); - }, ''); -} From 36565ac864ca380c7b50f6398fcc87976e8c50b9 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:23:38 +0200 Subject: [PATCH 10/26] copy over tests --- .eslintrc.js | 4 + .../__fixtures__/.eslintrc.js | 12 +++ .../error-codes.after.json | 4 + .../error-codes.before.json | 3 + .../error-code-extraction/input.js | 2 + .../error-code-extraction/output.js | 5 ++ .../__fixtures__/literal/error-codes.json | 3 + .../__fixtures__/literal/input.js | 1 + .../__fixtures__/literal/output.js | 6 ++ .../no-error-code-annotation/error-codes.json | 1 + .../no-error-code-annotation/input.js | 1 + .../no-error-code-annotation/output.js | 3 + .../no-error-code-throw/error-codes.json | 1 + .../__fixtures__/no-error-code-throw/input.js | 1 + .../babel-plugin-minify-errors/index.test.js | 84 +++++++++++++++++++ .../babel-plugin-minify-errors/package.json | 8 +- pnpm-lock.yaml | 79 +++++++++-------- 17 files changed, 179 insertions(+), 39 deletions(-) create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/.eslintrc.js create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/error-codes.after.json create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/error-codes.before.json create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/input.js create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/output.js create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/literal/error-codes.json create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/literal/output.js create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/error-codes.json create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/input.js create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/output.js create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/error-codes.json create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/input.js create mode 100644 packages-internal/babel-plugin-minify-errors/index.test.js diff --git a/.eslintrc.js b/.eslintrc.js index 8c828c846ffa23..168786dfac72c4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -228,6 +228,10 @@ module.exports = { "The 'use client' pragma can't be used with export * in the same module. This is not supported by Next.js.", selector: 'ExpressionStatement[expression.value="use client"] ~ ExportAllDeclaration', }, + { + message: "Use 'throw new Error(...)' instead of 'throw Error(...)'.", + selector: "ThrowStatement > CallExpression[callee.name='Error']", + }, ], // We re-export default in many places, remove when https://github.com/airbnb/javascript/issues/2500 gets resolved diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/.eslintrc.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/.eslintrc.js new file mode 100644 index 00000000000000..4b5538251f2805 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/.eslintrc.js @@ -0,0 +1,12 @@ +module.exports = { + rules: { + // keeps test simple + 'no-unreachable': 'off', + // keeps test simple + 'no-useless-concat': 'off', + + // Babel import helpers do not add one. + // Since this is auto generated code we don't care about code style. + 'import/newline-after-import': 'off', + }, +}; diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/error-codes.after.json b/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/error-codes.after.json new file mode 100644 index 00000000000000..de8fbe089805cd --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/error-codes.after.json @@ -0,0 +1,4 @@ +{ + "1": "exists", + "2": "will be created" +} diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/error-codes.before.json b/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/error-codes.before.json new file mode 100644 index 00000000000000..c6c451ad4dec41 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/error-codes.before.json @@ -0,0 +1,3 @@ +{ + "1": "exists" +} diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/input.js new file mode 100644 index 00000000000000..3654728a32bb3a --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/input.js @@ -0,0 +1,2 @@ +throw new Error('exists'); +throw new Error('will be created'); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/output.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/output.js new file mode 100644 index 00000000000000..41342d27e3b230 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/output.js @@ -0,0 +1,5 @@ +import _formatMuiErrorMessage from '@mui/utils/formatMuiErrorMessage'; +throw new Error(process.env.NODE_ENV !== 'production' ? 'exists' : _formatMuiErrorMessage(1)); +throw new Error( + process.env.NODE_ENV !== 'production' ? 'will be created' : _formatMuiErrorMessage(2), +); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/error-codes.json b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/error-codes.json new file mode 100644 index 00000000000000..c209c45d724a19 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/error-codes.json @@ -0,0 +1,3 @@ +{ + "1": "MUI: Expected valid input target.\nDid you use `inputComponent`" +} diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js new file mode 100644 index 00000000000000..7ad6f799674480 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js @@ -0,0 +1 @@ +throw new Error('MUI: Expected valid input target.\n' + 'Did you use `inputComponent`'); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/output.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/output.js new file mode 100644 index 00000000000000..c41e3b01fda8b1 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/output.js @@ -0,0 +1,6 @@ +import _formatMuiErrorMessage from '@mui/utils/formatMuiErrorMessage'; +throw new Error( + process.env.NODE_ENV !== 'production' + ? 'MUI: Expected valid input target.\n' + 'Did you use `inputComponent`' + : _formatMuiErrorMessage(1), +); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/error-codes.json b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/error-codes.json new file mode 100644 index 00000000000000..0967ef424bce67 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/error-codes.json @@ -0,0 +1 @@ +{} diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/input.js new file mode 100644 index 00000000000000..5bcce1cf2b7ce4 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/input.js @@ -0,0 +1 @@ +throw new Error('MUI: Expected valid input target.\n' + 'Did you use inputComponent'); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/output.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/output.js new file mode 100644 index 00000000000000..069754e40df18f --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/output.js @@ -0,0 +1,3 @@ +throw /* FIXME (minify-errors-in-prod): Unminified error message in production build! */ new Error( + 'MUI: Expected valid input target.\n' + 'Did you use inputComponent', +); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/error-codes.json b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/error-codes.json new file mode 100644 index 00000000000000..0967ef424bce67 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/error-codes.json @@ -0,0 +1 @@ +{} diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/input.js new file mode 100644 index 00000000000000..72da44d4249716 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/input.js @@ -0,0 +1 @@ +throw new Error('missing'); diff --git a/packages-internal/babel-plugin-minify-errors/index.test.js b/packages-internal/babel-plugin-minify-errors/index.test.js new file mode 100644 index 00000000000000..adb0a36c191ef1 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/index.test.js @@ -0,0 +1,84 @@ +import * as fs from 'fs'; +import * as path from 'path'; +import * as os from 'os'; +import { pluginTester } from 'babel-plugin-tester'; +import { expect } from 'chai'; +import plugin from './index'; + +const temporaryErrorCodesPath = path.join(os.tmpdir(), 'error-codes.json'); +const fixturePath = path.resolve(__dirname, './__fixtures__'); + +function readOutputFixtureSync(fixture, file) { + // babel hardcodes the linefeed to \n + return fs + .readFileSync(path.join(fixturePath, fixture, file), { encoding: 'utf8' }) + .replace(/\r?\n/g, '\n'); +} + +pluginTester({ + plugin, + filepath: __filename, + tests: [ + { + title: 'literal', + pluginOptions: { + errorCodesPath: path.join(fixturePath, 'literal', 'error-codes.json'), + }, + fixture: path.join(fixturePath, 'literal', 'input.js'), + output: readOutputFixtureSync('literal', 'output.js'), + }, + { + title: 'annotates missing error codes', + pluginOptions: { + errorCodesPath: path.join(fixturePath, 'no-error-code-annotation', 'error-codes.json'), + }, + fixture: path.join(fixturePath, 'no-error-code-annotation', 'input.js'), + output: readOutputFixtureSync('no-error-code-annotation', 'output.js'), + }, + { + title: 'can throw on missing error codes', + // babel prefixes with filename. + // We're only interested in the message. + error: + /: Missing error code for message 'missing'. Did you forget to run `pnpm extract-error-codes` first?/, + fixture: path.join(fixturePath, 'no-error-code-throw', 'input.js'), + pluginOptions: { + errorCodesPath: path.join(fixturePath, 'no-error-code-throw', 'error-codes.json'), + missingError: 'throw', + }, + }, + { + title: 'can extract errors', + + fixture: path.join(fixturePath, 'error-code-extraction', 'input.js'), + pluginOptions: { + errorCodesPath: temporaryErrorCodesPath, + missingError: 'write', + }, + output: readOutputFixtureSync('error-code-extraction', 'output.js'), + setup() { + fs.copyFileSync( + path.join(fixturePath, 'error-code-extraction', 'error-codes.before.json'), + temporaryErrorCodesPath, + ); + + return function teardown() { + try { + const actualErrorCodes = JSON.parse( + fs.readFileSync(temporaryErrorCodesPath, { encoding: 'utf8' }), + ); + const expectedErrorCodes = JSON.parse( + fs.readFileSync( + path.join(fixturePath, 'error-code-extraction', 'error-codes.after.json'), + ), + ); + + expect(actualErrorCodes).to.deep.equal(expectedErrorCodes); + } finally { + fs.unlinkSync(temporaryErrorCodesPath); + } + }; + }, + }, + ], +}); diff --git a/packages-internal/babel-plugin-minify-errors/package.json b/packages-internal/babel-plugin-minify-errors/package.json index be02390bc0a974..07fb856bb99d85 100644 --- a/packages-internal/babel-plugin-minify-errors/package.json +++ b/packages-internal/babel-plugin-minify-errors/package.json @@ -16,12 +16,16 @@ "type": "opencollective", "url": "https://opencollective.com/mui-org" }, - "scripts": {}, + "scripts": { + "test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages-internal/babel-plugin-minify-errors/**/*.test.{js,ts,tsx}'" + }, "dependencies": { "@babel/helper-module-imports": "^7.24.7" }, "devDependencies": { - "@types/babel__helper-module-imports": "^7.18.3" + "@types/babel__helper-module-imports": "^7.18.3", + "babel-plugin-tester": "^11.0.4", + "chai": "^4.5.0" }, "sideEffects": false, "type": "commonjs", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 256f5082a48c1a..4f8add6cda2b36 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -140,7 +140,7 @@ importers: version: 7.18.0(eslint@8.57.1)(typescript@5.5.4) babel-loader: specifier: ^9.2.1 - version: 9.2.1(@babel/core@7.25.2)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) + version: 9.2.1(@babel/core@7.25.2)(webpack@5.94.0(webpack-cli@5.1.4)) babel-plugin-istanbul: specifier: ^7.0.0 version: 7.0.0 @@ -167,7 +167,7 @@ importers: version: 5.3.0 compression-webpack-plugin: specifier: ^11.1.0 - version: 11.1.0(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) + version: 11.1.0(webpack@5.94.0(webpack-cli@5.1.4)) concurrently: specifier: ^8.2.2 version: 8.2.2 @@ -194,7 +194,7 @@ importers: version: 9.1.0(eslint@8.57.1) eslint-import-resolver-webpack: specifier: ^0.13.9 - version: 0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) + version: 0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4)) eslint-plugin-babel: specifier: ^5.3.1 version: 5.3.1(eslint@8.57.1) @@ -254,7 +254,7 @@ importers: version: 0.4.0 karma-webpack: specifier: ^5.0.0 - version: 5.0.0(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) + version: 5.0.0(webpack@5.94.0(webpack-cli@5.1.4)) lerna: specifier: ^8.1.8 version: 8.1.8(babel-plugin-macros@3.1.0)(encoding@0.1.13) @@ -305,7 +305,7 @@ importers: version: 1.10.0 terser-webpack-plugin: specifier: ^5.3.10 - version: 5.3.10(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) + version: 5.3.10(webpack@5.94.0(webpack-cli@5.1.4)) tsx: specifier: ^4.19.1 version: 4.19.1 @@ -314,7 +314,7 @@ importers: version: 5.5.4 webpack: specifier: ^5.94.0 - version: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + version: 5.94.0(webpack-cli@5.1.4) webpack-bundle-analyzer: specifier: ^4.10.2 version: 4.10.2 @@ -547,7 +547,7 @@ importers: version: 0.16.2(@emotion/react@11.13.3(@types/react@18.3.4)(react@18.3.1))(react@18.3.1) webpack: specifier: ^5.94.0 - version: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + version: 5.94.0(webpack-cli@5.1.4) docs: dependencies: @@ -919,6 +919,12 @@ importers: '@types/babel__helper-module-imports': specifier: ^7.18.3 version: 7.18.3 + babel-plugin-tester: + specifier: ^11.0.4 + version: 11.0.4(@babel/core@7.25.2) + chai: + specifier: ^4.5.0 + version: 4.5.0 packages-internal/babel-plugin-resolve-imports: dependencies: @@ -2356,7 +2362,7 @@ importers: version: 11.2.0 html-webpack-plugin: specifier: ^5.6.0 - version: 5.6.0(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) + version: 5.6.0(webpack@5.94.0(webpack-cli@5.1.4)) lodash: specifier: ^4.17.21 version: 4.17.21 @@ -2398,7 +2404,7 @@ importers: version: 1.6.28 webpack: specifier: ^5.94.0 - version: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + version: 5.94.0(webpack-cli@5.1.4) yargs: specifier: ^17.7.2 version: 17.7.2 @@ -17157,19 +17163,19 @@ snapshots: '@webassemblyjs/ast': 1.12.1 '@xtuc/long': 4.2.2 - '@webpack-cli/configtest@2.1.1(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)))': + '@webpack-cli/configtest@2.1.1(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4))': dependencies: - webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + webpack: 5.94.0(webpack-cli@5.1.4) webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0) - '@webpack-cli/info@2.0.2(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)))': + '@webpack-cli/info@2.0.2(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4))': dependencies: - webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + webpack: 5.94.0(webpack-cli@5.1.4) webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0) - '@webpack-cli/serve@2.0.5(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)))': + '@webpack-cli/serve@2.0.5(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4))': dependencies: - webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + webpack: 5.94.0(webpack-cli@5.1.4) webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0) '@wyw-in-js/processor-utils@0.5.4': @@ -17626,12 +17632,12 @@ snapshots: dependencies: '@babel/core': 7.25.2 - babel-loader@9.2.1(@babel/core@7.25.2)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))): + babel-loader@9.2.1(@babel/core@7.25.2)(webpack@5.94.0(webpack-cli@5.1.4)): dependencies: '@babel/core': 7.25.2 find-cache-dir: 4.0.0 schema-utils: 4.2.0 - webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + webpack: 5.94.0(webpack-cli@5.1.4) babel-merge@3.0.0(@babel/core@7.25.2): dependencies: @@ -18323,11 +18329,11 @@ snapshots: dependencies: mime-db: 1.52.0 - compression-webpack-plugin@11.1.0(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))): + compression-webpack-plugin@11.1.0(webpack@5.94.0(webpack-cli@5.1.4)): dependencies: schema-utils: 4.2.0 serialize-javascript: 6.0.2 - webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + webpack: 5.94.0(webpack-cli@5.1.4) compression@1.7.4: dependencies: @@ -19345,7 +19351,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-import-resolver-webpack@0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))): + eslint-import-resolver-webpack@0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4)): dependencies: debug: 3.2.7 enhanced-resolve: 0.9.1 @@ -19358,18 +19364,18 @@ snapshots: lodash: 4.17.21 resolve: 2.0.0-next.5 semver: 5.7.2 - webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + webpack: 5.94.0(webpack-cli@5.1.4) transitivePeerDependencies: - supports-color - eslint-module-utils@2.11.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-webpack@0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))))(eslint@8.57.1): + eslint-module-utils@2.11.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-webpack@0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4)))(eslint@8.57.1): dependencies: debug: 3.2.7 optionalDependencies: '@typescript-eslint/parser': 7.18.0(eslint@8.57.1)(typescript@5.5.4) eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-webpack: 0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) + eslint-import-resolver-webpack: 0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4)) transitivePeerDependencies: - supports-color @@ -19397,7 +19403,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.11.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-webpack@0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))))(eslint@8.57.1) + eslint-module-utils: 2.11.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-webpack@0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4)))(eslint@8.57.1) hasown: 2.0.2 is-core-module: 2.15.1 is-glob: 4.0.3 @@ -20441,7 +20447,7 @@ snapshots: readable-stream: 1.0.34 through2: 0.4.2 - html-webpack-plugin@5.6.0(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))): + html-webpack-plugin@5.6.0(webpack@5.94.0(webpack-cli@5.1.4)): dependencies: '@types/html-minifier-terser': 6.1.0 html-minifier-terser: 6.1.0 @@ -20449,7 +20455,7 @@ snapshots: pretty-error: 4.0.0 tapable: 2.2.1 optionalDependencies: - webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + webpack: 5.94.0(webpack-cli@5.1.4) htmlparser2@6.1.0: dependencies: @@ -21358,11 +21364,11 @@ snapshots: dependencies: graceful-fs: 4.2.11 - karma-webpack@5.0.0(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))): + karma-webpack@5.0.0(webpack@5.94.0(webpack-cli@5.1.4)): dependencies: glob: 7.2.3 minimatch: 3.1.2 - webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + webpack: 5.94.0(webpack-cli@5.1.4) webpack-merge: 4.2.2 karma@6.4.4: @@ -25010,14 +25016,14 @@ snapshots: mkdirp: 0.5.6 rimraf: 2.6.3 - terser-webpack-plugin@5.3.10(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))): + terser-webpack-plugin@5.3.10(webpack@5.94.0(webpack-cli@5.1.4)): dependencies: '@jridgewell/trace-mapping': 0.3.25 jest-worker: 27.5.1 schema-utils: 3.3.0 serialize-javascript: 6.0.2 terser: 5.29.2 - webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + webpack: 5.94.0(webpack-cli@5.1.4) terser@5.29.2: dependencies: @@ -25610,9 +25616,9 @@ snapshots: webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0): dependencies: '@discoveryjs/json-ext': 0.5.7 - '@webpack-cli/configtest': 2.1.1(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) - '@webpack-cli/info': 2.0.2(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) - '@webpack-cli/serve': 2.0.5(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) + '@webpack-cli/configtest': 2.1.1(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4)) + '@webpack-cli/info': 2.0.2(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4)) + '@webpack-cli/serve': 2.0.5(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4)) colorette: 2.0.20 commander: 10.0.1 cross-spawn: 7.0.3 @@ -25621,7 +25627,7 @@ snapshots: import-local: 3.1.0 interpret: 3.1.1 rechoir: 0.8.0 - webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) + webpack: 5.94.0(webpack-cli@5.1.4) webpack-merge: 5.9.0 optionalDependencies: webpack-bundle-analyzer: 4.10.2 @@ -25639,7 +25645,7 @@ snapshots: webpack-virtual-modules@0.6.1: {} - webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)): + webpack@5.94.0(webpack-cli@5.1.4): dependencies: '@types/estree': 1.0.5 '@webassemblyjs/ast': 1.12.1 @@ -25661,7 +25667,7 @@ snapshots: neo-async: 2.6.2 schema-utils: 3.3.0 tapable: 2.2.1 - terser-webpack-plugin: 5.3.10(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) + terser-webpack-plugin: 5.3.10(webpack@5.94.0(webpack-cli@5.1.4)) watchpack: 2.4.1 webpack-sources: 3.2.3 optionalDependencies: @@ -25957,4 +25963,3 @@ snapshots: react: 18.3.1 zwitch@2.0.4: {} - \ No newline at end of file From 43edd085daa1e3538c458d3097959f9e24ce3188 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:27:47 +0200 Subject: [PATCH 11/26] Update pnpm-lock.yaml --- pnpm-lock.yaml | 72 +++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f8add6cda2b36..289a0a70c52929 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -140,7 +140,7 @@ importers: version: 7.18.0(eslint@8.57.1)(typescript@5.5.4) babel-loader: specifier: ^9.2.1 - version: 9.2.1(@babel/core@7.25.2)(webpack@5.94.0(webpack-cli@5.1.4)) + version: 9.2.1(@babel/core@7.25.2)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) babel-plugin-istanbul: specifier: ^7.0.0 version: 7.0.0 @@ -167,7 +167,7 @@ importers: version: 5.3.0 compression-webpack-plugin: specifier: ^11.1.0 - version: 11.1.0(webpack@5.94.0(webpack-cli@5.1.4)) + version: 11.1.0(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) concurrently: specifier: ^8.2.2 version: 8.2.2 @@ -194,7 +194,7 @@ importers: version: 9.1.0(eslint@8.57.1) eslint-import-resolver-webpack: specifier: ^0.13.9 - version: 0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4)) + version: 0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) eslint-plugin-babel: specifier: ^5.3.1 version: 5.3.1(eslint@8.57.1) @@ -254,7 +254,7 @@ importers: version: 0.4.0 karma-webpack: specifier: ^5.0.0 - version: 5.0.0(webpack@5.94.0(webpack-cli@5.1.4)) + version: 5.0.0(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) lerna: specifier: ^8.1.8 version: 8.1.8(babel-plugin-macros@3.1.0)(encoding@0.1.13) @@ -305,7 +305,7 @@ importers: version: 1.10.0 terser-webpack-plugin: specifier: ^5.3.10 - version: 5.3.10(webpack@5.94.0(webpack-cli@5.1.4)) + version: 5.3.10(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) tsx: specifier: ^4.19.1 version: 4.19.1 @@ -314,7 +314,7 @@ importers: version: 5.5.4 webpack: specifier: ^5.94.0 - version: 5.94.0(webpack-cli@5.1.4) + version: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) webpack-bundle-analyzer: specifier: ^4.10.2 version: 4.10.2 @@ -547,7 +547,7 @@ importers: version: 0.16.2(@emotion/react@11.13.3(@types/react@18.3.4)(react@18.3.1))(react@18.3.1) webpack: specifier: ^5.94.0 - version: 5.94.0(webpack-cli@5.1.4) + version: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) docs: dependencies: @@ -2362,7 +2362,7 @@ importers: version: 11.2.0 html-webpack-plugin: specifier: ^5.6.0 - version: 5.6.0(webpack@5.94.0(webpack-cli@5.1.4)) + version: 5.6.0(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) lodash: specifier: ^4.17.21 version: 4.17.21 @@ -2404,7 +2404,7 @@ importers: version: 1.6.28 webpack: specifier: ^5.94.0 - version: 5.94.0(webpack-cli@5.1.4) + version: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) yargs: specifier: ^17.7.2 version: 17.7.2 @@ -17163,19 +17163,19 @@ snapshots: '@webassemblyjs/ast': 1.12.1 '@xtuc/long': 4.2.2 - '@webpack-cli/configtest@2.1.1(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4))': + '@webpack-cli/configtest@2.1.1(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)))': dependencies: - webpack: 5.94.0(webpack-cli@5.1.4) + webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0) - '@webpack-cli/info@2.0.2(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4))': + '@webpack-cli/info@2.0.2(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)))': dependencies: - webpack: 5.94.0(webpack-cli@5.1.4) + webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0) - '@webpack-cli/serve@2.0.5(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4))': + '@webpack-cli/serve@2.0.5(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)))': dependencies: - webpack: 5.94.0(webpack-cli@5.1.4) + webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) webpack-cli: 5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0) '@wyw-in-js/processor-utils@0.5.4': @@ -17632,12 +17632,12 @@ snapshots: dependencies: '@babel/core': 7.25.2 - babel-loader@9.2.1(@babel/core@7.25.2)(webpack@5.94.0(webpack-cli@5.1.4)): + babel-loader@9.2.1(@babel/core@7.25.2)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))): dependencies: '@babel/core': 7.25.2 find-cache-dir: 4.0.0 schema-utils: 4.2.0 - webpack: 5.94.0(webpack-cli@5.1.4) + webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) babel-merge@3.0.0(@babel/core@7.25.2): dependencies: @@ -18329,11 +18329,11 @@ snapshots: dependencies: mime-db: 1.52.0 - compression-webpack-plugin@11.1.0(webpack@5.94.0(webpack-cli@5.1.4)): + compression-webpack-plugin@11.1.0(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))): dependencies: schema-utils: 4.2.0 serialize-javascript: 6.0.2 - webpack: 5.94.0(webpack-cli@5.1.4) + webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) compression@1.7.4: dependencies: @@ -19351,7 +19351,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-import-resolver-webpack@0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4)): + eslint-import-resolver-webpack@0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))): dependencies: debug: 3.2.7 enhanced-resolve: 0.9.1 @@ -19364,18 +19364,18 @@ snapshots: lodash: 4.17.21 resolve: 2.0.0-next.5 semver: 5.7.2 - webpack: 5.94.0(webpack-cli@5.1.4) + webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) transitivePeerDependencies: - supports-color - eslint-module-utils@2.11.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-webpack@0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4)))(eslint@8.57.1): + eslint-module-utils@2.11.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-webpack@0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))))(eslint@8.57.1): dependencies: debug: 3.2.7 optionalDependencies: '@typescript-eslint/parser': 7.18.0(eslint@8.57.1)(typescript@5.5.4) eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-webpack: 0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4)) + eslint-import-resolver-webpack: 0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) transitivePeerDependencies: - supports-color @@ -19403,7 +19403,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.11.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-webpack@0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4)))(eslint@8.57.1) + eslint-module-utils: 2.11.0(@typescript-eslint/parser@7.18.0(eslint@8.57.1)(typescript@5.5.4))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-webpack@0.13.9(eslint-plugin-import@2.30.0)(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))))(eslint@8.57.1) hasown: 2.0.2 is-core-module: 2.15.1 is-glob: 4.0.3 @@ -20447,7 +20447,7 @@ snapshots: readable-stream: 1.0.34 through2: 0.4.2 - html-webpack-plugin@5.6.0(webpack@5.94.0(webpack-cli@5.1.4)): + html-webpack-plugin@5.6.0(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))): dependencies: '@types/html-minifier-terser': 6.1.0 html-minifier-terser: 6.1.0 @@ -20455,7 +20455,7 @@ snapshots: pretty-error: 4.0.0 tapable: 2.2.1 optionalDependencies: - webpack: 5.94.0(webpack-cli@5.1.4) + webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) htmlparser2@6.1.0: dependencies: @@ -21364,11 +21364,11 @@ snapshots: dependencies: graceful-fs: 4.2.11 - karma-webpack@5.0.0(webpack@5.94.0(webpack-cli@5.1.4)): + karma-webpack@5.0.0(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))): dependencies: glob: 7.2.3 minimatch: 3.1.2 - webpack: 5.94.0(webpack-cli@5.1.4) + webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) webpack-merge: 4.2.2 karma@6.4.4: @@ -25016,14 +25016,14 @@ snapshots: mkdirp: 0.5.6 rimraf: 2.6.3 - terser-webpack-plugin@5.3.10(webpack@5.94.0(webpack-cli@5.1.4)): + terser-webpack-plugin@5.3.10(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))): dependencies: '@jridgewell/trace-mapping': 0.3.25 jest-worker: 27.5.1 schema-utils: 3.3.0 serialize-javascript: 6.0.2 terser: 5.29.2 - webpack: 5.94.0(webpack-cli@5.1.4) + webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) terser@5.29.2: dependencies: @@ -25616,9 +25616,9 @@ snapshots: webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0): dependencies: '@discoveryjs/json-ext': 0.5.7 - '@webpack-cli/configtest': 2.1.1(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4)) - '@webpack-cli/info': 2.0.2(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4)) - '@webpack-cli/serve': 2.0.5(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4)) + '@webpack-cli/configtest': 2.1.1(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) + '@webpack-cli/info': 2.0.2(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) + '@webpack-cli/serve': 2.0.5(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) colorette: 2.0.20 commander: 10.0.1 cross-spawn: 7.0.3 @@ -25627,7 +25627,7 @@ snapshots: import-local: 3.1.0 interpret: 3.1.1 rechoir: 0.8.0 - webpack: 5.94.0(webpack-cli@5.1.4) + webpack: 5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)) webpack-merge: 5.9.0 optionalDependencies: webpack-bundle-analyzer: 4.10.2 @@ -25645,7 +25645,7 @@ snapshots: webpack-virtual-modules@0.6.1: {} - webpack@5.94.0(webpack-cli@5.1.4): + webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0)): dependencies: '@types/estree': 1.0.5 '@webassemblyjs/ast': 1.12.1 @@ -25667,7 +25667,7 @@ snapshots: neo-async: 2.6.2 schema-utils: 3.3.0 tapable: 2.2.1 - terser-webpack-plugin: 5.3.10(webpack@5.94.0(webpack-cli@5.1.4)) + terser-webpack-plugin: 5.3.10(webpack@5.94.0(webpack-cli@5.1.4(webpack-bundle-analyzer@4.10.2)(webpack@5.94.0))) watchpack: 2.4.1 webpack-sources: 3.2.3 optionalDependencies: From 56fd0405d638dc7db0869fde1cd1c138c49a92db Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:46:45 +0200 Subject: [PATCH 12/26] more tests --- .../interpolation/error-codes.json | 3 ++ .../__fixtures__/interpolation/input.js | 5 ++++ .../__fixtures__/interpolation/output.js | 18 ++++++++++++ .../__fixtures__/literal/input.js | 1 + .../__fixtures__/literal/output.js | 5 ++++ .../unminifyable-annotation/error-codes.json | 1 + .../unminifyable-annotation/input.js | 4 +++ .../unminifyable-annotation/output.js | 4 +++ .../unminifyable-throw/error-codes.json | 1 + .../__fixtures__/unminifyable-throw/input.js | 4 +++ .../babel-plugin-minify-errors/index.js | 4 ++- .../babel-plugin-minify-errors/index.test.js | 28 +++++++++++++++++++ 12 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/error-codes.json create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/input.js create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/output.js create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/error-codes.json create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/input.js create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/output.js create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/error-codes.json create mode 100644 packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/input.js diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/error-codes.json b/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/error-codes.json new file mode 100644 index 00000000000000..17bea7ce743eec --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/error-codes.json @@ -0,0 +1,3 @@ +{ + "1": "MUI: %s, %s" +} diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/input.js new file mode 100644 index 00000000000000..08d0118aa3e165 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/input.js @@ -0,0 +1,5 @@ +const foo = 'foo'; +const bar = 'bar'; +throw new Error(`MUI: ${foo}, ${bar}`); +throw new Error(`MUI: ${foo}` + `, ${bar}`); +throw new Error('MUI: ' + `${foo}, ${bar}`); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/output.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/output.js new file mode 100644 index 00000000000000..7d5887fa7657fd --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/output.js @@ -0,0 +1,18 @@ +import _formatMuiErrorMessage from '@mui/utils/formatMuiErrorMessage'; +const foo = 'foo'; +const bar = 'bar'; +throw new Error( + process.env.NODE_ENV !== 'production' + ? `MUI: ${foo}, ${bar}` + : _formatMuiErrorMessage(1, foo, bar), +); +throw new Error( + process.env.NODE_ENV !== 'production' + ? `MUI: ${foo}` + `, ${bar}` + : _formatMuiErrorMessage(1, foo, bar), +); +throw new Error( + process.env.NODE_ENV !== 'production' + ? 'MUI: ' + `${foo}, ${bar}` + : _formatMuiErrorMessage(1, foo, bar), +); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js index 7ad6f799674480..a518c4e12e7784 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js @@ -1 +1,2 @@ throw new Error('MUI: Expected valid input target.\n' + 'Did you use `inputComponent`'); +throw new Error(`MUI: Expected valid input target.\n` + `Did you use \`inputComponent\``); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/output.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/output.js index c41e3b01fda8b1..e0705efb04a30e 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/output.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/output.js @@ -4,3 +4,8 @@ throw new Error( ? 'MUI: Expected valid input target.\n' + 'Did you use `inputComponent`' : _formatMuiErrorMessage(1), ); +throw new Error( + process.env.NODE_ENV !== 'production' + ? `MUI: Expected valid input target.\n` + `Did you use \`inputComponent\`` + : _formatMuiErrorMessage(1), +); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/error-codes.json b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/error-codes.json new file mode 100644 index 00000000000000..0967ef424bce67 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/error-codes.json @@ -0,0 +1 @@ +{} diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/input.js new file mode 100644 index 00000000000000..e508fd9ae529a8 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/input.js @@ -0,0 +1,4 @@ +const foo = 'foo'; +const bar = ['bar']; +throw new Error(foo); +throw new Error(...bar); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/output.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/output.js new file mode 100644 index 00000000000000..0d425ce67ef0d8 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/output.js @@ -0,0 +1,4 @@ +const foo = 'foo'; +const bar = ['bar']; +throw /* FIXME (minify-errors-in-prod): Unminifyable error in production! */ new Error(foo); +throw /* FIXME (minify-errors-in-prod): Unminifyable error in production! */ new Error(...bar); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/error-codes.json b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/error-codes.json new file mode 100644 index 00000000000000..0967ef424bce67 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/error-codes.json @@ -0,0 +1 @@ +{} diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/input.js new file mode 100644 index 00000000000000..e508fd9ae529a8 --- /dev/null +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/input.js @@ -0,0 +1,4 @@ +const foo = 'foo'; +const bar = ['bar']; +throw new Error(foo); +throw new Error(...bar); diff --git a/packages-internal/babel-plugin-minify-errors/index.js b/packages-internal/babel-plugin-minify-errors/index.js index d96756ce15ad0f..7cba791733190d 100644 --- a/packages-internal/babel-plugin-minify-errors/index.js +++ b/packages-internal/babel-plugin-minify-errors/index.js @@ -71,7 +71,9 @@ function handleUnminifyable(missingError, path) { return; } case 'throw': { - throw new Error(`Unminifyable error.`); + throw new Error( + `Unminifyable error. You can only use literal strings and template strings as error messages.`, + ); } case 'write': { return; diff --git a/packages-internal/babel-plugin-minify-errors/index.test.js b/packages-internal/babel-plugin-minify-errors/index.test.js index adb0a36c191ef1..4d8b36c5c68882 100644 --- a/packages-internal/babel-plugin-minify-errors/index.test.js +++ b/packages-internal/babel-plugin-minify-errors/index.test.js @@ -27,6 +27,14 @@ pluginTester({ fixture: path.join(fixturePath, 'literal', 'input.js'), output: readOutputFixtureSync('literal', 'output.js'), }, + { + title: 'interpolation', + pluginOptions: { + errorCodesPath: path.join(fixturePath, 'interpolation', 'error-codes.json'), + }, + fixture: path.join(fixturePath, 'interpolation', 'input.js'), + output: readOutputFixtureSync('interpolation', 'output.js'), + }, { title: 'annotates missing error codes', pluginOptions: { @@ -47,6 +55,26 @@ pluginTester({ missingError: 'throw', }, }, + { + title: 'annotates unminifyable errors', + pluginOptions: { + errorCodesPath: path.join(fixturePath, 'unminifyable-annotation', 'error-codes.json'), + }, + fixture: path.join(fixturePath, 'unminifyable-annotation', 'input.js'), + output: readOutputFixtureSync('unminifyable-annotation', 'output.js'), + }, + { + title: 'can throw on unminifyable errors', + // babel prefixes with filename. + // We're only interested in the message. + error: + /: Unminifyable error. You can only use literal strings and template strings as error messages.?/, + fixture: path.join(fixturePath, 'unminifyable-throw', 'input.js'), + pluginOptions: { + errorCodesPath: path.join(fixturePath, 'unminifyable-throw', 'error-codes.json'), + missingError: 'throw', + }, + }, { title: 'can extract errors', From eb960dfd6f2319054c4335c75eacefa72c88e670 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Mon, 30 Sep 2024 18:59:06 +0200 Subject: [PATCH 13/26] remove babel-plugin-macros --- .codesandbox/ci.json | 2 - .eslintignore | 1 - babel.config.js | 9 - package.json | 1 - packages/mui-babel-macros/CHANGELOG.md | 5 - packages/mui-babel-macros/MuiError.macro.d.ts | 3 - packages/mui-babel-macros/MuiError.macro.js | 188 ------------------ .../mui-babel-macros/MuiError.macro.test.js | 101 ---------- packages/mui-babel-macros/README.md | 9 - .../__fixtures__/.eslintrc.js | 12 -- .../error-codes.after.json | 4 - .../error-codes.before.json | 3 - .../error-code-extraction/input.js | 4 - .../error-code-extraction/output.js | 5 - .../factory-call/error-codes.json | 1 - .../__fixtures__/factory-call/input.js | 4 - .../__fixtures__/literal/error-codes.json | 3 - .../__fixtures__/literal/input.js | 3 - .../__fixtures__/literal/output.js | 7 - .../no-error-code-annotation/error-codes.json | 1 - .../no-error-code-annotation/input.js | 3 - .../no-error-code-annotation/output.js | 2 - .../no-error-code-throw/error-codes.json | 1 - .../__fixtures__/no-error-code-throw/input.js | 3 - packages/mui-babel-macros/package.json | 46 ----- packages/mui-base/package.json | 1 - .../unstable_useNumberInput/useNumberInput.ts | 3 +- packages/mui-base/src/useInput/useInput.ts | 3 +- packages/mui-material/package.json | 1 - .../mui-material/src/Select/SelectInput.js | 3 +- .../mui-material/src/styles/createPalette.js | 17 +- .../src/styles/createThemeNoVars.js | 3 +- .../src/styles/createThemeWithVars.js | 6 +- packages/mui-material/src/styles/index.js | 4 +- .../mui-material/src/styles/makeStyles.js | 4 +- .../src/styles/responsiveFontSizes.js | 3 +- .../mui-material/src/styles/withStyles.js | 4 +- packages/mui-material/src/styles/withTheme.js | 4 +- packages/mui-system/package.json | 1 - .../src/colorManipulator/colorManipulator.js | 11 +- .../cssContainerQueries.ts | 6 +- packages/mui-system/src/index.js | 4 +- packages/mui-utils/package.json | 1 - .../mui-utils/src/capitalize/capitalize.ts | 4 +- .../formatMuiErrorMessage.ts | 9 +- pnpm-lock.yaml | 50 ----- 46 files changed, 32 insertions(+), 531 deletions(-) delete mode 100644 packages/mui-babel-macros/CHANGELOG.md delete mode 100644 packages/mui-babel-macros/MuiError.macro.d.ts delete mode 100644 packages/mui-babel-macros/MuiError.macro.js delete mode 100644 packages/mui-babel-macros/MuiError.macro.test.js delete mode 100644 packages/mui-babel-macros/README.md delete mode 100644 packages/mui-babel-macros/__fixtures__/.eslintrc.js delete mode 100644 packages/mui-babel-macros/__fixtures__/error-code-extraction/error-codes.after.json delete mode 100644 packages/mui-babel-macros/__fixtures__/error-code-extraction/error-codes.before.json delete mode 100644 packages/mui-babel-macros/__fixtures__/error-code-extraction/input.js delete mode 100644 packages/mui-babel-macros/__fixtures__/error-code-extraction/output.js delete mode 100644 packages/mui-babel-macros/__fixtures__/factory-call/error-codes.json delete mode 100644 packages/mui-babel-macros/__fixtures__/factory-call/input.js delete mode 100644 packages/mui-babel-macros/__fixtures__/literal/error-codes.json delete mode 100644 packages/mui-babel-macros/__fixtures__/literal/input.js delete mode 100644 packages/mui-babel-macros/__fixtures__/literal/output.js delete mode 100644 packages/mui-babel-macros/__fixtures__/no-error-code-annotation/error-codes.json delete mode 100644 packages/mui-babel-macros/__fixtures__/no-error-code-annotation/input.js delete mode 100644 packages/mui-babel-macros/__fixtures__/no-error-code-annotation/output.js delete mode 100644 packages/mui-babel-macros/__fixtures__/no-error-code-throw/error-codes.json delete mode 100644 packages/mui-babel-macros/__fixtures__/no-error-code-throw/input.js delete mode 100644 packages/mui-babel-macros/package.json diff --git a/.codesandbox/ci.json b/.codesandbox/ci.json index 437b8c3d5eb5ef..2881171258056b 100644 --- a/.codesandbox/ci.json +++ b/.codesandbox/ci.json @@ -4,7 +4,6 @@ "node": "20", "packages": [ "packages/markdown", - "packages/mui-babel-macros", "packages/mui-base", "packages/mui-codemod", "packages/mui-core-downloads-tracker", @@ -33,7 +32,6 @@ "@mui/docs": "packages/mui-docs/build", "@mui/icons-material": "packages/mui-icons-material/build", "@mui/internal-test-utils": "packages-internal/test-utils", - "@mui/internal-babel-macros": "packages/mui-babel-macros", "@mui/internal-docs-utils": "packages-internal/docs-utils", "@mui/internal-markdown": "packages/markdown", "@mui/internal-scripts": "packages-internal/scripts", diff --git a/.eslintignore b/.eslintignore index 8100e5ec04840b..ec34e0c6403844 100644 --- a/.eslintignore +++ b/.eslintignore @@ -16,7 +16,6 @@ /packages/mui-icons-material/material-icons/ /packages/mui-icons-material/src/*.js /packages/mui-icons-material/templateSvgIcon.js -/packages/mui-utils/macros/__fixtures__/ # Ignore fixtures /packages-internal/scripts/typescript-to-proptypes/test/*/* /test/bundling/fixtures/**/*.fixture.js diff --git a/babel.config.js b/babel.config.js index e5045952938ca1..de9a6cdea126ae 100644 --- a/babel.config.js +++ b/babel.config.js @@ -78,15 +78,6 @@ module.exports = function getBabelConfig(api) { /** @type {babel.PluginItem[]} */ const plugins = [ - [ - 'babel-plugin-macros', - { - muiError: { - errorCodesPath, - missingError, - }, - }, - ], 'babel-plugin-optimize-clsx', [ '@babel/plugin-transform-runtime', diff --git a/package.json b/package.json index bd575bcc6e742e..ced2f180c8f1ae 100644 --- a/package.json +++ b/package.json @@ -138,7 +138,6 @@ "@typescript-eslint/parser": "^7.18.0", "babel-loader": "^9.2.1", "babel-plugin-istanbul": "^7.0.0", - "babel-plugin-macros": "^3.1.0", "babel-plugin-module-resolver": "^5.0.2", "babel-plugin-optimize-clsx": "^2.6.2", "babel-plugin-react-remove-properties": "^0.3.0", diff --git a/packages/mui-babel-macros/CHANGELOG.md b/packages/mui-babel-macros/CHANGELOG.md deleted file mode 100644 index a6c93f9bf457a6..00000000000000 --- a/packages/mui-babel-macros/CHANGELOG.md +++ /dev/null @@ -1,5 +0,0 @@ -# Changelog - -## 1.0.0 - -Initial release as an npm package. diff --git a/packages/mui-babel-macros/MuiError.macro.d.ts b/packages/mui-babel-macros/MuiError.macro.d.ts deleted file mode 100644 index 54293408e59b1a..00000000000000 --- a/packages/mui-babel-macros/MuiError.macro.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default class MuiError { - constructor(message: string, ...args: string[]); -} diff --git a/packages/mui-babel-macros/MuiError.macro.js b/packages/mui-babel-macros/MuiError.macro.js deleted file mode 100644 index 70a77e3595f5cd..00000000000000 --- a/packages/mui-babel-macros/MuiError.macro.js +++ /dev/null @@ -1,188 +0,0 @@ -const fs = require('fs'); -const { createMacro, MacroError } = require('babel-plugin-macros'); -const helperModuleImports = require('@babel/helper-module-imports'); - -function invertObject(object) { - const inverted = {}; - Object.keys(object).forEach((key) => { - inverted[object[key]] = key; - }); - return inverted; -} - -/** - * Supported import: - * Bare specifier `'@mui/internal-babel-macros/MuiError.macro'` - * @param {import('babel-plugin-macros').MacroParams} param0 - */ -function muiError({ references, babel, config, source }) { - const { errorCodesPath = {}, missingError = 'annotate' } = config; - const errorCodes = JSON.parse(fs.readFileSync(errorCodesPath, { encoding: 'utf8' })); - const errorCodesLookup = invertObject(errorCodes); - let updatedErrorCodes = false; - - let handleMissingErrorCode; - switch (missingError) { - case 'annotate': - handleMissingErrorCode = ({ devMessage, newExpressionPath }) => { - // Outputs: - // /* FIXME (minify-errors-in-prod): Unminified error message in production build! */ - // throw new Error(`A message with ${interpolation}`) - newExpressionPath.replaceWith( - babel.types.newExpression(babel.types.identifier('Error'), [devMessage]), - ); - newExpressionPath.addComment( - 'leading', - ' FIXME (minify-errors-in-prod): Unminified error message in production build! ', - ); - }; - break; - case 'throw': - handleMissingErrorCode = ({ errorMessageLiteral }) => { - throw new MacroError( - `Missing error code for message '${errorMessageLiteral}'. Did you forget to run \`pnpm extract-error-codes\` first?`, - ); - }; - break; - case 'write': - handleMissingErrorCode = ({ errorMessageLiteral }) => { - updatedErrorCodes = true; - // error codes are 1-based - const newErrorCode = Object.keys(errorCodesLookup).length + 1; - errorCodesLookup[errorMessageLiteral] = newErrorCode; - return newErrorCode; - }; - break; - default: - throw new MacroError( - `Unknown missing error behavior '${missingError}'. Can only handle 'annotate', 'throw' and 'write'.`, - ); - } - - /** - * Evaluates a babel node as a string. - * - * Supported nodes - * - `'just a literal'` - * - `'a literal' + 'concatenated' + 'with +'` - * Cannot evaluate template literals or Array.prototype.join etc. - * - * @param {import('@babel/core').types.Node} node - */ - function evaluateMessage(node) { - if (babel.types.isBinaryExpression(node)) { - if (node.operator !== '+') { - throw new Error(`Unsupported binary operator '${node.operator}'. Can only evaluate '+'.`); - } - return `${evaluateMessage(node.left, babel)}${evaluateMessage(node.right, babel)}`; - } - if (babel.types.isStringLiteral(node)) { - return node.value; - } - throw new Error('Can only evaluate strings that are concatenated with `+` or string literals.'); - } - - /** - * The identifier for the callee in `formatMuiErrorMessage()` - * Creating an identifier per MuiError reference would create duplicate imports. - * It's not obvious that these will be deduplicated by bundlers. - * We can already do this at transpile-time - * - * @type {import('@babel/core').NodePath | null} - */ - let formatMuiErrorMessageIdentifier = null; - - references.default.forEach((babelPath) => { - const newExpressionPath = babelPath.parentPath; - if (!newExpressionPath.isNewExpression()) { - throw new MacroError( - 'Encountered `MuiError` outside of a "new expression" i.e. `new MuiError()`. Use `throw new MuiError(message)` over `throw MuiError(message)`.', - ); - } - - const errorMessageLiteral = evaluateMessage(newExpressionPath.node.arguments[0]); - const errorMessageExpressions = newExpressionPath.node.arguments.slice(1); - const errorMessageQuasis = errorMessageLiteral - .split('%s') - // Providing `cooked` here is important. - // Otherwise babel will generate "" with NODE_ENV=test - // - // Original code used `cooked: String.raw({ raw: cooked })` - // Thought it's unclear what for. - // 'One line\nNext line' will end up as `One line - // Next line` which is what you'd want from that literal. - .map((cooked) => babel.types.templateElement({ raw: cooked.replace(/`/g, '\\`'), cooked })); - - // Outputs: - // `A ${adj} message that contains ${noun}`; - const devMessage = babel.types.templateLiteral(errorMessageQuasis, errorMessageExpressions); - - let errorCode = errorCodesLookup[errorMessageLiteral]; - if (errorCode === undefined) { - errorCode = handleMissingErrorCode({ devMessage, errorMessageLiteral, newExpressionPath }); - if (errorCode === undefined) { - return; - } - } - errorCode = parseInt(errorCode, 10); - - if (formatMuiErrorMessageIdentifier === null) { - const isBareImportSourceIdentifier = source.startsWith('@mui/internal-babel-macros'); - if (isBareImportSourceIdentifier) { - // Input: import MuiError from '@mui/internal-babel-macros/MuiError.macro' - // Outputs: - // import { formatMuiErrorMessage } from '@mui/utils'; - formatMuiErrorMessageIdentifier = helperModuleImports.addDefault( - babelPath, - '@mui/utils/formatMuiErrorMessage', - { nameHint: '_formatMuiErrorMessage' }, - ); - } else { - throw new Error('Only package imports from @mui/internal-babel-macros are supported'); - } - } - - // Outputs: - // formatMuiErrorMessage(ERROR_CODE, adj, noun) - const prodMessage = babel.types.callExpression( - babel.types.cloneDeep(formatMuiErrorMessageIdentifier), - [babel.types.numericLiteral(errorCode), ...errorMessageExpressions], - ); - - // Outputs: - // new Error( - // process.env.NODE_ENV !== "production" - // ? `A message with ${interpolation}` - // : formatProdError('A message with %s', interpolation) - // ) - newExpressionPath.replaceWith( - babel.types.newExpression(babel.types.identifier('Error'), [ - babel.types.conditionalExpression( - babel.types.binaryExpression( - '!==', - babel.types.memberExpression( - babel.types.memberExpression( - babel.types.identifier('process'), - babel.types.identifier('env'), - ), - babel.types.identifier('NODE_ENV'), - ), - babel.types.stringLiteral('production'), - ), - devMessage, - prodMessage, - ), - ]), - ); - }); - - if (missingError === 'write' && updatedErrorCodes) { - fs.writeFileSync(errorCodesPath, JSON.stringify(invertObject(errorCodesLookup), null, 2)); - } - - return { keepImports: false }; -} - -module.exports = createMacro(muiError, { - configName: 'muiError', -}); diff --git a/packages/mui-babel-macros/MuiError.macro.test.js b/packages/mui-babel-macros/MuiError.macro.test.js deleted file mode 100644 index cf2cbb3aee402d..00000000000000 --- a/packages/mui-babel-macros/MuiError.macro.test.js +++ /dev/null @@ -1,101 +0,0 @@ -import * as fs from 'fs'; -import * as path from 'path'; -import * as os from 'os'; -import { pluginTester } from 'babel-plugin-tester'; -import plugin from 'babel-plugin-macros'; -import { expect } from 'chai'; - -const temporaryErrorCodesPath = path.join(os.tmpdir(), 'error-codes.json'); -const fixturePath = path.resolve(__dirname, './__fixtures__'); - -function readOutputFixtureSync(fixture, file) { - // babel hardcodes the linefeed to \n - return fs - .readFileSync(path.join(fixturePath, fixture, file), { encoding: 'utf8' }) - .replace(/\r?\n/g, '\n'); -} - -pluginTester({ - plugin, - filepath: __filename, - tests: [ - { - title: 'literal', - pluginOptions: { - muiError: { errorCodesPath: path.join(fixturePath, 'literal', 'error-codes.json') }, - }, - fixture: path.join(fixturePath, 'literal', 'input.js'), - output: readOutputFixtureSync('literal', 'output.js'), - }, - { - title: 'annotates missing error codes', - pluginOptions: { - muiError: { - errorCodesPath: path.join(fixturePath, 'no-error-code-annotation', 'error-codes.json'), - }, - }, - fixture: path.join(fixturePath, 'no-error-code-annotation', 'input.js'), - output: readOutputFixtureSync('no-error-code-annotation', 'output.js'), - }, - { - title: 'can throw on missing error codes', - // babel prefixes with filename. - // We're only interested in the message. - error: - /: Missing error code for message 'missing'. Did you forget to run `pnpm extract-error-codes` first?/, - fixture: path.join(fixturePath, 'no-error-code-throw', 'input.js'), - pluginOptions: { - muiError: { - errorCodesPath: path.join(fixturePath, 'no-error-code-throw', 'error-codes.json'), - missingError: 'throw', - }, - }, - }, - { - title: 'can extract errors', - - fixture: path.join(fixturePath, 'error-code-extraction', 'input.js'), - pluginOptions: { - muiError: { - errorCodesPath: temporaryErrorCodesPath, - missingError: 'write', - }, - }, - output: readOutputFixtureSync('error-code-extraction', 'output.js'), - setup() { - fs.copyFileSync( - path.join(fixturePath, 'error-code-extraction', 'error-codes.before.json'), - temporaryErrorCodesPath, - ); - - return function teardown() { - try { - const actualErrorCodes = JSON.parse( - fs.readFileSync(temporaryErrorCodesPath, { encoding: 'utf8' }), - ); - const expectedErrorCodes = JSON.parse( - fs.readFileSync( - path.join(fixturePath, 'error-code-extraction', 'error-codes.after.json'), - ), - ); - - expect(actualErrorCodes).to.deep.equal(expectedErrorCodes); - } finally { - fs.unlinkSync(temporaryErrorCodesPath); - } - }; - }, - }, - { - title: 'throws if not called as a constructor', - error: - /: Encountered `MuiError` outside of a "new expression" i\.e\. `new MuiError\(\)`\. Use `throw new MuiError\(message\)` over `throw MuiError\(message\)`\./, - fixture: path.join(fixturePath, 'factory-call', 'input.js'), - pluginOptions: { - muiError: { - errorCodesPath: path.join(fixturePath, 'factory-call', 'error-codes.json'), - }, - }, - }, - ], -}); diff --git a/packages/mui-babel-macros/README.md b/packages/mui-babel-macros/README.md deleted file mode 100644 index 4fcfb319018975..00000000000000 --- a/packages/mui-babel-macros/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# @mui/internal-babel-macros - -This package contains the error macro used in MUI projects. -This is an internal package not meant for general use. - -## Release - -There is no build step. -To publish the package to npm, run: `pnpm release:publish` diff --git a/packages/mui-babel-macros/__fixtures__/.eslintrc.js b/packages/mui-babel-macros/__fixtures__/.eslintrc.js deleted file mode 100644 index 4b5538251f2805..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/.eslintrc.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - rules: { - // keeps test simple - 'no-unreachable': 'off', - // keeps test simple - 'no-useless-concat': 'off', - - // Babel import helpers do not add one. - // Since this is auto generated code we don't care about code style. - 'import/newline-after-import': 'off', - }, -}; diff --git a/packages/mui-babel-macros/__fixtures__/error-code-extraction/error-codes.after.json b/packages/mui-babel-macros/__fixtures__/error-code-extraction/error-codes.after.json deleted file mode 100644 index de8fbe089805cd..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/error-code-extraction/error-codes.after.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "1": "exists", - "2": "will be created" -} diff --git a/packages/mui-babel-macros/__fixtures__/error-code-extraction/error-codes.before.json b/packages/mui-babel-macros/__fixtures__/error-code-extraction/error-codes.before.json deleted file mode 100644 index c6c451ad4dec41..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/error-code-extraction/error-codes.before.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "1": "exists" -} diff --git a/packages/mui-babel-macros/__fixtures__/error-code-extraction/input.js b/packages/mui-babel-macros/__fixtures__/error-code-extraction/input.js deleted file mode 100644 index 69a30d073b7136..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/error-code-extraction/input.js +++ /dev/null @@ -1,4 +0,0 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; - -throw new MuiError('exists'); -throw new MuiError('will be created'); diff --git a/packages/mui-babel-macros/__fixtures__/error-code-extraction/output.js b/packages/mui-babel-macros/__fixtures__/error-code-extraction/output.js deleted file mode 100644 index 7a1d72c6a355cf..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/error-code-extraction/output.js +++ /dev/null @@ -1,5 +0,0 @@ -import _formatMuiErrorMessage from '@mui/utils/formatMuiErrorMessage'; -throw new Error(process.env.NODE_ENV !== 'production' ? `exists` : _formatMuiErrorMessage(1)); -throw new Error( - process.env.NODE_ENV !== 'production' ? `will be created` : _formatMuiErrorMessage(2), -); diff --git a/packages/mui-babel-macros/__fixtures__/factory-call/error-codes.json b/packages/mui-babel-macros/__fixtures__/factory-call/error-codes.json deleted file mode 100644 index 0967ef424bce67..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/factory-call/error-codes.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/packages/mui-babel-macros/__fixtures__/factory-call/input.js b/packages/mui-babel-macros/__fixtures__/factory-call/input.js deleted file mode 100644 index c4957eb663baad..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/factory-call/input.js +++ /dev/null @@ -1,4 +0,0 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; - -// `throw Error(message)` is valid JS but we limit error construction to a single syntax. -throw MuiError('my message'); diff --git a/packages/mui-babel-macros/__fixtures__/literal/error-codes.json b/packages/mui-babel-macros/__fixtures__/literal/error-codes.json deleted file mode 100644 index c209c45d724a19..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/literal/error-codes.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "1": "MUI: Expected valid input target.\nDid you use `inputComponent`" -} diff --git a/packages/mui-babel-macros/__fixtures__/literal/input.js b/packages/mui-babel-macros/__fixtures__/literal/input.js deleted file mode 100644 index 2ed3398ceb8021..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/literal/input.js +++ /dev/null @@ -1,3 +0,0 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; - -throw new MuiError('MUI: Expected valid input target.\n' + 'Did you use `inputComponent`'); diff --git a/packages/mui-babel-macros/__fixtures__/literal/output.js b/packages/mui-babel-macros/__fixtures__/literal/output.js deleted file mode 100644 index 9ca62d0007b57c..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/literal/output.js +++ /dev/null @@ -1,7 +0,0 @@ -import _formatMuiErrorMessage from '@mui/utils/formatMuiErrorMessage'; -throw new Error( - process.env.NODE_ENV !== 'production' - ? `MUI: Expected valid input target. -Did you use \`inputComponent\`` - : _formatMuiErrorMessage(1), -); diff --git a/packages/mui-babel-macros/__fixtures__/no-error-code-annotation/error-codes.json b/packages/mui-babel-macros/__fixtures__/no-error-code-annotation/error-codes.json deleted file mode 100644 index 0967ef424bce67..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/no-error-code-annotation/error-codes.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/packages/mui-babel-macros/__fixtures__/no-error-code-annotation/input.js b/packages/mui-babel-macros/__fixtures__/no-error-code-annotation/input.js deleted file mode 100644 index 922dbfba609578..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/no-error-code-annotation/input.js +++ /dev/null @@ -1,3 +0,0 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; - -throw new MuiError('MUI: Expected valid input target.\n' + 'Did you use inputComponent'); diff --git a/packages/mui-babel-macros/__fixtures__/no-error-code-annotation/output.js b/packages/mui-babel-macros/__fixtures__/no-error-code-annotation/output.js deleted file mode 100644 index 0d694b13d4eef7..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/no-error-code-annotation/output.js +++ /dev/null @@ -1,2 +0,0 @@ -throw /* FIXME (minify-errors-in-prod): Unminified error message in production build! */ new Error(`MUI: Expected valid input target. -Did you use inputComponent`); diff --git a/packages/mui-babel-macros/__fixtures__/no-error-code-throw/error-codes.json b/packages/mui-babel-macros/__fixtures__/no-error-code-throw/error-codes.json deleted file mode 100644 index 0967ef424bce67..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/no-error-code-throw/error-codes.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/packages/mui-babel-macros/__fixtures__/no-error-code-throw/input.js b/packages/mui-babel-macros/__fixtures__/no-error-code-throw/input.js deleted file mode 100644 index d804f33d59c04d..00000000000000 --- a/packages/mui-babel-macros/__fixtures__/no-error-code-throw/input.js +++ /dev/null @@ -1,3 +0,0 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; - -throw new MuiError('missing'); diff --git a/packages/mui-babel-macros/package.json b/packages/mui-babel-macros/package.json deleted file mode 100644 index f10caf897c1008..00000000000000 --- a/packages/mui-babel-macros/package.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "@mui/internal-babel-macros", - "version": "1.0.9", - "author": "MUI Team", - "description": "MUI Babel macros. This is an internal package not meant for general use.", - "main": "./MuiError.macro.js", - "repository": { - "type": "git", - "url": "git+https://github.com/mui/material-ui.git", - "directory": "packages/mui-babel-macros" - }, - "license": "MIT", - "bugs": { - "url": "https://github.com/mui/material-ui/issues" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/mui-org" - }, - "scripts": { - "release:publish": "pnpm publish --tag latest", - "release:publish:dry-run": "pnpm publish --tag latest --registry=\"http://localhost:4873/\"", - "test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/mui-babel-macros/**/*.test.{js,ts,tsx}'" - }, - "dependencies": { - "@babel/helper-module-imports": "^7.24.7", - "@babel/runtime": "^7.25.6", - "babel-plugin-macros": "^3.1.0" - }, - "devDependencies": { - "@mui/internal-babel-macros": "workspace:*", - "@types/babel-plugin-macros": "^3.1.3", - "babel-plugin-tester": "^11.0.4", - "chai": "^4.5.0" - }, - "peerDependencies": { - "@mui/utils": "^5.0.0 || ^6.0.0" - }, - "sideEffects": false, - "engines": { - "node": ">=14.0.0" - }, - "publishConfig": { - "access": "public" - } -} diff --git a/packages/mui-base/package.json b/packages/mui-base/package.json index f30326005055dd..05674fefac2e95 100644 --- a/packages/mui-base/package.json +++ b/packages/mui-base/package.json @@ -49,7 +49,6 @@ "prop-types": "^15.8.1" }, "devDependencies": { - "@mui/internal-babel-macros": "workspace:^", "@mui/internal-test-utils": "workspace:^", "@mui/types": "workspace:^", "@testing-library/react": "^16.0.1", diff --git a/packages/mui-base/src/unstable_useNumberInput/useNumberInput.ts b/packages/mui-base/src/unstable_useNumberInput/useNumberInput.ts index 1129b7013fd1e7..8f98e2071880fa 100644 --- a/packages/mui-base/src/unstable_useNumberInput/useNumberInput.ts +++ b/packages/mui-base/src/unstable_useNumberInput/useNumberInput.ts @@ -1,6 +1,5 @@ 'use client'; import * as React from 'react'; -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; import { unstable_useForkRef as useForkRef, unstable_useId as useId } from '@mui/utils'; import { extractEventHandlers } from '../utils/extractEventHandlers'; import { MuiCancellableEvent } from '../utils/MuiCancellableEvent'; @@ -185,7 +184,7 @@ export function useNumberInput(parameters: UseNumberInputParameters): UseNumberI (otherHandlers: Partial) => (event: React.ChangeEvent & MuiCancellableEvent) => { if (!isControlled && event.target === null) { - throw new MuiError( + throw new Error( 'MUI: Expected valid input target. ' + 'Did you use a custom `slots.input` and forget to forward refs? ' + 'See https://mui.com/r/input-component-ref-interface for more info.', diff --git a/packages/mui-base/src/useInput/useInput.ts b/packages/mui-base/src/useInput/useInput.ts index 146d7f0882232d..0a86f63ccd3e2e 100644 --- a/packages/mui-base/src/useInput/useInput.ts +++ b/packages/mui-base/src/useInput/useInput.ts @@ -1,6 +1,5 @@ 'use client'; import * as React from 'react'; -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; import { unstable_useForkRef as useForkRef } from '@mui/utils'; import { FormControlState, useFormControlContext } from '../FormControl'; import { extractEventHandlers } from '../utils/extractEventHandlers'; @@ -140,7 +139,7 @@ export function useInput(parameters: UseInputParameters = {}): UseInputReturnVal if (!isControlled) { const element = event.target || inputRef.current; if (element == null) { - throw new MuiError( + throw new Error( 'MUI: Expected valid input target. ' + 'Did you use a custom `slots.input` and forget to forward refs? ' + 'See https://mui.com/r/input-component-ref-interface for more info.', diff --git a/packages/mui-material/package.json b/packages/mui-material/package.json index deaa62decc3c5b..724dd3c099239d 100644 --- a/packages/mui-material/package.json +++ b/packages/mui-material/package.json @@ -54,7 +54,6 @@ "react-transition-group": "^4.4.5" }, "devDependencies": { - "@mui/internal-babel-macros": "workspace:^", "@mui/internal-test-utils": "workspace:^", "@testing-library/dom": "^10.4.0", "@testing-library/user-event": "^14.5.2", diff --git a/packages/mui-material/src/Select/SelectInput.js b/packages/mui-material/src/Select/SelectInput.js index 27bf3ede4f1818..691a5643420af2 100644 --- a/packages/mui-material/src/Select/SelectInput.js +++ b/packages/mui-material/src/Select/SelectInput.js @@ -3,7 +3,6 @@ import * as React from 'react'; import { isFragment } from 'react-is'; import PropTypes from 'prop-types'; import clsx from 'clsx'; -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; import composeClasses from '@mui/utils/composeClasses'; import useId from '@mui/utils/useId'; import refType from '@mui/utils/refType'; @@ -372,7 +371,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { if (multiple) { if (!Array.isArray(value)) { - throw new MuiError( + throw new Error( 'MUI: The `value` prop must be an array ' + 'when using the `Select` component with `multiple`.', ); diff --git a/packages/mui-material/src/styles/createPalette.js b/packages/mui-material/src/styles/createPalette.js index 949c41e7a8d6e2..57aeeeb1d74701 100644 --- a/packages/mui-material/src/styles/createPalette.js +++ b/packages/mui-material/src/styles/createPalette.js @@ -1,5 +1,4 @@ import deepmerge from '@mui/utils/deepmerge'; -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; import { darken, getContrastRatio, lighten } from '@mui/system/colorManipulator'; import common from '../colors/common'; import grey from '../colors/grey'; @@ -223,18 +222,16 @@ export default function createPalette(palette) { } if (!color.hasOwnProperty('main')) { - throw new MuiError( - 'MUI: The color%s provided to augmentColor(color) is invalid.\n' + - 'The color object needs to have a `main` property or a `%s` property.', - name ? ` (${name})` : '', - mainShade, + throw new Error( + `MUI: The color${name ? ` (${name})` : ''} provided to augmentColor(color) is invalid.\n` + + `The color object needs to have a \`main\` property or a \`${mainShade}\` property.`, ); } if (typeof color.main !== 'string') { - throw new MuiError( - 'MUI: The color%s provided to augmentColor(color) is invalid.\n' + - '`color.main` should be a string, but `%s` was provided instead.\n' + + throw new Error( + `MUI: The color${name ? ` (${name})` : ''} provided to augmentColor(color) is invalid.\n` + + `\`color.main\` should be a string, but \`${JSON.stringify(color.main)}\` was provided instead.\n` + '\n' + 'Did you intend to use one of the following approaches?\n' + '\n' + @@ -247,8 +244,6 @@ export default function createPalette(palette) { 'const theme2 = createTheme({ palette: {\n' + ' primary: { main: green[500] },\n' + '} });', - name ? ` (${name})` : '', - JSON.stringify(color.main), ); } diff --git a/packages/mui-material/src/styles/createThemeNoVars.js b/packages/mui-material/src/styles/createThemeNoVars.js index 77e5abdeafba79..cac5deb8f86d3b 100644 --- a/packages/mui-material/src/styles/createThemeNoVars.js +++ b/packages/mui-material/src/styles/createThemeNoVars.js @@ -3,7 +3,6 @@ import styleFunctionSx, { unstable_defaultSxConfig as defaultSxConfig, } from '@mui/system/styleFunctionSx'; import systemCreateTheme from '@mui/system/createTheme'; -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; import generateUtilityClass from '@mui/utils/generateUtilityClass'; import createMixins from './createMixins'; import createPalette from './createPalette'; @@ -25,7 +24,7 @@ function createThemeNoVars(options = {}, ...args) { } = options; if (options.vars) { - throw new MuiError( + throw new Error( 'MUI: `vars` is a private field used for CSS variables support.\n' + 'Please use another name.', ); diff --git a/packages/mui-material/src/styles/createThemeWithVars.js b/packages/mui-material/src/styles/createThemeWithVars.js index 026f1b9e6ede5d..5b5c124e7d2fec 100644 --- a/packages/mui-material/src/styles/createThemeWithVars.js +++ b/packages/mui-material/src/styles/createThemeWithVars.js @@ -1,4 +1,3 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; import deepmerge from '@mui/utils/deepmerge'; import { unstable_createGetCssVar as systemCreateGetCssVar, createSpacing } from '@mui/system'; import { createUnarySpacing } from '@mui/system/spacing'; @@ -157,9 +156,8 @@ export default function createThemeWithVars(options = {}, ...args) { } if (!defaultScheme) { - throw new MuiError( - 'MUI: The `colorSchemes.%s` option is either missing or invalid.', - defaultColorScheme, + throw new Error( + `MUI: The \`colorSchemes.${defaultColorScheme}\` option is either missing or invalid.`, ); } diff --git a/packages/mui-material/src/styles/index.js b/packages/mui-material/src/styles/index.js index e856d1d5d2fa43..f090be87dabdf8 100644 --- a/packages/mui-material/src/styles/index.js +++ b/packages/mui-material/src/styles/index.js @@ -1,5 +1,3 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; - export { default as THEME_ID } from './identifier'; export { default as adaptV4Theme } from './adaptV4Theme'; export { @@ -21,7 +19,7 @@ export { unstable_createBreakpoints } from '@mui/system/createBreakpoints'; // TODO: Remove this function in v6. // eslint-disable-next-line @typescript-eslint/naming-convention export function experimental_sx() { - throw new MuiError( + throw new Error( 'MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.' + 'For more details, see https://github.com/mui/material-ui/pull/35150.', ); diff --git a/packages/mui-material/src/styles/makeStyles.js b/packages/mui-material/src/styles/makeStyles.js index 380bbc39f5a8c8..43111168bfa91a 100644 --- a/packages/mui-material/src/styles/makeStyles.js +++ b/packages/mui-material/src/styles/makeStyles.js @@ -1,7 +1,5 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; - export default function makeStyles() { - throw new MuiError( + throw new Error( 'MUI: makeStyles is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.', diff --git a/packages/mui-material/src/styles/responsiveFontSizes.js b/packages/mui-material/src/styles/responsiveFontSizes.js index e01b0a3e186c5c..651ee6e0170abe 100644 --- a/packages/mui-material/src/styles/responsiveFontSizes.js +++ b/packages/mui-material/src/styles/responsiveFontSizes.js @@ -1,4 +1,3 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; import { isUnitless, convertLength, responsiveProperty, alignProperty, fontGrid } from './cssUtils'; export default function responsiveFontSizes(themeInput, options = {}) { @@ -51,7 +50,7 @@ export default function responsiveFontSizes(themeInput, options = {}) { let { lineHeight } = style; if (!isUnitless(lineHeight) && !disableAlign) { - throw new MuiError( + throw new Error( 'MUI: Unsupported non-unitless line height with grid alignment.\n' + 'Use unitless line heights instead.', ); diff --git a/packages/mui-material/src/styles/withStyles.js b/packages/mui-material/src/styles/withStyles.js index b5064fae0a4d51..0475fcdfedc019 100644 --- a/packages/mui-material/src/styles/withStyles.js +++ b/packages/mui-material/src/styles/withStyles.js @@ -1,7 +1,5 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; - export default function withStyles() { - throw new MuiError( + throw new Error( 'MUI: withStyles is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.', diff --git a/packages/mui-material/src/styles/withTheme.js b/packages/mui-material/src/styles/withTheme.js index 1b24aa0c8feeb8..dea14dc6c09bf5 100644 --- a/packages/mui-material/src/styles/withTheme.js +++ b/packages/mui-material/src/styles/withTheme.js @@ -1,7 +1,5 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; - export default function withTheme() { - throw new MuiError( + throw new Error( 'MUI: withTheme is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.', diff --git a/packages/mui-system/package.json b/packages/mui-system/package.json index 4e7888f874a259..40f698215c738a 100644 --- a/packages/mui-system/package.json +++ b/packages/mui-system/package.json @@ -51,7 +51,6 @@ "devDependencies": { "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0", - "@mui/internal-babel-macros": "workspace:^", "@mui/internal-test-utils": "workspace:^", "@mui/system": "workspace:*", "@types/chai": "^4.3.19", diff --git a/packages/mui-system/src/colorManipulator/colorManipulator.js b/packages/mui-system/src/colorManipulator/colorManipulator.js index 721949fb2a296e..90e66d116e5567 100644 --- a/packages/mui-system/src/colorManipulator/colorManipulator.js +++ b/packages/mui-system/src/colorManipulator/colorManipulator.js @@ -1,6 +1,5 @@ /* eslint-disable @typescript-eslint/naming-convention */ import clamp from '@mui/utils/clamp'; -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; /** * Returns a number whose value is limited to the given range. @@ -69,10 +68,9 @@ export function decomposeColor(color) { const type = color.substring(0, marker); if (!['rgb', 'rgba', 'hsl', 'hsla', 'color'].includes(type)) { - throw new MuiError( - 'MUI: Unsupported `%s` color.\n' + + throw new Error( + `MUI: Unsupported \`${color}\` color.\n` + 'The following formats are supported: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().', - color, ); } @@ -86,10 +84,9 @@ export function decomposeColor(color) { values[3] = values[3].slice(1); } if (!['srgb', 'display-p3', 'a98-rgb', 'prophoto-rgb', 'rec-2020'].includes(colorSpace)) { - throw new MuiError( - 'MUI: unsupported `%s` color space.\n' + + throw new Error( + `MUI: unsupported \`${colorSpace}\` color space.\n` + 'The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.', - colorSpace, ); } } else { diff --git a/packages/mui-system/src/cssContainerQueries/cssContainerQueries.ts b/packages/mui-system/src/cssContainerQueries/cssContainerQueries.ts index c2e3f284f92be0..4e7d3e988b77f9 100644 --- a/packages/mui-system/src/cssContainerQueries/cssContainerQueries.ts +++ b/packages/mui-system/src/cssContainerQueries/cssContainerQueries.ts @@ -1,4 +1,3 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; import { Breakpoints, Breakpoint } from '../createBreakpoints/createBreakpoints'; interface ContainerQueries { @@ -58,10 +57,9 @@ export function getContainerQuery(theme: CssContainerQueries, shorthand: string) const matches = shorthand.match(/^@([^/]+)?\/?(.+)?$/); if (!matches) { if (process.env.NODE_ENV !== 'production') { - throw new MuiError( - 'MUI: The provided shorthand %s is invalid. The format should be `@` or `@/`.\n' + + throw new Error( + `MUI: The provided shorthand ${`(${shorthand})`} is invalid. The format should be \`@\` or \`@/\`.\n` + 'For example, `@sm` or `@600` or `@40rem/sidebar`.', - `(${shorthand})`, ); } return null; diff --git a/packages/mui-system/src/index.js b/packages/mui-system/src/index.js index b3c0bc3a6cd6ed..3d50f593c45269 100644 --- a/packages/mui-system/src/index.js +++ b/packages/mui-system/src/index.js @@ -1,5 +1,3 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; - export { css, keyframes, StyledEngineProvider } from '@mui/styled-engine'; export { default as GlobalStyles } from './GlobalStyles'; export { default as borders } from './borders'; @@ -38,7 +36,7 @@ export { // TODO: Remove this function in v6 // eslint-disable-next-line @typescript-eslint/naming-convention export function experimental_sx() { - throw new MuiError( + throw new Error( 'MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.' + 'For more details, see https://github.com/mui/material-ui/pull/35150.', ); diff --git a/packages/mui-utils/package.json b/packages/mui-utils/package.json index a0cec5b9667f08..e5d49cf4613302 100644 --- a/packages/mui-utils/package.json +++ b/packages/mui-utils/package.json @@ -46,7 +46,6 @@ "react-is": "^18.3.1" }, "devDependencies": { - "@mui/internal-babel-macros": "workspace:^", "@mui/internal-test-utils": "workspace:^", "@mui/types": "workspace:^", "@types/chai": "^4.3.19", diff --git a/packages/mui-utils/src/capitalize/capitalize.ts b/packages/mui-utils/src/capitalize/capitalize.ts index 6b3407ffb374ec..a4a30e01acbdf4 100644 --- a/packages/mui-utils/src/capitalize/capitalize.ts +++ b/packages/mui-utils/src/capitalize/capitalize.ts @@ -1,12 +1,10 @@ -import MuiError from '@mui/internal-babel-macros/MuiError.macro'; - // It should to be noted that this function isn't equivalent to `text-transform: capitalize`. // // A strict capitalization should uppercase the first letter of each word in the sentence. // We only handle the first word. export default function capitalize(string: string): string { if (typeof string !== 'string') { - throw new MuiError('MUI: `capitalize(string)` expects a string argument.'); + throw new Error('MUI: `capitalize(string)` expects a string argument.'); } return string.charAt(0).toUpperCase() + string.slice(1); diff --git a/packages/mui-utils/src/formatMuiErrorMessage/formatMuiErrorMessage.ts b/packages/mui-utils/src/formatMuiErrorMessage/formatMuiErrorMessage.ts index 3118870f40e511..0bf1ec53f2fe17 100644 --- a/packages/mui-utils/src/formatMuiErrorMessage/formatMuiErrorMessage.ts +++ b/packages/mui-utils/src/formatMuiErrorMessage/formatMuiErrorMessage.ts @@ -1,6 +1,11 @@ /** - * WARNING: Don't import this directly. - * Use `MuiError` from `@mui/internal-babel-macros/MuiError.macro` instead. + * WARNING: Don't import this directly. It's imported by the code generated by + * `@mui/interal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error` + * constructors to ensure the plugin works as expected. Supported patterns include: + * throw new Error('My message'); + * throw new Error(`My message: ${foo}`); + * throw new Error(`My message: ${foo}` + 'another string'); + * ... * @param {number} code */ export default function formatMuiErrorMessage(code: number): string { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 289a0a70c52929..de559d7d629720 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -144,9 +144,6 @@ importers: babel-plugin-istanbul: specifier: ^7.0.0 version: 7.0.0 - babel-plugin-macros: - specifier: ^3.1.0 - version: 3.1.0 babel-plugin-module-resolver: specifier: ^5.0.2 version: 5.0.2 @@ -1292,34 +1289,6 @@ importers: specifier: ^4.5.0 version: 4.5.0 - packages/mui-babel-macros: - dependencies: - '@babel/helper-module-imports': - specifier: ^7.24.7 - version: 7.24.7 - '@babel/runtime': - specifier: ^7.25.6 - version: 7.25.6 - '@mui/utils': - specifier: ^5.0.0 || ^6.0.0 - version: 6.1.1(@types/react@18.3.4)(react@18.3.1) - babel-plugin-macros: - specifier: ^3.1.0 - version: 3.1.0 - devDependencies: - '@mui/internal-babel-macros': - specifier: workspace:* - version: 'link:' - '@types/babel-plugin-macros': - specifier: ^3.1.3 - version: 3.1.3 - babel-plugin-tester: - specifier: ^11.0.4 - version: 11.0.4(@babel/core@7.25.2) - chai: - specifier: ^4.5.0 - version: 4.5.0 - packages/mui-base: dependencies: '@babel/runtime': @@ -1344,9 +1313,6 @@ importers: specifier: ^15.8.1 version: 15.8.1 devDependencies: - '@mui/internal-babel-macros': - specifier: workspace:^ - version: link:../mui-babel-macros '@mui/internal-test-utils': specifier: workspace:^ version: link:../../packages-internal/test-utils @@ -1787,9 +1753,6 @@ importers: specifier: ^4.4.5 version: 4.4.5(react-dom@18.3.1(react@18.3.1))(react@18.3.1) devDependencies: - '@mui/internal-babel-macros': - specifier: workspace:^ - version: link:../mui-babel-macros '@mui/internal-test-utils': specifier: workspace:^ version: link:../../packages-internal/test-utils @@ -2121,9 +2084,6 @@ importers: '@emotion/styled': specifier: ^11.13.0 version: 11.13.0(@emotion/react@11.13.3(@types/react@18.3.4)(react@18.3.1))(@types/react@18.3.4)(react@18.3.1) - '@mui/internal-babel-macros': - specifier: workspace:^ - version: link:../mui-babel-macros '@mui/internal-test-utils': specifier: workspace:^ version: link:../../packages-internal/test-utils @@ -2193,9 +2153,6 @@ importers: specifier: ^18.3.1 version: 18.3.1 devDependencies: - '@mui/internal-babel-macros': - specifier: workspace:^ - version: link:../mui-babel-macros '@mui/internal-test-utils': specifier: workspace:^ version: link:../../packages-internal/test-utils @@ -5381,9 +5338,6 @@ packages: '@types/autosuggest-highlight@3.2.3': resolution: {integrity: sha512-8Mb21KWtpn6PvRQXjsKhrXIcxbSloGqNH50RntwGeJsGPW4xvNhfml+3kKulaKpO/7pgZfOmzsJz7VbepArlGQ==} - '@types/babel-plugin-macros@3.1.3': - resolution: {integrity: sha512-JU+MgpsHK3taY18mBETy5XlwY6LVngte7QXYzUuXEaaX0CN8dBqbjXtADe+gJmkSQE1FJHufzPj++OWZlhRmGw==} - '@types/babel__core@7.20.5': resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==} @@ -16683,10 +16637,6 @@ snapshots: '@types/autosuggest-highlight@3.2.3': {} - '@types/babel-plugin-macros@3.1.3': - dependencies: - '@types/babel__core': 7.20.5 - '@types/babel__core@7.20.5': dependencies: '@babel/parser': 7.25.6 From 1e851f1b5bb9f39ed91d7179b3625e9ed4b69d71 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Tue, 1 Oct 2024 07:21:42 +0200 Subject: [PATCH 14/26] new errors --- docs/public/static/error-codes.json | 16 ++++++++++++++-- .../components/ApiPage/definitions/classes.ts | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/public/static/error-codes.json b/docs/public/static/error-codes.json index c4514997394204..cf6446839b44df 100644 --- a/docs/public/static/error-codes.json +++ b/docs/public/static/error-codes.json @@ -19,5 +19,17 @@ "18": "MUI: The provided shorthand %s is invalid. The format should be `@` or `@/`.\nFor example, `@sm` or `@600` or `@40rem/sidebar`.", "19": "MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.For more details, see https://github.com/mui/material-ui/pull/35150.", "20": "MUI: `vars` is a private field used for CSS variables support.\nPlease use another name.", - "21": "MUI: The `colorSchemes.%s` option is either missing or invalid." -} + "21": "MUI: The `colorSchemes.%s` option is either missing or invalid.", + "22": "MUI: The Accordion doesn't accept a Fragment as a child. Consider providing an array instead.", + "23": "MUI: Expected the first child of Accordion to be a valid element.", + "24": "MUI: Combining `raised={true}` with `variant=\"outlined\"` has no effect.", + "25": "MUI: Either `children`, `image`, `src` or `component` prop must be specified.", + "26": "MUI: You have provided the `disableShrink` prop with a variant other than `indeterminate`. This will have no effect.", + "27": "MUI: You used an element after ListItemSecondaryAction. For ListItem to detect that it has a secondary action you must pass it as the last child to ListItem.", + "28": "MUI: Combining `elevation={%s}` with `variant=\"%s\"` has no effect. Either use `elevation={0}` or use a different `variant`.", + "29": "MUI: You need to use the `getAriaLabel` prop instead of `aria-label` when using a range slider.", + "30": "MUI: You need to use the `getAriaValueText` prop instead of `aria-valuetext` when using a range slider.", + "31": "MUI: The page prop of a TablePagination is out of range (0 to %s, but page is %s).", + "32": "Animation cancelled", + "33": "Element already at target position" +} \ No newline at end of file diff --git a/docs/src/modules/components/ApiPage/definitions/classes.ts b/docs/src/modules/components/ApiPage/definitions/classes.ts index ac8a8ef0e57d3e..055f640e0006a4 100644 --- a/docs/src/modules/components/ApiPage/definitions/classes.ts +++ b/docs/src/modules/components/ApiPage/definitions/classes.ts @@ -60,14 +60,14 @@ export function getClassApiDefinitions(params: GetClassApiDefinitionsParams): Cl if (description.includes('{{conditions}}')) { if (!conditions) { - throw Error(errorMessage(componentName, classDefinition.className, 'conditions')); + throw new Error(errorMessage(componentName, classDefinition.className, 'conditions')); } description = description.replace(/{{conditions}}/, conditions); } if (description.includes('{{nodeName}}')) { if (!nodeName) { - throw Error(errorMessage(componentName, classDefinition.className, 'nodeName')); + throw new Error(errorMessage(componentName, classDefinition.className, 'nodeName')); } description = description.replace(/{{nodeName}}/, nodeName); } From 94e0df173b97c309d6eda53ff823bbd6233e6d51 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Tue, 1 Oct 2024 07:27:37 +0200 Subject: [PATCH 15/26] newline --- docs/public/static/error-codes.json | 14 ++++++++++++-- .../babel-plugin-minify-errors/index.js | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/public/static/error-codes.json b/docs/public/static/error-codes.json index cf6446839b44df..ee4b83ba42d827 100644 --- a/docs/public/static/error-codes.json +++ b/docs/public/static/error-codes.json @@ -31,5 +31,15 @@ "30": "MUI: You need to use the `getAriaValueText` prop instead of `aria-valuetext` when using a range slider.", "31": "MUI: The page prop of a TablePagination is out of range (0 to %s, but page is %s).", "32": "Animation cancelled", - "33": "Element already at target position" -} \ No newline at end of file + "33": "Element already at target position", + "34": "No TabsContext provided", + "35": "useCompoundItem must be used within a useCompoundParent", + "36": "Unhandled action", + "37": "useList: The `getItemDomElement` prop is required when using the `DOM` focus management.", + "38": "useList: The `getItemId` prop is required when using the `activeDescendant` focus management.", + "39": "useListItem must be used within a ListProvider", + "40": "useMenuButton: no menu context available.", + "41": "MenuItem: ListContext was not found.", + "42": "Option: ListContext was not found.", + "43": "You can not use the clone and component prop at the same time." +} diff --git a/packages-internal/babel-plugin-minify-errors/index.js b/packages-internal/babel-plugin-minify-errors/index.js index 7cba791733190d..6025e724bc0701 100644 --- a/packages-internal/babel-plugin-minify-errors/index.js +++ b/packages-internal/babel-plugin-minify-errors/index.js @@ -203,7 +203,7 @@ module.exports = function plugin({ types: t }, { errorCodesPath, missingError = const invertedErrorCodes = Object.fromEntries( Array.from(errorCodesLookup, ([key, value]) => [value, key]), ); - fs.writeFileSync(errorCodesPath, JSON.stringify(invertedErrorCodes, null, 2)); + fs.writeFileSync(errorCodesPath, `${JSON.stringify(invertedErrorCodes, null, 2)}\n`); } }, }; From 890be7ddaa89c369a89b0aa40feea5b316df0a6f Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Tue, 1 Oct 2024 07:34:17 +0200 Subject: [PATCH 16/26] dwef --- docs/public/static/error-codes.json | 57 +++++++++++++++++------------ package.json | 2 +- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/docs/public/static/error-codes.json b/docs/public/static/error-codes.json index ee4b83ba42d827..a46c83dd7a7571 100644 --- a/docs/public/static/error-codes.json +++ b/docs/public/static/error-codes.json @@ -19,27 +19,38 @@ "18": "MUI: The provided shorthand %s is invalid. The format should be `@` or `@/`.\nFor example, `@sm` or `@600` or `@40rem/sidebar`.", "19": "MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.For more details, see https://github.com/mui/material-ui/pull/35150.", "20": "MUI: `vars` is a private field used for CSS variables support.\nPlease use another name.", - "21": "MUI: The `colorSchemes.%s` option is either missing or invalid.", - "22": "MUI: The Accordion doesn't accept a Fragment as a child. Consider providing an array instead.", - "23": "MUI: Expected the first child of Accordion to be a valid element.", - "24": "MUI: Combining `raised={true}` with `variant=\"outlined\"` has no effect.", - "25": "MUI: Either `children`, `image`, `src` or `component` prop must be specified.", - "26": "MUI: You have provided the `disableShrink` prop with a variant other than `indeterminate`. This will have no effect.", - "27": "MUI: You used an element after ListItemSecondaryAction. For ListItem to detect that it has a secondary action you must pass it as the last child to ListItem.", - "28": "MUI: Combining `elevation={%s}` with `variant=\"%s\"` has no effect. Either use `elevation={0}` or use a different `variant`.", - "29": "MUI: You need to use the `getAriaLabel` prop instead of `aria-label` when using a range slider.", - "30": "MUI: You need to use the `getAriaValueText` prop instead of `aria-valuetext` when using a range slider.", - "31": "MUI: The page prop of a TablePagination is out of range (0 to %s, but page is %s).", - "32": "Animation cancelled", - "33": "Element already at target position", - "34": "No TabsContext provided", - "35": "useCompoundItem must be used within a useCompoundParent", - "36": "Unhandled action", - "37": "useList: The `getItemDomElement` prop is required when using the `DOM` focus management.", - "38": "useList: The `getItemId` prop is required when using the `activeDescendant` focus management.", - "39": "useListItem must be used within a ListProvider", - "40": "useMenuButton: no menu context available.", - "41": "MenuItem: ListContext was not found.", - "42": "Option: ListContext was not found.", - "43": "You can not use the clone and component prop at the same time." + "21": "Invalid %s `%s` supplied to `%s`. Expected an HTMLElement.", + "22": "The %s `%s` of `%s` is deprecated. %s", + "23": "Invalid %s `%s` supplied to `%s`. Expected an element that can hold a ref. %s For more information see https://mui.com/r/caveat-with-refs-guide", + "24": "Invalid %s `%s` supplied to `%s`. Expected an element type that can hold a ref. %s For more information see https://mui.com/r/caveat-with-refs-guide", + "25": "The following props are not supported: %s. Please remove them.", + "26": "The prop `%s` of `%s` can only be used together with the `%s` prop.", + "27": "The prop `%s` is not supported. Please remove it.", + "28": "MUI: The Accordion doesn't accept a Fragment as a child. Consider providing an array instead.", + "29": "MUI: Expected the first child of Accordion to be a valid element.", + "30": "MUI: Combining `raised={true}` with `variant=\"outlined\"` has no effect.", + "31": "MUI: Either `children`, `image`, `src` or `component` prop must be specified.", + "32": "MUI: You have provided the `disableShrink` prop with a variant other than `indeterminate`. This will have no effect.", + "33": "MUI: You used an element after ListItemSecondaryAction. For ListItem to detect that it has a secondary action you must pass it as the last child to ListItem.", + "34": "MUI: Combining `elevation={%s}` with `variant=\"%s\"` has no effect. Either use `elevation={0}` or use a different `variant`.", + "35": "MUI: You need to use the `getAriaLabel` prop instead of `aria-label` when using a range slider.", + "36": "MUI: You need to use the `getAriaValueText` prop instead of `aria-valuetext` when using a range slider.", + "37": "MUI: The page prop of a TablePagination is out of range (0 to %s, but page is %s).", + "38": "Animation cancelled", + "39": "Element already at target position", + "40": "MUI: The `colorSchemes.%s` option is either missing or invalid.", + "41": "No TabsContext provided", + "42": "useCompoundItem must be used within a useCompoundParent", + "43": "Unhandled action", + "44": "useList: The `getItemDomElement` prop is required when using the `DOM` focus management.", + "45": "useList: The `getItemId` prop is required when using the `activeDescendant` focus management.", + "46": "useListItem must be used within a ListProvider", + "47": "useMenuButton: no menu context available.", + "48": "MenuItem: ListContext was not found.", + "49": "Option: ListContext was not found.", + "50": "No TabContext provided", + "51": "Missing transition context", + "52": "MUI: The loadingPosition=\"start\" should be used in combination with startIcon.", + "53": "MUI: The loadingPosition=\"end\" should be used in combination with endIcon.", + "54": "You can not use the clone and component prop at the same time." } diff --git a/package.json b/package.json index ced2f180c8f1ae..40f782c295ab17 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "docs:typescript:formatted": "tsx ./docs/scripts/formattedTSDemos", "docs:mdicons:synonyms": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js,.mjs\" ./docs/scripts/updateIconSynonyms && pnpm prettier", "docs:zipRules": "cd docs && rm mui-vale.zip && zip -r mui-vale.zip mui-vale && cd ../ && vale sync", - "extract-error-codes": "cross-env MUI_EXTRACT_ERROR_CODES=true lerna run --concurrency 8 build:modern", + "extract-error-codes": "cross-env MUI_EXTRACT_ERROR_CODES=true lerna run --concurrency 1 build:modern", "rsc:build": "tsx ./packages/rsc-builder/buildRsc.ts", "template:screenshot": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" ./docs/scripts/generateTemplateScreenshots", "template:update-theme": "cross-env BABEL_ENV=development babel-node --extensions \".tsx,.ts,.js\" ./docs/scripts/updateTemplatesTheme", From 151d2dd81fc7e025c8ad13daf1bd1f0ebaa3b6b8 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:02:00 +0200 Subject: [PATCH 17/26] Update formatMuiErrorMessage.ts --- .../formatMuiErrorMessage.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/packages/mui-utils/src/formatMuiErrorMessage/formatMuiErrorMessage.ts b/packages/mui-utils/src/formatMuiErrorMessage/formatMuiErrorMessage.ts index 0bf1ec53f2fe17..c4cdc505d7bbbe 100644 --- a/packages/mui-utils/src/formatMuiErrorMessage/formatMuiErrorMessage.ts +++ b/packages/mui-utils/src/formatMuiErrorMessage/formatMuiErrorMessage.ts @@ -8,17 +8,8 @@ * ... * @param {number} code */ -export default function formatMuiErrorMessage(code: number): string { - // Apply babel-plugin-transform-template-literals in loose mode - // loose mode is safe if we're concatenating primitives - // see https://babeljs.io/docs/en/babel-plugin-transform-template-literals#loose - /* eslint-disable prefer-template */ - let url = 'https://mui.com/production-error/?code=' + code; - for (let i = 1; i < arguments.length; i += 1) { - // rest params over-transpile for this case - // eslint-disable-next-line prefer-rest-params - url += '&args[]=' + encodeURIComponent(arguments[i]); - } - return 'Minified MUI error #' + code + '; visit ' + url + ' for the full message.'; - /* eslint-enable prefer-template */ +export default function formatMuiErrorMessage(code: number, ...args: string[]): string { + const url = new URL(`https://mui.com/production-error/?code=${code}`); + args.forEach((arg) => url.searchParams.append('args[]', arg)); + return `Minified MUI error #${code}; visit ${url} for the full message.`; } From 544874d5d6367427d6501adca5c113df99b49fbe Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:18:27 +0200 Subject: [PATCH 18/26] Update babel.config.js --- babel.config.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/babel.config.js b/babel.config.js index de9a6cdea126ae..9617e35302eb45 100644 --- a/babel.config.js +++ b/babel.config.js @@ -105,13 +105,13 @@ module.exports = function getBabelConfig(api) { ], }, ], - [ - '@mui/internal-babel-plugin-minify-errors', - { - missingError, - errorCodesPath, - }, - ], + // [ + // '@mui/internal-babel-plugin-minify-errors', + // { + // missingError, + // errorCodesPath, + // }, + // ], ...(useESModules ? [ [ From 607e9cf9ea32004cc5ae4aa6d4427fcf9c0d46d8 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Tue, 1 Oct 2024 08:27:40 +0200 Subject: [PATCH 19/26] Update babel.config.js --- babel.config.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/babel.config.js b/babel.config.js index 9617e35302eb45..de9a6cdea126ae 100644 --- a/babel.config.js +++ b/babel.config.js @@ -105,13 +105,13 @@ module.exports = function getBabelConfig(api) { ], }, ], - // [ - // '@mui/internal-babel-plugin-minify-errors', - // { - // missingError, - // errorCodesPath, - // }, - // ], + [ + '@mui/internal-babel-plugin-minify-errors', + { + missingError, + errorCodesPath, + }, + ], ...(useESModules ? [ [ From a90e7c2cde4d453caf8c6da316e382d09be5a78c Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:35:42 +0200 Subject: [PATCH 20/26] comment marker --- docs/public/static/error-codes.json | 34 +------------------ .../babel-plugin-minify-errors/index.js | 9 +++++ .../unstable_useNumberInput/useNumberInput.ts | 2 +- packages/mui-base/src/useInput/useInput.ts | 2 +- .../mui-material/src/InputBase/InputBase.js | 2 +- .../mui-material/src/Select/SelectInput.js | 2 +- .../mui-material/src/styles/createPalette.js | 4 +-- .../src/styles/createThemeNoVars.js | 2 +- .../src/styles/createThemeWithVars.js | 2 +- packages/mui-material/src/styles/index.js | 2 +- .../mui-material/src/styles/makeStyles.js | 2 +- .../src/styles/responsiveFontSizes.js | 2 +- .../mui-material/src/styles/withStyles.js | 2 +- packages/mui-material/src/styles/withTheme.js | 2 +- .../src/colorManipulator/colorManipulator.js | 4 +-- .../cssContainerQueries.ts | 2 +- packages/mui-system/src/index.js | 2 +- .../mui-utils/src/capitalize/capitalize.ts | 2 +- 18 files changed, 28 insertions(+), 51 deletions(-) diff --git a/docs/public/static/error-codes.json b/docs/public/static/error-codes.json index a46c83dd7a7571..d59718ea0c5590 100644 --- a/docs/public/static/error-codes.json +++ b/docs/public/static/error-codes.json @@ -20,37 +20,5 @@ "19": "MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.For more details, see https://github.com/mui/material-ui/pull/35150.", "20": "MUI: `vars` is a private field used for CSS variables support.\nPlease use another name.", "21": "Invalid %s `%s` supplied to `%s`. Expected an HTMLElement.", - "22": "The %s `%s` of `%s` is deprecated. %s", - "23": "Invalid %s `%s` supplied to `%s`. Expected an element that can hold a ref. %s For more information see https://mui.com/r/caveat-with-refs-guide", - "24": "Invalid %s `%s` supplied to `%s`. Expected an element type that can hold a ref. %s For more information see https://mui.com/r/caveat-with-refs-guide", - "25": "The following props are not supported: %s. Please remove them.", - "26": "The prop `%s` of `%s` can only be used together with the `%s` prop.", - "27": "The prop `%s` is not supported. Please remove it.", - "28": "MUI: The Accordion doesn't accept a Fragment as a child. Consider providing an array instead.", - "29": "MUI: Expected the first child of Accordion to be a valid element.", - "30": "MUI: Combining `raised={true}` with `variant=\"outlined\"` has no effect.", - "31": "MUI: Either `children`, `image`, `src` or `component` prop must be specified.", - "32": "MUI: You have provided the `disableShrink` prop with a variant other than `indeterminate`. This will have no effect.", - "33": "MUI: You used an element after ListItemSecondaryAction. For ListItem to detect that it has a secondary action you must pass it as the last child to ListItem.", - "34": "MUI: Combining `elevation={%s}` with `variant=\"%s\"` has no effect. Either use `elevation={0}` or use a different `variant`.", - "35": "MUI: You need to use the `getAriaLabel` prop instead of `aria-label` when using a range slider.", - "36": "MUI: You need to use the `getAriaValueText` prop instead of `aria-valuetext` when using a range slider.", - "37": "MUI: The page prop of a TablePagination is out of range (0 to %s, but page is %s).", - "38": "Animation cancelled", - "39": "Element already at target position", - "40": "MUI: The `colorSchemes.%s` option is either missing or invalid.", - "41": "No TabsContext provided", - "42": "useCompoundItem must be used within a useCompoundParent", - "43": "Unhandled action", - "44": "useList: The `getItemDomElement` prop is required when using the `DOM` focus management.", - "45": "useList: The `getItemId` prop is required when using the `activeDescendant` focus management.", - "46": "useListItem must be used within a ListProvider", - "47": "useMenuButton: no menu context available.", - "48": "MenuItem: ListContext was not found.", - "49": "Option: ListContext was not found.", - "50": "No TabContext provided", - "51": "Missing transition context", - "52": "MUI: The loadingPosition=\"start\" should be used in combination with startIcon.", - "53": "MUI: The loadingPosition=\"end\" should be used in combination with endIcon.", - "54": "You can not use the clone and component prop at the same time." + "22": "MUI: The `colorSchemes.%s` option is either missing or invalid." } diff --git a/packages-internal/babel-plugin-minify-errors/index.js b/packages-internal/babel-plugin-minify-errors/index.js index 6025e724bc0701..6f5ac03ab3dca9 100644 --- a/packages-internal/babel-plugin-minify-errors/index.js +++ b/packages-internal/babel-plugin-minify-errors/index.js @@ -107,6 +107,15 @@ module.exports = function plugin({ types: t }, { errorCodesPath, missingError = if (!newExpressionPath.get('callee').isIdentifier({ name: 'Error' })) { return; } + + if ( + !newExpressionPath.node.leadingComments?.some((comment) => + comment.value.includes('mui-minify-error'), + ) + ) { + return; + } + const messagePath = newExpressionPath.get('arguments')[0]; if (!messagePath) { return; diff --git a/packages/mui-base/src/unstable_useNumberInput/useNumberInput.ts b/packages/mui-base/src/unstable_useNumberInput/useNumberInput.ts index 8f98e2071880fa..b3b6ab6de523ff 100644 --- a/packages/mui-base/src/unstable_useNumberInput/useNumberInput.ts +++ b/packages/mui-base/src/unstable_useNumberInput/useNumberInput.ts @@ -184,7 +184,7 @@ export function useNumberInput(parameters: UseNumberInputParameters): UseNumberI (otherHandlers: Partial) => (event: React.ChangeEvent & MuiCancellableEvent) => { if (!isControlled && event.target === null) { - throw new Error( + throw /* mui-minify-error */ new Error( 'MUI: Expected valid input target. ' + 'Did you use a custom `slots.input` and forget to forward refs? ' + 'See https://mui.com/r/input-component-ref-interface for more info.', diff --git a/packages/mui-base/src/useInput/useInput.ts b/packages/mui-base/src/useInput/useInput.ts index 0a86f63ccd3e2e..3dd07dc44ee5c2 100644 --- a/packages/mui-base/src/useInput/useInput.ts +++ b/packages/mui-base/src/useInput/useInput.ts @@ -139,7 +139,7 @@ export function useInput(parameters: UseInputParameters = {}): UseInputReturnVal if (!isControlled) { const element = event.target || inputRef.current; if (element == null) { - throw new Error( + throw /* mui-minify-error */ new Error( 'MUI: Expected valid input target. ' + 'Did you use a custom `slots.input` and forget to forward refs? ' + 'See https://mui.com/r/input-component-ref-interface for more info.', diff --git a/packages/mui-material/src/InputBase/InputBase.js b/packages/mui-material/src/InputBase/InputBase.js index c3fe3d3d1ffdfa..341c425c8b5c49 100644 --- a/packages/mui-material/src/InputBase/InputBase.js +++ b/packages/mui-material/src/InputBase/InputBase.js @@ -424,7 +424,7 @@ const InputBase = React.forwardRef(function InputBase(inProps, ref) { if (!isControlled) { const element = event.target || inputRef.current; if (element == null) { - throw new Error( + throw /* mui-minify-error */ new Error( 'MUI: Expected valid input target. ' + 'Did you use a custom `inputComponent` and forget to forward refs? ' + 'See https://mui.com/r/input-component-ref-interface for more info.', diff --git a/packages/mui-material/src/Select/SelectInput.js b/packages/mui-material/src/Select/SelectInput.js index 691a5643420af2..a6fd6fe6ccb87a 100644 --- a/packages/mui-material/src/Select/SelectInput.js +++ b/packages/mui-material/src/Select/SelectInput.js @@ -371,7 +371,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { if (multiple) { if (!Array.isArray(value)) { - throw new Error( + throw /* mui-minify-error */ new Error( 'MUI: The `value` prop must be an array ' + 'when using the `Select` component with `multiple`.', ); diff --git a/packages/mui-material/src/styles/createPalette.js b/packages/mui-material/src/styles/createPalette.js index 57aeeeb1d74701..67d76525c9a514 100644 --- a/packages/mui-material/src/styles/createPalette.js +++ b/packages/mui-material/src/styles/createPalette.js @@ -222,14 +222,14 @@ export default function createPalette(palette) { } if (!color.hasOwnProperty('main')) { - throw new Error( + throw /* mui-minify-error */ new Error( `MUI: The color${name ? ` (${name})` : ''} provided to augmentColor(color) is invalid.\n` + `The color object needs to have a \`main\` property or a \`${mainShade}\` property.`, ); } if (typeof color.main !== 'string') { - throw new Error( + throw /* mui-minify-error */ new Error( `MUI: The color${name ? ` (${name})` : ''} provided to augmentColor(color) is invalid.\n` + `\`color.main\` should be a string, but \`${JSON.stringify(color.main)}\` was provided instead.\n` + '\n' + diff --git a/packages/mui-material/src/styles/createThemeNoVars.js b/packages/mui-material/src/styles/createThemeNoVars.js index cac5deb8f86d3b..a16356cb747be6 100644 --- a/packages/mui-material/src/styles/createThemeNoVars.js +++ b/packages/mui-material/src/styles/createThemeNoVars.js @@ -24,7 +24,7 @@ function createThemeNoVars(options = {}, ...args) { } = options; if (options.vars) { - throw new Error( + throw /* mui-minify-error */ new Error( 'MUI: `vars` is a private field used for CSS variables support.\n' + 'Please use another name.', ); diff --git a/packages/mui-material/src/styles/createThemeWithVars.js b/packages/mui-material/src/styles/createThemeWithVars.js index 5b5c124e7d2fec..f2335fdccee266 100644 --- a/packages/mui-material/src/styles/createThemeWithVars.js +++ b/packages/mui-material/src/styles/createThemeWithVars.js @@ -156,7 +156,7 @@ export default function createThemeWithVars(options = {}, ...args) { } if (!defaultScheme) { - throw new Error( + throw /* mui-minify-error */ new Error( `MUI: The \`colorSchemes.${defaultColorScheme}\` option is either missing or invalid.`, ); } diff --git a/packages/mui-material/src/styles/index.js b/packages/mui-material/src/styles/index.js index f090be87dabdf8..8c14dec1c6bf32 100644 --- a/packages/mui-material/src/styles/index.js +++ b/packages/mui-material/src/styles/index.js @@ -19,7 +19,7 @@ export { unstable_createBreakpoints } from '@mui/system/createBreakpoints'; // TODO: Remove this function in v6. // eslint-disable-next-line @typescript-eslint/naming-convention export function experimental_sx() { - throw new Error( + throw /* mui-minify-error */ new Error( 'MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.' + 'For more details, see https://github.com/mui/material-ui/pull/35150.', ); diff --git a/packages/mui-material/src/styles/makeStyles.js b/packages/mui-material/src/styles/makeStyles.js index 43111168bfa91a..2a791811293687 100644 --- a/packages/mui-material/src/styles/makeStyles.js +++ b/packages/mui-material/src/styles/makeStyles.js @@ -1,5 +1,5 @@ export default function makeStyles() { - throw new Error( + throw /* mui-minify-error */ new Error( 'MUI: makeStyles is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.', diff --git a/packages/mui-material/src/styles/responsiveFontSizes.js b/packages/mui-material/src/styles/responsiveFontSizes.js index 651ee6e0170abe..3d0b197bdf384e 100644 --- a/packages/mui-material/src/styles/responsiveFontSizes.js +++ b/packages/mui-material/src/styles/responsiveFontSizes.js @@ -50,7 +50,7 @@ export default function responsiveFontSizes(themeInput, options = {}) { let { lineHeight } = style; if (!isUnitless(lineHeight) && !disableAlign) { - throw new Error( + throw /* mui-minify-error */ new Error( 'MUI: Unsupported non-unitless line height with grid alignment.\n' + 'Use unitless line heights instead.', ); diff --git a/packages/mui-material/src/styles/withStyles.js b/packages/mui-material/src/styles/withStyles.js index 0475fcdfedc019..ac19a003dcfe00 100644 --- a/packages/mui-material/src/styles/withStyles.js +++ b/packages/mui-material/src/styles/withStyles.js @@ -1,5 +1,5 @@ export default function withStyles() { - throw new Error( + throw /* mui-minify-error */ new Error( 'MUI: withStyles is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.', diff --git a/packages/mui-material/src/styles/withTheme.js b/packages/mui-material/src/styles/withTheme.js index dea14dc6c09bf5..21123d5f632698 100644 --- a/packages/mui-material/src/styles/withTheme.js +++ b/packages/mui-material/src/styles/withTheme.js @@ -1,5 +1,5 @@ export default function withTheme() { - throw new Error( + throw /* mui-minify-error */ new Error( 'MUI: withTheme is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.', diff --git a/packages/mui-system/src/colorManipulator/colorManipulator.js b/packages/mui-system/src/colorManipulator/colorManipulator.js index 90e66d116e5567..5bac2ed9936e40 100644 --- a/packages/mui-system/src/colorManipulator/colorManipulator.js +++ b/packages/mui-system/src/colorManipulator/colorManipulator.js @@ -68,7 +68,7 @@ export function decomposeColor(color) { const type = color.substring(0, marker); if (!['rgb', 'rgba', 'hsl', 'hsla', 'color'].includes(type)) { - throw new Error( + throw /* mui-minify-error */ new Error( `MUI: Unsupported \`${color}\` color.\n` + 'The following formats are supported: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().', ); @@ -84,7 +84,7 @@ export function decomposeColor(color) { values[3] = values[3].slice(1); } if (!['srgb', 'display-p3', 'a98-rgb', 'prophoto-rgb', 'rec-2020'].includes(colorSpace)) { - throw new Error( + throw /* mui-minify-error */ new Error( `MUI: unsupported \`${colorSpace}\` color space.\n` + 'The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.', ); diff --git a/packages/mui-system/src/cssContainerQueries/cssContainerQueries.ts b/packages/mui-system/src/cssContainerQueries/cssContainerQueries.ts index 4e7d3e988b77f9..734220dce64182 100644 --- a/packages/mui-system/src/cssContainerQueries/cssContainerQueries.ts +++ b/packages/mui-system/src/cssContainerQueries/cssContainerQueries.ts @@ -57,7 +57,7 @@ export function getContainerQuery(theme: CssContainerQueries, shorthand: string) const matches = shorthand.match(/^@([^/]+)?\/?(.+)?$/); if (!matches) { if (process.env.NODE_ENV !== 'production') { - throw new Error( + throw /* mui-minify-error */ new Error( `MUI: The provided shorthand ${`(${shorthand})`} is invalid. The format should be \`@\` or \`@/\`.\n` + 'For example, `@sm` or `@600` or `@40rem/sidebar`.', ); diff --git a/packages/mui-system/src/index.js b/packages/mui-system/src/index.js index 3d50f593c45269..3fbdc0e0c44bec 100644 --- a/packages/mui-system/src/index.js +++ b/packages/mui-system/src/index.js @@ -36,7 +36,7 @@ export { // TODO: Remove this function in v6 // eslint-disable-next-line @typescript-eslint/naming-convention export function experimental_sx() { - throw new Error( + throw /* mui-minify-error */ new Error( 'MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.' + 'For more details, see https://github.com/mui/material-ui/pull/35150.', ); diff --git a/packages/mui-utils/src/capitalize/capitalize.ts b/packages/mui-utils/src/capitalize/capitalize.ts index a4a30e01acbdf4..851b46f51e1949 100644 --- a/packages/mui-utils/src/capitalize/capitalize.ts +++ b/packages/mui-utils/src/capitalize/capitalize.ts @@ -4,7 +4,7 @@ // We only handle the first word. export default function capitalize(string: string): string { if (typeof string !== 'string') { - throw new Error('MUI: `capitalize(string)` expects a string argument.'); + throw /* mui-minify-error */ new Error('MUI: `capitalize(string)` expects a string argument.'); } return string.charAt(0).toUpperCase() + string.slice(1); From 1814bc3c71495ede14c0e568d007963a25058162 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:38:15 +0200 Subject: [PATCH 21/26] Update .eslintrc.js --- .eslintrc.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 168786dfac72c4..14f1e2c3a34dc4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -229,8 +229,8 @@ module.exports = { selector: 'ExpressionStatement[expression.value="use client"] ~ ExportAllDeclaration', }, { - message: "Use 'throw new Error(...)' instead of 'throw Error(...)'.", - selector: "ThrowStatement > CallExpression[callee.name='Error']", + selector: "CallExpression[callee.name='Error']", + message: 'Calling Error without new is forbidden. Use new Error() instead.', }, ], From dde2095923a3ea0704384a2de620f34afdbfc491 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:38:21 +0200 Subject: [PATCH 22/26] Update .eslintrc.js --- .eslintrc.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 14f1e2c3a34dc4..4557c0775e0e76 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -229,8 +229,8 @@ module.exports = { selector: 'ExpressionStatement[expression.value="use client"] ~ ExportAllDeclaration', }, { - selector: "CallExpression[callee.name='Error']", message: 'Calling Error without new is forbidden. Use new Error() instead.', + selector: "CallExpression[callee.name='Error']", }, ], From eda022bdd42346e8f4e1405198fee876be7a4425 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:48:53 +0200 Subject: [PATCH 23/26] tests --- .../__fixtures__/error-code-extraction/input.js | 4 ++-- .../__fixtures__/interpolation/input.js | 6 +++--- .../__fixtures__/literal/input.js | 8 ++++++-- .../__fixtures__/no-error-code-annotation/input.js | 4 +++- .../__fixtures__/no-error-code-throw/input.js | 2 +- .../__fixtures__/unminifyable-annotation/input.js | 4 ++-- .../__fixtures__/unminifyable-throw/input.js | 4 ++-- packages-internal/babel-plugin-minify-errors/index.js | 8 +++++++- 8 files changed, 26 insertions(+), 14 deletions(-) diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/input.js index 3654728a32bb3a..99d12277d9fe4c 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/input.js @@ -1,2 +1,2 @@ -throw new Error('exists'); -throw new Error('will be created'); +throw /* mui-minify-error */ new Error('exists'); +throw /* mui-minify-error */ new Error('will be created'); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/input.js index 08d0118aa3e165..3400caac942b45 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/input.js @@ -1,5 +1,5 @@ const foo = 'foo'; const bar = 'bar'; -throw new Error(`MUI: ${foo}, ${bar}`); -throw new Error(`MUI: ${foo}` + `, ${bar}`); -throw new Error('MUI: ' + `${foo}, ${bar}`); +throw /* mui-minify-error */ new Error(`MUI: ${foo}, ${bar}`); +throw /* mui-minify-error */ new Error(`MUI: ${foo}` + `, ${bar}`); +throw /* mui-minify-error */ new Error('MUI: ' + `${foo}, ${bar}`); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js index a518c4e12e7784..c0cfea02e60489 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js @@ -1,2 +1,6 @@ -throw new Error('MUI: Expected valid input target.\n' + 'Did you use `inputComponent`'); -throw new Error(`MUI: Expected valid input target.\n` + `Did you use \`inputComponent\``); +throw /* mui-minify-error */ new Error( + 'MUI: Expected valid input target.\n' + 'Did you use `inputComponent`', +); +throw /* mui-minify-error */ new Error( + `MUI: Expected valid input target.\n` + `Did you use \`inputComponent\``, +); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/input.js index 5bcce1cf2b7ce4..f0a1c78d61ce55 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/input.js @@ -1 +1,3 @@ -throw new Error('MUI: Expected valid input target.\n' + 'Did you use inputComponent'); +throw /* mui-minify-error */ new Error( + 'MUI: Expected valid input target.\n' + 'Did you use inputComponent', +); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/input.js index 72da44d4249716..309b5471f4ec32 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/input.js @@ -1 +1 @@ -throw new Error('missing'); +throw /* mui-minify-error */ new Error('missing'); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/input.js index e508fd9ae529a8..f6ad4d6105e5f0 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/input.js @@ -1,4 +1,4 @@ const foo = 'foo'; const bar = ['bar']; -throw new Error(foo); -throw new Error(...bar); +throw /* mui-minify-error */ new Error(foo); +throw /* mui-minify-error */ new Error(...bar); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/input.js index e508fd9ae529a8..f6ad4d6105e5f0 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/input.js @@ -1,4 +1,4 @@ const foo = 'foo'; const bar = ['bar']; -throw new Error(foo); -throw new Error(...bar); +throw /* mui-minify-error */ new Error(foo); +throw /* mui-minify-error */ new Error(...bar); diff --git a/packages-internal/babel-plugin-minify-errors/index.js b/packages-internal/babel-plugin-minify-errors/index.js index 6f5ac03ab3dca9..254be22c371a83 100644 --- a/packages-internal/babel-plugin-minify-errors/index.js +++ b/packages-internal/babel-plugin-minify-errors/index.js @@ -3,6 +3,8 @@ const helperModuleImports = require('@babel/helper-module-imports'); const fs = require('fs'); +const COMMENT_MARKER = 'mui-minify-error'; + /** * @typedef {import('@babel/core')} babel */ @@ -110,12 +112,16 @@ module.exports = function plugin({ types: t }, { errorCodesPath, missingError = if ( !newExpressionPath.node.leadingComments?.some((comment) => - comment.value.includes('mui-minify-error'), + comment.value.includes(COMMENT_MARKER), ) ) { return; } + newExpressionPath.node.leadingComments = newExpressionPath.node.leadingComments.filter( + (comment) => !comment.value.includes(COMMENT_MARKER), + ); + const messagePath = newExpressionPath.get('arguments')[0]; if (!messagePath) { return; From 9e81663ea621d348a2f32a5f7cb1b3a56c6aa6db Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Tue, 1 Oct 2024 17:02:40 +0200 Subject: [PATCH 24/26] Update createRenderer.tsx --- packages-internal/test-utils/src/createRenderer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages-internal/test-utils/src/createRenderer.tsx b/packages-internal/test-utils/src/createRenderer.tsx index f7107db5c1afe8..692174acbdc113 100644 --- a/packages-internal/test-utils/src/createRenderer.tsx +++ b/packages-internal/test-utils/src/createRenderer.tsx @@ -545,7 +545,7 @@ export function createRenderer(globalOptions: CreateRendererOptions = {}): Rende afterEach(() => { if (!clock.isReal()) { - const error = Error( + const error = new Error( "Can't cleanup before fake timers are restored.\n" + 'Be sure to:\n' + ' 1. Only use `clock` from `createRenderer`.\n' + From 65cf4ddd91b8fcb24201b8bf955b4e047242f365 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Sat, 5 Oct 2024 16:20:59 +0200 Subject: [PATCH 25/26] rename --- .../__fixtures__/error-code-extraction/input.js | 4 ++-- .../__fixtures__/interpolation/input.js | 6 +++--- .../__fixtures__/literal/input.js | 4 ++-- .../__fixtures__/no-error-code-annotation/input.js | 2 +- .../__fixtures__/no-error-code-throw/input.js | 2 +- .../__fixtures__/unminifyable-annotation/input.js | 4 ++-- .../__fixtures__/unminifyable-throw/input.js | 4 ++-- packages-internal/babel-plugin-minify-errors/index.js | 2 +- .../mui-base/src/unstable_useNumberInput/useNumberInput.ts | 2 +- packages/mui-base/src/useInput/useInput.ts | 2 +- packages/mui-material/src/InputBase/InputBase.js | 2 +- packages/mui-material/src/Select/SelectInput.js | 2 +- packages/mui-material/src/styles/createPalette.js | 4 ++-- packages/mui-material/src/styles/createThemeNoVars.js | 2 +- packages/mui-material/src/styles/createThemeWithVars.js | 2 +- packages/mui-material/src/styles/index.js | 2 +- packages/mui-material/src/styles/makeStyles.js | 2 +- packages/mui-material/src/styles/responsiveFontSizes.js | 2 +- packages/mui-material/src/styles/withStyles.js | 2 +- packages/mui-material/src/styles/withTheme.js | 2 +- .../mui-system/src/colorManipulator/colorManipulator.js | 4 ++-- .../src/cssContainerQueries/cssContainerQueries.ts | 2 +- packages/mui-system/src/index.js | 2 +- packages/mui-utils/src/capitalize/capitalize.ts | 2 +- 24 files changed, 32 insertions(+), 32 deletions(-) diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/input.js index 99d12277d9fe4c..0cc2982ad5f3a3 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/error-code-extraction/input.js @@ -1,2 +1,2 @@ -throw /* mui-minify-error */ new Error('exists'); -throw /* mui-minify-error */ new Error('will be created'); +throw /* minify-error */ new Error('exists'); +throw /* minify-error */ new Error('will be created'); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/input.js index 3400caac942b45..bf99cee19dae5c 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/interpolation/input.js @@ -1,5 +1,5 @@ const foo = 'foo'; const bar = 'bar'; -throw /* mui-minify-error */ new Error(`MUI: ${foo}, ${bar}`); -throw /* mui-minify-error */ new Error(`MUI: ${foo}` + `, ${bar}`); -throw /* mui-minify-error */ new Error('MUI: ' + `${foo}, ${bar}`); +throw /* minify-error */ new Error(`MUI: ${foo}, ${bar}`); +throw /* minify-error */ new Error(`MUI: ${foo}` + `, ${bar}`); +throw /* minify-error */ new Error('MUI: ' + `${foo}, ${bar}`); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js index c0cfea02e60489..63567b147abee5 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/literal/input.js @@ -1,6 +1,6 @@ -throw /* mui-minify-error */ new Error( +throw /* minify-error */ new Error( 'MUI: Expected valid input target.\n' + 'Did you use `inputComponent`', ); -throw /* mui-minify-error */ new Error( +throw /* minify-error */ new Error( `MUI: Expected valid input target.\n` + `Did you use \`inputComponent\``, ); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/input.js index f0a1c78d61ce55..be815c1b3427b2 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-annotation/input.js @@ -1,3 +1,3 @@ -throw /* mui-minify-error */ new Error( +throw /* minify-error */ new Error( 'MUI: Expected valid input target.\n' + 'Did you use inputComponent', ); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/input.js index 309b5471f4ec32..3c8d1a793d474b 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/no-error-code-throw/input.js @@ -1 +1 @@ -throw /* mui-minify-error */ new Error('missing'); +throw /* minify-error */ new Error('missing'); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/input.js index f6ad4d6105e5f0..865fba71e2aa10 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-annotation/input.js @@ -1,4 +1,4 @@ const foo = 'foo'; const bar = ['bar']; -throw /* mui-minify-error */ new Error(foo); -throw /* mui-minify-error */ new Error(...bar); +throw /* minify-error */ new Error(foo); +throw /* minify-error */ new Error(...bar); diff --git a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/input.js b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/input.js index f6ad4d6105e5f0..865fba71e2aa10 100644 --- a/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/input.js +++ b/packages-internal/babel-plugin-minify-errors/__fixtures__/unminifyable-throw/input.js @@ -1,4 +1,4 @@ const foo = 'foo'; const bar = ['bar']; -throw /* mui-minify-error */ new Error(foo); -throw /* mui-minify-error */ new Error(...bar); +throw /* minify-error */ new Error(foo); +throw /* minify-error */ new Error(...bar); diff --git a/packages-internal/babel-plugin-minify-errors/index.js b/packages-internal/babel-plugin-minify-errors/index.js index 254be22c371a83..390c70a545d0e0 100644 --- a/packages-internal/babel-plugin-minify-errors/index.js +++ b/packages-internal/babel-plugin-minify-errors/index.js @@ -3,7 +3,7 @@ const helperModuleImports = require('@babel/helper-module-imports'); const fs = require('fs'); -const COMMENT_MARKER = 'mui-minify-error'; +const COMMENT_MARKER = 'minify-error'; /** * @typedef {import('@babel/core')} babel diff --git a/packages/mui-base/src/unstable_useNumberInput/useNumberInput.ts b/packages/mui-base/src/unstable_useNumberInput/useNumberInput.ts index b3b6ab6de523ff..3c3dc249904d5e 100644 --- a/packages/mui-base/src/unstable_useNumberInput/useNumberInput.ts +++ b/packages/mui-base/src/unstable_useNumberInput/useNumberInput.ts @@ -184,7 +184,7 @@ export function useNumberInput(parameters: UseNumberInputParameters): UseNumberI (otherHandlers: Partial) => (event: React.ChangeEvent & MuiCancellableEvent) => { if (!isControlled && event.target === null) { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( 'MUI: Expected valid input target. ' + 'Did you use a custom `slots.input` and forget to forward refs? ' + 'See https://mui.com/r/input-component-ref-interface for more info.', diff --git a/packages/mui-base/src/useInput/useInput.ts b/packages/mui-base/src/useInput/useInput.ts index 3dd07dc44ee5c2..a7bf95138a5b6c 100644 --- a/packages/mui-base/src/useInput/useInput.ts +++ b/packages/mui-base/src/useInput/useInput.ts @@ -139,7 +139,7 @@ export function useInput(parameters: UseInputParameters = {}): UseInputReturnVal if (!isControlled) { const element = event.target || inputRef.current; if (element == null) { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( 'MUI: Expected valid input target. ' + 'Did you use a custom `slots.input` and forget to forward refs? ' + 'See https://mui.com/r/input-component-ref-interface for more info.', diff --git a/packages/mui-material/src/InputBase/InputBase.js b/packages/mui-material/src/InputBase/InputBase.js index 341c425c8b5c49..54e1c8babea2a2 100644 --- a/packages/mui-material/src/InputBase/InputBase.js +++ b/packages/mui-material/src/InputBase/InputBase.js @@ -424,7 +424,7 @@ const InputBase = React.forwardRef(function InputBase(inProps, ref) { if (!isControlled) { const element = event.target || inputRef.current; if (element == null) { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( 'MUI: Expected valid input target. ' + 'Did you use a custom `inputComponent` and forget to forward refs? ' + 'See https://mui.com/r/input-component-ref-interface for more info.', diff --git a/packages/mui-material/src/Select/SelectInput.js b/packages/mui-material/src/Select/SelectInput.js index a6fd6fe6ccb87a..e8e7dc989c6808 100644 --- a/packages/mui-material/src/Select/SelectInput.js +++ b/packages/mui-material/src/Select/SelectInput.js @@ -371,7 +371,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) { if (multiple) { if (!Array.isArray(value)) { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( 'MUI: The `value` prop must be an array ' + 'when using the `Select` component with `multiple`.', ); diff --git a/packages/mui-material/src/styles/createPalette.js b/packages/mui-material/src/styles/createPalette.js index 67d76525c9a514..d3c47d9dfa9b32 100644 --- a/packages/mui-material/src/styles/createPalette.js +++ b/packages/mui-material/src/styles/createPalette.js @@ -222,14 +222,14 @@ export default function createPalette(palette) { } if (!color.hasOwnProperty('main')) { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( `MUI: The color${name ? ` (${name})` : ''} provided to augmentColor(color) is invalid.\n` + `The color object needs to have a \`main\` property or a \`${mainShade}\` property.`, ); } if (typeof color.main !== 'string') { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( `MUI: The color${name ? ` (${name})` : ''} provided to augmentColor(color) is invalid.\n` + `\`color.main\` should be a string, but \`${JSON.stringify(color.main)}\` was provided instead.\n` + '\n' + diff --git a/packages/mui-material/src/styles/createThemeNoVars.js b/packages/mui-material/src/styles/createThemeNoVars.js index a16356cb747be6..713c3db3f57a76 100644 --- a/packages/mui-material/src/styles/createThemeNoVars.js +++ b/packages/mui-material/src/styles/createThemeNoVars.js @@ -24,7 +24,7 @@ function createThemeNoVars(options = {}, ...args) { } = options; if (options.vars) { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( 'MUI: `vars` is a private field used for CSS variables support.\n' + 'Please use another name.', ); diff --git a/packages/mui-material/src/styles/createThemeWithVars.js b/packages/mui-material/src/styles/createThemeWithVars.js index f3cdb6a49f2475..9e1fd9f76707e9 100644 --- a/packages/mui-material/src/styles/createThemeWithVars.js +++ b/packages/mui-material/src/styles/createThemeWithVars.js @@ -157,7 +157,7 @@ export default function createThemeWithVars(options = {}, ...args) { } if (!defaultScheme) { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( `MUI: The \`colorSchemes.${defaultColorScheme}\` option is either missing or invalid.`, ); } diff --git a/packages/mui-material/src/styles/index.js b/packages/mui-material/src/styles/index.js index 8c14dec1c6bf32..d98971ae31a471 100644 --- a/packages/mui-material/src/styles/index.js +++ b/packages/mui-material/src/styles/index.js @@ -19,7 +19,7 @@ export { unstable_createBreakpoints } from '@mui/system/createBreakpoints'; // TODO: Remove this function in v6. // eslint-disable-next-line @typescript-eslint/naming-convention export function experimental_sx() { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( 'MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.' + 'For more details, see https://github.com/mui/material-ui/pull/35150.', ); diff --git a/packages/mui-material/src/styles/makeStyles.js b/packages/mui-material/src/styles/makeStyles.js index 2a791811293687..7a22383ce7537a 100644 --- a/packages/mui-material/src/styles/makeStyles.js +++ b/packages/mui-material/src/styles/makeStyles.js @@ -1,5 +1,5 @@ export default function makeStyles() { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( 'MUI: makeStyles is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.', diff --git a/packages/mui-material/src/styles/responsiveFontSizes.js b/packages/mui-material/src/styles/responsiveFontSizes.js index 3d0b197bdf384e..63d343fd8e328b 100644 --- a/packages/mui-material/src/styles/responsiveFontSizes.js +++ b/packages/mui-material/src/styles/responsiveFontSizes.js @@ -50,7 +50,7 @@ export default function responsiveFontSizes(themeInput, options = {}) { let { lineHeight } = style; if (!isUnitless(lineHeight) && !disableAlign) { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( 'MUI: Unsupported non-unitless line height with grid alignment.\n' + 'Use unitless line heights instead.', ); diff --git a/packages/mui-material/src/styles/withStyles.js b/packages/mui-material/src/styles/withStyles.js index ac19a003dcfe00..b8ca2dcb5df811 100644 --- a/packages/mui-material/src/styles/withStyles.js +++ b/packages/mui-material/src/styles/withStyles.js @@ -1,5 +1,5 @@ export default function withStyles() { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( 'MUI: withStyles is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.', diff --git a/packages/mui-material/src/styles/withTheme.js b/packages/mui-material/src/styles/withTheme.js index 21123d5f632698..3c5d8f5ae62a1e 100644 --- a/packages/mui-material/src/styles/withTheme.js +++ b/packages/mui-material/src/styles/withTheme.js @@ -1,5 +1,5 @@ export default function withTheme() { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( 'MUI: withTheme is no longer exported from @mui/material/styles.\n' + 'You have to import it from @mui/styles.\n' + 'See https://mui.com/r/migration-v4/#mui-material-styles for more details.', diff --git a/packages/mui-system/src/colorManipulator/colorManipulator.js b/packages/mui-system/src/colorManipulator/colorManipulator.js index 5bac2ed9936e40..3bc8b02359ced3 100644 --- a/packages/mui-system/src/colorManipulator/colorManipulator.js +++ b/packages/mui-system/src/colorManipulator/colorManipulator.js @@ -68,7 +68,7 @@ export function decomposeColor(color) { const type = color.substring(0, marker); if (!['rgb', 'rgba', 'hsl', 'hsla', 'color'].includes(type)) { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( `MUI: Unsupported \`${color}\` color.\n` + 'The following formats are supported: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla(), color().', ); @@ -84,7 +84,7 @@ export function decomposeColor(color) { values[3] = values[3].slice(1); } if (!['srgb', 'display-p3', 'a98-rgb', 'prophoto-rgb', 'rec-2020'].includes(colorSpace)) { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( `MUI: unsupported \`${colorSpace}\` color space.\n` + 'The following color spaces are supported: srgb, display-p3, a98-rgb, prophoto-rgb, rec-2020.', ); diff --git a/packages/mui-system/src/cssContainerQueries/cssContainerQueries.ts b/packages/mui-system/src/cssContainerQueries/cssContainerQueries.ts index 734220dce64182..532ca044dda7ed 100644 --- a/packages/mui-system/src/cssContainerQueries/cssContainerQueries.ts +++ b/packages/mui-system/src/cssContainerQueries/cssContainerQueries.ts @@ -57,7 +57,7 @@ export function getContainerQuery(theme: CssContainerQueries, shorthand: string) const matches = shorthand.match(/^@([^/]+)?\/?(.+)?$/); if (!matches) { if (process.env.NODE_ENV !== 'production') { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( `MUI: The provided shorthand ${`(${shorthand})`} is invalid. The format should be \`@\` or \`@/\`.\n` + 'For example, `@sm` or `@600` or `@40rem/sidebar`.', ); diff --git a/packages/mui-system/src/index.js b/packages/mui-system/src/index.js index f4e6dc4940a45c..4a4bb930f387fd 100644 --- a/packages/mui-system/src/index.js +++ b/packages/mui-system/src/index.js @@ -36,7 +36,7 @@ export { // TODO: Remove this function in v6 // eslint-disable-next-line @typescript-eslint/naming-convention export function experimental_sx() { - throw /* mui-minify-error */ new Error( + throw /* minify-error */ new Error( 'MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.' + 'For more details, see https://github.com/mui/material-ui/pull/35150.', ); diff --git a/packages/mui-utils/src/capitalize/capitalize.ts b/packages/mui-utils/src/capitalize/capitalize.ts index 851b46f51e1949..b4496bbbbd7def 100644 --- a/packages/mui-utils/src/capitalize/capitalize.ts +++ b/packages/mui-utils/src/capitalize/capitalize.ts @@ -4,7 +4,7 @@ // We only handle the first word. export default function capitalize(string: string): string { if (typeof string !== 'string') { - throw /* mui-minify-error */ new Error('MUI: `capitalize(string)` expects a string argument.'); + throw /* minify-error */ new Error('MUI: `capitalize(string)` expects a string argument.'); } return string.charAt(0).toUpperCase() + string.slice(1); From f49eba08fd20e1236b3fb375de4779f1e7e085c9 Mon Sep 17 00:00:00 2001 From: MUI bot <2109932+Janpot@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:13:12 +0200 Subject: [PATCH 26/26] Update error-codes.json --- docs/public/static/error-codes.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/public/static/error-codes.json b/docs/public/static/error-codes.json index d59718ea0c5590..c4514997394204 100644 --- a/docs/public/static/error-codes.json +++ b/docs/public/static/error-codes.json @@ -19,6 +19,5 @@ "18": "MUI: The provided shorthand %s is invalid. The format should be `@` or `@/`.\nFor example, `@sm` or `@600` or `@40rem/sidebar`.", "19": "MUI: The `experimental_sx` has been moved to `theme.unstable_sx`.For more details, see https://github.com/mui/material-ui/pull/35150.", "20": "MUI: `vars` is a private field used for CSS variables support.\nPlease use another name.", - "21": "Invalid %s `%s` supplied to `%s`. Expected an HTMLElement.", - "22": "MUI: The `colorSchemes.%s` option is either missing or invalid." + "21": "MUI: The `colorSchemes.%s` option is either missing or invalid." }