Skip to content

RangeError: Maximum call stack size exceeded #36608

@longfeng-li

Description

@longfeng-li

TypeScript Version: 3.4.5

Search Terms:
I was trying to convert ION to JSON using recursive function. My recursive function only have at most 10 layers depth. I don't know why it returns stack over flow error. If My ION file has less 1000 lines, this code works. However if the file contains more than 1200 lines, it return stack errors.

Code
const getJsonFromIonReader = function(reader) {
console.log('count: ', count++);
const ionType = reader.type();

if (ionType.name === 'struct') {
const result = {};

reader.stepIn();
let current = reader.next();
while (current != undefined) {
  result[reader.fieldName()] = getJsonFromIonReader(reader);
  current = reader.next();
}
reader.stepOut();
return result;

} else if (ionType.name === 'list') {
const result = [];
reader.stepIn();
let current = reader.next();
while (current != undefined) {
result.push(getJsonFromIonReader(reader));
current = reader.next();
}
reader.stepOut();
return result;
} else if (ionType.name === 'null') {
return null;
} else if (ionType.name === 'int') {
return reader.numberValue();
} else if (ionType.name === 'bool') {
return reader.booleanValue();
} else if (ionType.name === 'timestamp') {
return reader.timestampValue().toString();
} else if (ionType.name === 'decimal') {
return reader.decimalValue().toString();
} else if (ionType.isScalar === true) {
return reader.stringValue();
}
throw new Error('encountered an ionType that is not handled: ' + ionType);
};

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.

Expected behavior:
It should be able to convert ION to JSON for at least 4000 lines file

Actual behavior:
It fails when the files size it more than 1000 lines

RangeError: Maximum call stack size exceeded

  at checkExpressionWorker (node_modules/typescript/lib/typescript.js:52222:28)
  at checkExpression (node_modules/typescript/lib/typescript.js:52185:42)
  at checkBinaryLikeExpression (node_modules/typescript/lib/typescript.js:51650:28)
  at checkBinaryExpression (node_modules/typescript/lib/typescript.js:51638:20)
  at checkExpressionWorker (node_modules/typescript/lib/typescript.js:52281:28)
  at checkExpression (node_modules/typescript/lib/typescript.js:52185:42)
  at checkBinaryLikeExpression (node_modules/typescript/lib/typescript.js:51650:28)
  at checkBinaryExpression (node_modules/typescript/lib/typescript.js:51638:20)
  at checkExpressionWorker (node_modules/typescript/lib/typescript.js:52281:28)
  at checkExpression (node_modules/typescript/lib/typescript.js:52185:42)

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs More InfoThe issue still hasn't been fully clarified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions