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

"Literal cannot be cast Identifier" when processing new ECMAScript/TypeScript export/import syntax #18336

Open
jakebailey opened this issue Dec 19, 2024 · 0 comments
Labels
question Further information is requested

Comments

@jakebailey
Copy link

Description of the issue

In the TypeScript repo, we have tests which include very new ECMAScript syntax; in particular https://github.com/microsoft/TypeScript/blob/56a08250f3516b3f5bc120d6c7ab4450a9a69352/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts contains a new syntax for imports/exports that uses string literals instead of identifiers.

CodeQL scans our tests (depending on our config), and then crashes when encountering this code:

[2024-12-17 17:54:44] [build-stdout] Extracting /mnt/vss/_work/1/s/tests/cases/conformance/es2021/logicalAssignment/logicalAssignment9.ts
[2024-12-17 17:54:44] [build-stdout] Done extracting /mnt/vss/_work/1/s/tests/cases/conformance/es2021/logicalAssignment/logicalAssignment9.ts (0 ms)
[2024-12-17 17:54:44] [build-stdout] Extracting /mnt/vss/_work/1/s/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_exportEmpty.ts
[2024-12-17 17:54:44] [build-stdout] Done extracting /mnt/vss/_work/1/s/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_exportEmpty.ts (1 ms)
[2024-12-17 17:54:44] [build-stdout] Extracting /mnt/vss/_work/1/s/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_importEmpty.ts
[2024-12-17 17:54:44] [build-stdout] Done extracting /mnt/vss/_work/1/s/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_importEmpty.ts (1 ms)
[2024-12-17 17:54:44] [build-stdout] Extracting /mnt/vss/_work/1/s/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts
[2024-12-17 17:54:44] [build-stderr] Exception while extracting /mnt/vss/_work/1/s/tests/cases/conformance/es2022/arbitraryModuleNamespaceIdentifiers/arbitraryModuleNamespaceIdentifiers_module.ts.
[2024-12-17 17:54:44] [build-stderr] java.lang.ClassCastException: class com.semmle.js.ast.Literal cannot be cast to class com.semmle.js.ast.Identifier (com.semmle.js.ast.Literal and com.semmle.js.ast.Identifier are in unnamed module of loader 'app')
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertExportSpecifier(TypeScriptASTConverter.java:1220)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertNodeUntyped(TypeScriptASTConverter.java:416)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertNode(TypeScriptASTConverter.java:318)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertNode(TypeScriptASTConverter.java:310)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertNodes(TypeScriptASTConverter.java:709)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertChildren(TypeScriptASTConverter.java:777)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertChildren(TypeScriptASTConverter.java:756)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertExportDeclaration(TypeScriptASTConverter.java:1212)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertNodeUntyped(TypeScriptASTConverter.java:414)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertNode(TypeScriptASTConverter.java:318)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertNode(TypeScriptASTConverter.java:310)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertNodes(TypeScriptASTConverter.java:709)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertNodes(TypeScriptASTConverter.java:697)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertSourceFile(TypeScriptASTConverter.java:2161)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertNodeUntyped(TypeScriptASTConverter.java:563)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertNode(TypeScriptASTConverter.java:318)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertNode(TypeScriptASTConverter.java:310)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptASTConverter.convertAST(TypeScriptASTConverter.java:217)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.ts.extractor.TypeScriptParser.parse(TypeScriptParser.java:440)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.js.extractor.TypeScriptExtractor.extract(TypeScriptExtractor.java:24)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.js.extractor.FileExtractor.extractContents(FileExtractor.java:553)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.js.extractor.FileExtractor.extract(FileExtractor.java:460)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.js.extractor.AutoBuild.doExtract(AutoBuild.java:1255)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.js.extractor.AutoBuild.extract(AutoBuild.java:1241)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.js.extractor.AutoBuild.extractTypeScriptFiles(AutoBuild.java:1194)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.js.extractor.AutoBuild.extractTypeScript(AutoBuild.java:1091)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.js.extractor.AutoBuild.extractSource(AutoBuild.java:758)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.js.extractor.AutoBuild.run(AutoBuild.java:464)
[2024-12-17 17:54:44] [build-stderr] 	at com.semmle.js.extractor.AutoBuild.main(AutoBuild.java:1360)

I don't think this syntax is supported yet, but the crash seems to halt database generation, which means that any files after a file with the bad syntax are entirely skipped.

For TypeScript, we can theoretically just ignore these paths, but this syntax will eventually make its way into user code and npm, where it will also cause crashes.

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

1 participant