From 64f58b74f6a4ac346e1199f7eca221d910d6b327 Mon Sep 17 00:00:00 2001 From: Asger Feldthaus Date: Fri, 7 Aug 2020 11:55:26 +0100 Subject: [PATCH] JS: Fix extractor crash when some parameters have no type annotation --- .../extractor/src/com/semmle/js/extractor/ScopeManager.java | 4 +++- .../RegressionTests/PartialFunctionArgs/Test.expected | 1 + .../TypeScript/RegressionTests/PartialFunctionArgs/Test.ql | 4 ++++ .../RegressionTests/PartialFunctionArgs/tsconfig.json | 3 +++ .../TypeScript/RegressionTests/PartialFunctionArgs/tst.ts | 1 + 5 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/Test.expected create mode 100644 javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/Test.ql create mode 100644 javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/tsconfig.json create mode 100644 javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/tst.ts diff --git a/javascript/extractor/src/com/semmle/js/extractor/ScopeManager.java b/javascript/extractor/src/com/semmle/js/extractor/ScopeManager.java index 3bffa4ad3ae4..109b73f23097 100644 --- a/javascript/extractor/src/com/semmle/js/extractor/ScopeManager.java +++ b/javascript/extractor/src/com/semmle/js/extractor/ScopeManager.java @@ -622,7 +622,9 @@ public Void visit(FunctionExpression nd, Void c) { nd.getReturnType().accept(this, c); } for (ITypeExpression paramType : nd.getParameterTypes()) { - paramType.accept(this, c); + if (paramType != null) { + paramType.accept(this, c); + } } // note: `infer` types may not occur in type parameter bounds. return null; diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/Test.expected b/javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/Test.expected new file mode 100644 index 000000000000..20f2f4b6afa8 --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/Test.expected @@ -0,0 +1 @@ +| tst.ts:1:1:1:61 | type Fo ... : never | tst.ts:1:15:1:61 | T exten ... : never | diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/Test.ql b/javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/Test.ql new file mode 100644 index 000000000000..e6934ec24889 --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/Test.ql @@ -0,0 +1,4 @@ +import javascript + +from TypeAliasDeclaration decl +select decl, decl.getDefinition() diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/tsconfig.json b/javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/tsconfig.json new file mode 100644 index 000000000000..a1aaa6366d3b --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/tsconfig.json @@ -0,0 +1,3 @@ +{ + "include": ["."] +} \ No newline at end of file diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/tst.ts b/javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/tst.ts new file mode 100644 index 000000000000..4fc0417a6301 --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/RegressionTests/PartialFunctionArgs/tst.ts @@ -0,0 +1 @@ +type Foo = T extends (a, ...b: infer U) => any ? U : never