chore: small bundle size (#24135)

* update warning

* rm warning

* replace with dev warning

* fix test

* fix site

* Update webpack.config.js

Co-authored-by: 偏右 <afc163@gmail.com>

* Update webpack.config.js

* fix sytax

* adjust

* move into function

Co-authored-by: 偏右 <afc163@gmail.com>
This commit is contained in:
二货机器人 2020-05-14 15:57:04 +08:00 committed by GitHub
parent 4aa1b62659
commit 2e284aa017
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 114 additions and 90 deletions

View File

@ -0,0 +1,7 @@
import devWarning, { resetWarned } from 'rc-util/lib/warning';
export { resetWarned };
export default (valid: boolean, component: string, message: string): void => {
devWarning(valid, `[antd: ${component}] ${message}`);
};

View File

@ -1,7 +0,0 @@
import warning, { resetWarned } from 'rc-util/lib/warning';
export { resetWarned };
export default (valid: boolean, component: string, message: string): void => {
warning(valid, `[antd: ${component}] ${message}`);
};

View File

@ -12,7 +12,7 @@ import classNames from 'classnames';
import omit from 'omit.js'; import omit from 'omit.js';
import Select, { InternalSelectProps, OptionType } from '../select'; import Select, { InternalSelectProps, OptionType } from '../select';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
const { Option } = Select; const { Option } = Select;
@ -25,7 +25,10 @@ export interface DataSourceItemObject {
export type DataSourceItemType = string | DataSourceItemObject; export type DataSourceItemType = string | DataSourceItemObject;
export interface AutoCompleteProps export interface AutoCompleteProps
extends Omit<InternalSelectProps<string>, 'inputIcon' | 'loading' | 'mode' | 'optionLabelProp' | 'labelInValue'> { extends Omit<
InternalSelectProps<string>,
'inputIcon' | 'loading' | 'mode' | 'optionLabelProp' | 'labelInValue'
> {
dataSource?: DataSourceItemType[]; dataSource?: DataSourceItemType[];
} }
@ -90,13 +93,13 @@ const AutoComplete: React.RefForwardingComponent<Select, AutoCompleteProps> = (p
// ============================ Warning ============================ // ============================ Warning ============================
React.useEffect(() => { React.useEffect(() => {
warning( devWarning(
!('dataSource' in props), !('dataSource' in props),
'AutoComplete', 'AutoComplete',
'`dataSource` is deprecated, please use `options` instead.', '`dataSource` is deprecated, please use `options` instead.',
); );
warning( devWarning(
!customizeInput || !('size' in props), !customizeInput || !('size' in props),
'AutoComplete', 'AutoComplete',
'You need to control style self instead of setting `size` when using customize input.', 'You need to control style self instead of setting `size` when using customize input.',

View File

@ -2,7 +2,7 @@ import * as React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
export interface AvatarProps { export interface AvatarProps {
/** Shape of avatar, options:`circle`, `square` */ /** Shape of avatar, options:`circle`, `square` */
@ -109,7 +109,7 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {
...others ...others
} = this.props; } = this.props;
warning( devWarning(
!(typeof icon === 'string' && icon.length > 2), !(typeof icon === 'string' && icon.length > 2),
'Avatar', 'Avatar',
`\`icon\` is using ReactNode instead of string naming in v4. Please check \`${icon}\` at https://ant.design/components/icon`, `\`icon\` is using ReactNode instead of string naming in v4. Please check \`${icon}\` at https://ant.design/components/icon`,

View File

@ -6,7 +6,7 @@ import BreadcrumbItem from './BreadcrumbItem';
import BreadcrumbSeparator from './BreadcrumbSeparator'; import BreadcrumbSeparator from './BreadcrumbSeparator';
import Menu from '../menu'; import Menu from '../menu';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import { Omit } from '../_util/type'; import { Omit } from '../_util/type';
export interface Route { export interface Route {
@ -130,7 +130,7 @@ export default class Breadcrumb extends React.Component<BreadcrumbProps, any> {
return element; return element;
} }
warning( devWarning(
element.type && element.type &&
(element.type.__ANT_BREADCRUMB_ITEM === true || (element.type.__ANT_BREADCRUMB_ITEM === true ||
element.type.__ANT_BREADCRUMB_SEPARATOR === true), element.type.__ANT_BREADCRUMB_SEPARATOR === true),

View File

@ -7,7 +7,7 @@ import Group from './button-group';
import { ConfigContext } from '../config-provider'; import { ConfigContext } from '../config-provider';
import Wave from '../_util/wave'; import Wave from '../_util/wave';
import { Omit, tuple } from '../_util/type'; import { Omit, tuple } from '../_util/type';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import SizeContext, { SizeType } from '../config-provider/SizeContext'; import SizeContext, { SizeType } from '../config-provider/SizeContext';
import LoadingIcon from './LoadingIcon'; import LoadingIcon from './LoadingIcon';
@ -186,7 +186,7 @@ const InternalButton: React.ForwardRefRenderFunction<unknown, ButtonProps> = (pr
...rest ...rest
} = props; } = props;
warning( devWarning(
!(typeof icon === 'string' && icon.length > 2), !(typeof icon === 'string' && icon.length > 2),
'Button', 'Button',
`\`icon\` is using ReactNode instead of string naming in v4. Please check \`${icon}\` at https://ant.design/components/icon`, `\`icon\` is using ReactNode instead of string naming in v4. Please check \`${icon}\` at https://ant.design/components/icon`,

View File

@ -14,7 +14,7 @@ import LeftOutlined from '@ant-design/icons/LeftOutlined';
import Input from '../input'; import Input from '../input';
import { ConfigConsumer, ConfigConsumerProps, RenderEmptyHandler } from '../config-provider'; import { ConfigConsumer, ConfigConsumerProps, RenderEmptyHandler } from '../config-provider';
import LocaleReceiver from '../locale-provider/LocaleReceiver'; import LocaleReceiver from '../locale-provider/LocaleReceiver';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import SizeContext, { SizeType } from '../config-provider/SizeContext'; import SizeContext, { SizeType } from '../config-provider/SizeContext';
export interface CascaderOptionType { export interface CascaderOptionType {
@ -211,7 +211,7 @@ const defaultDisplayRender = (label: string[]) => label.join(' / ');
function warningValueNotExist(list: CascaderOptionType[], fieldNames: FieldNamesType = {}) { function warningValueNotExist(list: CascaderOptionType[], fieldNames: FieldNamesType = {}) {
(list || []).forEach(item => { (list || []).forEach(item => {
const valueFieldName = fieldNames.value || 'value'; const valueFieldName = fieldNames.value || 'value';
warning(valueFieldName in item, 'Cascader', 'Not found `value` in `options`.'); devWarning(valueFieldName in item, 'Cascader', 'Not found `value` in `options`.');
warningValueNotExist(item[fieldNames.children || 'children'], fieldNames); warningValueNotExist(item[fieldNames.children || 'children'], fieldNames);
}); });
} }
@ -384,7 +384,7 @@ class Cascader extends React.Component<CascaderProps, CascaderState> {
return matchCount >= limit; return matchCount >= limit;
}); });
} else { } else {
warning( devWarning(
typeof limit !== 'number', typeof limit !== 'number',
'Cascader', 'Cascader',
"'limit' of showSearch should be positive number or false.", "'limit' of showSearch should be positive number or false.",

View File

@ -3,7 +3,7 @@ import classNames from 'classnames';
import RcCheckbox from 'rc-checkbox'; import RcCheckbox from 'rc-checkbox';
import CheckboxGroup, { GroupContext } from './Group'; import CheckboxGroup, { GroupContext } from './Group';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
export interface AbstractCheckboxProps<T> { export interface AbstractCheckboxProps<T> {
prefixCls?: string; prefixCls?: string;
@ -60,7 +60,7 @@ class Checkbox extends React.PureComponent<CheckboxProps, {}> {
const { value } = this.props; const { value } = this.props;
this.context?.registerValue(value); this.context?.registerValue(value);
warning( devWarning(
'checked' in this.props || this.context || !('value' in this.props), 'checked' in this.props || this.context || !('value' in this.props),
'Checkbox', 'Checkbox',
'`value` is not a valid prop, do you mean `checked`?', '`value` is not a valid prop, do you mean `checked`?',

View File

@ -2,7 +2,7 @@ import React from 'react';
import { mount } from 'enzyme'; import { mount } from 'enzyme';
import Checkbox from '..'; import Checkbox from '..';
import focusTest from '../../../tests/shared/focusTest'; import focusTest from '../../../tests/shared/focusTest';
import { resetWarned } from '../../_util/warning'; import { resetWarned } from '../../_util/devWarning';
import mountTest from '../../../tests/shared/mountTest'; import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest'; import rtlTest from '../../../tests/shared/rtlTest';

View File

@ -3,7 +3,7 @@ import MockDate from 'mockdate';
import { mount } from 'enzyme'; import { mount } from 'enzyme';
import Descriptions from '..'; import Descriptions from '..';
import mountTest from '../../../tests/shared/mountTest'; import mountTest from '../../../tests/shared/mountTest';
import { resetWarned } from '../../_util/warning'; import { resetWarned } from '../../_util/devWarning';
describe('Descriptions', () => { describe('Descriptions', () => {
mountTest(Descriptions); mountTest(Descriptions);

View File

@ -7,7 +7,7 @@ import ResponsiveObserve, {
ScreenMap, ScreenMap,
responsiveArray, responsiveArray,
} from '../_util/responsiveObserve'; } from '../_util/responsiveObserve';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import { ConfigContext } from '../config-provider'; import { ConfigContext } from '../config-provider';
import Row from './Row'; import Row from './Row';
import DescriptionsItem from './Item'; import DescriptionsItem from './Item';
@ -49,7 +49,7 @@ function getFilledItem(
clone = React.cloneElement(node, { clone = React.cloneElement(node, {
span: rowRestCol, span: rowRestCol,
}); });
warning( devWarning(
span === undefined, span === undefined,
'Descriptions', 'Descriptions',
'Sum of column `span` in a line not match `column` of Descriptions.', 'Sum of column `span` in a line not match `column` of Descriptions.',

View File

@ -5,7 +5,7 @@ import RightOutlined from '@ant-design/icons/RightOutlined';
import DropdownButton from './dropdown-button'; import DropdownButton from './dropdown-button';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import { tuple } from '../_util/type'; import { tuple } from '../_util/type';
const Placements = tuple( const Placements = tuple(
@ -88,7 +88,7 @@ export default class Dropdown extends React.Component<DropDownProps, any> {
const overlayProps = overlayNode.props; const overlayProps = overlayNode.props;
// Warning if use other mode // Warning if use other mode
warning( devWarning(
!overlayProps.mode || overlayProps.mode === 'vertical', !overlayProps.mode || overlayProps.mode === 'vertical',
'Dropdown', 'Dropdown',
`mode="${overlayProps.mode}" is not supported for Dropdown's Menu.`, `mode="${overlayProps.mode}" is not supported for Dropdown's Menu.`,

View File

@ -8,7 +8,7 @@ import omit from 'omit.js';
import Row from '../grid/row'; import Row from '../grid/row';
import { ConfigContext } from '../config-provider'; import { ConfigContext } from '../config-provider';
import { tuple } from '../_util/type'; import { tuple } from '../_util/type';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import FormItemLabel, { FormItemLabelProps } from './FormItemLabel'; import FormItemLabel, { FormItemLabelProps } from './FormItemLabel';
import FormItemInput, { FormItemInputProps } from './FormItemInput'; import FormItemInput, { FormItemInputProps } from './FormItemInput';
import { FormContext, FormItemContext } from './context'; import { FormContext, FormItemContext } from './context';
@ -51,7 +51,7 @@ export interface FormItemProps extends FormItemLabelProps, FormItemInputProps, R
function hasValidName(name?: NamePath): Boolean { function hasValidName(name?: NamePath): Boolean {
if (name === null) { if (name === null) {
warning(false, 'Form.Item', '`null` is passed as `name` property'); devWarning(false, 'Form.Item', '`null` is passed as `name` property');
} }
return !(name === undefined || name === null); return !(name === undefined || name === null);
} }
@ -285,27 +285,27 @@ function FormItem(props: FormItemProps): React.ReactElement {
let childNode: React.ReactNode = null; let childNode: React.ReactNode = null;
if (Array.isArray(children) && hasName) { if (Array.isArray(children) && hasName) {
warning(false, 'Form.Item', '`children` is array of render props cannot have `name`.'); devWarning(false, 'Form.Item', '`children` is array of render props cannot have `name`.');
childNode = children; childNode = children;
} else if (isRenderProps && (!shouldUpdate || hasName)) { } else if (isRenderProps && (!shouldUpdate || hasName)) {
warning( devWarning(
!!shouldUpdate, !!shouldUpdate,
'Form.Item', 'Form.Item',
'`children` of render props only work with `shouldUpdate`.', '`children` of render props only work with `shouldUpdate`.',
); );
warning( devWarning(
!hasName, !hasName,
'Form.Item', 'Form.Item',
"Do not use `name` with `children` of render props since it's not a field.", "Do not use `name` with `children` of render props since it's not a field.",
); );
} else if (dependencies && !isRenderProps && !hasName) { } else if (dependencies && !isRenderProps && !hasName) {
warning( devWarning(
false, false,
'Form.Item', 'Form.Item',
'Must set `name` or use render props when `dependencies` is set.', 'Must set `name` or use render props when `dependencies` is set.',
); );
} else if (React.isValidElement(children)) { } else if (React.isValidElement(children)) {
warning( devWarning(
children.props.defaultValue === undefined, children.props.defaultValue === undefined,
'Form.Item', 'Form.Item',
'`defaultValue` will not work on controlled Field. You should use `initialValues` of Form instead.', '`defaultValue` will not work on controlled Field. You should use `initialValues` of Form instead.',
@ -334,7 +334,7 @@ function FormItem(props: FormItemProps): React.ReactElement {
} else if (isRenderProps && shouldUpdate && !hasName) { } else if (isRenderProps && shouldUpdate && !hasName) {
childNode = (children as RenderChildren)(context); childNode = (children as RenderChildren)(context);
} else { } else {
warning( devWarning(
!mergedName.length, !mergedName.length,
'Form.Item', 'Form.Item',
'`name` is only used for validate React element. If you are using Form.Item as layout display, please remove `name` instead.', '`name` is only used for validate React element. If you are using Form.Item as layout display, please remove `name` instead.',

View File

@ -1,7 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import { List } from 'rc-field-form'; import { List } from 'rc-field-form';
import { StoreValue } from 'rc-field-form/lib/interface'; import { StoreValue } from 'rc-field-form/lib/interface';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
interface FieldData { interface FieldData {
name: number; name: number;
@ -21,12 +21,15 @@ interface FormListProps {
} }
const FormList: React.FC<FormListProps> = ({ children, ...props }) => { const FormList: React.FC<FormListProps> = ({ children, ...props }) => {
warning(!!props.name, 'Form.List', 'Miss `name` prop.'); devWarning(!!props.name, 'Form.List', 'Miss `name` prop.');
return ( return (
<List {...props}> <List {...props}>
{(fields, operation) => { {(fields, operation) => {
return children(fields.map(field => ({ ...field, fieldKey: field.key })), operation); return children(
fields.map(field => ({ ...field, fieldKey: field.key })),
operation,
);
}} }}
</List> </List>
); );

View File

@ -3,7 +3,7 @@ import InternalForm, { useForm, FormInstance, FormProps } from './Form';
import Item, { FormItemProps } from './FormItem'; import Item, { FormItemProps } from './FormItem';
import List from './FormList'; import List from './FormList';
import { FormProvider } from './context'; import { FormProvider } from './context';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
type InternalForm = typeof InternalForm; type InternalForm = typeof InternalForm;
interface Form extends InternalForm { interface Form extends InternalForm {
@ -23,7 +23,7 @@ Form.List = List;
Form.useForm = useForm; Form.useForm = useForm;
Form.Provider = FormProvider; Form.Provider = FormProvider;
Form.create = () => { Form.create = () => {
warning( devWarning(
false, false,
'Form', 'Form',
'antd v4 removed `Form.create`. Please remove or use `@ant-design/compatible` instead.', 'antd v4 removed `Form.create`. Please remove or use `@ant-design/compatible` instead.',

View File

@ -1,7 +1,7 @@
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
const Icon = () => { const Icon = () => {
warning(false, 'Icon', 'Empty Icon'); devWarning(false, 'Icon', 'Empty Icon');
return null; return null;
}; };

View File

@ -9,7 +9,7 @@ import { Omit, LiteralUnion } from '../_util/type';
import ClearableLabeledInput, { hasPrefixSuffix } from './ClearableLabeledInput'; import ClearableLabeledInput, { hasPrefixSuffix } from './ClearableLabeledInput';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import SizeContext, { SizeType } from '../config-provider/SizeContext'; import SizeContext, { SizeType } from '../config-provider/SizeContext';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
export interface InputProps export interface InputProps
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix' | 'type'> { extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix' | 'type'> {
@ -153,7 +153,7 @@ class Input extends React.Component<InputProps, InputState> {
getSnapshotBeforeUpdate(prevProps: InputProps) { getSnapshotBeforeUpdate(prevProps: InputProps) {
if (hasPrefixSuffix(prevProps) !== hasPrefixSuffix(this.props)) { if (hasPrefixSuffix(prevProps) !== hasPrefixSuffix(this.props)) {
warning( devWarning(
this.input !== document.activeElement, this.input !== document.activeElement,
'Input', 'Input',
`When Input is focused, dynamic add or remove prefix / suffix will make it lose focus caused by dom structure change. Read more: https://ant.design/components/input/#FAQ`, `When Input is focused, dynamic add or remove prefix / suffix will make it lose focus caused by dom structure change. Read more: https://ant.design/components/input/#FAQ`,

View File

@ -1,6 +1,6 @@
import * as React from 'react'; import * as React from 'react';
import { ValidateMessages } from 'rc-field-form/lib/interface'; import { ValidateMessages } from 'rc-field-form/lib/interface';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import { ModalLocale, changeConfirmLocale } from '../modal/locale'; import { ModalLocale, changeConfirmLocale } from '../modal/locale';
import { TransferLocale as TransferLocaleForEmpty } from '../empty'; import { TransferLocale as TransferLocaleForEmpty } from '../empty';
@ -51,7 +51,7 @@ export default class LocaleProvider extends React.Component<LocaleProviderProps,
super(props); super(props);
changeConfirmLocale(props.locale && props.locale.Modal); changeConfirmLocale(props.locale && props.locale.Modal);
warning( devWarning(
props._ANT_MARK__ === ANT_MARK, props._ANT_MARK__ === ANT_MARK,
'LocaleProvider', 'LocaleProvider',
'`LocaleProvider` is deprecated. Please use `locale` with `ConfigProvider` instead: http://u.ant.design/locale', '`LocaleProvider` is deprecated. Please use `locale` with `ConfigProvider` instead: http://u.ant.design/locale',

View File

@ -12,7 +12,7 @@ import Layout from '../../layout';
import Tooltip from '../../tooltip'; import Tooltip from '../../tooltip';
import mountTest from '../../../tests/shared/mountTest'; import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest'; import rtlTest from '../../../tests/shared/rtlTest';
import { resetWarned } from '../../_util/warning'; import { resetWarned } from '../../_util/devWarning';
const { SubMenu } = Menu; const { SubMenu } = Menu;

View File

@ -5,7 +5,7 @@ import omit from 'omit.js';
import SubMenu from './SubMenu'; import SubMenu from './SubMenu';
import Item from './MenuItem'; import Item from './MenuItem';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import { SiderContext, SiderContextProps } from '../layout/Sider'; import { SiderContext, SiderContextProps } from '../layout/Sider';
import raf from '../_util/raf'; import raf from '../_util/raf';
import collapseMotion from '../_util/motion'; import collapseMotion from '../_util/motion';
@ -120,13 +120,13 @@ class InternalMenu extends React.Component<InternalMenuProps, MenuState> {
constructor(props: InternalMenuProps) { constructor(props: InternalMenuProps) {
super(props); super(props);
warning( devWarning(
!('inlineCollapsed' in props && props.mode !== 'inline'), !('inlineCollapsed' in props && props.mode !== 'inline'),
'Menu', 'Menu',
'`inlineCollapsed` should only be used when `mode` is inline.', '`inlineCollapsed` should only be used when `mode` is inline.',
); );
warning( devWarning(
!(props.siderCollapsed !== undefined && 'inlineCollapsed' in props), !(props.siderCollapsed !== undefined && 'inlineCollapsed' in props),
'Menu', 'Menu',
'`inlineCollapsed` not control Menu under Sider. Should set `collapsed` on Sider instead.', '`inlineCollapsed` not control Menu under Sider. Should set `collapsed` on Sider instead.',
@ -197,7 +197,7 @@ class InternalMenu extends React.Component<InternalMenuProps, MenuState> {
} }
if (openAnimation) { if (openAnimation) {
warning( devWarning(
typeof openAnimation === 'string', typeof openAnimation === 'string',
'Menu', 'Menu',
'`openAnimation` do not support object. Please use `motion` instead.', '`openAnimation` do not support object. Please use `motion` instead.',

View File

@ -2,7 +2,7 @@ import * as React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import Dialog, { ModalFuncProps } from './Modal'; import Dialog, { ModalFuncProps } from './Modal';
import ActionButton from './ActionButton'; import ActionButton from './ActionButton';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
interface ConfirmDialogProps extends ModalFuncProps { interface ConfirmDialogProps extends ModalFuncProps {
afterClose?: () => void; afterClose?: () => void;
@ -29,7 +29,7 @@ const ConfirmDialog = (props: ConfirmDialogProps) => {
cancelButtonProps, cancelButtonProps,
} = props; } = props;
warning( devWarning(
!(typeof icon === 'string' && icon.length > 2), !(typeof icon === 'string' && icon.length > 2),
'Modal', 'Modal',
`\`icon\` is using ReactNode instead of string naming in v4. Please check \`${icon}\` at https://ant.design/components/icon`, `\`icon\` is using ReactNode instead of string naming in v4. Please check \`${icon}\` at https://ant.design/components/icon`,

View File

@ -6,7 +6,7 @@ import ExclamationCircleFilled from '@ant-design/icons/ExclamationCircleFilled';
import WarningFilled from '@ant-design/icons/WarningFilled'; import WarningFilled from '@ant-design/icons/WarningFilled';
import { ConfigConsumerProps, ConfigConsumer } from '../config-provider'; import { ConfigConsumerProps, ConfigConsumer } from '../config-provider';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import noFound from './noFound'; import noFound from './noFound';
import serverError from './serverError'; import serverError from './serverError';
@ -52,7 +52,7 @@ const ExceptionStatus = Object.keys(ExceptionMap);
const renderIcon = (prefixCls: string, { status, icon }: ResultProps) => { const renderIcon = (prefixCls: string, { status, icon }: ResultProps) => {
const className = classnames(`${prefixCls}-icon`); const className = classnames(`${prefixCls}-icon`);
warning( devWarning(
!(typeof icon === 'string' && icon.length > 2), !(typeof icon === 'string' && icon.length > 2),
'Result', 'Result',
`\`icon\` is using ReactNode instead of string naming in v4. Please check \`${icon}\` at https://ant.design/components/icon`, `\`icon\` is using ReactNode instead of string naming in v4. Please check \`${icon}\` at https://ant.design/components/icon`,

View File

@ -2,7 +2,7 @@ import React from 'react';
import { mount } from 'enzyme'; import { mount } from 'enzyme';
import Switch from '..'; import Switch from '..';
import focusTest from '../../../tests/shared/focusTest'; import focusTest from '../../../tests/shared/focusTest';
import { resetWarned } from '../../_util/warning'; import { resetWarned } from '../../_util/devWarning';
import mountTest from '../../../tests/shared/mountTest'; import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest'; import rtlTest from '../../../tests/shared/rtlTest';

View File

@ -7,7 +7,7 @@ import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
import Wave from '../_util/wave'; import Wave from '../_util/wave';
import { ConfigContext } from '../config-provider'; import { ConfigContext } from '../config-provider';
import SizeContext from '../config-provider/SizeContext'; import SizeContext from '../config-provider/SizeContext';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
export type SwitchSize = 'small' | 'default'; export type SwitchSize = 'small' | 'default';
export type SwitchChangeEventHandler = (checked: boolean, event: MouseEvent) => void; export type SwitchChangeEventHandler = (checked: boolean, event: MouseEvent) => void;
@ -36,7 +36,7 @@ interface CompoundedComponent
} }
const Switch = React.forwardRef<unknown, SwitchProps>((props, ref) => { const Switch = React.forwardRef<unknown, SwitchProps>((props, ref) => {
warning( devWarning(
'checked' in props || !('value' in props), 'checked' in props || !('value' in props),
'Switch', 'Switch',
'`value` is not a valid prop, do you mean `checked`?', '`value` is not a valid prop, do you mean `checked`?',

View File

@ -35,7 +35,7 @@ import defaultLocale from '../locale/en_US';
import SizeContext, { SizeType } from '../config-provider/SizeContext'; import SizeContext, { SizeType } from '../config-provider/SizeContext';
import Column from './Column'; import Column from './Column';
import ColumnGroup from './ColumnGroup'; import ColumnGroup from './ColumnGroup';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import useBreakpoint from '../grid/hooks/useBreakpoint'; import useBreakpoint from '../grid/hooks/useBreakpoint';
export { ColumnsType, TablePaginationConfig }; export { ColumnsType, TablePaginationConfig };
@ -315,7 +315,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
// Dynamic table data // Dynamic table data
if (mergedData.length < total!) { if (mergedData.length < total!) {
if (mergedData.length > pageSize) { if (mergedData.length > pageSize) {
warning( devWarning(
false, false,
'Table', 'Table',
'`dataSource` length is less than `pagination.total` but large than `pagination.pageSize`. Please make sure your config correct data with async mode.', '`dataSource` length is less than `pagination.total` but large than `pagination.pageSize`. Please make sure your config correct data with async mode.',

View File

@ -5,7 +5,7 @@ import React from 'react';
import { mount } from 'enzyme'; import { mount } from 'enzyme';
import Table from '..'; import Table from '..';
import scrollTo from '../../_util/scrollTo'; import scrollTo from '../../_util/scrollTo';
import { resetWarned } from '../../_util/warning'; import { resetWarned } from '../../_util/devWarning';
describe('Table.pagination', () => { describe('Table.pagination', () => {
const columns = [ const columns = [

View File

@ -2,7 +2,7 @@ import React from 'react';
import { mount, render } from 'enzyme'; import { mount, render } from 'enzyme';
import Table from '..'; import Table from '..';
import Checkbox from '../../checkbox'; import Checkbox from '../../checkbox';
import { resetWarned } from '../../_util/warning'; import { resetWarned } from '../../_util/devWarning';
import ConfigProvider from '../../config-provider'; import ConfigProvider from '../../config-provider';
describe('Table.rowSelection', () => { describe('Table.rowSelection', () => {

View File

@ -6,7 +6,7 @@ import Checkbox, { CheckboxProps } from '../../checkbox';
import Dropdown from '../../dropdown'; import Dropdown from '../../dropdown';
import Menu from '../../menu'; import Menu from '../../menu';
import Radio from '../../radio'; import Radio from '../../radio';
import warning from '../../_util/warning'; import devWarning from '../../_util/devWarning';
import { import {
TableRowSelection, TableRowSelection,
Key, Key,
@ -178,7 +178,7 @@ export default function useSelection<RecordType>(
const keys = Array.from(keySet); const keys = Array.from(keySet);
setSelectedKeys(keys); setSelectedKeys(keys);
if (onSelectInvert) { if (onSelectInvert) {
warning( devWarning(
false, false,
'Table', 'Table',
'`onSelectInvert` will be removed in future. Please use `onChange` instead.', '`onSelectInvert` will be removed in future. Please use `onChange` instead.',
@ -215,7 +215,7 @@ export default function useSelection<RecordType>(
process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'production' &&
('checked' in checkboxProps || 'defaultChecked' in checkboxProps) ('checked' in checkboxProps || 'defaultChecked' in checkboxProps)
) { ) {
warning( devWarning(
false, false,
'Table', 'Table',
'Do not set `checked` or `defaultChecked` in `getCheckboxProps`. Please use `selectedRowKeys` instead.', 'Do not set `checked` or `defaultChecked` in `getCheckboxProps`. Please use `selectedRowKeys` instead.',

View File

@ -4,7 +4,7 @@ import moment from 'moment';
import TimePicker from '..'; import TimePicker from '..';
import focusTest from '../../../tests/shared/focusTest'; import focusTest from '../../../tests/shared/focusTest';
import mountTest from '../../../tests/shared/mountTest'; import mountTest from '../../../tests/shared/mountTest';
import { resetWarned } from '../../_util/warning'; import { resetWarned } from '../../_util/devWarning';
import rtlTest from '../../../tests/shared/rtlTest'; import rtlTest from '../../../tests/shared/rtlTest';
describe('TimePicker', () => { describe('TimePicker', () => {

View File

@ -2,7 +2,7 @@ import { Moment } from 'moment';
import * as React from 'react'; import * as React from 'react';
import DatePicker from '../date-picker'; import DatePicker from '../date-picker';
import { PickerTimeProps, RangePickerTimeProps } from '../date-picker/generatePicker'; import { PickerTimeProps, RangePickerTimeProps } from '../date-picker/generatePicker';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import { Omit } from '../_util/type'; import { Omit } from '../_util/type';
const { TimePicker: InternalTimePicker, RangePicker: InternalRangePicker } = DatePicker; const { TimePicker: InternalTimePicker, RangePicker: InternalRangePicker } = DatePicker;
@ -30,7 +30,7 @@ const TimePicker = React.forwardRef<any, TimePickerProps>(
return renderExtraFooter; return renderExtraFooter;
} }
if (addon) { if (addon) {
warning( devWarning(
false, false,
'TimePicker', 'TimePicker',
'`addon` is deprecated. Please use `renderExtraFooter` instead.', '`addon` is deprecated. Please use `renderExtraFooter` instead.',

View File

@ -9,7 +9,7 @@ import RcTreeSelect, {
import classNames from 'classnames'; import classNames from 'classnames';
import omit from 'omit.js'; import omit from 'omit.js';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import { AntTreeNodeProps } from '../tree'; import { AntTreeNodeProps } from '../tree';
import getIcons from '../select/utils/iconUtil'; import getIcons from '../select/utils/iconUtil';
import renderSwitcherIcon from '../tree/utils/iconUtil'; import renderSwitcherIcon from '../tree/utils/iconUtil';
@ -55,7 +55,7 @@ class TreeSelect<T> extends React.Component<TreeSelectProps<T>, {}> {
constructor(props: TreeSelectProps<T>) { constructor(props: TreeSelectProps<T>) {
super(props); super(props);
warning( devWarning(
props.multiple !== false || !props.treeCheckable, props.multiple !== false || !props.treeCheckable,
'TreeSelect', 'TreeSelect',
'`multiple` will alway be `true` when `treeCheckable` is true', '`multiple` will alway be `true` when `treeCheckable` is true',

View File

@ -11,7 +11,7 @@ import ResizeObserver from 'rc-resize-observer';
import { ConfigConsumerProps, configConsumerProps } from '../config-provider'; import { ConfigConsumerProps, configConsumerProps } from '../config-provider';
import { withConfigConsumer } from '../config-provider/context'; import { withConfigConsumer } from '../config-provider/context';
import LocaleReceiver from '../locale-provider/LocaleReceiver'; import LocaleReceiver from '../locale-provider/LocaleReceiver';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import TransButton from '../_util/transButton'; import TransButton from '../_util/transButton';
import raf from '../_util/raf'; import raf from '../_util/raf';
import isStyleSupport from '../_util/styleChecker'; import isStyleSupport from '../_util/styleChecker';
@ -111,7 +111,7 @@ class Base extends React.Component<InternalBlockProps & ConfigConsumerProps, Bas
static getDerivedStateFromProps(nextProps: BlockProps) { static getDerivedStateFromProps(nextProps: BlockProps) {
const { children, editable } = nextProps; const { children, editable } = nextProps;
warning( devWarning(
!editable || typeof children === 'string', !editable || typeof children === 'string',
'Typography', 'Typography',
'When `editable` is enabled, the `children` should use string.', 'When `editable` is enabled, the `children` should use string.',
@ -296,7 +296,7 @@ class Base extends React.Component<InternalBlockProps & ConfigConsumerProps, Bas
// Do not measure if css already support ellipsis // Do not measure if css already support ellipsis
if (this.canUseCSSEllipsis()) return; if (this.canUseCSSEllipsis()) return;
warning( devWarning(
toArray(children).every((child: React.ReactNode) => typeof child === 'string'), toArray(children).every((child: React.ReactNode) => typeof child === 'string'),
'Typography', 'Typography',
'`ellipsis` should use string as children only.', '`ellipsis` should use string as children only.',

View File

@ -1,5 +1,5 @@
import * as React from 'react'; import * as React from 'react';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import Base, { BlockProps } from './Base'; import Base, { BlockProps } from './Base';
export interface TextProps extends BlockProps { export interface TextProps extends BlockProps {
@ -7,7 +7,7 @@ export interface TextProps extends BlockProps {
} }
const Text: React.FC<TextProps> = ({ ellipsis, ...restProps }) => { const Text: React.FC<TextProps> = ({ ellipsis, ...restProps }) => {
warning( devWarning(
typeof ellipsis !== 'object', typeof ellipsis !== 'object',
'Typography.Text', 'Typography.Text',
'`ellipsis` only supports boolean value.', '`ellipsis` only supports boolean value.',

View File

@ -1,5 +1,5 @@
import * as React from 'react'; import * as React from 'react';
import warning from 'warning'; import devWarning from '../_util/devWarning';
import Base, { BlockProps } from './Base'; import Base, { BlockProps } from './Base';
import { tupleNum, Omit } from '../_util/type'; import { tupleNum, Omit } from '../_util/type';
@ -14,7 +14,7 @@ const Title: React.FC<TitleProps> = props => {
if (TITLE_ELE_LIST.indexOf(level) !== -1) { if (TITLE_ELE_LIST.indexOf(level) !== -1) {
component = `h${level}`; component = `h${level}`;
} else { } else {
warning(false, 'Title only accept `1 | 2 | 3 | 4` as `level` value.'); devWarning(false, 'Typography.Title', 'Title only accept `1 | 2 | 3 | 4` as `level` value.');
component = 'h1'; component = 'h1';
} }

View File

@ -1,7 +1,7 @@
import * as React from 'react'; import * as React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
import { composeRef } from '../_util/ref'; import { composeRef } from '../_util/ref';
export interface TypographyProps { export interface TypographyProps {
@ -34,7 +34,7 @@ const Typography: React.RefForwardingComponent<{}, InternalTypographyProps> = (
let mergedRef = ref; let mergedRef = ref;
if (setContentRef) { if (setContentRef) {
warning(false, 'Typography', '`setContentRef` is deprecated. Please use `ref` instead.'); devWarning(false, 'Typography', '`setContentRef` is deprecated. Please use `ref` instead.');
mergedRef = composeRef(ref, setContentRef); mergedRef = composeRef(ref, setContentRef);
} }

View File

@ -61,7 +61,7 @@ describe('Typography', () => {
mount(<Title level={false} />); mount(<Title level={false} />);
expect(errorSpy).toHaveBeenCalledWith( expect(errorSpy).toHaveBeenCalledWith(
'Warning: Title only accept `1 | 2 | 3 | 4` as `level` value.', 'Warning: [antd: Typography.Title] Title only accept `1 | 2 | 3 | 4` as `level` value.',
); );
}); });
}); });

View File

@ -17,7 +17,7 @@ import { T, fileToObject, getFileItem, removeFileItem } from './utils';
import LocaleReceiver from '../locale-provider/LocaleReceiver'; import LocaleReceiver from '../locale-provider/LocaleReceiver';
import defaultLocale from '../locale/default'; import defaultLocale from '../locale/default';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import warning from '../_util/warning'; import devWarning from '../_util/devWarning';
export { UploadProps }; export { UploadProps };
@ -61,7 +61,7 @@ class Upload extends React.Component<UploadProps, UploadState> {
dragState: 'drop', dragState: 'drop',
}; };
warning( devWarning(
'fileList' in props || !('value' in props), 'fileList' in props || !('value' in props),
'Upload', 'Upload',
'`value` is not a valid prop, do you mean `fileList`?', '`value` is not a valid prop, do you mean `fileList`?',

View File

@ -5,7 +5,7 @@ import Upload from '..';
import Form from '../../form'; import Form from '../../form';
import { T, fileToObject, getFileItem, removeFileItem } from '../utils'; import { T, fileToObject, getFileItem, removeFileItem } from '../utils';
import { setup, teardown } from './mock'; import { setup, teardown } from './mock';
import { resetWarned } from '../../_util/warning'; import { resetWarned } from '../../_util/devWarning';
import mountTest from '../../../tests/shared/mountTest'; import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest'; import rtlTest from '../../../tests/shared/rtlTest';

View File

@ -257,6 +257,7 @@
"rimraf": "^3.0.0", "rimraf": "^3.0.0",
"scrollama": "^2.0.0", "scrollama": "^2.0.0",
"simple-git": "^2.0.0", "simple-git": "^2.0.0",
"string-replace-loader": "^2.3.0",
"stylelint": "^13.0.0", "stylelint": "^13.0.0",
"stylelint-config-prettier": "^8.0.0", "stylelint-config-prettier": "^8.0.0",
"stylelint-config-rational-order": "^0.1.2", "stylelint-config-rational-order": "^0.1.2",

View File

@ -3,7 +3,7 @@ import React from 'react';
import AntdIcon, { createFromIconfontCN } from '@ant-design/icons'; import AntdIcon, { createFromIconfontCN } from '@ant-design/icons';
import { withThemeSuffix, removeTypeTheme, getThemeFromTypeName } from './utils'; import { withThemeSuffix, removeTypeTheme, getThemeFromTypeName } from './utils';
import warning from '../../../../components/_util/warning'; import warning from '../../../../components/_util/devWarning';
const IconFont = createFromIconfontCN({ const IconFont = createFromIconfontCN({
scriptUrl: '//at.alicdn.com/t/font_1329669_t1u72b9zk8s.js', scriptUrl: '//at.alicdn.com/t/font_1329669_t1u72b9zk8s.js',

View File

@ -1,4 +1,4 @@
import warning from '../../../../components/_util/warning'; import warning from '../../../../components/_util/devWarning';
// These props make sure that the SVG behaviours like general text. // These props make sure that the SVG behaviours like general text.
// Reference: https://blog.prototypr.io/align-svg-icons-to-text-and-say-goodbye-to-font-icons-d44b3d7b26b4 // Reference: https://blog.prototypr.io/align-svg-icons-to-text-and-say-goodbye-to-font-icons-d44b3d7b26b4
@ -27,10 +27,7 @@ export function getThemeFromTypeName(type) {
} }
export function removeTypeTheme(type) { export function removeTypeTheme(type) {
return type return type.replace(fillTester, '').replace(outlineTester, '').replace(twoToneTester, '');
.replace(fillTester, '')
.replace(outlineTester, '')
.replace(twoToneTester, '');
} }
export function withThemeSuffix(type, theme) { export function withThemeSuffix(type, theme) {

View File

@ -34,10 +34,29 @@ function externalMoment(config) {
}; };
} }
function injectWarningCondition(config) {
config.module.rules.forEach(rule => {
// Remove devWarning if needed
if (rule.test.test('test.tsx')) {
rule.use = [
...rule.use,
{
loader: 'string-replace-loader',
options: {
search: 'devWarning(',
replace: "if (process.env.NODE_ENV !== 'production') devWarning(",
},
},
];
}
});
}
function processWebpackThemeConfig(themeConfig, theme, vars) { function processWebpackThemeConfig(themeConfig, theme, vars) {
themeConfig.forEach(config => { themeConfig.forEach(config => {
ignoreMomentLocale(config); ignoreMomentLocale(config);
externalMoment(config); externalMoment(config);
injectWarningCondition(config);
// rename default entry to ${theme} entry // rename default entry to ${theme} entry
Object.keys(config.entry).forEach(entryName => { Object.keys(config.entry).forEach(entryName => {
@ -79,6 +98,7 @@ if (process.env.RUN_ENV === 'PRODUCTION') {
if (process.env.ESBUILD) { if (process.env.ESBUILD) {
config.optimization.minimizer[0] = new EsbuildPlugin(); config.optimization.minimizer[0] = new EsbuildPlugin();
} }
// skip codesandbox ci // skip codesandbox ci
if (!process.env.CSB_REPO) { if (!process.env.CSB_REPO) {
config.plugins.push( config.plugins.push(