Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 13.7k
Set impliedNodeFormat based on redirectedReference options#60039
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
daad4205a97e076badddca01b64315a114f100f9398ba691a778b288632e498fd13d3b6951b0bc0afec156c9473e19fe205c07256545746180fd886ac24ab71325ee2File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Diff view
Diff view
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1419,12 +1419,9 @@ export function getImpliedNodeFormatForFileWorker( | ||
| host: ModuleResolutionHost, | ||
| options: CompilerOptions, | ||
| ): ResolutionMode | Partial<CreateSourceFileOptions> | undefined { | ||
| const moduleResolution = getEmitModuleResolutionKind(options); | ||
| const shouldLookupFromPackageJson = ModuleResolutionKind.Node16 <= moduleResolution && moduleResolution <= ModuleResolutionKind.NodeNext | ||
| || pathContainsNodeModules(fileName); | ||
| return fileExtensionIsOneOf(fileName, [Extension.Dmts, Extension.Mts, Extension.Mjs]) ? ModuleKind.ESNext : | ||
| fileExtensionIsOneOf(fileName, [Extension.Dcts, Extension.Cts, Extension.Cjs]) ? ModuleKind.CommonJS : | ||
| shouldLookupFromPackageJson && fileExtensionIsOneOf(fileName, [Extension.Dts, Extension.Ts, Extension.Tsx, Extension.Js, Extension.Jsx]) ? lookupFromPackageJson() : | ||
| fileExtensionIsOneOf(fileName, [Extension.Dts, Extension.Ts, Extension.Tsx, Extension.Js, Extension.Jsx]) ? lookupFromPackageJson() : | ||
| undefined; // other extensions, like `json` or `tsbuildinfo`, are set as `undefined` here but they should never be fed through the transformer pipeline | ||
| function lookupFromPackageJson(): Partial<CreateSourceFileOptions> { | ||
| @@ -3784,22 +3781,20 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg | ||
| } | ||
| let redirectedPath: Path | undefined; | ||
| if (!useSourceOfProjectReferenceRedirect) { | ||
| const redirectProject = getProjectReferenceRedirectProject(fileName); | ||
| if (redirectProject) { | ||
| if (redirectProject.commandLine.options.outFile) { | ||
| // Shouldnt create many to 1 mapping file in --out scenario | ||
| return undefined; | ||
| } | ||
| const redirect = getProjectReferenceOutputName(redirectProject, fileName); | ||
| fileName = redirect; | ||
| // Once we start redirecting to a file, we can potentially come back to it | ||
| // via a back-reference from another file in the .d.ts folder. If that happens we'll | ||
| // end up trying to add it to the program *again* because we were tracking it via its | ||
| // original (un-redirected) name. So we have to map both the original path and the redirected path | ||
| // to the source file we're about to find/create | ||
| redirectedPath = toPath(redirect); | ||
| const redirectProject = getProjectReferenceRedirectProject(fileName); | ||
| if (!useSourceOfProjectReferenceRedirect && redirectProject) { | ||
| if (redirectProject.commandLine.options.outFile) { | ||
| // Shouldnt create many to 1 mapping file in --out scenario | ||
| return undefined; | ||
| } | ||
| const redirect = getProjectReferenceOutputName(redirectProject, fileName); | ||
| fileName = redirect; | ||
| // Once we start redirecting to a file, we can potentially come back to it | ||
| // via a back-reference from another file in the .d.ts folder. If that happens we'll | ||
| // end up trying to add it to the program *again* because we were tracking it via its | ||
| // original (un-redirected) name. So we have to map both the original path and the redirected path | ||
| // to the source file we're about to find/create | ||
| redirectedPath = toPath(redirect); | ||
| } | ||
| // We haven't looked for this file, do so now and cache result | ||
| @@ -5211,24 +5206,13 @@ export function getEmitModuleFormatOfFileWorker(sourceFile: Pick<SourceFile, "fi | ||
| /** @internal Prefer `program.getImpliedNodeFormatForEmit` when possible. */ | ||
| export function getImpliedNodeFormatForEmitWorker(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode { | ||
| const moduleKind = getEmitModuleKind(options); | ||
| if (ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext) { | ||
| return sourceFile.impliedNodeFormat; | ||
| } | ||
| if ( | ||
| sourceFile.impliedNodeFormat === ModuleKind.CommonJS | ||
| && (sourceFile.packageJsonScope?.contents.packageJsonContent.type === "commonjs" | ||
| || fileExtensionIsOneOf(sourceFile.fileName, [Extension.Cjs, Extension.Cts])) | ||
| ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext | ||
| || fileExtensionIsOneOf(sourceFile.fileName, [Extension.Cts, Extension.Dcts, Extension.Cjs, Extension.Mts, Extension.Dmts, Extension.Mjs]) | ||
| || pathContainsNodeModules(sourceFile.fileName) | ||
sheetalkamat marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page.
This comment was marked as duplicate.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| ) { | ||
| return ModuleKind.CommonJS; | ||
| } | ||
| if ( | ||
| sourceFile.impliedNodeFormat === ModuleKind.ESNext | ||
| && (sourceFile.packageJsonScope?.contents.packageJsonContent.type === "module" | ||
| || fileExtensionIsOneOf(sourceFile.fileName, [Extension.Mjs, Extension.Mts])) | ||
| ) { | ||
| return ModuleKind.ESNext; | ||
| return sourceFile.impliedNodeFormat; | ||
| } | ||
| return undefined; | ||
| } | ||
| /** @internal Prefer `program.getDefaultResolutionModeForFile` when possible. */ | ||
| export function getDefaultResolutionModeForFileWorker(sourceFile: Pick<SourceFile, "fileName" | "impliedNodeFormat" | "packageJsonScope">, options: CompilerOptions): ResolutionMode { | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.