Skip to content

tsc 2.5.1 crashes with error: TypeError: Cannot read property '240' of undefined. #17982

Closed
@svstanev

Description

@svstanev

The problem appears to be invoking the getDeclarationSpaces (tsc.js:33049) function with a node of kind 240 (NamespaceImport). For some reason the ts.SyntaxKind enum is missing thus the error. In this case (d.kind === 240) the default switch clause is triggered which either way appears to be an error. The same source code compiles just fine with tsc v2.4.2 though. At first glance the getDeclarationSpaces function seems to be changed in the latest version while the node its been called with appears pretty much the same.

As of now I have no clue which part of my source code is related to problem. What I've found so far is that the error appears while processing a .ts source file that has these two imports:

...

import * as Header from './header'
import * as Signal from './signal'

...

and the node in question (NamespaceImport) has a symbol named 'Signal' so I can only guess that the issue may have be related to the 2nd line from the snippet above.

TypeScript Version: 2.5.1

Code

tsc.js v2.5.1:

            function getDeclarationSpaces(d) {
                switch (d.kind) {
                    case 230:
                    case 231:
                        return 2;
                    case 233:
                        return ts.isAmbientModule(d) || ts.getModuleInstanceState(d) !== 0
                            ? 4 | 1
                            : 4;
                    case 229:
                    case 232:
                        return 2 | 1;
                    case 237:
                        var result_3 = 0;
                        var target = resolveAlias(getSymbolOfNode(d));
                        ts.forEach(target.declarations, function (d) { result_3 |= getDeclarationSpaces(d); });
                        return result_3;
                    case 226:
                    case 176:
                    case 228:
                    case 242:
                        return 1;
                    default:
                        ts.Debug.fail(ts.SyntaxKind[d.kind]); // TypeError: Cannot read property '240' of undefined
                }
            }

Expected behavior:

Actual behavior:

TypeError: Cannot read property '240' of undefined
    at getDeclarationSpaces (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:33072:52)
    at checkExportsOnMergedDeclarations (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:33019:41)
    at checkInterfaceDeclaration (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:34711:17)
    at checkSourceElement (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:35450:28)
    at Object.forEach (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:275:30)
    at checkSourceFileWorker (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:35517:20)
    at checkSourceFile (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:35502:13)
    at getDiagnosticsWorker (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:35555:17)
    at Object.getDiagnostics (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:35544:24)
    at /Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:56140:85
    at runWithCancellationToken (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:56118:24)
    at getSemanticDiagnosticsForFileNoCache (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:56132:20)
    at getAndCacheDiagnostics (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:56340:26)
    at getSemanticDiagnosticsForFile (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:56129:20)
    at /Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:56086:24
    at Object.flatMap (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:507:25)
    at getDiagnosticsHelper (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:56082:56)
    at Object.getSemanticDiagnostics (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:56093:20)
    at compileProgram (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:59083:43)
    at compile (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:59040:26)
    at performCompilation (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:58929:33)
    at Object.executeCommandLine (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:58872:9)
    at Object.<anonymous> (/Users/svstanev/work/myproj/node_modules/typescript/lib/tsc.js:59230:4)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/svstanev/work/myproj/node_modules/typescript/bin/tsc:2:1)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:425:7)
    at startup (bootstrap_node.js:146:9)
    at bootstrap_node.js:540:3

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions