Skip to content

Commit 01138dc

Browse files
authored
Skip parse.icon if everything is there (#444)
1 parent 8e50c34 commit 01138dc

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

.npmrc.proregistry

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
@fortawesome:registry=https://npm.fontawesome.com/
2-
//npm.fontawesome.com/:_authToken=${FONTAWESOME_NPM_AUTH_TOKEN}
2+
//npm.fontawesome.com/:_authToken=${FONTAWESOME_NPM_AUTH_TOKEN}

src/components/FontAwesomeIcon.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default function FontAwesomeIcon({ forwardedRef, ...props }) {
1818
} = props
1919

2020
const iconLookup = normalizeIconArgs(iconArgs)
21+
2122
const classes = objectWithKey('classes', [
2223
...classList(props),
2324
...className.split(' ')

src/components/__tests__/FontAwesomeIcon.test.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as fontawesome from '@fortawesome/fontawesome-svg-core'
22
import log from '../../logger'
3-
import { faClose } from '@fortawesome/free-solid-svg-icons'
3+
import { faTimes } from '@fortawesome/free-solid-svg-icons'
44
import { faCoffee, faCircle, faSpartan } from '../__fixtures__/icons'
55
import { coreHasFeature, REFERENCE_ICON_USING_STRING, REFERENCE_ICON_BY_STYLE, ICON_ALIASES, mount } from '../__fixtures__/helpers'
66

@@ -10,6 +10,10 @@ beforeEach(() => {
1010
fontawesome.library.add(faCoffee, faCircle, faSpartan)
1111
})
1212

13+
afterEach(() => {
14+
fontawesome.library.reset()
15+
})
16+
1317
test('using a FAT icon using array format', () => {
1418
const vm = mount({
1519
icon: ['fat', 'spartan']
@@ -21,21 +25,19 @@ test('using a FAT icon using array format', () => {
2125

2226
if (coreHasFeature(ICON_ALIASES)) {
2327
test('find a free-solid-svg-icon with array format', () => {
24-
fontawesome.library.reset()
25-
fontawesome.library.add(faClose)
28+
fontawesome.library.add(faTimes)
2629
const vm = mount({ icon: ['fas', 'xmark'] })
2730

2831
expect(vm.type).toBe('svg')
2932
expect(vm.props.className.includes('fa-xmark')).toBeTruthy()
3033
})
3134

3235
test('find a free-solid-svg-icon that is an alias ', () => {
33-
fontawesome.library.reset()
34-
fontawesome.library.add(faClose)
36+
fontawesome.library.add(faTimes)
3537
const vm = mount({ icon: ['fas', 'close'] })
3638

3739
expect(vm.type).toBe('svg')
38-
expect(vm.props.className.includes('fa-close')).toBeTruthy()
40+
expect(vm.props.className.includes('fa-xmark')).toBeTruthy()
3941
})
4042
}
4143

@@ -71,6 +73,14 @@ if (coreHasFeature(REFERENCE_ICON_BY_STYLE)) {
7173
})
7274
}
7375

76+
test('using imported object from svg icons package', () => {
77+
const vm = mount({
78+
icon: faTimes
79+
})
80+
81+
expect(vm.type).toBe('svg')
82+
})
83+
7484
test('using pack and name', () => {
7585
const vm = mount({
7686
icon: ['fas', 'coffee'],

src/utils/normalize-icon-args.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import { parse as faParse } from '@fortawesome/fontawesome-svg-core'
22

33
// Normalize icon arguments
44
export default function normalizeIconArgs(icon) {
5+
// this has everything that it needs to be rendered which means it was probably imported
6+
// directly from an icon svg package
7+
if (icon && typeof icon === 'object' && icon.prefix && icon.iconName && icon.icon) {
8+
return icon
9+
}
10+
511
if (faParse.icon) {
612
return faParse.icon(icon)
713
}
@@ -12,7 +18,7 @@ export default function normalizeIconArgs(icon) {
1218
}
1319

1420
// if the icon is an object and has a prefix and an icon name, return it
15-
if (typeof icon === 'object' && icon.prefix && icon.iconName) {
21+
if (icon && typeof icon === 'object' && icon.prefix && icon.iconName) {
1622
return icon
1723
}
1824

0 commit comments

Comments
 (0)