Fix declaration emit crash on export assigned arrow function using external name - #4648
Merged
weswigham merged 4 commits intoJul 15, 2026
Conversation
…me from another file
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a declaration emit crash in the Go port when emitting .d.ts for a CommonJS module.exports = (x) => {} where the parameter type references an external module name (via import("...")), and adds a compiler regression test + baselines to prevent recurrence.
Changes:
- Add a compiler regression test exercising a JS
module.exportsarrow function annotated with a JSDoc function type referencingimport("@jest/types").Config.InitialOptions. - Extend declaration-emit accessibility diagnostics to handle parameters whose parent is an
ArrowFunctionorFunctionExpression(preventing the reported panic). - Adjust export-assignment transformation to reuse a full signature type node by emitting a
constvariable statement rather than always emitting a function declaration.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
internal/transformers/declarations/transform.go |
Passes assignment type info into function-like export assignment transforms and may emit declare const to reuse a full signature type node. |
internal/transformers/declarations/diagnostics.go |
Prevents panic by handling ArrowFunction/FunctionExpression parents for parameter visibility diagnostics. |
testdata/tests/cases/compiler/declarationEmitJsExportAssignedArrowNoCrash.ts |
New regression test reproducing the crash scenario. |
testdata/baselines/reference/compiler/declarationEmitJsExportAssignedArrowNoCrash.types |
Expected type baseline for the new regression test. |
testdata/baselines/reference/compiler/declarationEmitJsExportAssignedArrowNoCrash.symbols |
Expected symbols baseline for the new regression test. |
testdata/baselines/reference/compiler/declarationEmitJsExportAssignedArrowNoCrash.js |
Expected emit baseline (including generated .d.ts) for the new regression test. |
Comment on lines
1222
to
+1225
| if tx.needsDeclare { | ||
| mods = append(mods, tx.Factory().NewModifier(ast.KindDeclareKeyword)) | ||
| } | ||
| funcDecl := tx.transformFunctionLikeToDeclaration(unwrapped, newId, tx.Factory().NewModifierList(mods)) | ||
| fullSignatureType := assignment.Type() |
RyanCavanaugh
approved these changes
Jul 15, 2026
weswigham
enabled auto-merge
July 15, 2026 18:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4629.
Fixing the panic (which is just the change to add the expression kinds to the message lookup helper, since we transform those now) revealed that we weren't reusing the input type node at all, which is why there was an error at all. The rest of the change is adjusting the transformer to transform to a variable statement instead of a function declaration when the whole assignment has a type node.