Skip to content

Prevent valid JSX from being seen as the start of a generic arrow function, fix crashes #52450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 1, 2023

Conversation

jakebailey
Copy link
Member

@jakebailey jakebailey commented Jan 27, 2023

Fixes #52449

The arrow function lookahead was too overzealous in determining what was "definitely" an arrow function. Switching a "true" to an "unknown" result fixes the issue.

But, I am suspicious of this because there is no error saying that the variable const isn't found (unlike T).

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jan 27, 2023
@jakebailey
Copy link
Member Author

Consider me no longer suspicious; it's lowercase so it's an intrinsic.

@jakebailey
Copy link
Member Author

@typescript-bot test this
@typescript-bot test top100
@typescript-bot user test this
@typescript-bot user test tsserver
@typescript-bot test tsserver top100
@typescript-bot run dt
@typescript-bot perf test this
@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 27, 2023

Heya @jakebailey, I've started to run the parallelized Definitely Typed test suite on this PR at c705d8c. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 27, 2023

Heya @jakebailey, I've started to run the diff-based user code test suite on this PR at c705d8c. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 27, 2023

Heya @jakebailey, I've started to run the diff-based user code test suite (tsserver) on this PR at c705d8c. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 27, 2023

Heya @jakebailey, I've started to run the diff-based top-repos suite (tsserver) on this PR at c705d8c. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 27, 2023

Heya @jakebailey, I've started to run the perf test suite on this PR at c705d8c. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 27, 2023

Heya @jakebailey, I've started to run the extended test suite on this PR at c705d8c. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 27, 2023

Heya @jakebailey, I've started to run the diff-based top-repos suite on this PR at c705d8c. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 27, 2023

Heya @jakebailey, I've started to run the tarball bundle task on this PR at c705d8c. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 27, 2023

Hey @jakebailey, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/144224/artifacts?artifactName=tgz&fileId=023D793625B734A30ED172091FFD2C82D575EE1B930E7CB2CF4107270D4288C202&fileName=/typescript-5.0.0-insiders.20230127.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user test suite comparing main and refs/pull/52450/merge:

Everything looks good!

1 similar comment
@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user test suite comparing main and refs/pull/52450/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

Heya @jakebailey, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here.

@jakebailey
Copy link
Member Author

jakebailey commented Jan 27, 2023

The recent esbuild commit regarding generic arrow functions in TSX files is related: evanw/esbuild@8824778

In that to this PR you can just add:

else if (third === SyntaxKind.GreaterThanToken) {
    return Tristate.Unknown;
}

However, there's sort of a mutual exclusivity between the relevant piece of code:

let fn = async <T> () => {};

And this test:

var x1 = <T>() => {}</T>;
x1.isElement;

I'm personally convinced both should parse (and so esbuild doesn't have to change), but I'm not totally sure how to get there given our current goofy arrow function parsing method.

@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jan 27, 2023
@typescript-bot
Copy link
Collaborator

