Typescript: Compiler hang when importing big JS file with --allowJs

Created on 8 Jul 2017  ·  3Comments  ·  Source: microsoft/TypeScript

TypeScript Version: 2.4.1

Repro project
When importing a big JS file (a working parser) (245 Kbytes commonjs format) (with --allowJs enabled) the compiler hangs forever. Minimal repro project provided: tsc-hang-00

Expected behavior:
Compilations ends with or without errors.

Actual behavior:
Compilations hangs forever and keeps consuming CPU.

Tests conditions

  • Windows 10, NodeJS 8.0, TS 2.4.1
  • Travis: Linux Container, NodeJS 8.0, TS 2.4.1
Bug

Most helpful comment

Heya, just wanted to say I have another, simpler repro at https://github.com/filipesilva/tsc-allowjs-big-file. It was inspired by @dzonatan's repro at https://github.com/angular/angular-cli/issues/9636#issuecomment-390203543.

It just has a class with a thousand methods:

export class BigClass {
  myVar: any;

  method000() { return this.myVar; }
  method001() { return this.myVar; }
  // ...
  method999() { return this.myVar; }
}

Running npm test on that repository will compile this typescript file to javascript, and then compile the resulting javascript file with --allowJs.

This yields the RangeError: Maximum call stack size exceeded error with TS 2.7.2 and 2.8.4. However, with TS 2.9.1, no error is thrown and compilation succeeds.

All 3 comments

I tried to profile what's going on here and trying to capture a CPU profile for any length of time (even 1s) will cause the Chrome profiler to crash while processing the CPU profile.

Profiling probably isn't useful for a 245k file — it's usually a bug or an algorithmic performance problem, both of which usually express themselves as very deep stacks. My initial debugging method is to start debugging and just pause a few times. I'll fall back to profiling (or printf debugging of caches) if there doesn't seem to be a pattern in the locations.

There are two relevant meanings of 'location': which node is currently being checked, and where the instruction pointer is when debugging is paused.

Heya, just wanted to say I have another, simpler repro at https://github.com/filipesilva/tsc-allowjs-big-file. It was inspired by @dzonatan's repro at https://github.com/angular/angular-cli/issues/9636#issuecomment-390203543.

It just has a class with a thousand methods:

export class BigClass {
  myVar: any;

  method000() { return this.myVar; }
  method001() { return this.myVar; }
  // ...
  method999() { return this.myVar; }
}

Running npm test on that repository will compile this typescript file to javascript, and then compile the resulting javascript file with --allowJs.

This yields the RangeError: Maximum call stack size exceeded error with TS 2.7.2 and 2.8.4. However, with TS 2.9.1, no error is thrown and compilation succeeds.

Was this page helpful?
0 / 5 - 0 ratings