-
Notifications
You must be signed in to change notification settings - Fork 714
Port PR 61805 - module=node20 #1797
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ports TypeScript PR 61805 to address changes related to the module=node20
configuration, focusing on updates to module resolution behavior and module format handling in Node.js 20 environments.
Key changes include:
- Removal of legacy module resolution validation errors
- Updated module output formats for ESM vs CJS contexts
- Improved import assertion to import attributes error messaging
- Corrected module resolution strategy selection
Reviewed Changes
Copilot reviewed 300 out of 645 changed files in this pull request and generated no comments.
File | Description |
---|---|
Multiple baseline error files | Removed TS5109 errors requiring Node16 module resolution with Node20 module setting |
Multiple baseline JavaScript output files | Updated module compilation output to use proper ESM syntax instead of CommonJS when appropriate |
Import assertion baseline files | Changed error messages from import assertions to import attributes deprecation warnings |
Module resolution trace files | Updated to show Node16 resolution strategy instead of Bundler |
Hm, data race... |
I can't figure out how to deal with the circularity errors when compiling concurrently. These are the kinds of errors that we have been silencing by skipping the tests ( |
53306a6
to
38d667c
Compare
targetFile := core.Find(moduleSymbol.Declarations, ast.IsSourceFile) | ||
usageMode := c.getEmitSyntaxForModuleSpecifierExpression(reference) | ||
var exportModuleDotExportsSymbol *ast.Symbol | ||
if namespaceImport != nil && targetFile != nil && | ||
core.ModuleKindNode20 <= c.moduleKind && c.moduleKind <= core.ModuleKindNodeNext && | ||
usageMode == core.ModuleKindCommonJS && | ||
c.program.GetImpliedNodeFormatForEmit(targetFile.AsSourceFile()) == core.ModuleKindESNext { | ||
exportModuleDotExportsSymbol = c.getExportOfModule(symbol, ast.InternalSymbolNameModuleExports, namespaceImport, dontResolveAlias) | ||
} | ||
if exportModuleDotExportsSymbol != nil { | ||
if !suppressInteropError && symbol.Flags&(ast.SymbolFlagsModule|ast.SymbolFlagsVariable) == 0 { | ||
c.error(referencingLocation, diagnostics.This_module_can_only_be_referenced_with_ECMAScript_imports_Slashexports_by_turning_on_the_0_flag_and_referencing_its_default_export, "esModuleInterop") | ||
} | ||
if c.compilerOptions.GetESModuleInterop() && c.hasSignatures(typ) { | ||
return c.cloneTypeAsModuleType(exportModuleDotExportsSymbol, typ, referenceParent) | ||
} | ||
return exportModuleDotExportsSymbol | ||
} | ||
|
||
isEsmCjsRef := targetFile != nil && isESMFormatImportImportingCommonjsFormatFile(usageMode, c.program.GetImpliedNodeFormatForEmit(targetFile.AsSourceFile())) | ||
if c.compilerOptions.GetESModuleInterop() || isEsmCjsRef { | ||
if c.hasSignatures(typ) || c.getPropertyOfTypeEx(typ, ast.InternalSymbolNameDefault, true /*skipObjectFunctionPropertyAugment*/, false /*includeTypeOnlyMembers*/) != nil || isEsmCjsRef { | ||
var moduleType *Type | ||
if typ.Flags()&TypeFlagsStructuredType != 0 { | ||
moduleType = c.getTypeWithSyntheticDefaultImportType(typ, symbol, moduleSymbol, reference) | ||
} else { | ||
moduleType = c.createDefaultPropertyWrapperForModule(symbol, symbol.Parent, nil) | ||
} | ||
return c.cloneTypeAsModuleType(symbol, moduleType, referenceParent) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bit is the code that's causing the circularity. Perhaps that's why it was commented out originally?
The circularities are real. I believe what’s going on here is this: suppose you have a big circle of imports: a.ts → b.ts → c.ts → d.ts → e.ts → a.ts. In single-threaded mode, we always start with a.ts because of file order / source order, and we go off down the chain:
With this algorithm, the circle can be arbitrarily long, but we only ever report an error on the place where we start, which is semi-arbitrary but deterministic by file order, source order, etc. But if we divvy up all the files between multiple independent checkers, there’s a strong chance multiple of them will start resolving the chain in different places, resulting in the same error being reported in a different file. I’m not sure what we want to actually do about this.
|
That's what I thought, unfortunately. As a non-fix, should the tests be fixed to not use a circular reference? It seems like those which break aren't intentionally testing that behavior. |
Yeah, I think that would be fine for now. |
38d667c
to
d80e0e6
Compare
microsoft/TypeScript#62568 does that, and it indeed makes this PR pass tests when applied to the submodule. |
Ports microsoft/TypeScript#61805