@jakebailey
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - main..52450
Metric main 52450 Delta Best Worst
Angular - node (v18.10.0, x64)
Memory used 359,834k (± 0.03%) 359,854k (± 0.02%) +21k (+ 0.01%) 359,760k 359,929k
Parse Time 3.96s (± 0.87%) 3.95s (± 1.08%) -0.00s (- 0.08%) 3.89s 4.02s
Bind Time 1.18s (± 0.69%) 1.17s (± 0.70%) -0.00s (- 0.28%) 1.16s 1.18s
Check Time 8.66s (± 0.31%) 8.68s (± 0.54%) +0.02s (+ 0.27%) 8.63s 8.75s
Emit Time 7.65s (± 0.93%) 7.63s (± 0.52%) -0.02s (- 0.20%) 7.60s 7.68s
Total Time 21.44s (± 0.27%) 21.45s (± 0.52%) +0.01s (+ 0.04%) 21.31s 21.62s
Compiler-Unions - node (v18.10.0, x64)
Memory used 193,493k (± 1.19%) 192,558k (± 0.02%) -935k (- 0.48%) 192,509k 192,594k
Parse Time 1.64s (± 1.37%) 1.65s (± 2.05%) +0.00s (+ 0.20%) 1.61s 1.68s
Bind Time 0.79s (± 0.69%) 0.80s (± 1.12%) +0.01s (+ 0.63%) 0.79s 0.81s
Check Time 9.62s (± 0.60%) 9.69s (± 0.65%) +0.07s (+ 0.69%) 9.59s 9.74s
Emit Time 2.80s (± 0.43%) 2.82s (± 0.92%) +0.01s (+ 0.48%) 2.78s 2.86s
Total Time 14.86s (± 0.58%) 14.95s (± 0.35%) +0.10s (+ 0.65%) 14.86s 15.01s
Monaco - node (v18.10.0, x64)
Memory used 344,010k (± 0.01%) 343,962k (± 0.01%) -48k (- 0.01%) 343,889k 344,010k
Parse Time 2.94s (± 0.61%) 2.96s (± 0.89%) +0.02s (+ 0.62%) 2.92s 2.99s
Bind Time 1.03s (± 0.79%) 1.04s (± 1.41%) +0.01s (+ 0.81%) 1.02s 1.06s
Check Time 7.06s (± 0.65%) 7.07s (± 0.39%) +0.01s (+ 0.14%) 7.04s 7.11s
Emit Time 4.32s (± 0.74%) 4.34s (± 0.65%) +0.02s (+ 0.54%) 4.30s 4.38s
Total Time 15.35s (± 0.57%) 15.41s (± 0.34%) +0.06s (+ 0.39%) 15.34s 15.48s
TFS - node (v18.10.0, x64)
Memory used 300,383k (± 0.00%) 300,377k (± 0.01%) -6k (- 0.00%) 300,335k 300,417k
Parse Time 2.24s (± 1.53%) 2.24s (± 1.00%) +0.00s (+ 0.07%) 2.21s 2.27s
Bind Time 1.17s (± 0.70%) 1.17s (± 0.00%) -0.00s (- 0.28%) 1.17s 1.17s
Check Time 6.52s (± 0.57%) 6.53s (± 0.60%) +0.00s (+ 0.05%) 6.49s 6.60s
Emit Time 3.91s (± 0.53%) 3.93s (± 1.12%) +0.03s (+ 0.68%) 3.88s 4.01s
Total Time 13.85s (± 0.58%) 13.87s (± 0.56%) +0.02s (+ 0.16%) 13.80s 13.98s
material-ui - node (v18.10.0, x64)
Memory used 476,755k (± 0.01%) 476,768k (± 0.02%) +13k (+ 0.00%) 476,715k 476,922k
Parse Time 3.55s (± 0.92%) 3.55s (± 2.04%) 0.00s ( 0.00%) 3.40s 3.59s
Bind Time 0.96s (± 1.09%) 1.00s (± 6.86%) +0.03s (+ 3.63%) 0.97s 1.14s
Check Time 17.09s (± 0.49%) 17.19s (± 0.70%) +0.09s (+ 0.55%) 17.07s 17.35s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 21.60s (± 0.48%) 21.73s (± 0.59%) +0.13s (+ 0.59%) 21.61s 21.91s
xstate - node (v18.10.0, x64)
Memory used 548,660k (± 0.03%) 548,702k (± 0.02%) +42k (+ 0.01%) 548,531k 548,902k
Parse Time 4.57s (± 0.52%) 4.58s (± 0.77%) +0.01s (+ 0.22%) 4.56s 4.65s
Bind Time 1.72s (± 0.48%) 1.72s (± 1.04%) -0.00s (- 0.29%) 1.70s 1.75s
Check Time 2.73s (± 0.80%) 2.72s (± 0.68%) -0.01s (- 0.24%) 2.70s 2.75s
Emit Time 0.08s (± 0.00%) 0.09s (± 5.95%) +0.01s (+ 8.33%) 0.08s 0.09s
Total Time 9.12s (± 0.44%) 9.12s (± 0.65%) +0.00s (+ 0.02%) 9.07s 9.23s
Angular - node (v16.17.1, x64)
Memory used 359,218k (± 0.00%) 359,225k (± 0.01%) +8k (+ 0.00%) 359,190k 359,262k
Parse Time 4.17s (± 0.20%) 4.19s (± 0.38%) +0.02s (+ 0.36%) 4.17s 4.21s
Bind Time 1.21s (± 0.43%) 1.22s (± 0.84%) +0.01s (+ 0.82%) 1.21s 1.24s
Check Time 9.41s (± 0.30%) 9.41s (± 0.32%) -0.00s (- 0.02%) 9.38s 9.45s
Emit Time 8.06s (± 0.64%) 8.06s (± 0.28%) -0.00s (- 0.04%) 8.03s 8.09s
Total Time 22.86s (± 0.35%) 22.88s (± 0.15%) +0.02s (+ 0.07%) 22.83s 22.93s
Compiler-Unions - node (v16.17.1, x64)
Memory used 194,269k (± 0.05%) 194,198k (± 0.05%) -71k (- 0.04%) 194,100k 194,380k
Parse Time 1.80s (± 0.23%) 1.81s (± 0.97%) +0.01s (+ 0.46%) 1.79s 1.84s
Bind Time 0.84s (± 0.97%) 0.85s (± 0.96%) +0.00s (+ 0.40%) 0.84s 0.86s
Check Time 10.37s (± 0.31%) 10.39s (± 0.81%) +0.02s (+ 0.18%) 10.27s 10.53s
Emit Time 3.06s (± 0.60%) 3.06s (± 0.58%) -0.00s (- 0.11%) 3.03s 3.08s
Total Time 16.07s (± 0.24%) 16.09s (± 0.57%) +0.03s (+ 0.16%) 16.01s 16.27s
Monaco - node (v16.17.1, x64)
Memory used 343,274k (± 0.02%) 343,236k (± 0.01%) -38k (- 0.01%) 343,205k 343,263k
Parse Time 3.17s (± 1.03%) 3.17s (± 1.15%) +0.00s (+ 0.05%) 3.11s 3.22s
Bind Time 1.11s (± 0.89%) 1.11s (± 0.73%) +0.01s (+ 0.45%) 1.10s 1.12s
Check Time 7.73s (± 0.25%) 7.73s (± 0.48%) -0.00s (- 0.02%) 7.69s 7.78s
Emit Time 4.53s (± 0.95%) 4.53s (± 0.26%) +0.00s (+ 0.04%) 4.51s 4.54s
Total Time 16.53s (± 0.40%) 16.54s (± 0.18%) +0.01s (+ 0.06%) 16.50s 16.58s
TFS - node (v16.17.1, x64)
Memory used 299,756k (± 0.00%) 299,757k (± 0.00%) +2k (+ 0.00%) 299,743k 299,783k
Parse Time 2.48s (± 1.50%) 2.48s (± 0.98%) +0.00s (+ 0.07%) 2.45s 2.51s
Bind Time 1.25s (± 0.33%) 1.25s (± 0.41%) +0.00s (+ 0.13%) 1.25s 1.26s
Check Time 7.20s (± 0.38%) 7.19s (± 0.28%) -0.01s (- 0.09%) 7.16s 7.22s
Emit Time 4.22s (± 0.49%) 4.23s (± 0.65%) +0.01s (+ 0.24%) 4.20s 4.27s
Total Time 15.14s (± 0.37%) 15.14s (± 0.27%) -0.00s (- 0.01%) 15.09s 15.21s
material-ui - node (v16.17.1, x64)
Memory used 476,178k (± 0.02%) 476,061k (± 0.01%) -117k (- 0.02%) 476,032k 476,153k
Parse Time 3.71s (± 0.36%) 3.72s (± 0.22%) +0.01s (+ 0.31%) 3.71s 3.73s
Bind Time 1.02s (± 0.00%) 1.02s (± 0.51%) -0.00s (- 0.33%) 1.01s 1.02s
Check Time 18.11s (± 0.30%) 18.10s (± 0.41%) -0.02s (- 0.08%) 18.00s 18.18s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 22.84s (± 0.27%) 22.84s (± 0.31%) -0.01s (- 0.04%) 22.75s 22.92s
xstate - node (v16.17.1, x64)
Memory used 546,232k (± 0.01%) 546,300k (± 0.02%) +68k (+ 0.01%) 546,203k 546,423k
Parse Time 4.76s (± 0.29%) 4.77s (± 0.30%) +0.01s (+ 0.28%) 4.75s 4.79s
Bind Time 1.80s (± 3.60%) 1.78s (± 4.99%) -0.02s (- 1.30%) 1.66s 1.85s
Check Time 2.98s (± 1.15%) 3.04s (± 3.19%) +0.06s (+ 1.84%) 2.95s 3.16s
Emit Time 0.09s (± 5.76%) 0.10s (± 5.76%) +0.00s (+ 0.00%) 0.09s 0.10s
Total Time 9.64s (± 0.42%) 9.68s (± 0.20%) +0.04s (+ 0.43%) 9.66s 9.71s
Angular - node (v14.15.1, x64)
Memory used 352,832k (± 0.01%) 352,835k (± 0.01%) +3k (+ 0.00%) 352,791k 352,877k
Parse Time 4.22s (± 0.79%) 4.23s (± 0.47%) +0.01s (+ 0.16%) 4.20s 4.26s
Bind Time 1.28s (± 0.49%) 1.28s (± 0.59%) +0.00s (+ 0.13%) 1.27s 1.29s
Check Time 9.70s (± 0.23%) 9.70s (± 0.68%) -0.00s (- 0.00%) 9.58s 9.76s
Emit Time 8.40s (± 0.73%) 8.40s (± 0.43%) 0.00s ( 0.00%) 8.35s 8.44s
Total Time 23.61s (± 0.17%) 23.61s (± 0.43%) +0.01s (+ 0.03%) 23.44s 23.74s
Compiler-Unions - node (v14.15.1, x64)
Memory used 189,203k (± 0.08%) 189,664k (± 0.68%) +461k (+ 0.24%) 189,006k 192,300k
Parse Time 1.85s (± 0.76%) 1.85s (± 1.17%) -0.00s (- 0.18%) 1.82s 1.88s
Bind Time 0.86s (± 1.20%) 0.86s (± 0.87%) -0.00s (- 0.19%) 0.85s 0.87s
Check Time 10.46s (± 0.42%) 10.44s (± 0.45%) -0.02s (- 0.22%) 10.37s 10.51s
Emit Time 3.40s (± 4.99%) 3.40s (± 3.98%) -0.00s (- 0.05%) 3.16s 3.53s
Total Time 16.58s (± 1.00%) 16.55s (± 0.88%) -0.03s (- 0.19%) 16.26s 16.66s
Monaco - node (v14.15.1, x64)
Memory used 338,025k (± 0.00%) 338,029k (± 0.00%) +5k (+ 0.00%) 338,015k 338,038k
Parse Time 3.24s (± 0.94%) 3.21s (± 0.52%) -0.03s (- 0.98%) 3.19s 3.24s
Bind Time 1.11s (± 0.47%) 1.11s (± 0.88%) +0.01s (+ 0.45%) 1.10s 1.13s
Check Time 8.04s (± 0.29%) 8.08s (± 0.52%) +0.05s (+ 0.58%) 8.01s 8.12s
Emit Time 4.76s (± 0.59%) 4.79s (± 0.76%) +0.03s (+ 0.70%) 4.75s 4.84s
Total Time 17.15s (± 0.36%) 17.20s (± 0.35%) +0.05s (+ 0.29%) 17.12s 17.28s
TFS - node (v14.15.1, x64)
Memory used 294,583k (± 0.01%) 294,583k (± 0.00%) 0k ( 0.00%) 294,566k 294,600k
Parse Time 2.74s (± 0.27%) 2.77s (± 0.46%) +0.03s (+ 1.03%) 2.75s 2.79s
Bind Time 1.10s (± 1.21%) 1.11s (± 0.68%) +0.01s (+ 1.21%) 1.10s 1.12s
Check Time 7.52s (± 0.58%) 7.50s (± 0.60%) -0.02s (- 0.24%) 7.41s 7.53s
Emit Time 4.62s (± 0.71%) 4.61s (± 0.65%) -0.01s (- 0.25%) 4.58s 4.65s
Total Time 15.98s (± 0.51%) 15.99s (± 0.35%) +0.01s (+ 0.07%) 15.93s 16.07s
material-ui - node (v14.15.1, x64)
Memory used 471,559k (± 0.01%) 471,556k (± 0.00%) -3k (- 0.00%) 471,545k 471,578k
Parse Time 3.93s (± 0.67%) 3.95s (± 0.69%) +0.01s (+ 0.34%) 3.92s 3.99s
Bind Time 1.04s (± 0.94%) 1.05s (± 0.99%) +0.01s (+ 0.48%) 1.03s 1.06s
Check Time 19.00s (± 0.33%) 19.04s (± 0.35%) +0.04s (+ 0.21%) 18.96s 19.14s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 23.97s (± 0.34%) 24.03s (± 0.22%) +0.06s (+ 0.24%) 23.98s 24.11s
xstate - node (v14.15.1, x64)
Memory used 534,470k (± 0.01%) 534,461k (± 0.00%) -9k (- 0.00%) 534,429k 534,496k
Parse Time 5.15s (± 1.24%) 5.17s (± 1.03%) +0.03s (+ 0.52%) 5.10s 5.23s
Bind Time 1.72s (± 0.49%) 1.71s (± 1.05%) -0.01s (- 0.29%) 1.69s 1.74s
Check Time 3.09s (± 0.88%) 3.09s (± 0.56%) -0.00s (- 0.05%) 3.07s 3.12s
Emit Time 0.10s (± 0.00%) 0.10s (± 0.00%) 0.00s ( 0.00%) 0.10s 0.10s
Total Time 10.06s (± 0.80%) 10.08s (± 0.60%) +0.02s (+ 0.18%) 10.00s 10.14s
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v18.10.0, x64)
  • Angular - node (v16.17.1, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v18.10.0, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v18.10.0, x64)
  • Monaco - node (v16.17.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v18.10.0, x64)
  • TFS - node (v16.17.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v18.10.0, x64)
  • material-ui - node (v16.17.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v18.10.0, x64)
  • xstate - node (v16.17.1, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 52450 6
Baseline main 6

TSServer

Comparison Report - main..52450
Metric main 52450 Delta Best Worst
Compiler-UnionsTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 2,531ms (± 1.10%) 2,525ms (± 1.93%) -7ms (- 0.27%) 2,469ms 2,606ms
Req 2 - geterr 5,517ms (± 0.63%) 5,503ms (± 0.30%) -14ms (- 0.25%) 5,482ms 5,529ms
Req 3 - references 368ms (± 1.18%) 366ms (± 0.65%) -2ms (- 0.63%) 363ms 370ms
Req 4 - navto 285ms (± 0.26%) 285ms (± 0.26%) 0ms ( 0.00%) 284ms 286ms
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) 0 ( 0.00%) 1,356 1,356
Req 5 - completionInfo 66ms (± 3.11%) 67ms (± 0.82%) +0ms (+ 0.25%) 66ms 67ms
CompilerTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 2,707ms (± 1.14%) 2,744ms (± 1.15%) +37ms (+ 1.35%) 2,694ms 2,780ms
Req 2 - geterr 4,057ms (± 0.65%) 4,066ms (± 0.67%) +9ms (+ 0.22%) 4,029ms 4,100ms
Req 3 - references 370ms (± 0.65%) 367ms (± 0.81%) -3ms (- 0.72%) 361ms 369ms
Req 4 - navto 299ms (± 1.49%) 297ms (± 0.79%) -2ms (- 0.78%) 294ms 300ms
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) 0 ( 0.00%) 1,518 1,518
Req 5 - completionInfo 79ms (± 8.12%) 78ms (± 9.18%) -1ms (- 1.05%) 66ms 83ms
xstateTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 3,507ms (± 0.52%) 3,504ms (± 0.70%) -4ms (- 0.10%) 3,470ms 3,542ms
Req 2 - geterr 1,426ms (± 0.89%) 1,426ms (± 1.21%) +0ms (+ 0.01%) 1,403ms 1,450ms
Req 3 - references 105ms (± 1.90%) 104ms (± 1.33%) -2ms (- 1.43%) 102ms 106ms
Req 4 - navto 358ms (± 0.63%) 356ms (± 0.77%) -2ms (- 0.47%) 354ms 360ms
Req 5 - completionInfo count 3,171 (± 0.00%) 3,171 (± 0.00%) 0 ( 0.00%) 3,171 3,171
Req 5 - completionInfo 470ms (± 0.67%) 468ms (± 1.41%) -1ms (- 0.28%) 458ms 477ms
Compiler-UnionsTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,770ms (± 1.04%) 2,794ms (± 0.51%) +25ms (+ 0.89%) 2,774ms 2,812ms
Req 2 - geterr 5,852ms (± 0.45%) 5,878ms (± 0.49%) +26ms (+ 0.45%) 5,842ms 5,915ms
Req 3 - references 374ms (± 1.02%) 377ms (± 1.34%) +3ms (+ 0.76%) 372ms 386ms
Req 4 - navto 278ms (± 0.71%) 277ms (± 0.87%) -1ms (- 0.24%) 274ms 280ms
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) 0 ( 0.00%) 1,356 1,356
Req 5 - completionInfo 77ms (± 8.12%) 76ms (± 5.39%) -1ms (- 0.65%) 71ms 83ms
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,934ms (± 0.52%) 2,937ms (± 0.33%) +3ms (+ 0.10%) 2,924ms 2,950ms
Req 2 - geterr 4,403ms (± 0.38%) 4,395ms (± 0.50%) -8ms (- 0.19%) 4,367ms 4,416ms
Req 3 - references 380ms (± 1.02%) 379ms (± 0.70%) -1ms (- 0.35%) 376ms 383ms
Req 4 - navto 289ms (± 0.72%) 290ms (± 0.48%) +1ms (+ 0.35%) 288ms 291ms
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) 0 ( 0.00%) 1,518 1,518
Req 5 - completionInfo 71ms (± 0.72%) 72ms (± 0.72%) +0ms (+ 0.47%) 71ms 72ms
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 3,631ms (± 0.41%) 3,648ms (± 0.20%) +18ms (+ 0.48%) 3,641ms 3,661ms
Req 2 - geterr 1,571ms (± 1.09%) 1,561ms (± 0.84%) -9ms (- 0.59%) 1,549ms 1,583ms
Req 3 - references 110ms (± 2.15%) 112ms (± 1.04%) +2ms (+ 1.97%) 111ms 114ms
Req 4 - navto 342ms (± 1.04%) 341ms (± 1.03%) -1ms (- 0.15%) 337ms 347ms
Req 5 - completionInfo count 3,171 (± 0.00%) 3,171 (± 0.00%) 0 ( 0.00%) 3,171 3,171
Req 5 - completionInfo 478ms (± 0.79%) 482ms (± 0.86%) +5ms (+ 0.98%) 478ms 489ms
Compiler-UnionsTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 2,906ms (± 0.35%) 2,907ms (± 0.40%) +1ms (+ 0.05%) 2,898ms 2,927ms
Req 2 - geterr 6,264ms (± 0.51%) 6,304ms (± 0.69%) +39ms (+ 0.63%) 6,242ms 6,351ms
Req 3 - references 388ms (± 0.70%) 391ms (± 0.38%) +3ms (+ 0.64%) 389ms 393ms
Req 4 - navto 282ms (± 1.73%) 284ms (± 1.23%) +2ms (+ 0.53%) 281ms 289ms
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) 0 ( 0.00%) 1,356 1,356
Req 5 - completionInfo 85ms (± 6.38%) 83ms (±10.65%) -1ms (- 1.58%) 73ms 93ms
CompilerTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 3,074ms (± 0.40%) 3,070ms (± 0.20%) -5ms (- 0.16%) 3,062ms 3,079ms
Req 2 - geterr 4,694ms (± 0.37%) 4,689ms (± 0.56%) -5ms (- 0.11%) 4,658ms 4,725ms
Req 3 - references 403ms (± 0.65%) 404ms (± 0.76%) +1ms (+ 0.12%) 400ms 407ms
Req 4 - navto 293ms (± 0.91%) 292ms (± 0.67%) -0ms (- 0.11%) 290ms 295ms
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) 0 ( 0.00%) 1,518 1,518
Req 5 - completionInfo 81ms (± 1.01%) 82ms (± 3.34%) +1ms (+ 1.24%) 80ms 87ms
xstateTSServer - node (v14.15.1, x64)
Req 1 - updateOpen 3,962ms (± 0.47%) 3,978ms (± 0.22%) +16ms (+ 0.40%) 3,967ms 3,988ms
Req 2 - geterr 1,524ms (± 2.03%) 1,505ms (± 0.67%) -19ms (- 1.23%) 1,488ms 1,517ms
Req 3 - references 132ms (± 2.25%) 133ms (± 0.74%) +1ms (+ 0.63%) 132ms 134ms
Req 4 - navto 374ms (± 0.57%) 373ms (± 1.30%) -1ms (- 0.22%) 364ms 377ms
Req 5 - completionInfo count 3,171 (± 0.00%) 3,171 (± 0.00%) 0 ( 0.00%) 3,171 3,171
Req 5 - completionInfo 505ms (± 2.35%) 510ms (± 1.97%) +5ms (+ 1.02%) 495ms 524ms
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.15.1, x64)
Scenarios
  • Compiler-UnionsTSServer - node (v18.10.0, x64)
  • Compiler-UnionsTSServer - node (v16.17.1, x64)
  • Compiler-UnionsTSServer - node (v14.15.1, x64)
  • CompilerTSServer - node (v18.10.0, x64)
  • CompilerTSServer - node (v16.17.1, x64)
  • CompilerTSServer - node (v14.15.1, x64)
  • xstateTSServer - node (v18.10.0, x64)
  • xstateTSServer - node (v16.17.1, x64)
  • xstateTSServer - node (v14.15.1, x64)
