[Wasm] Inline _importModule

^KT-59556 fixed
This commit is contained in:
Ilya Goncharov
2023-06-22 13:56:47 +00:00
committed by Space Team
parent 1ad0a662fd
commit d865202bd5
6 changed files with 7 additions and 11 deletions
@@ -193,7 +193,7 @@ fun WasmCompiledModuleFragment.generateAsyncJsWrapper(
.sorted() .sorted()
.joinToString("") { .joinToString("") {
val moduleSpecifier = it.toJsStringLiteral() val moduleSpecifier = it.toJsStringLiteral()
" $moduleSpecifier: await _importModule($moduleSpecifier),\n" " $moduleSpecifier: imports[$moduleSpecifier] ?? await import($moduleSpecifier),\n"
} }
val referencesToQualifiedAndImportedDeclarations = jsModuleAndQualifierReferences val referencesToQualifiedAndImportedDeclarations = jsModuleAndQualifierReferences
@@ -205,7 +205,7 @@ fun WasmCompiledModuleFragment.generateAsyncJsWrapper(
append(it.jsVariableName) append(it.jsVariableName)
append(" = ") append(" = ")
if (module != null) { if (module != null) {
append("(await _importModule(${module.toJsStringLiteral()}))") append("(imports[${module.toJsStringLiteral()}] ?? await import(${module.toJsStringLiteral()}))")
if (qualifier != null) if (qualifier != null)
append(".") append(".")
} }
@@ -231,10 +231,6 @@ export async function instantiate(imports={}, runInitializer=true) {
externrefBoxes.set(ref, ifNotCached); externrefBoxes.set(ref, ifNotCached);
return ifNotCached; return ifNotCached;
} }
async function _importModule(x) {
return imports[x] ?? await import(x);
}
$referencesToQualifiedAndImportedDeclarations $referencesToQualifiedAndImportedDeclarations
+1 -1
View File
@@ -1,7 +1,7 @@
// TARGET_BACKEND: WASM // TARGET_BACKEND: WASM
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 12_946 // WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 12_946
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_579 // WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_456
// FILE: test.kt // FILE: test.kt
+1 -1
View File
@@ -1,7 +1,7 @@
// TARGET_BACKEND: WASM // TARGET_BACKEND: WASM
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 47_948 // WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 47_948
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_605 // WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_482
fun box(): String { fun box(): String {
println("Hello, World!") println("Hello, World!")
+1 -1
View File
@@ -1,7 +1,7 @@
// TARGET_BACKEND: WASM // TARGET_BACKEND: WASM
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 14_307 // WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 14_307
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_134 // WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_011
// FILE: test.kt // FILE: test.kt
+1 -1
View File
@@ -1,7 +1,7 @@
// TARGET_BACKEND: WASM // TARGET_BACKEND: WASM
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 18_621 // WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 18_621
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_451 // WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_328
object Simple object Simple
+1 -1
View File
@@ -1,6 +1,6 @@
// TARGET_BACKEND: WASM // TARGET_BACKEND: WASM
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 12_988 // WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 12_988
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_451 // WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_328
fun box() = "OK" fun box() = "OK"