Fix using followed by newline ignoring [no LineTerminator here] grammar restriction#3869
Merged
Merged
Conversation
…clarations Fix operator precedence bug in nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLine where hasPrecedingLineBreak() check was only applied to OpenBraceToken due to Go's && binding tighter than ||, instead of applying to both isBindingIdentifier() and OpenBraceToken as in the TypeScript reference implementation. Agent-Logs-Url: https://github.com/microsoft/typescript-go/sessions/b40162ed-f661-46b3-bea6-cba2dc0dcb36 Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix tsgo parser bug with newline after using
Fix May 15, 2026
using followed by newline ignoring [no LineTerminator here] grammar restriction
jakebailey
approved these changes
May 15, 2026
| return p.lookAhead((*Parser).nextTokenIsEqualsOrSemicolonOrColonToken) | ||
| } | ||
| return p.isBindingIdentifier() || p.token == ast.KindOpenBraceToken && !p.hasPrecedingLineBreak() | ||
| return (p.isBindingIdentifier() || p.token == ast.KindOpenBraceToken) && !p.hasPrecedingLineBreak() |
Member
There was a problem hiding this comment.
This is just a plain porting bug, nothing to do with && vs || precedence:
return (isBindingIdentifier() || token() === SyntaxKind.OpenBraceToken) && !scanner.hasPrecedingLineBreak();
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes an operator precedence bug in the parser where using followed by a newline and identifier was incorrectly parsed as a using declaration instead of two separate expression statements, violating the [no LineTerminator here] grammar restriction.
Changes:
- Added parentheses around the disjunction in
nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLineso the line break check applies to both branches. - Added a new compiler test case
usingDeclarationWithNewline.tsand corresponding baselines.
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/parser/parser.go | Operator precedence fix via parentheses around the binding identifier / open brace check. |
| testdata/tests/cases/compiler/usingDeclarationWithNewline.ts | New test case verifying using\nidentifier; parses as two expression statements. |
| testdata/baselines/reference/compiler/usingDeclarationWithNewline.types | Baseline types output. |
| testdata/baselines/reference/compiler/usingDeclarationWithNewline.symbols | Baseline symbols output. |
| testdata/baselines/reference/compiler/usingDeclarationWithNewline.js | Baseline JS emit confirming two statements. |
| testdata/baselines/reference/compiler/usingDeclarationWithNewline.errors.txt | Baseline error output. |
DanielRosenwasser
approved these changes
May 15, 2026
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.
Operator precedence bug in
nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLinecausedusing\nidentifierto be parsed as ausingdeclaration instead of two expression statements.Go's
&&binds tighter than||, so:usingDeclarationWithNewline.tsconfirmingusing\nidentifier;emits as two expression statements