Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding functions from typescript lib files to analysis #18748

Open
michelledaviest opened this issue Feb 12, 2025 · 2 comments
Open

Adding functions from typescript lib files to analysis #18748

michelledaviest opened this issue Feb 12, 2025 · 2 comments
Labels
question Further information is requested

Comments

@michelledaviest
Copy link

Hello,

I want to be able to get the CallSignatureType for functions defined in the typescript lib files. I can't seem to get this to work. However, getting the getReturnTypeAnnotation seems to work for some functions. Please let me know how to add typescript lib files to my analysis so I can get call signatures consistently. Do I have to copy over the .d.ts files from the typescript source?

JavaScript file:

let x = BigInt.asUintN(64, 0); 

let cachedTextEncoder = new TextEncoder('utf-8');
let y = cachedTextEncoder.encode("hi")

The following CodeQL query returns no results:

from Function called_function, CallExpr call
where called_function.getName() = call.getCalleeName() 
select call, called_function.getCallSignature()

The following CodeQL query returns results for the cachedTextEncoder.encode call:

from Function called_function, CallExpr call
where called_function.getName() = call.getCalleeName() 
select call, called_function.getCallSignature()

I am building the codeql database as follows after running tsc --init in the directory with the js file I want to analyze.

codeql database create --language=javascript -- ql_db

Thank you!

@michelledaviest michelledaviest added the question Further information is requested label Feb 12, 2025
@asgerf
Copy link
Contributor

asgerf commented Feb 12, 2025

getCallSignature only has results for functions in TypeScript files, that is, files with the extension .ts or .tsx. Could you double check if the files have this extension?

@michelledaviest
Copy link
Author

michelledaviest commented Feb 12, 2025

Yes, both have .ts files. The typescript source that has the call signature for

  • BigInt.asUintN is here
  • I can;t find the source for TextEncoder.encode - it shows up in the file util.d.ts under typescript's typing of node, but here is a link to the MDN docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants