microsoft/TypeScript

Decorator declaration inside a function causes the typescript language server to crash

Closed this issue ยท 3 comments

๐Ÿ”Ž Search Terms

decorator language server crash

๐Ÿ•— Version & Regression Information

  • This is the behavior in every version I tried (5.9.3 and 5.4.5), and I reviewed the FAQ for entries about "decorator"

โฏ Playground Link

https://www.typescriptlang.org/play/?#code/KYDwDg9gTgLgBAMwK4DsDGMCWEVwM4zBgAUMAhlAObAwBccxAdMxZXvWSgJ4DaAugEo4AXgB8cTlwA0cNDkIg6cAMIAbMnjwBZGgAsIAEwAiwOVDIxoy+aBhCA3gCg4LuFBpIouZOiw43ROpowAC2wCgwOjD6BkwsVOwS3A7OrmlyKARwKGRhInDRmHiMGQRQSBjQjDl5ANRwAESMDXD1xBkKMNW5wBJ4+DBQmCiUQvUNxC1trP0aA0MjY40CDQDcqWku7jCeuIQEjARExDXAMhpc6AxCYnBOmw8BO14SAO5kmPDkVDQlZKqqUi6IoyZiMGYCdaPOAAX0hG1h6xhjkcaHUmjgAGUIGE1Bp+vdXKVBhVLFBiGAkAAjVSYNABMgGHCqLhwMD0AAKZGoDmRCIAAkcwAiLldKBBLNiwlzqMRPKp6GVhqM7gi0oLCMLoWR3p8CsDimBGOLLHKoKp4WlkciXEA

๐Ÿ’ป Code

import { Page, test } from "@playwright/test";

export function step(target: (...args: any[]) => any, context: ClassMethodDecoratorContext) {
    return function replacementMethod(...args: any) {
        const name = this.constructor.name + "." + (context.name as string) + "(" + (args as string) + ")";
        return test.step(name, async () => {
            return await target.call(this, ...args);
        });
    };
}

class SomeClass {
    constructor(public readonly p: Page) {}

    @step
    async gotoSomePage(url: string) {
        @step
        await this.p.goto(url);
    }
}

๐Ÿ™ Actual behavior

when (by accident) a decorator method was added into a function (line 17 / line 15 in the TS Playground), the typescript language server just gives up and exits with SIGTERM.

๐Ÿ™‚ Expected behavior

mark the second decorator as wrong, or at least have the language-server exit SIGTERM with a more meaningful explanation into the Logfiles. Have it print out, in which location the language server failed. tsc just print "Error: Debug Failure. False expression."

In my Repo, I had 10 files changed and I was looking for 4 hours to find the issue.

Additional information about the issue

I uploaded this to a repository here: https://github.com/devilofhell/decorator-crashes-ts-language-service/blob/main/page.ts


Here is a picture of the VS Code log:
Image

Note: this only happens after you start VS Code, or open a new file, since only that triggers the language server to build up its content. VS Code just gives up after 5 retries.


here is the log file from /home/r975115/.vscode-server/data/logs/20251022T110530/exthost7/vscode.typescript-language-features/tsserver-log-cYXMY8/tsserver.log

tsserver.log


if executing tsc, it says nothing meaningful. no information why or where it crashed.

/home/r975115/Repositories/decorator-crashes-ts-language-service/node_modules/typescript/lib/_tsc.js:1284
    throw e;
    ^

Error: Debug Failure. False expression.
    at parseVariableDeclarationList (/home/r975115/Repositories/decorator-crashes-ts-language-service/node_modules/typescript/lib/_tsc.js:33762:15)
    at parseVariableStatement (/home/r975115/Repositories/decorator-crashes-ts-language-service/node_modules/typescript/lib/_tsc.js:33788:29)
    at parseDeclarationWorker (/home/r975115/Repositories/decorator-crashes-ts-language-service/node_modules/typescript/lib/_tsc.js:33602:16)
    at parseDeclaration (/home/r975115/Repositories/decorator-crashes-ts-language-service/node_modules/typescript/lib/_tsc.js:33584:14)
    at parseStatement (/home/r975115/Repositories/decorator-crashes-ts-language-service/node_modules/typescript/lib/_tsc.js:33537:16)
    at parseListElement (/home/r975115/Repositories/decorator-crashes-ts-language-service/node_modules/typescript/lib/_tsc.js:30115:12)
    at parseList (/home/r975115/Repositories/decorator-crashes-ts-language-service/node_modules/typescript/lib/_tsc.js:30100:19)
    at parseBlock (/home/r975115/Repositories/decorator-crashes-ts-language-service/node_modules/typescript/lib/_tsc.js:32993:26)
    at parseFunctionBlock (/home/r975115/Repositories/decorator-crashes-ts-language-service/node_modules/typescript/lib/_tsc.js:33024:19)
    at parseFunctionBlockOrSemicolon (/home/r975115/Repositories/decorator-crashes-ts-language-service/node_modules/typescript/lib/_tsc.js:33667:12)

the barebones repro is just this:

@dec
await 1

This is fixed in TS7.

a.ts:1:1 - error TS1206: Decorators are not valid here.

1 @dec
  ~

Given how unlikely this mistake is, I don't think this warrants trying to fix in the 5.9/6 codebase, so we'll call this "fixed in a future release"

Never mind, that linked fix is obviously correct