Skip to content

Improve CommonJS support, round 2#2946

Merged
ahejlsberg merged 13 commits intomainfrom
cjs-exports-merging
Mar 4, 2026
Merged

Improve CommonJS support, round 2#2946
ahejlsberg merged 13 commits intomainfrom
cjs-exports-merging

Conversation

@ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Mar 2, 2026

With this PR, in a CommonJS module with an export assignment (export = in TS or module.exports = in JS) we now overlay type and uninstantiated namespace declarations in the module onto the namespace of the exported entity. An export assignment is in error if (a) the module exports value members or (b) if the module exports type or namespace members and the exported entity also exports type or namespace members.

With these changes, the following is now permitted:

// File mod.ts
export type Foo = number[];  // This declaration is overlayed onto the namespace of the `export =`
export = { greeting: "hello" };

// File main.ts
import mod = require("./mod");
const greeting = mod.greeting;
const x: mod.Foo = [1, 2, 3];

This PR furthermore aligns Corsa more closely with Strada as follows:

  • Permit multiple module.exports assignments in a file and union the assigned types.
  • Exclude module.exports assignments from stricter checking of TypeScript export = declarations.

This PR supersedes #2893.

Copy link
Contributor

Copilot AI left a 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 expands CommonJS export = / module.exports support by merging type/namespace-only exports into the export-assignment namespace, relaxing/aligning some restrictions, and updating tests/baselines to reflect the new behavior.

Changes:

  • Add new compiler tests covering export-assignment merging in .ts and @checkJs .js scenarios.
  • Update many conformance/compiler baselines to reflect relaxed module.exports handling (e.g., removing prior TS1203 errors and updating symbol/type displays).
  • Add/update baselines for multiple module.exports assignments and export-assignment namespace merging.

Reviewed changes

Copilot reviewed 300 out of 302 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
testdata/tests/cases/compiler/exportAssignmentMerging1.ts New test covering type/namespace merging with export =
testdata/tests/cases/compiler/exportAssignmentMerging2.ts New test covering merging with exported uninstantiated namespace assigned via export =
testdata/tests/cases/compiler/exportAssignmentMerging3.ts New negative test for conflicting type members when merging into exported namespace
testdata/tests/cases/compiler/exportAssignmentMerging4.ts New negative test for value exports alongside export =
testdata/tests/cases/compiler/exportAssignmentMerging5.ts New @checkJs test for typedef merging into module.exports
testdata/baselines/reference/submodule/conformance/typedefCrossModule4.errors.txt.diff Baseline update reflecting changed export-assignment error reporting
testdata/baselines/reference/submodule/conformance/typedefCrossModule4.errors.txt Baseline removal/update reflecting changed export-assignment errors
testdata/baselines/reference/submodule/conformance/typedefCrossModule3.types.diff Baseline update for module symbol/type display ("export=")
testdata/baselines/reference/submodule/conformance/typedefCrossModule3.types Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/typedefCrossModule3.symbols.diff Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/typedefCrossModule3.symbols Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/typedefCrossModule3.errors.txt.diff Baseline update removing TS1203 export-assignment errors
testdata/baselines/reference/submodule/conformance/typedefCrossModule3.errors.txt Baseline removal/update removing TS1203 export-assignment errors
testdata/baselines/reference/submodule/conformance/typedefCrossModule.types.diff Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/typedefCrossModule.types Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/typedefCrossModule.symbols.diff Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/typedefCrossModule.symbols Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/typedefCrossModule.errors.txt.diff Baseline update removing TS1203 export-assignment errors
testdata/baselines/reference/submodule/conformance/typedefCrossModule.errors.txt Baseline update removing TS1203 export-assignment errors
testdata/baselines/reference/submodule/conformance/typeTagModuleExports.errors.txt.diff Baseline update for export-assignment error set
testdata/baselines/reference/submodule/conformance/typeTagModuleExports.errors.txt Baseline update for export-assignment error set
testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment17.errors.txt.diff Baseline update for export-assignment error set
testdata/baselines/reference/submodule/conformance/typeFromPropertyAssignment17.errors.txt Baseline update for export-assignment error set
testdata/baselines/reference/submodule/conformance/requireTwoPropertyAccesses.errors.txt.diff Baseline update for export-assignment error set
testdata/baselines/reference/submodule/conformance/requireTwoPropertyAccesses.errors.txt Baseline update for export-assignment error set
testdata/baselines/reference/submodule/conformance/paramTagTypeResolution.errors.txt.diff Baseline update for export-assignment error set
testdata/baselines/reference/submodule/conformance/paramTagTypeResolution.errors.txt Baseline update for export-assignment error set
testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsExportAssignment(module=nodenext).errors.txt Baseline update removing TS1203 in file.js path
testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsExportAssignment(module=node20).errors.txt Baseline update removing TS1203 in file.js path
testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsExportAssignment(module=node18).errors.txt Baseline update removing TS1203 in file.js path
testdata/baselines/reference/submodule/conformance/nodeModulesAllowJsExportAssignment(module=node16).errors.txt Baseline update removing TS1203 in file.js path
testdata/baselines/reference/submodule/conformance/moduleExportWithExportPropertyAssignment4.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportWithExportPropertyAssignment2.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportWithExportPropertyAssignment2.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportWithExportPropertyAssignment.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportWithExportPropertyAssignment.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportPropertyAssignmentDefault.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportPropertyAssignmentDefault.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAssignment7.errors.txt.diff Baseline update removing TS1203 in mod.js
testdata/baselines/reference/submodule/conformance/moduleExportAssignment7.errors.txt Baseline update removing TS1203 in mod.js
testdata/baselines/reference/submodule/conformance/moduleExportAssignment5.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAssignment5.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAssignment4.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAssignment4.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAssignment3.errors.txt.diff Baseline update removing TS1203-only failure
testdata/baselines/reference/submodule/conformance/moduleExportAssignment3.errors.txt Baseline update removing TS1203-only failure
testdata/baselines/reference/submodule/conformance/moduleExportAliasUnknown.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAliasUnknown.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAliasImported.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAliasImported.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAliasExports.errors.txt.diff Baseline update removing TS1231 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAliasExports.errors.txt Baseline update removing TS1231 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAlias4.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAlias4.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/moduleExportAlias3.errors.txt.diff Baseline update removing TS1203-only failure
testdata/baselines/reference/submodule/conformance/moduleExportAlias3.errors.txt Baseline update removing TS1203-only failure
testdata/baselines/reference/submodule/conformance/jsdocTypeReferenceToImportOfFunctionExpression.types.diff Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsdocTypeReferenceToImportOfFunctionExpression.types Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsdocTypeReferenceToImportOfFunctionExpression.symbols.diff Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsdocTypeReferenceToImportOfFunctionExpression.symbols Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsdocTypeReferenceToImportOfClassExpression.types.diff Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsdocTypeReferenceToImportOfClassExpression.types Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsdocTypeReferenceToImportOfClassExpression.symbols.diff Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsdocTypeReferenceToImportOfClassExpression.symbols Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsdocTypeReferenceToImportOfClassExpression.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsdocTypeReferenceToImportOfClassExpression.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsdocTypeReferenceExports.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsdocTypeReferenceExports.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsdocImportType2.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsdocImportType2.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsdocImportType.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsdocImportType.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefPropertyAndExportAssignment.types.diff Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefPropertyAndExportAssignment.types Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefPropertyAndExportAssignment.symbols.diff Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefPropertyAndExportAssignment.symbols Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefPropertyAndExportAssignment.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndLatebound.types.diff Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndLatebound.types Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndLatebound.symbols.diff Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndLatebound.symbols Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndLatebound.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndLatebound.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndImportTypes.types.diff Baseline update for module type display and import typedef resolution
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndImportTypes.types Baseline update for module type display and import typedef resolution
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndImportTypes.symbols.diff Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndImportTypes.symbols Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndImportTypes.js.diff Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndImportTypes.js Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypedefAndImportTypes.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReferences(target=es2015).js.diff Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReferences(target=es2015).js Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReferences(target=es2015).errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReferences(target=es2015).errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReassignmentFromDeclaration2.js.diff Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReassignmentFromDeclaration2.js Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReassignmentFromDeclaration2.errors.txt.diff Baseline update (error output removed)
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReassignmentFromDeclaration2.errors.txt Baseline update (error output removed)
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReassignmentFromDeclaration.js.diff Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReassignmentFromDeclaration.js Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReassignmentFromDeclaration.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsTypeReassignmentFromDeclaration.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsReexportedCjsAlias(target=es2015).errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js.diff Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.js Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit2.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsPackageJson(target=es2015).js Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsPackageJson(target=es2015).errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).js.diff Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).js Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsJson(target=es2015).errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsImportAliasExposedWithinNamespace.errors.txt Baseline update removing TS18042 error line
testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionWithDefaultAssignedMember.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic(target=es2015).types.diff Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic(target=es2015).types Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic(target=es2015).symbols.diff Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic(target=es2015).symbols Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic(target=es2015).errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionPrototypeStatic(target=es2015).errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment(target=es2015).types.diff Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment(target=es2015).types Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment(target=es2015).symbols.diff Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsDeclarationsFunctionClassesCjsExportAssignment(target=es2015).symbols Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportedClassAliases.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportedClassAliases.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportSubAssignments(target=es2015).errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportSubAssignments(target=es2015).errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignmentWithKeywordName(target=es2015).errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignmentWithKeywordName(target=es2015).errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignmentExpressionPlusSecondary(target=es2015).errors.txt Baseline update removing TS1203 and adjusting caret output
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedVisibility(target=es2015).js.diff Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedVisibility(target=es2015).js Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedVisibility(target=es2015).errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedVisibility(target=es2015).errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance3(target=es2015).errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance3(target=es2015).errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance2(target=es2015).errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance2(target=es2015).errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance1(target=es2015).errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassInstance1(target=es2015).errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionShadowing(target=es2015).errors.txt.diff Baseline update removing TS1203 and adjusting caret output
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionShadowing(target=es2015).errors.txt Baseline update removing TS1203 and adjusting caret output
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionAnonymousWithSub(target=es2015).errors.txt Baseline update removing TS1203 and adjusting caret output
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionAnonymous(target=es2015).errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpressionAnonymous(target=es2015).errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpression(target=es2015).errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsExportAssignedClassExpression(target=es2015).errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsDocCommentsOnConsts(target=es2015).errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsDocCommentsOnConsts(target=es2015).errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic(target=es2015).types.diff Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic(target=es2015).types Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic(target=es2015).symbols.diff Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic(target=es2015).symbols Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic(target=es2015).errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsDeclarationsClassStatic(target=es2015).errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/jsDeclarationsClassExtendsVisibility(target=es2015).errors.txt Baseline update removing TS1203 in bar.js and adjusting counts
testdata/baselines/reference/submodule/conformance/importAliasModuleExports.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/importAliasModuleExports.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/globalMergeWithCommonJSAssignmentDeclaration.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/globalMergeWithCommonJSAssignmentDeclaration.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/enumTagOnExports2.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/enumTagOnExports2.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/contextualTypedSpecialAssignment.errors.txt.diff Baseline update removing TS1203 and adjusting caret output
testdata/baselines/reference/submodule/conformance/contextualTypedSpecialAssignment.errors.txt Baseline update removing TS1203 and adjusting caret output
testdata/baselines/reference/submodule/conformance/conflictingCommonJSES2015Exports.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/conflictingCommonJSES2015Exports.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/commonJSReexport.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/commonJSReexport.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/commonJSAliasedExport.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/commonJSAliasedExport.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/callbackCrossModule.types.diff Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/callbackCrossModule.types Baseline update for module type display ("export=")
testdata/baselines/reference/submodule/conformance/callbackCrossModule.symbols.diff Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/callbackCrossModule.symbols Baseline update for symbol binding locations
testdata/baselines/reference/submodule/conformance/callbackCrossModule.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/callbackCrossModule.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/conformance/binderUninitializedModuleExportsAssignment.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/conformance/binderUninitializedModuleExportsAssignment.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/compiler/truthinessCallExpressionCoercion4.errors.txt.diff Baseline update removing TS1231 nested export-assignment error
testdata/baselines/reference/submodule/compiler/truthinessCallExpressionCoercion4.errors.txt Baseline update removing TS1231 nested export-assignment error
testdata/baselines/reference/submodule/compiler/requireOfJsonFileInJsFile.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/compiler/requireOfJsonFileInJsFile.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/compiler/pushTypeGetTypeOfAlias.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/compiler/pushTypeGetTypeOfAlias.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.types.diff Baseline update for symbol self-references in type printing
testdata/baselines/reference/submodule/compiler/moduleExportsTypeNoExcessPropertyCheckFromContainedLiteral.types Baseline update for symbol self-references in type printing
testdata/baselines/reference/submodule/compiler/jsExportMemberMergedWithModuleAugmentation3.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/compiler/jsExportMemberMergedWithModuleAugmentation3.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/compiler/jsExportMemberMergedWithModuleAugmentation2.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/compiler/jsExportMemberMergedWithModuleAugmentation2.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/compiler/jsExportMemberMergedWithModuleAugmentation.errors.txt.diff Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/compiler/jsExportMemberMergedWithModuleAugmentation.errors.txt Baseline update removing TS1203 and adjusting error counts
testdata/baselines/reference/submodule/compiler/jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/compiler/jsDeclarationEmitExportAssignedFunctionWithExtraTypedefsMembers.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/compiler/jsDeclarationEmitExportAssignedArray.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/compiler/jsDeclarationEmitExportAssignedArray.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/compiler/javascriptImportDefaultBadExport.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/compiler/javascriptImportDefaultBadExport.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/compiler/incompatibleExports2.errors.txt.diff Baseline update (now empty)
testdata/baselines/reference/submodule/compiler/incompatibleExports2.errors.txt Baseline update (removed)
testdata/baselines/reference/submodule/compiler/incompatibleExports1.types.diff Baseline update for namespace type display
testdata/baselines/reference/submodule/compiler/incompatibleExports1.types Baseline update for namespace type display
testdata/baselines/reference/submodule/compiler/incompatibleExports1.errors.txt.diff Baseline update removing one TS2309 instance
testdata/baselines/reference/submodule/compiler/incompatibleExports1.errors.txt Baseline update removing one TS2309 instance
testdata/baselines/reference/submodule/compiler/importNonExportedMember12.errors.txt.diff Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/compiler/importNonExportedMember12.errors.txt Baseline update removing TS1203-only failures
testdata/baselines/reference/submodule/compiler/importDeclWithExportModifierAndExportAssignmentInAmbientContext.errors.txt.diff Baseline update (now empty)
testdata/baselines/reference/submodule/compiler/importDeclWithExportModifierAndExportAssignmentInAmbientContext.errors.txt Baseline update (removed)
testdata/baselines/reference/submodule/compiler/importDeclWithExportModifierAndExportAssignment.errors.txt.diff Baseline update removing TS2309 instance
testdata/baselines/reference/submodule/compiler/importDeclWithExportModifierAndExportAssignment.errors.txt Baseline update removing TS2309 instance
testdata/baselines/reference/submodule/compiler/amdLikeInputDeclarationEmit.errors.txt.diff Baseline update removing TS1231-only failure
testdata/baselines/reference/submodule/compiler/amdLikeInputDeclarationEmit.errors.txt Baseline update removing TS1231-only failure
testdata/baselines/reference/conformance/typedefModuleExportsIndirect3.types Baseline update for module type display ("export=")
testdata/baselines/reference/conformance/typedefModuleExportsIndirect3.symbols Baseline update for symbol binding locations
testdata/baselines/reference/conformance/typedefModuleExportsIndirect3.js Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/conformance/typedefModuleExportsIndirect3.errors.txt Baseline update removing TS1203-only failure
testdata/baselines/reference/conformance/typedefModuleExportsIndirect2.types Baseline update for module type display ("export=")
testdata/baselines/reference/conformance/typedefModuleExportsIndirect2.symbols Baseline update for symbol binding locations
testdata/baselines/reference/conformance/typedefModuleExportsIndirect2.js Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/conformance/typedefModuleExportsIndirect2.errors.txt Baseline update removing TS1203-only failure
testdata/baselines/reference/conformance/typedefModuleExportsIndirect1.types Baseline update for module type display ("export=")
testdata/baselines/reference/conformance/typedefModuleExportsIndirect1.symbols Baseline update for symbol binding locations
testdata/baselines/reference/conformance/typedefModuleExportsIndirect1.js Baseline update (now includes DtsFileErrors segment)
testdata/baselines/reference/conformance/typedefModuleExportsIndirect1.errors.txt Baseline update removing TS1203-only failure
testdata/baselines/reference/compiler/nestedJSDocImportType.errors.txt Baseline update removing TS1203 and adjusting caret output
testdata/baselines/reference/compiler/multipleModuleExportsAssignments.js New baseline for multiple module.exports assignments
testdata/baselines/reference/compiler/exportAssignmentMerging6.js New baseline output for JS export-assignment merging with value export error
testdata/baselines/reference/compiler/exportAssignmentMerging6.errors.txt New baseline error output for export-assignment + value export conflict
testdata/baselines/reference/compiler/exportAssignmentMerging5.types New baseline types output for @checkJs typedef merge with module.exports
testdata/baselines/reference/compiler/exportAssignmentMerging5.symbols New baseline symbols output for @checkJs typedef merge with module.exports
testdata/baselines/reference/compiler/exportAssignmentMerging5.js New baseline output for @checkJs typedef merge with module.exports
testdata/baselines/reference/compiler/exportAssignmentMerging4.js New baseline output for negative TS export/value conflict case
testdata/baselines/reference/compiler/exportAssignmentMerging4.errors.txt New baseline error output for negative TS export/value conflict case
testdata/baselines/reference/compiler/exportAssignmentMerging3.errors.txt New baseline error output for negative merge conflict case
testdata/baselines/reference/compiler/exportAssignmentMerging2.types New baseline types output for namespace assigned via export =
testdata/baselines/reference/compiler/exportAssignmentMerging2.js New baseline output for namespace assigned via export =
testdata/baselines/reference/compiler/exportAssignmentMerging1.types New baseline types output for type/namespace merging into export assignment
testdata/baselines/reference/compiler/exportAssignmentMerging1.js New baseline output for type/namespace merging into export assignment
testdata/baselines/reference/compiler/erasableSyntaxOnlyJS.errors.txt Baseline update removing TS1203 export-assignment error in JS

@@ -0,0 +1,14 @@
// @module: commonjs
// @declaration: true
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

New compiler tests should generally enable // @strict: true unless the behavior under test is specifically about non-strict mode. Please add // @strict: true near the top (and consider applying the same update to the other newly added exportAssignmentMerging*.ts tests in this PR).

Suggested change
// @declaration: true
// @declaration: true
// @strict: true

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

No need, // @strict: true is the default in Corsa.

@@ -0,0 +1,15 @@
// @module: commonjs
// @declaration: true
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

This new test runs in @checkJs mode but doesn't enable // @strict: true. To keep new coverage consistent and to catch regressions earlier, add // @strict: true unless this scenario is intentionally exercising non-strict behavior.

Suggested change
// @declaration: true
// @declaration: true
// @strict: true

Copilot uses AI. Check for mistakes.
Comment on lines +94 to +97
out/conn.d.ts(5,10): error TS2304: Cannot find name 'Conn'.


==== out/conn.d.ts (1 errors) ====
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

The updated baseline now reports a declaration-emit error where the generated .d.ts contains export = Conn; but no corresponding declare class Conn/declare const Conn in that output. That strongly suggests the binder/emitter lost the value declaration for the export-assigned symbol (or is emitting export = <identifier> without emitting the identifier’s declaration). Consider ensuring the export assignment keeps a usable ValueDeclaration for the exported entity (e.g., preserve the original class/function/var declaration as the value declaration) so the declaration emitter can emit the exported symbol before export =.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

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

