Skip to content

Commit

Permalink
fixed that output was generated before assigning properties
Browse files Browse the repository at this point in the history
  • Loading branch information
dpnolte committed Nov 2, 2018
1 parent 5f56767 commit fcd0827
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions codegen/src/main/kotlin/com/laidpack/codegen/TypeScriptGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ internal class TypeScriptGenerator private constructor (
private val typeVariables = target.typeVariables
private val isEnum = target.proto.classKind == ProtoBuf.Class.Kind.ENUM_CLASS
private val superTypes = target.superTypes
val output = generateDefinition()
private val propertiesOrEnumValues = if (target.propertiesOrEnumValues.isNotEmpty()) {
target.propertiesOrEnumValues.values
} else listOf()
val output by lazy {generateDefinition()}
private val propertiesOrEnumValues = target.propertiesOrEnumValues.values
private val transformer = TypeScriptTypeTransformer(customTypeScriptValueTransformers)

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

private fun generateProperties(): String {
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"
}
return propertiesOrEnumValues
.filter { it != null }
.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 fcd0827

Please sign in to comment.