[K/JS] Fix reexport with CommonJS and incremental compilation
This commit is contained in:
+1
-1
@@ -29,7 +29,7 @@ class JsExecutableProducer(
|
||||
fun buildExecutable(granularity: JsGenerationGranularity, outJsProgram: Boolean) =
|
||||
when (granularity) {
|
||||
JsGenerationGranularity.WHOLE_PROGRAM -> buildSingleModuleExecutable(outJsProgram)
|
||||
JsGenerationGranularity.PER_MODULE -> buildMultiArtifactExecutable(outJsProgram, JsPerModuleCache(caches))
|
||||
JsGenerationGranularity.PER_MODULE -> buildMultiArtifactExecutable(outJsProgram, JsPerModuleCache(moduleKind, caches))
|
||||
JsGenerationGranularity.PER_FILE -> buildMultiArtifactExecutable(outJsProgram, JsPerFileCache(caches))
|
||||
}
|
||||
|
||||
|
||||
+13
-2
@@ -6,9 +6,13 @@
|
||||
package org.jetbrains.kotlin.ir.backend.js.ic
|
||||
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.*
|
||||
import org.jetbrains.kotlin.serialization.js.ModuleKind
|
||||
import java.io.File
|
||||
|
||||
class JsPerModuleCache(private val moduleArtifacts: List<ModuleArtifact>) : JsMultiArtifactCache<JsPerModuleCache.CachedModuleInfo>() {
|
||||
class JsPerModuleCache(
|
||||
private val moduleKind: ModuleKind,
|
||||
private val moduleArtifacts: List<ModuleArtifact>
|
||||
) : JsMultiArtifactCache<JsPerModuleCache.CachedModuleInfo>() {
|
||||
companion object {
|
||||
private const val JS_MODULE_HEADER = "js.module.header.bin"
|
||||
private const val CACHED_MODULE_JS = "module.js"
|
||||
@@ -73,8 +77,15 @@ class JsPerModuleCache(private val moduleArtifacts: List<ModuleArtifact>) : JsMu
|
||||
} ?: compilationOutputs
|
||||
|
||||
override fun loadProgramHeadersFromCache(): List<CachedModuleInfo> {
|
||||
val mainModule = moduleArtifacts.last()
|
||||
return moduleArtifacts.map { artifact ->
|
||||
fun loadModuleInfo() = CachedModuleInfo(artifact, artifact.loadJsIrModule().makeModuleHeader())
|
||||
fun loadModuleInfo() = CachedModuleInfo(
|
||||
artifact,
|
||||
artifact
|
||||
.loadJsIrModule(mainModule.moduleSafeName.takeIf { moduleKind !== ModuleKind.ES && artifact !== mainModule })
|
||||
.makeModuleHeader()
|
||||
)
|
||||
|
||||
val actualInfo = when {
|
||||
artifact.forceRebuildJs -> loadModuleInfo()
|
||||
artifact.fileArtifacts.any { it.isModified() } -> loadModuleInfo()
|
||||
|
||||
@@ -32,11 +32,11 @@ class ModuleArtifact(
|
||||
val moduleSafeName = moduleName.safeModuleName
|
||||
val moduleExternalName = externalModuleName ?: moduleSafeName
|
||||
|
||||
fun loadJsIrModule(): JsIrModule {
|
||||
fun loadJsIrModule(reexportedInModuleWithName: String? = null): JsIrModule {
|
||||
val fragments = fileArtifacts.sortedBy { it.srcFilePath }.flatMap {
|
||||
val fragments = it.loadJsIrFragments()
|
||||
listOfNotNull(fragments?.mainFragment, fragments?.exportFragment)
|
||||
}
|
||||
return JsIrModule(moduleSafeName, moduleExternalName, fragments)
|
||||
return JsIrModule(moduleSafeName, moduleExternalName, fragments, reexportedInModuleWithName)
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+6
@@ -313,6 +313,12 @@ public class JsFirInvalidationPerFileTestGenerated extends AbstractJsFirInvalida
|
||||
runTest("js/js.translator/testData/incremental/invalidation/jsExport/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportReexport")
|
||||
public void testJsExportReexport() throws Exception {
|
||||
runTest("js/js.translator/testData/incremental/invalidation/jsExportReexport/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportWithMultipleFiles")
|
||||
public void testJsExportWithMultipleFiles() throws Exception {
|
||||
|
||||
Generated
+6
@@ -313,6 +313,12 @@ public class JsFirInvalidationPerModuleTestGenerated extends AbstractJsFirInvali
|
||||
runTest("js/js.translator/testData/incremental/invalidation/jsExport/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportReexport")
|
||||
public void testJsExportReexport() throws Exception {
|
||||
runTest("js/js.translator/testData/incremental/invalidation/jsExportReexport/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportWithMultipleFiles")
|
||||
public void testJsExportWithMultipleFiles() throws Exception {
|
||||
|
||||
Generated
+6
@@ -313,6 +313,12 @@ public class JsIrES6InvalidationPerFileTestGenerated extends AbstractJsIrES6Inva
|
||||
runTest("js/js.translator/testData/incremental/invalidation/jsExport/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportReexport")
|
||||
public void testJsExportReexport() throws Exception {
|
||||
runTest("js/js.translator/testData/incremental/invalidation/jsExportReexport/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportWithMultipleFiles")
|
||||
public void testJsExportWithMultipleFiles() throws Exception {
|
||||
|
||||
+6
@@ -313,6 +313,12 @@ public class JsIrES6InvalidationPerModuleTestGenerated extends AbstractJsIrES6In
|
||||
runTest("js/js.translator/testData/incremental/invalidation/jsExport/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportReexport")
|
||||
public void testJsExportReexport() throws Exception {
|
||||
runTest("js/js.translator/testData/incremental/invalidation/jsExportReexport/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportWithMultipleFiles")
|
||||
public void testJsExportWithMultipleFiles() throws Exception {
|
||||
|
||||
Generated
+6
@@ -313,6 +313,12 @@ public class JsIrInvalidationPerFileTestGenerated extends AbstractJsIrInvalidati
|
||||
runTest("js/js.translator/testData/incremental/invalidation/jsExport/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportReexport")
|
||||
public void testJsExportReexport() throws Exception {
|
||||
runTest("js/js.translator/testData/incremental/invalidation/jsExportReexport/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportWithMultipleFiles")
|
||||
public void testJsExportWithMultipleFiles() throws Exception {
|
||||
|
||||
Generated
+6
@@ -313,6 +313,12 @@ public class JsIrInvalidationPerModuleTestGenerated extends AbstractJsIrInvalida
|
||||
runTest("js/js.translator/testData/incremental/invalidation/jsExport/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportReexport")
|
||||
public void testJsExportReexport() throws Exception {
|
||||
runTest("js/js.translator/testData/incremental/invalidation/jsExportReexport/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportWithMultipleFiles")
|
||||
public void testJsExportWithMultipleFiles() throws Exception {
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
inline fun foo() = 77
|
||||
fun gaz() = 99
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
@JsExport inline fun foo() = 77
|
||||
fun gaz() = 99
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
@JsName("bar") @JsExport inline fun foo() = 77
|
||||
fun gaz() = 99
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
@JsName("baz") @JsExport inline fun foo() = 77
|
||||
fun gaz() = 99
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
@JsName("baz") @JsExport inline fun foo() = 77
|
||||
@JsExport fun gaz() = 99
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
@JsName("baz") @JsExport inline fun foo() = 77
|
||||
@JsName("gaz77") @JsExport fun gaz() = 99
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
@JsName("baz") @JsExport inline fun foo() = 77
|
||||
@JsName("gaz99") @JsExport fun gaz() = 99
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
STEP 0:
|
||||
modifications:
|
||||
U : l1.0.kt -> l1.kt
|
||||
added file: l1.kt
|
||||
STEP 1:
|
||||
modifications:
|
||||
U : l1.1.kt -> l1.kt
|
||||
modified ir: l1.kt
|
||||
STEP 2:
|
||||
modifications:
|
||||
U : l1.2.kt -> l1.kt
|
||||
modified ir: l1.kt
|
||||
STEP 3:
|
||||
modifications:
|
||||
U : l1.3.kt -> l1.kt
|
||||
modified ir: l1.kt
|
||||
STEP 4:
|
||||
modifications:
|
||||
U : l1.4.kt -> l1.kt
|
||||
modified ir: l1.kt
|
||||
STEP 5:
|
||||
modifications:
|
||||
U : l1.5.kt -> l1.kt
|
||||
modified ir: l1.kt
|
||||
STEP 6:
|
||||
modifications:
|
||||
U : l1.6.kt -> l1.kt
|
||||
modified ir: l1.kt
|
||||
@@ -0,0 +1,8 @@
|
||||
@JsModule("test")
|
||||
external fun test(step: Int): String
|
||||
|
||||
fun box(step: Int): String {
|
||||
if (foo() != 77) return "Fail foo"
|
||||
if (gaz() != 99) return "Fail gaz"
|
||||
return test(step)
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
STEP 0:
|
||||
dependencies: lib1
|
||||
added file: m.kt
|
||||
STEP 1..6:
|
||||
dependencies: lib1
|
||||
updated imports: m.kt
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
IGNORE_PER_FILE: true
|
||||
MODULE_KIND: commonjs
|
||||
|
||||
MODULES: lib1, main
|
||||
|
||||
STEP 0:
|
||||
libs: lib1, main
|
||||
dirty js modules: lib1, main
|
||||
dirty js files: lib1/l1, main/m, main/m.export, main
|
||||
STEP 1:
|
||||
libs: lib1, main
|
||||
dirty js modules: lib1, main
|
||||
dirty js files: lib1/l1, lib1/l1.export, lib1, main/m
|
||||
STEP 2..3:
|
||||
libs: lib1, main
|
||||
dirty js modules: lib1, main
|
||||
dirty js files: lib1/l1, lib1/l1.export, main/m
|
||||
STEP 4..6:
|
||||
libs: lib1, main
|
||||
dirty js modules: lib1, main
|
||||
dirty js files: lib1/l1, lib1/l1.export, main/m
|
||||
@@ -0,0 +1,34 @@
|
||||
module.exports = function (step) {
|
||||
const lib1 = require("./main.js")
|
||||
|
||||
let result;
|
||||
switch (step) {
|
||||
case 0: return "OK"
|
||||
case 1:
|
||||
result = lib1.foo()
|
||||
return result === 77 ? "OK" : `Fail 1: Expect 77 but got ${result}`
|
||||
case 2:
|
||||
result = lib1.bar()
|
||||
return result === 77 ? "OK" : `Fail 2: Expect 77 but got ${result}`
|
||||
case 3:
|
||||
result = lib1.baz()
|
||||
return result === 77 ? "OK" : `Fail 3: Expect 77 but got ${result}`
|
||||
case 4:
|
||||
result = lib1.baz()
|
||||
if (result !== 77) return `Fail 4: Expect 77 but got ${result}`
|
||||
result = lib1.gaz()
|
||||
return result === 99 ? "OK" : `Fail 4: Expect 99 but got ${result}`
|
||||
case 5:
|
||||
result = lib1.baz()
|
||||
if (result !== 77) return `Fail 5: Expect 77 but got ${result}`
|
||||
result = lib1.gaz77()
|
||||
return result === 99 ? "OK" : `Fail 5: Expect 99 but got ${result}`
|
||||
case 6:
|
||||
result = lib1.baz()
|
||||
if (result !== 77) return `Fail 6: Expect 77 but got ${result}`
|
||||
result = lib1.gaz99()
|
||||
return result === 99 ? "OK" : `Fail 6: Expect 99 but got ${result}`
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user