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
Using setIsAsync(true) on an ArrowFunction (which indirectly calls addModifier) can result in an error due to incorrect insertion of the async keyword.
To Reproduce
Self-contained reproduction file:
import{Node,Project}from"ts-morph";constproject=newProject();constfileText=`const f = a => a * 2;`;constsourceFile=project.createSourceFile("main.js",fileText);sourceFile.forEachDescendant((node)=>{if(Node.isArrowFunction(node)){node.setIsAsync(true);}});
This results in:
ManipulationError: Manipulation error: A syntax error was inserted.
main.js:1:13 - error TS1005: ',' expected.
1 const f = a async => a * 2;
~~~~~
main.js:1:19 - error TS1005: ';' expected.
1 const f = a async => a * 2;
~~
Error replacing tree: The children of the old and new trees were expected to have the same count (2:3).
-- Details --
Path: repro/main.js
Text: "const f = a async => a * 2;"
Stack: Error: Error replacing tree: The children of the old and new trees were expected to have the same count (2:3).
at #handleChildren (repro/node_modules/ts-morph/dist/ts-morph.js:1469:19)
at ParentFinderReplacementNodeHandler.handleNode (repro/node_modules/ts-morph/dist/ts-morph.js:1463:33)
at ParentFinderReplacementNodeHandler.handleNode (repro/node_modules/ts-morph/dist/ts-morph.js:1620:19)
at doManipulation (repro/node_modules/ts-morph/dist/ts-morph.js:2364:21)
at insertIntoParentTextRange (repro/node_modules/ts-morph/dist/ts-morph.js:2398:5)
at ArrowFunction.addModifier (repro/node_modules/ts-morph/dist/ts-morph.js:9175:13)
at ArrowFunction.toggleModifier (repro/node_modules/ts-morph/dist/ts-morph.js:9152:22)
at ArrowFunction.setIsAsync (repro/node_modules/ts-morph/dist/ts-morph.js:2884:18)
at file://repro/arrow.mjs:9:10
at nodeCallback (repro/node_modules/ts-morph/dist/ts-morph.js:3345:33)
at throwError (repro/node_modules/ts-morph/dist/ts-morph.js:2380:19)
at doManipulation (repro/node_modules/ts-morph/dist/ts-morph.js:2374:13)
at insertIntoParentTextRange (repro/node_modules/ts-morph/dist/ts-morph.js:2398:5)
at ArrowFunction.addModifier (repro/node_modules/ts-morph/dist/ts-morph.js:9175:13)
at ArrowFunction.toggleModifier (repro/node_modules/ts-morph/dist/ts-morph.js:9152:22)
at ArrowFunction.setIsAsync (repro/node_modules/ts-morph/dist/ts-morph.js:2884:18)
at file://repro/arrow.mjs:9:10
at nodeCallback (repro/node_modules/ts-morph/dist/ts-morph.js:3345:33)
at repro/node_modules/ts-morph/dist/ts-morph.js:3386:37
at VariableDeclaration.forEachChild (repro/node_modules/ts-morph/dist/ts-morph.js:3325:37) {
filePath: 'repro/main.js',
oldText: 'const f = a => a * 2;',
newText: 'const f = a async => a * 2;'
}
Node.js v20.18.0
Expected behavior
I would expect the resulting file to be const f = async a => a * 2;.
The text was updated successfully, but these errors were encountered:
Describe the bug
Version: 24.0.0 (latest)
Using
setIsAsync(true)
on anArrowFunction
(which indirectly callsaddModifier
) can result in an error due to incorrect insertion of theasync
keyword.To Reproduce
Self-contained reproduction file:
This results in:
Expected behavior
I would expect the resulting file to be
const f = async a => a * 2;
.The text was updated successfully, but these errors were encountered: