You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm kind of short of time to investigate this further - so I just report it so I don't loose track of this: If you try to addStatement() to a target method/function/arrow that is already indented it will break:
importProjectfrom'ts-simple-ast'constproject=newProject()constsourceFile=project.createSourceFile('created.ts',`function nonIndented(){} function indentedF(){ }`)sourceFile.getFunction('nonIndented').addStatements('return null;')console.log(sourceFile.getText())sourceFile.getFunction('indentedF').addStatements('return null;')console.log(sourceFile.getText())
calling addStatements on nonIndented function works nut on indentedF fails throwing this exceptino:
/home/sg/git/typescript-plugins-of-mine/typescript-plugin-proactive-code-fixes/node_modules/code-block-writer/dist/code-block-writer.js:380
this._text += Array(this._currentIndentation + 1).join(this._indentationText);
^
RangeError: Invalid array length
at CodeBlockWriter._writeIndentation (/home/sg/git/typescript-plugins-of-mine/typescript-plugin-proactive-code-fixes/node_modules/code-block-writer/dist/code-block-writer.js:380:23)
at CodeBlockWriter.writeIndividual (/home/sg/git/typescript-plugins-of-mine/typescript-plugin-proactive-code-fixes/node_modules/code-block-writer/dist/code-block-writer.js:317:26)
at /home/sg/git/typescript-plugins-of-mine/typescript-plugin-proactive-code-fixes/node_modules/code-block-writer/dist/code-block-writer.js:311:29
at Array.forEach (<anonymous>)
at CodeBlockWriter._writeIndentingNewLines (/home/sg/git/typescript-plugins-of-mine/typescript-plugin-proactive-code-fixes/node_modules/code-block-writer/dist/code-block-writer.js:306:15)
at CodeBlockWriter.write (/home/sg/git/typescript-plugins-of-mine/typescript-plugin-proactive-code-fixes/node_modules/code-block-writer/dist/code-block-writer.js:216:14)
at printTextFromStringOrWriter (/home/sg/git/typescript-plugins-of-mine/typescript-plugin-proactive-code-fixes/node_modules/ts-simple-ast/dist/utils/getTextFromStringOrWriter.js:11:16)
at Object.getTextFromStringOrWriter (/home/sg/git/typescript-plugins-of-mine/typescript-plugin-proactive-code-fixes/node_modules/ts-simple-ast/dist/utils/getTextFromStringOrWriter.js:5:5)
at SyntaxList.insertChildText (/home/sg/git/typescript-plugins-of-mine/typescript-plugin-proactive-code-fixes/node_modules/ts-simple-ast/dist/compiler/common/SyntaxList.js:22:34)
at FunctionDeclaration.StatementedNode.class_1.insertStatements (/home/sg/git/typescript-plugins-of-mine/typescript-plugin-proactive-code-fixes/node_modules/ts-simple-ast/dist/compiler/statement/StatementedNode.js:37:53)
The text was updated successfully, but these errors were encountered:
Thanks! I took a look and it's because the result of getting the indentation is 1.5. I didn't know it could be that. I'll fix code-block-writer to handle this situation.
dsherret
changed the title
addStatements fails if target method/function/arrow have 1 or more indentation levels
addStatements fails if containing block is only indented a portion of an indentation level
May 28, 2018
I'm kind of short of time to investigate this further - so I just report it so I don't loose track of this: If you try to addStatement() to a target method/function/arrow that is already indented it will break:
calling addStatements on nonIndented function works nut on indentedF fails throwing this exceptino:
The text was updated successfully, but these errors were encountered: