Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed functions that are imported then re-exported causing a crash #28

Merged
merged 3 commits into from
Apr 10, 2024

Conversation

daniel-chambers
Copy link
Collaborator

This PR fixes a bug where if one was to re-export functions from another file like so:

import { fileBChildFunction1 } from "./file-b";

export { fileBChildFunction1 };

you would cause the type inference to crash. This PR fixes the type inference so it correctly handles this corner case by following the import symbol's alias to its source then getting its declaration.

@daniel-chambers daniel-chambers self-assigned this Apr 10, 2024
@daniel-chambers daniel-chambers changed the title Fixed functions that are imported then exported causing a crash Fixed functions that are imported then re-exported causing a crash Apr 10, 2024
@@ -7,6 +7,8 @@ This changelog documents the changes between release versions.
## [Unreleased]
Changes to be included in the next upcoming release

- Fixed functions that are imported then re-exported causing a crash [#28](https://github.com/hasura/ndc-nodejs-lambda/pull/28)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +178 to +181
const exportTargetDeclaration =
exportTarget.valueDeclaration // 'export { name } from "./imported"'
?? typeChecker.getAliasedSymbol(exportTarget).valueDeclaration // 'import { name } from "./imported"; export { name }'
?? throwError("export target symbol does not have a value declaration");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +1 to +8
import { fileAChildFunction as renamedFileAChildFunction } from "./file-a"
import { fileBChildFunction1, fileBChildFunction2 } from "./file-b"

export {
renamedFileAChildFunction,
fileBChildFunction1,
fileBChildFunction2 as renamedFileBChildFunction2
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -206,4 +206,65 @@ describe("re-exported functions", function() {
}
})
});

it("supports re-exports of functions from other files that are first imported then exported", function() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@daniel-chambers daniel-chambers merged commit b752aab into main Apr 10, 2024
6 checks passed
@daniel-chambers daniel-chambers deleted the daniel/fix-indirect-exports branch April 10, 2024 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants