Skip to content

fix(4048): fix declaration emit for new keyword used as property names#4052

Open
a-tarasyuk wants to merge 1 commit into
microsoft:mainfrom
a-tarasyuk:fix/4048
Open

fix(4048): fix declaration emit for new keyword used as property names#4052
a-tarasyuk wants to merge 1 commit into
microsoft:mainfrom
a-tarasyuk:fix/4048

Conversation

@a-tarasyuk
Copy link
Copy Markdown
Contributor

Fixes #4048

Copilot AI review requested due to automatic review settings May 25, 2026 22:02
Copy link
Copy Markdown
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

Note

Copilot was unable to run its full agentic suite in this review.

Adds coverage for declaration emit around keyword property names and adjusts type-node building to ensure a method named new is emitted as a quoted property name (not a construct signature), updating/removing related baselines.

Changes:

  • Added a new compiler test case for keyword property names (new, delete, break, continue) in object literals and as const.
  • Updated pseudo type-to-AST node construction to special-case method names equal to new and emit them as string-literal property names.
  • Cleaned up accepted/baseline outputs related to emitMethodCalledNew.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
testdata/tests/cases/compiler/declarationEmitKeywordPropertyNames.ts New test to validate declaration emit for keyword property names.
testdata/submoduleAccepted.txt Removes an accepted baseline diff entry that should no longer be produced.
testdata/baselines/reference/submoduleAccepted/compiler/emitMethodCalledNew.js.diff Removes an obsolete accepted diff baseline.
testdata/baselines/reference/submodule/compiler/emitMethodCalledNew.js Updates expected output to emit "new" instead of ["new"].
testdata/baselines/reference/compiler/declarationEmitKeywordPropertyNames.* Adds new baselines for the new keyword-property-names test.
internal/checker/pseudotypenodebuilder.go Special-cases method name new to emit a string literal property name node.
internal/checker/nodecopy.go Simplifies reuseName logic by removing new-specific handling and always normalizing string-literals to identifiers.
Comments suppressed due to low confidence (1)

internal/checker/nodecopy.go:1

  • The previous logic intentionally avoided normalizing the string literal "new" into an identifier because, in method-signature contexts, new() is interpreted as a construct signature (different meaning than a method named "new"). The PR moves the special-casing into pseudoTypeToNode for one specific path, but reuseName is a shared helper; with this change, any other caller that reuses "new" as a method name risks emitting a construct signature again. Consider restoring an explicit guard in reuseName to not normalize "new" (and/or introducing a context-aware helper like reusePropertyNameForMethod vs reusePropertyNameForProperty) so the invariant is enforced centrally rather than depending on individual call sites.
package checker

Comment thread internal/checker/nodecopy.go
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.

Behavior difference: Object key named new is double-quoted in tsgo emit, but not in tsc emit

2 participants