Skip to content

Fix parameter property modifier followed by newline (fixes #28396) - #63713

Open
Abhirup0 wants to merge 1 commit into
microsoft:mainfrom
Abhirup0:fix-28396
Open

Fix parameter property modifier followed by newline (fixes #28396)#63713
Abhirup0 wants to merge 1 commit into
microsoft:mainfrom
Abhirup0:fix-28396

Conversation

@Abhirup0

@Abhirup0 Abhirup0 commented Aug 3, 2026

Copy link
Copy Markdown

Fixes #28396

Summary

When parsing constructor parameter property modifiers (public, private, protected, readonly, override), trailing line breaks between the modifier and parameter name caused nextTokenIsOnSameLineAndCanFollowModifier() to reject the modifier keyword. The parser subsequently fell back to treating the modifier keyword as a parameter name, emitting a syntax error due to a missing comma.

This PR passes permitLineBreak = true when parsing modifiers in parseParameterWorker(), allowing parameter property modifiers followed by a newline to be correctly recognized as modifiers when a valid parameter identifier follows.

Test Plan

  • Added tests/cases/compiler/parameterPropertyWithNewline.ts with baselines.
  • Ran npx hereby runtests --tests=parameterProperty (54/54 tests passing).
  • Ran npx hereby lint (0 errors, 0 warnings).

Disclosure: Authored, reviewed, and verified by me with AI pair-programming assistance (Antigravity/Gemini).

Copilot AI review requested due to automatic review settings August 3, 2026 15:31
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Aug 3, 2026
@typescript-automation typescript-automation Bot added For Backlog Bug PRs that fix a backlog bug labels Aug 3, 2026
@Abhirup0

Abhirup0 commented Aug 3, 2026

Copy link
Copy Markdown
Author

@Abhirup0 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

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 longstanding parser edge case where constructor parameter property modifiers (public/private/protected/readonly/override) were not recognized if a line break appeared before the parameter name, causing the modifier keyword to be mis-parsed as a parameter name.

Changes:

  • Extend modifier lookahead to optionally permit line breaks when deciding whether a token is a modifier.
  • Enable that behavior when parsing parameter modifiers (parseParameterWorker).
  • Add a new compiler test and baselines validating parameter properties with a newline after the modifier.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/compiler/parser.ts Adds a permitLineBreak path for modifier lookahead and uses it during parameter parsing to recognize parameter property modifiers across newlines.
tests/cases/compiler/parameterPropertyWithNewline.ts New regression test covering parameter property modifiers split by a newline.
tests/baselines/reference/parameterPropertyWithNewline.types Baseline for types output of the new regression test.
tests/baselines/reference/parameterPropertyWithNewline.symbols Baseline for symbols output of the new regression test.
tests/baselines/reference/parameterPropertyWithNewline.js Baseline for JS emit output of the new regression test.

Comment thread src/compiler/parser.ts
Comment on lines +8018 to +8020
function parseModifiers(allowDecorators: false, permitConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean, permitLineBreak?: boolean): NodeArray<Modifier> | undefined;
function parseModifiers(allowDecorators: true, permitConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean, permitLineBreak?: boolean): NodeArray<ModifierLike> | undefined;
function parseModifiers(allowDecorators: boolean, permitConstAsModifier?: boolean, stopOnStartOfClassStaticBlock?: boolean, permitLineBreak?: boolean): NodeArray<ModifierLike> | undefined {
Comment on lines +12 to +20
class Foo3 {
constructor(protected
baz: boolean) {}
}

class Foo4 {
constructor(readonly
qux: string) {}
}
@MartinJohns

Copy link
Copy Markdown
Contributor

@Abhirup0

Abhirup0 commented Aug 4, 2026

Copy link
Copy Markdown
Author

Thanks @MartinJohns ! I have updated the PR description to include the AI assistance disclosure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

parameter property's modifier may not be followed by newline

3 participants