Skip to content

Commit 47e6210

Browse files
authored
Merge pull request #1076 from asger-semmle/this-param-unused-import
Approved by xiemaisi
2 parents 242f8f2 + 5ef6eef commit 47e6210

File tree

5 files changed

+140
-115
lines changed

5 files changed

+140
-115
lines changed

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-03-07";
40+
public static final String EXTRACTOR_VERSION = "2019-03-11";
4141

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

javascript/extractor/src/com/semmle/js/parser/TypeScriptASTConverter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,6 +1595,7 @@ private FunctionExpression convertImplicitFunction(JsonObject node, SourceLocati
15951595
List<ITypeExpression> paramTypes = convertParameterTypes(node);
15961596
List<DecoratorList> paramDecorators = convertParameterDecorators(node);
15971597
List<TypeParameter> typeParameters = convertChildrenNotNull(node, "typeParameters");
1598+
ITypeExpression thisType = convertThisParameterType(node);
15981599
FunctionExpression method =
15991600
new FunctionExpression(
16001601
loc,
@@ -1607,7 +1608,7 @@ private FunctionExpression convertImplicitFunction(JsonObject node, SourceLocati
16071608
paramTypes,
16081609
paramDecorators,
16091610
returnType,
1610-
null);
1611+
thisType);
16111612
attachSymbolInformation(method, node);
16121613
return method;
16131614
}

javascript/extractor/tests/ts/output/trap/thisparameter.ts.trap

