-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ts): cleanup output and use as const and type extraction
- Loading branch information
Showing
5 changed files
with
257 additions
and
387 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 1 addition & 132 deletions
133
src/generators/asset-types/__tests__/__snapshots__/ts.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`\`TS\` asset generator generates constant only 1`] = ` | ||
"export const MY_ICONS_SET_CODEPOINTS: Record<string, string> = { | ||
\\"foo\\": \\"4265\\", | ||
\\"bar\\": \\"1231\\", | ||
}; | ||
" | ||
`; | ||
|
||
exports[`\`TS\` asset generator generates constant with literalId if no enum generated 1`] = ` | ||
"export type MyIconsSetId = | ||
| \\"foo\\" | ||
| \\"bar\\"; | ||
export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSetId]: string } = { | ||
\\"foo\\": \\"4265\\", | ||
\\"bar\\": \\"1231\\", | ||
}; | ||
" | ||
`; | ||
|
||
exports[`\`TS\` asset generator generates constant with literalKey if no enum generated 1`] = ` | ||
"export type MyIconsSetKey = | ||
| \\"Foo\\" | ||
| \\"Bar\\"; | ||
export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSetKey]: string } = { | ||
\\"foo\\": \\"4265\\", | ||
\\"bar\\": \\"1231\\", | ||
}; | ||
" | ||
`; | ||
|
||
exports[`\`TS\` asset generator generates no key string literal type if option passed like that 1`] = ` | ||
"export enum MyIconsSet { | ||
Foo = \\"foo\\", | ||
Bar = \\"bar\\", | ||
} | ||
export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSet]: string } = { | ||
[MyIconsSet.Foo]: \\"4265\\", | ||
[MyIconsSet.Bar]: \\"1231\\", | ||
}; | ||
" | ||
`; | ||
|
||
exports[`\`TS\` asset generator generates single quotes if format option passed 1`] = ` | ||
"export type MyIconsSetId = | ||
| 'foo' | ||
| 'bar'; | ||
export type MyIconsSetKey = | ||
| 'Foo' | ||
| 'Bar'; | ||
export enum MyIconsSet { | ||
Foo = 'foo', | ||
Bar = 'bar', | ||
} | ||
export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSet]: string } = { | ||
[MyIconsSet.Foo]: '4265', | ||
[MyIconsSet.Bar]: '1231', | ||
}; | ||
" | ||
`; | ||
|
||
exports[`\`TS\` asset generator prevents enum keys that start with digits 1`] = ` | ||
"export type MyIconsSetId = | ||
| \\"1234\\" | ||
| \\"5678\\"; | ||
export type MyIconsSetKey = | ||
| \\"i1234\\" | ||
| \\"i5678\\"; | ||
export enum MyIconsSet { | ||
i1234 = \\"1234\\", | ||
i5678 = \\"5678\\", | ||
} | ||
export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSet]: string } = { | ||
[MyIconsSet.i1234]: \\"undefined\\", | ||
[MyIconsSet.i5678]: \\"undefined\\", | ||
}; | ||
" | ||
`; | ||
|
||
exports[`\`TS\` asset generator prevents enum keys that start with digits when digits and chars 1`] = ` | ||
"export type MyIconsSetId = | ||
| \\"1234asdf\\" | ||
| \\"5678ab\\" | ||
| \\"foo\\"; | ||
export type MyIconsSetKey = | ||
| \\"i1234asdf\\" | ||
| \\"i5678ab\\" | ||
| \\"Foo\\"; | ||
export enum MyIconsSet { | ||
i1234asdf = \\"1234asdf\\", | ||
i5678ab = \\"5678ab\\", | ||
Foo = \\"foo\\", | ||
} | ||
export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSet]: string } = { | ||
[MyIconsSet.i1234asdf]: \\"undefined\\", | ||
[MyIconsSet.i5678ab]: \\"undefined\\", | ||
[MyIconsSet.Foo]: \\"4265\\", | ||
}; | ||
" | ||
`; | ||
|
||
exports[`\`TS\` asset generator renders expected TypeScript module content 1`] = ` | ||
"export type MyIconsSetId = | ||
| \\"foo\\" | ||
| \\"bar\\"; | ||
export type MyIconsSetKey = | ||
| \\"Foo\\" | ||
| \\"Bar\\"; | ||
export enum MyIconsSet { | ||
Foo = \\"foo\\", | ||
Bar = \\"bar\\", | ||
} | ||
export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSet]: string } = { | ||
[MyIconsSet.Foo]: \\"4265\\", | ||
[MyIconsSet.Bar]: \\"1231\\", | ||
}; | ||
" | ||
`; | ||
exports[`\`TS\` asset generator renders expected TypeScript module content 1`] = `"export enum MyIconsSet { Foo = \\"foo\\", Bar = \\"bar\\", } export type MyIconsSetId = \`MyIconsSet\`; export const MY_ICONS_SET_CODEPOINTS: { [key in MyIconsSetId]: string } = { \\"foo\\": \\"4265\\", \\"bar\\": \\"1231\\", }; "`; |
Oops, something went wrong.