Skip to content

Commit

Permalink
fix: exports object name
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Apr 4, 2020
1 parent d2b7d23 commit 8936f21
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions core/instrument/src/babel/extract-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export const traverseExports = (results: ExportTypes) => {
//check if it was a named export
if (!results.named[name]) {
const namedExport = extractExportVariable(declaration);

if (namedExport && namedExport.name) {
localExports[namedExport.name] = namedExport;
}
Expand Down Expand Up @@ -110,7 +111,8 @@ export const traverseExports = (results: ExportTypes) => {
node.left.object.name === 'exports'
) {
const exportedName = node.left.property.name;
const localName = node.right.name;

const localName = node.right.name || node.right.object?.name;
const namedExport = localExports[localName];
if (namedExport) {
namedExport.internalName = namedExport.name;
Expand Down Expand Up @@ -201,6 +203,6 @@ export const extractExports = (
};
const ast = parser.parse(source, parserOptions);

traverse(ast, traverseExports(results));
traverse(ast as any, traverseExports(results));
return results;
};
3 changes: 1 addition & 2 deletions core/instrument/src/babel/follow-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ export const followImports = (
return undefined;
}
const source = fileSource || fs.readFileSync(fileName, 'utf8');
const ast = initialAST || parser.parse(source, parserOptions);
const ast: any = initialAST || parser.parse(source, parserOptions);
const baseImportedName = importName.split('.')[0];

const exports: ExportTypes = {
named: {},
};
traverse(ast, traverseExports(exports));

const folderName = path.dirname(fileName);
const findExport =
baseImportedName === 'default' || baseImportedName === 'namespace'
Expand Down

0 comments on commit 8936f21

Please sign in to comment.