diff --git a/javascript/extractor/src/com/semmle/js/extractor/Main.java b/javascript/extractor/src/com/semmle/js/extractor/Main.java index b8c71d6c93e7..e92553898e8d 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/Main.java +++ b/javascript/extractor/src/com/semmle/js/extractor/Main.java @@ -37,7 +37,7 @@ public class Main { * A version identifier that should be updated every time the extractor changes in such a way that * it may produce different tuples for the same file under the same {@link ExtractorConfig}. */ - public static final String EXTRACTOR_VERSION = "2019-03-07"; + public static final String EXTRACTOR_VERSION = "2019-03-11"; public static final Pattern NEWLINE = Pattern.compile("\n"); diff --git a/javascript/extractor/src/com/semmle/js/parser/TypeScriptASTConverter.java b/javascript/extractor/src/com/semmle/js/parser/TypeScriptASTConverter.java index 8ce33fb4b465..3eb269b6f00c 100644 --- a/javascript/extractor/src/com/semmle/js/parser/TypeScriptASTConverter.java +++ b/javascript/extractor/src/com/semmle/js/parser/TypeScriptASTConverter.java @@ -1595,6 +1595,7 @@ private FunctionExpression convertImplicitFunction(JsonObject node, SourceLocati List paramTypes = convertParameterTypes(node); List paramDecorators = convertParameterDecorators(node); List typeParameters = convertChildrenNotNull(node, "typeParameters"); + ITypeExpression thisType = convertThisParameterType(node); FunctionExpression method = new FunctionExpression( loc, @@ -1607,7 +1608,7 @@ private FunctionExpression convertImplicitFunction(JsonObject node, SourceLocati paramTypes, paramDecorators, returnType, - null); + thisType); attachSymbolInformation(method, node); return method; } diff --git a/javascript/extractor/tests/ts/output/trap/thisparameter.ts.trap b/javascript/extractor/tests/ts/output/trap/thisparameter.ts.trap index 52902ec3e75e..0fed22335c04 100644 --- a/javascript/extractor/tests/ts/output/trap/thisparameter.ts.trap +++ b/javascript/extractor/tests/ts/output/trap/thisparameter.ts.trap @@ -608,146 +608,158 @@ scopenesting(#20205,#20200) variables(#20206,"arguments",#20205) isArgumentsObject(#20206) #20207=* -stmts(#20207,1,#20204,-2,"{}") -#20208=@"loc,{#10000},8,19,8,20" -locations_default(#20208,#10000,8,19,8,20) -hasLocation(#20207,#20208) -stmtContainers(#20207,#20204) +typeexprs(#20207,0,#20204,-4,"C") +hasLocation(#20207,#20127) +exprContainers(#20207,#20204) +literals("C","C",#20207) +typebind(#20207,#20162) +#20208=* +stmts(#20208,1,#20204,-2,"{}") +#20209=@"loc,{#10000},8,19,8,20" +locations_default(#20209,#10000,8,19,8,20) +hasLocation(#20208,#20209) +stmtContainers(#20208,#20204) isMethod(#20201) -#20209=* -properties(#20209,#20197,3,0,"constructor() {}") -#20210=@"loc,{#10000},7,9,7,8" -locations_default(#20210,#10000,7,9,7,8) -hasLocation(#20209,#20210) -#20211=* -exprs(#20211,0,#20209,0,"constructor") -hasLocation(#20211,#20210) -enclosingStmt(#20211,#20197) -exprContainers(#20211,#20001) -literals("constructor","constructor",#20211) +#20210=* +properties(#20210,#20197,3,0,"constructor() {}") +#20211=@"loc,{#10000},7,9,7,8" +locations_default(#20211,#10000,7,9,7,8) +hasLocation(#20210,#20211) #20212=* -exprs(#20212,9,#20209,1,"() {}") -hasLocation(#20212,#20210) +exprs(#20212,0,#20210,0,"constructor") +hasLocation(#20212,#20211) enclosingStmt(#20212,#20197) exprContainers(#20212,#20001) +literals("constructor","constructor",#20212) #20213=* -scopes(#20213,1) -scopenodes(#20212,#20213) -scopenesting(#20213,#20200) -#20214=@"var;{arguments};{#20213}" -variables(#20214,"arguments",#20213) -isArgumentsObject(#20214) -#20215=* -stmts(#20215,1,#20212,-2,"{}") -hasLocation(#20215,#20210) -stmtContainers(#20215,#20212) -isMethod(#20209) +exprs(#20213,9,#20210,1,"() {}") +hasLocation(#20213,#20211) +enclosingStmt(#20213,#20197) +exprContainers(#20213,#20001) +#20214=* +scopes(#20214,1) +scopenodes(#20213,#20214) +scopenesting(#20214,#20200) +#20215=@"var;{arguments};{#20214}" +variables(#20215,"arguments",#20214) +isArgumentsObject(#20215) #20216=* -stmts(#20216,34,#20001,4,"interfa ... : I);\n}") -#20217=@"loc,{#10000},11,1,13,1" -locations_default(#20217,#10000,11,1,13,1) -hasLocation(#20216,#20217) -stmtContainers(#20216,#20001) -#20218=* -typeexprs(#20218,1,#20216,0,"I") -hasLocation(#20218,#20138) -enclosingStmt(#20218,#20216) -exprContainers(#20218,#20001) -literals("I","I",#20218) -typedecl(#20218,#20163) +stmts(#20216,1,#20213,-2,"{}") +hasLocation(#20216,#20211) +stmtContainers(#20216,#20213) +isMethod(#20210) +#20217=* +stmts(#20217,34,#20001,4,"interfa ... : I);\n}") +#20218=@"loc,{#10000},11,1,13,1" +locations_default(#20218,#10000,11,1,13,1) +hasLocation(#20217,#20218) +stmtContainers(#20217,#20001) #20219=* -properties(#20219,#20216,2,0,"method(this: I);") -#20220=@"loc,{#10000},12,3,12,18" -locations_default(#20220,#10000,12,3,12,18) -hasLocation(#20219,#20220) -#20221=* -exprs(#20221,0,#20219,0,"method") -hasLocation(#20221,#20142) -enclosingStmt(#20221,#20216) -exprContainers(#20221,#20001) -literals("method","method",#20221) +typeexprs(#20219,1,#20217,0,"I") +hasLocation(#20219,#20138) +enclosingStmt(#20219,#20217) +exprContainers(#20219,#20001) +literals("I","I",#20219) +typedecl(#20219,#20163) +#20220=* +properties(#20220,#20217,2,0,"method(this: I);") +#20221=@"loc,{#10000},12,3,12,18" +locations_default(#20221,#10000,12,3,12,18) +hasLocation(#20220,#20221) #20222=* -exprs(#20222,9,#20219,1,"method(this: I);") -hasLocation(#20222,#20220) -enclosingStmt(#20222,#20216) +exprs(#20222,0,#20220,0,"method") +hasLocation(#20222,#20142) +enclosingStmt(#20222,#20217) exprContainers(#20222,#20001) +literals("method","method",#20222) #20223=* -scopes(#20223,1) -scopenodes(#20222,#20223) -scopenesting(#20223,#20000) -#20224=@"var;{arguments};{#20223}" -variables(#20224,"arguments",#20223) -isArgumentsObject(#20224) -isMethod(#20219) -isAbstractMember(#20219) -#20225=* -entry_cfg_node(#20225,#20001) -#20226=@"loc,{#10000},1,1,1,0" -locations_default(#20226,#10000,1,1,1,0) -hasLocation(#20225,#20226) +exprs(#20223,9,#20220,1,"method(this: I);") +hasLocation(#20223,#20221) +enclosingStmt(#20223,#20217) +exprContainers(#20223,#20001) +#20224=* +scopes(#20224,1) +scopenodes(#20223,#20224) +scopenesting(#20224,#20000) +#20225=@"var;{arguments};{#20224}" +variables(#20225,"arguments",#20224) +isArgumentsObject(#20225) +#20226=* +typeexprs(#20226,0,#20223,-4,"I") +hasLocation(#20226,#20150) +exprContainers(#20226,#20223) +literals("I","I",#20226) +typebind(#20226,#20163) +isMethod(#20220) +isAbstractMember(#20220) #20227=* -exit_cfg_node(#20227,#20001) -hasLocation(#20227,#20157) -successor(#20216,#20227) -successor(#20212,#20209) -#20228=* -entry_cfg_node(#20228,#20212) -hasLocation(#20228,#20210) +entry_cfg_node(#20227,#20001) +#20228=@"loc,{#10000},1,1,1,0" +locations_default(#20228,#10000,1,1,1,0) +hasLocation(#20227,#20228) #20229=* -exit_cfg_node(#20229,#20212) -hasLocation(#20229,#20210) -successor(#20215,#20229) -successor(#20228,#20215) -successor(#20211,#20212) -successor(#20209,#20197) -successor(#20204,#20201) +exit_cfg_node(#20229,#20001) +hasLocation(#20229,#20157) +successor(#20217,#20229) +successor(#20213,#20210) #20230=* -entry_cfg_node(#20230,#20204) -#20231=@"loc,{#10000},8,3,8,2" -locations_default(#20231,#10000,8,3,8,2) -hasLocation(#20230,#20231) +entry_cfg_node(#20230,#20213) +hasLocation(#20230,#20211) +#20231=* +exit_cfg_node(#20231,#20213) +hasLocation(#20231,#20211) +successor(#20216,#20231) +successor(#20230,#20216) +successor(#20212,#20213) +successor(#20210,#20197) +successor(#20204,#20201) #20232=* -exit_cfg_node(#20232,#20204) -#20233=@"loc,{#10000},8,21,8,20" -locations_default(#20233,#10000,8,21,8,20) +entry_cfg_node(#20232,#20204) +#20233=@"loc,{#10000},8,3,8,2" +locations_default(#20233,#10000,8,3,8,2) hasLocation(#20232,#20233) -successor(#20207,#20232) -successor(#20230,#20207) +#20234=* +exit_cfg_node(#20234,#20204) +#20235=@"loc,{#10000},8,21,8,20" +locations_default(#20235,#10000,8,21,8,20) +hasLocation(#20234,#20235) +successor(#20208,#20234) +successor(#20232,#20208) successor(#20203,#20204) -successor(#20201,#20211) +successor(#20201,#20212) successor(#20199,#20203) -successor(#20197,#20216) +successor(#20197,#20217) successor(#20188,#20199) successor(#20174,#20177) successor(#20178,#20175) -#20234=* -entry_cfg_node(#20234,#20178) -#20235=@"loc,{#10000},3,9,3,8" -locations_default(#20235,#10000,3,9,3,8) -hasLocation(#20234,#20235) #20236=* -exit_cfg_node(#20236,#20178) -#20237=@"loc,{#10000},3,45,3,44" -locations_default(#20237,#10000,3,45,3,44) +entry_cfg_node(#20236,#20178) +#20237=@"loc,{#10000},3,9,3,8" +locations_default(#20237,#10000,3,9,3,8) hasLocation(#20236,#20237) -successor(#20186,#20236) +#20238=* +exit_cfg_node(#20238,#20178) +#20239=@"loc,{#10000},3,45,3,44" +locations_default(#20239,#10000,3,45,3,44) +hasLocation(#20238,#20239) +successor(#20186,#20238) successor(#20182,#20186) -successor(#20234,#20182) +successor(#20236,#20182) successor(#20177,#20178) successor(#20175,#20188) successor(#20164,#20174) -#20238=* -entry_cfg_node(#20238,#20164) -hasLocation(#20238,#20226) -#20239=* -exit_cfg_node(#20239,#20164) -#20240=@"loc,{#10000},1,47,1,46" -locations_default(#20240,#10000,1,47,1,46) -hasLocation(#20239,#20240) -successor(#20172,#20239) +#20240=* +entry_cfg_node(#20240,#20164) +hasLocation(#20240,#20228) +#20241=* +exit_cfg_node(#20241,#20164) +#20242=@"loc,{#10000},1,47,1,46" +locations_default(#20242,#10000,1,47,1,46) +hasLocation(#20241,#20242) +successor(#20172,#20241) successor(#20168,#20172) -successor(#20238,#20168) +successor(#20240,#20168) successor(#20165,#20164) -successor(#20225,#20165) +successor(#20227,#20165) numlines(#10000,14,9,0) filetype(#10000,"typescript") diff --git a/javascript/ql/test/library-tests/TypeScript/TypeAnnotations/tests.expected b/javascript/ql/test/library-tests/TypeScript/TypeAnnotations/tests.expected index e3a4785d905d..5e4184551667 100644 --- a/javascript/ql/test/library-tests/TypeScript/TypeAnnotations/tests.expected +++ b/javascript/ql/test/library-tests/TypeScript/TypeAnnotations/tests.expected @@ -150,6 +150,7 @@ test_IsTypeExpr | 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 | test_ThisParameterTypes | function hasThisParam | tst.ts:116:29:116:32 | void | +| method hasThisParam of interface InterfaceWithThisParam | tst.ts:119:22:119:43 | Interfa ... isParam | test_ChildIndex test_TypeArguments | tst.ts:102:13:102:29 | f1("foo") | 0 | 1 | tst.ts:102:16:102:21 | string | diff --git a/javascript/ql/test/query-tests/Declarations/UnusedVariable/thisparam.ts b/javascript/ql/test/query-tests/Declarations/UnusedVariable/thisparam.ts new file mode 100644 index 000000000000..07f817e287a8 --- /dev/null +++ b/javascript/ql/test/query-tests/Declarations/UnusedVariable/thisparam.ts @@ -0,0 +1,11 @@ +import { Foo, Bar, Baz } from "somewhere"; // OK + +export function f(this: Foo) {} + +export class C { + m(this: Bar) {} +} + +export default { + foo(this: Baz) {} +}