Incorrect focus position and crash with multiline comments in `parser/typescript`
### Describe the bug
I've noticed that the current `parser/typescript` for JavaScript behaves a bit unexpectedly when determining the auto focus location. For example:
<img width="1440" height="900" alt="Image" src="https://github.com/user-attachments/assets/44bfed46-0139-490d-928f-2b706197cc90" />
👉 [Reproduction](https://ast-explorer.dev/#eNqrVspRslLKSixLLE4uyiwoUdJRKgAKlFQWpMIFkoECQCofSFXH5CkoxCjlJOallyamp4alFhVn5ufFKFkpWFrqQOQg2rwz81JAwsYxebVKtQB8bCBZ)
In contrast, the same position on [astexplorer.net](https://astexplorer.net/) maps to:
<img width="1440" height="900" alt="Image" src="https://github.com/user-attachments/assets/3512dcf5-f99d-4252-ac91-0b6991734d80" />
👉 [Reproduction](https://astexplorer.net/#/gist/e6565a61f2a70c0e516d48c1a99c0de5/latest)
I'm not sure if this is a bug, but I looked into the implementation of astexplorer.net and found that `parser/typescript` includes additional checks using `getStart` and `getEnd`.
Here's the expected position after applying that logic:
<img width="1440" height="900" alt="Image" src="https://github.com/user-attachments/assets/baa80240-18e7-4f02-970b-e4dfe1c369a7" />
This also resolves an issue where using multi-line comments with `parser/typescript` can cause the page to crash:
⚠️ Clicking this may cause the AST Explorer page to become unresponsive. [Reproduction](https://ast-explorer.dev/#eNpNklFrGzEQhP/KVBRiO8Z5KBTikkIphtK+FBwKpSpE0a3vlMq7h6Szcxj/964uEOfhOLTab3ZG7MlEszZP7uCyT6EvZml6LZSxp9eC18LNYmEZC/x0uRAkoUnSI8ue8F3h7dSLjhLBcQN67qMkmpDSEfLIxT2jJCL4RK5Qg8cRvpNMjN6lTGk1df+WAd4xhqxKMU60F4lgOmKn5JAoY5dkj83244RMAw+qs9eRK2z4ScZ39ebGsuVIBSX0GXf4o0VY8zUG/w/CCo74sr0HS0M4htLB4er6CkVqgCobijXLqlK5b3KgFLhF/WvrhHWh7aJ+JU9Wra296jipzV64qf1RvCtBBwZ+eQ0Zkq+xGnojv+3CrsBfzF28XQxV/NhJVJHhsT6nNZb/fqoau4H9NKVXk+VeI8/mOFXtGn+1k7RxvpvN9LREmOPuszrgrFqrKO3sQQm8P4Xz+gHXFZnPVfZsWTdAdAMmJWui43ZwLf2ilHWYNWvc3mqGeveyMT8CN7X8QWlz/g+jRc2t)
**Before**
<img width="1440" height="900" alt="Image" src="https://github.com/user-attachments/assets/81d75da3-dc34-48d6-a841-317bc0cc4906" />
**After**
<img width="1440" height="900" alt="Image" src="https://github.com/user-attachments/assets/4d25928c-f8f9-45d8-8266-273644e56f84" />
### Reproduction
https://ast-explorer.dev/#eNqrVspRslLKSixLLE4uyiwoUdJRKgAKlFQWpMIFkoECQCofSFXH5CkoxCjlJOallyamp4alFhVn5ufFKFkpWFrqQOQg2rwz81JAwsYxebVKtQB8bCBZ
### System Info
```Shell
System:
OS: macOS 15.5
CPU: (8) arm64 Apple M1
Memory: 428.94 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
npm: 11.4.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
pnpm: 10.14.0 - ~/.nvm/versions/node/v22.14.0/bin/pnpm
Browsers:
Edge: 138.0.3351.121
Safari: 18.5
Safari Technology Preview: 18.0
```
### Used Package Manager
npm
### Validations
- [x] Follow our [Code of Conduct](https://github.com/sxzz/.github/blob/main/CODE_OF_CONDUCT.md)
- [x] Read the [Contributing Guide](https://github.com/sxzz/contribute).
- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
- [x] The provided reproduction is a [minimal reproducible](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
0 条评论