microsoft / microsoft/monaco-editor

[Bug] Infinite recursion in TS worker

Open
#4,802 0 comments 0 reactions 0 assignees View on GitHub

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?
Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.52.2#XQAAAAJtAQAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscwzdYgm_1uhs0-3YGTBOsVJ4S4FwfCDQb5-2uUHXTVAefbVSd9IzaZ_vv9VR9KugsKimARHSWlrTPOQHROITHxmAevjJc6KddXWSN1sNwo5JNIgnYWKVmhb0B1SfnroyskXT-0iPN9Jt1ESDDhIFdl9bHkBkOA5r_rmys3ebjP0E59AKwWFt5EBjYnSrRhXL7kWpFwHklYQ1hQUn91POVdA_jOUWtLDn3wCOoajEAmWD58rw5EDD5f2ooMfBxDBAf7mH6cCx3rmhaggrs9a7igEnEmz8gXYmi1SLP36zjlnshLlgjSTmr_6Garow

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.

Image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.