Repository navigation
Reject U+0085 and U+200B as source whitespace - #65741
Open
Armin Azimi (arminazimi) wants to merge 3 commits into
Open
Armin Azimi (arminazimi) wants to merge 3 commits into
Armin Azimi (arminazimi) wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟢 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
Author
|
@microsoft-github-policy-service agree |
Member
|
Why not remove those cases from |
This branch has not been deployed
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 #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
WhiteSpaceorLineTerminator.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
TS1127at the offending character in.jsand.tsfiles.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
mainand passed after the fix. It checks the diagnostic code and span.
TS1127at line 1, column 4 for U+0085and line 2, column 4 for U+200B in both
.jsand.ts. Scanner testsalso cover valid whitespace and all four ECMAScript line terminators.
npx hereby validate,npx hereby tidy, andgit diff --exit-codepassed.npx hereby validate --allpassed the Go suite with no failures.Its only failing task was
test:scripts. The same twocheckPublicApitests failed with identical assertion output on a
maincompilerbuild on the same macOS host.