Skip to content

Commit 53abf83

Browse files
authored
Merge pull request github#3304 from asger-semmle/js/typescript-unary-type-expr
Approved by erik-krogh
2 parents 2ecef33 + 883846d commit 53abf83

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,16 @@ private Node convertLabeledStatement(JsonObject node, SourceLocation loc) throws
15881588
}
15891589

15901590
private Node convertLiteralType(JsonObject node, SourceLocation loc) throws ParseError {
1591-
return convertChild(node, "literal");
1591+
Node literal = convertChild(node, "literal");
1592+
// Convert a negated literal to a negative number
1593+
if (literal instanceof UnaryExpression) {
1594+
UnaryExpression unary = (UnaryExpression) literal;
1595+
if (unary.getOperator().equals("-") && unary.getArgument() instanceof Literal) {
1596+
Literal arg = (Literal) unary.getArgument();
1597+
literal = new Literal(loc, arg.getTokenType(), "-" + arg.getValue());
1598+
}
1599+
}
1600+
return literal;
15921601
}
15931602

15941603
private Node convertMappedType(JsonObject node, SourceLocation loc) throws ParseError {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| tst.ts:1:25:1:26 | -1 | -1 | -1 |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import javascript
2+
3+
from NumberLiteralTypeExpr t
4+
select t, t.getValue(), t.getIntValue()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"include": ["."]
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type Foo<T> = T extends -1 ? true : false;

0 commit comments

Comments
 (0)