Skip to content

Commit 5a5f817

Browse files
authored
Reduce bundle size (#312)
## Before ``` Build "@projectwallace/css-analyzer" to dist: 6.12 kB: analyzer.cjs.gz 5.5 kB: analyzer.cjs.br 5.61 kB: analyzer.modern.js.gz 5.07 kB: analyzer.modern.js.br 6.09 kB: analyzer.module.js.gz 5.47 kB: analyzer.module.js.br 6.22 kB: analyzer.umd.js.gz 5.58 kB: analyzer.umd.js.br ``` ## After ``` Build "@projectwallace/css-analyzer" to dist: 6 kB: analyzer.cjs.gz 5.38 kB: analyzer.cjs.br 5.47 kB: analyzer.modern.js.gz 4.93 kB: analyzer.modern.js.br 5.97 kB: analyzer.module.js.gz 5.38 kB: analyzer.module.js.br 6.1 kB: analyzer.umd.js.gz 5.47 kB: analyzer.umd.js.br ```
1 parent 0cfb55c commit 5a5f817

File tree

2 files changed

+8
-51
lines changed

2 files changed

+8
-51
lines changed

src/string-utils.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ function compareChar(referenceCode, testCode) {
2020
* @returns {boolean} true if the two strings are the same, false otherwise
2121
*/
2222
export function strEquals(base, test) {
23-
if (base.length !== test.length) return false
23+
let len = base.length;
24+
if (len !== test.length) return false
2425

25-
for (let i = 0; i < base.length; i++) {
26+
for (let i = 0; i < len; i++) {
2627
if (compareChar(base.charCodeAt(i), test.charCodeAt(i)) === false) {
2728
return false
2829
}
@@ -38,13 +39,14 @@ export function strEquals(base, test) {
3839
* @returns {boolean} true if `test` ends with `base`, false otherwise
3940
*/
4041
export function endsWith(base, test) {
41-
const offset = test.length - base.length
42+
let len = test.length
43+
const offset = len - base.length
4244

4345
if (offset < 0) {
4446
return false
4547
}
4648

47-
for (let i = test.length - 1; i >= offset; i--) {
49+
for (let i = len - 1; i >= offset; i--) {
4850
if (compareChar(base.charCodeAt(i - offset), test.charCodeAt(i)) === false) {
4951
return false
5052
}
@@ -60,7 +62,8 @@ export function endsWith(base, test) {
6062
* @returns {boolean} true if `test` starts with `base`, false otherwise
6163
*/
6264
export function startsWith(base, test) {
63-
if (test.length < base.length) return false
65+
let len = base.length
66+
if (test.length < len) return false
6467

6568
for (let i = 0; i < base.length; i++) {
6669
if (compareChar(base.charCodeAt(i), test.charCodeAt(i)) === false) {

src/values/destructure-font-shorthand.js

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,13 @@ const SIZE_KEYWORDS = new Set([
3434
'larger',
3535
])
3636

37-
const STRETCH_KEYWORDS = new Set([
38-
'ultra-condensed',
39-
'extra-condensed',
40-
'condensed',
41-
'semi-condensed',
42-
'semi-expanded',
43-
'expanded',
44-
'extra-expanded',
45-
'ultra-expanded',
46-
])
47-
const STYLE_KEYWORDS = new Set(['italic', 'oblique'])
48-
const WEIGHT_KEYWORDS = new Set(['light', 'bold', 'bolder'])
49-
const VARIANT_KEYWORDS = new Set([
50-
'small-caps',
51-
'all-small-caps',
52-
'petite-caps',
53-
'all-petite-caps',
54-
'unicase',
55-
'titling-caps',
56-
])
57-
5837
const COMMA = 44 // ','.charCodeAt(0) === 44
5938
const SLASH = 47 // '/'.charCodeAt(0) === 47
6039

6140
export function destructure(value, stringifyNode) {
6241
let font_family = []
6342
let font_size
6443
let line_height
65-
let font_weight
66-
let font_style
67-
let font_variant
68-
let font_stretch
6944

7045
value.children.forEach(function (node, item) {
7146
// any node that comes before the '/' is the font-size
@@ -121,7 +96,6 @@ export function destructure(value, stringifyNode) {
12196
// any node that's a number and not previously caught by line-height or font-size is the font-weight
12297
// (oblique <angle> will not be caught here, because that's a Dimension, not a Number)
12398
if (node.type == 'Number') {
124-
font_weight = stringifyNode(node)
12599
return
126100
}
127101

@@ -144,30 +118,10 @@ export function destructure(value, stringifyNode) {
144118
font_size = node.name
145119
return
146120
}
147-
if (STRETCH_KEYWORDS.has(node.name)) {
148-
font_stretch = node.name
149-
return
150-
}
151-
if (WEIGHT_KEYWORDS.has(node.name)) {
152-
font_weight = node.name
153-
return
154-
}
155-
if (STYLE_KEYWORDS.has(node.name)) {
156-
font_style = node.name
157-
return
158-
}
159-
if (VARIANT_KEYWORDS.has(node.name)) {
160-
font_variant = node.name
161-
return
162-
}
163121
}
164122
})
165123

166124
return {
167-
font_style,
168-
font_variant,
169-
font_weight,
170-
font_stretch,
171125
font_size,
172126
line_height,
173127
font_family: stringifyNode({

0 commit comments

Comments
 (0)