Merge pull request #766 from asger-semmle/ts-compiler-3.2

TS: Support TypeScript 3.2
This commit is contained in:
Max Schaefer
2019-01-16 08:49:45 +00:00
committed by GitHub
31 changed files with 5072 additions and 2707 deletions

View File

@@ -582,6 +582,9 @@ class TypeExpr extends ExprOrType, @typeexpr {
/** Holds if this is the `unknown` type. */
predicate isUnknownKeyword() { none() }
/** Holds if this is the `bigint` type. */
predicate isBigInt() { none() }
/** Gets this type expression, with any surrounding parentheses removed. */
override TypeExpr stripParens() { result = this }
@@ -633,6 +636,8 @@ private class KeywordTypeExpr extends @keywordtypeexpr, TypeExpr {
override predicate isObjectKeyword() { getName() = "object" }
override predicate isUnknownKeyword() { getName() = "unknown" }
override predicate isBigInt() { getName() = "bigint" }
}
/**
@@ -798,6 +803,18 @@ class BooleanLiteralTypeExpr extends @booleanliteraltypeexpr, LiteralTypeExpr {
predicate isFalse() { getValue() = "false" }
}
/** A bigint literal used as a TypeScript type annotation. */
class BigIntLiteralTypeExpr extends @bigintliteraltypeexpr, LiteralTypeExpr {
/** Gets the integer value of the bigint literal, if it can be represented as a QL integer. */
int getIntValue() { result = getValue().toInt() }
/**
* Gets the floating point value of this literal if it can be represented
* as a QL floating point value.
*/
float getFloatValue() { result = getValue().toFloat() }
}
/**
* An array type, such as `number[]`, or in general `T[]` where `T` is a type.
*
@@ -1950,6 +1967,11 @@ class StringType extends Type, @stringtype { }
*/
class NumberType extends Type, @numbertype { }
/**
* The predefined `bigint` type.
*/
class BigIntType extends Type, @biginttype { }
/**
* A boolean, number, or string literal type.
*/
@@ -1998,6 +2020,23 @@ class StringLiteralType extends LiteralType, @stringliteraltype {
override string getStringValue() { type_literal_value(this, result) }
}
/**
* A bigint literal as a static type.
*/
class BigIntLiteralType extends LiteralType {
override string getStringValue() { type_literal_value(this, result) }
/**
* Gets the value of the literal as an integer.
*/
int getIntValue() { result = getStringValue().toInt() }
/**
* Gets the value of the literal as a floating-point value.
*/
float getFloatValue() { result = getStringValue().toFloat() }
}
/**
* The `boolean` type, internally represented as the union type `true | false`.
*/

View File

@@ -560,12 +560,13 @@ case @typeexpr.kind of
| 32 = @importvartypeaccess
| 33 = @optionaltypeexpr
| 34 = @resttypeexpr
| 35 = @bigintliteraltypeexpr
;
@typeref = @typeaccess | @typedecl;
@typeidentifier = @typedecl | @localtypeaccess | @typelabel | @localvartypeaccess | @localnamespaceaccess;
@typeexpr_parent = @expr | @stmt | @property | @typeexpr;
@literaltypeexpr = @stringliteraltypeexpr | @numberliteraltypeexpr | @booleanliteraltypeexpr;
@literaltypeexpr = @stringliteraltypeexpr | @numberliteraltypeexpr | @booleanliteraltypeexpr | @bigintliteraltypeexpr;
@typeaccess = @localtypeaccess | @qualifiedtypeaccess | @importtypeaccess;
@vartypeaccess = @localvartypeaccess | @qualifiedvartypeaccess | @thisvartypeaccess | @importvartypeaccess;
@namespaceaccess = @localnamespaceaccess | @qualifiednamespaceaccess | @importnamespaceaccess;
@@ -612,6 +613,8 @@ case @type.kind of
| 21 = @numberliteraltype
| 22 = @stringliteraltype
| 23 = @unknowntype
| 24 = @biginttype
| 25 = @bigintliteraltype
;
@booleanliteraltype = @truetype | @falsetype;
@@ -678,8 +681,8 @@ type_property(
varchar(900) name: string ref,
int propertyType: @type ref);
@literaltype = @stringliteraltype | @numberliteraltype | @booleanliteraltype;
@type_with_literal_value = @stringliteraltype | @numberliteraltype;
@literaltype = @stringliteraltype | @numberliteraltype | @booleanliteraltype | @bigintliteraltype;
@type_with_literal_value = @stringliteraltype | @numberliteraltype | @bigintliteraltype;
type_literal_value(
unique int typ: @type_with_literal_value ref,
varchar(900) value: string ref);

View File

@@ -814,6 +814,10 @@
<v>100</v>
</e>
<e>
<k>@bigintliteraltypeexpr</k>
<v>100</v>
</e>
<e>
<k>@generictypeexpr</k>
<v>5220</v>
</e>
@@ -974,6 +978,14 @@
<v>100</v>
</e>
<e>
<k>@biginttype</k>
<v>100</v>
</e>
<e>
<k>@bigintliteraltype</k>
<v>100</v>
</e>
<e>
<k>@uniquesymboltype</k>
<v>100</v>
</e>

View File

@@ -0,0 +1,3 @@
| tst.ts:1:25:1:28 | 100n | 100.0 |
| tst.ts:2:25:2:56 | 1000000 ... 000000n | 1.0E30 |
| tst.ts:3:25:3:56 | 1000000 ... 000000n | 1.0E30 |

View File

@@ -0,0 +1,4 @@
import javascript
from BigIntLiteral literal
select literal, literal.getFloatValue()

View File

@@ -0,0 +1 @@
| tst.ts:1:25:1:28 | 100n | 100 |

View File

@@ -0,0 +1,4 @@
import javascript
from BigIntLiteral literal
select literal, literal.getIntValue()

View File

@@ -0,0 +1,4 @@
| tst.ts:1:5:1:11 | hundred |
| tst.ts:2:5:2:12 | bigValue |
| tst.ts:3:5:3:20 | bigNegativeValue |
| tst.ts:5:5:5:14 | bigintType |

View File

@@ -0,0 +1,5 @@
import javascript
from Expr e
where e.getType() instanceof BigIntType
select e

View File

@@ -0,0 +1 @@
| tst.ts:6:24:6:28 | 1000n | 1000 |

View File

@@ -0,0 +1,4 @@
import javascript
from BigIntLiteralTypeExpr type
select type, type.getIntValue()

View File

@@ -0,0 +1 @@
| tst.ts:5:24:5:29 | bigint |

View File

@@ -0,0 +1,5 @@
import javascript
from TypeExpr type
where type.isBigInt()
select type

View File

@@ -0,0 +1 @@
| 1000n | 1000 |

View File

@@ -0,0 +1,4 @@
import javascript
from BigIntLiteralType type
select type, type.getIntValue()

View File

@@ -0,0 +1 @@
{"include": ["."]}

View File

@@ -0,0 +1,6 @@
let hundred = 100n;
let bigValue = 1000000000000000000000000000000n;
let bigNegativeValue = -1000000000000000000000000000000n;
let bigintType: bigint;
let bigintLiteralType: 1000n;

View File

@@ -41,7 +41,7 @@
| tst.ts:29:22:29:26 | never | never |
| tst.ts:30:17:30:22 | symbol | symbol |
| tst.ts:31:25:31:37 | unique symbol | unique symbol |
| tst.ts:32:17:32:22 | object | any |
| tst.ts:32:17:32:22 | object | object |
| tst.ts:33:19:33:24 | string | string |
| tst.ts:33:19:33:38 | string & {x: string} | string & { x: string; } |
| tst.ts:33:28:33:38 | {x: string} | { x: string; } |