[JS IR BE] Initial export generation
This commit is contained in:
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.generators.tests
|
||||
|
||||
import org.jetbrains.kotlin.generators.tests.generator.testGroup
|
||||
import org.jetbrains.kotlin.js.test.AbstractDceTest
|
||||
import org.jetbrains.kotlin.js.test.AbstractIrJsTypeScriptExportTest
|
||||
import org.jetbrains.kotlin.js.test.AbstractJsLineNumberTest
|
||||
import org.jetbrains.kotlin.js.test.ir.semantics.*
|
||||
import org.jetbrains.kotlin.js.test.semantics.*
|
||||
@@ -28,6 +29,10 @@ fun main(args: Array<String>) {
|
||||
model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR)
|
||||
}
|
||||
|
||||
testClass<AbstractIrJsTypeScriptExportTest> {
|
||||
model("typescript-export/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR)
|
||||
}
|
||||
|
||||
testClass<AbstractSourceMapGenerationSmokeTest> {
|
||||
model("sourcemap/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.js.test
|
||||
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull
|
||||
import java.io.File
|
||||
import java.lang.Boolean.getBoolean
|
||||
|
||||
@Suppress("ConstantConditionIf")
|
||||
abstract class AbstractIrJsTypeScriptExportTest : BasicIrBoxTest(
|
||||
pathToTestDir = TEST_DATA_DIR_PATH + "typescript-export/",
|
||||
testGroupOutputDirPrefix = "typescript-export/",
|
||||
pathToRootOutputDir = TEST_DATA_DIR_PATH
|
||||
) {
|
||||
override val generateDts = true
|
||||
private val updateReferenceDtsFiles = getBoolean("kotlin.js.updateReferenceDtsFiles")
|
||||
|
||||
override fun performAdditionalChecks(inputFile: File, outputFile: File) {
|
||||
val referenceDtsFile = inputFile.withReplacedExtensionOrNull(".kt", ".d.ts")
|
||||
?: error("Can't find reference .d.ts file")
|
||||
val generatedDtsFile = outputFile.withReplacedExtensionOrNull("_v5", ".d.ts")
|
||||
?: error("Can't find generated .d.ts file")
|
||||
|
||||
val generatedDts = generatedDtsFile.readText()
|
||||
|
||||
if (updateReferenceDtsFiles)
|
||||
referenceDtsFile.writeText(generatedDts)
|
||||
else
|
||||
KotlinTestUtils.assertEqualsToFile(referenceDtsFile, generatedDts)
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.cli.common.output.writeAllTo
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.daemon.common.PackageMetadata
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.incremental.js.IncrementalDataProviderImpl
|
||||
import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumerImpl
|
||||
@@ -49,7 +48,6 @@ import org.jetbrains.kotlin.js.test.interop.ScriptEngineV8Lazy
|
||||
import org.jetbrains.kotlin.js.test.utils.*
|
||||
import org.jetbrains.kotlin.js.util.TextOutputImpl
|
||||
import org.jetbrains.kotlin.metadata.DebugProtoBuf
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
@@ -200,8 +198,14 @@ abstract class BasicBoxTest(
|
||||
additionalFiles += additionalJsFile
|
||||
}
|
||||
|
||||
val additionalMainFiles = mutableListOf<String>()
|
||||
val additionalMainJsFile = filePath.removeSuffix("." + KotlinFileType.EXTENSION) + "__main.js"
|
||||
if (File(additionalMainJsFile).exists()) {
|
||||
additionalMainFiles += additionalMainJsFile
|
||||
}
|
||||
|
||||
val allJsFiles = additionalFiles + inputJsFiles + generatedJsFiles.map { it.first } + globalCommonFiles + localCommonFiles +
|
||||
additionalCommonFiles
|
||||
additionalCommonFiles + additionalMainFiles
|
||||
|
||||
val dontRunGeneratedCode = InTextDirectivesUtils.dontRunGeneratedCode(targetBackend, file)
|
||||
|
||||
@@ -217,7 +221,7 @@ abstract class BasicBoxTest(
|
||||
}
|
||||
|
||||
performAdditionalChecks(generatedJsFiles.map { it.first }, outputPrefixFile, outputPostfixFile)
|
||||
|
||||
performAdditionalChecks(file, File(mainModule.outputFileName(outputDir)))
|
||||
val expectedReachableNodesMatcher = EXPECTED_REACHABLE_NODES.matcher(fileContent)
|
||||
val expectedReachableNodesFound = expectedReachableNodesMatcher.find()
|
||||
|
||||
@@ -277,6 +281,7 @@ abstract class BasicBoxTest(
|
||||
}
|
||||
|
||||
protected open fun performAdditionalChecks(generatedJsFiles: List<String>, outputPrefixFile: File?, outputPostfixFile: File?) {}
|
||||
protected open fun performAdditionalChecks(inputFile: File, outputFile: File) {}
|
||||
|
||||
private fun generateNodeRunner(
|
||||
files: Collection<String>,
|
||||
|
||||
@@ -17,7 +17,9 @@ import org.jetbrains.kotlin.js.facade.MainCallParameters
|
||||
import org.jetbrains.kotlin.js.facade.TranslationUnit
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull
|
||||
import java.io.File
|
||||
import java.lang.Boolean.getBoolean
|
||||
|
||||
private val fullRuntimeKlib = loadKlib("compiler/ir/serialization.js/build/fullRuntime/klib")
|
||||
private val defaultRuntimeKlib = loadKlib("compiler/ir/serialization.js/build/reducedRuntime/klib")
|
||||
@@ -26,7 +28,7 @@ private val kotlinTestKLib = loadKlib("compiler/ir/serialization.js/build/kotlin
|
||||
abstract class BasicIrBoxTest(
|
||||
pathToTestDir: String,
|
||||
testGroupOutputDirPrefix: String,
|
||||
pathToRootOutputDir: String = BasicBoxTest.TEST_DATA_DIR_PATH,
|
||||
pathToRootOutputDir: String = TEST_DATA_DIR_PATH,
|
||||
generateSourceMap: Boolean = false,
|
||||
generateNodeJsRunner: Boolean = false
|
||||
) : BasicBoxTest(
|
||||
@@ -38,6 +40,7 @@ abstract class BasicIrBoxTest(
|
||||
generateNodeJsRunner = generateNodeJsRunner,
|
||||
targetBackend = TargetBackend.JS_IR
|
||||
) {
|
||||
open val generateDts = false
|
||||
|
||||
override val skipMinification = true
|
||||
|
||||
@@ -53,6 +56,7 @@ abstract class BasicIrBoxTest(
|
||||
|
||||
override val testChecker get() = if (runTestInNashorn) NashornIrJsTestChecker() else V8IrJsTestChecker
|
||||
|
||||
@Suppress("ConstantConditionIf")
|
||||
override fun translateFiles(
|
||||
units: List<TranslationUnit>,
|
||||
outputFile: File,
|
||||
@@ -70,7 +74,7 @@ abstract class BasicIrBoxTest(
|
||||
val filesToCompile = units
|
||||
.map { (it as TranslationUnit.SourceFile).file }
|
||||
// TODO: split input files to some parts (global common, local common, test)
|
||||
.filterNot { it.virtualFilePath.contains(BasicBoxTest.COMMON_FILES_DIR_PATH) }
|
||||
.filterNot { it.virtualFilePath.contains(COMMON_FILES_DIR_PATH) }
|
||||
|
||||
val runtimeKlibs = if (needsFullIrRuntime) listOf(fullRuntimeKlib, kotlinTestKLib) else listOf(defaultRuntimeKlib)
|
||||
|
||||
@@ -85,7 +89,7 @@ abstract class BasicIrBoxTest(
|
||||
}
|
||||
|
||||
if (isMainModule) {
|
||||
val debugMode = false
|
||||
val debugMode = getBoolean("kotlin.js.debugMode")
|
||||
|
||||
val phaseConfig = if (debugMode) {
|
||||
val allPhasesSet = jsPhases.toPhaseMap().values.toSet()
|
||||
@@ -102,7 +106,7 @@ abstract class BasicIrBoxTest(
|
||||
PhaseConfig(jsPhases)
|
||||
}
|
||||
|
||||
val jsCode = compile(
|
||||
val compiledModule = compile(
|
||||
project = config.project,
|
||||
files = filesToCompile,
|
||||
configuration = config.configuration,
|
||||
@@ -113,9 +117,14 @@ abstract class BasicIrBoxTest(
|
||||
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction)))
|
||||
)
|
||||
|
||||
val wrappedCode = wrapWithModuleEmulationMarkers(jsCode, moduleId = config.moduleId, moduleKind = config.moduleKind)
|
||||
val wrappedCode = wrapWithModuleEmulationMarkers(compiledModule.jsCode, moduleId = config.moduleId, moduleKind = config.moduleKind)
|
||||
outputFile.write(wrappedCode)
|
||||
|
||||
if (generateDts) {
|
||||
val dtsFile = outputFile.withReplacedExtensionOrNull("_v5.js", ".d.ts")
|
||||
dtsFile?.write(compiledModule.tsDefinitions ?: error("No ts definitions"))
|
||||
}
|
||||
|
||||
} else {
|
||||
generateKLib(
|
||||
project = config.project,
|
||||
@@ -142,7 +151,7 @@ abstract class BasicIrBoxTest(
|
||||
// TODO: should we do anything special for module systems?
|
||||
// TODO: return list of js from translateFiles and provide then to this function with other js files
|
||||
|
||||
testChecker.check(jsFiles, testModuleName, null, testFunction, expectedResult, withModuleSystem)
|
||||
testChecker.check(jsFiles, testModuleName, testPackage, testFunction, expectedResult, withModuleSystem)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment
|
||||
import java.io.Closeable
|
||||
import java.io.File
|
||||
import java.lang.Boolean.getBoolean
|
||||
|
||||
private val wasmRuntimeKlib =
|
||||
loadKlib("compiler/ir/serialization.js/build/wasmRuntime/klib")
|
||||
@@ -88,7 +89,7 @@ abstract class BasicWasmBoxTest(
|
||||
testFunction: String
|
||||
) {
|
||||
val filesToCompile = units.map { (it as TranslationUnit.SourceFile).file }
|
||||
val debugMode = false
|
||||
val debugMode = getBoolean("kotlin.js.debugMode")
|
||||
|
||||
val phaseConfig = if (debugMode) {
|
||||
val allPhasesSet = wasmPhases.toPhaseMap().values.toSet()
|
||||
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright 2010-2019 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.js.test;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("js/js.translator/testData/typescript-export")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExportTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInTypescript_export() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/typescript-export"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/typescript-export/declarations")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Declarations extends AbstractIrJsTypeScriptExportTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInDeclarations() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/typescript-export/declarations"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("declarations.kt")
|
||||
public void testDeclarations() throws Exception {
|
||||
runTest("js/js.translator/testData/typescript-export/declarations/declarations.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/typescript-export/inheritance")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Inheritance extends AbstractIrJsTypeScriptExportTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInInheritance() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/typescript-export/inheritance"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("inheritance.kt")
|
||||
public void testInheritance() throws Exception {
|
||||
runTest("js/js.translator/testData/typescript-export/inheritance/inheritance.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/typescript-export/namespaces")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Namespaces extends AbstractIrJsTypeScriptExportTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInNamespaces() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/typescript-export/namespaces"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("namespaces.kt")
|
||||
public void testNamespaces() throws Exception {
|
||||
runTest("js/js.translator/testData/typescript-export/namespaces/namespaces.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/typescript-export/primitives")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Primitives extends AbstractIrJsTypeScriptExportTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInPrimitives() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/typescript-export/primitives"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("primitives.kt")
|
||||
public void testPrimitives() throws Exception {
|
||||
runTest("js/js.translator/testData/typescript-export/primitives/primitives.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/typescript-export/selectiveExport")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class SelectiveExport extends AbstractIrJsTypeScriptExportTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInSelectiveExport() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/typescript-export/selectiveExport"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("selectiveExport.kt")
|
||||
public void testSelectiveExport() throws Exception {
|
||||
runTest("js/js.translator/testData/typescript-export/selectiveExport/selectiveExport.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("js/js.translator/testData/typescript-export/visibility")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Visibility extends AbstractIrJsTypeScriptExportTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInVisibility() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/typescript-export/visibility"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("visibility.kt")
|
||||
public void testVisibility() throws Exception {
|
||||
runTest("js/js.translator/testData/typescript-export/visibility/visibility.kt");
|
||||
}
|
||||
}
|
||||
}
|
||||
-10
@@ -6425,11 +6425,6 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/propertyAccess/accessToInstanceProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("accessorsWithJsName.kt")
|
||||
public void testAccessorsWithJsName() throws Exception {
|
||||
runTest("js/js.translator/testData/box/propertyAccess/accessorsWithJsName.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInPropertyAccess() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("js/js.translator/testData/box/propertyAccess"), Pattern.compile("^([^_](.+))\\.kt$"), TargetBackend.JS_IR, true);
|
||||
}
|
||||
@@ -6449,11 +6444,6 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/propertyAccess/customSetter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultAccessorsWithJsName.kt")
|
||||
public void testDefaultAccessorsWithJsName() throws Exception {
|
||||
runTest("js/js.translator/testData/box/propertyAccess/defaultAccessorsWithJsName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("enumerable.kt")
|
||||
public void testEnumerable() throws Exception {
|
||||
runTest("js/js.translator/testData/box/propertyAccess/enumerable.kt");
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1291
|
||||
|
||||
class A {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// DONT_TARGET_EXACT_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1288
|
||||
package foo
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// EXPECTED_REACHABLE_NODES: 1288
|
||||
|
||||
@JsExport
|
||||
|
||||
+6
-4
@@ -1,14 +1,16 @@
|
||||
{
|
||||
"dependencies" : {
|
||||
"dependencies": {
|
||||
"require-from-string": "1.2.0"
|
||||
},
|
||||
"devDependencies" : {
|
||||
"devDependencies": {
|
||||
"mocha": "3.2.0",
|
||||
"mocha-teamcity-reporter": "1.1.1"
|
||||
"mocha-teamcity-reporter": "1.1.1",
|
||||
"typescript": "^3.5.3"
|
||||
},
|
||||
"scripts": {
|
||||
"runOnTeamcity": "mocha --reporter mocha-teamcity-reporter",
|
||||
"test": "mocha",
|
||||
"runIrTestInNode" : "node $NODE_DEBUG_OPTION runIrTestInNode.js"
|
||||
"runIrTestInNode": "node $NODE_DEBUG_OPTION runIrTestInNode.js",
|
||||
"generateTypeScriptTests": "tsc --build typescript-export/*/"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"strict": true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
declare namespace JS_TESTS {
|
||||
type Nullable<T> = T | null | undefined
|
||||
namespace foo {
|
||||
function sum(x: number, y: number): number
|
||||
function varargInt(x: Int32Array): number
|
||||
function varargNullableInt(x: Array<Nullable<number>>): number
|
||||
function varargWithOtherParameters(x: string, y: Array<string>, z: string): number
|
||||
function varargWithComplexType(x: Array<(p0: Array<Int32Array>) => Array<Int32Array>>): number
|
||||
function sumNullable(x: Nullable<number>, y: Nullable<number>): number
|
||||
function defaultParameters(x: number, y: string): string
|
||||
function generic1<T>(x: T): T
|
||||
function generic2<T>(x: Nullable<T>): boolean
|
||||
function generic3<A, B, C, D, E>(a: A, b: B, c: C, d: D): Nullable<E>
|
||||
function inlineFun(x: number, callback: (p0: number) => void): void
|
||||
const _const_val: number;
|
||||
const _val: number;
|
||||
let _var: number;
|
||||
const _valCustom: number;
|
||||
const _valCustomWithField: number;
|
||||
let _varCustom: number;
|
||||
let _varCustomWithField: number;
|
||||
class A {
|
||||
constructor()
|
||||
}
|
||||
class A1 {
|
||||
constructor(x: number)
|
||||
readonly x: number;
|
||||
}
|
||||
class A2 {
|
||||
constructor(x: string, y: boolean)
|
||||
readonly x: string;
|
||||
y: boolean;
|
||||
}
|
||||
class A3 {
|
||||
constructor()
|
||||
readonly x: number;
|
||||
}
|
||||
class A4 {
|
||||
constructor()
|
||||
readonly _valCustom: number;
|
||||
readonly _valCustomWithField: number;
|
||||
_varCustom: number;
|
||||
_varCustomWithField: number;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// CHECK_TYPESCRIPT_DECLARATIONS
|
||||
// RUN_PLAIN_BOX_FUNCTION
|
||||
|
||||
@file:JsExport
|
||||
|
||||
package foo
|
||||
|
||||
// TODO: Test the same for member functions:
|
||||
|
||||
fun sum(x: Int, y: Int): Int =
|
||||
x + y
|
||||
|
||||
fun varargInt(vararg x: Int): Int =
|
||||
x.size
|
||||
|
||||
fun varargNullableInt(vararg x: Int?): Int =
|
||||
x.size
|
||||
|
||||
fun varargWithOtherParameters(x: String, vararg y: String, z: String): Int =
|
||||
x.length + y.size + z.length
|
||||
|
||||
fun varargWithComplexType(vararg x: (Array<IntArray>) -> Array<IntArray>): Int =
|
||||
x.size
|
||||
|
||||
fun sumNullable(x: Int?, y: Int?): Int =
|
||||
(x ?: 0) + (y ?: 0)
|
||||
|
||||
fun defaultParameters(x: Int = 10, y: String = "OK"): String =
|
||||
x.toString() + y
|
||||
|
||||
fun <T> generic1(x: T): T = x
|
||||
|
||||
fun <T> generic2(x: T?): Boolean = (x == null)
|
||||
|
||||
fun <A, B, C, D, E> generic3(a: A, b: B, c: C, d: D): E? = null
|
||||
|
||||
inline fun inlineFun(x: Int, callback: (Int) -> Unit) {
|
||||
callback(x)
|
||||
}
|
||||
|
||||
// Properties
|
||||
|
||||
const val _const_val: Int = 1
|
||||
val _val: Int = 1
|
||||
var _var: Int = 1
|
||||
|
||||
val _valCustom: Int
|
||||
get() = 1
|
||||
|
||||
val _valCustomWithField: Int = 1
|
||||
get() = field + 1
|
||||
|
||||
var _varCustom: Int
|
||||
get() = 1
|
||||
set(value) {}
|
||||
|
||||
var _varCustomWithField: Int = 1
|
||||
get() = field * 10
|
||||
set(value) { field = value * 10 }
|
||||
|
||||
// Classes
|
||||
|
||||
class A
|
||||
class A1(val x: Int)
|
||||
class A2(val x: String, var y: Boolean)
|
||||
class A3 {
|
||||
val x: Int = 100
|
||||
}
|
||||
class A4 {
|
||||
val _valCustom: Int
|
||||
get() = 1
|
||||
|
||||
val _valCustomWithField: Int = 1
|
||||
get() = field + 1
|
||||
|
||||
var _varCustom: Int
|
||||
get() = 1
|
||||
set(value) {}
|
||||
|
||||
var _varCustomWithField: Int = 1
|
||||
get() = field * 10
|
||||
set(value) { field = value * 10 }
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
"use strict";
|
||||
var foo = JS_TESTS.foo;
|
||||
var varargInt = JS_TESTS.foo.varargInt;
|
||||
var varargNullableInt = JS_TESTS.foo.varargNullableInt;
|
||||
var varargWithOtherParameters = JS_TESTS.foo.varargWithOtherParameters;
|
||||
var varargWithComplexType = JS_TESTS.foo.varargWithComplexType;
|
||||
var sumNullable = JS_TESTS.foo.sumNullable;
|
||||
var defaultParameters = JS_TESTS.foo.defaultParameters;
|
||||
var generic1 = JS_TESTS.foo.generic1;
|
||||
var generic2 = JS_TESTS.foo.generic2;
|
||||
var generic3 = JS_TESTS.foo.generic3;
|
||||
var inlineFun = JS_TESTS.foo.inlineFun;
|
||||
var _const_val = JS_TESTS.foo._const_val;
|
||||
var _val = JS_TESTS.foo._val;
|
||||
var _var = JS_TESTS.foo._var;
|
||||
var A = JS_TESTS.foo.A;
|
||||
var A1 = JS_TESTS.foo.A1;
|
||||
var A2 = JS_TESTS.foo.A2;
|
||||
var A3 = JS_TESTS.foo.A3;
|
||||
var _valCustom = JS_TESTS.foo._valCustom;
|
||||
var _valCustomWithField = JS_TESTS.foo._valCustomWithField;
|
||||
var A4 = JS_TESTS.foo.A4;
|
||||
function assert(condition) {
|
||||
if (!condition) {
|
||||
throw "Assertion failed";
|
||||
}
|
||||
}
|
||||
function box() {
|
||||
assert(foo.sum(10, 20) === 30);
|
||||
assert(varargInt(new Int32Array([1, 2, 3])) === 3);
|
||||
assert(varargNullableInt([10, 20, 30, null, undefined, 40]) === 6);
|
||||
assert(varargWithOtherParameters("1234", ["1", "2", "3"], "12") === 9);
|
||||
assert(varargWithComplexType([]) === 0);
|
||||
assert(varargWithComplexType([
|
||||
function (x) { return x; },
|
||||
function (x) { return [new Int32Array([1, 2, 3])]; },
|
||||
function (x) { return []; },
|
||||
]) === 3);
|
||||
assert(sumNullable(10, null) === 10);
|
||||
assert(sumNullable(undefined, 20) === 20);
|
||||
assert(sumNullable(1, 2) === 3);
|
||||
assert(defaultParameters(20, "OK") === "20OK");
|
||||
assert(generic1("FOO") === "FOO");
|
||||
assert(generic1({ x: 10 }).x === 10);
|
||||
assert(generic2(null) === true);
|
||||
assert(generic2(undefined) === true);
|
||||
assert(generic2(10) === false);
|
||||
assert(generic3(10, true, "__", {}) === null);
|
||||
var result = 0;
|
||||
inlineFun(10, function (x) { result = x; });
|
||||
assert(result === 10);
|
||||
assert(_const_val === 1);
|
||||
assert(_val === 1);
|
||||
assert(_var === 1);
|
||||
foo._var = 1000;
|
||||
assert(foo._var === 1000);
|
||||
assert(foo._valCustom === 1);
|
||||
assert(foo._valCustomWithField === 2);
|
||||
assert(foo._varCustom === 1);
|
||||
foo._varCustom = 20;
|
||||
assert(foo._varCustom === 1);
|
||||
assert(foo._varCustomWithField === 10);
|
||||
foo._varCustomWithField = 10;
|
||||
assert(foo._varCustomWithField === 1000);
|
||||
new A();
|
||||
assert(new A1(10).x === 10);
|
||||
assert(new A2("10", true).x === "10");
|
||||
assert(new A3().x === 100);
|
||||
var a4 = new A4();
|
||||
assert(a4._valCustom === 1);
|
||||
assert(a4._valCustomWithField === 2);
|
||||
assert(a4._varCustom === 1);
|
||||
a4._varCustom = 20;
|
||||
assert(a4._varCustom === 1);
|
||||
assert(a4._varCustomWithField === 10);
|
||||
a4._varCustomWithField = 10;
|
||||
assert(a4._varCustomWithField === 1000);
|
||||
return "OK";
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
|
||||
import foo = JS_TESTS.foo;
|
||||
import varargInt = JS_TESTS.foo.varargInt;
|
||||
import varargNullableInt = JS_TESTS.foo.varargNullableInt;
|
||||
import varargWithOtherParameters = JS_TESTS.foo.varargWithOtherParameters;
|
||||
import varargWithComplexType = JS_TESTS.foo.varargWithComplexType;
|
||||
import sumNullable = JS_TESTS.foo.sumNullable;
|
||||
import defaultParameters = JS_TESTS.foo.defaultParameters;
|
||||
import generic1 = JS_TESTS.foo.generic1;
|
||||
import generic2 = JS_TESTS.foo.generic2;
|
||||
import generic3 = JS_TESTS.foo.generic3;
|
||||
import inlineFun = JS_TESTS.foo.inlineFun;
|
||||
import _const_val = JS_TESTS.foo._const_val;
|
||||
import _val = JS_TESTS.foo._val;
|
||||
import _var = JS_TESTS.foo._var;
|
||||
import A = JS_TESTS.foo.A;
|
||||
import A1 = JS_TESTS.foo.A1;
|
||||
import A2 = JS_TESTS.foo.A2;
|
||||
import A3 = JS_TESTS.foo.A3;
|
||||
import _valCustom = JS_TESTS.foo._valCustom;
|
||||
import _valCustomWithField = JS_TESTS.foo._valCustomWithField;
|
||||
import A4 = JS_TESTS.foo.A4;
|
||||
|
||||
function assert(condition: boolean) {
|
||||
if (!condition) {
|
||||
throw "Assertion failed";
|
||||
}
|
||||
}
|
||||
|
||||
function box(): string {
|
||||
assert(foo.sum(10, 20) === 30);
|
||||
assert(varargInt(new Int32Array([1, 2, 3])) === 3);
|
||||
assert(varargNullableInt([10, 20, 30, null, undefined, 40]) === 6);
|
||||
assert(varargWithOtherParameters("1234", ["1", "2", "3"], "12") === 9);
|
||||
assert(varargWithComplexType([]) === 0);
|
||||
assert(varargWithComplexType([
|
||||
x => x,
|
||||
x => [new Int32Array([1, 2, 3])],
|
||||
x => [],
|
||||
]) === 3);
|
||||
|
||||
assert(sumNullable(10, null) === 10);
|
||||
assert(sumNullable(undefined, 20) === 20);
|
||||
assert(sumNullable(1, 2) === 3);
|
||||
assert(defaultParameters(20, "OK") === "20OK");
|
||||
assert(generic1<string>("FOO") === "FOO");
|
||||
assert(generic1({x: 10}).x === 10);
|
||||
assert(generic2(null) === true);
|
||||
assert(generic2(undefined) === true);
|
||||
assert(generic2(10) === false);
|
||||
assert(generic3(10, true, "__", {}) === null);
|
||||
|
||||
let result: number = 0;
|
||||
inlineFun(10, x => { result = x; });
|
||||
assert(result === 10);
|
||||
|
||||
assert(_const_val === 1);
|
||||
assert(_val === 1);
|
||||
assert(_var === 1);
|
||||
foo._var = 1000;
|
||||
assert(foo._var === 1000);
|
||||
|
||||
assert(foo._valCustom === 1);
|
||||
assert(foo._valCustomWithField === 2);
|
||||
assert(foo._varCustom === 1);
|
||||
foo._varCustom = 20;
|
||||
assert(foo._varCustom === 1);
|
||||
assert(foo._varCustomWithField === 10);
|
||||
foo._varCustomWithField = 10;
|
||||
assert(foo._varCustomWithField === 1000);
|
||||
|
||||
new A();
|
||||
assert(new A1(10).x === 10);
|
||||
assert(new A2("10", true).x === "10");
|
||||
assert(new A3().x === 100);
|
||||
|
||||
|
||||
const a4 = new A4();
|
||||
|
||||
assert(a4._valCustom === 1);
|
||||
assert(a4._valCustomWithField === 2);
|
||||
assert(a4._varCustom === 1);
|
||||
a4._varCustom = 20;
|
||||
assert(a4._varCustom === 1);
|
||||
assert(a4._varCustomWithField === 10);
|
||||
a4._varCustomWithField = 10;
|
||||
assert(a4._varCustomWithField === 1000);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"include": [ "./*" ],
|
||||
"extends": "../common.tsconfig.json"
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
declare namespace JS_TESTS {
|
||||
type Nullable<T> = T | null | undefined
|
||||
namespace foo {
|
||||
interface I<T, S, U> {
|
||||
x: T;
|
||||
readonly y: S;
|
||||
z(u: U): void
|
||||
}
|
||||
interface I2 {
|
||||
x: string;
|
||||
readonly y: boolean;
|
||||
z(z: number): void
|
||||
}
|
||||
}
|
||||
namespace foo {
|
||||
abstract class AC implements foo.I2 {
|
||||
constructor()
|
||||
x: string;
|
||||
abstract readonly y: boolean;
|
||||
abstract z(z: number): void
|
||||
readonly acProp: string;
|
||||
abstract readonly acAbstractProp: string;
|
||||
}
|
||||
class OC extends foo.AC implements foo.I<string, boolean, number> {
|
||||
constructor(y: boolean, acAbstractProp: string)
|
||||
readonly y: boolean;
|
||||
readonly acAbstractProp: string;
|
||||
z(z: number): void
|
||||
}
|
||||
class FC extends foo.OC {
|
||||
constructor()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// CHECK_TYPESCRIPT_DECLARATIONS
|
||||
// RUN_PLAIN_BOX_FUNCTION
|
||||
|
||||
@file:JsExport
|
||||
|
||||
package foo
|
||||
|
||||
external interface I<T, out S, in U> {
|
||||
var x: T
|
||||
val y: S
|
||||
fun z(u: U)
|
||||
}
|
||||
|
||||
external interface I2 {
|
||||
var x: String
|
||||
val y: Boolean
|
||||
fun z(z: Int)
|
||||
}
|
||||
|
||||
abstract class AC : I2 {
|
||||
override var x = "AC"
|
||||
override abstract val y: Boolean
|
||||
override abstract fun z(z: Int)
|
||||
|
||||
val acProp: String = "acProp"
|
||||
abstract val acAbstractProp: String
|
||||
}
|
||||
|
||||
open class OC(
|
||||
override val y: Boolean,
|
||||
override val acAbstractProp: String
|
||||
) : AC(), I<String, Boolean, Int> {
|
||||
override fun z(z: Int) {
|
||||
}
|
||||
|
||||
private val privateX: String = "privateX"
|
||||
private fun privateFun(): String = "privateFun"
|
||||
}
|
||||
|
||||
final class FC : OC(true, "FC")
|
||||
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
var __extends = (this && this.__extends) || (function () {
|
||||
var extendStatics = function (d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
return function (d, b) {
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};
|
||||
})();
|
||||
var OC = JS_TESTS.foo.OC;
|
||||
var AC = JS_TESTS.foo.AC;
|
||||
var FC = JS_TESTS.foo.FC;
|
||||
var Impl = /** @class */ (function (_super) {
|
||||
__extends(Impl, _super);
|
||||
function Impl() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
}
|
||||
Impl.prototype.z = function (z) {
|
||||
};
|
||||
Object.defineProperty(Impl.prototype, "acAbstractProp", {
|
||||
get: function () { return "Impl"; },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Impl.prototype, "y", {
|
||||
get: function () { return true; },
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return Impl;
|
||||
}(AC));
|
||||
function box() {
|
||||
var impl = new Impl();
|
||||
if (impl.acProp !== "acProp")
|
||||
return "Fail 1";
|
||||
if (impl.x !== "AC")
|
||||
return "Fail 2";
|
||||
if (impl.acAbstractProp !== "Impl")
|
||||
return "Fail 2.1";
|
||||
if (impl.y !== true)
|
||||
return "Fail 2.2";
|
||||
var oc = new OC(false, "OC");
|
||||
if (oc.y !== false)
|
||||
return "Fail 3";
|
||||
if (oc.acAbstractProp !== "OC")
|
||||
return "Fail 4";
|
||||
oc.z(10);
|
||||
var fc = new FC();
|
||||
if (fc.y !== true)
|
||||
return "Fail 5";
|
||||
if (fc.acAbstractProp !== "FC")
|
||||
return "Fail 6";
|
||||
fc.z(10);
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import OC = JS_TESTS.foo.OC;
|
||||
import AC = JS_TESTS.foo.AC;
|
||||
import FC = JS_TESTS.foo.FC;
|
||||
|
||||
class Impl extends AC {
|
||||
z(z: number): void {
|
||||
}
|
||||
|
||||
get acAbstractProp(): string { return "Impl"; }
|
||||
get y(): boolean { return true; }
|
||||
}
|
||||
|
||||
function box(): string {
|
||||
const impl = new Impl();
|
||||
if (impl.acProp !== "acProp") return "Fail 1";
|
||||
if (impl.x !== "AC") return "Fail 2";
|
||||
if (impl.acAbstractProp !== "Impl") return "Fail 2.1";
|
||||
if (impl.y !== true) return "Fail 2.2";
|
||||
|
||||
|
||||
const oc = new OC(false, "OC");
|
||||
if (oc.y !== false) return "Fail 3";
|
||||
if (oc.acAbstractProp !== "OC") return "Fail 4";
|
||||
oc.z(10);
|
||||
|
||||
|
||||
const fc = new FC();
|
||||
if (fc.y !== true) return "Fail 5";
|
||||
if (fc.acAbstractProp !== "FC") return "Fail 6";
|
||||
fc.z(10);
|
||||
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"include": [ "./*" ],
|
||||
"extends": "../common.tsconfig.json"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
declare namespace JS_TESTS {
|
||||
type Nullable<T> = T | null | undefined
|
||||
namespace foo.bar.baz {
|
||||
class C1 {
|
||||
constructor(value: string)
|
||||
readonly value: string;
|
||||
component1(): string
|
||||
copy(value: string): foo.bar.baz.C1
|
||||
toString(): string
|
||||
hashCode(): number
|
||||
equals(other: Nullable<any>): boolean
|
||||
}
|
||||
function f(x1: foo.bar.baz.C1, x2: a.b.C2, x3: C3): string
|
||||
}
|
||||
namespace a.b {
|
||||
class C2 {
|
||||
constructor(value: string)
|
||||
readonly value: string;
|
||||
component1(): string
|
||||
copy(value: string): a.b.C2
|
||||
toString(): string
|
||||
hashCode(): number
|
||||
equals(other: Nullable<any>): boolean
|
||||
}
|
||||
function f(x1: foo.bar.baz.C1, x2: a.b.C2, x3: C3): string
|
||||
}
|
||||
class C3 {
|
||||
constructor(value: string)
|
||||
readonly value: string;
|
||||
component1(): string
|
||||
copy(value: string): C3
|
||||
toString(): string
|
||||
hashCode(): number
|
||||
equals(other: Nullable<any>): boolean
|
||||
}
|
||||
function f(x1: foo.bar.baz.C1, x2: a.b.C2, x3: C3): string
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// CHECK_TYPESCRIPT_DECLARATIONS
|
||||
// RUN_PLAIN_BOX_FUNCTION
|
||||
|
||||
// FILE: file1.kt
|
||||
|
||||
package foo.bar.baz
|
||||
|
||||
import a.b.*
|
||||
import C3
|
||||
|
||||
@JsExport
|
||||
data class C1(val value: String)
|
||||
|
||||
@JsExport
|
||||
fun f(x1: C1, x2: C2, x3: C3): String {
|
||||
return "foo.bar.baz.f($x1, $x2, $x3)"
|
||||
}
|
||||
|
||||
// FILE: file2.kt
|
||||
|
||||
@file:JsExport
|
||||
|
||||
package a.b
|
||||
|
||||
import foo.bar.baz.*
|
||||
import C3
|
||||
|
||||
data class C2(val value: String)
|
||||
fun f(x1: C1, x2: C2, x3: C3): String {
|
||||
return "a.b.f($x1, $x2, $x3)"
|
||||
}
|
||||
|
||||
// FILE: file3.kt
|
||||
|
||||
@file:JsExport
|
||||
|
||||
import a.b.*
|
||||
import foo.bar.baz.*
|
||||
|
||||
@JsExport
|
||||
data class C3(val value: String)
|
||||
|
||||
@JsExport
|
||||
fun f(x1: C1, x2: C2, x3: C3): String {
|
||||
return "f($x1, $x2, $x3)"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
var C1 = JS_TESTS.foo.bar.baz.C1;
|
||||
var C2 = JS_TESTS.a.b.C2;
|
||||
var C3 = JS_TESTS.C3;
|
||||
function box() {
|
||||
var c1 = new C1("1");
|
||||
var c2 = new C2("2");
|
||||
var c3 = new C3("3");
|
||||
var res1 = JS_TESTS.foo.bar.baz.f(c1, c2, c3);
|
||||
var res2 = JS_TESTS.a.b.f(c1, c2, c3);
|
||||
var res3 = JS_TESTS.f(c1, c2, c3);
|
||||
if (res1 !== "foo.bar.baz.f(C1(value=1), C2(value=2), C3(value=3))")
|
||||
return "Fail 1: " + res1;
|
||||
if (res2 !== "a.b.f(C1(value=1), C2(value=2), C3(value=3))")
|
||||
return "Fail 2: " + res2;
|
||||
if (res3 !== "f(C1(value=1), C2(value=2), C3(value=3))")
|
||||
return "Fail 3: " + res3;
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import C1 = JS_TESTS.foo.bar.baz.C1;
|
||||
import C2 = JS_TESTS.a.b.C2;
|
||||
import C3 = JS_TESTS.C3;
|
||||
|
||||
function box(): string {
|
||||
const c1 = new C1("1");
|
||||
const c2 = new C2("2");
|
||||
const c3 = new C3("3");
|
||||
|
||||
const res1 = JS_TESTS.foo.bar.baz.f(c1, c2, c3);
|
||||
const res2 = JS_TESTS.a.b.f(c1, c2, c3);
|
||||
const res3 = JS_TESTS.f(c1, c2, c3);
|
||||
|
||||
if (res1 !== "foo.bar.baz.f(C1(value=1), C2(value=2), C3(value=3))")
|
||||
return "Fail 1: " + res1;
|
||||
|
||||
if (res2 !== "a.b.f(C1(value=1), C2(value=2), C3(value=3))")
|
||||
return "Fail 2: " + res2;
|
||||
|
||||
if (res3 !== "f(C1(value=1), C2(value=2), C3(value=3))")
|
||||
return "Fail 3: " + res3;
|
||||
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"include": [ "./*" ],
|
||||
"extends": "../common.tsconfig.json"
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
declare namespace JS_TESTS {
|
||||
type Nullable<T> = T | null | undefined
|
||||
namespace foo {
|
||||
const _any: any;
|
||||
const _unit: void;
|
||||
function _nothing(): never
|
||||
const _throwable: Error;
|
||||
const _string: string;
|
||||
const _boolean: boolean;
|
||||
const _byte: number;
|
||||
const _short: number;
|
||||
const _int: number;
|
||||
const _float: number;
|
||||
const _double: number;
|
||||
const _byte_array: Int8Array;
|
||||
const _short_array: Int16Array;
|
||||
const _int_array: Int32Array;
|
||||
const _float_array: Float32Array;
|
||||
const _double_array: Float64Array;
|
||||
const _array_byte: Array<number>;
|
||||
const _array_short: Array<number>;
|
||||
const _array_int: Array<number>;
|
||||
const _array_float: Array<number>;
|
||||
const _array_double: Array<number>;
|
||||
const _array_string: Array<string>;
|
||||
const _array_boolean: Array<boolean>;
|
||||
const _array_array_string: Array<Array<string>>;
|
||||
const _array_array_int_array: Array<Array<Int32Array>>;
|
||||
const _fun_unit: () => void;
|
||||
const _fun_int_unit: (p0: number) => void;
|
||||
const _fun_boolean_int_string_intarray: (p0: boolean, p1: number, p2: string) => Int32Array;
|
||||
const _curried_fun: (p0: number) => (p0: number) => (p0: number) => (p0: number) => (p0: number) => number;
|
||||
const _higher_order_fun: (p0: (p0: number) => string, p1: (p0: string) => number) => (p0: number) => number;
|
||||
const _n_any: Nullable<any>;
|
||||
const _n_nothing: Nullable<never>;
|
||||
const _n_throwable: Nullable<Error>;
|
||||
const _n_string: Nullable<string>;
|
||||
const _n_boolean: Nullable<boolean>;
|
||||
const _n_byte: Nullable<number>;
|
||||
const _n_short_array: Nullable<Int16Array>;
|
||||
const _n_array_int: Nullable<Array<number>>;
|
||||
const _array_n_int: Array<Nullable<number>>;
|
||||
const _n_array_n_int: Nullable<Array<Nullable<number>>>;
|
||||
const _array_n_array_string: Array<Nullable<Array<string>>>;
|
||||
const _fun_n_int_unit: (p0: Nullable<number>) => void;
|
||||
const _fun_n_boolean_n_int_n_string_n_intarray: (p0: Nullable<boolean>, p1: Nullable<number>, p2: Nullable<string>) => Nullable<Int32Array>;
|
||||
const _n_curried_fun: (p0: Nullable<number>) => (p0: Nullable<number>) => (p0: Nullable<number>) => Nullable<number>;
|
||||
const _n_higher_order_fun: (p0: (p0: Nullable<number>) => Nullable<string>, p1: (p0: Nullable<string>) => Nullable<number>) => (p0: Nullable<number>) => Nullable<number>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// CHECK_TYPESCRIPT_DECLARATIONS
|
||||
// RUN_PLAIN_BOX_FUNCTION
|
||||
|
||||
@file:JsExport
|
||||
|
||||
package foo
|
||||
|
||||
val _any: Any = Any()
|
||||
|
||||
val _unit: Unit = Unit
|
||||
|
||||
fun _nothing(): Nothing { throw Throwable() }
|
||||
|
||||
val _throwable: Throwable = Throwable()
|
||||
|
||||
val _string: String = "ZZZ"
|
||||
|
||||
val _boolean: Boolean = true
|
||||
|
||||
val _byte: Byte = 1.toByte()
|
||||
val _short: Short = 1.toShort()
|
||||
val _int: Int = 1
|
||||
val _float: Float = 1.0f
|
||||
val _double: Double = 1.0
|
||||
// TODO: Char and Long
|
||||
|
||||
val _byte_array: ByteArray = byteArrayOf()
|
||||
val _short_array: ShortArray = shortArrayOf()
|
||||
val _int_array: IntArray = intArrayOf()
|
||||
val _float_array: FloatArray = floatArrayOf()
|
||||
val _double_array: DoubleArray = doubleArrayOf()
|
||||
|
||||
val _array_byte: Array<Byte> = emptyArray()
|
||||
val _array_short: Array<Short> = emptyArray()
|
||||
val _array_int: Array<Int> = emptyArray()
|
||||
val _array_float: Array<Float> = emptyArray()
|
||||
val _array_double: Array<Double> = emptyArray()
|
||||
val _array_string: Array<String> = emptyArray()
|
||||
val _array_boolean: Array<Boolean> = emptyArray()
|
||||
val _array_array_string: Array<Array<String>> = arrayOf(emptyArray())
|
||||
val _array_array_int_array: Array<Array<IntArray>> = arrayOf(arrayOf(intArrayOf()))
|
||||
|
||||
val _fun_unit: () -> Unit = { }
|
||||
val _fun_int_unit: (Int) -> Unit = { x -> }
|
||||
|
||||
val _fun_boolean_int_string_intarray: (Boolean, Int, String) -> IntArray =
|
||||
{ b, i, s -> intArrayOf(b.toString().length, i, s.length) }
|
||||
|
||||
val _curried_fun: (Int) -> (Int) -> (Int) -> (Int) -> (Int) -> Int =
|
||||
{ x1 -> { x2 -> { x3 -> { x4 -> { x5 -> x1 + x2 + x3 + x4 + x5 } } } } }
|
||||
|
||||
val _higher_order_fun: ((Int) -> String, (String) -> Int) -> ((Int) -> Int) =
|
||||
{ f1, f2 -> { x -> f2(f1(x)) } }
|
||||
|
||||
|
||||
// Nullable types
|
||||
|
||||
val _n_any: Any? = Any()
|
||||
|
||||
// TODO:
|
||||
// val _n_unit: Unit? = Unit
|
||||
|
||||
val _n_nothing: Nothing? = null
|
||||
|
||||
val _n_throwable: Throwable? = Throwable()
|
||||
|
||||
val _n_string: String? = "ZZZ"
|
||||
|
||||
val _n_boolean: Boolean? = true
|
||||
|
||||
val _n_byte: Byte? = 1.toByte()
|
||||
|
||||
// TODO: Char and Long
|
||||
|
||||
val _n_short_array: ShortArray? = shortArrayOf()
|
||||
|
||||
val _n_array_int: Array<Int>? = emptyArray()
|
||||
val _array_n_int: Array<Int?> = emptyArray()
|
||||
val _n_array_n_int: Array<Int?>? = emptyArray()
|
||||
|
||||
val _array_n_array_string: Array<Array<String>?> = arrayOf(arrayOf(":)"))
|
||||
|
||||
val _fun_n_int_unit: (Int?) -> Unit = { x -> }
|
||||
|
||||
val _fun_n_boolean_n_int_n_string_n_intarray: (Boolean?, Int?, String?) -> IntArray? =
|
||||
{ b, i, s -> null }
|
||||
|
||||
val _n_curried_fun: (Int?) -> (Int?) -> (Int?) -> Int? =
|
||||
{ x1 -> { x2 -> { x3 -> (x1 ?: 0) + (x2 ?: 0) + (x3 ?: 0) } } }
|
||||
|
||||
val _n_higher_order_fun: ((Int?) -> String?, (String?) -> Int?) -> ((Int?) -> Int?) =
|
||||
{ f1, f2 -> { x -> f2(f1(x)) } }
|
||||
@@ -0,0 +1,58 @@
|
||||
"use strict";
|
||||
var foo = JS_TESTS.foo;
|
||||
function assert(condition) {
|
||||
if (!condition) {
|
||||
throw "Assertion failed";
|
||||
}
|
||||
}
|
||||
assert(typeof foo._any === "object");
|
||||
assert(foo._string === "ZZZ");
|
||||
assert(foo._boolean === true);
|
||||
assert(foo._byte === 1);
|
||||
assert(foo._short === 1);
|
||||
assert(foo._float === 1);
|
||||
assert(foo._double === 1);
|
||||
assert(foo._byte_array instanceof Int8Array);
|
||||
assert(foo._short_array instanceof Int16Array);
|
||||
assert(foo._int_array instanceof Int32Array);
|
||||
assert(foo._float_array instanceof Float32Array);
|
||||
assert(foo._double_array instanceof Float64Array);
|
||||
assert(foo._array_byte instanceof Array);
|
||||
assert(foo._array_short instanceof Array);
|
||||
assert(foo._array_int instanceof Array);
|
||||
assert(foo._array_float instanceof Array);
|
||||
assert(foo._array_double instanceof Array);
|
||||
assert(foo._array_string instanceof Array);
|
||||
assert(foo._array_boolean instanceof Array);
|
||||
assert(foo._array_array_string instanceof Array);
|
||||
assert(foo._array_array_string[0] instanceof Array);
|
||||
assert(foo._array_array_int_array instanceof Array);
|
||||
assert(foo._array_array_int_array[0] instanceof Array);
|
||||
assert(foo._array_array_int_array[0][0] instanceof Int32Array);
|
||||
foo._fun_unit();
|
||||
foo._fun_int_unit(10);
|
||||
assert(foo._fun_boolean_int_string_intarray(true, 20, "A") instanceof Int32Array);
|
||||
assert(foo._curried_fun(1)(2)(3)(4)(5) == 15);
|
||||
assert(foo._higher_order_fun(function (n) { return String(n); }, function (s) { return s.length; })(1000) == 4);
|
||||
assert(foo._n_any != null);
|
||||
assert(foo._n_nothing == null);
|
||||
assert(foo._n_throwable instanceof Error);
|
||||
assert(foo._n_string === "ZZZ");
|
||||
assert(foo._n_boolean === true);
|
||||
assert(foo._n_byte === 1);
|
||||
assert(foo._n_short_array instanceof Int16Array);
|
||||
assert(foo._n_array_int instanceof Array);
|
||||
assert(foo._array_n_int instanceof Array);
|
||||
assert(foo._n_array_n_int instanceof Array);
|
||||
assert(foo._array_n_array_string instanceof Array);
|
||||
var x = foo._array_n_array_string[0];
|
||||
assert(x != null);
|
||||
assert(x instanceof Array);
|
||||
assert(x == null ? false : (x[0] === ":)"));
|
||||
foo._fun_n_int_unit(null);
|
||||
assert(foo._fun_n_boolean_n_int_n_string_n_intarray(false, undefined, "ZZZ") == null);
|
||||
assert(foo._n_curried_fun(10)(null)(30) === 40);
|
||||
assert(foo._n_higher_order_fun(function (n) { return String(n); }, function (s) { return (s == null ? 10 : s.length); })(1000) === 4);
|
||||
function box() {
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import foo = JS_TESTS.foo;
|
||||
|
||||
function assert(condition: boolean) {
|
||||
if (!condition) {
|
||||
throw "Assertion failed";
|
||||
}
|
||||
}
|
||||
|
||||
assert(typeof foo._any === "object");
|
||||
assert(foo._string === "ZZZ");
|
||||
assert(foo._boolean === true);
|
||||
assert(foo._byte === 1);
|
||||
assert(foo._short === 1);
|
||||
assert(foo._float === 1);
|
||||
assert(foo._double === 1);
|
||||
assert(foo._byte_array instanceof Int8Array);
|
||||
assert(foo._short_array instanceof Int16Array);
|
||||
assert(foo._int_array instanceof Int32Array);
|
||||
assert(foo._float_array instanceof Float32Array);
|
||||
assert(foo._double_array instanceof Float64Array);
|
||||
assert(foo._array_byte instanceof Array);
|
||||
assert(foo._array_short instanceof Array);
|
||||
assert(foo._array_int instanceof Array);
|
||||
assert(foo._array_float instanceof Array);
|
||||
assert(foo._array_double instanceof Array);
|
||||
assert(foo._array_string instanceof Array);
|
||||
assert(foo._array_boolean instanceof Array);
|
||||
|
||||
assert(foo._array_array_string instanceof Array);
|
||||
assert(foo._array_array_string[0] instanceof Array);
|
||||
|
||||
assert(foo._array_array_int_array instanceof Array);
|
||||
assert(foo._array_array_int_array[0] instanceof Array);
|
||||
assert(foo._array_array_int_array[0][0] instanceof Int32Array);
|
||||
|
||||
foo._fun_unit();
|
||||
foo._fun_int_unit(10);
|
||||
assert(foo._fun_boolean_int_string_intarray(true, 20, "A") instanceof Int32Array);
|
||||
assert(foo._curried_fun(1)(2)(3)(4)(5) == 15);
|
||||
assert(foo._higher_order_fun((n) => String(n), (s) => s.length)(1000) == 4);
|
||||
assert(foo._n_any != null);
|
||||
assert(foo._n_nothing == null);
|
||||
assert(foo._n_throwable instanceof Error);
|
||||
assert(foo._n_string === "ZZZ");
|
||||
assert(foo._n_boolean === true);
|
||||
assert(foo._n_byte === 1);
|
||||
assert(foo._n_short_array instanceof Int16Array);
|
||||
assert(foo._n_array_int instanceof Array);
|
||||
assert(foo._array_n_int instanceof Array);
|
||||
assert(foo._n_array_n_int instanceof Array);
|
||||
|
||||
assert(foo._array_n_array_string instanceof Array);
|
||||
let x = foo._array_n_array_string[0];
|
||||
assert(x != null);
|
||||
assert(x instanceof Array);
|
||||
assert(x == null ? false : (x[0] === ":)"));
|
||||
|
||||
foo._fun_n_int_unit(null);
|
||||
|
||||
assert(foo._fun_n_boolean_n_int_n_string_n_intarray(false, undefined, "ZZZ") == null);
|
||||
assert(foo._n_curried_fun(10)(null)(30) === 40);
|
||||
assert(foo._n_higher_order_fun(
|
||||
n => String(n),
|
||||
s => (s == null ? 10 : s.length)
|
||||
)(1000) === 4);
|
||||
|
||||
function box(): string {
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"include": [ "./*" ],
|
||||
"extends": "../common.tsconfig.json"
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
declare namespace JS_TESTS {
|
||||
type Nullable<T> = T | null | undefined
|
||||
namespace foo {
|
||||
interface ExportedInternalInterface {
|
||||
}
|
||||
}
|
||||
namespace foo {
|
||||
interface FileLevelExportedExternalInterface {
|
||||
}
|
||||
}
|
||||
namespace foo {
|
||||
const exportedVal: number;
|
||||
function exportedFun(): number
|
||||
class ExportedClass {
|
||||
constructor()
|
||||
readonly value: number;
|
||||
}
|
||||
}
|
||||
namespace foo {
|
||||
const fileLevelExportedVal: number;
|
||||
function fileLevelExportedFun(): number
|
||||
class FileLevelExportedClass {
|
||||
constructor()
|
||||
readonly value: number;
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// CHECK_TYPESCRIPT_DECLARATIONS
|
||||
// RUN_PLAIN_BOX_FUNCTION
|
||||
|
||||
// FILE: file1.kt
|
||||
package foo
|
||||
|
||||
@JsExport
|
||||
val exportedVal = 10
|
||||
|
||||
@JsExport
|
||||
fun exportedFun() = 10
|
||||
|
||||
@JsExport
|
||||
class ExportedClass {
|
||||
val value = 10
|
||||
}
|
||||
|
||||
@JsExport
|
||||
external interface ExportedInternalInterface
|
||||
|
||||
val _val = 10
|
||||
|
||||
fun _fun() = 10
|
||||
|
||||
class Class
|
||||
|
||||
external interface ExternalInterface
|
||||
|
||||
// FILE: file2.kt
|
||||
|
||||
@file:JsExport
|
||||
|
||||
package foo
|
||||
|
||||
val fileLevelExportedVal = 10
|
||||
fun fileLevelExportedFun() = 10
|
||||
class FileLevelExportedClass {
|
||||
val value = 10
|
||||
}
|
||||
external interface FileLevelExportedExternalInterface
|
||||
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
"use strict";
|
||||
var foo = JS_TESTS.foo;
|
||||
function box() {
|
||||
var tens = [
|
||||
foo.exportedVal,
|
||||
foo.exportedFun(),
|
||||
new foo.ExportedClass().value,
|
||||
foo.fileLevelExportedVal,
|
||||
foo.fileLevelExportedFun(),
|
||||
new foo.FileLevelExportedClass().value
|
||||
];
|
||||
if (tens.every(function (value) { return value === 10; }))
|
||||
return "OK";
|
||||
return "FAIL";
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import foo = JS_TESTS.foo;
|
||||
|
||||
function box(): string {
|
||||
const tens: number[] = [
|
||||
foo.exportedVal,
|
||||
foo.exportedFun(),
|
||||
new foo.ExportedClass().value,
|
||||
foo.fileLevelExportedVal,
|
||||
foo.fileLevelExportedFun(),
|
||||
new foo.FileLevelExportedClass().value
|
||||
];
|
||||
|
||||
if (tens.every((value) => value === 10))
|
||||
return "OK";
|
||||
|
||||
return "FAIL";
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"include": [ "./*" ],
|
||||
"extends": "../common.tsconfig.json"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"include": [ "./*" ],
|
||||
"extends": "../common.tsconfig.json"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
declare namespace JS_TESTS {
|
||||
type Nullable<T> = T | null | undefined
|
||||
interface publicInterface {
|
||||
}
|
||||
const publicVal: number;
|
||||
function publicFun(): number
|
||||
class publicClass {
|
||||
constructor()
|
||||
}
|
||||
class Class {
|
||||
constructor()
|
||||
readonly publicVal: number;
|
||||
publicFun(): number
|
||||
}
|
||||
namespace Class {
|
||||
class publicClass {
|
||||
constructor()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// CHECK_TYPESCRIPT_DECLARATIONS
|
||||
// RUN_PLAIN_BOX_FUNCTION
|
||||
|
||||
@file:JsExport
|
||||
|
||||
internal val internalVal = 10
|
||||
internal fun internalFun() = 10
|
||||
internal class internalClass
|
||||
internal external interface internalInterface
|
||||
|
||||
private val privateVal = 10
|
||||
private fun privateFun() = 10
|
||||
private class privateClass
|
||||
private external interface privateInterface
|
||||
|
||||
public val publicVal = 10
|
||||
public fun publicFun() = 10
|
||||
public class publicClass
|
||||
public external interface publicInterface
|
||||
|
||||
open class Class {
|
||||
internal val internalVal = 10
|
||||
internal fun internalFun() = 10
|
||||
internal class internalClass
|
||||
|
||||
private val privateVal = 10
|
||||
private fun privateFun() = 10
|
||||
private class privateClass
|
||||
|
||||
protected val protectedVal = 10
|
||||
protected fun protectedFun() = 10
|
||||
protected class protectedClass
|
||||
|
||||
public val publicVal = 10
|
||||
public fun publicFun() = 10
|
||||
public class publicClass
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
var Class = JS_TESTS.Class;
|
||||
function box() {
|
||||
var tens = [
|
||||
JS_TESTS.publicVal,
|
||||
JS_TESTS.publicFun(),
|
||||
new JS_TESTS.Class().publicVal,
|
||||
new JS_TESTS.Class().publicFun()
|
||||
];
|
||||
if (!tens.every(function (value) { return value === 10; }))
|
||||
return "Fail 1";
|
||||
if (!(new Class() instanceof Class))
|
||||
return "Fail 2";
|
||||
if (!(new Class.publicClass() instanceof Class.publicClass))
|
||||
return "Fail 3";
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import Class = JS_TESTS.Class;
|
||||
|
||||
function box(): string {
|
||||
const tens: number[] = [
|
||||
JS_TESTS.publicVal,
|
||||
JS_TESTS.publicFun(),
|
||||
new JS_TESTS.Class().publicVal,
|
||||
new JS_TESTS.Class().publicFun()
|
||||
];
|
||||
|
||||
if (!tens.every(value => value === 10))
|
||||
return "Fail 1";
|
||||
if (!(new Class() instanceof Class))
|
||||
return "Fail 2";
|
||||
if (!(new Class.publicClass() instanceof Class.publicClass))
|
||||
return "Fail 3";
|
||||
return "OK";
|
||||
}
|
||||
Reference in New Issue
Block a user