|
| 1 | +import { parse } from '@babel/parser'; |
| 2 | +import babelGenerator from '@babel/generator'; |
| 3 | +import babelTraverse from '@babel/traverse'; |
| 4 | + |
1 | 5 | import { prepareCompiler } from './PrepareCompiler'; |
| 6 | +import { ImportExportTranspiler } from '../../src/compiler/transpilers'; |
| 7 | +import { ErrorReporter } from '../../src/compiler/ErrorReporter'; |
2 | 8 |
|
3 | 9 | describe('Transpilers', () => { |
4 | 10 | it('CubeCheckDuplicatePropTranspiler', async () => { |
@@ -43,4 +49,36 @@ describe('Transpilers', () => { |
43 | 49 |
|
44 | 50 | await compiler.compile(); |
45 | 51 | }); |
| 52 | + |
| 53 | + it('ImportExportTranspiler', async () => { |
| 54 | + const ieTranspiler = new ImportExportTranspiler(); |
| 55 | + const errorsReport = new ErrorReporter(); |
| 56 | + const code = ` |
| 57 | + export const helperFunction = () => 'hello' |
| 58 | + export { helperFunction as alias } |
| 59 | + export default helperFunction |
| 60 | + `; |
| 61 | + const ast = parse( |
| 62 | + code, |
| 63 | + { |
| 64 | + sourceFilename: 'code.js', |
| 65 | + sourceType: 'module', |
| 66 | + plugins: ['objectRestSpread'], |
| 67 | + }, |
| 68 | + ); |
| 69 | + |
| 70 | + babelTraverse(ast, ieTranspiler.traverseObject(errorsReport)); |
| 71 | + const content = babelGenerator(ast, {}, code).code; |
| 72 | + |
| 73 | + expect(content).toEqual(`const helperFunction = () => 'hello'; |
| 74 | +addExport({ |
| 75 | + helperFunction: helperFunction |
| 76 | +}) |
| 77 | +addExport({ |
| 78 | + alias: helperFunction |
| 79 | +}); |
| 80 | +setExport(helperFunction);`); |
| 81 | + |
| 82 | + errorsReport.throwIfAny(); // should not throw |
| 83 | + }); |
46 | 84 | }); |
0 commit comments