microsoft / microsoft/monaco-editor
[Bug] Infinite recursion in TS worker
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 46.8k
- Forks
- 4.1k
- Avg merge
- 17h 58m
- Merged PRs (30d)
- 1
Description
Reproducible in vscode.dev or in VS Code Desktop?
- Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
- Not reproducible in the monaco editor playground
Monaco Editor Playground Link
Monaco Editor Playground Code
const value = /* set from `myEditor.getModel()`: */ `function hello() {
for (let foo of foo) { foo(); bar; };
}`;
// Hover on each property to see its docs!
const myEditor = monaco.editor.create(document.getElementById("container"), {
value,
language: "javascript",
automaticLayout: true,
});
Reproduction Steps
Open the playground link and check the developer console.
Uncaught (in promise) RangeError: Maximum call stack size exceeded
at isDeclarationWithExplicitTypeAnnotation (tsWorker.js:73813:55)
at getExplicitTypeOfSymbol (tsWorker.js:73830:17)
at getTypeOfDottedName (tsWorker.js:73862:22)
at getExplicitTypeOfSymbol (tsWorker.js:73835:38)
at getTypeOfDottedName (tsWorker.js:73862:22)
at getExplicitTypeOfSymbol (tsWorker.js:73835:38)
at getTypeOfDottedName (tsWorker.js:73862:22)
at getExplicitTypeOfSymbol (tsWorker.js:73835:38)
at getTypeOfDottedName (tsWorker.js:73862:22)
at getExplicitTypeOfSymbol (tsWorker.js:73835:38)
Actual (Problematic) Behavior
An uncaught error is thrown.
Expected Behavior
No uncaught error.
Additional Context
We use monaco in our game to provide an in-game code editor. A player reported a problem with the in-game editor. In our game, we have a global exception handler. When monaco throws this uncaught error, an error popup is shown.
The MRE uses the player-provided script. I know that for (let foo of foo) { foo(); bar; }; is not valid JS code. Another example:
const a = [() => { }];
const b = 0;
for (const a of a) { a(); b }
This is still not valid JS code (ReferenceError: Cannot access 'a' before initialization), but having an uncaught error is unexpected.
It looks like that monaco is trying to "diagnose" the provided code, and this error is thrown by the TS worker. I'm not sure if this problem should be reported here or at https://github.com/microsoft/TypeScript (the infinite recursion is in https://github.com/microsoft/TypeScript/blob/main/src/compiler/checker.ts).
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 linked Monaco Editor Playground reproduction and inspect the TS worker stack trace, especially isDeclarationWithExplicitTypeAnnotation, getExplicitTypeOfSymbol, and getTypeOfDottedName. Then compare the recursion in TypeScript's src/compiler/checker.ts. Done means the provided invalid JavaScript examples produce diagnostics without an uncaught RangeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100