Skip to content

Commit 608de70

Browse files
committed
JS: Associate symbols with external module decls
1 parent 5faff56 commit 608de70

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2191,6 +2191,7 @@ public Label visit(ExternalModuleDeclaration nd, Context c) {
21912191
visitAll(nd.getBody(), key);
21922192
contextManager.leaveContainer();
21932193
scopeManager.leaveScope();
2194+
emitNodeSymbol(nd, key);
21942195
return key;
21952196
}
21962197

javascript/extractor/src/com/semmle/ts/ast/ExternalModuleDeclaration.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import java.util.List;
88

99
/** A statement of form <code>declare module "X" {...}</code>. */
10-
public class ExternalModuleDeclaration extends Statement {
10+
public class ExternalModuleDeclaration extends Statement implements INodeWithSymbol {
1111
private final Literal name;
1212
private final List<Statement> body;
13+
private int symbol = -1;
1314

1415
public ExternalModuleDeclaration(SourceLocation loc, Literal name, List<Statement> body) {
1516
super("ExternalModuleDeclaration", loc);
@@ -29,4 +30,14 @@ public Literal getName() {
2930
public List<Statement> getBody() {
3031
return body;
3132
}
33+
34+
@Override
35+
public int getSymbol() {
36+
return this.symbol;
37+
}
38+
39+
@Override
40+
public void setSymbol(int symbol) {
41+
this.symbol = symbol;
42+
}
3243
}

javascript/extractor/src/com/semmle/ts/extractor/TypeScriptASTConverter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ private Node convertNodeUntyped(JsonObject node, String defaultKind) throws Pars
591591
return convertTryStatement(node, loc);
592592
case "TupleType":
593593
return convertTupleType(node, loc);
594-
case "NamedTupleMember":
594+
case "NamedTupleMember":
595595
return convertNamedTupleMember(node, loc);
596596
case "TypeAliasDeclaration":
597597
return convertTypeAliasDeclaration(node, loc);
@@ -1710,7 +1710,10 @@ private Node convertNamespaceDeclaration(JsonObject node, SourceLocation loc) th
17101710
}
17111711
if (nameNode instanceof Literal) {
17121712
// Declaration of form: declare module "X" {...}
1713-
return new ExternalModuleDeclaration(loc, (Literal) nameNode, body);
1713+
ExternalModuleDeclaration decl = new ExternalModuleDeclaration(loc, (Literal) nameNode, body);
1714+
attachSymbolInformation(decl, node);
1715+
System.out.println("ExternalModuleDeclaration symbol = " + decl.getSymbol());
1716+
return decl;
17141717
}
17151718
if (hasFlag(node, "GlobalAugmentation")) {
17161719
// Declaration of form: declare global {...}

javascript/ql/lib/semmlecode.javascript.dbscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ case @symbol.kind of
713713
;
714714

715715
@type_with_symbol = @type_reference | @typevariable_type | @typeof_type | @unique_symbol_type;
716-
@ast_node_with_symbol = @type_definition | @namespace_definition | @toplevel | @typeaccess | @namespace_access | @var_decl | @function | @invokeexpr | @import_declaration | @external_module_reference;
716+
@ast_node_with_symbol = @type_definition | @namespace_definition | @toplevel | @typeaccess | @namespace_access | @var_decl | @function | @invokeexpr | @import_declaration | @external_module_reference | @external_module_declaration;
717717

718718
ast_node_symbol(
719719
unique int node: @ast_node_with_symbol ref,

0 commit comments

Comments
 (0)