Skip to content

Commit 2c9ba27

Browse files
xiaoxiangmoemrmckeb
authored andcommitted
Change named exports to default export (#2)
1 parent 25a1ed4 commit 2c9ba27

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`utils / cssSnapshots createExports should create an exports file 1`] = `
4+
"
5+
declare const classes: {
6+
'classA': string;
7+
'ClassB': string;
8+
'class-c': string;
9+
'parent': string;
10+
'childA': string;
11+
'childB': string;
12+
'nestedChild': string;
13+
};
14+
export default classes;
15+
"
16+
`;
17+
18+
exports[`utils / cssSnapshots createExports should create an exports file 2`] = `
19+
"
20+
declare const classes: {
21+
'local-class-inside-global': string;
22+
'local-class': string;
23+
'local-class-2': string;
24+
'local-class-inside-local': string;
25+
};
26+
export default classes;
27+
"
28+
`;

src/helpers/__tests__/cssSnapshots.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,8 @@ describe('utils / cssSnapshots', () => {
4444
it('should create an exports file', () => {
4545
const exportsA = createExports(classesA);
4646
const exportsB = createExports(classesB);
47-
// tslint:disable max-line-length
48-
expect(exportsA).toMatchInlineSnapshot(
49-
`"export const classA: string;export const ClassB: string;export const class-c: string;export const parent: string;export const childA: string;export const childB: string;export const nestedChild: string;"`,
50-
);
51-
expect(exportsB).toMatchInlineSnapshot(
52-
`"export const local-class-inside-global: string;export const local-class: string;export const local-class-2: string;export const local-class-inside-local: string;"`,
53-
);
54-
// tslint:enable max-line-length
47+
expect(exportsA).toMatchSnapshot();
48+
expect(exportsB).toMatchSnapshot();
5549
});
5650
});
5751
});

src/helpers/cssSnapshots.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ const processor = postcss(postcssIcssSelectors({ mode: 'local' }));
77

88
export const getClasses = (css: string) =>
99
extractICSS(processor.process(css).root).icssExports;
10-
export const createExports = (classes: IICSSExports) =>
11-
Object.keys(classes)
12-
.map((exportName) => `export const ${exportName}: string;`)
13-
.join('');
10+
11+
const exportNameToProperty = (exportName: string) => `'${exportName}': string;`;
12+
export const createExports = (classes: IICSSExports) => `
13+
declare const classes: {
14+
${Object.keys(classes)
15+
.map(exportNameToProperty)
16+
.join('\n ')}
17+
};
18+
export default classes;
19+
`;
1420

1521
export const getDtsSnapshot = (
1622
ts: typeof ts_module,

0 commit comments

Comments
 (0)