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
Error received: "Error: The parent was not a syntax kind of CallExpression."
When using getParentIfKindOrThrow, this sometimes throws on the callExpression syntax. This seems to occur depending on the length of the script.
To Reproduce
import{Project}from"ts-morph";constgenerateSourceFile=(script: string): SourceFile=>{constproject=newProject({useInMemoryFileSystem: true});project.createSourceFile("script.ts",script)constsourceFile=project.getSourceFileOrThrow("script.ts");returnsourceFile;}// This script throws...constscript=`declare function getSomeField(id: string): boolean;getSomeField(“abcdefg wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww”);`constsourceFile=generateSourceFile(script);constfunc=sourceFile.getFunction("getSomeField");try{constgetFieldByIdNodes=func?.findReferencesAsNodes();for(constnodeofgetFieldByIdNodes){constcallExpression=node.getParentIfKindOrThrow(SyntaxKind.CallExpression);
....}}catch(err){console.log(error);}
But updating script to be:
const script = \n declare function getSomeField(id: string): boolean;getSomeField(“abcdefg wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww”); \n
Then it no longer throws.
Also adding in a few extra characters into the script such as:
const script = declare function getSomeField(id: string): boolean;getSomeField("abcdefg wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww zz"); results in it no longer throwing too.
Why would wrapping this in newline stop it from throwing?
The text was updated successfully, but these errors were encountered:
Describe the bug
Version: 20.0.0
Error received: "Error: The parent was not a syntax kind of CallExpression."
When using
getParentIfKindOrThrow
, this sometimes throws on thecallExpression
syntax. This seems to occur depending on the length of the script.To Reproduce
But updating
script
to be:const script =
\n declare function getSomeField(id: string): boolean;getSomeField(“abcdefg wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww”); \n
Then it no longer throws.
Also adding in a few extra characters into the script such as:
const script =
declare function getSomeField(id: string): boolean;getSomeField("abcdefg wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww zz");
results in it no longer throwing too.Why would wrapping this in newline stop it from throwing?
The text was updated successfully, but these errors were encountered: