Skip to content

Commit 697f8cf

Browse files
judehuntermrmckeb
authored andcommitted
Support Sass indented syntax (mrmckeb#68)
1 parent 27184dd commit 697f8cf

File tree

5 files changed

+119
-1
lines changed

5 files changed

+119
-1
lines changed

src/helpers/__tests__/__snapshots__/getDtsSnapshot.test.ts.snap

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ export default classes;
1717

1818
exports[`utils / cssSnapshots with file 'empty.module.less' getClasses should return an object matching expected CSS 1`] = `Object {}`;
1919

20+
exports[`utils / cssSnapshots with file 'empty.module.sass' createExports should create an exports file 1`] = `
21+
"declare const classes: {
22+
23+
};
24+
export default classes;
25+
"
26+
`;
27+
28+
exports[`utils / cssSnapshots with file 'empty.module.sass' getClasses should return an object matching expected CSS 1`] = `Object {}`;
29+
2030
exports[`utils / cssSnapshots with file 'empty.module.scss' createExports should create an exports file 1`] = `
2131
"declare const classes: {
2232
@@ -159,6 +169,58 @@ Object {
159169
}
160170
`;
161171

172+
exports[`utils / cssSnapshots with file 'test.module.sass' createExports should create an exports file 1`] = `
173+
"declare const classes: {
174+
'local-class-inside-global': string;
175+
'local-class': string;
176+
'local-class-2': string;
177+
'local-class-inside-local': string;
178+
'reserved-words': string;
179+
'default': string;
180+
'const': string;
181+
'nested-class-parent': string;
182+
'child-class': string;
183+
'nested-class-parent--extended': string;
184+
'section-1': string;
185+
'section-2': string;
186+
'section-3': string;
187+
'section-4': string;
188+
'section-5': string;
189+
'section-6': string;
190+
'section-7': string;
191+
'section-8': string;
192+
'section-9': string;
193+
'class-with-mixin': string;
194+
};
195+
export default classes;
196+
"
197+
`;
198+
199+
exports[`utils / cssSnapshots with file 'test.module.sass' getClasses should return an object matching expected CSS 1`] = `
200+
Object {
201+
"child-class": "test-module__child-class---2vfhc",
202+
"class-with-mixin": "test-module__class-with-mixin---3zUq-",
203+
"const": "test-module__const---39o_j",
204+
"default": "test-module__default---h-tcC",
205+
"local-class": "test-module__local-class---1yStp",
206+
"local-class-2": "test-module__local-class-2---3xCgt",
207+
"local-class-inside-global": "test-module__local-class-inside-global---Mznd5",
208+
"local-class-inside-local": "test-module__local-class-inside-local---1z2Qf",
209+
"nested-class-parent": "test-module__nested-class-parent---3oyeq",
210+
"nested-class-parent--extended": "test-module__nested-class-parent--extended---cjRbg",
211+
"reserved-words": "test-module__reserved-words---3hGie",
212+
"section-1": "test-module__section-1---2QkaE",
213+
"section-2": "test-module__section-2---23KHs",
214+
"section-3": "test-module__section-3---2BttW",
215+
"section-4": "test-module__section-4---1TrSo",
216+
"section-5": "test-module__section-5---1PIYZ",
217+
"section-6": "test-module__section-6---tbEch",
218+
"section-7": "test-module__section-7---i7uWX",
219+
"section-8": "test-module__section-8---1jfNT",
220+
"section-9": "test-module__section-9---1akFT",
221+
}
222+
`;
223+
162224
exports[`utils / cssSnapshots with file 'test.module.scss' createExports should create an exports file 1`] = `
163225
"declare const classes: {
164226
'local-class-inside-global': string;

src/helpers/__tests__/fixtures/empty.module.sass

Whitespace-only changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
:global .global-class
2+
color: rebeccapurple
3+
4+
5+
:global(.global-class-2)
6+
.local-class-inside-global
7+
color: rebeccapurple
8+
9+
10+
11+
:local .local-class
12+
color: rebeccapurple
13+
14+
15+
:local(.local-class-2)
16+
.local-class-inside-local
17+
color: rebeccapurple
18+
19+
20+
21+
.reserved-words
22+
.default
23+
color: rebeccapurple
24+
25+
.const
26+
color: rebeccapurple
27+
28+
29+
.nested-class-parent
30+
.child-class
31+
color: rebeccapurple
32+
33+
&--extended
34+
color: rebeccapurple
35+
36+
37+
38+
$color: rebeccapurple !default
39+
40+
@for $section from 1 to 10
41+
.section-#{$section}
42+
color: $color
43+
44+
@import 'mixin'
45+
46+
.class-with-mixin
47+
@include set-margin(0)
48+
49+
// .commented-parent-class {
50+
// .commented-child-class
51+
// }

src/helpers/__tests__/getDtsSnapshot.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const testFileNames = [
1313
'test.module.css',
1414
'test.module.less',
1515
'test.module.scss',
16+
'test.module.sass',
1617
'empty.module.less',
18+
'empty.module.sass',
1719
'empty.module.scss',
1820
'import.module.css',
1921
'import.module.less',

src/helpers/getClasses.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import { Options, CustomRenderer } from '../options';
99
export const enum FileTypes {
1010
css = 'css',
1111
less = 'less',
12+
sass = 'sass',
1213
scss = 'scss',
1314
}
1415

1516
export const getFileType = (fileName: string) => {
1617
if (fileName.endsWith('.css')) return FileTypes.css;
1718
if (fileName.endsWith('.less')) return FileTypes.less;
19+
if (fileName.endsWith('.sass')) return FileTypes.sass;
1820
return FileTypes.scss;
1921
};
2022

@@ -50,13 +52,14 @@ export const getClasses = (
5052
transformedCss = output.css.toString();
5153
},
5254
);
53-
} else if (fileType === FileTypes.scss) {
55+
} else if (fileType === FileTypes.scss || fileType === FileTypes.sass) {
5456
const filePath = getFilePath(fileName);
5557
const { includePaths, ...sassOptions } = rendererOptions.sass || {};
5658

5759
transformedCss = sass
5860
.renderSync({
5961
data: css,
62+
indentedSyntax: fileType === FileTypes.sass,
6063
includePaths: [filePath, 'node_modules', ...(includePaths || [])],
6164
...sassOptions,
6265
})

0 commit comments

Comments
 (0)