JS: Preserve information about 'defer' keyword

This commit is contained in:
Asger F
2025-09-05 11:19:04 +02:00
parent 76ca1a576f
commit 215602c963
12 changed files with 71 additions and 14 deletions

View File

@@ -151,6 +151,14 @@ class ImportDeclaration extends Stmt, Import, @import_declaration {
/** Holds if this is declared with the `type` keyword, so it only imports types. */
predicate isTypeOnly() { has_type_keyword(this) }
/**
* Holds if this is declared with the `defer` keyword, for example:
* ```ts
* import defer * as f from "somewhere";
* ```
*/
predicate isDeferredImport() { has_defer_keyword(this) }
override string getAPrimaryQlClass() { result = "ImportDeclaration" }
}

View File

@@ -516,6 +516,7 @@ has_private_keyword (int id: @property ref);
has_protected_keyword (int id: @property ref);
has_readonly_keyword (int id: @property ref);
has_type_keyword (int id: @type_keyword_operand ref);
has_defer_keyword (int id: @import_declaration ref);
is_optional_member (int id: @property ref);
has_definite_assignment_assertion (int id: @field_or_vardeclarator ref);
is_optional_parameter_declaration (unique int parameter: @pattern ref);

View File

@@ -4319,6 +4319,17 @@
<dependencies/>
</relation>
<relation>
<name>has_defer_keyword</name>
<cardinality>1000</cardinality>
<columnsizes>
<e>
<k>id</k>
<v>1000</v>
</e>
</columnsizes>
<dependencies/>
</relation>
<relation>
<name>is_optional_member</name>
<cardinality>3668</cardinality>
<columnsizes>

View File

@@ -1 +1 @@
| tst.ts:1:1:1:31 | import ... m "fs"; |
| tst.ts:1:1:1:44 | import ... where"; |

View File

@@ -1,5 +1,3 @@
import javascript
from ImportDeclaration decl
select decl
query predicate deferredImports(ImportDeclaration decl) { decl.isDeferredImport() }

View File

@@ -1 +1,4 @@
import defer * as fs from "fs";
import defer * as deferred from "somewhere";
import type * as t from "somewhere";
import * as normal from "somewhere";
import defer from "somewhere";