Benchmark Name Iterations
Current 52450 6
Baseline main 6

Startup

Comparison Report - main..52450
Metric main 52450 Delta Best Worst
tsc-startup - node (v16.17.1, x64)
Execution time 142.62ms (± 0.19%) 142.49ms (± 0.18%) -0.14ms (- 0.10%) 141.86ms 145.59ms
tsserver-startup - node (v16.17.1, x64)
Execution time 226.34ms (± 0.18%) 226.97ms (± 0.16%) +0.63ms (+ 0.28%) 225.96ms 232.82ms
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time 229.01ms (± 0.23%) 229.12ms (± 0.18%) +0.11ms (+ 0.05%) 228.24ms 236.45ms
typescript-startup - node (v16.17.1, x64)
Execution time 209.44ms (± 0.17%) 209.96ms (± 0.20%) +0.52ms (+ 0.25%) 209.10ms 217.08ms
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v16.17.1, x64)
Scenarios
  • tsc-startup - node (v16.17.1, x64)
  • tsserver-startup - node (v16.17.1, x64)
  • tsserverlibrary-startup - node (v16.17.1, x64)
  • typescript-startup - node (v16.17.1, x64)
Benchmark Name Iterations
Current 52450 6
Baseline main 6

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top-repos suite comparing main and refs/pull/52450/merge:

