Skip to content

change named export to default export #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/helpers/__tests__/__snapshots__/cssSnapshots.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`utils / cssSnapshots createExports should create an exports file 1`] = `
"
declare const classes: {
'classA': string;
'ClassB': string;
'class-c': string;
'parent': string;
'childA': string;
'childB': string;
'nestedChild': string;
};
export default classes;
"
`;

exports[`utils / cssSnapshots createExports should create an exports file 2`] = `
"
declare const classes: {
'local-class-inside-global': string;
'local-class': string;
'local-class-2': string;
'local-class-inside-local': string;
};
export default classes;
"
`;
10 changes: 2 additions & 8 deletions src/helpers/__tests__/cssSnapshots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,8 @@ describe('utils / cssSnapshots', () => {
it('should create an exports file', () => {
const exportsA = createExports(classesA);
const exportsB = createExports(classesB);
// tslint:disable max-line-length
expect(exportsA).toMatchInlineSnapshot(
`"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;"`,
);
expect(exportsB).toMatchInlineSnapshot(
`"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;"`,
);
// tslint:enable max-line-length
expect(exportsA).toMatchSnapshot();
expect(exportsB).toMatchSnapshot();
});
});
});
14 changes: 10 additions & 4 deletions src/helpers/cssSnapshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ const processor = postcss(postcssIcssSelectors({ mode: 'local' }));

export const getClasses = (css: string) =>
extractICSS(processor.process(css).root).icssExports;
export const createExports = (classes: IICSSExports) =>
Object.keys(classes)
.map((exportName) => `export const ${exportName}: string;`)
.join('');

const exportNameToProperty = (exportName: string) => `'${exportName}': string;`;
export const createExports = (classes: IICSSExports) => `
declare const classes: {
${Object.keys(classes)
.map(exportNameToProperty)
.join('\n ')}
};
export default classes;
`;

export const getDtsSnapshot = (
ts: typeof ts_module,
Expand Down