Skip to content

Fix using followed by newline ignoring [no LineTerminator here] grammar restriction#3869

Merged
DanielRosenwasser merged 2 commits into
mainfrom
copilot/fix-tsgo-parser-using-bug
May 15, 2026
Merged

Fix using followed by newline ignoring [no LineTerminator here] grammar restriction#3869
DanielRosenwasser merged 2 commits into
mainfrom
copilot/fix-tsgo-parser-using-bug

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

Operator precedence bug in nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLine caused using\nidentifier to be parsed as a using declaration instead of two expression statements.

Go's && binds tighter than ||, so:

// Bug: hasPrecedingLineBreak() only guards OpenBraceToken
return p.isBindingIdentifier() || p.token == ast.KindOpenBraceToken && !p.hasPrecedingLineBreak()

// Fix: matches TS reference (parser.ts:7356)
return (p.isBindingIdentifier() || p.token == ast.KindOpenBraceToken) && !p.hasPrecedingLineBreak()
  • Parser fix: Added parentheses to apply the line break check to both branches
  • Test: Added usingDeclarationWithNewline.ts confirming using\nidentifier; emits as two expression statements

…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 using followed by newline ignoring [no LineTerminator here] grammar restriction May 15, 2026
Copilot AI requested a review from jakebailey May 15, 2026 18:09
Comment thread internal/parser/parser.go
return p.lookAhead((*Parser).nextTokenIsEqualsOrSemicolonOrColonToken)
}
return p.isBindingIdentifier() || p.token == ast.KindOpenBraceToken && !p.hasPrecedingLineBreak()
return (p.isBindingIdentifier() || p.token == ast.KindOpenBraceToken) && !p.hasPrecedingLineBreak()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a plain porting bug, nothing to do with && vs || precedence:

return (isBindingIdentifier() || token() === SyntaxKind.OpenBraceToken) && !scanner.hasPrecedingLineBreak();

@jakebailey jakebailey marked this pull request as ready for review May 15, 2026 18:12
Copilot AI review requested due to automatic review settings May 15, 2026 18:12
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.

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 nextTokenIsBindingIdentifierOrStartOfDestructuringOnSameLine so the line break check applies to both branches.
  • Added a new compiler test case usingDeclarationWithNewline.ts and 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 DanielRosenwasser added this pull request to the merge queue May 15, 2026
Merged via the queue into main with commit e5a356e May 15, 2026
25 checks passed
@DanielRosenwasser DanielRosenwasser deleted the copilot/fix-tsgo-parser-using-bug branch May 15, 2026 19:18
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.

tsgo parser bug: using followed by a newline ignores [no LineTerminator here] grammar restriction

4 participants