Lines changed: 125 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -608,146 +608,158 @@ scopenesting(#20205,#20200)
608608
variables(#20206,"arguments",#20205)
609609
isArgumentsObject(#20206)
610610
#20207=*
611-
stmts(#20207,1,#20204,-2,"{}")
612-
#20208=@"loc,{#10000},8,19,8,20"
613-
locations_default(#20208,#10000,8,19,8,20)
614-
hasLocation(#20207,#20208)
615-
stmtContainers(#20207,#20204)
611+
typeexprs(#20207,0,#20204,-4,"C")
612+
hasLocation(#20207,#20127)
613+
exprContainers(#20207,#20204)
614+
literals("C","C",#20207)
615+
typebind(#20207,#20162)
616+
#20208=*
617+
stmts(#20208,1,#20204,-2,"{}")
618+
#20209=@"loc,{#10000},8,19,8,20"
619+
locations_default(#20209,#10000,8,19,8,20)
620+
hasLocation(#20208,#20209)
621+
stmtContainers(#20208,#20204)
616622
isMethod(#20201)
617-
#20209=*
618-
properties(#20209,#20197,3,0,"constructor() {}")
619-
#20210=@"loc,{#10000},7,9,7,8"
620-
locations_default(#20210,#10000,7,9,7,8)
621-
hasLocation(#20209,#20210)
622-
#20211=*
623-
exprs(#20211,0,#20209,0,"constructor")
624-
hasLocation(#20211,#20210)
625-
enclosingStmt(#20211,#20197)
626-
exprContainers(#20211,#20001)
627-
literals("constructor","constructor",#20211)
623+
#20210=*
624+
properties(#20210,#20197,3,0,"constructor() {}")
625+
#20211=@"loc,{#10000},7,9,7,8"
626+
locations_default(#20211,#10000,7,9,7,8)
627+
hasLocation(#20210,#20211)
628628
#20212=*
629-
exprs(#20212,9,#20209,1,"() {}")
630-
hasLocation(#20212,#20210)
629+
exprs(#20212,0,#20210,0,"constructor")
630+
hasLocation(#20212,#20211)
631631
enclosingStmt(#20212,#20197)
632632
exprContainers(#20212,#20001)
633+
literals("constructor","constructor",#20212)
633634
#20213=*
634-
scopes(#20213,1)
635-
scopenodes(#20212,#20213)
636-
scopenesting(#20213,#20200)
637-
#20214=@"var;{arguments};{#20213}"
638-
variables(#20214,"arguments",#20213)
639-
isArgumentsObject(#20214)
640-
#20215=*
641-
stmts(#20215,1,#20212,-2,"{}")
642-
hasLocation(#20215,#20210)
643-
stmtContainers(#20215,#20212)
644-
isMethod(#20209)
635+
exprs(#20213,9,#20210,1,"() {}")
636+
hasLocation(#20213,#20211)
637+
enclosingStmt(#20213,#20197)
638+
exprContainers(#20213,#20001)
639+
#20214=*
640+
scopes(#20214,1)
641+
scopenodes(#20213,#20214)
642+
scopenesting(#20214,#20200)
643+
#20215=@"var;{arguments};{#20214}"
644+
variables(#20215,"arguments",#20214)
645+
isArgumentsObject(#20215)
645646
#20216=*
646-
stmts(#20216,34,#20001,4,"interfa ... : I);\n}")
647-
#20217=@"loc,{#10000},11,1,13,1"
648-
locations_default(#20217,#10000,11,1,13,1)
649-
hasLocation(#20216,#20217)
650-
stmtContainers(#20216,#20001)
651-
#20218=*
652-
typeexprs(#20218,1,#20216,0,"I")
653-
hasLocation(#20218,#20138)
654-
enclosingStmt(#20218,#20216)
655-
exprContainers(#20218,#20001)
656-
literals("I","I",#20218)
657-
typedecl(#20218,#20163)
647+
stmts(#20216,1,#20213,-2,"{}")
648+
hasLocation(#20216,#20211)
649+
stmtContainers(#20216,#20213)
650+
isMethod(#20210)
651+
#20217=*
652+
stmts(#20217,34,#20001,4,"interfa ... : I);\n}")
653+
#20218=@"loc,{#10000},11,1,13,1"
654+
locations_default(#20218,#10000,11,1,13,1)
655+
hasLocation(#20217,#20218)
656+
stmtContainers(#20217,#20001)
658657
#20219=*
659-
properties(#20219,#20216,2,0,"method(this: I);")
660-
#20220=@"loc,{#10000},12,3,12,18"
661-
locations_default(#20220,#10000,12,3,12,18)
662-
hasLocation(#20219,#20220)
663-
#20221=*
664-
exprs(#20221,0,#20219,0,"method")
665-
hasLocation(#20221,#20142)
666-
enclosingStmt(#20221,#20216)
667-
exprContainers(#20221,#20001)
668-
literals("method","method",#20221)
658+
typeexprs(#20219,1,#20217,0,"I")
659+
hasLocation(#20219,#20138)
660+
enclosingStmt(#20219,#20217)
661+
exprContainers(#20219,#20001)
662+
literals("I","I",#20219)
663+
typedecl(#20219,#20163)
664+
#20220=*
665+
properties(#20220,#20217,2,0,"method(this: I);")
666+
#20221=@"loc,{#10000},12,3,12,18"
667+
locations_default(#20221,#10000,12,3,12,18)
668+
hasLocation(#20220,#20221)
669669
#20222=*
670-
exprs(#20222,9,#20219,1,"method(this: I);")
671-
hasLocation(#20222,#20220)
672-
enclosingStmt(#20222,#20216)
670+
exprs(#20222,0,#20220,0,"method")
671+
hasLocation(#20222,#20142)
672+
enclosingStmt(#20222,#20217)
673673
exprContainers(#20222,#20001)
674+
literals("method","method",#20222)
674675
#20223=*
675-
scopes(#20223,1)
676-
scopenodes(#20222,#20223)
677-
scopenesting(#20223,#20000)
678-
#20224=@"var;{arguments};{#20223}"
679-
variables(#20224,"arguments",#20223)
680-
isArgumentsObject(#20224)
681-
isMethod(#20219)
682-
isAbstractMember(#20219)
683-
#20225=*
684-
entry_cfg_node(#20225,#20001)
685-
#20226=@"loc,{#10000},1,1,1,0"
686-
locations_default(#20226,#10000,1,1,1,0)
687-
hasLocation(#20225,#20226)
676+
exprs(#20223,9,#20220,1,"method(this: I);")
677+
hasLocation(#20223,#20221)
678+
enclosingStmt(#20223,#20217)
679+
exprContainers(#20223,#20001)
680+
#20224=*
681+
scopes(#20224,1)
682+
scopenodes(#20223,#20224)
683+
scopenesting(#20224,#20000)
684+
#20225=@"var;{arguments};{#20224}"
685+
variables(#20225,"arguments",#20224)
686+
isArgumentsObject(#20225)
687+
#20226=*
688+
typeexprs(#20226,0,#20223,-4,"I")
689+
hasLocation(#20226,#20150)
690+
exprContainers(#20226,#20223)
691+
literals("I","I",#20226)
692+
typebind(#20226,#20163)
693+
isMethod(#20220)
694+
isAbstractMember(#20220)
688695
#20227=*
689-
exit_cfg_node(#20227,#20001)
690-
hasLocation(#20227,#20157)
691-
successor(#20216,#20227)
692-
successor(#20212,#20209)
693-
#20228=*
694-
entry_cfg_node(#20228,#20212)
695-
hasLocation(#20228,#20210)
696+
entry_cfg_node(#20227,#20001)
697+
#20228=@"loc,{#10000},1,1,1,0"
698+
locations_default(#20228,#10000,1,1,1,0)
699+
hasLocation(#20227,#20228)
696700
#20229=*
697-
exit_cfg_node(#20229,#20212)
698-
hasLocation(#20229,#20210)
699-
successor(#20215,#20229)
700-
successor(#20228,#20215)
701-
successor(#20211,#20212)
702-
successor(#20209,#20197)
703-
successor(#20204,#20201)
701+
exit_cfg_node(#20229,#20001)
702+
hasLocation(#20229,#20157)
703+
successor(#20217,#20229)
704+
successor(#20213,#20210)
704705
#20230=*
705-
entry_cfg_node(#20230,#20204)
706-
#20231=@"loc,{#10000},8,3,8,2"
707-
locations_default(#20231,#10000,8,3,8,2)
708-
hasLocation(#20230,#20231)
706+
entry_cfg_node(#20230,#20213)
707+
hasLocation(#20230,#20211)
708+
#20231=*
709+
exit_cfg_node(#20231,#20213)
710+
hasLocation(#20231,#20211)
711+
successor(#20216,#20231)
712+
successor(#20230,#20216)
713+
successor(#20212,#20213)
714+
successor(#20210,#20197)
715+
successor(#20204,#20201)
709716
#20232=*
710-
exit_cfg_node(#20232,#20204)
711-
#20233=@"loc,{#10000},8,21,8,20"
712-
locations_default(#20233,#10000,8,21,8,20)
717+
entry_cfg_node(#20232,#20204)
718+
#20233=@"loc,{#10000},8,3,8,2"
719+
locations_default(#20233,#10000,8,3,8,2)
713720
hasLocation(#20232,#20233)
714-
successor(#20207,#20232)
715-
successor(#20230,#20207)
721+
#20234=*
722+
exit_cfg_node(#20234,#20204)
723+
#20235=@"loc,{#10000},8,21,8,20"
724+
locations_default(#20235,#10000,8,21,8,20)
725+
hasLocation(#20234,#20235)
726+
successor(#20208,#20234)
727+
successor(#20232,#20208)
716728
successor(#20203,#20204)
717-
successor(#20201,#20211)
729+
successor(#20201,#20212)
718730
successor(#20199,#20203)
719-
successor(#20197,#20216)
731+
successor(#20197,#20217)
720732
successor(#20188,#20199)
721733
successor(#20174,#20177)
722734
successor(#20178,#20175)
723-
#20234=*
724-
entry_cfg_node(#20234,#20178)
725-
#20235=@"loc,{#10000},3,9,3,8"
726-
locations_default(#20235,#10000,3,9,3,8)
727-
hasLocation(#20234,#20235)
728735
#20236=*
729-
exit_cfg_node(#20236,#20178)
730-
#20237=@"loc,{#10000},3,45,3,44"
731-
locations_default(#20237,#10000,3,45,3,44)
736+
entry_cfg_node(#20236,#20178)
737+
#20237=@"loc,{#10000},3,9,3,8"
738+
locations_default(#20237,#10000,3,9,3,8)
732739
hasLocation(#20236,#20237)
733-
successor(#20186,#20236)
740+
#20238=*
741+
exit_cfg_node(#20238,#20178)
742+
#20239=@"loc,{#10000},3,45,3,44"
743+
locations_default(#20239,#10000,3,45,3,44)
744+
hasLocation(#20238,#20239)
745+
successor(#20186,#20238)
734746
successor(#20182,#20186)
735-
successor(#20234,#20182)
747+
successor(#20236,#20182)
736748
successor(#20177,#20178)
737749
successor(#20175,#20188)
738750
successor(#20164,#20174)
739-
#20238=*
740-
entry_cfg_node(#20238,#20164)
741-
hasLocation(#20238,#20226)
742-
#20239=*
743-
exit_cfg_node(#20239,#20164)
744-
#20240=@"loc,{#10000},1,47,1,46"
745-
locations_default(#20240,#10000,1,47,1,46)
746-
hasLocation(#20239,#20240)
747-
successor(#20172,#20239)
751+
#20240=*
752+
entry_cfg_node(#20240,#20164)
753+
hasLocation(#20240,#20228)
754+
#20241=*
755+
exit_cfg_node(#20241,#20164)
756+
#20242=@"loc,{#10000},1,47,1,46"
757+
locations_default(#20242,#10000,1,47,1,46)
758+
hasLocation(#20241,#20242)
759+
successor(#20172,#20241)
748760
successor(#20168,#20172)
749-
successor(#20238,#20168)
761+
successor(#20240,#20168)
750762
successor(#20165,#20164)
751-
successor(#20225,#20165)
763+
successor(#20227,#20165)
752764
numlines(#10000,14,9,0)
753765
filetype(#10000,"typescript")

javascript/ql/test/library-tests/TypeScript/TypeAnnotations/tests.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ test_IsTypeExpr
150150
| tst.ts:81:38:81:50 | x is typeof x | tst.ts:81:38:81:38 | x | tst.ts:81:43:81:50 | typeof x |
151151
test_ThisParameterTypes
152152
| function hasThisParam | tst.ts:116:29:116:32 | void |
153+
| method hasThisParam of interface InterfaceWithThisParam | tst.ts:119:22:119:43 | Interfa ... isParam |
153154
test_ChildIndex
154155
test_TypeArguments
155156
| tst.ts:102:13:102:29 | f1<string>("foo") | 0 | 1 | tst.ts:102:16:102:21 | string |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Foo, Bar, Baz } from "somewhere"; // OK
2+
3+
export function f(this: Foo) {}
4+
5+
export class C {
6+
m(this: Bar) {}
7+
}
8+
9+
export default {
10+
foo(this: Baz) {}
11+
}

0 commit comments

Comments
 (0)