Skip to content

Commit 0867c55

Browse files
committed
rename getId() to getIdentifier()
1 parent 68441bd commit 0867c55

File tree

7 files changed

+32
-36
lines changed

7 files changed

+32
-36
lines changed

javascript/ql/src/semmle/javascript/DefUse.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ private predicate defn(ControlFlowNode def, Expr lhs, AST::ValueNode rhs) {
3030
or
3131
exists(VariableDeclarator vd | def = vd | lhs = vd.getBindingPattern() and rhs = vd.getInit())
3232
or
33-
exists(Function f | def = f.getId() | lhs = def and rhs = f)
33+
exists(Function f | def = f.getIdentifier() | lhs = def and rhs = f)
3434
or
3535
exists(ClassDefinition c | lhs = c.getIdentifier() | def = c and rhs = c and not c.isAmbient())
3636
or
37-
exists(NamespaceDeclaration n | def = n | lhs = n.getId() and rhs = n)
37+
exists(NamespaceDeclaration n | def = n | lhs = n.getIdentifier() and rhs = n)
3838
or
3939
exists(EnumDeclaration ed | def = ed.getIdentifier() | lhs = def and rhs = ed)
4040
or
41-
exists(ImportEqualsDeclaration i | def = i | lhs = i.getId() and rhs = i.getImportedEntity())
41+
exists(ImportEqualsDeclaration i | def = i | lhs = i.getIdentifier() and rhs = i.getImportedEntity())
4242
or
4343
exists(ImportSpecifier i | def = i | lhs = i.getLocal() and rhs = i)
4444
or
@@ -149,7 +149,7 @@ class RValue extends RefExpr {
149149
or
150150
this = any(UpdateExpr u).getOperand().getUnderlyingReference()
151151
or
152-
this = any(NamespaceDeclaration decl).getId()
152+
this = any(NamespaceDeclaration decl).getIdentifier()
153153
}
154154
}
155155

javascript/ql/src/semmle/javascript/ES2015Modules.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class ExportDefaultDeclaration extends ExportDeclaration, @exportdefaultdeclarat
330330
/** Gets the declaration, if any, exported by this default export. */
331331
VarDecl getADecl() {
332332
exists(ExprOrStmt op | op = getOperand() |
333-
result = op.(FunctionDeclStmt).getId() or
333+
result = op.(FunctionDeclStmt).getIdentifier() or
334334
result = op.(ClassDeclStmt).getIdentifier()
335335
)
336336
}
@@ -364,13 +364,13 @@ class ExportNamedDeclaration extends ExportDeclaration, @exportnameddeclaration
364364
Identifier getAnExportedDecl() {
365365
exists(ExprOrStmt op | op = getOperand() |
366366
result = op.(DeclStmt).getADecl().getBindingPattern().getABindingVarRef() or
367-
result = op.(FunctionDeclStmt).getId() or
367+
result = op.(FunctionDeclStmt).getIdentifier() or
368368
result = op.(ClassDeclStmt).getIdentifier() or
369-
result = op.(NamespaceDeclaration).getId() or
369+
result = op.(NamespaceDeclaration).getIdentifier() or
370370
result = op.(EnumDeclaration).getIdentifier() or
371371
result = op.(InterfaceDeclaration).getIdentifier() or
372372
result = op.(TypeAliasDeclaration).getIdentifier() or
373-
result = op.(ImportEqualsDeclaration).getId()
373+
result = op.(ImportEqualsDeclaration).getIdentifier()
374374
)
375375
}
376376

javascript/ql/src/semmle/javascript/Functions.qll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Function extends @function, Parameterized, TypeParameterized, StmtContaine
7878
}
7979

8080
/** Gets the identifier specifying the name of this function, if any. */
81-
VarDecl getId() { result = getChildExpr(-1) }
81+
VarDecl getIdentifier() { result = getChildExpr(-1) }
8282