Everything looks good!

@evanw
Copy link
Contributor

evanw commented Jan 27, 2023

Thanks for looking at this!

I'm worried that this PR potentially makes these already-complicated rules too much more complicated. Previously you could definitively tell whether something is an arrow function in JSX or not by examining the next few tokens. I thought that property was kind of nice. But now it depends on a lot more code and arbitrary look-ahead, which adds many more additional ambiguities to resolve.

For example, this PR currently means the following:

// JSX
<T extends />;
<T extends {...x} />;
<T extends {...x}>() = {}</T>;

// arrow
<T extends {}>() => {};
<T extends {...x}>() => {};

Having to distinguish between <T extends {...x}>() = {}</T> and <T extends {...x}>() => {} seems like unnecessary complexity to me (i.e. it might mean a lot of additional work for me as the author of another TSX-to-JS transpiler). While {...x} isn't currently valid type syntax, I've seen some comments on this issue tracker that sound like it's not out of the question to add it, so it could actually come up in the future.

Anyway, I thought I'd put a plug in for keeping the look-ahead rules for this edge case simple like they were before, instead of (as far as I understand) now requiring unbounded look-ahead and relying on the full details of TypeScript's arrow function parser (including error-recovery for invalid syntax).

It probably doesn't matter too much what's done here IMO since this is an edge case as long as the internal compiler error is fixed. But I was expecting something like the addition of a rule for the / token which would return false from isArrowFunctionInJsx.

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top-repos suite comparing main and refs/pull/52450/merge:

