fun translateWasm()

in src/main/kotlin/com/compiler/server/compiler/components/KotlinToJSTranslator.kt [51:79]


    fun translateWasm(
        files: List<ProjectFile>,
        debugInfo: Boolean,
        projectType: ProjectType,
        userCompilerArguments: JsCompilerArguments,
        translate: (List<ProjectFile>, ProjectType, Boolean, JsCompilerArguments) -> CompilationResult<WasmTranslationSuccessfulOutput>
    ): TranslationResultWithJsCode {
        return try {
            val compilationResult = translate(
                files,
                projectType,
                debugInfo,
                userCompilerArguments
            )
            val wasmCompilationOutput = when (compilationResult) {
                is Compiled<WasmTranslationSuccessfulOutput> -> compilationResult.result
                is NotCompiled -> return TranslationJSResult(compilerDiagnostics = compilationResult.compilerDiagnostics)
            }
            TranslationWasmResult(
                jsCode = wasmCompilationOutput.jsCode,
                jsInstantiated = wasmCompilationOutput.jsInstantiated,
                compilerDiagnostics = compilationResult.compilerDiagnostics,
                wasm = wasmCompilationOutput.wasm,
                wat = if (debugInfo) wasmCompilationOutput.wat else null
            )
        } catch (e: Exception) {
            TranslationJSResult(exception = e.toExceptionDescriptor())
        }
    }