8383
/**
8484
* Gets the name of this function if it has one, or a name inferred from its context.
@@ -89,9 +89,9 @@ class Function extends @function, Parameterized, TypeParameterized, StmtContaine
8989
* can be inferred, there is no result.
9090
*/
9191
string getName() {
92-
result = getId().getName()
92+
result = getIdentifier().getName()
9393
or
94-
not exists(getId()) and
94+
not exists(getIdentifier()) and
9595
(
9696
exists(VarDef vd | this = vd.getSource() | result = vd.getTarget().(VarRef).getName())
9797
or
@@ -111,7 +111,7 @@ class Function extends @function, Parameterized, TypeParameterized, StmtContaine
111111
}
112112

113113
/** Gets the variable holding this function. */
114-
Variable getVariable() { result = getId().getVariable() }
114+
Variable getVariable() { result = getIdentifier().getVariable() }
115115

116116
/** Gets the `arguments` variable of this function, if any. */
117117
ArgumentsVariable getArgumentsVariable() { result.getFunction() = this }
@@ -183,11 +183,11 @@ class Function extends @function, Parameterized, TypeParameterized, StmtContaine
183183
not exists(getAParameter()) and
184184
(
185185
// if the function has a name, the opening parenthesis comes right after it
186-
result = getId().getLastToken().getNextToken()
186+
result = getIdentifier().getLastToken().getNextToken()
187187
or
188188
// otherwise this must be an arrow function with no parameters, so the opening
189189
// parenthesis is the very first token of the function
190-
not exists(getId()) and result = getFirstToken()
190+
not exists(getIdentifier()) and result = getFirstToken()
191191
)
192192
}
193193