Everything looks good!

@jakebailey
Copy link
Member Author

I can understand that; having fixed numerous bugs in this same place it's getting a little frustrating.

I'll try and see if there's a more straightforward way here, but I'm having a little bit of a hard time thinking of how to do it.

@evanw
Copy link
Contributor

evanw commented Jan 27, 2023

Some quick thoughts (feel free to disregard). The internal compiler error could potentially be fixed like this:

 export function rangeOfTypeParameters(sourceFile: SourceFile, typeParameters: NodeArray<TypeParameterDeclaration>): TextRange {
     // Include the `<>`
     const pos = typeParameters.pos - 1;
-    const end = skipTrivia(sourceFile.text, typeParameters.end) + 1;
+    const end = Math.min(sourceFile.text.length, skipTrivia(sourceFile.text, typeParameters.end) + 1);
     return { pos, end };
 }

And if you wanted to add support for the <T extends /> case, it could potentially be added like this:

 const isArrowFunctionInJsx = lookAhead(() => {
     parseOptional(SyntaxKind.ConstKeyword);
     const third = nextToken();
     if (third === SyntaxKind.ExtendsKeyword) {
         const fourth = nextToken();
         switch (fourth) {
             case SyntaxKind.EqualsToken:
             case SyntaxKind.GreaterThanToken:
+            case SyntaxKind.SlashToken:
                 return false;
             default:
                 return true;
         }
     }
     else if (third === SyntaxKind.CommaToken || third === SyntaxKind.EqualsToken) {
         return true;
     }
     return false;
 });