Now fixed.

Comment on lines +101 to +104
export type Whatever = string | number;
export = Conn;
~~~~
!!! error TS2304: Cannot find name 'Conn'.
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

The updated baseline now reports a declaration-emit error where the generated .d.ts contains export = Conn; but no corresponding declare class Conn/declare const Conn in that output. That strongly suggests the binder/emitter lost the value declaration for the export-assigned symbol (or is emitting export = <identifier> without emitting the identifier’s declaration). Consider ensuring the export assignment keeps a usable ValueDeclaration for the exported entity (e.g., preserve the original class/function/var declaration as the value declaration) so the declaration emitter can emit the exported symbol before export =.

Copilot uses AI. Check for mistakes.
Comment on lines +41 to +45
dist/typedefModuleExportsIndirect1.d.ts(5,10): error TS2304: Cannot find name 'dummy'.


==== dist/typedefModuleExportsIndirect1.d.ts (1 errors) ====
export type C = {
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

Similar to the Conn case, this baseline introduces a .d.ts emit error where export = dummy; is emitted without any declaration for dummy in the .d.ts. If this PR’s export-assignment merging changes alter how the exported symbol’s declaration is selected (e.g., preferring the assignment node over the original variable/function declaration), the declaration emitter may no longer have a declaration to print. A concrete fix is to make sure the emitted .d.ts declares the exported binding (e.g., declare const dummy: ...;) or to emit an anonymous _default symbol for object/function/class exports when the original name isn’t directly emit-able.

Copilot uses AI. Check for mistakes.
Comment on lines +49 to +51
export = dummy;
~~~~~
!!! error TS2304: Cannot find name 'dummy'.
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

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

Similar to the Conn case, this baseline introduces a .d.ts emit error where export = dummy; is emitted without any declaration for dummy in the .d.ts. If this PR’s export-assignment merging changes alter how the exported symbol’s declaration is selected (e.g., preferring the assignment node over the original variable/function declaration), the declaration emitter may no longer have a declaration to print. A concrete fix is to make sure the emitted .d.ts declares the exported binding (e.g., declare const dummy: ...;) or to emit an anonymous _default symbol for object/function/class exports when the original name isn’t directly emit-able.

Copilot uses AI. Check for mistakes.
@ahejlsberg
Copy link
Member Author

ahejlsberg commented Mar 2, 2026

@weswigham We already have an issue around declaration file generation for CommonJS modules with module.exports assignments. For example, this:

const dummy = 0;
module.exports = dummy;

generates an invalid declaration file (an actual declaration of dummy is missing):

export = dummy;

(EDIT: The above has now been fixed.)

Furthermore, with this PR we'll permit multiple module.exports assignments and non-top-level module.exports assignments. Neither is handled correctly currently. In particular, nested module.exports assignments are simply ignored.

symbol := b.declareSymbol(ast.GetExports(container.Symbol()), container.Symbol(), node, flags, ast.SymbolFlagsAll)
symbol := b.declareSymbol(ast.GetExports(container.Symbol()), container.Symbol(), node, flags, core.IfElse(ast.IsJSExportAssignment(node), 0, ast.SymbolFlagsAll))
if ast.IsJSExportAssignment(node) || node.AsExportAssignment().IsExportEquals {
// Will be an error later, since the module already has other exports. Just make sure this has a valueDeclaration set.
Copy link
Member

Choose a reason for hiding this comment

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

I think this is no longer true for JSExportAssignments, right?

Suggested change
// Will be an error later, since the module already has other exports. Just make sure this has a valueDeclaration set.
// This may be an error later, since the module already has other exports.
// Just make sure this has a valueDeclaration set.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, will fix.

@ahejlsberg
Copy link
Member Author

Latest commits fixes the issue in the example here. However, as can be seen in this test, the declaration emitter doesn't properly handle nested module.exports assignments. The logic that handles that in Strada is located in symbolTableToDeclarationStatements, which is stubbed out in nodebuilderimpl.go in Corsa. I'm not going to attempt to fix that in this PR.

@weswigham
Copy link
Member

weswigham commented Mar 3, 2026

That's incorrect - that's a stub in corsa because it's unused, and should continue to be, since we don't do semantic js declaration emit, but syntactic emit, same as TS, now. If we want to support non-top-level export assignments in corsa, we need to add a non-top-level visitor to the declaration emitter transform - it's new logic, and should be part of the initial implementation of the checker logic, too - that's what I've been saying about how "some js checker work has included declaration emit logic and some hasn't, and we'll need to audit what's missing". We're not "waiting to port something" - the strategy is entirely different. Originally, the hope was we'd need no new declaration emitter logic since the reparser was going to handle all those transforms. If we back off that approach, that means you need declaration emitter logic to mimic the checker logic.

@jakebailey
Copy link
Member

I think we have been gradually backing off on that logic, as we discover more things that the reparser can't do (e.g., the defineProperties stuff).

@ahejlsberg
Copy link
Member Author

Just to recap, in the design meeting we agreed to merge this PR and create a separate PR to issue errors when generating declaration files for CommonJS modules with constructs that aren't supported by the emitter. Specifically, the following aren't supported when generating declaration files:

  • Multiple module.exports assignments in a module.
  • Nested module.exports assignments.
  • Nested exports.xxx assignments.
  • Nested Object.defineProperty(module.exports, ...) calls.

@ahejlsberg ahejlsberg enabled auto-merge March 4, 2026 22:00
@ahejlsberg ahejlsberg added this pull request to the merge queue Mar 4, 2026
Merged via the queue into main with commit 49eb28a Mar 4, 2026
21 checks passed
@ahejlsberg ahejlsberg deleted the cjs-exports-merging branch March 4, 2026 22:43
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.

5 participants