Skip to content

Commit 7ba0476

Browse files
authored
Merge pull request github#2098 from asger-semmle/ts-computed-field-name-context
Approved by esben-semmle
2 parents 3726b79 + 7355fdf commit 7ba0476

File tree

14 files changed

+286
-191
lines changed

14 files changed

+286
-191
lines changed

change-notes/1.23/extractor-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
global scripts are now extracted as modules.
1010
* Top-level `await` is now supported.
1111
* A bug was fixed in how the TypeScript extractor handles default-exported anonymous classes.
12+
* A bug was fixed in how the TypeScript extractor handles computed instance field names.

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/extractor/src/com/semmle/js/extractor/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class Main {
3737
* A version identifier that should be updated every time the extractor changes in such a way that
3838
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
3939
*/
40-
public static final String EXTRACTOR_VERSION = "2019-10-07";
40+
public static final String EXTRACTOR_VERSION = "2019-10-08";
4141

4242
public static final Pattern NEWLINE = Pattern.compile("\n");
4343

javascript/extractor/tests/cfg/output/trap/fields.js.trap

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,7 @@ hasLocation(#20156,#20157)
457457
#20158=*
458458
exprs(#20158,0,#20156,0,"x")
459459
hasLocation(#20158,#20059)
460-
enclosingStmt(#20158,#20139)
461-
exprContainers(#20158,#20001)
460+
exprContainers(#20158,#20146)
462461
literals("x","x",#20158)
463462
#20159=*
464463
properties(#20159,#20139,4,8,"static y;")
@@ -650,8 +649,7 @@ hasLocation(#20207,#20208)
650649
#20209=*
651650
exprs(#20209,0,#20207,0,"z")
652651
hasLocation(#20209,#20128)
653-
enclosingStmt(#20209,#20180)
654-
exprContainers(#20209,#20001)
652+
exprContainers(#20209,#20188)
655653
literals("z","z",#20209)
656654
#20210=*
657655
entry_cfg_node(#20210,#20001)

javascript/extractor/tests/esnext/output/trap/fields.js.trap

Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -258,18 +258,17 @@ properties(#20090,#20086,2,8,"x = new.target;")
258258
locations_default(#20091,#10000,2,3,2,17)
259259
hasLocation(#20090,#20091)
260260
#20092=*
261-
exprs(#20092,0,#20090,0,"x")
262-
hasLocation(#20092,#20031)
263-
enclosingStmt(#20092,#20086)
264-
exprContainers(#20092,#20001)
265-
literals("x","x",#20092)
266261
#20093=*
262+
exprs(#20093,0,#20090,0,"x")
263+
hasLocation(#20093,#20031)
264+
exprContainers(#20093,#20092)
265+
literals("x","x",#20093)
267266
#20094=*
268267
exprs(#20094,82,#20090,1,"new.target")
269268
#20095=@"loc,{#10000},2,7,2,16"
270269
locations_default(#20095,#10000,2,7,2,16)
271270
hasLocation(#20094,#20095)
272-
exprContainers(#20094,#20093)
271+
exprContainers(#20094,#20092)
273272
#20096=*
274273
properties(#20096,#20086,3,0,"constructor() {}")
275274
#20097=@"loc,{#10000},1,9,1,8"
@@ -281,21 +280,21 @@ hasLocation(#20098,#20097)
281280
enclosingStmt(#20098,#20086)
282281
exprContainers(#20098,#20001)
283282
literals("constructor","constructor",#20098)
284-
exprs(#20093,9,#20096,1,"() {}")
285-
hasLocation(#20093,#20097)
286-
enclosingStmt(#20093,#20086)
287-
exprContainers(#20093,#20001)
283+
exprs(#20092,9,#20096,1,"() {}")
284+
hasLocation(#20092,#20097)
285+
enclosingStmt(#20092,#20086)
286+
exprContainers(#20092,#20001)
288287
#20099=*
289288
scopes(#20099,1)
290-
scopenodes(#20093,#20099)
289+
scopenodes(#20092,#20099)
291290
scopenesting(#20099,#20089)
292291
#20100=@"var;{arguments};{#20099}"
293292
variables(#20100,"arguments",#20099)
294293
isArgumentsObject(#20100)
295294
#20101=*
296-
stmts(#20101,1,#20093,-2,"{}")
295+
stmts(#20101,1,#20092,-2,"{}")
297296
hasLocation(#20101,#20097)
298-
stmtContainers(#20101,#20093)
297+
stmtContainers(#20101,#20092)
299298
isMethod(#20096)
300299
#20102=*
301300
stmts(#20102,26,#20001,1,"class B ... er.x;\n}")
@@ -328,26 +327,25 @@ properties(#20107,#20102,2,8,"y = super.x;")
328327
locations_default(#20108,#10000,6,3,6,14)
329328
hasLocation(#20107,#20108)
330329
#20109=*
331-
exprs(#20109,0,#20107,0,"y")
332-
hasLocation(#20109,#20054)
333-
enclosingStmt(#20109,#20102)
334-
exprContainers(#20109,#20001)
335-
literals("y","y",#20109)
336330
#20110=*
331+
exprs(#20110,0,#20107,0,"y")
332+
hasLocation(#20110,#20054)
333+
exprContainers(#20110,#20109)
334+
literals("y","y",#20110)
337335
#20111=*
338336
exprs(#20111,14,#20107,1,"super.x")
339337
#20112=@"loc,{#10000},6,7,6,13"
340338
locations_default(#20112,#10000,6,7,6,13)
341339
hasLocation(#20111,#20112)
342-
exprContainers(#20111,#20110)
340+
exprContainers(#20111,#20109)
343341
#20113=*
344342
exprs(#20113,81,#20111,0,"super")
345343
hasLocation(#20113,#20058)
346-
exprContainers(#20113,#20110)
344+
exprContainers(#20113,#20109)
347345
#20114=*
348346
exprs(#20114,0,#20111,1,"x")
349347
hasLocation(#20114,#20062)
350-
exprContainers(#20114,#20110)
348+
exprContainers(#20114,#20109)
351349
literals("x","x",#20114)
352350
#20115=*
353351
properties(#20115,#20102,3,0,"constru ... rgs); }")
@@ -360,54 +358,54 @@ hasLocation(#20117,#20116)
360358
enclosingStmt(#20117,#20102)
361359
exprContainers(#20117,#20001)
362360
literals("constructor","constructor",#20117)
363-
exprs(#20110,9,#20115,1,"(...arg ... rgs); }")
364-
hasLocation(#20110,#20116)
365-
enclosingStmt(#20110,#20102)
366-
exprContainers(#20110,#20001)
361+
exprs(#20109,9,#20115,1,"(...arg ... rgs); }")
362+
hasLocation(#20109,#20116)
363+
enclosingStmt(#20109,#20102)
364+
exprContainers(#20109,#20001)
367365
#20118=*
368366
scopes(#20118,1)
369-
scopenodes(#20110,#20118)
367+
scopenodes(#20109,#20118)
370368
scopenesting(#20118,#20105)
371369
#20119=@"var;{args};{#20118}"
372370
variables(#20119,"args",#20118)
373371
#20120=*
374-
exprs(#20120,78,#20110,0,"args")
372+
exprs(#20120,78,#20109,0,"args")
375373
hasLocation(#20120,#20116)
376-
exprContainers(#20120,#20110)
374+
exprContainers(#20120,#20109)
377375
literals("args","args",#20120)
378376
decl(#20120,#20119)
379377
#20121=@"var;{arguments};{#20118}"
380378
variables(#20121,"arguments",#20118)
381379
isArgumentsObject(#20121)
382-
hasRestParameter(#20110)
380+
hasRestParameter(#20109)
383381
#20122=*
384-
stmts(#20122,1,#20110,-2,"{ super(...args); }")
382+
stmts(#20122,1,#20109,-2,"{ super(...args); }")
385383
hasLocation(#20122,#20116)
386-
stmtContainers(#20122,#20110)
384+
stmtContainers(#20122,#20109)
387385
#20123=*
388386
stmts(#20123,2,#20122,0,"super(...args);")
389387
hasLocation(#20123,#20116)
390-
stmtContainers(#20123,#20110)
388+
stmtContainers(#20123,#20109)
391389
#20124=*
392390
exprs(#20124,13,#20123,0,"super(...args)")
393391
hasLocation(#20124,#20116)
394392
enclosingStmt(#20124,#20123)
395-
exprContainers(#20124,#20110)
393+
exprContainers(#20124,#20109)
396394
#20125=*
397395
exprs(#20125,81,#20124,-1,"super")
398396
hasLocation(#20125,#20116)
399397
enclosingStmt(#20125,#20123)
400-
exprContainers(#20125,#20110)
398+
exprContainers(#20125,#20109)
401399
#20126=*
402400
exprs(#20126,66,#20124,0,"...args")
403401
hasLocation(#20126,#20116)
404402
enclosingStmt(#20126,#20123)
405-
exprContainers(#20126,#20110)
403+
exprContainers(#20126,#20109)
406404
#20127=*
407405
exprs(#20127,79,#20126,0,"args")
408406
hasLocation(#20127,#20116)
409407
enclosingStmt(#20127,#20123)
410-
exprContainers(#20127,#20110)
408+
exprContainers(#20127,#20109)
411409
literals("args","args",#20127)
412410
bind(#20127,#20119)
413411
isMethod(#20115)
@@ -435,12 +433,11 @@ properties(#20132,#20128,2,8,"async;")
435433
locations_default(#20133,#10000,10,3,10,8)
436434
hasLocation(#20132,#20133)
437435
#20134=*
438-
exprs(#20134,0,#20132,0,"async")
439-
hasLocation(#20134,#20073)
440-
enclosingStmt(#20134,#20128)
441-
exprContainers(#20134,#20001)
442-
literals("async","async",#20134)
443436
#20135=*
437+
exprs(#20135,0,#20132,0,"async")
438+
hasLocation(#20135,#20073)
439+
exprContainers(#20135,#20134)
440+
literals("async","async",#20135)
444441
#20136=*
445442
properties(#20136,#20128,3,0,"constructor() {}")
446443
#20137=@"loc,{#10000},9,9,9,8"
@@ -452,21 +449,21 @@ hasLocation(#20138,#20137)
452449
enclosingStmt(#20138,#20128)
453450
exprContainers(#20138,#20001)
454451
literals("constructor","constructor",#20138)
455-
exprs(#20135,9,#20136,1,"() {}")
456-
hasLocation(#20135,#20137)
457-
enclosingStmt(#20135,#20128)
458-
exprContainers(#20135,#20001)
452+
exprs(#20134,9,#20136,1,"() {}")
453+
hasLocation(#20134,#20137)
454+
enclosingStmt(#20134,#20128)
455+
exprContainers(#20134,#20001)
459456
#20139=*
460457
scopes(#20139,1)
461-
scopenodes(#20135,#20139)
458+
scopenodes(#20134,#20139)
462459
scopenesting(#20139,#20131)
463460
#20140=@"var;{arguments};{#20139}"
464461
variables(#20140,"arguments",#20139)
465462
isArgumentsObject(#20140)
466463
#20141=*
467-
stmts(#20141,1,#20135,-2,"{}")
464+
stmts(#20141,1,#20134,-2,"{}")
468465
hasLocation(#20141,#20137)
469-
stmtContainers(#20141,#20135)
466+
stmtContainers(#20141,#20134)
470467
isMethod(#20136)
471468
#20142=*
472469
entry_cfg_node(#20142,#20001)
@@ -476,59 +473,59 @@ hasLocation(#20142,#20143)
476473
#20144=*
477474
exit_cfg_node(#20144,#20001)
478475
hasLocation(#20144,#20078)
479-
successor(#20134,#20132)
480-
successor(#20135,#20136)
476+
successor(#20135,#20132)
477+
successor(#20134,#20136)
481478
#20145=*
482-
entry_cfg_node(#20145,#20135)
479+
entry_cfg_node(#20145,#20134)
483480
hasLocation(#20145,#20137)
484481
successor(#20132,#20141)
485482
#20146=*
486-
exit_cfg_node(#20146,#20135)
483+
exit_cfg_node(#20146,#20134)
487484
hasLocation(#20146,#20137)
488485
successor(#20141,#20146)
489-
successor(#20145,#20134)
490-
successor(#20138,#20135)
486+
successor(#20145,#20135)
487+
successor(#20138,#20134)
491488
successor(#20136,#20128)
492489
successor(#20130,#20138)
493490
successor(#20128,#20144)
494491
successor(#20114,#20111)
495492
successor(#20113,#20114)
496493
successor(#20111,#20107)
497-
successor(#20109,#20113)
498-
successor(#20110,#20115)
494+
successor(#20110,#20113)
495+
successor(#20109,#20115)
499496
#20147=*
500-
entry_cfg_node(#20147,#20110)
497+
entry_cfg_node(#20147,#20109)
501498
hasLocation(#20147,#20116)
502499
#20148=*
503-
exit_cfg_node(#20148,#20110)
500+
exit_cfg_node(#20148,#20109)
504501
hasLocation(#20148,#20116)
505502
successor(#20122,#20123)
506503
successor(#20123,#20125)
507504
successor(#20127,#20126)
508505
successor(#20126,#20124)
509506
successor(#20125,#20127)
510507
successor(#20107,#20148)
511-
successor(#20124,#20109)
508+
successor(#20124,#20110)
512509
successor(#20120,#20122)
513510
successor(#20147,#20120)
514-
successor(#20117,#20110)
511+
successor(#20117,#20109)
515512
successor(#20115,#20102)
516513
successor(#20106,#20117)
517514
successor(#20104,#20106)
518515
successor(#20102,#20130)
519516
successor(#20094,#20090)
520-
successor(#20092,#20094)
521-
successor(#20093,#20096)
517+
successor(#20093,#20094)
518+
successor(#20092,#20096)
522519
#20149=*
523-
entry_cfg_node(#20149,#20093)
520+
entry_cfg_node(#20149,#20092)
524521
hasLocation(#20149,#20097)
525522
successor(#20090,#20101)
526523
#20150=*
527-
exit_cfg_node(#20150,#20093)
524+
exit_cfg_node(#20150,#20092)
528525
hasLocation(#20150,#20097)
529526
successor(#20101,#20150)
530-
successor(#20149,#20092)
531-
successor(#20098,#20093)
527+
successor(#20149,#20093)
528+
successor(#20098,#20092)
532529
successor(#20096,#20086)
533530
successor(#20088,#20098)
534531
successor(#20086,#20104)

0 commit comments

Comments
 (0)