microsoft / microsoft/TypeScript
Automatic Brace Insertion (ABI) is undesirable
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.7-beta
Search Terms: automatic brace insertion ABI syntax error
Code:
function a() {
"Automatic Brace Insertion! (ABI)";
Expected behavior:
The input is syntactically invalid, so emit should fail regardless of the state of noEmitOnError. Other forms of un-parsable input already do this, e.g. function a(
Actual behavior:
A closing brace is inserted in the emitted JS code.
function a() {
"Automatic Brace Insertion! (ABI)";
}
This means that users who are not using noEmitOnError are silently having invalid code transformed into valid code. I can confirm this actually happened to someone shipping something to production.
Playground Link: ABI Playground Link
Related Issues: https://github.com/microsoft/TypeScript/issues/34870 , https://github.com/microsoft/TypeScript/issues/34871 , Lazy Twitter report
I would suggest this bug deserves to be fixed based on Design Goal 7 (Preserve runtime behavior of all JavaScript code) and Design Non-Goal 7 (Introduce behaviour that is likely to surprise users).
Tagline: If the braces don't fit, you must not emit.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ABI Playground Link and the minimal TypeScript input shown in the issue, then compare its emit behavior with the linked unterminated-function example. Trace the compiler's handling of this malformed input and verify that emit does not add a closing brace or produce runnable JavaScript.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100