Skip to content

Commit 8146619

Browse files
committed
JS: Set context of computed field names to enclosing ctor
1 parent 2235072 commit 8146619

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,9 +1377,8 @@ public Label visit(MemberDefinition<?> nd, Context c) {
13771377
trapwriter.addTuple("properties", methkey, c.parent, c.childIndex, kind, tostring);
13781378
locationManager.emitNodeLocation(nd, methkey);
13791379
visitAll(nd.getDecorators(), methkey, IdContext.varBind, -1, -1);
1380-
visit(nd.getKey(), methkey, 0, nd.isComputed() ? IdContext.varBind : IdContext.label);
13811380

1382-
// the initialiser expression of an instance field is evaluated as part of
1381+
// the name and initialiser expression of an instance field is evaluated as part of
13831382
// the constructor, so we adjust our syntactic context to reflect this
13841383
MethodDefinition ctor = null;
13851384
if (nd instanceof FieldDefinition && !nd.isStatic() && !ctors.isEmpty()) ctor = ctors.peek();
@@ -1388,6 +1387,7 @@ public Label visit(MemberDefinition<?> nd, Context c) {
13881387
constructorKey = trapwriter.localID(ctor.getValue());
13891388
contextManager.enterContainer(constructorKey);
13901389
}
1390+
visit(nd.getKey(), methkey, 0, nd.isComputed() ? IdContext.varBind : IdContext.label);
13911391
visit(nd.getValue(), methkey, 1, c.idcontext);
13921392
if (ctor != null) contextManager.leaveContainer();
13931393

javascript/ql/test/library-tests/Expr/tests.expected

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,9 @@ test_RelationalComparisons
16201620
| comparison.js:8:1:8:6 | 2 >= 1 | comparison.js:8:6:8:6 | 1 | comparison.js:8:1:8:1 | 2 |
16211621
| es2015.js:23:8:23:12 | n-->0 | es2015.js:23:12:23:12 | 0 | es2015.js:23:8:23:10 | n-- |
16221622
test_getEnclosingFunction
1623+
| computedFieldNames.ts:3:4:3:7 | key1 | computedFieldNames.ts:2:21:2:20 | () {} |
16231624
| computedFieldNames.ts:3:12:3:12 | 4 | computedFieldNames.ts:2:21:2:20 | () {} |
1625+
| computedFieldNames.ts:8:4:8:7 | key2 | computedFieldNames.ts:10:3:10:18 | constructor() {} |
16241626
| computedFieldNames.ts:8:12:8:12 | 4 | computedFieldNames.ts:10:3:10:18 | constructor() {} |
16251627
| es2015.js:1:24:1:24 | s | es2015.js:1:24:1:36 | s => s.length |
16261628
| es2015.js:1:29:1:29 | s | es2015.js:1:24:1:36 | s => s.length |
@@ -1817,13 +1819,13 @@ test_getContainer
18171819
| computedFieldNames.ts:2:7:2:19 | NoConstructor | computedFieldNames.ts:1:1:12:0 | <toplevel> |
18181820
| computedFieldNames.ts:2:21:2:20 | () {} | computedFieldNames.ts:1:1:12:0 | <toplevel> |
18191821
| computedFieldNames.ts:2:21:2:20 | constructor | computedFieldNames.ts:1:1:12:0 | <toplevel> |
1820-
| computedFieldNames.ts:3:4:3:7 | key1 | computedFieldNames.ts:1:1:12:0 | <toplevel> |
1822+
| computedFieldNames.ts:3:4:3:7 | key1 | computedFieldNames.ts:2:21:2:20 | () {} |
18211823
| computedFieldNames.ts:3:12:3:12 | 4 | computedFieldNames.ts:2:21:2:20 | () {} |
18221824
| computedFieldNames.ts:6:7:6:10 | key2 | computedFieldNames.ts:1:1:12:0 | <toplevel> |
18231825
| computedFieldNames.ts:6:7:6:19 | key2 = "key2" | computedFieldNames.ts:1:1:12:0 | <toplevel> |
18241826
| computedFieldNames.ts:6:14:6:19 | "key2" | computedFieldNames.ts:1:1:12:0 | <toplevel> |
18251827
| computedFieldNames.ts:7:7:7:21 | WithConstructor | computedFieldNames.ts:1:1:12:0 | <toplevel> |
1826-
| computedFieldNames.ts:8:4:8:7 | key2 | computedFieldNames.ts:1:1:12:0 | <toplevel> |
1828+
| computedFieldNames.ts:8:4:8:7 | key2 | computedFieldNames.ts:10:3:10:18 | constructor() {} |
18271829
| computedFieldNames.ts:8:12:8:12 | 4 | computedFieldNames.ts:10:3:10:18 | constructor() {} |
18281830
| computedFieldNames.ts:10:3:10:18 | constructor() {} | computedFieldNames.ts:1:1:12:0 | <toplevel> |
18291831
| computedFieldNames.ts:10:3:10:18 | constructor() {} | computedFieldNames.ts:1:1:12:0 | <toplevel> |
@@ -2286,12 +2288,10 @@ test_getEnclosingStmt
22862288
| computedFieldNames.ts:2:7:2:19 | NoConstructor | computedFieldNames.ts:2:1:4:1 | class N ... = 4;\\n} |
22872289
| computedFieldNames.ts:2:21:2:20 | () {} | computedFieldNames.ts:2:1:4:1 | class N ... = 4;\\n} |
22882290
| computedFieldNames.ts:2:21:2:20 | constructor | computedFieldNames.ts:2:1:4:1 | class N ... = 4;\\n} |
2289-
| computedFieldNames.ts:3:4:3:7 | key1 | computedFieldNames.ts:2:1:4:1 | class N ... = 4;\\n} |
22902291
| computedFieldNames.ts:6:7:6:10 | key2 | computedFieldNames.ts:6:1:6:20 | const key2 = "key2"; |
22912292
| computedFieldNames.ts:6:7:6:19 | key2 = "key2" | computedFieldNames.ts:6:1:6:20 | const key2 = "key2"; |
22922293
| computedFieldNames.ts:6:14:6:19 | "key2" | computedFieldNames.ts:6:1:6:20 | const key2 = "key2"; |
22932294
| computedFieldNames.ts:7:7:7:21 | WithConstructor | computedFieldNames.ts:7:1:11:1 | class W ... () {}\\n} |
2294-
| computedFieldNames.ts:8:4:8:7 | key2 | computedFieldNames.ts:7:1:11:1 | class W ... () {}\\n} |
22952295
| computedFieldNames.ts:10:3:10:18 | constructor() {} | computedFieldNames.ts:7:1:11:1 | class W ... () {}\\n} |
22962296
| computedFieldNames.ts:10:3:10:18 | constructor() {} | computedFieldNames.ts:7:1:11:1 | class W ... () {}\\n} |
22972297
| es2015.js:1:1:1:18 | ["a", "ab", "abc"] | es2015.js:1:1:1:38 | ["a", " ... ength); |

javascript/ql/test/query-tests/Declarations/DeadStoreOfLocal/DeadStoreOfLocal.expected

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
| computedFieldNames.ts:3:5:3:17 | key1 = "key1" | The initial value of key1 is unused, since it is always overwritten. |
2-
| computedFieldNames.ts:8:5:8:17 | key2 = "key2" | The initial value of key2 is unused, since it is always overwritten. |
31
| overload.ts:10:12:10:14 | baz | This definition of baz is useless, since its value is never read. |
42
| tst2.js:26:9:26:14 | x = 23 | The initial value of x is unused, since it is always overwritten. |
53
| tst2.js:28:9:28:14 | x = 42 | This definition of x is useless, since its value is never read. |

0 commit comments

Comments
 (0)