Skip to content

'Debug Failure: Unexpected Node' when using a JSDoc type with a decorator #37276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
refi64 opened this issue Mar 7, 2020 · 0 comments · Fixed by #37836
Closed

'Debug Failure: Unexpected Node' when using a JSDoc type with a decorator #37276

refi64 opened this issue Mar 7, 2020 · 0 comments · Fixed by #37836
Assignees
Labels
Bug A bug in TypeScript

Comments

@refi64
Copy link

refi64 commented Mar 7, 2020

TypeScript Version: Nightly, 3.8.3

Search Terms: jsdoc, "unexpected node"

Expected behavior: Compilation to show an error. (I accidentally used a JSDoc type, jumping between too many different languages at once...)

Actual behavior: TypeScript crashed, from the CLI it crashed even before any diagnostics were printed:

/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:81040
                throw e;
                ^

Error: Debug Failure. Unexpected node.
Node 297 was unexpected.
    at serializeTypeNode (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64374:37)
    at serializeTypeOfNode (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64249:28)
    at addOldTypeMetadata (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64191:92)
    at addTypeMetadata (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64185:17)
    at transformAllDecoratorsOfDeclaration (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64104:13)
    at generateClassElementDecorationExpression (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64129:40)
    at generateClassElementDecorationExpressions (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64115:34)
    at addClassElementDecorationStatements (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:64108:44)
    at visitClassDeclaration (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:63906:13)
    at visitTypeScript (/var/home/ryan/code/bkglass/proxissh/node_modules/typescript/lib/tsc.js:63795:28)
error Command failed with exit code 1.

From the playground, the error is a bit different and a diagnostic is shown first:

Uncaught (in promise) Error: Debug Failure. Unexpected node.
Node JSDocNullableType was unexpected.
    at ae (tsWorker.js:21)
    at ne (tsWorker.js:21)
    at tsWorker.js:21
    at tsWorker.js:21
    at q (tsWorker.js:21)
    at X (tsWorker.js:21)
    at tsWorker.js:21
    at J (tsWorker.js:21)
    at tsWorker.js:21
    at F (tsWorker.js:21)

Related Issues: #27999 seems similar

Code

declare function decorator(): PropertyDecorator

class X {
    @decorator()
    foo?: string?
}

Note that this requires emitDecoratorMetadata: true and experimentalDecorators: true.

Output
"use strict";
X;
{
    foo ?  : string ?
        :
    ;
}
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "useDefineForClassFields": false,
    "alwaysStrict": true,
    "allowUnreachableCode": false,
    "allowUnusedLabels": false,
    "downlevelIteration": false,
    "noEmitHelpers": false,
    "noLib": false,
    "noStrictGenericChecks": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "esModuleInterop": true,
    "preserveConstEnums": false,
    "removeComments": false,
    "skipLibCheck": false,
    "checkJs": false,
    "allowJs": false,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "ES2017",
    "module": "ESNext"
  }
}

Playground Link: Provided

EDIT: Please ignore the title rename, I hit Enter too soon by accident...

@refi64 refi64 changed the title Debug Failure: Unexpected Node 'Debug Failure: Unexpected Node' when using a JSDoc type with a decorator Mar 7, 2020
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Mar 12, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.9.1 milestone Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants