Skip to content

Commit 8bedd94

Browse files
committed
Hash keys in compiled style objects
Reduce the size of minifed JS by "minifying" the compiled style keys produced by StyleX. This patch uses a base 62 hashing function to generate smaller hashes, which are prefixed with `k` to avoid requiring quotes around hashes that start with a number.
1 parent 52709c6 commit 8bedd94

26 files changed

+1132
-981
lines changed

packages/babel-plugin/__tests__/stylex-transform-call-test.js

+107-107
Large diffs are not rendered by default.

packages/babel-plugin/__tests__/stylex-transform-create-test.js

+181-181
Large diffs are not rendered by default.

packages/babel-plugin/__tests__/stylex-transform-import-test.js

+48-48
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('@stylexjs/babel-plugin', () => {
7070
_inject2(".x1e2nbdu{color:red}", 3000);
7171
export const styles = {
7272
foo: {
73-
color: "x1e2nbdu",
73+
kMwMTN: "x1e2nbdu",
7474
$$css: true
7575
}
7676
};"
@@ -113,7 +113,7 @@ describe('@stylexjs/babel-plugin', () => {
113113
_inject2(".x1e2nbdu{color:red}", 3000);
114114
const styles = {
115115
foo: {
116-
color: "x1e2nbdu",
116+
kMwMTN: "x1e2nbdu",
117117
$$css: true
118118
}
119119
};
@@ -138,7 +138,7 @@ describe('@stylexjs/babel-plugin', () => {
138138
_inject2(".x1e2nbdu{color:red}", 3000);
139139
export default {
140140
foo: {
141-
color: "x1e2nbdu",
141+
kMwMTN: "x1e2nbdu",
142142
$$css: true
143143
}
144144
};"
@@ -163,7 +163,7 @@ describe('@stylexjs/babel-plugin', () => {
163163
_inject2(".x1e2nbdu{color:red}", 3000);
164164
const styles = {
165165
foo: {
166-
color: "x1e2nbdu",
166+
kMwMTN: "x1e2nbdu",
167167
$$css: true
168168
}
169169
};
@@ -196,17 +196,17 @@ describe('@stylexjs/babel-plugin', () => {
196196
_inject2(".x14odnwx{padding:5px}", 1000);
197197
const styles = {
198198
default: {
199-
backgroundColor: "xrkmrrc",
200-
color: "xju2f9n",
201-
padding: "x14odnwx",
202-
paddingInline: null,
203-
paddingStart: null,
204-
paddingLeft: null,
205-
paddingEnd: null,
206-
paddingRight: null,
207-
paddingBlock: null,
208-
paddingTop: null,
209-
paddingBottom: null,
199+
kWkggS: "xrkmrrc",
200+
kMwMTN: "xju2f9n",
201+
kmVPX3: "x14odnwx",
202+
kg3NbH: null,
203+
kuDDbn: null,
204+
kE3dHu: null,
205+
kP0aTx: null,
206+
kpe85a: null,
207+
k8WAf4: null,
208+
kLKAdn: null,
209+
kGO01o: null,
210210
$$css: true
211211
}
212212
};
@@ -237,17 +237,17 @@ describe('@stylexjs/babel-plugin', () => {
237237
_inject2(".x14odnwx{padding:5px}", 1000);
238238
const styles = {
239239
default: {
240-
backgroundColor: "xrkmrrc",
241-
color: "xju2f9n",
242-
padding: "x14odnwx",
243-
paddingInline: null,
244-
paddingStart: null,
245-
paddingLeft: null,
246-
paddingEnd: null,
247-
paddingRight: null,
248-
paddingBlock: null,
249-
paddingTop: null,
250-
paddingBottom: null,
240+
kWkggS: "xrkmrrc",
241+
kMwMTN: "xju2f9n",
242+
kmVPX3: "x14odnwx",
243+
kg3NbH: null,
244+
kuDDbn: null,
245+
kE3dHu: null,
246+
kP0aTx: null,
247+
kpe85a: null,
248+
k8WAf4: null,
249+
kLKAdn: null,
250+
kGO01o: null,
251251
$$css: true
252252
}
253253
};
@@ -278,17 +278,17 @@ describe('@stylexjs/babel-plugin', () => {
278278
_inject2(".x14odnwx{padding:5px}", 1000);
279279
const styles = {
280280
default: {
281-
backgroundColor: "xrkmrrc",
282-
color: "xju2f9n",
283-
padding: "x14odnwx",
284-
paddingInline: null,
285-
paddingStart: null,
286-
paddingLeft: null,
287-
paddingEnd: null,
288-
paddingRight: null,
289-
paddingBlock: null,
290-
paddingTop: null,
291-
paddingBottom: null,
281+
kWkggS: "xrkmrrc",
282+
kMwMTN: "xju2f9n",
283+
kmVPX3: "x14odnwx",
284+
kg3NbH: null,
285+
kuDDbn: null,
286+
kE3dHu: null,
287+
kP0aTx: null,
288+
kpe85a: null,
289+
k8WAf4: null,
290+
kLKAdn: null,
291+
kGO01o: null,
292292
$$css: true
293293
}
294294
};
@@ -319,17 +319,17 @@ describe('@stylexjs/babel-plugin', () => {
319319
_inject2(".x14odnwx{padding:5px}", 1000);
320320
const styles = {
321321
default: {
322-
backgroundColor: "xrkmrrc",
323-
color: "xju2f9n",
324-
padding: "x14odnwx",
325-
paddingInline: null,
326-
paddingStart: null,
327-
paddingLeft: null,
328-
paddingEnd: null,
329-
paddingRight: null,
330-
paddingBlock: null,
331-
paddingTop: null,
332-
paddingBottom: null,
322+
kWkggS: "xrkmrrc",
323+
kMwMTN: "xju2f9n",
324+
kmVPX3: "x14odnwx",
325+
kg3NbH: null,
326+
kuDDbn: null,
327+
kE3dHu: null,
328+
kP0aTx: null,
329+
kpe85a: null,
330+
k8WAf4: null,
331+
kLKAdn: null,
332+
kGO01o: null,
333333
$$css: true
334334
}
335335
};

packages/babel-plugin/__tests__/stylex-transform-keyframes-test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ describe('@stylexjs/babel-plugin', () => {
180180
_inject2(".x1vfi257{animation-name:x1jkcf39-B}", 3000);
181181
export const styles = {
182182
root: {
183-
animationName: "x1vfi257",
183+
kKVMdj: "x1vfi257",
184184
$$css: true
185185
}
186186
};"

packages/babel-plugin/__tests__/stylex-transform-legacy-shorthands-test.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ describe('Legacy-shorthand-expansion resolution', () => {
6060
_inject2(".x1t2a60a{padding-left:5px}", 3000, ".x1t2a60a{padding-right:5px}");
6161
export const styles = {
6262
foo: {
63-
paddingTop: "x123j3cw",
64-
paddingEnd: "x1mpkggp",
65-
paddingBottom: "xs9asl8",
66-
paddingStart: "x1t2a60a",
63+
kLKAdn: "x123j3cw",
64+
kP0aTx: "x1mpkggp",
65+
kGO01o: "xs9asl8",
66+
kuDDbn: "x1t2a60a",
6767
$$css: true
6868
}
6969
};
@@ -154,10 +154,10 @@ describe('Legacy-shorthand-expansion resolution', () => {
154154
_inject2(".x1mpkggp{padding-right:5px}", 3000, ".x1mpkggp{padding-left:5px}");
155155
export const styles = {
156156
foo: {
157-
paddingStart: "x1t2a60a",
158-
paddingEnd: "x1mpkggp",
159-
paddingLeft: null,
160-
paddingRight: null,
157+
kuDDbn: "x1t2a60a",
158+
kP0aTx: "x1mpkggp",
159+
kE3dHu: null,
160+
kpe85a: null,
161161
$$css: true
162162
}
163163
};

0 commit comments

Comments
 (0)