Skip to content

Commit

Permalink
Moving JS only runtime to JS sourceset, using unsafeCast instead of d…
Browse files Browse the repository at this point in the history
…ynamicCastTo.
  • Loading branch information
Salomon BRYS committed Dec 20, 2022
1 parent 8296759 commit 23ca02b
Show file tree
Hide file tree
Showing 23 changed files with 16 additions and 349 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ plugins {

allprojects {
group = "deezer.kustomexport"
version = "0.7.0"
version = "0.8.0"

repositories {
mavenLocal()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ import deezer.kustomexport.compiler.js.InterfaceDescriptor
import deezer.kustomexport.compiler.js.SealedClassDescriptor
import deezer.kustomexport.compiler.js.TopLevelFunctionDescriptor
import deezer.kustomexport.compiler.js.ValueClassDescriptor
import deezer.kustomexport.compiler.js.pattern.`class`.transform
import deezer.kustomexport.compiler.js.pattern.`interface`.transform
import deezer.kustomexport.compiler.js.pattern.enum.transform
import deezer.kustomexport.compiler.js.pattern.function.transform
import deezer.kustomexport.compiler.js.pattern.transform
import deezer.kustomexport.compiler.js.pattern.parseClass
import deezer.kustomexport.compiler.js.pattern.parseFunction
import deezer.kustomexport.compiler.js.pattern.value.transform

// Trick to share the Logger everywhere without injecting the dependency everywhere
internal lateinit var sharedLogger: KSPLogger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import com.squareup.kotlinpoet.TypeName
import deezer.kustomexport.compiler.CompilerArgs

val jsExport = ClassName("kotlin.js", "JsExport")
val unsafeCast = MemberName("kotlin.js", "unsafeCast")

val dynamicCastTo = MemberName("deezer.kustomexport", "dynamicCastTo")
val dynamicNull = MemberName("deezer.kustomexport", "dynamicNull")
val dynamicString = MemberName("deezer.kustomexport", "dynamicString")
val dynamicNotString = MemberName("deezer.kustomexport", "dynamicNotString")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* under the License.
*/

package deezer.kustomexport.compiler.js.pattern.`class`
package deezer.kustomexport.compiler.js.pattern

import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
Expand All @@ -28,22 +28,8 @@ import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.STRING
import com.squareup.kotlinpoet.TypeName
import com.squareup.kotlinpoet.TypeSpec
import deezer.kustomexport.compiler.js.ALL_KOTLIN_EXCEPTIONS
import deezer.kustomexport.compiler.js.ClassDescriptor
import deezer.kustomexport.compiler.js.FormatString
import deezer.kustomexport.compiler.js.MethodNameDisambiguation
import deezer.kustomexport.compiler.js.ParameterDescriptor
import deezer.kustomexport.compiler.js.dynamicCastTo
import deezer.kustomexport.compiler.js.dynamicNotString
import deezer.kustomexport.compiler.js.dynamicNull
import deezer.kustomexport.compiler.js.dynamicString
import deezer.kustomexport.compiler.js.jsExport
import deezer.kustomexport.compiler.js.jsPackage
import deezer.kustomexport.compiler.js.*
import deezer.kustomexport.compiler.js.mapping.INDENTATION
import deezer.kustomexport.compiler.js.pattern.asClassName
import deezer.kustomexport.compiler.js.pattern.buildWrappingFunction
import deezer.kustomexport.compiler.js.pattern.overrideGetterSetter
import deezer.kustomexport.compiler.js.pattern.suppress

fun ClassDescriptor.transform() = transformClass(this)

Expand Down Expand Up @@ -140,9 +126,9 @@ private fun buildExportedClass(
// Without that, it fails at runtime because there is no dynamicCastTo method on null.
// > TypeError: Cannot read properties of null (reading 'dynamicCastTo')
origin.constructorParams
.joinToString { "${it.name}·=·%M${if (ctorDyn == dynamicNull) "?" else ""}.%M<%T>()" },
.joinToString { "${it.name}·=·%M.%M<%T>()" },
*origin.constructorParams
.flatMap { listOf(ctorDyn, dynamicCastTo, it.type.exportedTypeName) }.toTypedArray()
.flatMap { listOf(ctorDyn, unsafeCast, it.type.exportedTypeName) }.toTypedArray()
)
)
.addParameter(ParameterSpec("common", originalClass))
Expand Down Expand Up @@ -188,7 +174,7 @@ private fun buildExportedClass(
b.addSuperclassConstructorParameter(
CodeBlock.of(
"common = %M.%M<%T>()",
dynamicNull, dynamicCastTo, supr.origin.concreteTypeName.asClassName()
dynamicNull, unsafeCast, supr.origin.concreteTypeName.asClassName()
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* under the License.
*/

package deezer.kustomexport.compiler.js.pattern.enum
package deezer.kustomexport.compiler.js.pattern

import com.squareup.kotlinpoet.ARRAY
import com.squareup.kotlinpoet.ClassName
Expand All @@ -30,7 +30,6 @@ import deezer.kustomexport.compiler.js.EnumDescriptor
import deezer.kustomexport.compiler.js.jsExport
import deezer.kustomexport.compiler.js.jsPackage
import deezer.kustomexport.compiler.js.mapping.INDENTATION
import deezer.kustomexport.compiler.js.pattern.overrideGetterSetter

fun EnumDescriptor.transform() = transformEnum(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@
* under the License.
*/

package deezer.kustomexport.compiler.js.pattern.function
package deezer.kustomexport.compiler.js.pattern

import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.MemberName
import deezer.kustomexport.compiler.js.TopLevelFunctionDescriptor
import deezer.kustomexport.compiler.js.jsExport
import deezer.kustomexport.compiler.js.jsPackage
import deezer.kustomexport.compiler.js.pattern.addParameters
import deezer.kustomexport.compiler.js.pattern.buildWrappingFunctionBody
import deezer.kustomexport.compiler.js.pattern.returnType

fun TopLevelFunctionDescriptor.transform() = transformFunction(this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* under the License.
*/

package deezer.kustomexport.compiler.js.pattern.`interface`
package deezer.kustomexport.compiler.js.pattern

import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.FileSpec
Expand All @@ -33,10 +33,6 @@ import deezer.kustomexport.compiler.js.PropertyDescriptor
import deezer.kustomexport.compiler.js.jsExport
import deezer.kustomexport.compiler.js.jsPackage
import deezer.kustomexport.compiler.js.mapping.INDENTATION
import deezer.kustomexport.compiler.js.pattern.OverrideMode
import deezer.kustomexport.compiler.js.pattern.buildWrappingFunction
import deezer.kustomexport.compiler.js.pattern.overrideGetterSetter
import deezer.kustomexport.compiler.js.pattern.packageName
import java.util.Locale

fun InterfaceDescriptor.transform() = transformInterface(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* under the License.
*/

package deezer.kustomexport.compiler.js.pattern.`class`
package deezer.kustomexport.compiler.js.pattern

import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.CodeBlock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* under the License.
*/

package deezer.kustomexport.compiler.js.pattern.value
package deezer.kustomexport.compiler.js.pattern

import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.FileSpec
Expand Down
29 changes: 0 additions & 29 deletions lib/src/commonMain/kotlin/deezer/kustomexport/Dynamics.kt

This file was deleted.

This file was deleted.

22 changes: 0 additions & 22 deletions lib/src/iosMain/kotlin/deezer/kustomexport/dynamicCastTo.kt

This file was deleted.

27 changes: 0 additions & 27 deletions lib/src/iosMain/kotlin/deezer/kustomexport/dynamicNull.kt

This file was deleted.

22 changes: 0 additions & 22 deletions lib/src/iosSimulatorArm64Main/kotlin/kustomexport/dynamicCastTo.kt

This file was deleted.

27 changes: 0 additions & 27 deletions lib/src/iosSimulatorArm64Main/kotlin/kustomexport/dynamicNull.kt

This file was deleted.

6 changes: 3 additions & 3 deletions lib/src/jsMain/kotlin/deezer/kustomexport/Dynamics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

package deezer.kustomexport

actual val dynamicNull: dynamic = null
actual val dynamicString: dynamic = "marker"
actual val dynamicNotString: dynamic = 123456
val dynamicNull: dynamic = null
val dynamicString: dynamic = "marker"
val dynamicNotString: dynamic = 123456
23 changes: 0 additions & 23 deletions lib/src/jsMain/kotlin/deezer/kustomexport/dynamicCastTo.kt

This file was deleted.

22 changes: 0 additions & 22 deletions lib/src/jvmMain/kotlin/deezer/kustomexport/dynamicCastTo.kt

This file was deleted.

27 changes: 0 additions & 27 deletions lib/src/jvmMain/kotlin/deezer/kustomexport/dynamicNull.kt

This file was deleted.

Loading

0 comments on commit 23ca02b

Please sign in to comment.