Fix declaration emit dropping readonly from as const object literal properties#3933
Open
Copilot wants to merge 3 commits into
Open
Fix declaration emit dropping readonly from as const object literal properties#3933Copilot wants to merge 3 commits into
as const object literal properties#3933Copilot wants to merge 3 commits into
Conversation
Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/a6a59cb3-682f-426b-8fed-1bddcd23ab2c Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
…properties Fix pseudotypenodebuilder to use the ObjectLiteralExpression node instead of the property name when checking isConstContext. The property name's parent could be a MethodDeclaration which isConstContext doesn't traverse through, causing readonly to be dropped from method shorthands and outer properties in as const objects. Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/a6a59cb3-682f-426b-8fed-1bddcd23ab2c Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix tsgo declaration emit to retain readonly for method shorthands
Fix declaration emit dropping readonly from May 16, 2026
as const object literal properties
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a declaration emit regression in the Go port where as const object literals could lose readonly on all properties when the first property was a method shorthand, by ensuring const-context detection starts from the object literal node rather than the first property’s name.
Changes:
- Update pseudo type node building to compute
isConstfrom the containingObjectLiteralExpression(so method shorthands don’t break const-context propagation). - Add a new compiler test + reference baselines covering
as constwith a method shorthand and nested object property. - Update an existing reference baseline (
declarationEmitConstObjectLiteralGenericMethod1) to reflect correct readonly + function-type property emission for const object literal methods.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/checker/pseudotypenodebuilder.go | Fixes const-context detection for pseudo object literal emission by anchoring the check at the object literal node. |
| testdata/tests/cases/compiler/declarationEmitReadonlyAsConst.ts | Adds regression test reproducing the missing-readonly behavior with a leading method shorthand. |
| testdata/baselines/reference/compiler/declarationEmitReadonlyAsConst.types | Reference type baseline for the new test. |
| testdata/baselines/reference/compiler/declarationEmitReadonlyAsConst.symbols | Reference symbol baseline for the new test. |
| testdata/baselines/reference/compiler/declarationEmitReadonlyAsConst.js | Reference JS + .d.ts baseline verifying readonly properties and function-type method emission. |
| testdata/baselines/reference/compiler/declarationEmitConstObjectLiteralGenericMethod1.js | Updates .d.ts reference output to match corrected readonly/function-type emission for const object literal generic methods. |
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.
as constobject literals were missingreadonlyon method shorthands and outer properties in declaration emit:Analysis
pseudotypenodebuilder.godetermines const context viaisConstContext(elements[0].Name). That function walks the parent chain but only propagates throughPropertyAssignment/ShorthandPropertyAssignment— notMethodDeclaration. When the first element is a method, the traversal dead-ends andisConstisfalse, droppingreadonlyfrom all properties.Fix
Pass
elements[0].Name.Parent.Parent(theObjectLiteralExpression) instead of the property name. The object literal's parent is directly theas constassertion, soisConstContextresolves correctly regardless of which property kind comes first.