Skip to content

Commit

Permalink
fix: fix as export
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe authored and egm0121 committed Jan 13, 2023
1 parent a02abff commit 7556055
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
12 changes: 11 additions & 1 deletion spec/__snapshots__/integration.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ exports[`integration function named export definition should match snapshot 1`]
import moduleTwo from 'moduleTwo';
import myDefaultExport, { myNamedExport } from 'moduleThree/deep/file';
import helpers from './local/helpers';
import { helloNamedFunction } from './namedExportDefinition';
import { helloNamedFunction, helloAsFunction } from './namedExportDefinition';
jest.mock('moduleOne');
jest.mock('moduleTwo');
Expand All @@ -198,6 +198,16 @@ describe('helloNamedFunction', () => {
// const retValue = helloNamedFunction(myArgOne,myArgTwo);
expect(false).toBeTruthy();
});
});
describe('helloAsFunction', () => {
it('should expose a function', () => {
expect(helloAsFunction).toBeDefined();
});
it('helloAsFunction should return expected output', () => {
// const retValue = helloAsFunction(myArgOne,myArgTwo);
expect(false).toBeTruthy();
});
});"
`;
Expand Down
6 changes: 5 additions & 1 deletion spec/fixtures/functions/namedExportDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ function helloNamedFunction(myArgOne, myArgTwo) {

};

export { helloNamedFunction };
function helloAsNamedFunction(myArgOne, myArgTwo) {

};

export { helloNamedFunction, helloAsNamedFunction as helloAsFunction };
11 changes: 6 additions & 5 deletions src/parse-source-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,23 +337,24 @@ export function parseSourceFile(file: ts.SourceFile): ParsedSourceFile {
function exportDeclarationWalker(node: ts.ExportDeclaration){
debug('exportDeclarationWalker', node.exportClause?.getFullText());
node.exportClause && (node.exportClause as ts.NamedExports).elements.forEach(identifier => {
const idName = identifier.name.escapedText;
const asName = identifier.name.escapedText;
const idName = identifier.propertyName?.escapedText || asName;
debug('exportDeclarationWalker', idName);
const foundClassByIdentifier = result.classes.find(klass => klass.name === idName);
if(foundClassByIdentifier) {
result.exportClass = foundClassByIdentifier;
result.exportClass = { ...foundClassByIdentifier, name: asName };
}
const foundFunctionByIdentifier = result.functions.find(func => func.name === idName);
if(foundFunctionByIdentifier){
result.exportFunctions.push(foundFunctionByIdentifier);
result.exportFunctions.push({ ...foundFunctionByIdentifier, name: asName });
}
const foundPojoByIdentifier = result.pojos.find(pojo => pojo.name === idName);
if(foundPojoByIdentifier){
result.exportPojos.push(foundPojoByIdentifier);
result.exportPojos.push({ ...foundPojoByIdentifier, name: asName });
}
const foundComponentByIdentifier = result.components.find(component => component.name === idName);
if(foundComponentByIdentifier){
result.exportComponents.push(foundComponentByIdentifier);
result.exportComponents.push({ ...foundComponentByIdentifier, name: asName });
}
});
}
Expand Down

0 comments on commit 7556055

Please sign in to comment.