Skip to content

Commit 66e1b1f

Browse files
authored
Replace spread operators with Object.assign to reduce bundle size (5.03kB -> 4.94kB)
1 parent e478a00 commit 66e1b1f

File tree

3 files changed

+45
-46
lines changed

3 files changed

+45
-46
lines changed

benchmark/run.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ import byteSize from './format-filesize.js'
22
import { analyze as analyzeCss } from '../dist/analyzer.modern.js'
33
import * as fs from 'fs'
44
const files = [
5-
['bol-com-20190617', 'Bol.com', 117],
6-
['bootstrap-5.0.0', 'Bootstrap 5.0.0', 49],
7-
['cnn-20220403', 'CNN', 360],
8-
['css-tricks-20190319', 'CSS-Tricks', 50],
9-
['cnn-20220403', 'CNN', 360],
10-
['facebook-20190319', 'Facebook.com', 71],
11-
['github-20210501', 'GitHub.com', 95],
12-
['gazelle-20210905', 'Gazelle.nl', 312],
13-
['lego-20190617', 'Lego.com', 59],
14-
['smashing-magazine-20190319', 'Smashing Magazine.com', 285],
15-
['trello-20190617', 'Trello.com', 80]
5+
['bol-com-20190617', 'Bol.com', 130],
6+
['bootstrap-5.0.0', 'Bootstrap 5.0.0', 54],
7+
['cnn-20220403', 'CNN', 406],
8+
['css-tricks-20190319', 'CSS-Tricks', 54],
9+
['facebook-20190319', 'Facebook.com', 79],
10+
['github-20210501', 'GitHub.com', 101],
11+
['gazelle-20210905', 'Gazelle.nl', 332],
12+
['lego-20190617', 'Lego.com', 63],
13+
['smashing-magazine-20190319', 'Smashing Magazine.com', 332],
14+
['trello-20190617', 'Trello.com', 86]
1615
]
1716

1817
let maxLen = -1

src/atrules/atrules.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ const analyzeAtRules = ({ atrules, stringifyNode }) => {
7272
media: medias.count(),
7373
charset: charsets.count(),
7474
supports: supports.count(),
75-
keyframes: {
76-
...keyframes.count(),
77-
prefixed: {
78-
...prefixedKeyframes.count(),
75+
keyframes: Object.assign(
76+
keyframes.count(), {
77+
prefixed: Object.assign(
78+
prefixedKeyframes.count(), {
7979
ratio: keyframes.size() === 0 ? 0 : prefixedKeyframes.size() / keyframes.size()
80-
}
81-
},
80+
}),
81+
}),
8282
container: containers.count(),
8383
layer: layers.count(),
8484
}

src/index.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,14 @@ const analyze = (css) => {
362362
total: emptyRules,
363363
ratio: totalRules === 0 ? 0 : emptyRules / totalRules
364364
},
365-
selectors: {
366-
...selectorsPerRule.aggregate(),
365+
selectors: Object.assign(
366+
selectorsPerRule.aggregate(), {
367367
items: selectorsPerRule.toArray(),
368-
},
369-
declarations: {
370-
...declarationsPerRule.aggregate(),
368+
}),
369+
declarations: Object.assign(
370+
declarationsPerRule.aggregate(), {
371371
items: declarationsPerRule.toArray()
372-
},
372+
}),
373373
},
374374
selectors: {
375375
total: totalSelectors,
@@ -384,19 +384,19 @@ const analyze = (css) => {
384384
median: [aggregatesA.median, aggregatesB.median, aggregatesC.median],
385385
items: specificities
386386
},
387-
complexity: {
388-
...complexityAggregator.aggregate(),
389-
...complexityCount,
390-
items: complexities,
391-
},
392-
id: {
393-
...ids.count(),
387+
complexity: Object.assign(
388+
complexityAggregator.aggregate(),
389+
complexityCount, {
390+
items: complexities
391+
}),
392+
id: Object.assign(
393+
ids.count(), {
394394
ratio: totalSelectors === 0 ? 0 : ids.size() / totalSelectors,
395-
},
396-
accessibility: {
397-
...a11y.count(),
395+
}),
396+
accessibility: Object.assign(
397+
a11y.count(), {
398398
ratio: totalSelectors === 0 ? 0 : a11y.size() / totalSelectors,
399-
},
399+
}),
400400
keyframes: keyframeSelectors.count(),
401401
},
402402
declarations: {
@@ -414,21 +414,21 @@ const analyze = (css) => {
414414
},
415415
},
416416
},
417-
properties: {
418-
...properties.count(),
419-
prefixed: {
420-
...propertyVendorPrefixes.count(),
417+
properties: Object.assign(
418+
properties.count(), {
419+
prefixed: Object.assign(
420+
propertyVendorPrefixes.count(), {
421421
ratio: properties.size() === 0 ? 0 : propertyVendorPrefixes.size() / properties.size(),
422-
},
423-
custom: {
424-
...customProperties.count(),
422+
}),
423+
custom: Object.assign(
424+
customProperties.count(), {
425425
ratio: properties.size() === 0 ? 0 : customProperties.size() / properties.size(),
426-
},
427-
browserhacks: {
428-
...propertyHacks.count(),
426+
}),
427+
browserhacks: Object.assign(
428+
propertyHacks.count(), {
429429
ratio: properties.size() === 0 ? 0 : propertyHacks.size() / properties.size(),
430-
}
431-
},
430+
}),
431+
}),
432432
values: {
433433
colors: colors.count(),
434434
fontFamilies: analyzeFontFamilies({ stringifyNode, fontValues, fontFamilyValues }),

0 commit comments

Comments
 (0)