Skip to content

Commit 7556055

Browse files
yimingheegm0121
authored andcommitted
fix: fix as export
1 parent a02abff commit 7556055

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

spec/__snapshots__/integration.test.ts.snap

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ exports[`integration function named export definition should match snapshot 1`]
182182
import moduleTwo from 'moduleTwo';
183183
import myDefaultExport, { myNamedExport } from 'moduleThree/deep/file';
184184
import helpers from './local/helpers';
185-
import { helloNamedFunction } from './namedExportDefinition';
185+
import { helloNamedFunction, helloAsFunction } from './namedExportDefinition';
186186
187187
jest.mock('moduleOne');
188188
jest.mock('moduleTwo');
@@ -198,6 +198,16 @@ describe('helloNamedFunction', () => {
198198
// const retValue = helloNamedFunction(myArgOne,myArgTwo);
199199
expect(false).toBeTruthy();
200200
});
201+
});
202+
describe('helloAsFunction', () => {
203+
it('should expose a function', () => {
204+
expect(helloAsFunction).toBeDefined();
205+
});
206+
207+
it('helloAsFunction should return expected output', () => {
208+
// const retValue = helloAsFunction(myArgOne,myArgTwo);
209+
expect(false).toBeTruthy();
210+
});
201211
});"
202212
`;
203213

spec/fixtures/functions/namedExportDefinition.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ function helloNamedFunction(myArgOne, myArgTwo) {
88

99
};
1010

11-
export { helloNamedFunction };
11+
function helloAsNamedFunction(myArgOne, myArgTwo) {
12+
13+
};
14+
15+
export { helloNamedFunction, helloAsNamedFunction as helloAsFunction };

src/parse-source-file.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,23 +337,24 @@ export function parseSourceFile(file: ts.SourceFile): ParsedSourceFile {
337337
function exportDeclarationWalker(node: ts.ExportDeclaration){
338338
debug('exportDeclarationWalker', node.exportClause?.getFullText());
339339
node.exportClause && (node.exportClause as ts.NamedExports).elements.forEach(identifier => {
340-
const idName = identifier.name.escapedText;
340+
const asName = identifier.name.escapedText;
341+
const idName = identifier.propertyName?.escapedText || asName;
341342
debug('exportDeclarationWalker', idName);
342343
const foundClassByIdentifier = result.classes.find(klass => klass.name === idName);
343344
if(foundClassByIdentifier) {
344-
result.exportClass = foundClassByIdentifier;
345+
result.exportClass = { ...foundClassByIdentifier, name: asName };
345346
}
346347
const foundFunctionByIdentifier = result.functions.find(func => func.name === idName);
347348
if(foundFunctionByIdentifier){
348-
result.exportFunctions.push(foundFunctionByIdentifier);
349+
result.exportFunctions.push({ ...foundFunctionByIdentifier, name: asName });
349350
}
350351
const foundPojoByIdentifier = result.pojos.find(pojo => pojo.name === idName);
351352
if(foundPojoByIdentifier){
352-
result.exportPojos.push(foundPojoByIdentifier);
353+
result.exportPojos.push({ ...foundPojoByIdentifier, name: asName });
353354
}
354355
const foundComponentByIdentifier = result.components.find(component => component.name === idName);
355356
if(foundComponentByIdentifier){
356-
result.exportComponents.push(foundComponentByIdentifier);
357+
result.exportComponents.push({ ...foundComponentByIdentifier, name: asName });
357358
}
358359
});
359360
}

0 commit comments

Comments
 (0)