From b8d856c0576f1ada4e56af5ce2ebbabd5081b332 Mon Sep 17 00:00:00 2001 From: Eric Pabst Date: Sat, 15 Sep 2018 15:24:02 -0600 Subject: [PATCH] Handle a typeof TypeQuery --- src/main/kotlin/ts2kt/typeScriptAstUtils.kt | 5 +++++ testData/class/variables/varTypeOf.d.kt | 5 +++++ testData/class/variables/varTypeOf.d.ts | 3 +++ 3 files changed, 13 insertions(+) create mode 100644 testData/class/variables/varTypeOf.d.kt create mode 100644 testData/class/variables/varTypeOf.d.ts diff --git a/src/main/kotlin/ts2kt/typeScriptAstUtils.kt b/src/main/kotlin/ts2kt/typeScriptAstUtils.kt index e2af129..e8459ac 100644 --- a/src/main/kotlin/ts2kt/typeScriptAstUtils.kt +++ b/src/main/kotlin/ts2kt/typeScriptAstUtils.kt @@ -266,6 +266,7 @@ fun TypeNode.toKotlinType(typeMapper: ObjectTypeToKotlinTypeMapper): KtType { SyntaxKind.TypeReference -> (this.cast()).toKotlinTypeUnion(typeMapper).singleType SyntaxKind.ExpressionWithTypeArguments -> (this.cast()).toKotlinType(typeMapper) + SyntaxKind.TypeQuery -> (this.cast()).toKotlinType(typeMapper) SyntaxKind.Identifier -> KtType(KtQualifiedName((this.cast()).unescapedText)) SyntaxKind.TypeLiteral -> (this.cast()).toKotlinType(typeMapper) @@ -320,6 +321,10 @@ fun ExpressionWithTypeArguments.toKotlinType(typeMapper: ObjectTypeToKotlinTypeM return KtType(name ?: KtQualifiedName("???"), typeArguments?.arr?.map { typeMapper.mapType(it) } ?: emptyList()) } +fun TypeQueryNode.toKotlinType(typeMapper: ObjectTypeToKotlinTypeMapper): KtType { + return KtType(DYNAMIC, comment = "typeof " + this.exprName.unsafeCast().stringifyQualifiedName()?.asString()) +} + private fun PropertyAccessExpression.toKtQualifiedName(): KtQualifiedName { val identifier = identifierName.unescapedText diff --git a/testData/class/variables/varTypeOf.d.kt b/testData/class/variables/varTypeOf.d.kt new file mode 100644 index 0000000..35f5abf --- /dev/null +++ b/testData/class/variables/varTypeOf.d.kt @@ -0,0 +1,5 @@ +package varTypeOf + +external open class VarTypeOfClass { + open var myVar: dynamic /* typeof someOtherVar */ = definedExternally +} diff --git a/testData/class/variables/varTypeOf.d.ts b/testData/class/variables/varTypeOf.d.ts new file mode 100644 index 0000000..823c1f8 --- /dev/null +++ b/testData/class/variables/varTypeOf.d.ts @@ -0,0 +1,3 @@ +declare class VarTypeOfClass { + myVar: typeof someOtherVar; +}