Skip to content

Commit 7da334a

Browse files
Michael Gregoryskovy
authored andcommitted
fix: restore number camel-casing behavior changed in MR 161
1 parent 46f82a9 commit 7da334a

File tree

7 files changed

+44
-137
lines changed

7 files changed

+44
-137
lines changed

__tests__/__snapshots__/main.test.ts.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Array [
77
export const nestedAnother: string;
88
export const nestedClass: string;
99
export const nestedStyles: string;
10+
export const number1: string;
1011
export const someStyles: string;
1112
",
1213
"path": "../__generated__/__tests__/dummy-styles/alias-prefixes.scss.d.ts",
@@ -15,6 +16,7 @@ export const someStyles: string;
1516
"contents": "export const myCustomClass: string;
1617
export const nestedAnother: string;
1718
export const nestedClass: string;
19+
export const number1: string;
1820
export const someClass: string;
1921
export const someStyles: string;
2022
",
@@ -23,6 +25,7 @@ export const someStyles: string;
2325
Object {
2426
"contents": "export const nestedAnother: string;
2527
export const nestedClass: string;
28+
export const number1: string;
2629
export const someStyles: string;
2730
",
2831
"path": "../__generated__/__tests__/dummy-styles/complex.scss.d.ts",
@@ -70,6 +73,7 @@ Array [
7073
nestedAnother: string;
7174
nestedClass: string;
7275
nestedStyles: string;
76+
number1: string;
7377
someStyles: string;
7478
};
7579
@@ -86,6 +90,7 @@ export default styles;
8690
myCustomClass: string;
8791
nestedAnother: string;
8892
nestedClass: string;
93+
number1: string;
8994
someClass: string;
9095
someStyles: string;
9196
};
@@ -102,6 +107,7 @@ export default styles;
102107
"contents": "export type Styles = {
103108
nestedAnother: string;
104109
nestedClass: string;
110+
number1: string;
105111
someStyles: string;
106112
};
107113
@@ -203,6 +209,7 @@ Array [
203209
export const nestedAnother: string;
204210
export const nestedClass: string;
205211
export const nestedStyles: string;
212+
export const number1: string;
206213
export const someStyles: string;
207214
",
208215
"path": "../__generated__/__tests__/dummy-styles/alias-prefixes.scss.d.ts",
@@ -211,6 +218,7 @@ export const someStyles: string;
211218
"contents": "export const myCustomClass: string;
212219
export const nestedAnother: string;
213220
export const nestedClass: string;
221+
export const number1: string;
214222
export const someClass: string;
215223
export const someStyles: string;
216224
",
@@ -219,6 +227,7 @@ export const someStyles: string;
219227
Object {
220228
"contents": "export const nestedAnother: string;
221229
export const nestedClass: string;
230+
export const number1: string;
222231
export const someStyles: string;
223232
",
224233
"path": "../__generated__/__tests__/dummy-styles/complex.scss.d.ts",
@@ -266,6 +275,7 @@ Array [
266275
nestedAnother: string;
267276
nestedClass: string;
268277
nestedStyles: string;
278+
number1: string;
269279
someStyles: string;
270280
};
271281
@@ -282,6 +292,7 @@ export default styles;
282292
myCustomClass: string;
283293
nestedAnother: string;
284294
nestedClass: string;
295+
number1: string;
285296
someClass: string;
286297
someStyles: string;
287298
};
@@ -298,6 +309,7 @@ export default styles;
298309
"contents": "export type Styles = {
299310
nestedAnother: string;
300311
nestedClass: string;
312+
number1: string;
301313
someStyles: string;
302314
};
303315

__tests__/dummy-styles/complex.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
color: red;
33
}
44

