TypeScript ``` RangeError: 最大调用堆栈大小超过 ```

ryoqjall  于 2个月前  发布在  TypeScript
关注(0)|答案(2)|浏览(31)

TypeScript版本:3.4.5
搜索关键词:将ION转换为JSON的递归函数。我的递归函数最多只有10层深度。我不知道为什么它会返回堆栈溢出错误。如果我的ION文件少于1000行,这段代码就可以正常工作。然而,如果文件包含超过1200行,它就会返回堆栈错误。
代码:

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.


预期行为:
它应该能够将至少4000行的ION转换为JSON
实际行为:
当文件大小超过1000行时,它就会失败。RangeError:最大调用堆栈大小超出范围

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)


练习链接:
相关问题:
0aydgbwb

0aydgbwb1#

I found that for some reason, TypeScript can't load my 'structured' ION string. I need to remove all the space and /n

rur96b6h

rur96b6h2#

应该由#36248修复。无论如何,3.4.5在这一点上相当陈旧;一个在新版本上的可复现样本将是很好的。

相关问题