@@ -309,8 +309,8 @@ class Function extends @function, Parameterized, TypeParameterized, StmtContaine
309309
*/
310310
private string inferNameFromVarDef() {
311311
// in ambiguous cases like `var f = function g() {}`, prefer `g` to `f`
312-
if exists(getId())
313-
then result = "function " + getId().getName()
312+
if exists(getIdentifier())
313+
then result = "function " + getIdentifier().getName()
314314
else
315315
exists(VarDef vd | this = vd.getSource() |
316316
result = "function " + vd.getTarget().(VarRef).getName()

javascript/ql/src/semmle/javascript/GlobalAccessPaths.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ module AccessPath {
267267
or
268268
exists(FunctionDeclStmt fun |
269269
node = DataFlow::valueNode(fun) and
270-
result = fun.getId().(GlobalVarDecl).getName() and
270+
result = fun.getIdentifier().(GlobalVarDecl).getName() and
271271
root.isGlobal()
272272
)
273273
or
@@ -285,7 +285,7 @@ module AccessPath {
285285
or
286286
exists(NamespaceDeclaration decl |
287287
node = DataFlow::valueNode(decl) and
288-
result = decl.getId().(GlobalVarDecl).getName() and
288+
result = decl.getIdentifier().(GlobalVarDecl).getName() and
289289
root.isGlobal()
290290
)
291291
}

javascript/ql/src/semmle/javascript/TypeScript.qll

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ class NamespaceDefinition extends Stmt, @namespacedefinition, AST::ValueNode {
1010
/**
1111
* Gets the identifier naming the namespace.
1212
*/
13-
Identifier getId() {
14-
result = this.(NamespaceDeclaration).getId()
15-
or
16-
result = this.(EnumDeclaration).getIdentifier()
17-
}
13+
Identifier getIdentifier() { none() } // Overridden in subtypes.
1814

1915
/**
2016
* Gets unqualified name of the namespace being defined.
@@ -29,7 +25,7 @@ class NamespaceDefinition extends Stmt, @namespacedefinition, AST::ValueNode {
2925
* Gets the local namespace name induced by this namespace.
3026
*/
3127
LocalNamespaceName getLocalNamespaceName() {
32-
result = getId().(LocalNamespaceDecl).getLocalNamespaceName()
28+
result = getIdentifier().(LocalNamespaceDecl).getLocalNamespaceName()
3329
}
3430

3531
/**
@@ -55,10 +51,10 @@ class NamespaceDefinition extends Stmt, @namespacedefinition, AST::ValueNode {
5551
*/
5652
class NamespaceDeclaration extends NamespaceDefinition, StmtContainer, @namespacedeclaration {
5753
/** Gets the name of this namespace. */
58-
override Identifier getId() { result = getChildExpr(-1) }
54+
override Identifier getIdentifier() { result = getChildExpr(-1) }
5955

6056
/** Gets the name of this namespace as a string. */
61-
override string getName() { result = getId().getName() }
57+
override string getName() { result = getIdentifier().getName() }
6258

6359
/** Gets the `i`th statement in this namespace. */
6460
Stmt getStmt(int i) {
@@ -83,7 +79,7 @@ class NamespaceDeclaration extends NamespaceDefinition, StmtContainer, @namespac
8379
predicate isInstantiated() { isInstantiated(this) }
8480

8581
override ControlFlowNode getFirstControlFlowNode() {
86-
if hasDeclareKeyword(this) then result = this else result = getId()
82+
if hasDeclareKeyword(this) then result = this else result = getIdentifier()
8783
}
8884
}
8985

@@ -179,12 +175,12 @@ class GlobalAugmentationDeclaration extends Stmt, StmtContainer, @globalaugmenta
179175
/** A TypeScript "import-equals" declaration. */
180176
class ImportEqualsDeclaration extends Stmt, @importequalsdeclaration {
181177
/** Gets the name under which the imported entity is imported. */
182-
Identifier getId() { result = getChildExpr(0) }
178+
Identifier getIdentifier() { result = getChildExpr(0) }
183179

184180
/** Gets the expression specifying the imported module or entity. */
185181
Expr getImportedEntity() { result = getChildExpr(1) }
186182

187-
override ControlFlowNode getFirstControlFlowNode() { result = getId() }
183+
override ControlFlowNode getFirstControlFlowNode() { result = getIdentifier() }
188184
}
189185

190186
/**
@@ -348,7 +344,7 @@ class TypeDecl extends Identifier, TypeRef, LexicalDecl {
348344
this = any(ClassOrInterface ci).getIdentifier() or
349345
this = any(TypeParameter tp).getIdentifier() or
350346
this = any(ImportSpecifier im).getLocal() or
351-
this = any(ImportEqualsDeclaration im).getId() or
347+
this = any(ImportEqualsDeclaration im).getIdentifier() or
352348
this = any(TypeAliasDeclaration td).getIdentifier() or
353349
this = any(EnumDeclaration ed).getIdentifier() or
354350
this = any(EnumMember member).getIdentifier()
@@ -1226,8 +1222,8 @@ abstract class NamespaceRef extends ASTNode { }
12261222
*/
12271223
class LocalNamespaceDecl extends VarDecl, NamespaceRef {
12281224
LocalNamespaceDecl() {
1229-
any(NamespaceDeclaration nd).getId() = this or
1230-
any(ImportEqualsDeclaration im).getId() = this or
1225+
any(NamespaceDeclaration nd).getIdentifier() = this or
1226+
any(ImportEqualsDeclaration im).getIdentifier() = this or
12311227
any(ImportSpecifier im).getLocal() = this or
12321228
any(EnumDeclaration ed).getIdentifier() = this
12331229
}
@@ -1325,7 +1321,7 @@ class ImportVarTypeAccess extends VarTypeAccess, ImportTypeExpr, @importvartypea
13251321
*/
13261322
class EnumDeclaration extends NamespaceDefinition, @enumdeclaration, AST::ValueNode {
13271323
/** Gets the name of this enum, such as `E` in `enum E { A, B }`. */
1328-
Identifier getIdentifier() { result = getChildExpr(0) }
1324+
override Identifier getIdentifier() { result = getChildExpr(0) }
13291325

13301326
/** Gets the name of this enum as a string. */
13311327
override string getName() { result = getIdentifier().getName() }

javascript/ql/src/semmle/javascript/Variables.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ class LocalVariable extends Variable {
312312
this = result.getScope().getAVariable()
313313
or
314314
exists(VarDecl d | d = getADeclaration() |
315-
if d = any(FunctionDeclStmt fds).getId()
316-
then exists(FunctionDeclStmt fds | d = fds.getId() | result = fds.getEnclosingContainer())
315+
if d = any(FunctionDeclStmt fds).getIdentifier()
316+
then exists(FunctionDeclStmt fds | d = fds.getIdentifier() | result = fds.getEnclosingContainer())
317317
else result = d.getContainer()
318318
)
319319
}

javascript/ql/src/semmle/javascript/dataflow/internal/BasicExprTypeInference.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private class AnalyzedNamespaceDeclaration extends DataFlow::AnalyzedValueNode {
111111

112112
AbstractValue getPreviousValue() {
113113
exists(AnalyzedSsaDefinition def |
114-
def.getVariable().getAUse() = astNode.getId() and
114+
def.getVariable().getAUse() = astNode.getIdentifier() and
115115
result = def.getAnRhsValue()
116116
)
117117
}

0 commit comments

Comments
 (0)