[K/Wasm] Add simple TypeScript definitions generating ^KT-65009 Fixed
This commit is contained in:
+2
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.test.services.AdditionalSourceProvider
|
||||
import org.jetbrains.kotlin.test.services.EnvironmentConfigurator
|
||||
import org.jetbrains.kotlin.test.services.LibraryProvider
|
||||
import org.jetbrains.kotlin.test.services.sourceProviders.CoroutineHelpersSourceFilesProvider
|
||||
import org.jetbrains.kotlin.wasm.test.handlers.WasmDtsHandler
|
||||
|
||||
abstract class AbstractWasmBlackBoxCodegenTestBase<R : ResultingArtifact.FrontendOutput<R>, I : ResultingArtifact.BackendInput<I>, A : ResultingArtifact.Binary<A>>(
|
||||
private val targetFrontend: FrontendKind<R>,
|
||||
@@ -94,6 +95,7 @@ abstract class AbstractWasmBlackBoxCodegenTestBase<R : ResultingArtifact.Fronten
|
||||
|
||||
wasmArtifactsHandlersStep {
|
||||
useHandlers(wasmBoxTestRunner)
|
||||
useHandlers(::WasmDtsHandler)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ class WasmBackendFacade(
|
||||
override fun transform(module: TestModule, inputArtifact: BinaryArtifacts.KLib): BinaryArtifacts.Wasm? {
|
||||
val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module)
|
||||
val generateSourceMaps = WasmEnvironmentConfigurationDirectives.GENERATE_SOURCE_MAP in testServices.moduleStructure.allDirectives
|
||||
val generateDts = WasmEnvironmentConfigurationDirectives.CHECK_TYPESCRIPT_DECLARATIONS in testServices.moduleStructure.allDirectives
|
||||
|
||||
// Enforce PL with the ERROR log level to fail any tests where PL detected any incompatibilities.
|
||||
configuration.setupPartialLinkageConfig(PartialLinkageConfig(PartialLinkageMode.ENABLE, PartialLinkageLogLevel.ERROR))
|
||||
@@ -93,12 +94,13 @@ class WasmBackendFacade(
|
||||
)
|
||||
|
||||
val testPackage = extractTestPackage(testServices)
|
||||
val (allModules, backendContext) = compileToLoweredIr(
|
||||
val (allModules, backendContext, typeScriptFragment) = compileToLoweredIr(
|
||||
depsDescriptors = moduleStructure,
|
||||
phaseConfig = phaseConfig,
|
||||
irFactory = IrFactoryImpl,
|
||||
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, "box"))),
|
||||
propertyLazyInitialization = true,
|
||||
generateTypeScriptFragment = generateDts
|
||||
)
|
||||
val generateWat = debugMode >= DebugMode.DEBUG
|
||||
val baseFileName = "index"
|
||||
@@ -106,11 +108,12 @@ class WasmBackendFacade(
|
||||
val compilerResult = compileWasm(
|
||||
allModules = allModules,
|
||||
backendContext = backendContext,
|
||||
typeScriptFragment = typeScriptFragment,
|
||||
baseFileName = baseFileName,
|
||||
emitNameSection = true,
|
||||
allowIncompleteImplementations = false,
|
||||
generateWat = generateWat,
|
||||
generateSourceMaps = generateSourceMaps
|
||||
generateSourceMaps = generateSourceMaps,
|
||||
)
|
||||
|
||||
val dceDumpNameCache = DceDumpNameCache()
|
||||
@@ -121,11 +124,12 @@ class WasmBackendFacade(
|
||||
val compilerResultWithDCE = compileWasm(
|
||||
allModules = allModules,
|
||||
backendContext = backendContext,
|
||||
typeScriptFragment = typeScriptFragment,
|
||||
baseFileName = baseFileName,
|
||||
emitNameSection = true,
|
||||
allowIncompleteImplementations = true,
|
||||
generateWat = generateWat,
|
||||
generateSourceMaps = generateSourceMaps
|
||||
generateSourceMaps = generateSourceMaps,
|
||||
)
|
||||
|
||||
return BinaryArtifacts.Wasm(
|
||||
@@ -148,7 +152,8 @@ class WasmBackendFacade(
|
||||
jsUninstantiatedWrapper = jsUninstantiatedWrapper,
|
||||
jsWrapper = jsWrapper,
|
||||
wasm = newWasm,
|
||||
debugInformation = null
|
||||
debugInformation = null,
|
||||
dts = dts
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.wasm.test.handlers
|
||||
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.backend.handlers.WasmBinaryArtifactHandler
|
||||
import org.jetbrains.kotlin.test.directives.WasmEnvironmentConfigurationDirectives
|
||||
import org.jetbrains.kotlin.test.model.BinaryArtifacts
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.moduleStructure
|
||||
import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull
|
||||
|
||||
class WasmDtsHandler(testServices: TestServices) : WasmBinaryArtifactHandler(testServices) {
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {}
|
||||
|
||||
override fun processModule(module: TestModule, info: BinaryArtifacts.Wasm) {
|
||||
val globalDirectives = testServices.moduleStructure.allDirectives
|
||||
if (WasmEnvironmentConfigurationDirectives.CHECK_TYPESCRIPT_DECLARATIONS !in globalDirectives) return
|
||||
|
||||
val referenceDtsFile = module.files.first().originalFile.withReplacedExtensionOrNull(".kt", ".d.ts")
|
||||
?: error("Can't find reference .d.ts file")
|
||||
|
||||
val generatedDts = info.compilerResult.dts
|
||||
?: error("Can't find generated .d.ts file")
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(referenceDtsFile, generatedDts)
|
||||
}
|
||||
}
|
||||
+58
@@ -186,4 +186,62 @@ public class FirWasmCodegenWasmJsInteropTestGenerated extends AbstractFirWasmCod
|
||||
public void testWasmImport() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/wasmImport.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class TypeScriptDeclarations {
|
||||
@Test
|
||||
public void testAllFilesPresentInTypeScriptDeclarations() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.WASM, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("externalDeclarations.kt")
|
||||
public void testExternalDeclarations() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/externalDeclarations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("generics.kt")
|
||||
public void testGenerics() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/generics.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsPrimitives.kt")
|
||||
public void testJsPrimitives() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/jsPrimitives.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableJsPrimitives.kt")
|
||||
public void testNullableJsPrimitives() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/nullableJsPrimitives.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullablePrimitives.kt")
|
||||
public void testNullablePrimitives() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/nullablePrimitives.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableUnisnged.kt")
|
||||
public void testNullableUnisnged() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/nullableUnisnged.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primitives.kt")
|
||||
public void testPrimitives() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/primitives.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unisnged.kt")
|
||||
public void testUnisnged() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/unisnged.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+58
@@ -186,4 +186,62 @@ public class K1WasmCodegenWasmJsInteropTestGenerated extends AbstractK1WasmCodeg
|
||||
public void testWasmImport() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/wasmImport.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
public class TypeScriptDeclarations {
|
||||
@Test
|
||||
public void testAllFilesPresentInTypeScriptDeclarations() throws Exception {
|
||||
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.WASM, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("externalDeclarations.kt")
|
||||
public void testExternalDeclarations() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/externalDeclarations.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("generics.kt")
|
||||
public void testGenerics() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/generics.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsPrimitives.kt")
|
||||
public void testJsPrimitives() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/jsPrimitives.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableJsPrimitives.kt")
|
||||
public void testNullableJsPrimitives() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/nullableJsPrimitives.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullablePrimitives.kt")
|
||||
public void testNullablePrimitives() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/nullablePrimitives.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("nullableUnisnged.kt")
|
||||
public void testNullableUnisnged() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/nullableUnisnged.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("primitives.kt")
|
||||
public void testPrimitives() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/primitives.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("unisnged.kt")
|
||||
public void testUnisnged() throws Exception {
|
||||
runTest("compiler/testData/codegen/boxWasmJsInterop/typeScriptDeclarations/unisnged.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user