-
Notifications
You must be signed in to change notification settings - Fork 860
Use export type syntax
#5554
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
Use export type syntax
#5554
Changes from all commits
90ebaf9
a7b6964
bce2ed9
4b850f7
2c009c1
3f9d72f
a3d1cf1
c50e1a6
a89a834
11188bf
176619f
196541e
3cbb6ab
da7c9fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,3 +12,4 @@ scripts | |
| generator-eui | ||
| cypress | ||
| react-datepicker | ||
| .eslintrc.js | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2515,162 +2515,5 @@ let something: any; | |
| expect(result.code).toBe('let something;'); | ||
| }); | ||
| }); | ||
|
|
||
| it('can be disabled', () => { | ||
| const configuredBabelOptions = JSON.parse(JSON.stringify(babelOptions)); | ||
| configuredBabelOptions.plugins[0] = ['./scripts/babel/proptypes-from-ts-props', { generatePropTypes: false }]; | ||
|
|
||
| const result = transform( | ||
| ` | ||
| import React from 'react'; | ||
| interface IFooProps {bar: string} | ||
| const FooComponent: React.SFC<IFooProps> = () => { | ||
| return (<div>Hello World</div>); | ||
| }`, | ||
| configuredBabelOptions | ||
| ); | ||
|
|
||
| expect(result.code).toBe(`import React from 'react'; | ||
| const FooComponent = () => { | ||
| return <div>Hello World</div>; | ||
| };`); | ||
| }); | ||
| }); | ||
|
|
||
| describe('remove types from exports', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is all handled by babel now outside of our custom plugin 🎉
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As it turns out, I'll also need these tests removed to upgrade Typescript to 4.5.x (it starts outputting |
||
| it('removes sole type export from ExportNamedDeclaration', () => { | ||
| const result = transform( | ||
| ` | ||
| type Foo = string; | ||
| export { Foo }; | ||
| `, | ||
| babelOptions | ||
| ); | ||
|
|
||
| expect(result.code).toBe(''); | ||
| }); | ||
|
|
||
| it('removes multiple type export from ExportNamedDeclaration', () => { | ||
| const result = transform( | ||
| ` | ||
| type Foo = string; | ||
| type Bar = number | Foo; | ||
| export { Foo, Bar }; | ||
| `, | ||
| babelOptions | ||
| ); | ||
|
|
||
| expect(result.code).toBe(''); | ||
| }); | ||
|
|
||
| it('removes type exports from ExportNamedDeclaration, leaving legitimate exports', () => { | ||
| const result = transform( | ||
| ` | ||
| type Foo = string; | ||
| type Bar = Foo | boolean; | ||
| const A = 500; | ||
| const B = { bar: A }; | ||
| export { Foo, A, Bar, B }; | ||
| `, | ||
| babelOptions | ||
| ); | ||
|
|
||
| expect(result.code).toBe(`const A = 500; | ||
| const B = { | ||
| bar: A | ||
| }; | ||
| export { A, B };`); | ||
| }); | ||
|
|
||
| it('removes type exports from ExportNamedDeclaration with a source', () => { | ||
| const result = transform( | ||
| ` | ||
| export { Foo, A } from './foo'; | ||
| `, | ||
| { | ||
| ...babelOptions, | ||
| plugins: [ | ||
| [ | ||
| './scripts/babel/proptypes-from-ts-props', | ||
| { | ||
| fs: { | ||
| existsSync: () => true, | ||
| statSync: () => ({ isDirectory: () => false }), | ||
| readFileSync: filepath => { | ||
| if (filepath.endsWith(`${path.sep}foo`)) { | ||
| return Buffer.from(` | ||
| export type Foo = string; | ||
| `); | ||
| } | ||
|
|
||
| throw new Error(`Test tried to import from ${filepath}`); | ||
| }, | ||
| }, | ||
| }, | ||
| ], | ||
| ], | ||
| } | ||
| ); | ||
|
|
||
| expect(result.code).toBe("export { A } from './foo';"); | ||
| }); | ||
|
|
||
| it('removes type exports from ExportNamedDeclaration when the imported name differs from the exported one', () => { | ||
| const result = transform( | ||
| ` | ||
| export { Foo as Bar, A as B } from './foo'; | ||
| `, | ||
| { | ||
| ...babelOptions, | ||
| plugins: [ | ||
| [ | ||
| './scripts/babel/proptypes-from-ts-props', | ||
| { | ||
| fs: { | ||
| existsSync: () => true, | ||
| statSync: () => ({ isDirectory: () => false }), | ||
| readFileSync: filepath => { | ||
| if (filepath.endsWith(`${path.sep}foo`)) { | ||
| return Buffer.from(` | ||
| export const A = 5; | ||
| export type Foo = string; | ||
| `); | ||
| } | ||
|
|
||
| throw new Error(`Test tried to import from ${filepath}`); | ||
| }, | ||
| }, | ||
| }, | ||
| ], | ||
| ], | ||
| } | ||
| ); | ||
|
|
||
| expect(result.code).toBe("export { A as B } from './foo';"); | ||
| }); | ||
|
|
||
| it('removes type export statements', () => { | ||
| const result = transform( | ||
| ` | ||
| export type Foo = string; | ||
| `, | ||
| babelOptions | ||
| ); | ||
|
|
||
| expect(result.code).toBe(''); | ||
| }); | ||
|
|
||
| it('removes 3rd-party type exports', () => { | ||
| const result = transform( | ||
| ` | ||
| export { DraggableLocation, Draggable, DragDropContextProps } from 'react-beautiful-dnd'; | ||
| `, | ||
| babelOptions | ||
| ); | ||
|
|
||
| expect(result.code).toBe( | ||
| "export { Draggable } from 'react-beautiful-dnd';" | ||
| ); | ||
| }); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.