Skip to content

Commit

Permalink
Add contracts to node append and tag declaration calls (#264)
Browse files Browse the repository at this point in the history
* Added contracts for callbacks passed to DOM elements in JVM

* Added contracts for callbacks passed to DOM elements in JS

* Added contracts for callbacks passed to DOM elements in WASM-JS

* Added contracts for callbacks passed to tag elements

* Cleaning up code
  • Loading branch information
severn-everett authored May 5, 2024
1 parent f1b51c6 commit 43ca4ba
Show file tree
Hide file tree
Showing 34 changed files with 3,447 additions and 1,109 deletions.
54 changes: 24 additions & 30 deletions buildSrc/src/main/kotlin/kotlinx/html/generate/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,7 @@ fun generate(pkg: String, todir: String, jsdir: String, wasmJsDir: String) {

repository.tags.values.filterIgnored().groupBy { it.name[0] }.entries.forEach { e ->
writeIntoFile("$todir/gen-tags-${e.key}.kt") {
packg(pkg)
emptyLine()
import("kotlinx.html.*")
import("kotlinx.html.impl.*")
import("kotlinx.html.attributes.*")
emptyLine()

doNotEditWarning()
emptyLine()
emptyLine()
fullImportsHeader(pkg)

e.value.forEach {
tagClass(repository, it, emptySet())
Expand Down Expand Up @@ -124,16 +115,7 @@ fun generate(pkg: String, todir: String, jsdir: String, wasmJsDir: String) {

FileOutputStream("$todir/gen-tag-unions.kt").writer(Charsets.UTF_8).use {
with(it) {
packg(pkg)
emptyLine()
import("kotlinx.html.*")
import("kotlinx.html.impl.*")
import("kotlinx.html.attributes.*")
emptyLine()

doNotEditWarning()
emptyLine()
emptyLine()
fullImportsHeader(pkg)

repository.groupUnions.values.forEach { union ->
clazz(
Expand Down Expand Up @@ -163,16 +145,7 @@ fun generate(pkg: String, todir: String, jsdir: String, wasmJsDir: String) {

FileOutputStream("$todir/gen-tag-groups.kt").writer(Charsets.UTF_8).use {
with(it) {
packg(pkg)
emptyLine()
import("kotlinx.html.*")
import("kotlinx.html.impl.*")
import("kotlinx.html.attributes.*")
emptyLine()

doNotEditWarning()
emptyLine()
emptyLine()
fullImportsHeader(pkg)

repository.tagGroups.values.forEach { group ->
val unions = repository.unionsByGroups[group.name].orEmpty().map { it.name }
Expand Down Expand Up @@ -319,6 +292,7 @@ private fun generateConsumerTags(
emptyLine()
packg(pkg)
emptyLine()
contractImports()
import("kotlinx.html.*")
import("kotlinx.html.attributes.*")

Expand Down Expand Up @@ -379,3 +353,23 @@ private fun Appendable.writeKotlinPoet(builder: FileSpec.Builder.() -> Unit) {
.build()
.writeTo(this)
}

private fun Appendable.fullImportsHeader(pkg: String) {
packg(pkg)
emptyLine()
contractImports()
import("kotlinx.html.*")
import("kotlinx.html.impl.*")
import("kotlinx.html.attributes.*")
emptyLine()

doNotEditWarning()
emptyLine()
emptyLine()
}

private fun Appendable.contractImports() {
import("kotlin.contracts.ExperimentalContracts")
import("kotlin.contracts.InvocationKind")
import("kotlin.contracts.contract")
}
Loading

0 comments on commit 43ca4ba

Please sign in to comment.