Skip to content

Commit

Permalink
fix: 修复生成的组件名称可能会重复导致编译失败或死循环. close iconfont-cli#15
Browse files Browse the repository at this point in the history
  • Loading branch information
axetroy committed Jul 31, 2023
1 parent 8300cc5 commit 6bfb28a
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ interface Props extends Omit<SVGAttributes<SVGElement>, 'color'> {
color?: string | string[];
}

declare const IconSetup: FunctionComponent<Props>;
declare const IconFontIconAlipay: FunctionComponent<Props>;

export default IconSetup;
export default IconFontIconAlipay;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const DEFAULT_STYLE = {
display: 'block',
};

const IconAlipay = ({ size, color, style: _style, ...rest }) => {
const IconFontIconAlipay = ({ size, color, style: _style, ...rest }) => {
const style = _style ? { ...DEFAULT_STYLE, ..._style } : DEFAULT_STYLE;

return (
Expand All @@ -24,8 +24,8 @@ const IconAlipay = ({ size, color, style: _style, ...rest }) => {
);
};

IconAlipay.defaultProps = {
IconFontIconAlipay.defaultProps = {
size: 14,
};

export default IconAlipay;
export default IconFontIconAlipay;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ interface Props extends Omit<SVGAttributes<SVGElement>, 'color'> {
color?: string | string[];
}

declare const IconUser: FunctionComponent<Props>;
declare const IconFontIconSetup: FunctionComponent<Props>;

export default IconUser;
export default IconFontIconSetup;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const DEFAULT_STYLE = {
display: 'block',
};

const IconSetup = ({ size, color, style: _style, ...rest }) => {
const IconFontIconSetup = ({ size, color, style: _style, ...rest }) => {
const style = _style ? { ...DEFAULT_STYLE, ..._style } : DEFAULT_STYLE;

return (
Expand Down Expand Up @@ -60,8 +60,8 @@ const IconSetup = ({ size, color, style: _style, ...rest }) => {
);
};

IconSetup.defaultProps = {
IconFontIconSetup.defaultProps = {
size: 14,
};

export default IconSetup;
export default IconFontIconSetup;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ interface Props extends Omit<SVGAttributes<SVGElement>, 'color'> {
color?: string | string[];
}

declare const IconAlipay: FunctionComponent<Props>;
declare const IconFontIconUser: FunctionComponent<Props>;

export default IconAlipay;
export default IconFontIconUser;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const DEFAULT_STYLE = {
display: 'block',
};

const IconUser = ({ size, color, style: _style, ...rest }) => {
const IconFontIconUser = ({ size, color, style: _style, ...rest }) => {
const style = _style ? { ...DEFAULT_STYLE, ..._style } : DEFAULT_STYLE;

return (
Expand All @@ -24,8 +24,8 @@ const IconUser = ({ size, color, style: _style, ...rest }) => {
);
};

IconUser.defaultProps = {
IconFontIconUser.defaultProps = {
size: 14,
};

export default IconUser;
export default IconFontIconUser;
6 changes: 3 additions & 3 deletions snapshots/demo-js/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable */

import { SVGAttributes, FunctionComponent } from 'react';
export { default as IconAlipay } from './IconAlipay';
export { default as IconUser } from './IconUser';
export { default as IconSetup } from './IconSetup';
export { default as IconFontIconAlipay } from './IconFontIconAlipay';
export { default as IconFontIconUser } from './IconFontIconUser';
export { default as IconFontIconSetup } from './IconFontIconSetup';

interface Props extends Omit<SVGAttributes<SVGElement>, 'color'> {
name: 'alipay' | 'user' | 'setup';
Expand Down
18 changes: 9 additions & 9 deletions snapshots/demo-js/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* eslint-disable */

import React from 'react';
import IconAlipay from './IconAlipay';
import IconUser from './IconUser';
import IconSetup from './IconSetup';
export { default as IconAlipay } from './IconAlipay';
export { default as IconUser } from './IconUser';
export { default as IconSetup } from './IconSetup';
import IconFontIconAlipay from './IconFontIconAlipay';
import IconFontIconUser from './IconFontIconUser';
import IconFontIconSetup from './IconFontIconSetup';
export { default as IconFontIconAlipay } from './IconFontIconAlipay';
export { default as IconFontIconUser } from './IconFontIconUser';
export { default as IconFontIconSetup } from './IconFontIconSetup';

const IconFont = ({ name, ...rest }) => {
switch (name) {
case 'alipay':
return <IconAlipay {...rest} />;
return <IconFontIconAlipay {...rest} />;
case 'user':
return <IconUser {...rest} />;
return <IconFontIconUser {...rest} />;
case 'setup':
return <IconSetup {...rest} />;
return <IconFontIconSetup {...rest} />;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const DEFAULT_STYLE: CSSProperties = {
display: 'block',
};

const IconAlipay: FunctionComponent<Props> = ({ size, color, style: _style, ...rest }) => {
const IconFontIconAlipay: FunctionComponent<Props> = ({ size, color, style: _style, ...rest }) => {
const style = _style ? { ...DEFAULT_STYLE, ..._style } : DEFAULT_STYLE;

return (
Expand All @@ -30,8 +30,8 @@ const IconAlipay: FunctionComponent<Props> = ({ size, color, style: _style, ...r
);
};

IconAlipay.defaultProps = {
IconFontIconAlipay.defaultProps = {
size: 16,
};

export default IconAlipay;
export default IconFontIconAlipay;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const DEFAULT_STYLE: CSSProperties = {
display: 'block',
};

const IconSetup: FunctionComponent<Props> = ({ size, color, style: _style, ...rest }) => {
const IconFontIconSetup: FunctionComponent<Props> = ({ size, color, style: _style, ...rest }) => {
const style = _style ? { ...DEFAULT_STYLE, ..._style } : DEFAULT_STYLE;

return (
Expand Down Expand Up @@ -66,8 +66,8 @@ const IconSetup: FunctionComponent<Props> = ({ size, color, style: _style, ...re
);
};

IconSetup.defaultProps = {
IconFontIconSetup.defaultProps = {
size: 16,
};

export default IconSetup;
export default IconFontIconSetup;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const DEFAULT_STYLE: CSSProperties = {
display: 'block',
};

const IconUser: FunctionComponent<Props> = ({ size, color, style: _style, ...rest }) => {
const IconFontIconUser: FunctionComponent<Props> = ({ size, color, style: _style, ...rest }) => {
const style = _style ? { ...DEFAULT_STYLE, ..._style } : DEFAULT_STYLE;

return (
Expand All @@ -30,8 +30,8 @@ const IconUser: FunctionComponent<Props> = ({ size, color, style: _style, ...res
);
};

IconUser.defaultProps = {
IconFontIconUser.defaultProps = {
size: 16,
};

export default IconUser;
export default IconFontIconUser;
18 changes: 9 additions & 9 deletions snapshots/demo-ts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
/* eslint-disable */

import React, { SVGAttributes, FunctionComponent } from 'react';
import IconAlipay from './IconAlipay';
import IconUser from './IconUser';
import IconSetup from './IconSetup';
export { default as IconAlipay } from './IconAlipay';
export { default as IconUser } from './IconUser';
export { default as IconSetup } from './IconSetup';
import IconFontIconAlipay from './IconFontIconAlipay';
import IconFontIconUser from './IconFontIconUser';
import IconFontIconSetup from './IconFontIconSetup';
export { default as IconFontIconAlipay } from './IconFontIconAlipay';
export { default as IconFontIconUser } from './IconFontIconUser';
export { default as IconFontIconSetup } from './IconFontIconSetup';

export type IconNames = 'alipay' | 'user' | 'setup';

Expand All @@ -20,11 +20,11 @@ interface Props extends Omit<SVGAttributes<SVGElement>, 'color'> {
const IconFont: FunctionComponent<Props> = ({ name, ...rest }) => {
switch (name) {
case 'alipay':
return <IconAlipay {...rest} />;
return <IconFontIconAlipay {...rest} />;
case 'user':
return <IconUser {...rest} />;
return <IconFontIconUser {...rest} />;
case 'setup':
return <IconSetup {...rest} />;
return <IconFontIconSetup {...rest} />;

}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/generateComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const generateComponent = (data: XmlData, config: Config) => {
(_, value) => value.replace(/^[-_.=+#@!~*]+(.+?)$/, '$1')
)
: iconId;
const componentName = upperFirst(camelCase(iconId));
const componentName = 'IconFont' + upperFirst(camelCase(iconId));

names.push(iconIdAfterTrim);

Expand Down

0 comments on commit 6bfb28a

Please sign in to comment.