Skip to content

Fix declaration emit crash on export assigned arrow function using external name - #4648

Merged
weswigham merged 4 commits into
microsoft:mainfrom
weswigham:fix-missing-declaration-arrow-function-diagnostic
Jul 15, 2026
Merged

Fix declaration emit crash on export assigned arrow function using external name#4648
weswigham merged 4 commits into
microsoft:mainfrom
weswigham:fix-missing-declaration-arrow-function-diagnostic

Conversation

@weswigham

Copy link
Copy Markdown
Member

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.exports arrow function annotated with a JSDoc function type referencing import("@jest/types").Config.InitialOptions.
  • Extend declaration-emit accessibility diagnostics to handle parameters whose parent is an ArrowFunction or FunctionExpression (preventing the reported panic).
  • Adjust export-assignment transformation to reuse a full signature type node by emitting a const variable 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 thread internal/transformers/declarations/transform.go Outdated
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()
@weswigham
weswigham enabled auto-merge July 15, 2026 18:41
@weswigham
weswigham requested a review from RyanCavanaugh July 15, 2026 20:20
@weswigham
weswigham added this pull request to the merge queue Jul 15, 2026
Merged via the queue into microsoft:main with commit 80d4f46 Jul 15, 2026
21 checks passed
@weswigham
weswigham deleted the fix-missing-declaration-arrow-function-diagnostic branch July 15, 2026 21:03
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.

panic: Unknown parent for parameter: KindArrowFunction

3 participants