5+
.number-1 {
6+
color: green;
7+
}
8+
59
.nested {
610
&-class {
711
background: green;

__tests__/main.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describeAllImplementations((implementation) => {
6060

6161
expect(fs.writeFileSync).toBeCalledWith(
6262
`${expectedDirname}/complex.scss.d.ts`,
63-
"export const nestedAnother: string;\nexport const nestedClass: string;\nexport const someStyles: string;\n"
63+
"export const nestedAnother: string;\nexport const nestedClass: string;\nexport const number1: string;\nexport const someStyles: string;\n"
6464
);
6565
expect(fs.writeFileSync).toBeCalledWith(
6666
`${expectedDirname}/style.scss.d.ts`,
@@ -101,7 +101,7 @@ describeAllImplementations((implementation) => {
101101

102102
expect(fs.writeFileSync).toBeCalledWith(
103103
`${expectedDirname}/complex.scss.d.ts`,
104-
"export const nestedAnother: string;\nexport const nestedClass: string;\nexport const someStyles: string;\n"
104+
"export const nestedAnother: string;\nexport const nestedClass: string;\nexport const number1: string;\nexport const someStyles: string;\n"
105105
);
106106

107107
// Files that should match the ignore pattern.

__tests__/sass/file-to-class-names.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ describeAllImplementations((implementation) => {
99
`${__dirname}/../dummy-styles/complex.scss`
1010
);
1111

12-
expect(result).toEqual(["nestedAnother", "nestedClass", "someStyles"]);
12+
expect(result).toEqual([
13+
"nestedAnother",
14+
"nestedClass",
15+
"number1",
16+
"someStyles",
17+
]);
1318
});
1419

1520
describe("nameFormat", () => {
@@ -25,6 +30,7 @@ describeAllImplementations((implementation) => {
2530
expect(result).toEqual([
2631
"nested-another",
2732
"nested-class",
33+
"number-1",
2834
"some-styles",
2935
]);
3036
});
@@ -41,6 +47,7 @@ describeAllImplementations((implementation) => {
4147
expect(result).toEqual([
4248
"nested-another",
4349
"nested-class",
50+
"number-1",
4451
"some-styles",
4552
]);
4653
});
@@ -57,6 +64,7 @@ describeAllImplementations((implementation) => {
5764
expect(result).toEqual([
5865
"nested_another",
5966
"nested_class",
67+
"number_1",
6068
"some_styles",
6169
]);
6270
});
@@ -101,6 +109,9 @@ describeAllImplementations((implementation) => {
101109
"nested-class",
102110
"nestedAnother",
103111
"nestedClass",
112+
"number_1",
113+
"number-1",
114+
"number1",
104115
"some_styles",
105116
"some-styles",
106117
"someStyles",
@@ -121,6 +132,8 @@ describeAllImplementations((implementation) => {
121132
"nested_class",
122133
"nested-another",
123134
"nested-class",
135+
"number_1",
136+
"number-1",
124137
"some_styles",
125138
"some-styles",
126139
]);
@@ -138,6 +151,7 @@ describeAllImplementations((implementation) => {
138151
expect(result).toEqual([
139152
"nested_another",
140153
"nested_class",
154+
"number_1",
141155
"some_styles",
142156
]);
143157
});
@@ -160,6 +174,7 @@ describeAllImplementations((implementation) => {
160174
"myCustomClass",
161175
"nestedAnother",
162176
"nestedClass",
177+
"number1",
163178
"someClass",
164179
"someStyles",
165180
]);
@@ -186,6 +201,7 @@ describeAllImplementations((implementation) => {
186201
"nestedAnother",
187202
"nestedClass",
188203
"nestedStyles",
204+
"number1",
189205
"someStyles",
190206
]);
191207
});

lib/sass/file-to-class-names.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from "fs";
2-
import { camelCase, paramCase, snakeCase } from "change-case";
2+
import { camelCase, kebabCase, snakeCase } from "case-anything";
33

44
import { sourceToClassNames } from "./source-to-class-names";
55
import { Implementations, getImplementation } from "../implementations";
@@ -17,7 +17,7 @@ const transformersMap = {
1717
/-/.test(className) ? camelCase(className) : className,
1818
kebab: (className: ClassName) => transformersMap.param(className),
1919
none: (className: ClassName) => className,
20-
param: (className: ClassName) => paramCase(className),
20+
param: (className: ClassName) => kebabCase(className),
2121
snake: (className: ClassName) => snakeCase(className),
2222
} as const;
2323

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@
8080
},
8181
"dependencies": {
8282
"bundle-require": "^3.0.4",
83+
"case-anything": "^2.1.10",
8384
"chalk": "4.1.2",
84-
"change-case": "^4.1.2",
8585
"chokidar": "^3.5.3",
8686
"css-modules-loader-core": "^1.1.0",
8787
"esbuild": "^0.14.21",

0 commit comments

Comments
 (0)