Skip to content

Commit

Permalink
added check if target type has properties
Browse files Browse the repository at this point in the history
  • Loading branch information
dpnolte committed Nov 2, 2018
1 parent aaed8e9 commit 5f56767
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ internal class TypeScriptGenerator private constructor (
private val isEnum = target.proto.classKind == ProtoBuf.Class.Kind.ENUM_CLASS
private val superTypes = target.superTypes
val output = generateDefinition()
private val propertiesOrEnumValues = target.propertiesOrEnumValues.values
private val propertiesOrEnumValues = if (target.propertiesOrEnumValues.isNotEmpty()) {
target.propertiesOrEnumValues.values
} else listOf()
private val transformer = TypeScriptTypeTransformer(customTypeScriptValueTransformers)

override fun toString(): String {
Expand All @@ -38,14 +40,12 @@ internal class TypeScriptGenerator private constructor (
}

private fun generateProperties(): String {
return if (propertiesOrEnumValues.isNotEmpty()) {
propertiesOrEnumValues.joinToString("") { property ->
val propertyName = property.jsonName()
val propertyType = transformer.transformType(property.type, typesWithinScope, typeVariables)
val isNullable = if (property.type.nullable) "?" else ""
"$indent$indent$propertyName$isNullable: $propertyType;\n"
}
} else ""
return propertiesOrEnumValues.joinToString ("") { property ->
val propertyName = property.jsonName()
val propertyType = transformer.transformType(property.type, typesWithinScope, typeVariables)
val isNullable = if (property.type.nullable) "?" else ""
"$indent$indent$propertyName$isNullable: $propertyType;\n"
}
}

private fun generateEnum(): String {
Expand Down

0 comments on commit 5f56767

Please sign in to comment.