From 9d59cdfdc77f086c5307e15136815faa644541f7 Mon Sep 17 00:00:00 2001 From: Chandler Prall Date: Thu, 20 Jun 2019 13:47:55 -0600 Subject: [PATCH 1/2] Strip TS type exports even when they are being renamed --- .../babel/proptypes-from-ts-props/index.js | 8 ++--- .../proptypes-from-ts-props/index.test.js | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/scripts/babel/proptypes-from-ts-props/index.js b/scripts/babel/proptypes-from-ts-props/index.js index 6871a8f33ad..a9e699a549c 100644 --- a/scripts/babel/proptypes-from-ts-props/index.js +++ b/scripts/babel/proptypes-from-ts-props/index.js @@ -765,7 +765,7 @@ const typeDefinitionExtractors = { case 'ImportSpecifier': return specifier.imported.name; case 'ExportSpecifier': - return specifier.exported.name; + return specifier.local.name; // default: // throw new Error(`Unable to process import specifier type ${specifier.type}`); @@ -1103,9 +1103,9 @@ module.exports = function propTypesFromTypeScript({ types }) { const specifiers = path.get('specifiers'); specifiers.forEach(specifierPath => { if (types.isExportSpecifier(specifierPath)) { - const { node: { exported } } = specifierPath; - if (types.isIdentifier(exported)) { - const { name } = exported; + const { node: { local } } = specifierPath; + if (types.isIdentifier(local)) { + const { name } = local; const def = typeDefinitions[name]; if (isTSType(def)) { specifierPath.remove(); diff --git a/scripts/babel/proptypes-from-ts-props/index.test.js b/scripts/babel/proptypes-from-ts-props/index.test.js index 72215851ce1..c6b719c75bb 100644 --- a/scripts/babel/proptypes-from-ts-props/index.test.js +++ b/scripts/babel/proptypes-from-ts-props/index.test.js @@ -2441,6 +2441,40 @@ export { Foo, A } from './foo'; 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( ` From c22aad1ef4f0d6d99e3b9c58d63e8c4cc01ce750 Mon Sep 17 00:00:00 2001 From: Chandler Prall Date: Thu, 20 Jun 2019 13:55:29 -0600 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f0911e3c41..6d64d06d97b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Fixed `EuiInMemoryTable` to allow sorting on computed columns ([#2044](https://github.com/elastic/eui/pull/2044)) - Fixed TypeScript `Toast` member export ([#2052](https://github.com/elastic/eui/pull/2052)) - Fixed style of readOnly input groups via `EuiFormControlLayout` and `prepend`/`append` ([#2057](https://github.com/elastic/eui/pull/2057)) +- Removed TS types from ES exports when the exported name differs from the imported one ([#2069](https://github.com/elastic/eui/pull/2069)) ## [`12.0.0`](https://github.com/elastic/eui/tree/v12.0.0)