Skip to content
This repository was archived by the owner on Nov 6, 2019. It is now read-only.

Commit 046da2e

Browse files
committed
Handle a typeof TypeQuery
1 parent 3f9f7af commit 046da2e

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/ast/typescript/typeScriptAstUtils.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ fun TypeNode.toKotlinType(typeMapper: ObjectTypeToKotlinTypeMapper): KtType {
266266

267267
SyntaxKind.TypeReference -> (this.cast<TypeReferenceNode>()).toKotlinTypeUnion(typeMapper).singleType
268268
SyntaxKind.ExpressionWithTypeArguments -> (this.cast<ExpressionWithTypeArguments>()).toKotlinType(typeMapper)
269+
SyntaxKind.TypeQuery -> (this.cast<TypeQueryNode>()).toKotlinType(typeMapper)
269270

270271
SyntaxKind.Identifier -> KtType(KtQualifiedName((this.cast<Identifier>()).unescapedText))
271272
SyntaxKind.TypeLiteral -> (this.cast<TypeLiteralNode>()).toKotlinType(typeMapper)
@@ -320,6 +321,10 @@ fun ExpressionWithTypeArguments.toKotlinType(typeMapper: ObjectTypeToKotlinTypeM
320321
return KtType(name ?: KtQualifiedName("???"), typeArguments?.arr?.map { typeMapper.mapType(it) } ?: emptyList())
321322
}
322323

324+
fun TypeQueryNode.toKotlinType(typeMapper: ObjectTypeToKotlinTypeMapper): KtType {
325+
return KtType(DYNAMIC, comment = "typeof " + this.exprName.unsafeCast<Node>().stringifyQualifiedName()?.asString())
326+
}
327+
323328
private fun PropertyAccessExpression.toKtQualifiedName(): KtQualifiedName {
324329
val identifier = identifierName.unescapedText
325330

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package varTypeOf
2+
3+
external open class VarTypeOfClass {
4+
open var myVar: dynamic /* typeof someOtherVar */ = definedExternally
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare class VarTypeOfClass {
2+
myVar: typeof someOtherVar;
3+
}

0 commit comments

Comments
 (0)