microsoft / microsoft/TypeScript
`eval?.()` is now an indirect eval
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Bug Report
There has apparently been a recent change to the behavior of eval?.() in all major JavaScript engines. It is now considered an indirect eval instead of a direct eval. This behavior was changed in July 2020. TypeScript is still compiling it as a direct eval and I didn't see an issue about this, so I created this issue.
More context: https://bugs.chromium.org/p/v8/issues/detail?id=10630
🔎 Search Terms
optional chain direct indirect eval scope
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
globalThis.a = "global";
(a => eval?.("console.log(a)"))("local");
🙁 Actual behavior
When compiled with TypeScript, this prints local instead. That matches the behavior of older JavaScript runtimes such as node v14 but doesn't match the latest JavaScript runtimes.
🙂 Expected behavior
This code now prints global when run in an up-to-date browser or in node v15, so it should print global when compiled with TypeScript as well.
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 by compiling and running the provided Playground example in a current JavaScript runtime, then compare the emitted JavaScript with the reported global-versus-local result. The payload names no source files or tests, so locate the compiler path handling optional-call expressions and add coverage showing the expected indirect-eval behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100