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

Expose import mode calculation functions #49360

Merged

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Jun 2, 2022

Fixes #49340

getModeForUsageLocation should be the preferred function, however you may need to resort to getModeForResolutionAtIndex in some implementations of resolveModuleNames (though it's potentially unable to handle partial name lists).

@typescript-bot typescript-bot added Author: Team For Milestone Bug labels Jun 2, 2022
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jun 2, 2022

@iclanton given changes at microsoft/rushstack#3434, you might want to move that out from TypeScriptInternals once this lands.

* If you have an actual import node, prefer using getModeForUsageLocation on the reference string node.
* @param file File to fetch the resolution mode within
* @param index Index into the file's complete resolution list to get the resolution of - this is a concatenation of the file's imports and module augmentations
*/
export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number) {
Copy link
Member

@DanielRosenwasser DanielRosenwasser Jun 2, 2022

Choose a reason for hiding this comment

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

Idea:

Suggested change
export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number) {
export function getModeForResolutionAtIndex(file: SourceFile, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined;
/** @internal */
export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined;
export function getModeForResolutionAtIndex(file: SourceFileImportsList, index: number): ModuleKind.CommonJS | ModuleKind.ESNext | undefined {

Then you don't have to expose SourceFileImportsList

Copy link
Member

@DanielRosenwasser DanielRosenwasser Jun 3, 2022

Choose a reason for hiding this comment

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

I've pushed the changes since I think we should get this into 4.7.3.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jun 3, 2022

@typescript-bot cherry-pick this to release-4.7

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 3, 2022

Heya @DanielRosenwasser, I've started to run the task to cherry-pick this into release-4.7 on this PR at 4e40185. You can monitor the build here.

typescript-bot pushed a commit to typescript-bot/TypeScript that referenced this issue Jun 3, 2022
Component commits:
5eb6425 Expose import mode calculation functions

1f907ae Make `SourceFileImportsList` internal again.

4e40185 Accepted API baselines.
@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 3, 2022

Hey @DanielRosenwasser, I've opened #49370 for you.

DanielRosenwasser added a commit that referenced this issue Jun 3, 2022
…e-4.7 (#49370)

* Cherry-pick PR #49360 into release-4.7

Component commits:
5eb6425 Expose import mode calculation functions

1f907ae Make `SourceFileImportsList` internal again.

4e40185 Accepted API baselines.

* Fix lints.

Co-authored-by: Daniel Rosenwasser <drosen@microsoft.com>
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
@DanielRosenwasser DanielRosenwasser merged commit 3ccbe80 into microsoft:main Jun 3, 2022
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug
Projects
None yet
3 participants