Skip to content

Commit ed5fd96

Browse files
authored
Merge pull request #1227 from asger-semmle/typescript3.4
Approved by xiemaisi
2 parents 9f13b6b + bfa6208 commit ed5fd96

File tree

28 files changed

+2354
-59
lines changed

28 files changed

+2354
-59
lines changed

change-notes/1.21/analysis-javascript.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
* The security queries now track data flow through Base64 decoders such as the Node.js `Buffer` class, the DOM function `atob`, and a number of npm packages intcluding [`abab`](https://www.npmjs.com/package/abab), [`atob`](https://www.npmjs.com/package/atob), [`btoa`](https://www.npmjs.com/package/btoa), [`base-64`](https://www.npmjs.com/package/base-64), [`js-base64`](https://www.npmjs.com/package/js-base64), [`Base64.js`](https://www.npmjs.com/package/Base64) and [`base64-js`](https://www.npmjs.com/package/base64-js).
1414

15+
* TypeScript 3.4 features are now supported.
16+
1517

1618
## New queries
1719

change-notes/support/versions-compilers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Java,"Java 6 to 11 [2]_.","javac (OpenJDK and Oracle JDK)
1313
Eclipse compiler for Java (ECJ) batch compiler",``.java``
1414
JavaScript,ECMAScript 2018 or lower,Not applicable,"``.js``, ``.jsx``, ``.mjs``, ``.es``, ``.es6``, ``.htm``, ``.html``, ``.xhm``, ``.xhtml``, ``.vue``, ``.json`` [3]_."
1515
Python,"2.7, 3.5, 3.6, 3.7",Not applicable,``.py``
16-
TypeScript [4]_.,"2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2",Standard TypeScript compiler,"``.ts``, ``.tsx``"
16+
TypeScript [4]_.,"2.6-3.4",Standard TypeScript compiler,"``.ts``, ``.tsx``"

javascript/extractor/lib/typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "typescript-parser-wrapper",
33
"private": true,
44
"dependencies": {
5-
"typescript": "3.3.3333"
5+
"typescript": "3.4"
66
},
77
"scripts": {
88
"build": "tsc --project tsconfig.json && rollup -c",

javascript/extractor/lib/typescript/yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,9 +509,9 @@ tsutils@^2.12.1:
509509
dependencies:
510510
tslib "^1.8.1"
511511

512-
typescript@3.3.3333:
513-
version "3.3.3333"
514-
resolved "typescript-3.3.3333.tgz#171b2c5af66c59e9431199117a3bcadc66fdcfd6"
512+
typescript@3.4:
513+
version "3.4.3"
514+
resolved "typescript-3.4.3.tgz#0eb320e4ace9b10eadf5bc6103286b0f8b7c224f"
515515

516516
wrappy@1:
517517
version "1.0.2"

javascript/extractor/src/com/semmle/js/ast/DefaultVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.semmle.ts.ast.InterfaceTypeExpr;
3636
import com.semmle.ts.ast.IntersectionTypeExpr;
3737
import com.semmle.ts.ast.IsTypeExpr;
38-
import com.semmle.ts.ast.KeyofTypeExpr;
38+
import com.semmle.ts.ast.UnaryTypeExpr;
3939
import com.semmle.ts.ast.KeywordTypeExpr;
4040
import com.semmle.ts.ast.MappedTypeExpr;
4141
import com.semmle.ts.ast.NamespaceDeclaration;
@@ -619,7 +619,7 @@ public R visit(TupleTypeExpr nd, C c) {
619619
}
620620

621621
@Override
622-
public R visit(KeyofTypeExpr nd, C c) {
622+
public R visit(UnaryTypeExpr nd, C c) {
623623
return visit((TypeExpression) nd, c);
624624
}
625625

javascript/extractor/src/com/semmle/js/ast/NodeCopier.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.semmle.ts.ast.InterfaceTypeExpr;
3232
import com.semmle.ts.ast.IntersectionTypeExpr;
3333
import com.semmle.ts.ast.IsTypeExpr;
34-
import com.semmle.ts.ast.KeyofTypeExpr;
34+
import com.semmle.ts.ast.UnaryTypeExpr;
3535
import com.semmle.ts.ast.KeywordTypeExpr;
3636
import com.semmle.ts.ast.MappedTypeExpr;
3737
import com.semmle.ts.ast.NamespaceDeclaration;
@@ -700,8 +700,8 @@ public INode visit(TupleTypeExpr nd, Void c) {
700700
}
701701

702702
@Override
703-
public INode visit(KeyofTypeExpr nd, Void c) {
704-
return new KeyofTypeExpr(visit(nd.getLoc()), copy(nd.getElementType()));
703+
public INode visit(UnaryTypeExpr nd, Void c) {
704+
return new UnaryTypeExpr(visit(nd.getLoc()), nd.getKind(), copy(nd.getElementType()));
705705
}
706706

707707
@Override

javascript/extractor/src/com/semmle/js/ast/Visitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import com.semmle.ts.ast.InterfaceTypeExpr;
3232
import com.semmle.ts.ast.IntersectionTypeExpr;
3333
import com.semmle.ts.ast.IsTypeExpr;
34-
import com.semmle.ts.ast.KeyofTypeExpr;
34+
import com.semmle.ts.ast.UnaryTypeExpr;
3535
import com.semmle.ts.ast.KeywordTypeExpr;
3636
import com.semmle.ts.ast.MappedTypeExpr;
3737
import com.semmle.ts.ast.NamespaceDeclaration;
@@ -250,7 +250,7 @@ public interface Visitor<C, R> {
250250

251251
public R visit(TupleTypeExpr nd, C c);
252252

253-
public R visit(KeyofTypeExpr nd, C c);
253+
public R visit(UnaryTypeExpr nd, C c);
254254

255255
public R visit(GenericTypeExpr nd, C c);
256256

javascript/extractor/src/com/semmle/js/extractor/ASTExtractor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
import com.semmle.ts.ast.InterfaceTypeExpr;
126126
import com.semmle.ts.ast.IntersectionTypeExpr;
127127
import com.semmle.ts.ast.IsTypeExpr;
128-
import com.semmle.ts.ast.KeyofTypeExpr;
128+
import com.semmle.ts.ast.UnaryTypeExpr;
129129
import com.semmle.ts.ast.KeywordTypeExpr;
130130
import com.semmle.ts.ast.MappedTypeExpr;
131131
import com.semmle.ts.ast.NamespaceDeclaration;
@@ -1672,7 +1672,7 @@ public Label visit(TupleTypeExpr nd, Context c) {
16721672
}
16731673

16741674
@Override
1675-
public Label visit(KeyofTypeExpr nd, Context c) {
1675+
public Label visit(UnaryTypeExpr nd, Context c) {
16761676
Label key = super.visit(nd, c);
16771677
visit(nd.getElementType(), key, 0, IdContext.typeBind);
16781678
return key;

javascript/extractor/src/com/semmle/js/extractor/TypeExprKinds.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import com.semmle.ts.ast.InterfaceTypeExpr;
1818
import com.semmle.ts.ast.IntersectionTypeExpr;
1919
import com.semmle.ts.ast.IsTypeExpr;
20-
import com.semmle.ts.ast.KeyofTypeExpr;
20+
import com.semmle.ts.ast.UnaryTypeExpr;
2121
import com.semmle.ts.ast.KeywordTypeExpr;
2222
import com.semmle.ts.ast.MappedTypeExpr;
2323
import com.semmle.ts.ast.OptionalTypeExpr;
@@ -66,6 +66,7 @@ public class TypeExprKinds {
6666
private static final int optionalTypeExpr = 33;
6767
private static final int restTypeExpr = 34;
6868
private static final int bigintLiteralTypeExpr = 35;
69+
private static final int readonlyTypeExpr = 36;
6970

7071
public static int getTypeExprKind(final INode type, final IdContext idcontext) {
7172
Integer kind =
@@ -126,8 +127,12 @@ public Integer visit(TupleTypeExpr nd, Void c) {
126127
}
127128

128129
@Override
129-
public Integer visit(KeyofTypeExpr nd, Void c) {
130-
return keyofTypeExpr;
130+
public Integer visit(UnaryTypeExpr nd, Void c) {
131+
switch (nd.getKind()) {
132+
case Keyof: return keyofTypeExpr;
133+
case Readonly: return readonlyTypeExpr;
134+
}
135+
throw new CatastrophicError("Unhandled UnaryTypeExpr kind: " + nd.getKind());
131136
}
132137

133138
@Override

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
import com.semmle.ts.ast.InterfaceTypeExpr;
127127
import com.semmle.ts.ast.IntersectionTypeExpr;
128128
import com.semmle.ts.ast.IsTypeExpr;
129-
import com.semmle.ts.ast.KeyofTypeExpr;
129+
import com.semmle.ts.ast.UnaryTypeExpr;
130130
import com.semmle.ts.ast.KeywordTypeExpr;
131131
import com.semmle.ts.ast.MappedTypeExpr;
132132
import com.semmle.ts.ast.NamespaceDeclaration;
@@ -345,7 +345,7 @@ private Node convertNodeUntyped(JsonObject node, String defaultKind) throws Pars
345345
case "ArrowFunction":
346346
return convertArrowFunction(node, loc);
347347
case "AsExpression":
348-
return convertAsExpression(node, loc);
348+
return convertTypeAssertionExpression(node, loc);
349349
case "AwaitExpression":
350350
return convertAwaitExpression(node, loc);
351351
case "BigIntKeyword":
@@ -797,11 +797,6 @@ private Node convertArrowFunction(JsonObject node, SourceLocation loc) throws Pa
797797
convertChildAsType(node, "type"));
798798
}
799799

800-
private Node convertAsExpression(JsonObject node, SourceLocation loc) throws ParseError {
801-
return new TypeAssertion(
802-
loc, convertChild(node, "expression"), convertChildAsType(node, "type"), true);
803-
}
804-
805800
private Node convertAwaitExpression(JsonObject node, SourceLocation loc) throws ParseError {
806801
return new AwaitExpression(loc, convertChild(node, "expression"));
807802
}
@@ -2115,8 +2110,12 @@ private Node convertTypeAliasDeclaration(JsonObject node, SourceLocation loc) th
21152110

21162111
private Node convertTypeAssertionExpression(JsonObject node, SourceLocation loc)
21172112
throws ParseError {
2118-
return new TypeAssertion(
2119-
loc, convertChild(node, "expression"), convertChildAsType(node, "type"), false);
2113+
ITypeExpression type = convertChildAsType(node, "type");
2114+
// `T as const` is extracted as a cast to the keyword type `const`.
2115+
if (type instanceof Identifier && ((Identifier) type).getName().equals("const")) {
2116+
type = new KeywordTypeExpr(type.getLoc(), "const");
2117+
}
2118+
return new TypeAssertion(loc, convertChild(node, "expression"), type, false);
21202119
}
21212120

21222121
private Node convertTypeLiteral(JsonObject obj, SourceLocation loc) throws ParseError {
@@ -2130,7 +2129,10 @@ private Node convertTypeOfExpression(JsonObject node, SourceLocation loc) throws
21302129
private Node convertTypeOperator(JsonObject node, SourceLocation loc) throws ParseError {
21312130
String operator = syntaxKinds.get("" + node.get("operator").getAsInt()).getAsString();
21322131
if (operator.equals("KeyOfKeyword")) {
2133-
return new KeyofTypeExpr(loc, convertChildAsType(node, "type"));
2132+
return new UnaryTypeExpr(loc, UnaryTypeExpr.Kind.Keyof, convertChildAsType(node, "type"));
2133+
}
2134+
if (operator.equals("ReadonlyKeyword")) {
2135+
return new UnaryTypeExpr(loc, UnaryTypeExpr.Kind.Readonly, convertChildAsType(node, "type"));
21342136
}
21352137
if (operator.equals("UniqueKeyword")) {
21362138
return new KeywordTypeExpr(loc, "unique symbol");

0 commit comments

Comments
 (0)