Skip to content

Reject U+0085 and U+200B as source whitespace - #65741

Open
Armin Azimi (arminazimi) wants to merge 3 commits into
microsoft:mainfrom
arminazimi:fix/scanner-whitespace-65730
Open

Armin Azimi (arminazimi) wants to merge 3 commits into
microsoft:mainfrom
arminazimi:fix/scanner-whitespace-65730

Conversation

@arminazimi

Copy link
Copy Markdown

Fixes #65730

Motivation & Guidance

I selected this issue and asked OpenAI Codex to reproduce it on main,
check the ECMAScript lexical grammar, write a failing regression test
before changing the scanner, and verify both JavaScript and TypeScript.

Codex implemented the fix and tests, regenerated the affected baselines,
ran the checks, created commit c4e1ef7c5, and drafted this description.
I personally reviewed and approved the final diff. I will review this
description separately and respond to maintainers myself.

Analysis

The scanner consumed U+0085 (NEXT LINE) and U+200B (ZERO WIDTH SPACE) as
whitespace between tokens. ECMAScript 2026 classifies neither character as
WhiteSpace or LineTerminator.

Fix

Use a source-whitespace check in the shared scanner and its trivia
helpers. Both characters now reach the existing invalid-character path
and report TS1127 at the offending character in .js and .ts files.
Source files that previously relied on either character as a token
separator now receive a syntax diagnostic.

Updated two legacy NEXT LINE fixtures to expect the new behavior. The
source-map fixture now uses U+00A0 at the token boundary so it continues
to exercise source mapping with valid input.

Tests

  • The focused scanner regression failed for both characters on main
    and passed after the fix. It checks the diagnostic code and span.
  • The compiler regression checks TS1127 at line 1, column 4 for U+0085
    and line 2, column 4 for U+200B in both .js and .ts. Scanner tests
    also cover valid whitespace and all four ECMAScript line terminators.
  • Scanner and parser package tests, npx hereby validate,
    npx hereby tidy, and git diff --exit-code passed.
  • npx hereby validate --all passed the Go suite with no failures.
    Its only failing task was test:scripts. The same two checkPublicApi
    tests failed with identical assertion output on a main compiler
    build on the same macOS host.

Copilot AI balanced review requested due to automatic review settings November 30, 2026 20:16
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 30, 2026
@typescript-automation typescript-automation Bot added the For Backlog Bug PRs that fix a backlog bug label Nov 30, 2026

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.

🟢 Approval recommended

No active review issues were identified for the source-whitespace alignment change.

No open issues 🎉

1 file not reviewed
  • tsc/testdata/baselines/reference/compiler/sourceMap-LineBreaks(target=es2015).js: Generated file
What changed in this PR

Fixes #65730 by aligning the TypeScript compiler’s source-whitespace handling with ECMAScript: U+0085 and U+200B now produce TS1127 instead of separating tokens.

Changes:

  • Applies the stricter whitespace check in the scanner and trivia helpers.
  • Adds scanner and JavaScript/TypeScript regressions while preserving valid whitespace and line-terminator behavior.
  • Updates legacy NEXT LINE expectations and substitutes valid U+00A0 in the source-map fixture.
File Description
tsc/​testdata/​tests/​cases/​compiler/​sourceMap-LineBreaks.ts Uses U+00A0 at the token boundary.
tsc/​testdata/​tests/​cases/​compiler/​invalidUnicodeWhitespace.ts Adds JavaScript and TypeScript regressions.
tsc/​testdata/​tests/​cases/​compiler/​fileWithNextLine3.ts Updates the comment to expect invalid NEXT LINE.
tsc/​testdata/​tests/​cases/​compiler/​fileWithNextLine2.ts Updates the comment to expect invalid NEXT LINE.
tsc/​testdata/​baselines/​reference/​compiler/​sourceMap-LineBreaks(target=es2015).types Reflects the renamed U+00A0 variable.
tsc/​testdata/​baselines/​reference/​compiler/​sourceMap-LineBreaks(target=es2015).symbols Updates fixture symbol expectations.
tsc/​testdata/​baselines/​reference/​compiler/​sourceMap-LineBreaks(target=es2015).sourcemap.txt Updates source-map text for U+00A0.
tsc/​testdata/​baselines/​reference/​compiler/​sourceMap-LineBreaks(target=es2015).js.map Refreshes the visualization link’s embedded fixture.
tsc/​testdata/​baselines/​reference/​compiler/​sourceMap-LineBreaks(target=es2015).js Updates source and emitted variable names.
tsc/​testdata/​baselines/​reference/​compiler/​invalidUnicodeWhitespace.errors.txt Records diagnostic positions in both languages.
tsc/​testdata/​baselines/​reference/​compiler/​fileWithNextLine3.types Records types after parser recovery.
tsc/​testdata/​baselines/​reference/​compiler/​fileWithNextLine3.symbols Mirrors the updated fixture comment.
tsc/​testdata/​baselines/​reference/​compiler/​fileWithNextLine3.js Records recovered return-statement output.
tsc/​testdata/​baselines/​reference/​compiler/​fileWithNextLine3.errors.txt Expects TS1127 after return.
tsc/​testdata/​baselines/​reference/​compiler/​fileWithNextLine2.types Records types after parser recovery.
tsc/​testdata/​baselines/​reference/​compiler/​fileWithNextLine2.symbols Mirrors the updated fixture comment.
tsc/​testdata/​baselines/​reference/​compiler/​fileWithNextLine2.js Records recovered variable-declaration output.
tsc/​testdata/​baselines/​reference/​compiler/​fileWithNextLine2.errors.txt Adds invalid-character and recovery diagnostics.
tsc/​internal/​scanner/​scanner.go Excludes both characters from source whitespace.
tsc/​internal/​scanner/​scanner_test.go Tests rejection, diagnostic spans, and valid separators.

Review effort: Balanced

@arminazimi

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@RyanCavanaugh

Copy link
Copy Markdown
Member

Why not remove those cases from IsWhiteSpaceSingleLine instead?

This branch has not been deployed

No deployments
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.

Scanner treats U+0085 and U+200B as whitespace, but ECMAScript doesn't

3 participants