Fix parameter property modifier followed by newline (fixes #28396) - #63713
Open
Abhirup0 wants to merge 1 commit into
Open
Fix parameter property modifier followed by newline (fixes #28396)#63713Abhirup0 wants to merge 1 commit into
Abhirup0 wants to merge 1 commit into
Conversation
Author
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
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 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) {} | ||
| } |
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 #28396
Summary
When parsing constructor parameter property modifiers (
public,private,protected,readonly,override), trailing line breaks between the modifier and parameter name causednextTokenIsOnSameLineAndCanFollowModifier()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 = truewhen parsing modifiers inparseParameterWorker(), allowing parameter property modifiers followed by a newline to be correctly recognized as modifiers when a valid parameter identifier follows.Test Plan
tests/cases/compiler/parameterPropertyWithNewline.tswith baselines.npx hereby runtests --tests=parameterProperty(54/54 tests passing).npx hereby lint(0 errors, 0 warnings).