From 234f968294c5cfe47048ebd28dc85c97fd6df7c3 Mon Sep 17 00:00:00 2001 From: Asger Feldthaus Date: Tue, 23 Jun 2020 11:42:28 +0100 Subject: [PATCH 1/3] JS: Deprecate property lookup on types --- .../lib/typescript/src/type_table.ts | 22 ++++++----- .../ql/src/semmle/javascript/TypeScript.qll | 39 ++++++------------- .../TypeScript/ArrayTypes/ArrayTypes.expected | 15 ------- .../ArrayTypes/NumberIndexTypes.expected | 15 ------- .../TypeScript/ArrayTypes/TupleTypes.expected | 1 - .../TypeScript/BaseTypes/BaseTypes.expected | 1 - .../TypeScript/BaseTypes/SelfTypes.expected | 4 -- .../CallSignatureTypes/test.expected | 27 ------------- .../ExpansiveTypes/ExpansiveTypes.expected | 6 +++ .../ExpansiveTypes/NonExpansiveTypes.expected | 32 +-------------- .../GlobalQualifiedNames.expected | 4 -- .../TypeScript/ExternalTypes/Types.expected | 4 -- .../LexicalTypes/TypeReferences.expected | 8 ---- .../Namespaces.expected | 1 - .../RegressionTests/EmptyName/test.expected | 6 --- .../SemicolonInName/test.expected | 2 - .../LexicalTypeVariables.expected | 1 - .../SignatureTypeParameters.expected | 12 ------ 18 files changed, 31 insertions(+), 169 deletions(-) diff --git a/javascript/extractor/lib/typescript/src/type_table.ts b/javascript/extractor/lib/typescript/src/type_table.ts index 287d11c1bd74..7a5b4fab6a1d 100644 --- a/javascript/extractor/lib/typescript/src/type_table.ts +++ b/javascript/extractor/lib/typescript/src/type_table.ts @@ -875,21 +875,23 @@ export class TypeTable { } /** - * Returns the properties of the given type, or `null` if the properties of this - * type could not be computed. + * Returns the properties to extract for the given type or `null` if nothing should be extracted. + * + * For performance reasons we only extract properties needed to recognize promise types at the QL + * level. */ - private tryGetProperties(type: ts.Type) { - // Workaround for https://github.com/Microsoft/TypeScript/issues/30845 - // Should be safe to remove once that has been fixed. - try { - return type.getProperties(); - } catch (e) { - return null; + private getPropertiesToExtract(type: ts.Type) { + if (this.getSelfType(type) === type) { + let thenSymbol = this.typeChecker.getPropertyOfType(type, "then"); + if (thenSymbol != null) { + return [thenSymbol]; + } } + return null; } private extractProperties(type: ts.Type, id: number) { - let props = this.tryGetProperties(type); + let props = this.getPropertiesToExtract(type); if (props == null) return; for (let symbol of props) { let propertyType = this.tryGetTypeOfSymbol(symbol); diff --git a/javascript/ql/src/semmle/javascript/TypeScript.qll b/javascript/ql/src/semmle/javascript/TypeScript.qll index 8da09d065145..72536ea5db4a 100644 --- a/javascript/ql/src/semmle/javascript/TypeScript.qll +++ b/javascript/ql/src/semmle/javascript/TypeScript.qll @@ -1649,11 +1649,9 @@ class Type extends @type { Type getChild(int i) { type_child(result, this, i) } /** - * Gets the type of the given property of this type. - * - * Note that this does not account for properties implied by index signatures. + * DEPRECATED. Property lookup on types is no longer supported. */ - Type getProperty(string name) { type_property(this, name, result) } + deprecated Type getProperty(string name) { none() } /** * Gets the type of the string index signature on this type, @@ -1758,33 +1756,19 @@ class Type extends @type { int getNumConstructorSignature() { result = count(getAConstructorSignature()) } /** - * Gets the last signature of the method of the given name. - * - * For overloaded methods, this is the most general version of the its - * signature, which covers all cases, but with less precision than the - * overload signatures. - * - * Use `getAMethodOverload` to get any of its overload signatures. + * DEPRECATED. Method lookup on types is no longer supported. */ - FunctionCallSignatureType getMethod(string name) { - result = getProperty(name).getLastFunctionSignature() - } + deprecated FunctionCallSignatureType getMethod(string name) { none() } /** - * Gets the `n`th overload signature of the given method. + * DEPRECATED. Method lookup on types is no longer supported. */ - FunctionCallSignatureType getMethodOverload(string name, int n) { - result = getProperty(name).getFunctionSignature(n) - } + deprecated FunctionCallSignatureType getMethodOverload(string name, int n) { none() } /** - * Gets a signature of the method of the given name. - * - * Overloaded methods have multiple signatures. + * DEPRECATED. Method lookup on types is no longer supported. */ - FunctionCallSignatureType getAMethodOverload(string name) { - result = getProperty(name).getAFunctionSignature() - } + deprecated FunctionCallSignatureType getAMethodOverload(string name) { none() } /** * Repeatedly unfolds union and intersection types and gets any of the underlying types, @@ -2638,10 +2622,11 @@ private class PromiseTypeName extends TypeName { name.matches("%Deferred") ) and // The `then` method should take a callback, taking an argument of type `T`. - exists(TypeReference self | self = getType() | + exists(TypeReference self, Type thenMethod | self = getType() | self.getNumTypeArgument() = 1 and - self - .getAMethodOverload("then") + type_property(self, "then", thenMethod) and + thenMethod + .getAFunctionSignature() .getParameter(0) .unfold() .getAFunctionSignature() diff --git a/javascript/ql/test/library-tests/TypeScript/ArrayTypes/ArrayTypes.expected b/javascript/ql/test/library-tests/TypeScript/ArrayTypes/ArrayTypes.expected index 178800c032a4..abf10730c0ab 100644 --- a/javascript/ql/test/library-tests/TypeScript/ArrayTypes/ArrayTypes.expected +++ b/javascript/ql/test/library-tests/TypeScript/ArrayTypes/ArrayTypes.expected @@ -1,20 +1,5 @@ -| (T \| ConcatArray)[] | `T \| ConcatArray` | -| (number \| ConcatArray)[] | `number \| ConcatArray` | -| (number[] \| ConcatArray)[] | `number[] \| ConcatArray` | -| (string \| number \| ConcatArray)[] | `string \| number \| ConcatArray` | -| (string \| number)[] | `string \| number` | -| ConcatArray[] | `ConcatArray` | -| ConcatArray[] | `ConcatArray` | -| ConcatArray[] | `ConcatArray` | -| ConcatArray[] | `ConcatArray` | -| S[] | `S` | -| T[] | `T` | -| U[] | `U` | | [number, string] | `string \| number` | -| any[] | `any` | | number[] | `number` | -| number[][] | `number[]` | | readonly T[] | `T` | | readonly number[] | `number` | | readonly number[][] | `number[]` | -| string[] | `string` | diff --git a/javascript/ql/test/library-tests/TypeScript/ArrayTypes/NumberIndexTypes.expected b/javascript/ql/test/library-tests/TypeScript/ArrayTypes/NumberIndexTypes.expected index a48d79176876..b1730697490e 100644 --- a/javascript/ql/test/library-tests/TypeScript/ArrayTypes/NumberIndexTypes.expected +++ b/javascript/ql/test/library-tests/TypeScript/ArrayTypes/NumberIndexTypes.expected @@ -1,22 +1,7 @@ -| (T \| ConcatArray)[] | T \| ConcatArray | -| (number \| ConcatArray)[] | number \| ConcatArray | -| (number[] \| ConcatArray)[] | number[] \| ConcatArray | -| (string \| number \| ConcatArray)[] | string \| number \| ConcatArray | -| (string \| number)[] | string \| number | -| ConcatArray[] | ConcatArray | -| ConcatArray[] | ConcatArray | -| ConcatArray[] | ConcatArray | -| ConcatArray[] | ConcatArray | | NumberIndexable | object | -| S[] | S | -| T[] | T | -| U[] | U | | [number, string] | string \| number | -| any[] | any | | number[] | number | -| number[][] | number[] | | readonly T[] | T | | readonly number[] | number | | readonly number[][] | number[] | | string | string | -| string[] | string | diff --git a/javascript/ql/test/library-tests/TypeScript/ArrayTypes/TupleTypes.expected b/javascript/ql/test/library-tests/TypeScript/ArrayTypes/TupleTypes.expected index 45c7d18b6047..e69de29bb2d1 100644 --- a/javascript/ql/test/library-tests/TypeScript/ArrayTypes/TupleTypes.expected +++ b/javascript/ql/test/library-tests/TypeScript/ArrayTypes/TupleTypes.expected @@ -1 +0,0 @@ -| [number, string] | (string \| number)[] | diff --git a/javascript/ql/test/library-tests/TypeScript/BaseTypes/BaseTypes.expected b/javascript/ql/test/library-tests/TypeScript/BaseTypes/BaseTypes.expected index 993212d1e6b3..b6e9c06ec571 100644 --- a/javascript/ql/test/library-tests/TypeScript/BaseTypes/BaseTypes.expected +++ b/javascript/ql/test/library-tests/TypeScript/BaseTypes/BaseTypes.expected @@ -13,4 +13,3 @@ | IMulti | IGenericBase | | IStringSub | IGenericBase | | ISub | IBase | -| RegExpMatchArray | Array | diff --git a/javascript/ql/test/library-tests/TypeScript/BaseTypes/SelfTypes.expected b/javascript/ql/test/library-tests/TypeScript/BaseTypes/SelfTypes.expected index 1504cae486e9..c82909543dfc 100644 --- a/javascript/ql/test/library-tests/TypeScript/BaseTypes/SelfTypes.expected +++ b/javascript/ql/test/library-tests/TypeScript/BaseTypes/SelfTypes.expected @@ -7,7 +7,6 @@ | CImplementsString | CImplementsString | | CStringSub | CStringSub | | CSub | CSub | -| CollatorOptions | CollatorOptions | | IBase | IBase | | IEmpty | IEmpty | | IEmptySub | IEmptySub | @@ -16,6 +15,3 @@ | IMulti | IMulti | | IStringSub | IStringSub | | ISub | ISub | -| NumberFormatOptions | NumberFormatOptions | -| RegExp | RegExp | -| RegExpMatchArray | RegExpMatchArray | diff --git a/javascript/ql/test/library-tests/TypeScript/CallSignatureTypes/test.expected b/javascript/ql/test/library-tests/TypeScript/CallSignatureTypes/test.expected index 3e49ac18fa4d..2c6bf9153a8b 100644 --- a/javascript/ql/test/library-tests/TypeScript/CallSignatureTypes/test.expected +++ b/javascript/ql/test/library-tests/TypeScript/CallSignatureTypes/test.expected @@ -108,51 +108,24 @@ test_FunctionCallSig | tst.ts:63:3:63:23 | method2 ... ing[]); | (y: string[]): any | | tst.ts:64:3:64:21 | method3(y: string); | (y: string): any | test_getRestParameterType -| (...items: (string \| ConcatArray)[]): T[] | string \| ConcatArray | -| (...items: ConcatArray[]): T[] | ConcatArray | -| (...items: string[]): number | string | -| (...strings: string[]): string | string | | (...y: string[]): any | string | -| (start: number, deleteCount: number, ...items: string[]): T[] | string | -| (substring: string, ...args: any[]): string | any | | (x: number, ...y: string[]): any | string | | new (...y: string[]): any | string | | new (x: number, ...y: string[]): any | string | test_getRestParameterArray -| (...items: (string \| ConcatArray)[]): T[] | (string \| ConcatArray)[] | -| (...items: ConcatArray[]): T[] | ConcatArray[] | -| (...items: string[]): number | string[] | -| (...strings: string[]): string | string[] | | (...y: string[]): any | string[] | -| (start: number, deleteCount: number, ...items: string[]): T[] | string[] | -| (substring: string, ...args: any[]): string | any[] | | (x: number, ...y: string[]): any | string[] | | new (...y: string[]): any | string[] | | new (x: number, ...y: string[]): any | string[] | test_RestSig_getParameter -| (...items: (string \| ConcatArray)[]): T[] | 0 | items | string \| ConcatArray | -| (...items: ConcatArray[]): T[] | 0 | items | ConcatArray | -| (...items: string[]): number | 0 | items | string | -| (...strings: string[]): string | 0 | strings | string | | (...y: string[]): any | 0 | y | string | -| (start: number, deleteCount: number, ...items: string[]): T[] | 0 | start | number | -| (start: number, deleteCount: number, ...items: string[]): T[] | 1 | deleteCount | number | -| (start: number, deleteCount: number, ...items: string[]): T[] | 2 | items | string | -| (substring: string, ...args: any[]): string | 0 | substring | string | -| (substring: string, ...args: any[]): string | 1 | args | any | | (x: number, ...y: string[]): any | 0 | x | number | | (x: number, ...y: string[]): any | 1 | y | string | | new (...y: string[]): any | 0 | y | string | | new (x: number, ...y: string[]): any | 0 | x | number | | new (x: number, ...y: string[]): any | 1 | y | string | test_RestSig_numRequiredParams -| (...items: (string \| ConcatArray)[]): T[] | 0 | -| (...items: ConcatArray[]): T[] | 0 | -| (...items: string[]): number | 0 | -| (...strings: string[]): string | 0 | | (...y: string[]): any | 0 | -| (start: number, deleteCount: number, ...items: string[]): T[] | 2 | -| (substring: string, ...args: any[]): string | 1 | | (x: number, ...y: string[]): any | 1 | | new (...y: string[]): any | 0 | | new (x: number, ...y: string[]): any | 1 | diff --git a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/ExpansiveTypes.expected b/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/ExpansiveTypes.expected index d7a7b838ea5c..5265a81f3357 100644 --- a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/ExpansiveTypes.expected +++ b/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/ExpansiveTypes.expected @@ -1,3 +1,8 @@ +WARNING: Predicate getProperty has been deprecated and may be removed in future (ExpansiveTypes.ql:5,19-30) +| After in library-tests/TypeScript/ExpansiveTypes/leading_into_expansion.ts | has no properties | +| AfterX in library-tests/TypeScript/ExpansiveTypes/used_from_expansion.ts | has no properties | +| Before in library-tests/TypeScript/ExpansiveTypes/leading_into_expansion.ts | has no properties | +| BeforeX in library-tests/TypeScript/ExpansiveTypes/used_from_expansion.ts | has no properties | | Box in library-tests/TypeScript/ExpansiveTypes/shared_non_expansive.ts | has no properties | | Box in library-tests/TypeScript/ExpansiveTypes/through_non_expansive.ts | has no properties | | C in library-tests/TypeScript/ExpansiveTypes/expansive_class.ts | has no properties | @@ -21,3 +26,4 @@ | ExpansiveSignature in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has no properties | | ExpansiveSignatureTypeBound in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has no properties | | ExpansiveX in library-tests/TypeScript/ExpansiveTypes/used_from_expansion.ts | has no properties | +| NonExpansive in library-tests/TypeScript/ExpansiveTypes/shared_non_expansive.ts | has no properties | diff --git a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/NonExpansiveTypes.expected b/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/NonExpansiveTypes.expected index be88dc0f34ef..e6e660fd9dcf 100644 --- a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/NonExpansiveTypes.expected +++ b/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/NonExpansiveTypes.expected @@ -1,31 +1 @@ -| After in library-tests/TypeScript/ExpansiveTypes/leading_into_expansion.ts | has properties | -| AfterX in library-tests/TypeScript/ExpansiveTypes/used_from_expansion.ts | has properties | -| Array in global scope | has properties | -| Before in library-tests/TypeScript/ExpansiveTypes/leading_into_expansion.ts | has properties | -| BeforeX in library-tests/TypeScript/ExpansiveTypes/used_from_expansion.ts | has properties | -| Box in library-tests/TypeScript/ExpansiveTypes/shared_non_expansive.ts | has properties | -| Box in library-tests/TypeScript/ExpansiveTypes/through_non_expansive.ts | has properties | -| C in library-tests/TypeScript/ExpansiveTypes/expansive_class.ts | has properties | -| Expand in library-tests/TypeScript/ExpansiveTypes/through_non_expansive.ts | has properties | -| ExpandUsingObjectLiteral in library-tests/TypeScript/ExpansiveTypes/expansive_object_literal.ts | has properties | -| Expansive in library-tests/TypeScript/ExpansiveTypes/leading_into_expansion.ts | has properties | -| Expansive in library-tests/TypeScript/ExpansiveTypes/simple.ts | has properties | -| ExpansiveA in library-tests/TypeScript/ExpansiveTypes/mutual.ts | has properties | -| ExpansiveA in library-tests/TypeScript/ExpansiveTypes/mutual_multigraph.ts | has properties | -| ExpansiveB in library-tests/TypeScript/ExpansiveTypes/mutual.ts | has properties | -| ExpansiveB in library-tests/TypeScript/ExpansiveTypes/mutual_multigraph.ts | has properties | -| ExpansiveByInference in library-tests/TypeScript/ExpansiveTypes/expansive_by_inference.ts | has properties | -| ExpansiveC in library-tests/TypeScript/ExpansiveTypes/mutual.ts | has properties | -| ExpansiveC in library-tests/TypeScript/ExpansiveTypes/mutual_multigraph.ts | has properties | -| ExpansiveConstructSignature in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has properties | -| ExpansiveD in library-tests/TypeScript/ExpansiveTypes/mutual.ts | has properties | -| ExpansiveD in library-tests/TypeScript/ExpansiveTypes/mutual_multigraph.ts | has properties | -| ExpansiveFunctionType in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has properties | -| ExpansiveMethod in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has properties | -| ExpansiveParameter in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has properties | -| ExpansiveSignature in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has properties | -| ExpansiveSignatureTypeBound in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has properties | -| ExpansiveX in library-tests/TypeScript/ExpansiveTypes/used_from_expansion.ts | has properties | -| Intl.CollatorOptions in global scope | has properties | -| Intl.NumberFormatOptions in global scope | has properties | -| NonExpansive in library-tests/TypeScript/ExpansiveTypes/shared_non_expansive.ts | has properties | +WARNING: Predicate getProperty has been deprecated and may be removed in future (NonExpansiveTypes.ql:4,19-30) diff --git a/javascript/ql/test/library-tests/TypeScript/ExternalTypes/GlobalQualifiedNames.expected b/javascript/ql/test/library-tests/TypeScript/ExternalTypes/GlobalQualifiedNames.expected index 5ec7d2978c2e..50447d5738a2 100644 --- a/javascript/ql/test/library-tests/TypeScript/ExternalTypes/GlobalQualifiedNames.expected +++ b/javascript/ql/test/library-tests/TypeScript/ExternalTypes/GlobalQualifiedNames.expected @@ -1,8 +1,4 @@ -| Intl.CollatorOptions | CollatorOptions | -| Intl.NumberFormatOptions | NumberFormatOptions | | LegacyGlobals.LegacySubclass | LegacySubclass | | Modern.ModernClass | ModernClass | | ModernGlobals.ModernSubclass | ModernSubclass | -| RegExp | RegExp | -| RegExpMatchArray | RegExpMatchArray | | __Legacy.LegacyClass | LegacyClass | diff --git a/javascript/ql/test/library-tests/TypeScript/ExternalTypes/Types.expected b/javascript/ql/test/library-tests/TypeScript/ExternalTypes/Types.expected index 0edfe5ea8cee..8fc560cd692e 100644 --- a/javascript/ql/test/library-tests/TypeScript/ExternalTypes/Types.expected +++ b/javascript/ql/test/library-tests/TypeScript/ExternalTypes/Types.expected @@ -1,5 +1,4 @@ | Augmentation | defined in augmentation.ts | -| CollatorOptions | has no definition | | ExternalType1 | has no definition | | ExternalType2 | has no definition | | InternalType | defined in client_esmodule.ts | @@ -7,9 +6,6 @@ | LegacySubclass | has no definition | | ModernClass | has no definition | | ModernSubclass | has no definition | -| NumberFormatOptions | has no definition | | OtherClass | has no definition | -| RegExp | has no definition | -| RegExpMatchArray | has no definition | | UtilClass | has no definition | | UtilExtraClass | has no definition | diff --git a/javascript/ql/test/library-tests/TypeScript/LexicalTypes/TypeReferences.expected b/javascript/ql/test/library-tests/TypeScript/LexicalTypes/TypeReferences.expected index 22de8996b657..4e6e39d9f47b 100644 --- a/javascript/ql/test/library-tests/TypeScript/LexicalTypes/TypeReferences.expected +++ b/javascript/ql/test/library-tests/TypeScript/LexicalTypes/TypeReferences.expected @@ -1,24 +1,16 @@ | C | 1 | bar.ts:10:10:10:24 | class C {} | | C | 1 | foo.ts:10:10:10:24 | class C {} | -| C | 1 | bar.ts:10:10:10:24 | class C {} | -| C | 1 | foo.ts:10:10:10:24 | class C {} | | C | 1 | bar.ts:10:10:10:24 | class C {} | | C | 1 | foo.ts:10:10:10:24 | class C {} | | ExportedClass | 1 | bar.ts:4:8:4:34 | class E ... Bar> {} | | ExportedClass | 1 | foo.ts:4:8:4:34 | class E ... Foo> {} | -| ExportedClass | 1 | bar.ts:4:8:4:34 | class E ... Bar> {} | -| ExportedClass | 1 | foo.ts:4:8:4:34 | class E ... Foo> {} | | ExportedClass | 1 | bar.ts:4:8:4:34 | class E ... Bar> {} | | ExportedClass | 1 | foo.ts:4:8:4:34 | class E ... Foo> {} | | InnerC | 1 | foo.ts:13:3:13:23 | class I ... oo1> {} | | InnerC | 1 | foo.ts:18:3:18:23 | class I ... oo2> {} | -| InnerC | 1 | foo.ts:13:3:13:23 | class I ... oo1> {} | -| InnerC | 1 | foo.ts:18:3:18:23 | class I ... oo2> {} | | InnerC | 1 | foo.ts:13:3:13:23 | class I ... oo1> {} | | InnerC | 1 | foo.ts:18:3:18:23 | class I ... oo2> {} | | LocalClass | 1 | bar.ts:3:1:3:24 | class L ... Bar> {} | | LocalClass | 1 | foo.ts:3:1:3:24 | class L ... Foo> {} | -| LocalClass | 1 | bar.ts:3:1:3:24 | class L ... Bar> {} | -| LocalClass | 1 | foo.ts:3:1:3:24 | class L ... Foo> {} | | LocalClass | 1 | bar.ts:3:1:3:24 | class L ... Bar> {} | | LocalClass | 1 | foo.ts:3:1:3:24 | class L ... Foo> {} | diff --git a/javascript/ql/test/library-tests/TypeScript/QualifiedNameResolution/Namespaces.expected b/javascript/ql/test/library-tests/TypeScript/QualifiedNameResolution/Namespaces.expected index 14e5b3f58e68..214b23594e7f 100644 --- a/javascript/ql/test/library-tests/TypeScript/QualifiedNameResolution/Namespaces.expected +++ b/javascript/ql/test/library-tests/TypeScript/QualifiedNameResolution/Namespaces.expected @@ -20,7 +20,6 @@ | Glob in global scope | | H in namespaces.ts:27 | | H.I in namespaces.ts:27 | -| Intl in global scope | | N in library-tests/TypeScript/QualifiedNameResolution/export-specifiers.ts | | X in global scope | | X in library-tests/TypeScript/QualifiedNameResolution/namespaces.ts | diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmptyName/test.expected b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmptyName/test.expected index 10f73fbb1a62..47317a00a867 100644 --- a/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmptyName/test.expected +++ b/javascript/ql/test/library-tests/TypeScript/RegressionTests/EmptyName/test.expected @@ -1,10 +1,4 @@ -| Array in global scope | -| Intl in global scope | -| Intl.CollatorOptions in global scope | -| Intl.NumberFormatOptions in global scope | | MK in unknown scope | | Mapped in library-tests/TypeScript/RegressionTests/EmptyName/test.ts | -| RegExp in global scope | -| RegExpMatchArray in global scope | | fn in library-tests/TypeScript/RegressionTests/EmptyName/test.ts | | library-tests/TypeScript/RegressionTests/EmptyName/test.ts | diff --git a/javascript/ql/test/library-tests/TypeScript/RegressionTests/SemicolonInName/test.expected b/javascript/ql/test/library-tests/TypeScript/RegressionTests/SemicolonInName/test.expected index f0dd1b478b57..074e6d0c2777 100644 --- a/javascript/ql/test/library-tests/TypeScript/RegressionTests/SemicolonInName/test.expected +++ b/javascript/ql/test/library-tests/TypeScript/RegressionTests/SemicolonInName/test.expected @@ -1,4 +1,2 @@ | Bar.Foo in global scope | Bar in global scope | -| Intl.CollatorOptions in global scope | Intl in global scope | -| Intl.NumberFormatOptions in global scope | Intl in global scope | | fn in library-tests/TypeScript/RegressionTests/SemicolonInName/test.ts | library-tests/TypeScript/RegressionTests/SemicolonInName/test.ts | diff --git a/javascript/ql/test/library-tests/TypeScript/TypeVariableTypes/LexicalTypeVariables.expected b/javascript/ql/test/library-tests/TypeScript/TypeVariableTypes/LexicalTypeVariables.expected index c701beea9ed3..3af63348cc2c 100644 --- a/javascript/ql/test/library-tests/TypeScript/TypeVariableTypes/LexicalTypeVariables.expected +++ b/javascript/ql/test/library-tests/TypeScript/TypeVariableTypes/LexicalTypeVariables.expected @@ -1,4 +1,3 @@ | D | D | | E | E | | S | S | -| U | U | diff --git a/javascript/ql/test/library-tests/TypeScript/TypeVariableTypes/SignatureTypeParameters.expected b/javascript/ql/test/library-tests/TypeScript/TypeVariableTypes/SignatureTypeParameters.expected index 3b6ee6a25b6c..307e516d3c79 100644 --- a/javascript/ql/test/library-tests/TypeScript/TypeVariableTypes/SignatureTypeParameters.expected +++ b/javascript/ql/test/library-tests/TypeScript/TypeVariableTypes/SignatureTypeParameters.expected @@ -2,18 +2,6 @@ | (x: () => E): E | 1 | 0 | E | no bound | | (x: E[] \| (() => E)): E | 1 | 0 | E | no bound | | (x: E[]): E | 1 | 0 | E | no bound | -| (callbackfn: (value: E, index: number, array: E[]) => va... | 1 | 0 | S | no bound | -| (callbackfn: (value: T \| S, index: number, array: (T... | 1 | 0 | S | no bound | -| (callbackfn: (value: T, index: number, array: T[]) => va... | 1 | 0 | S | no bound | -| (callbackfn: (value: any, index: number, array: any[])... | 1 | 0 | S | any | | (x: S, y: T[]): S | 1 | 0 | S | any[] | | (x: S, y: S): S | 1 | 0 | S | no bound | | (x: S, y: T): [S, T] | 1 | 0 | S | no bound | -| (callbackfn: (previousValue: U, currentValue: E, currentIndex: num... | 1 | 0 | U | no bound | -| (callbackfn: (previousValue: U, currentValue: T \| S, currentIndex:... | 1 | 0 | U | no bound | -| (callbackfn: (previousValue: U, currentValue: T, currentIndex: num... | 1 | 0 | U | no bound | -| (callbackfn: (previousValue: U, currentValue: any, currentIndex: n... | 1 | 0 | U | no bound | -| (callbackfn: (value: E, index: number, array: E[]) => U, thisArg?:... | 1 | 0 | U | no bound | -| (callbackfn: (value: T \| S, index: number, array: (T \| S)[]) => U,... | 1 | 0 | U | no bound | -| (callbackfn: (value: T, index: number, array: T[]) => U, thisArg?:... | 1 | 0 | U | no bound | -| (callbackfn: (value: any, index: number, array: any[]) => U, thisA... | 1 | 0 | U | no bound | From 4f67cc269bcfff90dd61cab59d7dc6f950bd88ae Mon Sep 17 00:00:00 2001 From: Asger Feldthaus Date: Tue, 23 Jun 2020 11:44:07 +0100 Subject: [PATCH 2/3] JS: Reduce ExpansiveTypes test --- .../ExpansiveTypes/ExpansiveTypes.expected | 29 ------- .../ExpansiveTypes/ExpansiveTypes.ql | 11 --- .../ExpansiveTypes/NonExpansiveTypes.expected | 1 - .../ExpansiveTypes/NonExpansiveTypes.ql | 5 -- .../TypeScript/ExpansiveTypes/Types.expected | 77 +++++++++++++++++++ .../TypeScript/ExpansiveTypes/Types.ql | 4 + 6 files changed, 81 insertions(+), 46 deletions(-) delete mode 100644 javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/ExpansiveTypes.expected delete mode 100644 javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/ExpansiveTypes.ql delete mode 100644 javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/NonExpansiveTypes.expected delete mode 100644 javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/NonExpansiveTypes.ql create mode 100644 javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/Types.expected create mode 100644 javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/Types.ql diff --git a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/ExpansiveTypes.expected b/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/ExpansiveTypes.expected deleted file mode 100644 index 5265a81f3357..000000000000 --- a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/ExpansiveTypes.expected +++ /dev/null @@ -1,29 +0,0 @@ -WARNING: Predicate getProperty has been deprecated and may be removed in future (ExpansiveTypes.ql:5,19-30) -| After in library-tests/TypeScript/ExpansiveTypes/leading_into_expansion.ts | has no properties | -| AfterX in library-tests/TypeScript/ExpansiveTypes/used_from_expansion.ts | has no properties | -| Before in library-tests/TypeScript/ExpansiveTypes/leading_into_expansion.ts | has no properties | -| BeforeX in library-tests/TypeScript/ExpansiveTypes/used_from_expansion.ts | has no properties | -| Box in library-tests/TypeScript/ExpansiveTypes/shared_non_expansive.ts | has no properties | -| Box in library-tests/TypeScript/ExpansiveTypes/through_non_expansive.ts | has no properties | -| C in library-tests/TypeScript/ExpansiveTypes/expansive_class.ts | has no properties | -| Expand in library-tests/TypeScript/ExpansiveTypes/through_non_expansive.ts | has no properties | -| ExpandUsingObjectLiteral in library-tests/TypeScript/ExpansiveTypes/expansive_object_literal.ts | has no properties | -| Expansive in library-tests/TypeScript/ExpansiveTypes/leading_into_expansion.ts | has no properties | -| Expansive in library-tests/TypeScript/ExpansiveTypes/simple.ts | has no properties | -| ExpansiveA in library-tests/TypeScript/ExpansiveTypes/mutual.ts | has no properties | -| ExpansiveA in library-tests/TypeScript/ExpansiveTypes/mutual_multigraph.ts | has no properties | -| ExpansiveB in library-tests/TypeScript/ExpansiveTypes/mutual.ts | has no properties | -| ExpansiveB in library-tests/TypeScript/ExpansiveTypes/mutual_multigraph.ts | has no properties | -| ExpansiveByInference in library-tests/TypeScript/ExpansiveTypes/expansive_by_inference.ts | has no properties | -| ExpansiveC in library-tests/TypeScript/ExpansiveTypes/mutual.ts | has no properties | -| ExpansiveC in library-tests/TypeScript/ExpansiveTypes/mutual_multigraph.ts | has no properties | -| ExpansiveConstructSignature in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has no properties | -| ExpansiveD in library-tests/TypeScript/ExpansiveTypes/mutual.ts | has no properties | -| ExpansiveD in library-tests/TypeScript/ExpansiveTypes/mutual_multigraph.ts | has no properties | -| ExpansiveFunctionType in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has no properties | -| ExpansiveMethod in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has no properties | -| ExpansiveParameter in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has no properties | -| ExpansiveSignature in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has no properties | -| ExpansiveSignatureTypeBound in library-tests/TypeScript/ExpansiveTypes/expansive_signature.ts | has no properties | -| ExpansiveX in library-tests/TypeScript/ExpansiveTypes/used_from_expansion.ts | has no properties | -| NonExpansive in library-tests/TypeScript/ExpansiveTypes/shared_non_expansive.ts | has no properties | diff --git a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/ExpansiveTypes.ql b/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/ExpansiveTypes.ql deleted file mode 100644 index 108559dc262c..000000000000 --- a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/ExpansiveTypes.ql +++ /dev/null @@ -1,11 +0,0 @@ -import javascript - -from TypeReference type -where - not exists(type.getProperty(_)) and - ( - exists(type.getADefinition().(ClassOrInterface).getAField()) - or - exists(type.getADefinition().(ClassOrInterface).getAMethod()) - ) -select type.getTypeName(), "has no properties" diff --git a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/NonExpansiveTypes.expected b/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/NonExpansiveTypes.expected deleted file mode 100644 index e6e660fd9dcf..000000000000 --- a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/NonExpansiveTypes.expected +++ /dev/null @@ -1 +0,0 @@ -WARNING: Predicate getProperty has been deprecated and may be removed in future (NonExpansiveTypes.ql:4,19-30) diff --git a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/NonExpansiveTypes.ql b/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/NonExpansiveTypes.ql deleted file mode 100644 index 14f99c2369e5..000000000000 --- a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/NonExpansiveTypes.ql +++ /dev/null @@ -1,5 +0,0 @@ -import javascript - -from TypeReference type -where exists(type.getProperty(_)) -select type.getTypeName(), "has properties" diff --git a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/Types.expected b/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/Types.expected new file mode 100644 index 000000000000..b769d79a261b --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/Types.expected @@ -0,0 +1,77 @@ +| After | +| AfterX | +| Before | +| BeforeX | +| Box> | +| Box | +| Box | +| Box | +| Box | +| C | +| C | +| Expand | +| Expand | +| ExpandUsingObjectLiteral | +| ExpandUsingObjectLiteral | +| Expansive | +| Expansive | +| Expansive | +| Expansive | +| Expansive | +| Expansive | +| ExpansiveA | +| ExpansiveA | +| ExpansiveA | +| ExpansiveA | +| ExpansiveB | +| ExpansiveB | +| ExpansiveB | +| ExpansiveB | +| ExpansiveB | +| ExpansiveB | +| ExpansiveByInference | +| ExpansiveByInference | +| ExpansiveC | +| ExpansiveC | +| ExpansiveC | +| ExpansiveC | +| ExpansiveC | +| ExpansiveC | +| ExpansiveConstructSignature | +| ExpansiveConstructSignature | +| ExpansiveD | +| ExpansiveD | +| ExpansiveD | +| ExpansiveD | +| ExpansiveFunctionType | +| ExpansiveFunctionType | +| ExpansiveMethod | +| ExpansiveMethod | +| ExpansiveParameter | +| ExpansiveParameter | +| ExpansiveSignature | +| ExpansiveSignature | +| ExpansiveSignatureTypeBound | +| ExpansiveSignatureTypeBound | +| ExpansiveX | +| ExpansiveX | +| NonExpansive> | +| NonExpansive | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | +| T[] | diff --git a/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/Types.ql b/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/Types.ql new file mode 100644 index 000000000000..6890e2937766 --- /dev/null +++ b/javascript/ql/test/library-tests/TypeScript/ExpansiveTypes/Types.ql @@ -0,0 +1,4 @@ +import javascript + +from TypeReference type +select type From e2a300e8113e09e25d2c74a8bde02b43c5edbf8b Mon Sep 17 00:00:00 2001 From: Asger Feldthaus Date: Tue, 23 Jun 2020 12:24:13 +0100 Subject: [PATCH 3/3] JS: Add change note --- change-notes/1.25/analysis-javascript.md | 1 + 1 file changed, 1 insertion(+) diff --git a/change-notes/1.25/analysis-javascript.md b/change-notes/1.25/analysis-javascript.md index 5a99e47cc396..e704c545f526 100644 --- a/change-notes/1.25/analysis-javascript.md +++ b/change-notes/1.25/analysis-javascript.md @@ -87,3 +87,4 @@ The following low-precision queries are no longer run by default on LGTM (their - `ParameterNode.asExpr()` and `.getAstNode()` now gets the parameter's AST node, whereas previously it had no result. - `Expr.flow()` now has a more meaningful result for destructuring patterns. Previously this node was disconnected from the data flow graph. Now it represents the values being destructured by the pattern. * The global data-flow and taint-tracking libraries now model indirect parameter accesses through the `arguments` object in some cases, which may lead to additional results from some of the security queries, particularly "Prototype pollution in utility function". +* The predicates `Type.getProperty()` and variants of `Type.getMethod()` have been deprecated due to lack of use-cases. Looking up a named property of a static type is no longer supported, favoring faster extraction times instead.