зеркало из https://github.com/github/codeql.git
JS: Fix extraction of non-substitution template literal types
This commit is contained in:
Родитель
e1d0bbb021
Коммит
b4a2a9db25
|
@ -5,7 +5,6 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
|
@ -1001,10 +1000,10 @@ public class TypeScriptASTConverter {
|
|||
private Node convertConditionalType(JsonObject node, SourceLocation loc) throws ParseError {
|
||||
return new ConditionalTypeExpr(
|
||||
loc,
|
||||
convertChild(node, "checkType"),
|
||||
convertChild(node, "extendsType"),
|
||||
convertChild(node, "trueType"),
|
||||
convertChild(node, "falseType"));
|
||||
convertChildAsType(node, "checkType"),
|
||||
convertChildAsType(node, "extendsType"),
|
||||
convertChildAsType(node, "trueType"),
|
||||
convertChildAsType(node, "falseType"));
|
||||
}
|
||||
|
||||
private SourceLocation getSourceRange(Position from, Position to) {
|
||||
|
@ -1613,6 +1612,10 @@ public class TypeScriptASTConverter {
|
|||
literal = new Literal(loc, arg.getTokenType(), "-" + arg.getValue());
|
||||
}
|
||||
}
|
||||
if (literal instanceof TemplateLiteral) {
|
||||
// A LiteralType containing a NoSubstitutionTemplateLiteral must produce a TemplateLiteralTypeExpr
|
||||
return new TemplateLiteralTypeExpr(literal.getLoc(), new ArrayList<>(), ((TemplateLiteral)literal).getQuasis());
|
||||
}
|
||||
return literal;
|
||||
}
|
||||
|
||||
|
@ -1842,7 +1845,7 @@ public class TypeScriptASTConverter {
|
|||
}
|
||||
|
||||
private Node convertOptionalType(JsonObject node, SourceLocation loc) throws ParseError {
|
||||
return new OptionalTypeExpr(loc, convertChild(node, "type"));
|
||||
return new OptionalTypeExpr(loc, convertChildAsType(node, "type"));
|
||||
}
|
||||
|
||||
private ITypeExpression asType(Node node) {
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
| tst.ts:2:11:2:21 | `foo ${T1}` |
|
||||
| tst.ts:4:45:4:49 | `foo` |
|
||||
| tst.ts:4:53:4:57 | `bar` |
|
||||
| tst.ts:5:46:5:50 | `foo` |
|
||||
| tst.ts:5:54:5:63 | `bar ${K}` |
|
||||
| tst.ts:7:15:7:19 | `foo` |
|
|
@ -0,0 +1,3 @@
|
|||
import javascript
|
||||
|
||||
query TemplateLiteralTypeExpr literalType() { any() }
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"include": ["."]
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
type T1 = 'foo' | 'bar';
|
||||
type T2 = `foo ${T1}`;
|
||||
|
||||
type FooToBar<K extends string> = K extends `foo` ? `bar` : K;
|
||||
type FooToBar2<K extends string> = K extends `foo` ? `bar ${K}` : K;
|
||||
|
||||
type Tuple = [`foo`?];
|
Загрузка…
Ссылка в новой задаче