@jakebailey
Copy link
Member Author

Oh, funny. I should have tried the latter (I later tried nearly the same thing to fix that other oddity you changed esbuild to match TypeScript on). I'll try it out in the morning.

@jakebailey
Copy link
Member Author

That suggestion worked great, thanks!

I don't think we need to modify rangeOfTypeParameters, actually; the parser fix means the bad tree no longer appears, so the crash doesn't occur.

@evanw
Copy link
Contributor

evanw commented Jan 27, 2023

I don't think we need to modify rangeOfTypeParameters, actually; the parser fix means the bad tree no longer appears, so the crash doesn't occur.

The crash can still occur in other cases such as <T extends /=>. Up to you whether you think that's important enough to fix or not (I don't have enough context).

@jakebailey
Copy link
Member Author

Ah, you're totally right. I'll add that; we definitely don't want more crashes, even if the code doesn't parse.

@jakebailey jakebailey changed the title Prevent valid JSX from being seen as the start of a generic arrow function Prevent valid JSX from being seen as the start of a generic arrow function, fix crashes Jan 27, 2023
@jakebailey
Copy link
Member Author

jakebailey commented Jan 27, 2023

I checked, and your suggested fix is again good; this probably fixes other potential crashes for users of this function in the LS. There's one other place which does a skipTrivia+1 but it's in a place where it's impossible for the file to have ended.

@jakebailey jakebailey merged commit 9584055 into microsoft:main Feb 1, 2023
@jakebailey jakebailey deleted the fix-52449 branch February 1, 2023 00:55
evanw added a commit to evanw/esbuild that referenced this pull request Feb 1, 2023
This adjusts esbuild's behavior to match the changes to the TypeScript compiler that were introduced by microsoft/TypeScript#52450.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TS 5.0 internal compiler error: "Debug Failure. Expected 20 <= 19"
4 participants