[JS IR] Enable DTS generation in IC
^KT-54398 Fixed
This commit is contained in:
committed by
Space Team
parent
d21cbfe02e
commit
9edaebf235
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.serialization.js.ModuleKind
|
||||
import org.jetbrains.kotlin.test.builders.LanguageVersionSettingsBuilder
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment
|
||||
import org.jetbrains.kotlin.test.util.JUnit4Assertions
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
|
||||
import org.junit.ComparisonFailure
|
||||
import java.io.File
|
||||
import java.util.EnumSet
|
||||
@@ -49,6 +50,8 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
private const val STDLIB_MODULE_NAME = "kotlin-kotlin-stdlib-js-ir"
|
||||
|
||||
private val KT_FILE_IGNORE_PATTERN = Regex("^.*\\..+\\.kt$")
|
||||
|
||||
private val JS_MODULE_KIND = ModuleKind.PLAIN
|
||||
}
|
||||
|
||||
override fun createEnvironment(): KotlinCoreEnvironment {
|
||||
@@ -94,7 +97,8 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
private fun createConfiguration(moduleName: String, language: List<String>): CompilerConfiguration {
|
||||
val copy = environment.configuration.copy()
|
||||
copy.put(CommonConfigurationKeys.MODULE_NAME, moduleName)
|
||||
copy.put(JSConfigurationKeys.MODULE_KIND, ModuleKind.PLAIN)
|
||||
copy.put(JSConfigurationKeys.GENERATE_DTS, true)
|
||||
copy.put(JSConfigurationKeys.MODULE_KIND, JS_MODULE_KIND)
|
||||
copy.put(JSConfigurationKeys.PROPERTY_LAZY_INITIALIZATION, true)
|
||||
|
||||
copy.languageVersionSettings = with(LanguageVersionSettingsBuilder()) {
|
||||
@@ -123,7 +127,8 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
val moduleName: String,
|
||||
val modulePath: String,
|
||||
val friends: List<String>,
|
||||
val expectedFileStats: Map<String, Set<String>>
|
||||
val expectedFileStats: Map<String, Set<String>>,
|
||||
val expectedDTS: String?
|
||||
)
|
||||
|
||||
private fun setupTestStep(projStep: ProjectInfo.ProjectBuildStep, module: String, buildKlib: Boolean): TestStepInfo {
|
||||
@@ -158,11 +163,16 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
val configuration = createConfiguration(module, projStep.language)
|
||||
buildArtifact(configuration, module, moduleSourceDir, dependencies, friends, outputKlibFile)
|
||||
}
|
||||
|
||||
val dtsFile = moduleStep.expectedDTS.ifNotEmpty {
|
||||
moduleTestDir.resolve(singleOrNull() ?: error("$module module may generate only one d.ts at step $projStepId"))
|
||||
}
|
||||
return TestStepInfo(
|
||||
module.safeModuleName,
|
||||
outputKlibFile.canonicalPath,
|
||||
friends.map { it.canonicalPath },
|
||||
expectedFileStats
|
||||
expectedFileStats,
|
||||
dtsFile?.readText()
|
||||
)
|
||||
}
|
||||
|
||||
@@ -232,6 +242,17 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun verifyDTS(stepId: Int, testInfo: List<TestStepInfo>, jsOutput: CompilationOutputs) {
|
||||
for (info in testInfo) {
|
||||
val expectedDTS = info.expectedDTS ?: continue
|
||||
val output = jsOutput.dependencies.find { it.first == info.moduleName }?.second ?: jsOutput
|
||||
val gotDTS = output.getFullTsDefinition(info.moduleName, JS_MODULE_KIND)
|
||||
JUnit4Assertions.assertEquals(expectedDTS, gotDTS) {
|
||||
"Mismatched d.ts for module ${info.moduleName} at step $stepId"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun execute() {
|
||||
for (projStep in projectInfo.steps) {
|
||||
val testInfo = projStep.order.map { setupTestStep(projStep, it, true) }
|
||||
@@ -272,6 +293,7 @@ abstract class AbstractInvalidationTest : KotlinTestWithEnvironment() {
|
||||
val (jsOutput, rebuiltModules) = jsExecutableProducer.buildExecutable(multiModule = true, outJsProgram = true)
|
||||
verifyJsExecutableProducerBuildModules(projStep.id, rebuiltModules, projStep.dirtyJS)
|
||||
verifyJsCode(projStep.id, mainModuleName, jsOutput)
|
||||
verifyDTS(projStep.id, testInfo, jsOutput)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -330,6 +330,11 @@ public class InvalidationTestGenerated extends AbstractInvalidationTest {
|
||||
runTest("js/js.translator/testData/incremental/invalidation/transitiveInlineFunction/");
|
||||
}
|
||||
|
||||
@TestMetadata("typeScriptExports")
|
||||
public void testTypeScriptExports() throws Exception {
|
||||
runTest("js/js.translator/testData/incremental/invalidation/typeScriptExports/");
|
||||
}
|
||||
|
||||
@TestMetadata("unicodeSerializationAndDeserialization")
|
||||
public void testUnicodeSerializationAndDeserialization() throws Exception {
|
||||
runTest("js/js.translator/testData/incremental/invalidation/unicodeSerializationAndDeserialization/");
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
fun foo() = 0
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
@JsExport
|
||||
fun foo() = 0
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
@JsExport
|
||||
@JsName("bar")
|
||||
fun foo() = 0
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
STEP 0:
|
||||
modifications:
|
||||
U : l1.0.4.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:
|
||||
STEP 4:
|
||||
modifications:
|
||||
U : l1.0.4.kt -> l1.kt
|
||||
modified ir: l1.kt
|
||||
STEP 5..6:
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
class MyClass(val stepId: Int) {
|
||||
fun qux() = foo() + stepId
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
@JsExport
|
||||
class MyClass(val stepId: Int) {
|
||||
fun qux() = foo() + stepId
|
||||
}
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
@JsExport
|
||||
class MyClass(val stepId: Int) {
|
||||
@JsName("baz")
|
||||
fun qux() = foo() + stepId
|
||||
}
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
@JsExport
|
||||
class MyClass(val stepId: Int) {
|
||||
@JsName("bar")
|
||||
fun qux() = foo() + stepId
|
||||
}
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
STEP 0:
|
||||
dependencies: lib1
|
||||
modifications:
|
||||
U : l2.0.kt -> l2.kt
|
||||
added file: l2.kt
|
||||
STEP 1..2:
|
||||
dependencies: lib1
|
||||
updated imports: l2.kt
|
||||
STEP 3:
|
||||
dependencies: lib1
|
||||
modifications:
|
||||
U : l2.3.kt -> l2.kt
|
||||
modified ir: l2.kt
|
||||
STEP 4:
|
||||
dependencies: lib1
|
||||
updated imports: l2.kt
|
||||
STEP 5:
|
||||
dependencies: lib1
|
||||
modifications:
|
||||
U : l2.5.kt -> l2.kt
|
||||
modified ir: l2.kt
|
||||
STEP 6:
|
||||
dependencies: lib1
|
||||
modifications:
|
||||
U : l2.6.kt -> l2.kt
|
||||
modified ir: l2.kt
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
declare namespace kotlin_main {
|
||||
type Nullable<T> = T | null | undefined
|
||||
function box(stepId: number): string;
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
declare namespace kotlin_main {
|
||||
type Nullable<T> = T | null | undefined
|
||||
function foo(): number;
|
||||
function box(stepId: number): string;
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
declare namespace kotlin_main {
|
||||
type Nullable<T> = T | null | undefined
|
||||
function bar(): number;
|
||||
function box(stepId: number): string;
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
declare namespace kotlin_main {
|
||||
type Nullable<T> = T | null | undefined
|
||||
function bar(): number;
|
||||
class MyClass {
|
||||
constructor(stepId: number);
|
||||
get stepId(): number;
|
||||
qux(): number;
|
||||
}
|
||||
function box(stepId: number): string;
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
declare namespace kotlin_main {
|
||||
type Nullable<T> = T | null | undefined
|
||||
class MyClass {
|
||||
constructor(stepId: number);
|
||||
get stepId(): number;
|
||||
qux(): number;
|
||||
}
|
||||
function box(stepId: number): string;
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
declare namespace kotlin_main {
|
||||
type Nullable<T> = T | null | undefined
|
||||
class MyClass {
|
||||
constructor(stepId: number);
|
||||
get stepId(): number;
|
||||
baz(): number;
|
||||
}
|
||||
function box(stepId: number): string;
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
declare namespace kotlin_main {
|
||||
type Nullable<T> = T | null | undefined
|
||||
class MyClass {
|
||||
constructor(stepId: number);
|
||||
get stepId(): number;
|
||||
bar(): number;
|
||||
}
|
||||
function box(stepId: number): string;
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fun box(stepId: Int): String {
|
||||
val x = MyClass(stepId).qux()
|
||||
if (x != stepId) {
|
||||
return "Fail: $x != $stepId"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
STEP 0:
|
||||
dependencies: lib1, lib2
|
||||
added file: m.kt
|
||||
expected dts: m.0.d.ts
|
||||
STEP 1:
|
||||
dependencies: lib1, lib2
|
||||
expected dts: m.1.d.ts
|
||||
STEP 2:
|
||||
dependencies: lib1, lib2
|
||||
expected dts: m.2.d.ts
|
||||
STEP 3:
|
||||
dependencies: lib1, lib2
|
||||
updated imports: m.kt
|
||||
expected dts: m.3.d.ts
|
||||
STEP 4:
|
||||
dependencies: lib1, lib2
|
||||
expected dts: m.4.d.ts
|
||||
STEP 5:
|
||||
dependencies: lib1, lib2
|
||||
updated imports: m.kt
|
||||
expected dts: m.5.d.ts
|
||||
STEP 6:
|
||||
dependencies: lib1, lib2
|
||||
updated imports: m.kt
|
||||
expected dts: m.6.d.ts
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
MODULES: lib1, lib2, main
|
||||
|
||||
STEP 0..1:
|
||||
libs: lib1, lib2, main
|
||||
dirty js: lib1, lib2, main
|
||||
STEP 2:
|
||||
libs: lib1, lib2, main
|
||||
dirty js: lib1, lib2
|
||||
STEP 3:
|
||||
libs: lib1, lib2, main
|
||||
dirty js: lib2, main
|
||||
STEP 4:
|
||||
libs: lib1, lib2, main
|
||||
dirty js: lib1, lib2, main
|
||||
STEP 5..6:
|
||||
libs: lib1, lib2, main
|
||||
dirty js: lib2, main
|
||||
Reference in New Issue
Block a user