Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/io/outfoxx/typescriptpoet/CodeBlock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ private constructor(
}

private fun argToLiteral(o: Any?) = when (o) {
is CodeBlock -> o.toString()
is CodeBlock -> o
else -> o.toString()
}

Expand Down
22 changes: 22 additions & 0 deletions src/test/java/io/outfoxx/typescriptpoet/test/CodeWriterTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,26 @@ class CodeWriterTests {
)
)
}

@Test
fun `test CodeBlock with import`() {
val testFunc = FunctionSpec.builder("test")
.returns(STRING)
.addCode(CodeBlock.of("return new %T()", TypeName.namedImport("X", "x")))
.build()

MatcherAssert.assertThat(
testFunc.toString(),
CoreMatchers.equalTo(
"""
import { X } from 'x';

function test(): string {
return new X();
}

""".trimIndent()
)
)
}
}