Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ export class ImportExportTranspiler implements TranspilerInterface {
}
});
const addExportCall = t.callExpression(t.identifier('addExport'), [t.objectExpression(<t.ObjectProperty[]>declarations)]);
if (path.get('declaration')) {
if ('declaration' in path.node && path.node.declaration) {
path.replaceWithMultiple([
// @todo fix without any
(<any>path.get('declaration')).node,
path.node.declaration,
t.callExpression(t.identifier('addExport'), [
t.objectExpression(
// @ts-ignore
Expand Down
38 changes: 38 additions & 0 deletions packages/cubejs-schema-compiler/test/unit/transpilers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { parse } from '@babel/parser';
import babelGenerator from '@babel/generator';
import babelTraverse from '@babel/traverse';

import { prepareCompiler } from './PrepareCompiler';
import { ImportExportTranspiler } from '../../src/compiler/transpilers';
import { ErrorReporter } from '../../src/compiler/ErrorReporter';

describe('Transpilers', () => {
it('CubeCheckDuplicatePropTranspiler', async () => {
Expand Down Expand Up @@ -43,4 +49,36 @@ describe('Transpilers', () => {

await compiler.compile();
});

it('ImportExportTranspiler', async () => {
const ieTranspiler = new ImportExportTranspiler();
const errorsReport = new ErrorReporter();
const code = `
export const helperFunction = () => 'hello'
export { helperFunction as alias }
export default helperFunction
`;
const ast = parse(
code,
{
sourceFilename: 'code.js',
sourceType: 'module',
plugins: ['objectRestSpread'],
},
);

babelTraverse(ast, ieTranspiler.traverseObject(errorsReport));
const content = babelGenerator(ast, {}, code).code;

expect(content).toEqual(`const helperFunction = () => 'hello';
addExport({
helperFunction: helperFunction
})
addExport({
alias: helperFunction
});
setExport(helperFunction);`);

errorsReport.throwIfAny(); // should not throw
});
});