From dbda8dcad1ad0456b8e46646bb31df082ce2f111 Mon Sep 17 00:00:00 2001 From: Artem Kobzar Date: Fri, 26 Aug 2022 09:51:59 +0000 Subject: [PATCH] [K/JS] test: add @file:JsExport tests for each @JsExport test + auto-generate TypeScript export tests. --- .../backend/js/export/ExportModelGenerator.kt | 6 + .../nonConsumableIdentifiersInExportedFile.kt | 34 ++ ...nonConsumableIdentifiersInExportedFile.txt | 58 +++ ...yConstructorWithoutJsNameInExportedFile.kt | 14 + ...ConstructorWithoutJsNameInExportedFile.txt | 22 ++ .../DiagnosticsTestWithJsStdLibGenerated.java | 12 + js/js.tests/build.gradle.kts | 36 ++ .../kotlin/js/test/BoxJsTestGenerated.java | 66 ++++ .../kotlin/js/test/ir/FirJsTestGenerated.java | 72 ++++ .../js/test/ir/IrBoxJsTestGenerated.java | 72 ++++ .../ir/IrJsTypeScriptExportTestGenerated.java | 330 +++++++++++++++++- .../bridgeSavingAfterExportInExportedFile.kt | 28 ++ ...lineClassConstructorParamInExportedFile.kt | 20 ++ .../export/exportFileWithClassWithInternal.kt | 32 ++ .../box/export/exportFileWithEnumClass.kt | 98 ++++++ .../box/export/exportFileWithInterface.kt | 96 +++++ .../box/export/exportFileWithNestedClass.kt | 47 +++ .../box/export/exportFileWithNestedObject.kt | 72 ++++ .../export/exportFileWithProtectedMembers.kt | 66 ++++ .../nonIndetifierModuleNameInExportedFile.kt | 17 + ...hainNonExportIntermediateInExportedFile.kt | 41 +++ ...dWithSameStableNameMethodInExportedFile.kt | 45 +++ .../reservedModuleNameInExportedFile.kt | 17 + .../abstract-classes.d.ts | 19 + .../abstract-classes.kt | 24 ++ .../abstract-classes__main.js | 14 + .../abstract-classes__main.ts | 17 + .../tsconfig.json | 0 .../constructors.d.ts | 37 ++ .../constructors.kt | 76 ++++ .../constructors__main.js | 38 ++ .../constructors__main.ts | 52 +++ .../tsconfig.json | 4 + .../constructors/constructors.kt | 8 +- .../data-classes.d.ts | 31 ++ .../data-classes.kt | 27 ++ .../data-classes__main.js | 35 ++ .../data-classes__main.ts | 45 +++ .../tsconfig.json | 4 + .../enum-classes.d.ts | 50 +++ .../enum-classes.kt | 38 ++ .../enum-classes__main.js | 36 ++ .../enum-classes__main.ts | 45 +++ .../tsconfig.json | 4 + .../escaped-declarations.d.ts | 34 ++ .../escaped-declarations.kt | 58 +++ .../escaped-declarations__main.js | 29 ++ .../escaped-declarations__main.ts | 37 ++ .../tsconfig.json | 4 + .../escaped-declarations.kt | 10 +- .../functions-in-exported-file/functions.d.ts | 22 ++ .../functions-in-exported-file/functions.kt | 67 ++++ .../functions__main.js | 59 ++++ .../functions__main.ts | 58 +++ .../functions-in-exported-file/tsconfig.json | 4 + .../functions/functions.d.ts | 6 +- .../typescript-export/functions/functions.kt | 5 +- .../inner-class.d.ts | 30 ++ .../inner-class.kt | 29 ++ .../inner-class__main.js | 24 ++ .../inner-class__main.ts | 30 ++ .../tsconfig.json | 4 + .../interfaces.d.ts | 28 ++ .../interfaces-in-exported-file/interfaces.kt | 37 ++ .../interfaces__main.js | 16 + .../interfaces__main.ts | 19 + .../interfaces-in-exported-file/tsconfig.json | 3 + .../js-name-in-exported-file/js-name.d.ts | 26 ++ .../js-name-in-exported-file/js-name.kt | 52 +++ .../js-name-in-exported-file/js-name__main.js | 16 + .../js-name-in-exported-file/js-name__main.ts | 21 ++ .../js-name-in-exported-file/tsconfig.json | 3 + .../typescript-export/js-name/js-name.d.ts | 7 +- .../typescript-export/js-name/js-name.kt | 1 + .../member-properties.d.ts | 17 + .../member-properties.kt | 34 ++ .../member-properties__main.js | 23 ++ .../member-properties__main.ts | 27 ++ .../tsconfig.json | 4 + .../methods-in-exported-file/methods.d.ts | 25 ++ .../methods-in-exported-file/methods.kt | 57 +++ .../methods-in-exported-file/methods__main.js | 48 +++ .../methods-in-exported-file/methods__main.ts | 46 +++ .../methods-in-exported-file/tsconfig.json | 4 + .../typescript-export/methods/methods.d.ts | 6 +- .../typescript-export/methods/methods.kt | 5 +- .../commonjs.d.ts | 10 + .../commonjs.kt | 24 ++ .../plain.d.ts | 12 + .../module-systems-in-exported-file/plain.kt | 23 ++ .../tsconfig.json | 0 .../module-systems-in-exported-file/umd.d.ts | 11 + .../module-systems-in-exported-file/umd.kt | 24 ++ .../module-systems/commonjs.kt | 5 +- .../typescript-export/module-systems/plain.kt | 5 +- .../typescript-export/module-systems/umd.kt | 5 +- .../namespaces.d.ts | 37 ++ .../namespaces-in-exported-file/namespaces.kt | 56 +++ .../namespaces__main.js | 19 + .../namespaces__main.ts | 24 ++ .../namespaces-in-exported-file/tsconfig.json | 4 + .../namespaces/namespaces.kt | 6 +- .../objects-in-exported-file/objects.d.ts | 46 +++ .../objects-in-exported-file/objects.kt | 58 +++ .../objects-in-exported-file/objects__main.js | 31 ++ .../objects-in-exported-file/objects__main.ts | 34 ++ .../objects-in-exported-file/tsconfig.json | 4 + .../primitives.d.ts | 49 +++ .../primitives-in-exported-file/primitives.kt | 142 ++++++++ .../primitives__main.js | 58 +++ .../primitives__main.ts | 69 ++++ .../primitives-in-exported-file/tsconfig.json | 4 + .../primitives/primitives.kt | 47 ++- .../properties.d.ts | 12 + .../properties-in-exported-file/properties.kt | 40 +++ .../properties__main.js | 27 ++ .../properties__main.ts | 33 ++ .../properties-in-exported-file/tsconfig.json | 4 + .../regular-classes.d.ts | 42 +++ .../regular-classes.kt | 47 +++ .../regular-classes__main.js | 26 ++ .../regular-classes__main.ts | 28 ++ .../tsconfig.json | 4 + .../sealed-classes.d.ts | 19 + .../sealed-classes.kt | 24 ++ .../sealed-classes__main.js | 14 + .../sealed-classes__main.ts | 16 + .../tsconfig.json | 4 + .../strict-implicit-export.d.ts} | 0 .../strict-implicit-export.kt} | 0 .../strict-implicit-export__main.js} | 0 .../strict-implicit-export__main.ts} | 0 .../strict-implicit-export/tsconfig.json | 4 + .../visibility-in-exported-file/tsconfig.json | 4 + .../visibility.d.ts | 49 +++ .../visibility-in-exported-file/visibility.kt | 78 +++++ .../visibility__main.js | 17 + .../visibility__main.ts | 18 + .../visibility/visibility.kt | 16 +- 139 files changed, 4242 insertions(+), 31 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.kt create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.txt create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.kt create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.txt create mode 100644 js/js.translator/testData/box/export/bridgeSavingAfterExportInExportedFile.kt create mode 100644 js/js.translator/testData/box/export/defaultInlineClassConstructorParamInExportedFile.kt create mode 100644 js/js.translator/testData/box/export/exportFileWithClassWithInternal.kt create mode 100644 js/js.translator/testData/box/export/exportFileWithEnumClass.kt create mode 100644 js/js.translator/testData/box/export/exportFileWithInterface.kt create mode 100644 js/js.translator/testData/box/export/exportFileWithNestedClass.kt create mode 100644 js/js.translator/testData/box/export/exportFileWithNestedObject.kt create mode 100644 js/js.translator/testData/box/export/exportFileWithProtectedMembers.kt create mode 100644 js/js.translator/testData/box/export/nonIndetifierModuleNameInExportedFile.kt create mode 100644 js/js.translator/testData/box/export/overriddenChainNonExportIntermediateInExportedFile.kt create mode 100644 js/js.translator/testData/box/export/overriddenExternalMethodWithSameStableNameMethodInExportedFile.kt create mode 100644 js/js.translator/testData/box/export/reservedModuleNameInExportedFile.kt create mode 100644 js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes.d.ts create mode 100644 js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes.kt create mode 100644 js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes__main.js create mode 100644 js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes__main.ts rename js/js.translator/testData/typescript-export/{strictImplicitExport => abstract-classes-in-exported-file}/tsconfig.json (100%) create mode 100644 js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors.d.ts create mode 100644 js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors.kt create mode 100644 js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors__main.js create mode 100644 js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors__main.ts create mode 100644 js/js.translator/testData/typescript-export/constructors-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes.d.ts create mode 100644 js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes.kt create mode 100644 js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes__main.js create mode 100644 js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes__main.ts create mode 100644 js/js.translator/testData/typescript-export/data-classes-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes.d.ts create mode 100644 js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes.kt create mode 100644 js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes__main.js create mode 100644 js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes__main.ts create mode 100644 js/js.translator/testData/typescript-export/enum-classes-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations.d.ts create mode 100644 js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations.kt create mode 100644 js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations__main.js create mode 100644 js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations__main.ts create mode 100644 js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/functions-in-exported-file/functions.d.ts create mode 100644 js/js.translator/testData/typescript-export/functions-in-exported-file/functions.kt create mode 100644 js/js.translator/testData/typescript-export/functions-in-exported-file/functions__main.js create mode 100644 js/js.translator/testData/typescript-export/functions-in-exported-file/functions__main.ts create mode 100644 js/js.translator/testData/typescript-export/functions-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class.d.ts create mode 100644 js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class.kt create mode 100644 js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class__main.js create mode 100644 js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class__main.ts create mode 100644 js/js.translator/testData/typescript-export/inner-classes-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.d.ts create mode 100644 js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt create mode 100644 js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.js create mode 100644 js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.ts create mode 100644 js/js.translator/testData/typescript-export/interfaces-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name.d.ts create mode 100644 js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name.kt create mode 100644 js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name__main.js create mode 100644 js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name__main.ts create mode 100644 js/js.translator/testData/typescript-export/js-name-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties.d.ts create mode 100644 js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties.kt create mode 100644 js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties__main.js create mode 100644 js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties__main.ts create mode 100644 js/js.translator/testData/typescript-export/member-properties-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/methods-in-exported-file/methods.d.ts create mode 100644 js/js.translator/testData/typescript-export/methods-in-exported-file/methods.kt create mode 100644 js/js.translator/testData/typescript-export/methods-in-exported-file/methods__main.js create mode 100644 js/js.translator/testData/typescript-export/methods-in-exported-file/methods__main.ts create mode 100644 js/js.translator/testData/typescript-export/methods-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/module-systems-in-exported-file/commonjs.d.ts create mode 100644 js/js.translator/testData/typescript-export/module-systems-in-exported-file/commonjs.kt create mode 100644 js/js.translator/testData/typescript-export/module-systems-in-exported-file/plain.d.ts create mode 100644 js/js.translator/testData/typescript-export/module-systems-in-exported-file/plain.kt create mode 100644 js/js.translator/testData/typescript-export/module-systems-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/module-systems-in-exported-file/umd.d.ts create mode 100644 js/js.translator/testData/typescript-export/module-systems-in-exported-file/umd.kt create mode 100644 js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces.d.ts create mode 100644 js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces.kt create mode 100644 js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces__main.js create mode 100644 js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces__main.ts create mode 100644 js/js.translator/testData/typescript-export/namespaces-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/objects-in-exported-file/objects.d.ts create mode 100644 js/js.translator/testData/typescript-export/objects-in-exported-file/objects.kt create mode 100644 js/js.translator/testData/typescript-export/objects-in-exported-file/objects__main.js create mode 100644 js/js.translator/testData/typescript-export/objects-in-exported-file/objects__main.ts create mode 100644 js/js.translator/testData/typescript-export/objects-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives.d.ts create mode 100644 js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives.kt create mode 100644 js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives__main.js create mode 100644 js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives__main.ts create mode 100644 js/js.translator/testData/typescript-export/primitives-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/properties-in-exported-file/properties.d.ts create mode 100644 js/js.translator/testData/typescript-export/properties-in-exported-file/properties.kt create mode 100644 js/js.translator/testData/typescript-export/properties-in-exported-file/properties__main.js create mode 100644 js/js.translator/testData/typescript-export/properties-in-exported-file/properties__main.ts create mode 100644 js/js.translator/testData/typescript-export/properties-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes.d.ts create mode 100644 js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes.kt create mode 100644 js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes__main.js create mode 100644 js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes__main.ts create mode 100644 js/js.translator/testData/typescript-export/regular-classes-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes.d.ts create mode 100644 js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes.kt create mode 100644 js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes__main.js create mode 100644 js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes__main.ts create mode 100644 js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/tsconfig.json rename js/js.translator/testData/typescript-export/{strictImplicitExport/declarations.d.ts => strict-implicit-export/strict-implicit-export.d.ts} (100%) rename js/js.translator/testData/typescript-export/{strictImplicitExport/declarations.kt => strict-implicit-export/strict-implicit-export.kt} (100%) rename js/js.translator/testData/typescript-export/{strictImplicitExport/declarations__main.js => strict-implicit-export/strict-implicit-export__main.js} (100%) rename js/js.translator/testData/typescript-export/{strictImplicitExport/declarations__main.ts => strict-implicit-export/strict-implicit-export__main.ts} (100%) create mode 100644 js/js.translator/testData/typescript-export/strict-implicit-export/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/visibility-in-exported-file/tsconfig.json create mode 100644 js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility.d.ts create mode 100644 js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility.kt create mode 100644 js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility__main.js create mode 100644 js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility__main.ts diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt index b1c0f38fd40..f02ad939b1c 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/export/ExportModelGenerator.kt @@ -719,6 +719,12 @@ private fun shouldDeclarationBeExportedImplicitlyOrExplicitly(declaration: IrDec } private fun shouldDeclarationBeExported(declaration: IrDeclarationWithName, context: JsIrBackendContext): Boolean { + // Formally, user have no ability to annotate EnumEntry as exported, without Enum Class + // But, when we add @file:JsExport, the annotation appears on the all of enum entries + // what make a wrong behaviour on non-exported members inside Enum Entry (check exportEnumClass and exportFileWithEnumClass tests) + if (declaration is IrClass && declaration.kind == ClassKind.ENUM_ENTRY) + return false + if (context.additionalExportedDeclarationNames.contains(declaration.fqNameWhenAvailable)) return true diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.kt new file mode 100644 index 00000000000..1e646c5168e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.kt @@ -0,0 +1,34 @@ +// !OPT_IN: kotlin.js.ExperimentalJsExport +// !RENDER_DIAGNOSTICS_MESSAGES +@file:JsExport + +package foo + +fun delete() {} + +val instanceof = 4 + +class eval + +@JsName("await") +fun foo() {} + +@JsName("this") +val bar = 4 + +@JsName("super") +class Baz + +class Test { + fun instanceof() {} + + @JsName("eval") + fun test() {} +} + +object NaN + +enum class Nums { + Infinity, + undefined +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.txt b/compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.txt new file mode 100644 index 00000000000..8d9d96e0eb5 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.txt @@ -0,0 +1,58 @@ +package + +package foo { + @kotlin.js.JsName(name = "this") public val bar: kotlin.Int = 4 + public val instanceof: kotlin.Int = 4 + public fun delete(): kotlin.Unit + @kotlin.js.JsName(name = "await") public fun foo(): kotlin.Unit + + @kotlin.js.JsName(name = "super") public final class Baz { + public constructor Baz() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public object NaN { + private constructor NaN() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final enum class Nums : kotlin.Enum { + enum entry Infinity + + enum entry undefined + + private constructor Nums() + @kotlin.internal.IntrinsicConstEvaluation public final override /*1*/ /*fake_override*/ val name: kotlin.String + public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int + protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: foo.Nums): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ val entries: kotlin.enums.EnumEntries + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): foo.Nums + public final /*synthesized*/ fun values(): kotlin.Array + } + + public final class Test { + public constructor Test() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun instanceof(): kotlin.Unit + @kotlin.js.JsName(name = "eval") public final fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final class eval { + public constructor eval() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.kt b/compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.kt new file mode 100644 index 00000000000..ad44f0843f1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.kt @@ -0,0 +1,14 @@ +// !OPT_IN: kotlin.js.ExperimentalJsExport +// !RENDER_DIAGNOSTICS_MESSAGES +@file:JsExport + +package foo + +class C(val x: String) { + constructor(x: Int): this(x.toString()) +} + +class C2(val x: String) { + @JsName("JsNameProvided") + constructor(x: Int): this(x.toString()) +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.txt b/compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.txt new file mode 100644 index 00000000000..c362f0317bb --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.txt @@ -0,0 +1,22 @@ +package + +package foo { + + public final class C { + public constructor C(/*0*/ x: kotlin.Int) + public constructor C(/*0*/ x: kotlin.String) + public final val x: kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final class C2 { + @kotlin.js.JsName(name = "JsNameProvided") public constructor C2(/*0*/ x: kotlin.Int) + public constructor C2(/*0*/ x: kotlin.String) + public final val x: kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticsTestWithJsStdLibGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticsTestWithJsStdLibGenerated.java index 8f13c7374be..1e8231e5129 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticsTestWithJsStdLibGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticsTestWithJsStdLibGenerated.java @@ -413,12 +413,24 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes runTest("compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiers.kt"); } + @Test + @TestMetadata("nonConsumableIdentifiersInExportedFile.kt") + public void testNonConsumableIdentifiersInExportedFile() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLib/export/nonConsumableIdentifiersInExportedFile.kt"); + } + @Test @TestMetadata("secondaryConstructorWithoutJsName.kt") public void testSecondaryConstructorWithoutJsName() throws Exception { runTest("compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsName.kt"); } + @Test + @TestMetadata("secondaryConstructorWithoutJsNameInExportedFile.kt") + public void testSecondaryConstructorWithoutJsNameInExportedFile() throws Exception { + runTest("compiler/testData/diagnostics/testsWithJsStdLib/export/secondaryConstructorWithoutJsNameInExportedFile.kt"); + } + @Test @TestMetadata("unexportableTypesInSignature.kt") public void testUnexportableTypesInSignature() throws Exception { diff --git a/js/js.tests/build.gradle.kts b/js/js.tests/build.gradle.kts index c52f934e360..ab06524b40f 100644 --- a/js/js.tests/build.gradle.kts +++ b/js/js.tests/build.gradle.kts @@ -156,6 +156,41 @@ val unzipJsShell by task { val testDataDir = project(":js:js.translator").projectDir.resolve("testData") val typescriptTestsDir = testDataDir.resolve("typescript-export") +val generateJsExportOnFileTestFilesForTS by task { + val exportFileDirPostfix = "-in-exported-file" + + from(typescriptTestsDir) { + include("**/*.kt") + include("**/*.ts") + include("**/tsconfig.json") + exclude("selective-export/*") + exclude("implicit-export/*") + exclude("inheritance/*") + exclude("strict-implicit-export/*") + exclude("*$exportFileDirPostfix") + + eachFile { + path = "${relativePath.parent}$exportFileDirPostfix/$name" + + var isFirstLine = true + filter { + when { + isFirstLine && name.endsWith(".kt") -> "/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */\n\n$it" + .also { isFirstLine = false } + + it.contains("// FILE") -> "$it\n\n@file:JsExport" + else -> it.replace("@JsExport", "") + } + } + + } + + } + + into(typescriptTestsDir) +} + + val installTsDependencies = task("installTsDependencies") { workingDir.set(testDataDir) args.set(listOf("install")) @@ -314,6 +349,7 @@ testsJar {} val generateTests by generator("org.jetbrains.kotlin.generators.tests.GenerateJsTestsKt") { dependsOn(":compiler:generateTestData") + dependsOn(generateJsExportOnFileTestFilesForTS) } val prepareMochaTestData by tasks.registering(Copy::class) { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java index 1816180f0de..aff2a10d0fe 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java @@ -2100,6 +2100,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/export/defaultInlineClassConstructorParam.kt"); } + @Test + @TestMetadata("defaultInlineClassConstructorParamInExportedFile.kt") + public void testDefaultInlineClassConstructorParamInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/defaultInlineClassConstructorParamInExportedFile.kt"); + } + @Test @TestMetadata("exportAllFile.kt") public void testExportAllFile() throws Exception { @@ -2124,6 +2130,42 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/export/exportEnumClass.kt"); } + @Test + @TestMetadata("exportFileWithClassWithInternal.kt") + public void testExportFileWithClassWithInternal() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithClassWithInternal.kt"); + } + + @Test + @TestMetadata("exportFileWithEnumClass.kt") + public void testExportFileWithEnumClass() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithEnumClass.kt"); + } + + @Test + @TestMetadata("exportFileWithInterface.kt") + public void testExportFileWithInterface() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithInterface.kt"); + } + + @Test + @TestMetadata("exportFileWithNestedClass.kt") + public void testExportFileWithNestedClass() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithNestedClass.kt"); + } + + @Test + @TestMetadata("exportFileWithNestedObject.kt") + public void testExportFileWithNestedObject() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithNestedObject.kt"); + } + + @Test + @TestMetadata("exportFileWithProtectedMembers.kt") + public void testExportFileWithProtectedMembers() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithProtectedMembers.kt"); + } + @Test @TestMetadata("exportInnerClass.kt") public void testExportInnerClass() throws Exception { @@ -2160,12 +2202,24 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/export/nonIndetifierModuleName.kt"); } + @Test + @TestMetadata("nonIndetifierModuleNameInExportedFile.kt") + public void testNonIndetifierModuleNameInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/nonIndetifierModuleNameInExportedFile.kt"); + } + @Test @TestMetadata("overriddenChainNonExportIntermediate.kt") public void testOverriddenChainNonExportIntermediate() throws Exception { runTest("js/js.translator/testData/box/export/overriddenChainNonExportIntermediate.kt"); } + @Test + @TestMetadata("overriddenChainNonExportIntermediateInExportedFile.kt") + public void testOverriddenChainNonExportIntermediateInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/overriddenChainNonExportIntermediateInExportedFile.kt"); + } + @Test @TestMetadata("overriddenExternalMethodWithSameNameMethod.kt") public void testOverriddenExternalMethodWithSameNameMethod() throws Exception { @@ -2178,6 +2232,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/export/overriddenExternalMethodWithSameStableNameMethod.kt"); } + @Test + @TestMetadata("overriddenExternalMethodWithSameStableNameMethodInExportedFile.kt") + public void testOverriddenExternalMethodWithSameStableNameMethodInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/overriddenExternalMethodWithSameStableNameMethodInExportedFile.kt"); + } + @Test @TestMetadata("overridenMethod.kt") public void testOverridenMethod() throws Exception { @@ -2190,6 +2250,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/export/reservedModuleName.kt"); } + @Test + @TestMetadata("reservedModuleNameInExportedFile.kt") + public void testReservedModuleNameInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/reservedModuleNameInExportedFile.kt"); + } + @Test @TestMetadata("vararg.kt") public void testVararg() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/FirJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/FirJsTestGenerated.java index abe8e000f51..3a8728b966c 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/FirJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/FirJsTestGenerated.java @@ -2560,12 +2560,24 @@ public class FirJsTestGenerated extends AbstractFirJsTest { runTest("js/js.translator/testData/box/export/bridgeSavingAfterExport.kt"); } + @Test + @TestMetadata("bridgeSavingAfterExportInExportedFile.kt") + public void testBridgeSavingAfterExportInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/bridgeSavingAfterExportInExportedFile.kt"); + } + @Test @TestMetadata("defaultInlineClassConstructorParam.kt") public void testDefaultInlineClassConstructorParam() throws Exception { runTest("js/js.translator/testData/box/export/defaultInlineClassConstructorParam.kt"); } + @Test + @TestMetadata("defaultInlineClassConstructorParamInExportedFile.kt") + public void testDefaultInlineClassConstructorParamInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/defaultInlineClassConstructorParamInExportedFile.kt"); + } + @Test @TestMetadata("exportAllFile.kt") public void testExportAllFile() throws Exception { @@ -2590,6 +2602,42 @@ public class FirJsTestGenerated extends AbstractFirJsTest { runTest("js/js.translator/testData/box/export/exportEnumClass.kt"); } + @Test + @TestMetadata("exportFileWithClassWithInternal.kt") + public void testExportFileWithClassWithInternal() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithClassWithInternal.kt"); + } + + @Test + @TestMetadata("exportFileWithEnumClass.kt") + public void testExportFileWithEnumClass() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithEnumClass.kt"); + } + + @Test + @TestMetadata("exportFileWithInterface.kt") + public void testExportFileWithInterface() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithInterface.kt"); + } + + @Test + @TestMetadata("exportFileWithNestedClass.kt") + public void testExportFileWithNestedClass() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithNestedClass.kt"); + } + + @Test + @TestMetadata("exportFileWithNestedObject.kt") + public void testExportFileWithNestedObject() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithNestedObject.kt"); + } + + @Test + @TestMetadata("exportFileWithProtectedMembers.kt") + public void testExportFileWithProtectedMembers() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithProtectedMembers.kt"); + } + @Test @TestMetadata("exportInnerClass.kt") public void testExportInnerClass() throws Exception { @@ -2626,12 +2674,24 @@ public class FirJsTestGenerated extends AbstractFirJsTest { runTest("js/js.translator/testData/box/export/nonIndetifierModuleName.kt"); } + @Test + @TestMetadata("nonIndetifierModuleNameInExportedFile.kt") + public void testNonIndetifierModuleNameInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/nonIndetifierModuleNameInExportedFile.kt"); + } + @Test @TestMetadata("overriddenChainNonExportIntermediate.kt") public void testOverriddenChainNonExportIntermediate() throws Exception { runTest("js/js.translator/testData/box/export/overriddenChainNonExportIntermediate.kt"); } + @Test + @TestMetadata("overriddenChainNonExportIntermediateInExportedFile.kt") + public void testOverriddenChainNonExportIntermediateInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/overriddenChainNonExportIntermediateInExportedFile.kt"); + } + @Test @TestMetadata("overriddenExternalMethodWithSameNameMethod.kt") public void testOverriddenExternalMethodWithSameNameMethod() throws Exception { @@ -2644,6 +2704,12 @@ public class FirJsTestGenerated extends AbstractFirJsTest { runTest("js/js.translator/testData/box/export/overriddenExternalMethodWithSameStableNameMethod.kt"); } + @Test + @TestMetadata("overriddenExternalMethodWithSameStableNameMethodInExportedFile.kt") + public void testOverriddenExternalMethodWithSameStableNameMethodInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/overriddenExternalMethodWithSameStableNameMethodInExportedFile.kt"); + } + @Test @TestMetadata("overriddenPropertyFromInterface.kt") public void testOverriddenPropertyFromInterface() throws Exception { @@ -2662,6 +2728,12 @@ public class FirJsTestGenerated extends AbstractFirJsTest { runTest("js/js.translator/testData/box/export/reservedModuleName.kt"); } + @Test + @TestMetadata("reservedModuleNameInExportedFile.kt") + public void testReservedModuleNameInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/reservedModuleNameInExportedFile.kt"); + } + @Test @TestMetadata("vararg.kt") public void testVararg() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java index 59f595b5d78..73f7c164e06 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java @@ -2560,12 +2560,24 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/export/bridgeSavingAfterExport.kt"); } + @Test + @TestMetadata("bridgeSavingAfterExportInExportedFile.kt") + public void testBridgeSavingAfterExportInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/bridgeSavingAfterExportInExportedFile.kt"); + } + @Test @TestMetadata("defaultInlineClassConstructorParam.kt") public void testDefaultInlineClassConstructorParam() throws Exception { runTest("js/js.translator/testData/box/export/defaultInlineClassConstructorParam.kt"); } + @Test + @TestMetadata("defaultInlineClassConstructorParamInExportedFile.kt") + public void testDefaultInlineClassConstructorParamInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/defaultInlineClassConstructorParamInExportedFile.kt"); + } + @Test @TestMetadata("exportAllFile.kt") public void testExportAllFile() throws Exception { @@ -2590,6 +2602,42 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/export/exportEnumClass.kt"); } + @Test + @TestMetadata("exportFileWithClassWithInternal.kt") + public void testExportFileWithClassWithInternal() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithClassWithInternal.kt"); + } + + @Test + @TestMetadata("exportFileWithEnumClass.kt") + public void testExportFileWithEnumClass() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithEnumClass.kt"); + } + + @Test + @TestMetadata("exportFileWithInterface.kt") + public void testExportFileWithInterface() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithInterface.kt"); + } + + @Test + @TestMetadata("exportFileWithNestedClass.kt") + public void testExportFileWithNestedClass() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithNestedClass.kt"); + } + + @Test + @TestMetadata("exportFileWithNestedObject.kt") + public void testExportFileWithNestedObject() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithNestedObject.kt"); + } + + @Test + @TestMetadata("exportFileWithProtectedMembers.kt") + public void testExportFileWithProtectedMembers() throws Exception { + runTest("js/js.translator/testData/box/export/exportFileWithProtectedMembers.kt"); + } + @Test @TestMetadata("exportInnerClass.kt") public void testExportInnerClass() throws Exception { @@ -2626,12 +2674,24 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/export/nonIndetifierModuleName.kt"); } + @Test + @TestMetadata("nonIndetifierModuleNameInExportedFile.kt") + public void testNonIndetifierModuleNameInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/nonIndetifierModuleNameInExportedFile.kt"); + } + @Test @TestMetadata("overriddenChainNonExportIntermediate.kt") public void testOverriddenChainNonExportIntermediate() throws Exception { runTest("js/js.translator/testData/box/export/overriddenChainNonExportIntermediate.kt"); } + @Test + @TestMetadata("overriddenChainNonExportIntermediateInExportedFile.kt") + public void testOverriddenChainNonExportIntermediateInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/overriddenChainNonExportIntermediateInExportedFile.kt"); + } + @Test @TestMetadata("overriddenExternalMethodWithSameNameMethod.kt") public void testOverriddenExternalMethodWithSameNameMethod() throws Exception { @@ -2644,6 +2704,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/export/overriddenExternalMethodWithSameStableNameMethod.kt"); } + @Test + @TestMetadata("overriddenExternalMethodWithSameStableNameMethodInExportedFile.kt") + public void testOverriddenExternalMethodWithSameStableNameMethodInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/overriddenExternalMethodWithSameStableNameMethodInExportedFile.kt"); + } + @Test @TestMetadata("overriddenPropertyFromInterface.kt") public void testOverriddenPropertyFromInterface() throws Exception { @@ -2662,6 +2728,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/export/reservedModuleName.kt"); } + @Test + @TestMetadata("reservedModuleNameInExportedFile.kt") + public void testReservedModuleNameInExportedFile() throws Exception { + runTest("js/js.translator/testData/box/export/reservedModuleNameInExportedFile.kt"); + } + @Test @TestMetadata("vararg.kt") public void testVararg() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsTypeScriptExportTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsTypeScriptExportTestGenerated.java index 4e1a6382538..f1addb799b3 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsTypeScriptExportTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsTypeScriptExportTestGenerated.java @@ -41,6 +41,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/abstract-classes-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Abstract_classes_in_exported_file { + @Test + @TestMetadata("abstract-classes.kt") + public void testAbstract_classes() throws Exception { + runTest("js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes.kt"); + } + + @Test + public void testAllFilesPresentInAbstract_classes_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/abstract-classes-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/constructors") @TestDataPath("$PROJECT_ROOT") @@ -57,6 +73,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/constructors-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Constructors_in_exported_file { + @Test + public void testAllFilesPresentInConstructors_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/constructors-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("constructors.kt") + public void testConstructors() throws Exception { + runTest("js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/data-classes") @TestDataPath("$PROJECT_ROOT") @@ -73,6 +105,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/data-classes-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Data_classes_in_exported_file { + @Test + public void testAllFilesPresentInData_classes_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/data-classes-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("data-classes.kt") + public void testData_classes() throws Exception { + runTest("js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/enum-classes") @TestDataPath("$PROJECT_ROOT") @@ -89,6 +137,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/enum-classes-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Enum_classes_in_exported_file { + @Test + public void testAllFilesPresentInEnum_classes_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/enum-classes-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("enum-classes.kt") + public void testEnum_classes() throws Exception { + runTest("js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/escaped-declarations") @TestDataPath("$PROJECT_ROOT") @@ -105,6 +169,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Escaped_declarations_in_exported_file { + @Test + public void testAllFilesPresentInEscaped_declarations_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("escaped-declarations.kt") + public void testEscaped_declarations() throws Exception { + runTest("js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/functions") @TestDataPath("$PROJECT_ROOT") @@ -121,6 +201,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/functions-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Functions_in_exported_file { + @Test + public void testAllFilesPresentInFunctions_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/functions-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("functions.kt") + public void testFunctions() throws Exception { + runTest("js/js.translator/testData/typescript-export/functions-in-exported-file/functions.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/implicit-export") @TestDataPath("$PROJECT_ROOT") @@ -169,6 +265,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/inner-classes-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Inner_classes_in_exported_file { + @Test + public void testAllFilesPresentInInner_classes_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/inner-classes-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("inner-class.kt") + public void testInner_class() throws Exception { + runTest("js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/interfaces") @TestDataPath("$PROJECT_ROOT") @@ -185,6 +297,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/interfaces-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Interfaces_in_exported_file { + @Test + public void testAllFilesPresentInInterfaces_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/interfaces-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("interfaces.kt") + public void testInterfaces() throws Exception { + runTest("js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/js-name") @TestDataPath("$PROJECT_ROOT") @@ -201,6 +329,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/js-name-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Js_name_in_exported_file { + @Test + public void testAllFilesPresentInJs_name_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/js-name-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("js-name.kt") + public void testJs_name() throws Exception { + runTest("js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/member-properties") @TestDataPath("$PROJECT_ROOT") @@ -217,6 +361,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/member-properties-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Member_properties_in_exported_file { + @Test + public void testAllFilesPresentInMember_properties_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/member-properties-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("member-properties.kt") + public void testMember_properties() throws Exception { + runTest("js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/methods") @TestDataPath("$PROJECT_ROOT") @@ -233,6 +393,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/methods-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Methods_in_exported_file { + @Test + public void testAllFilesPresentInMethods_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/methods-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("methods.kt") + public void testMethods() throws Exception { + runTest("js/js.translator/testData/typescript-export/methods-in-exported-file/methods.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/module-systems") @TestDataPath("$PROJECT_ROOT") @@ -261,6 +437,34 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/module-systems-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Module_systems_in_exported_file { + @Test + public void testAllFilesPresentInModule_systems_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/module-systems-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("commonjs.kt") + public void testCommonjs() throws Exception { + runTest("js/js.translator/testData/typescript-export/module-systems-in-exported-file/commonjs.kt"); + } + + @Test + @TestMetadata("plain.kt") + public void testPlain() throws Exception { + runTest("js/js.translator/testData/typescript-export/module-systems-in-exported-file/plain.kt"); + } + + @Test + @TestMetadata("umd.kt") + public void testUmd() throws Exception { + runTest("js/js.translator/testData/typescript-export/module-systems-in-exported-file/umd.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/namespaces") @TestDataPath("$PROJECT_ROOT") @@ -277,6 +481,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/namespaces-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Namespaces_in_exported_file { + @Test + public void testAllFilesPresentInNamespaces_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/namespaces-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("namespaces.kt") + public void testNamespaces() throws Exception { + runTest("js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/objects") @TestDataPath("$PROJECT_ROOT") @@ -293,6 +513,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/objects-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Objects_in_exported_file { + @Test + public void testAllFilesPresentInObjects_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/objects-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("objects.kt") + public void testObjects() throws Exception { + runTest("js/js.translator/testData/typescript-export/objects-in-exported-file/objects.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/primitives") @TestDataPath("$PROJECT_ROOT") @@ -309,6 +545,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/primitives-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Primitives_in_exported_file { + @Test + public void testAllFilesPresentInPrimitives_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/primitives-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("primitives.kt") + public void testPrimitives() throws Exception { + runTest("js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/properties") @TestDataPath("$PROJECT_ROOT") @@ -325,6 +577,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/properties-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Properties_in_exported_file { + @Test + public void testAllFilesPresentInProperties_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/properties-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("properties.kt") + public void testProperties() throws Exception { + runTest("js/js.translator/testData/typescript-export/properties-in-exported-file/properties.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/regular-classes") @TestDataPath("$PROJECT_ROOT") @@ -341,6 +609,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/regular-classes-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Regular_classes_in_exported_file { + @Test + public void testAllFilesPresentInRegular_classes_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/regular-classes-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("regular-classes.kt") + public void testRegular_classes() throws Exception { + runTest("js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/sealed-classes") @TestDataPath("$PROJECT_ROOT") @@ -357,6 +641,22 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } } + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/sealed-classes-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Sealed_classes_in_exported_file { + @Test + public void testAllFilesPresentInSealed_classes_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/sealed-classes-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("sealed-classes.kt") + public void testSealed_classes() throws Exception { + runTest("js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes.kt"); + } + } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/selective-export") @TestDataPath("$PROJECT_ROOT") @@ -374,18 +674,18 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp } @Nested - @TestMetadata("js/js.translator/testData/typescript-export/strictImplicitExport") + @TestMetadata("js/js.translator/testData/typescript-export/strict-implicit-export") @TestDataPath("$PROJECT_ROOT") - public class StrictImplicitExport { + public class Strict_implicit_export { @Test - public void testAllFilesPresentInStrictImplicitExport() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/strictImplicitExport"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + public void testAllFilesPresentInStrict_implicit_export() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/strict-implicit-export"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } @Test - @TestMetadata("declarations.kt") - public void testDeclarations() throws Exception { - runTest("js/js.translator/testData/typescript-export/strictImplicitExport/declarations.kt"); + @TestMetadata("strict-implicit-export.kt") + public void testStrict_implicit_export() throws Exception { + runTest("js/js.translator/testData/typescript-export/strict-implicit-export/strict-implicit-export.kt"); } } @@ -404,4 +704,20 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp runTest("js/js.translator/testData/typescript-export/visibility/visibility.kt"); } } + + @Nested + @TestMetadata("js/js.translator/testData/typescript-export/visibility-in-exported-file") + @TestDataPath("$PROJECT_ROOT") + public class Visibility_in_exported_file { + @Test + public void testAllFilesPresentInVisibility_in_exported_file() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/visibility-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); + } + + @Test + @TestMetadata("visibility.kt") + public void testVisibility() throws Exception { + runTest("js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility.kt"); + } + } } diff --git a/js/js.translator/testData/box/export/bridgeSavingAfterExportInExportedFile.kt b/js/js.translator/testData/box/export/bridgeSavingAfterExportInExportedFile.kt new file mode 100644 index 00000000000..a641b57ca60 --- /dev/null +++ b/js/js.translator/testData/box/export/bridgeSavingAfterExportInExportedFile.kt @@ -0,0 +1,28 @@ +// TARGET_BACKEND: JS_IR +// RUN_PLAIN_BOX_FUNCTION +// INFER_MAIN_MODULE + +// MODULE: bridge_saving_after_export +// FILE: lib.kt +@file:JsExport + +open class A { + open fun foo(value: T): T = value +} + +class B: A() { + override fun foo(value: String): String = value +} + +// FILE: test.js +function box() { + var a = new this["bridge_saving_after_export"].A() + var aFoo = a.foo("ok") + if (aFoo != "ok") return "fail 1" + + var b = new this["bridge_saving_after_export"].B() + var bFoo = b.foo("ok") + if (bFoo != "ok") return "fail 2" + + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testData/box/export/defaultInlineClassConstructorParamInExportedFile.kt b/js/js.translator/testData/box/export/defaultInlineClassConstructorParamInExportedFile.kt new file mode 100644 index 00000000000..d8a0c3db83c --- /dev/null +++ b/js/js.translator/testData/box/export/defaultInlineClassConstructorParamInExportedFile.kt @@ -0,0 +1,20 @@ +// IGNORE_FIR +// KT-49225 +// RUN_PLAIN_BOX_FUNCTION +// IGNORE_BACKEND: JS +// SPLIT_PER_MODULE + +// MODULE: lib +// FILE: koo.kt +value class Koo(val koo: String = "OK") + +// FILE: bar.kt +@file:JsExport + +class Bar(val koo: Koo = Koo()) + +// MODULE: main(lib) +// FILE: main.js +function box() { + return new kotlin_lib.Bar().koo; +} \ No newline at end of file diff --git a/js/js.translator/testData/box/export/exportFileWithClassWithInternal.kt b/js/js.translator/testData/box/export/exportFileWithClassWithInternal.kt new file mode 100644 index 00000000000..9effc57f099 --- /dev/null +++ b/js/js.translator/testData/box/export/exportFileWithClassWithInternal.kt @@ -0,0 +1,32 @@ +// FILE: lib.kt +@file:JsExport + +class Foo(internal val constructorParameter: String) { + internal val nonDefaultAccessor: String + get() = "hello" + + internal val defaultAccessor: String = constructorParameter + "!" +} + +enum class Bar(internal val constructorParameter: String) { + A("a"); + + internal val nonDefaultAccessor: String + get() = "hello" + + internal val defaultAccessor: String = constructorParameter + "!" +} + +// FILE: main.kt +fun box(): String { + val foo = Foo("foo") + if (foo.constructorParameter != "foo") return "fail1" + if (foo.nonDefaultAccessor != "hello") return "fail2" + if (foo.defaultAccessor != "foo!") return "fail3" + + if (Bar.A.constructorParameter != "a") return "fail4" + if (Bar.A.nonDefaultAccessor != "hello") return "fail5" + if (Bar.A.defaultAccessor != "a!") return "fail6" + + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testData/box/export/exportFileWithEnumClass.kt b/js/js.translator/testData/box/export/exportFileWithEnumClass.kt new file mode 100644 index 00000000000..f880db453e3 --- /dev/null +++ b/js/js.translator/testData/box/export/exportFileWithEnumClass.kt @@ -0,0 +1,98 @@ +// IGNORE_BACKEND: JS +// RUN_PLAIN_BOX_FUNCTION +// INFER_MAIN_MODULE + +// MODULE: export_enum_class +// FILE: lib.kt +@file:JsExport + +enum class Foo(val constructorParameter: String) { + A("aConstructorParameter"), + B("bConstructorParameter"); + + val foo = ordinal + + fun bar(value: String) = value + + fun bay() = name + + companion object { + val baz = "baz" + } +} + +enum class Bar { + A, + B { + var d = "d" + init { + d = "d2" + } + fun huh() = "huh" + }; + + val foo = ordinal + + fun bar(value: String) = value + + fun bay() = name +} + +class OuterClass { + enum class NestedEnum { + A, + B; + } +} + +// FILE: test.js +function box() { + if (this["export_enum_class"].Foo.A !== this["export_enum_class"].Foo.A) return "fail1" + if (this["export_enum_class"].Foo.B !== this["export_enum_class"].Foo.B) return "fail2" + + if (this["export_enum_class"].Foo.Companion.baz !== "baz") return "fail3" + + if (this["export_enum_class"].Foo.A.foo !== 0) return "fail4" + if (this["export_enum_class"].Foo.B.foo !== 1) return "fail5" + + if (this["export_enum_class"].Foo.A.bar("A") !== "A") return "fail6" + if (this["export_enum_class"].Foo.B.bar("B") !== "B") return "fail7" + + if (this["export_enum_class"].Foo.A.bay() !== "A") return "fail8" + if (this["export_enum_class"].Foo.B.bay() !== "B") return "fail9" + + if (this["export_enum_class"].Foo.A.constructorParameter !== "aConstructorParameter") return "fail10" + if (this["export_enum_class"].Foo.B.constructorParameter !== "bConstructorParameter") return "fail11" + + if (this["export_enum_class"].Bar.A.foo !== 0) return "fail12" + if (this["export_enum_class"].Bar.B.foo !== 1) return "fail13" + + if (this["export_enum_class"].Bar.A.bar("A") !== "A") return "fail14" + if (this["export_enum_class"].Bar.B.bar("B") !== "B") return "fail15" + + if (this["export_enum_class"].Bar.A.bay() !== "A") return "fail15" + if (this["export_enum_class"].Bar.B.bay() !== "B") return "fail16" + + if (this["export_enum_class"].Bar.B.constructor.prototype.hasOwnProperty('d')) return "fail17" + if (this["export_enum_class"].Bar.B.constructor.prototype.hasOwnProperty('huh')) return "fail18" + + if (this["export_enum_class"].Foo.valueOf("A") !== this["export_enum_class"].Foo.A) return "fail19" + if (this["export_enum_class"].Foo.valueOf("B") !== this["export_enum_class"].Foo.B) return "fail20" + + if (this["export_enum_class"].Foo.values().indexOf(this["export_enum_class"].Foo.A) === -1) return "fail21" + if (this["export_enum_class"].Foo.values().indexOf(this["export_enum_class"].Foo.B) === -1) return "fail22" + + if (this["export_enum_class"].Foo.A.name !== "A") return "fail23" + if (this["export_enum_class"].Foo.B.name !== "B") return "fail24" + + if (this["export_enum_class"].Foo.A.ordinal !== 0) return "fail25" + if (this["export_enum_class"].Foo.B.ordinal !== 1) return "fail26" + + if (this["export_enum_class"].OuterClass.NestedEnum.A.name !== "A") return "fail27" + if (this["export_enum_class"].OuterClass.NestedEnum.B.name !== "B") return "fail28" + + if (this["export_enum_class"].OuterClass.NestedEnum.A.ordinal !== 0) return "fail29" + if (this["export_enum_class"].OuterClass.NestedEnum.B.ordinal !== 1) return "fail30" + + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testData/box/export/exportFileWithInterface.kt b/js/js.translator/testData/box/export/exportFileWithInterface.kt new file mode 100644 index 00000000000..d5f63515678 --- /dev/null +++ b/js/js.translator/testData/box/export/exportFileWithInterface.kt @@ -0,0 +1,96 @@ +// IGNORE_BACKEND: JS +// RUN_PLAIN_BOX_FUNCTION +// INFER_MAIN_MODULE + +// MODULE: export_interface +// FILE: not_exported.kt + +interface ParentI { + val str: String +} + +interface ExtendedI: I { + fun bar(): Int +} + +open class NotExportedClass(override var value: Int) : ExtendedI { + override var variable: Int = value + override open fun foo(): String = "Not Exported" + override val str: String = "test 1" + override open fun bar(): Int = 42 +} + + +// FILE: exportes.kt +@file:JsExport + +interface I : ParentI { + val value: Int + var variable: Int + fun foo(): String +} + +class ExportedClass(override val value: Int) : ExtendedI { + override var variable: Int = value + override fun foo(): String = "Exported" + override val str: String = "test 2" + override open fun bar(): Int = 43 +} + +class AnotherOne : NotExportedClass(42) { + override fun foo(): String = "Another One Exported" +} + +fun generateNotExported(value: Int): NotExportedClass { + return NotExportedClass(value) +} + +fun consume(i: I): String { + return "Value is ${i.value}, variable is ${i.variable} and result is '${i.foo()}'" +} + +// FILE: test.js +function box() { + const { I, ExportedClass, AnotherOne, generateNotExported, consume } = this["export_interface"] + + if (I !== undefined) return "Fail: module should not export interface in runtime" + + const exported = new ExportedClass(1) + const another = new AnotherOne() + const notExported = generateNotExported (3) + + if (exported.foo() !== "Exported") return "Fail: foo function was not generated for ExportedClass" + if (another.foo() !== "Another One Exported") return "Fail: foo function was not generated for AnotherOne" + if (notExported.foo() !== "Not Exported") return "Fail: foo function was not generated for NotExportedClass" + + if (exported.value !== 1) return "Fail: value getter was not generated for ExportedClass" + if (another.value !== 42) return "Fail: value getter was not generated for AnotherOne" + if (notExported.value !== 3) return "Fail: value getter was not generated for NotExportedClass" + + if (exported.variable !== 1) return "Fail: variable getter was not generated for ExportedClass" + if (another.variable !== 42) return "Fail: variable getter was not generated for AnotherOne" + if (notExported.variable !== 3) return "Fail: variable getter was not generated for NotExportedClass" + + exported.variable = 101 + another.variable = 102 + notExported.variable = 103 + + if (exported.variable !== 101) return "Fail: variable setter was not generated for ExportedClass" + if (another.variable !== 102) return "Fail: variable setter was not generated for AnotherOne" + if (notExported.variable !== 103) return "Fail: variable setter was not generated for NotExportedClass" + + notExported.value = 42 + if (notExported.value !== 3) return "Fail: value setter was generated for NotExportedClass, but it shouldn't" + + if (consume(exported) !== "Value is 1, variable is 101 and result is 'Exported'") return "Fail: methods or fields of ExportedClass was mangled" + if (consume(another) !== "Value is 42, variable is 102 and result is 'Another One Exported'") return "Fail: methods or fields of AnotherOne was mangled" + if (consume(notExported) !== "Value is 3, variable is 103 and result is 'Not Exported'") return "Fail: methods or fields of NotExported was mangled" + + if (notExported.str !== undefined) return "Fail: str should not exist inside NotExportedClass" + if (exported.str !== undefined) return "Fail: str should not exist inside ExportedClass" + + if (notExported.bar !== undefined) return "Fail: bar should not exist inside NotExportedClass" + if (exported.bar !== undefined) return "Fail: bar should not exist inside ExportedClass" + + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testData/box/export/exportFileWithNestedClass.kt b/js/js.translator/testData/box/export/exportFileWithNestedClass.kt new file mode 100644 index 00000000000..1a08fbfc5f7 --- /dev/null +++ b/js/js.translator/testData/box/export/exportFileWithNestedClass.kt @@ -0,0 +1,47 @@ +// EXPECTED_REACHABLE_NODES: 1252 +// IGNORE_BACKEND: JS +// RUN_PLAIN_BOX_FUNCTION +// INFER_MAIN_MODULE +// SKIP_DCE_DRIVEN + +// MODULE: export_nested_class +// FILE: lib.kt +@file:JsExport + +abstract class A { + abstract fun foo(k: String): String +} + +class B { + class Foo : A() { + override fun foo(k: String): String { + return "O" + k + } + + fun bar(k: String): String { + return foo(k) + } + } +} + +object MyObject { + class A { + fun valueA() = "OK" + } + class B { + fun valueB() = "OK" + } + class C { + fun valueC() = "OK" + } +} + +// FILE: test.js +function box() { + if (new this["export_nested_class"].B.Foo().bar("K") != "OK") return "fail 1"; + if (new this["export_nested_class"].MyObject.A().valueA() != "OK") return "fail 2"; + if (new this["export_nested_class"].MyObject.B().valueB() != "OK") return "fail 3"; + if (new this["export_nested_class"].MyObject.C().valueC() != "OK") return "fail 4"; + + return "OK" +} \ No newline at end of file diff --git a/js/js.translator/testData/box/export/exportFileWithNestedObject.kt b/js/js.translator/testData/box/export/exportFileWithNestedObject.kt new file mode 100644 index 00000000000..f731048e3e8 --- /dev/null +++ b/js/js.translator/testData/box/export/exportFileWithNestedObject.kt @@ -0,0 +1,72 @@ +// EXPECTED_REACHABLE_NODES: 1265 +// RUN_PLAIN_BOX_FUNCTION +// INFER_MAIN_MODULE +// SKIP_MINIFICATION +// SKIP_DCE_DRIVEN +// SKIP_NODE_JS + +// See KT-43783 + +// MODULE: nestedObjectExport +// FILE: lib.kt +@file:JsExport + +class Abc { + companion object AbcCompanion { + fun xyz(): String = "Companion object method OK" + + val prop: String + get() = "Companion object property OK" + } +} + +class Foo { + companion object { + fun xyz(): String = "Companion object method OK" + + val prop: String + get() = "Companion object property OK" + } +} + +sealed class MyEnum(val name: String) { + object A: MyEnum("A") + object B: MyEnum("B") + object C: MyEnum("C") +} + +object MyObject { + object A { + fun valueA() = "OK" + } + object B { + fun valueB() = "OK" + } + object C { + fun valueC() = "OK" + } +} + +// FILE: test.js + +function box() { + const abcCompanion = nestedObjectExport.Abc.AbcCompanion; + + if (abcCompanion.xyz() != 'Companion object method OK') return 'companion object function failure'; + if (abcCompanion.prop != 'Companion object property OK') return 'companion object property failure'; + + const justCompanion = nestedObjectExport.Foo.Companion; + + if (justCompanion.xyz() != 'Companion object method OK') return 'companion object function failure'; + if (justCompanion.prop != 'Companion object property OK') return 'companion object property failure'; + + if (nestedObjectExport.MyEnum.A.name != 'A') return 'MyEnum.A failure'; + if (nestedObjectExport.MyEnum.B.name != 'B') return 'MyEnum.B failure'; + if (nestedObjectExport.MyEnum.C.name != 'C') return 'MyEnum.C failure'; + + if (nestedObjectExport.MyObject.A.valueA() != "OK") return 'MyObject.A failure'; + if (nestedObjectExport.MyObject.B.valueB() != "OK") return 'MyObject.B failure'; + if (nestedObjectExport.MyObject.C.valueC() != "OK") return 'MyObject.C failure'; + + return 'OK'; +} diff --git a/js/js.translator/testData/box/export/exportFileWithProtectedMembers.kt b/js/js.translator/testData/box/export/exportFileWithProtectedMembers.kt new file mode 100644 index 00000000000..ae46848d9d4 --- /dev/null +++ b/js/js.translator/testData/box/export/exportFileWithProtectedMembers.kt @@ -0,0 +1,66 @@ +// EXPECTED_REACHABLE_NODES: 1265 +// RUN_PLAIN_BOX_FUNCTION +// INFER_MAIN_MODULE +// SKIP_MINIFICATION +// SKIP_NODE_JS +// SKIP_DCE_DRIVEN + +// MODULE: exportProtectedMembers +// FILE: lib.kt +@file:JsExport + +open class Foo protected constructor() { + protected fun bar(): String = "protected method" + + private var _baz: String = "baz" + + protected var baz: String + get() = _baz + set(value) { + _baz = value + } + + protected val bazReadOnly: String + get() = _baz + + protected val quux: String = "quux" + + protected var quuz: String = "quuz" + + protected class NestedClass { + val prop: String = "nested class property" + } + protected object NestedObject { + val prop: String = "nested object property" + } + + protected companion object { + val prop: String = "companion object property" + } +} + +// FILE: test.js +function box() { + foo = new exportProtectedMembers.Foo(); + + if (foo.bar() != 'protected method') return 'failed to call protected method'; + if (foo.baz != 'baz') return 'failed to read `baz`'; + if (foo.bazReadOnly != 'baz') return 'failed to read `bazReadOnly`'; + foo.baz = 'beer'; + if (foo.baz != 'beer') return 'failed to write protected var'; + if (foo.bazReadOnly != 'beer') return 'unexpected value of `bazReadOnly` after modifying `baz`'; + if (foo.quux != 'quux') return 'failed to read `quux`'; + if (foo.quuz != 'quuz') return 'failed to read `quuz`'; + foo.quuz = 'ale'; + if (foo.quuz != 'ale') return 'failed to write `quuz`'; + + nestedClass = new exportProtectedMembers.Foo.NestedClass() + if (nestedClass.prop != 'nested class property') + return 'failed to read protected class property' + if (exportProtectedMembers.Foo.NestedObject.prop != 'nested object property') + return 'failed to read protected nested object property' + if (exportProtectedMembers.Foo.Companion.prop != 'companion object property') + return 'failed to read protected companion object property' + + return 'OK'; +} diff --git a/js/js.translator/testData/box/export/nonIndetifierModuleNameInExportedFile.kt b/js/js.translator/testData/box/export/nonIndetifierModuleNameInExportedFile.kt new file mode 100644 index 00000000000..565b7596e31 --- /dev/null +++ b/js/js.translator/testData/box/export/nonIndetifierModuleNameInExportedFile.kt @@ -0,0 +1,17 @@ +// EXPECTED_REACHABLE_NODES: 1270 +// SKIP_MINIFICATION +// RUN_PLAIN_BOX_FUNCTION +// INFER_MAIN_MODULE +// SKIP_NODE_JS + +// MODULE: non_identifier_module_name +// FILE: lib.kt +@file:JsExport + +@JsName("foo") +public fun foo(k: String): String = "O$k" + +// FILE: test.js +function box() { + return this["non_identifier_module_name"].foo("K"); +} diff --git a/js/js.translator/testData/box/export/overriddenChainNonExportIntermediateInExportedFile.kt b/js/js.translator/testData/box/export/overriddenChainNonExportIntermediateInExportedFile.kt new file mode 100644 index 00000000000..59b65d4bc4d --- /dev/null +++ b/js/js.translator/testData/box/export/overriddenChainNonExportIntermediateInExportedFile.kt @@ -0,0 +1,41 @@ +// EXPECTED_REACHABLE_NODES: 1252 +// IGNORE_BACKEND: JS +// RUN_PLAIN_BOX_FUNCTION +// INFER_MAIN_MODULE + +// MODULE: overriden_chain_non_export_intermediate +// FILE: not_exported.kt +abstract class B : A() { + abstract fun baz(): String + + override fun foo(): String = "foo" +} + + +// FILE: exported.kt +@file:JsExport + +abstract class A { + abstract fun foo(): String + + abstract fun bar(): String +} + +class C : B() { + override fun bar(): String = "bar" + override fun baz(): String = "baz" + + fun bay(): String = "bay" +} + +// FILE: test.js + +function box() { + return test(new this["overriden_chain_non_export_intermediate"].C()); +} + +function test(c) { + if (c.foo() === "foo" && c.bar() === "bar" && c.bay() == "bay") return "OK" + + return "fail" +} \ No newline at end of file diff --git a/js/js.translator/testData/box/export/overriddenExternalMethodWithSameStableNameMethodInExportedFile.kt b/js/js.translator/testData/box/export/overriddenExternalMethodWithSameStableNameMethodInExportedFile.kt new file mode 100644 index 00000000000..76b12cda977 --- /dev/null +++ b/js/js.translator/testData/box/export/overriddenExternalMethodWithSameStableNameMethodInExportedFile.kt @@ -0,0 +1,45 @@ +// EXPECTED_REACHABLE_NODES: 1252 +// IGNORE_BACKEND: JS +// RUN_PLAIN_BOX_FUNCTION +// INFER_MAIN_MODULE + +// MODULE: lib +// FILE: not_exported.kt + +external abstract class Foo { + abstract fun o(): String +} + +abstract class Bar : Foo() { + @JsName("oStable") + abstract fun String.o(): String + + override fun o(): String { + return "O".o() + } +} + +// FILE: exported.kt +@file:JsExport + +class Baz : Bar() { + override fun String.o(): String { + return this + } +} + +// FILE: test.js +function Foo() {} +Foo.prototype.k = function() { + return "K" +} + +function box() { + return test(new this["lib"].Baz()); +} + +function test(foo) { + const oStable = foo.oStable("OK") + if (oStable !== "OK") return "false: " + oStable + return foo.o() + foo.k() +} \ No newline at end of file diff --git a/js/js.translator/testData/box/export/reservedModuleNameInExportedFile.kt b/js/js.translator/testData/box/export/reservedModuleNameInExportedFile.kt new file mode 100644 index 00000000000..25942017d27 --- /dev/null +++ b/js/js.translator/testData/box/export/reservedModuleNameInExportedFile.kt @@ -0,0 +1,17 @@ +// IGNORE_BACKEND: JS +// EXPECTED_REACHABLE_NODES: 1270 +// SKIP_MINIFICATION +// RUN_PLAIN_BOX_FUNCTION +// INFER_MAIN_MODULE + +// MODULE: if +// FILE: lib.kt +@file:JsExport + +@JsName("foo") +public fun foo(k: String): String = "O$k" + +// FILE: test.js +function box() { + return this["if"].foo("K"); +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes.d.ts b/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes.d.ts new file mode 100644 index 00000000000..db5b60420c6 --- /dev/null +++ b/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes.d.ts @@ -0,0 +1,19 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + abstract class TestAbstract { + constructor(name: string); + get name(): string; + } + namespace TestAbstract { + class AA extends foo.TestAbstract { + constructor(); + bar(): string; + } + class BB extends foo.TestAbstract { + constructor(); + baz(): string; + } + } + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes.kt b/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes.kt new file mode 100644 index 00000000000..5c0957b4eab --- /dev/null +++ b/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes.kt @@ -0,0 +1,24 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: abstract-classes.kt + +@file:JsExport + +package foo + +// See KT-39364 + +abstract class TestAbstract(val name: String) { + class AA : TestAbstract("AA") { + fun bar(): String = "bar" + } + class BB : TestAbstract("BB") { + fun baz(): String = "baz" + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes__main.js b/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes__main.js new file mode 100644 index 00000000000..a0139b52540 --- /dev/null +++ b/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes__main.js @@ -0,0 +1,14 @@ +"use strict"; +var TestAbstract = JS_TESTS.foo.TestAbstract; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + assert(new TestAbstract.AA().name == "AA"); + assert(new TestAbstract.AA().bar() == "bar"); + assert(new TestAbstract.BB().name == "BB"); + assert(new TestAbstract.BB().baz() == "baz"); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes__main.ts b/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes__main.ts new file mode 100644 index 00000000000..92c4ff8e223 --- /dev/null +++ b/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/abstract-classes__main.ts @@ -0,0 +1,17 @@ +import TestAbstract = JS_TESTS.foo.TestAbstract; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + assert(new TestAbstract.AA().name == "AA"); + assert(new TestAbstract.AA().bar() == "bar"); + assert(new TestAbstract.BB().name == "BB"); + assert(new TestAbstract.BB().baz() == "baz"); + + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/strictImplicitExport/tsconfig.json b/js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/tsconfig.json similarity index 100% rename from js/js.translator/testData/typescript-export/strictImplicitExport/tsconfig.json rename to js/js.translator/testData/typescript-export/abstract-classes-in-exported-file/tsconfig.json diff --git a/js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors.d.ts b/js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors.d.ts new file mode 100644 index 00000000000..4b30ca4d16a --- /dev/null +++ b/js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors.d.ts @@ -0,0 +1,37 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + class ClassWithDefaultCtor { + constructor(); + get x(): string; + } + class ClassWithPrimaryCtor { + constructor(x: string); + get x(): string; + } + class ClassWithSecondaryCtor { + private constructor(); + get x(): string; + static create(y: string): ClassWithSecondaryCtor; + } + class ClassWithMultipleSecondaryCtors { + private constructor(); + get x(): string; + static createFromString(y: string): ClassWithMultipleSecondaryCtors; + static createFromInts(y: number, z: number): ClassWithMultipleSecondaryCtors; + } + class OpenClassWithMixedConstructors { + constructor(x: string); + get x(): string; + static createFromStrings(y: string, z: string): OpenClassWithMixedConstructors; + static createFromInts(y: number, z: number): OpenClassWithMixedConstructors; + } + class DerivedClassWithSecondaryCtor extends OpenClassWithMixedConstructors { + private constructor(); + static delegateToPrimary(y: string): DerivedClassWithSecondaryCtor; + static delegateToCreateFromInts(y: number, z: number): DerivedClassWithSecondaryCtor; + } + class KotlinGreeter { + constructor(greeting?: string); + get greeting(): string; + } +} diff --git a/js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors.kt b/js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors.kt new file mode 100644 index 00000000000..f2296f9ae1f --- /dev/null +++ b/js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors.kt @@ -0,0 +1,76 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// TARGET_BACKEND: JS_IR +// IGNORE_BACKEND: JS_IR_ES6 +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE + +// TODO fix statics export in DCE-driven mode +// SKIP_DCE_DRIVEN + +// MODULE: JS_TESTS +// FILE: f1.kt + +@file:JsExport + + +class ClassWithDefaultCtor { + val x = "ClassWithDefaultCtor::x" +} + + +class ClassWithPrimaryCtor( + val x: String +) + + +class ClassWithSecondaryCtor { + val x: String + @JsName("create") + constructor(y: String) { + x = y + } +} + + +class ClassWithMultipleSecondaryCtors { + val x: String + + @JsName("createFromString") + constructor(y: String) { + x = "fromString:$y" + } + + @JsName("createFromInts") + constructor(y: Int, z: Int) { + x = "fromInts:$y:$z" + } +} + + +open class OpenClassWithMixedConstructors(val x: String) { + @JsName("createFromStrings") + constructor(y: String, z: String) : this("fromStrings:$y:$z") + + @JsName("createFromInts") + constructor(y: Int, z: Int) : this(y.toString(), z.toString()) +} + + +class DerivedClassWithSecondaryCtor : OpenClassWithMixedConstructors { + @JsName("delegateToPrimary") + constructor(y: String) : super(y) + + @JsName("delegateToCreateFromInts") + constructor(y: Int, z: Int) : super(y, z) +} + +// FILE: f2.kt + +@file:JsExport + + +class KotlinGreeter(val greeting: String = "helau") \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors__main.js b/js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors__main.js new file mode 100644 index 00000000000..489fd99b83b --- /dev/null +++ b/js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors__main.js @@ -0,0 +1,38 @@ +"use strict"; +var ClassWithDefaultCtor = JS_TESTS.ClassWithDefaultCtor, ClassWithPrimaryCtor = JS_TESTS.ClassWithPrimaryCtor, ClassWithSecondaryCtor = JS_TESTS.ClassWithSecondaryCtor, ClassWithMultipleSecondaryCtors = JS_TESTS.ClassWithMultipleSecondaryCtors, DerivedClassWithSecondaryCtor = JS_TESTS.DerivedClassWithSecondaryCtor, OpenClassWithMixedConstructors = JS_TESTS.OpenClassWithMixedConstructors, KotlinGreeter = JS_TESTS.KotlinGreeter; +function box() { + var o1 = new ClassWithDefaultCtor(); + if (o1.x !== "ClassWithDefaultCtor::x") + return "Fail: ClassWithDefaultCtor"; + var o2 = new ClassWithPrimaryCtor("foo"); + if (o2.x !== "foo") + return "Fail: ClassWithPrimaryCtor"; + var o3 = ClassWithSecondaryCtor.create("foo2"); + if (o3.x !== "foo2") + return "Fail: ClassWithSecondaryCtor.create"; + var o4 = ClassWithMultipleSecondaryCtors.createFromString("foo3"); + if (o4.x !== "fromString:foo3") + return "Fail: ClassWithMultipleSecondaryCtors.createFromString"; + var o5 = ClassWithMultipleSecondaryCtors.createFromInts(1, 2); + if (o5.x !== "fromInts:1:2") + return "Fail: ClassWithMultipleSecondaryCtors.createFromInts"; + var o6 = new OpenClassWithMixedConstructors("foo4"); + if (o6.x !== "foo4") + return "Fail: OpenClassWithMixedConstructors"; + var o7 = OpenClassWithMixedConstructors.createFromStrings("foo", "bar"); + if (o7.x !== "fromStrings:foo:bar") + return "Fail: OpenClassWithMixedConstructors.createFromStrings"; + var o8 = OpenClassWithMixedConstructors.createFromInts(10, -20); + if (o8.x !== "fromStrings:10:-20") + return "Fail: OpenClassWithMixedConstructors.createFromInts"; + var o9 = DerivedClassWithSecondaryCtor.delegateToPrimary("foo6"); + if (o9.x !== "foo6") + return "Fail: DerivedClassWithSecondaryCtor.delegateToPrimary"; + var o10 = DerivedClassWithSecondaryCtor.delegateToCreateFromInts(-10, 20); + if (o10.x !== "fromStrings:-10:20") + return "Fail: DerivedClassWithSecondaryCtor.delegateToCreateFromInts"; + var kg = new KotlinGreeter("Hi"); + if (kg.greeting != "Hi") + return "Fail: KotlinGreeter"; + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors__main.ts b/js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors__main.ts new file mode 100644 index 00000000000..1271902ce0f --- /dev/null +++ b/js/js.translator/testData/typescript-export/constructors-in-exported-file/constructors__main.ts @@ -0,0 +1,52 @@ +const { + ClassWithDefaultCtor, + ClassWithPrimaryCtor, + ClassWithSecondaryCtor, + ClassWithMultipleSecondaryCtors, + DerivedClassWithSecondaryCtor, + OpenClassWithMixedConstructors, + KotlinGreeter +} = JS_TESTS; + +function box(): string { + const o1 = new ClassWithDefaultCtor(); + if (o1.x !== "ClassWithDefaultCtor::x") return "Fail: ClassWithDefaultCtor"; + + + const o2 = new ClassWithPrimaryCtor("foo"); + if (o2.x !== "foo") return "Fail: ClassWithPrimaryCtor"; + + + const o3 = ClassWithSecondaryCtor.create("foo2"); + if (o3.x !== "foo2") return "Fail: ClassWithSecondaryCtor.create"; + + + const o4 = ClassWithMultipleSecondaryCtors.createFromString("foo3"); + if (o4.x !== "fromString:foo3") return "Fail: ClassWithMultipleSecondaryCtors.createFromString"; + + const o5 = ClassWithMultipleSecondaryCtors.createFromInts(1, 2); + if (o5.x !== "fromInts:1:2") return "Fail: ClassWithMultipleSecondaryCtors.createFromInts"; + + + const o6 = new OpenClassWithMixedConstructors("foo4"); + if (o6.x !== "foo4") return "Fail: OpenClassWithMixedConstructors"; + + const o7 = OpenClassWithMixedConstructors.createFromStrings("foo", "bar"); + if (o7.x !== "fromStrings:foo:bar") return "Fail: OpenClassWithMixedConstructors.createFromStrings"; + + const o8 = OpenClassWithMixedConstructors.createFromInts(10, -20); + if (o8.x !== "fromStrings:10:-20") return "Fail: OpenClassWithMixedConstructors.createFromInts"; + + + const o9 = DerivedClassWithSecondaryCtor.delegateToPrimary("foo6"); + if (o9.x !== "foo6") return "Fail: DerivedClassWithSecondaryCtor.delegateToPrimary"; + + const o10 = DerivedClassWithSecondaryCtor.delegateToCreateFromInts(-10, 20); + if (o10.x !== "fromStrings:-10:20") return "Fail: DerivedClassWithSecondaryCtor.delegateToCreateFromInts"; + + + const kg = new KotlinGreeter("Hi"); + if (kg.greeting != "Hi") return "Fail: KotlinGreeter"; + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/constructors-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/constructors-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/constructors-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/constructors/constructors.kt b/js/js.translator/testData/typescript-export/constructors/constructors.kt index 73db62c5f53..0a2386605c6 100644 --- a/js/js.translator/testData/typescript-export/constructors/constructors.kt +++ b/js/js.translator/testData/typescript-export/constructors/constructors.kt @@ -12,16 +12,17 @@ // MODULE: JS_TESTS // FILE: f1.kt -@file:JsExport - +@JsExport class ClassWithDefaultCtor { val x = "ClassWithDefaultCtor::x" } +@JsExport class ClassWithPrimaryCtor( val x: String ) +@JsExport class ClassWithSecondaryCtor { val x: String @JsName("create") @@ -30,6 +31,7 @@ class ClassWithSecondaryCtor { } } +@JsExport class ClassWithMultipleSecondaryCtors { val x: String @@ -44,6 +46,7 @@ class ClassWithMultipleSecondaryCtors { } } +@JsExport open class OpenClassWithMixedConstructors(val x: String) { @JsName("createFromStrings") constructor(y: String, z: String) : this("fromStrings:$y:$z") @@ -52,6 +55,7 @@ open class OpenClassWithMixedConstructors(val x: String) { constructor(y: Int, z: Int) : this(y.toString(), z.toString()) } +@JsExport class DerivedClassWithSecondaryCtor : OpenClassWithMixedConstructors { @JsName("delegateToPrimary") constructor(y: String) : super(y) diff --git a/js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes.d.ts b/js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes.d.ts new file mode 100644 index 00000000000..dcfc9199c47 --- /dev/null +++ b/js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes.d.ts @@ -0,0 +1,31 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + class TestDataClass { + constructor(name: string); + get name(): string; + component1(): string; + copy(name?: string): foo.TestDataClass; + toString(): string; + hashCode(): number; + equals(other: Nullable): boolean; + } + namespace TestDataClass { + class Nested { + constructor(); + get prop(): string; + } + } + class KT39423 { + constructor(a: string, b?: Nullable); + get a(): string; + get b(): Nullable; + component1(): string; + component2(): Nullable; + copy(a?: string, b?: Nullable): foo.KT39423; + toString(): string; + hashCode(): number; + equals(other: Nullable): boolean; + } + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes.kt b/js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes.kt new file mode 100644 index 00000000000..ea64d325e9f --- /dev/null +++ b/js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes.kt @@ -0,0 +1,27 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: data-classes.kt + +@file:JsExport + +package foo + + + +data class TestDataClass(val name: String) { + class Nested { + val prop: String = "hello" + } +} + + +data class KT39423( + val a: String, + val b: Int? = null +) \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes__main.js b/js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes__main.js new file mode 100644 index 00000000000..898f484c364 --- /dev/null +++ b/js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes__main.js @@ -0,0 +1,35 @@ +"use strict"; +var TestDataClass = JS_TESTS.foo.TestDataClass; +var KT39423 = JS_TESTS.foo.KT39423; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + assert(new TestDataClass("Test").name === "Test"); + assert(new TestDataClass("Test").component1() === "Test"); + assert(new TestDataClass("Test").copy("NewTest").name === "NewTest"); + assert(new TestDataClass("Test").toString() === "TestDataClass(name=Test)"); + assert(new TestDataClass("Test").hashCode() === new TestDataClass("Test").hashCode()); + assert(new TestDataClass("Test").hashCode() !== new TestDataClass("AnotherTest").hashCode()); + assert(new TestDataClass("Test").equals(new TestDataClass("Test"))); + assert(!new TestDataClass("Test").equals(new TestDataClass("AnotherTest"))); + assert(new TestDataClass.Nested().prop === "hello"); + assert(new KT39423("Test").a === "Test"); + assert(new KT39423("Test").b === null); + assert(new KT39423("Test", null).a === "Test"); + assert(new KT39423("Test", null).b === null); + assert(new KT39423("Test", 42).a === "Test"); + assert(new KT39423("Test", 42).b === 42); + assert(new KT39423("Test", 42).component1() === "Test"); + assert(new KT39423("Test", 42).component2() === 42); + assert(new KT39423("Test", 42).copy("NewTest").a === "NewTest"); + assert(new KT39423("Test", 42).copy("NewTest").b === 42); + assert(new KT39423("Test", 42).copy("Test", null).a === "Test"); + assert(new KT39423("Test", 42).copy("Test", null).b === null); + assert(new KT39423("Test").toString() === "KT39423(a=Test, b=null)"); + assert(new KT39423("Test", null).toString() === "KT39423(a=Test, b=null)"); + assert(new KT39423("Test", 42).toString() === "KT39423(a=Test, b=42)"); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes__main.ts b/js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes__main.ts new file mode 100644 index 00000000000..4a831cc15ee --- /dev/null +++ b/js/js.translator/testData/typescript-export/data-classes-in-exported-file/data-classes__main.ts @@ -0,0 +1,45 @@ +import TestDataClass = JS_TESTS.foo.TestDataClass; +import KT39423 = JS_TESTS.foo.KT39423; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + assert(new TestDataClass("Test").name === "Test"); + assert(new TestDataClass("Test").component1() === "Test"); + assert(new TestDataClass("Test").copy("NewTest").name === "NewTest"); + assert(new TestDataClass("Test").toString() === "TestDataClass(name=Test)"); + + assert(new TestDataClass("Test").hashCode() === new TestDataClass("Test").hashCode()); + assert(new TestDataClass("Test").hashCode() !== new TestDataClass("AnotherTest").hashCode()); + + assert(new TestDataClass("Test").equals(new TestDataClass("Test"))); + assert(!new TestDataClass("Test").equals(new TestDataClass("AnotherTest"))); + + assert(new TestDataClass.Nested().prop === "hello"); + + assert(new KT39423("Test").a === "Test") + assert(new KT39423("Test").b === null) + assert(new KT39423("Test", null).a === "Test") + assert(new KT39423("Test", null).b === null) + + assert(new KT39423("Test", 42).a === "Test") + assert(new KT39423("Test", 42).b === 42) + + assert(new KT39423("Test", 42).component1() === "Test") + assert(new KT39423("Test", 42).component2() === 42) + + assert(new KT39423("Test", 42).copy("NewTest").a === "NewTest") + assert(new KT39423("Test", 42).copy("NewTest").b === 42) + assert(new KT39423("Test", 42).copy("Test", null).a === "Test") + assert(new KT39423("Test", 42).copy("Test", null).b === null) + + assert(new KT39423("Test").toString() === "KT39423(a=Test, b=null)") + assert(new KT39423("Test", null).toString() === "KT39423(a=Test, b=null)") + assert(new KT39423("Test", 42).toString() === "KT39423(a=Test, b=42)") + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/data-classes-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/data-classes-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/data-classes-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes.d.ts b/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes.d.ts new file mode 100644 index 00000000000..b5bb99419d0 --- /dev/null +++ b/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes.d.ts @@ -0,0 +1,50 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + abstract class TestEnumClass { + private constructor(); + get constructorParameter(): string; + static get A(): foo.TestEnumClass & { + get name(): "A"; + get ordinal(): 0; + }; + static get B(): foo.TestEnumClass & { + get name(): "B"; + get ordinal(): 1; + }; + get foo(): number; + bar(value: string): string; + bay(): string; + static values(): Array; + static valueOf(value: string): foo.TestEnumClass; + get name(): "A" | "B"; + get ordinal(): 0 | 1; + } + namespace TestEnumClass { + class Nested { + constructor(); + get prop(): string; + } + } + class OuterClass { + constructor(); + } + namespace OuterClass { + abstract class NestedEnum { + private constructor(); + static get A(): foo.OuterClass.NestedEnum & { + get name(): "A"; + get ordinal(): 0; + }; + static get B(): foo.OuterClass.NestedEnum & { + get name(): "B"; + get ordinal(): 1; + }; + static values(): Array; + static valueOf(value: string): foo.OuterClass.NestedEnum; + get name(): "A" | "B"; + get ordinal(): 0 | 1; + } + } + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes.kt b/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes.kt new file mode 100644 index 00000000000..62180d895c9 --- /dev/null +++ b/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes.kt @@ -0,0 +1,38 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: enum-classes.kt + +@file:JsExport + +package foo + + +enum class TestEnumClass(val constructorParameter: String) { + A("aConstructorParameter"), + B("bConstructorParameter"); + + val foo = ordinal + + fun bar(value: String) = value + + fun bay() = name + + class Nested { + val prop: String = "hello2" + } +} + + +class OuterClass { + enum class NestedEnum { + A, + B + } +} + diff --git a/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes__main.js b/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes__main.js new file mode 100644 index 00000000000..a7e4d36f0c7 --- /dev/null +++ b/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes__main.js @@ -0,0 +1,36 @@ +"use strict"; +var TestEnumClass = JS_TESTS.foo.TestEnumClass; +var OuterClass = JS_TESTS.foo.OuterClass; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + assert(TestEnumClass.A.foo == 0); + assert(TestEnumClass.B.foo == 1); + assert(TestEnumClass.A.bar("aBar") == "aBar"); + assert(TestEnumClass.B.bar("bBar") == "bBar"); + assert(TestEnumClass.A.bay() == "A"); + assert(TestEnumClass.B.bay() == "B"); + assert(TestEnumClass.A.constructorParameter == "aConstructorParameter"); + assert(TestEnumClass.B.constructorParameter == "bConstructorParameter"); + assert(TestEnumClass.valueOf("A") === TestEnumClass.A); + assert(TestEnumClass.valueOf("B") === TestEnumClass.B); + assert(TestEnumClass.values().indexOf(TestEnumClass.A) != -1); + assert(TestEnumClass.values().indexOf(TestEnumClass.B) != -1); + assert(TestEnumClass.A.name === "A"); + assert(TestEnumClass.B.name === "B"); + assert(TestEnumClass.A.ordinal === 0); + assert(TestEnumClass.B.ordinal === 1); + assert(new TestEnumClass.Nested().prop == "hello2"); + assert(OuterClass.NestedEnum.valueOf("A") === OuterClass.NestedEnum.A); + assert(OuterClass.NestedEnum.valueOf("B") === OuterClass.NestedEnum.B); + assert(OuterClass.NestedEnum.values().indexOf(OuterClass.NestedEnum.A) != -1); + assert(OuterClass.NestedEnum.values().indexOf(OuterClass.NestedEnum.B) != -1); + assert(OuterClass.NestedEnum.A.name === "A"); + assert(OuterClass.NestedEnum.B.name === "B"); + assert(OuterClass.NestedEnum.A.ordinal === 0); + assert(OuterClass.NestedEnum.B.ordinal === 1); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes__main.ts b/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes__main.ts new file mode 100644 index 00000000000..7031fba5c9f --- /dev/null +++ b/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/enum-classes__main.ts @@ -0,0 +1,45 @@ +import TestEnumClass = JS_TESTS.foo.TestEnumClass; +import OuterClass = JS_TESTS.foo.OuterClass; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + assert(TestEnumClass.A.foo == 0) + assert(TestEnumClass.B.foo == 1) + assert(TestEnumClass.A.bar("aBar") == "aBar") + assert(TestEnumClass.B.bar("bBar") == "bBar") + assert(TestEnumClass.A.bay() == "A") + assert(TestEnumClass.B.bay() == "B") + assert(TestEnumClass.A.constructorParameter == "aConstructorParameter") + assert(TestEnumClass.B.constructorParameter == "bConstructorParameter") + + assert(TestEnumClass.valueOf("A") === TestEnumClass.A) + assert(TestEnumClass.valueOf("B") === TestEnumClass.B) + + assert(TestEnumClass.values().indexOf(TestEnumClass.A) != -1) + assert(TestEnumClass.values().indexOf(TestEnumClass.B) != -1) + + assert(TestEnumClass.A.name === "A") + assert(TestEnumClass.B.name === "B") + assert(TestEnumClass.A.ordinal === 0) + assert(TestEnumClass.B.ordinal === 1) + + assert(new TestEnumClass.Nested().prop == "hello2") + + assert(OuterClass.NestedEnum.valueOf("A") === OuterClass.NestedEnum.A) + assert(OuterClass.NestedEnum.valueOf("B") === OuterClass.NestedEnum.B) + + assert(OuterClass.NestedEnum.values().indexOf(OuterClass.NestedEnum.A) != -1) + assert(OuterClass.NestedEnum.values().indexOf(OuterClass.NestedEnum.B) != -1) + + assert(OuterClass.NestedEnum.A.name === "A") + assert(OuterClass.NestedEnum.B.name === "B") + assert(OuterClass.NestedEnum.A.ordinal === 0) + assert(OuterClass.NestedEnum.B.ordinal === 1) + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/enum-classes-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations.d.ts b/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations.d.ts new file mode 100644 index 00000000000..59299178cea --- /dev/null +++ b/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations.d.ts @@ -0,0 +1,34 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + + + + function invalid_args_name_sum(first_value: number, second_value: number): number; + + class A1 { + constructor(first_value: number, second_value: number); + get "first value"(): number; + get "second.value"(): number; + set "second.value"(value: number); + } + class A2 { + constructor(); + get "invalid:name"(): number; + set "invalid:name"(value: number); + } + class A3 { + constructor(); + "invalid@name sum"(x: number, y: number): number; + invalid_args_name_sum(first_value: number, second_value: number): number; + } + class A4 { + constructor(); + static get Companion(): { + get "@invalid+name@"(): number; + set "@invalid+name@"(value: number); + "^)run.something.weird^("(): string; + }; + } + } +} diff --git a/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations.kt b/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations.kt new file mode 100644 index 00000000000..f1b66da197b --- /dev/null +++ b/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations.kt @@ -0,0 +1,58 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// IGNORE_BACKEND: JS +// !LANGUAGE: +JsAllowInvalidCharsIdentifiersEscaping +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: escaped-interfaces.kt + +@file:JsExport + + +package foo + + +fun `invalid@name sum`(x: Int, y: Int): Int = + x + y + + +fun invalid_args_name_sum(`first value`: Int, `second value`: Int): Int = + `first value` + `second value` + +// Properties + + +val `invalid name val`: Int = 1 + +var `invalid@name var`: Int = 1 + +// Classes + + +class `Invalid A` + +class A1(val `first value`: Int, var `second.value`: Int) + +class A2 { + var `invalid:name`: Int = 42 +} + +class A3 { + fun `invalid@name sum`(x: Int, y: Int): Int = + x + y + + fun invalid_args_name_sum(`first value`: Int, `second value`: Int): Int = + `first value` + `second value` +} + + +class A4 { + companion object { + var `@invalid+name@` = 23 + fun `^)run.something.weird^(`(): String = ")_(" + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations__main.js b/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations__main.js new file mode 100644 index 00000000000..a9f68a6ae6c --- /dev/null +++ b/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations__main.js @@ -0,0 +1,29 @@ +"use strict"; +var foo = JS_TESTS.foo; +var A1 = JS_TESTS.foo.A1; +var A2 = JS_TESTS.foo.A2; +var A3 = JS_TESTS.foo.A3; +var A4 = JS_TESTS.foo.A4; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + assert(foo.invalid_args_name_sum(10, 20) === 30); + assert(foo["invalid@name sum"](10, 20) === 30); + assert(foo["invalid name val"] === 1); + assert(foo["invalid@name var"] === 1); + foo["invalid@name var"] = 4; + assert(foo["invalid@name var"] === 4); + new foo["Invalid A"](); + assert(new A1(10, 20)["first value"] === 10); + assert(new A1(10, 20)["second.value"] === 20); + assert(new A2()["invalid:name"] === 42); + var a3 = new A3(); + assert(a3.invalid_args_name_sum(10, 20) === 30); + assert(a3["invalid@name sum"](10, 20) === 30); + assert(A4.Companion["@invalid+name@"] == 23); + assert(A4.Companion["^)run.something.weird^("]() === ")_("); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations__main.ts b/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations__main.ts new file mode 100644 index 00000000000..3cf8eedc13d --- /dev/null +++ b/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/escaped-declarations__main.ts @@ -0,0 +1,37 @@ +import foo = JS_TESTS.foo; +import A1 = JS_TESTS.foo.A1; +import A2 = JS_TESTS.foo.A2; +import A3 = JS_TESTS.foo.A3; +import A4 = JS_TESTS.foo.A4; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + assert(foo.invalid_args_name_sum(10, 20) === 30); + assert((foo as any)["invalid@name sum"](10, 20) === 30); + + assert((foo as any)["invalid name val"] === 1); + assert((foo as any)["invalid@name var"] === 1); + (foo as any)["invalid@name var"] = 4 + assert((foo as any)["invalid@name var"] === 4); + + new (foo as any)["Invalid A"](); + + assert(new A1(10, 20)["first value"] === 10); + assert(new A1(10, 20)["second.value"] === 20); + + assert(new A2()["invalid:name"] === 42); + + const a3 = new A3() + assert(a3.invalid_args_name_sum(10, 20) === 30); + assert(a3["invalid@name sum"](10, 20) === 30); + + assert(A4.Companion["@invalid+name@"] == 23); + assert(A4.Companion["^)run.something.weird^("]() === ")_("); + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/escaped-declarations-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/escaped-declarations/escaped-declarations.kt b/js/js.translator/testData/typescript-export/escaped-declarations/escaped-declarations.kt index 6b30617f2c4..6bbbe92fc30 100644 --- a/js/js.translator/testData/typescript-export/escaped-declarations/escaped-declarations.kt +++ b/js/js.translator/testData/typescript-export/escaped-declarations/escaped-declarations.kt @@ -8,28 +8,35 @@ // MODULE: JS_TESTS // FILE: escaped-interfaces.kt -@file:JsExport package foo +@JsExport fun `invalid@name sum`(x: Int, y: Int): Int = x + y +@JsExport fun invalid_args_name_sum(`first value`: Int, `second value`: Int): Int = `first value` + `second value` // Properties +@JsExport val `invalid name val`: Int = 1 +@JsExport var `invalid@name var`: Int = 1 // Classes +@JsExport class `Invalid A` +@JsExport class A1(val `first value`: Int, var `second.value`: Int) +@JsExport class A2 { var `invalid:name`: Int = 42 } +@JsExport class A3 { fun `invalid@name sum`(x: Int, y: Int): Int = x + y @@ -38,6 +45,7 @@ class A3 { `first value` + `second value` } +@JsExport class A4 { companion object { var `@invalid+name@` = 23 diff --git a/js/js.translator/testData/typescript-export/functions-in-exported-file/functions.d.ts b/js/js.translator/testData/typescript-export/functions-in-exported-file/functions.d.ts new file mode 100644 index 00000000000..8d97d19cdc3 --- /dev/null +++ b/js/js.translator/testData/typescript-export/functions-in-exported-file/functions.d.ts @@ -0,0 +1,22 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + interface SomeExternalInterface { + } + } + namespace foo { + function sum(x: number, y: number): number; + function varargInt(x: Int32Array): number; + function varargNullableInt(x: Array>): number; + function varargWithOtherParameters(x: string, y: Array, z: string): number; + function varargWithComplexType(x: Array<(p0: Array) => Array>): number; + function sumNullable(x: Nullable, y: Nullable): number; + function defaultParameters(a: string, x?: number, y?: string): string; + function generic1(x: T): T; + function generic2(x: Nullable): boolean; + function genericWithConstraint(x: T): T; + function genericWithMultipleConstraints */ & foo.SomeExternalInterface & Error>(x: T): T; + function generic3(a: A, b: B, c: C, d: D): Nullable; + function inlineFun(x: number, callback: (p0: number) => void): void; + } +} diff --git a/js/js.translator/testData/typescript-export/functions-in-exported-file/functions.kt b/js/js.translator/testData/typescript-export/functions-in-exported-file/functions.kt new file mode 100644 index 00000000000..889ef90a50a --- /dev/null +++ b/js/js.translator/testData/typescript-export/functions-in-exported-file/functions.kt @@ -0,0 +1,67 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: functions.kt + +@file:JsExport + +package foo + + +external interface SomeExternalInterface + + +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) -> Array): Int = + x.size + + +fun sumNullable(x: Int?, y: Int?): Int = + (x ?: 0) + (y ?: 0) + + +fun defaultParameters(a: String, x: Int = 10, y: String = "OK"): String = + a + x.toString() + y + + +fun generic1(x: T): T = x + + +fun generic2(x: T?): Boolean = (x == null) + + +fun genericWithConstraint(x: T): T = x + + +fun genericWithMultipleConstraints(x: T): T + where T : Comparable, + T : SomeExternalInterface, + T : Throwable = x + + +fun generic3(a: A, b: B, c: C, d: D): E? = null + + +inline fun inlineFun(x: Int, callback: (Int) -> Unit) { + callback(x) +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/functions-in-exported-file/functions__main.js b/js/js.translator/testData/typescript-export/functions-in-exported-file/functions__main.js new file mode 100644 index 00000000000..a26cd950666 --- /dev/null +++ b/js/js.translator/testData/typescript-export/functions-in-exported-file/functions__main.js @@ -0,0 +1,59 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var sum = JS_TESTS.foo.sum; +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 varargInt = JS_TESTS.foo.varargInt; +var sumNullable = JS_TESTS.foo.sumNullable; +var defaultParameters = JS_TESTS.foo.defaultParameters; +var varargNullableInt = JS_TESTS.foo.varargNullableInt; +var varargWithOtherParameters = JS_TESTS.foo.varargWithOtherParameters; +var varargWithComplexType = JS_TESTS.foo.varargWithComplexType; +var genericWithConstraint = JS_TESTS.foo.genericWithConstraint; +var genericWithMultipleConstraints = JS_TESTS.foo.genericWithMultipleConstraints; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + assert(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 () { return [new Int32Array([1, 2, 3])]; }, + function () { 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)); + assert(generic2(undefined)); + assert(!generic2(10)); + assert(generic3(10, true, "__", {}) === null); + assert(genericWithConstraint("Test") === "Test"); + var regExpMatchError = __assign(__assign({}, new Error("Test")), "test test".match(/tes/g)); + assert(genericWithMultipleConstraints(regExpMatchError) === regExpMatchError); + var result = 0; + inlineFun(10, function (x) { result = x; }); + assert(result === 10); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/functions-in-exported-file/functions__main.ts b/js/js.translator/testData/typescript-export/functions-in-exported-file/functions__main.ts new file mode 100644 index 00000000000..ebaef885299 --- /dev/null +++ b/js/js.translator/testData/typescript-export/functions-in-exported-file/functions__main.ts @@ -0,0 +1,58 @@ +import sum = JS_TESTS.foo.sum; +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 varargInt = JS_TESTS.foo.varargInt; +import sumNullable = JS_TESTS.foo.sumNullable; +import defaultParameters = JS_TESTS.foo.defaultParameters; +import varargNullableInt = JS_TESTS.foo.varargNullableInt; +import varargWithOtherParameters = JS_TESTS.foo.varargWithOtherParameters; +import varargWithComplexType = JS_TESTS.foo.varargWithComplexType; +import genericWithConstraint = JS_TESTS.foo.genericWithConstraint; +import genericWithMultipleConstraints = JS_TESTS.foo.genericWithMultipleConstraints; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + assert(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, + () => [new Int32Array([1, 2, 3])], + () => [], + ]) === 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)); + assert(generic2(undefined)); + assert(!generic2(10)); + assert(generic3(10, true, "__", {}) === null); + + assert(genericWithConstraint("Test") === "Test") + + const regExpMatchError: any = { ...new Error("Test"), ..."test test".match(/tes/g) } + assert(genericWithMultipleConstraints(regExpMatchError) === regExpMatchError) + + + let result: number = 0; + inlineFun(10, x => { result = x; }); + assert(result === 10); + + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/functions-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/functions-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/functions-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/functions/functions.d.ts b/js/js.translator/testData/typescript-export/functions/functions.d.ts index 9324dbe0ad9..8d97d19cdc3 100644 --- a/js/js.translator/testData/typescript-export/functions/functions.d.ts +++ b/js/js.translator/testData/typescript-export/functions/functions.d.ts @@ -1,5 +1,9 @@ declare namespace JS_TESTS { type Nullable = T | null | undefined + namespace foo { + interface SomeExternalInterface { + } + } namespace foo { function sum(x: number, y: number): number; function varargInt(x: Int32Array): number; @@ -11,7 +15,7 @@ declare namespace JS_TESTS { function generic1(x: T): T; function generic2(x: Nullable): boolean; function genericWithConstraint(x: T): T; - function genericWithMultipleConstraints */ & RegExpMatchArray & Error>(x: T): T; + function genericWithMultipleConstraints */ & foo.SomeExternalInterface & Error>(x: T): T; function generic3(a: A, b: B, c: C, d: D): Nullable; function inlineFun(x: number, callback: (p0: number) => void): void; } diff --git a/js/js.translator/testData/typescript-export/functions/functions.kt b/js/js.translator/testData/typescript-export/functions/functions.kt index 4cdf003b009..d96a434367d 100644 --- a/js/js.translator/testData/typescript-export/functions/functions.kt +++ b/js/js.translator/testData/typescript-export/functions/functions.kt @@ -8,7 +8,8 @@ package foo -external interface RegExpMatchArray +@JsExport +external interface SomeExternalInterface @JsExport fun sum(x: Int, y: Int): Int = @@ -50,7 +51,7 @@ fun genericWithConstraint(x: T): T = x @JsExport fun genericWithMultipleConstraints(x: T): T where T : Comparable, - T : RegExpMatchArray, + T : SomeExternalInterface, T : Throwable = x @JsExport diff --git a/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class.d.ts b/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class.d.ts new file mode 100644 index 00000000000..90d214bbc9c --- /dev/null +++ b/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class.d.ts @@ -0,0 +1,30 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + class TestInner { + constructor(a: string); + get a(): string; + get Inner(): { + new(a: string): TestInner.Inner; + } & typeof TestInner.Inner; + } + namespace TestInner { + class Inner { + protected constructor($outer: foo.TestInner, a: string); + get a(): string; + get concat(): string; + static fromNumber(a: number): foo.TestInner.Inner; + get SecondLayerInner(): { + new(a: string): TestInner.Inner.SecondLayerInner; + } & typeof TestInner.Inner.SecondLayerInner; + } + namespace Inner { + class SecondLayerInner { + protected constructor($outer: foo.TestInner.Inner, a: string); + get a(): string; + get concat(): string; + } + } + } + } +} diff --git a/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class.kt b/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class.kt new file mode 100644 index 00000000000..5f7e9be32d8 --- /dev/null +++ b/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class.kt @@ -0,0 +1,29 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// IGNORE_BACKEND: JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: inner-class.kt + +@file:JsExport + +package foo + + +class TestInner(val a: String) { + inner class Inner(val a: String) { + val concat: String = this@TestInner.a + this.a + + @JsName("fromNumber") + constructor(a: Int): this(a.toString()) + + @JsName("SecondLayerInner") + inner class InnerInner(val a: String) { + val concat: String = this@TestInner.a + this@Inner.a + this.a + } + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class__main.js b/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class__main.js new file mode 100644 index 00000000000..6269ae6cb0e --- /dev/null +++ b/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class__main.js @@ -0,0 +1,24 @@ +"use strict"; +var TestInner = JS_TESTS.foo.TestInner; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + var outer = new TestInner("Hello "); + var inner = new outer.Inner("World"); + var innerFromNumber = outer.Inner.fromNumber(1654); + var secondInner = new inner.SecondLayerInner("!"); + assert(outer instanceof TestInner); + assert(inner instanceof TestInner.Inner); + assert(innerFromNumber instanceof TestInner.Inner); + assert(secondInner instanceof TestInner.Inner.SecondLayerInner); + assert(inner.a == "World"); + assert(inner.concat == "Hello World"); + assert(innerFromNumber.a == "1654"); + assert(innerFromNumber.concat == "Hello 1654"); + assert(secondInner.a == "!"); + assert(secondInner.concat == "Hello World!"); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class__main.ts b/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class__main.ts new file mode 100644 index 00000000000..b26adc9955b --- /dev/null +++ b/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/inner-class__main.ts @@ -0,0 +1,30 @@ +import TestInner = JS_TESTS.foo.TestInner; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + const outer = new TestInner("Hello ") + const inner = new outer.Inner("World") + const innerFromNumber = outer.Inner.fromNumber(1654) + const secondInner = new inner.SecondLayerInner("!") + + assert(outer instanceof TestInner) + assert(inner instanceof TestInner.Inner) + assert(innerFromNumber instanceof TestInner.Inner) + assert(secondInner instanceof TestInner.Inner.SecondLayerInner) + + assert(inner.a == "World") + assert(inner.concat == "Hello World") + + assert(innerFromNumber.a == "1654") + assert(innerFromNumber.concat == "Hello 1654") + + assert(secondInner.a == "!") + assert(secondInner.concat == "Hello World!") + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/inner-classes-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.d.ts b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.d.ts new file mode 100644 index 00000000000..06fd2f146aa --- /dev/null +++ b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.d.ts @@ -0,0 +1,28 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + interface TestInterface { + readonly value: string; + getOwnerName(): string; + readonly __doNotUseOrImplementIt: { + readonly "foo.TestInterface": unique symbol; + }; + } + interface AnotherExportedInterface { + readonly __doNotUseOrImplementIt: { + readonly "foo.AnotherExportedInterface": unique symbol; + }; + } + class TestInterfaceImpl implements foo.TestInterface { + constructor(value: string); + get value(): string; + getOwnerName(): string; + readonly __doNotUseOrImplementIt: foo.TestInterface["__doNotUseOrImplementIt"]; + } + class ChildTestInterfaceImpl extends foo.TestInterfaceImpl implements foo.AnotherExportedInterface { + constructor(); + readonly __doNotUseOrImplementIt: foo.TestInterfaceImpl["__doNotUseOrImplementIt"] & foo.AnotherExportedInterface["__doNotUseOrImplementIt"]; + } + function processInterface(test: foo.TestInterface): string; + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt new file mode 100644 index 00000000000..d60a07badf8 --- /dev/null +++ b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces.kt @@ -0,0 +1,37 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: interfaces.kt + +@file:JsExport + +package foo + +// Classes + + +interface TestInterface { + val value: String + fun getOwnerName(): String +} + + +interface AnotherExportedInterface + + +open class TestInterfaceImpl(override val value: String) : TestInterface { + override fun getOwnerName() = "TestInterfaceImpl" +} + + +class ChildTestInterfaceImpl(): TestInterfaceImpl("Test"), AnotherExportedInterface + + +fun processInterface(test: TestInterface): String { + return "Owner ${test.getOwnerName()} has value '${test.value}'" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.js b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.js new file mode 100644 index 00000000000..f3aba8a8c27 --- /dev/null +++ b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.js @@ -0,0 +1,16 @@ +"use strict"; +var TestInterfaceImpl = JS_TESTS.foo.TestInterfaceImpl; +var ChildTestInterfaceImpl = JS_TESTS.foo.ChildTestInterfaceImpl; +var processInterface = JS_TESTS.foo.processInterface; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + assert(processInterface(new TestInterfaceImpl("bar")) === "Owner TestInterfaceImpl has value 'bar'"); + assert(processInterface(new ChildTestInterfaceImpl()) === "Owner TestInterfaceImpl has value 'Test'"); + // @ts-expect-error "Just test that this code will throw compilation error for a user" + assert(processInterface({ value: "bar", getOwnerName: function () { return "RandomObject"; } }) === "Owner RandomObject has value 'bar'"); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.ts b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.ts new file mode 100644 index 00000000000..c16a4278309 --- /dev/null +++ b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/interfaces__main.ts @@ -0,0 +1,19 @@ +import TestInterfaceImpl = JS_TESTS.foo.TestInterfaceImpl; +import ChildTestInterfaceImpl = JS_TESTS.foo.ChildTestInterfaceImpl; +import processInterface = JS_TESTS.foo.processInterface; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + assert(processInterface(new TestInterfaceImpl("bar")) === "Owner TestInterfaceImpl has value 'bar'") + assert(processInterface(new ChildTestInterfaceImpl()) === "Owner TestInterfaceImpl has value 'Test'") + + // @ts-expect-error "Just test that this code will throw compilation error for a user" + assert(processInterface({ value: "bar", getOwnerName: () => "RandomObject" }) === "Owner RandomObject has value 'bar'") + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/interfaces-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..706556bf1f5 --- /dev/null +++ b/js/js.translator/testData/typescript-export/interfaces-in-exported-file/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name.d.ts b/js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name.d.ts new file mode 100644 index 00000000000..5f9b219bd5a --- /dev/null +++ b/js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name.d.ts @@ -0,0 +1,26 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + interface Object { + readonly constructor: any; + } + } + namespace foo { + class JsNameTest { + private constructor(); + get value(): number; + runTest(): string; + acceptObject(impl: foo.Object): string; + static get NotCompanion(): { + create(): foo.JsNameTest; + createChild(value: number): foo.JsNameTest.NestedJsName; + }; + } + namespace JsNameTest { + class NestedJsName { + constructor(__value: number); + get value(): number; + } + } + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name.kt b/js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name.kt new file mode 100644 index 00000000000..1caada9acbb --- /dev/null +++ b/js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name.kt @@ -0,0 +1,52 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: js-name.kt + +@file:JsExport + +package foo + + +@JsName("Object") +external interface WeirdInterface { + val constructor: dynamic +} + + +@JsName("JsNameTest") +class __JsNameTest private constructor() { + @JsName("value") + val __value = 4 + + @JsName("runTest") + fun __runTest(): String { + return "JsNameTest" + } + + @JsName("acceptObject") + fun __acceptWeirdImpl(impl: WeirdInterface): String { + return impl.constructor.name + } + + @JsName("NotCompanion") + companion object { + @JsName("create") + fun __create(): __JsNameTest { + return __JsNameTest() + } + + @JsName("createChild") + fun __createChild(value: Int): __NestJsNameTest { + return __NestJsNameTest(value) + } + } + + @JsName("NestedJsName") + class __NestJsNameTest(@JsName("value") val __value: Int) +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name__main.js b/js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name__main.js new file mode 100644 index 00000000000..be1a103b50b --- /dev/null +++ b/js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name__main.js @@ -0,0 +1,16 @@ +"use strict"; +var JsNameTest = JS_TESTS.foo.JsNameTest; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + var jsNameTest = JsNameTest.NotCompanion.create(); + assert(jsNameTest.value === 4); + assert(jsNameTest.runTest() === "JsNameTest"); + assert(jsNameTest.acceptObject(Object) === "Function"); + var jsNameNestedTest = JsNameTest.NotCompanion.createChild(42); + assert(jsNameNestedTest.value === 42); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name__main.ts b/js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name__main.ts new file mode 100644 index 00000000000..564e7d6d27b --- /dev/null +++ b/js/js.translator/testData/typescript-export/js-name-in-exported-file/js-name__main.ts @@ -0,0 +1,21 @@ +import JsNameTest = JS_TESTS.foo.JsNameTest; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + const jsNameTest = JsNameTest.NotCompanion.create(); + + assert(jsNameTest.value === 4) + assert(jsNameTest.runTest() === "JsNameTest") + assert(jsNameTest.acceptObject(Object) === "Function") + + const jsNameNestedTest = JsNameTest.NotCompanion.createChild(42); + + assert(jsNameNestedTest.value === 42) + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/js-name-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/js-name-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..706556bf1f5 --- /dev/null +++ b/js/js.translator/testData/typescript-export/js-name-in-exported-file/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/js-name/js-name.d.ts b/js/js.translator/testData/typescript-export/js-name/js-name.d.ts index 68a04698a8f..5f9b219bd5a 100644 --- a/js/js.translator/testData/typescript-export/js-name/js-name.d.ts +++ b/js/js.translator/testData/typescript-export/js-name/js-name.d.ts @@ -1,11 +1,16 @@ declare namespace JS_TESTS { type Nullable = T | null | undefined + namespace foo { + interface Object { + readonly constructor: any; + } + } namespace foo { class JsNameTest { private constructor(); get value(): number; runTest(): string; - acceptObject(impl: Object): string; + acceptObject(impl: foo.Object): string; static get NotCompanion(): { create(): foo.JsNameTest; createChild(value: number): foo.JsNameTest.NestedJsName; diff --git a/js/js.translator/testData/typescript-export/js-name/js-name.kt b/js/js.translator/testData/typescript-export/js-name/js-name.kt index d6f42c9f6a0..843d02da957 100644 --- a/js/js.translator/testData/typescript-export/js-name/js-name.kt +++ b/js/js.translator/testData/typescript-export/js-name/js-name.kt @@ -8,6 +8,7 @@ package foo +@JsExport @JsName("Object") external interface WeirdInterface { val constructor: dynamic diff --git a/js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties.d.ts b/js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties.d.ts new file mode 100644 index 00000000000..637e9378b64 --- /dev/null +++ b/js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties.d.ts @@ -0,0 +1,17 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + class Test { + constructor(); + get _val(): number; + get _var(): number; + set _var(value: number); + get _valCustom(): number; + get _valCustomWithField(): number; + get _varCustom(): number; + set _varCustom(value: number); + get _varCustomWithField(): number; + set _varCustomWithField(value: number); + } + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties.kt b/js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties.kt new file mode 100644 index 00000000000..0ba6529adfd --- /dev/null +++ b/js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties.kt @@ -0,0 +1,34 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: member-properties.kt + +@file:JsExport + +package foo + + +class Test { + 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 } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties__main.js b/js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties__main.js new file mode 100644 index 00000000000..3c8760b3878 --- /dev/null +++ b/js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties__main.js @@ -0,0 +1,23 @@ +"use strict"; +var Test = JS_TESTS.foo.Test; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + var test = new Test(); + assert(test._val === 1); + assert(test._var === 1); + test._var = 1000; + assert(test._var === 1000); + assert(test._valCustom === 1); + assert(test._valCustomWithField === 2); + assert(test._varCustom === 1); + test._varCustom = 20; + assert(test._varCustom === 1); + assert(test._varCustomWithField === 10); + test._varCustomWithField = 10; + assert(test._varCustomWithField === 1000); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties__main.ts b/js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties__main.ts new file mode 100644 index 00000000000..aaefb1105a3 --- /dev/null +++ b/js/js.translator/testData/typescript-export/member-properties-in-exported-file/member-properties__main.ts @@ -0,0 +1,27 @@ +import Test = JS_TESTS.foo.Test; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + const test = new Test() + assert(test._val === 1); + assert(test._var === 1); + test._var = 1000; + assert(test._var === 1000); + + assert(test._valCustom === 1); + assert(test._valCustomWithField === 2); + assert(test._varCustom === 1); + test._varCustom = 20; + assert(test._varCustom === 1); + assert(test._varCustomWithField === 10); + test._varCustomWithField = 10; + assert(test._varCustomWithField === 1000); + + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/member-properties-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/member-properties-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/member-properties-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/methods-in-exported-file/methods.d.ts b/js/js.translator/testData/typescript-export/methods-in-exported-file/methods.d.ts new file mode 100644 index 00000000000..3f0c8d556e5 --- /dev/null +++ b/js/js.translator/testData/typescript-export/methods-in-exported-file/methods.d.ts @@ -0,0 +1,25 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + interface SomeExternalInterface { + } + } + namespace foo { + class Test { + constructor(); + sum(x: number, y: number): number; + varargInt(x: Int32Array): number; + varargNullableInt(x: Array>): number; + varargWithOtherParameters(x: string, y: Array, z: string): number; + varargWithComplexType(x: Array<(p0: Array) => Array>): number; + sumNullable(x: Nullable, y: Nullable): number; + defaultParameters(a: string, x?: number, y?: string): string; + generic1(x: T): T; + generic2(x: Nullable): boolean; + genericWithConstraint(x: T): T; + genericWithMultipleConstraints */ & foo.SomeExternalInterface & Error>(x: T): T; + generic3(a: A, b: B, c: C, d: D): Nullable; + inlineFun(x: number, callback: (p0: number) => void): void; + } + } +} diff --git a/js/js.translator/testData/typescript-export/methods-in-exported-file/methods.kt b/js/js.translator/testData/typescript-export/methods-in-exported-file/methods.kt new file mode 100644 index 00000000000..37875559816 --- /dev/null +++ b/js/js.translator/testData/typescript-export/methods-in-exported-file/methods.kt @@ -0,0 +1,57 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: member-properties.kt + +@file:JsExport + +package foo + + +external interface SomeExternalInterface + + +class Test { + 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) -> Array): Int = + x.size + + fun sumNullable(x: Int?, y: Int?): Int = + (x ?: 0) + (y ?: 0) + + fun defaultParameters(a: String, x: Int = 10, y: String = "OK"): String = + a + x.toString() + y + + fun generic1(x: T): T = x + + fun generic2(x: T?): Boolean = (x == null) + + fun genericWithConstraint(x: T): T = x + + fun genericWithMultipleConstraints(x: T): T + where T : Comparable, + T : SomeExternalInterface, + T : Throwable = x + + fun generic3(a: A, b: B, c: C, d: D): E? = null + + inline fun inlineFun(x: Int, callback: (Int) -> Unit) { + callback(x) + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/methods-in-exported-file/methods__main.js b/js/js.translator/testData/typescript-export/methods-in-exported-file/methods__main.js new file mode 100644 index 00000000000..256edb10814 --- /dev/null +++ b/js/js.translator/testData/typescript-export/methods-in-exported-file/methods__main.js @@ -0,0 +1,48 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var Test = JS_TESTS.foo.Test; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + var test = new Test(); + assert(test.sum(10, 20) === 30); + assert(test.varargInt(new Int32Array([1, 2, 3])) === 3); + assert(test.varargNullableInt([10, 20, 30, null, undefined, 40]) === 6); + assert(test.varargWithOtherParameters("1234", ["1", "2", "3"], "12") === 9); + assert(test.varargWithComplexType([]) === 0); + assert(test.varargWithComplexType([ + function (x) { return x; }, + function (x) { return [new Int32Array([1, 2, 3])]; }, + function (x) { return []; }, + ]) === 3); + assert(test.sumNullable(10, null) === 10); + assert(test.sumNullable(undefined, 20) === 20); + assert(test.sumNullable(1, 2) === 3); + assert(test.defaultParameters("", 20, "OK") === "20OK"); + assert(test.generic1("FOO") === "FOO"); + assert(test.generic1({ x: 10 }).x === 10); + assert(test.generic2(null) === true); + assert(test.generic2(undefined) === true); + assert(test.generic2(10) === false); + assert(test.generic3(10, true, "__", {}) === null); + assert(test.genericWithConstraint("Test") === "Test"); + var regExpMatchError = __assign(__assign({}, new Error("Test")), "test test".match(/tes/g)); + assert(test.genericWithMultipleConstraints(regExpMatchError) === regExpMatchError); + var result = 0; + test.inlineFun(10, function (x) { result = x; }); + assert(result === 10); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/methods-in-exported-file/methods__main.ts b/js/js.translator/testData/typescript-export/methods-in-exported-file/methods__main.ts new file mode 100644 index 00000000000..c91e6facd1c --- /dev/null +++ b/js/js.translator/testData/typescript-export/methods-in-exported-file/methods__main.ts @@ -0,0 +1,46 @@ +import Test = JS_TESTS.foo.Test; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + const test = new Test() + assert(test.sum(10, 20) === 30); + + assert(test.varargInt(new Int32Array([1, 2, 3])) === 3); + assert(test.varargNullableInt([10, 20, 30, null, undefined, 40]) === 6); + assert(test.varargWithOtherParameters("1234", ["1", "2", "3"], "12") === 9); + assert(test.varargWithComplexType([]) === 0); + assert(test.varargWithComplexType([ + x => x, + x => [new Int32Array([1, 2, 3])], + x => [], + ]) === 3); + + assert(test.sumNullable(10, null) === 10); + assert(test.sumNullable(undefined, 20) === 20); + assert(test.sumNullable(1, 2) === 3); + + assert(test.defaultParameters("", 20, "OK") === "20OK"); + + assert(test.generic1("FOO") === "FOO"); + assert(test.generic1({x: 10}).x === 10); + assert(test.generic2(null) === true); + assert(test.generic2(undefined) === true); + assert(test.generic2(10) === false); + assert(test.generic3(10, true, "__", {}) === null); + + assert(test.genericWithConstraint("Test") === "Test") + + const regExpMatchError: any = { ...new Error("Test"), ..."test test".match(/tes/g) } + assert(test.genericWithMultipleConstraints(regExpMatchError) === regExpMatchError) + + let result: number = 0; + test.inlineFun(10, x => { result = x; }); + assert(result === 10); + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/methods-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/methods-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/methods-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/methods/methods.d.ts b/js/js.translator/testData/typescript-export/methods/methods.d.ts index 8dcf0e3ba09..3f0c8d556e5 100644 --- a/js/js.translator/testData/typescript-export/methods/methods.d.ts +++ b/js/js.translator/testData/typescript-export/methods/methods.d.ts @@ -1,5 +1,9 @@ declare namespace JS_TESTS { type Nullable = T | null | undefined + namespace foo { + interface SomeExternalInterface { + } + } namespace foo { class Test { constructor(); @@ -13,7 +17,7 @@ declare namespace JS_TESTS { generic1(x: T): T; generic2(x: Nullable): boolean; genericWithConstraint(x: T): T; - genericWithMultipleConstraints */ & RegExpMatchArray & Error>(x: T): T; + genericWithMultipleConstraints */ & foo.SomeExternalInterface & Error>(x: T): T; generic3(a: A, b: B, c: C, d: D): Nullable; inlineFun(x: number, callback: (p0: number) => void): void; } diff --git a/js/js.translator/testData/typescript-export/methods/methods.kt b/js/js.translator/testData/typescript-export/methods/methods.kt index 46433ad437a..ce0795e3b4e 100644 --- a/js/js.translator/testData/typescript-export/methods/methods.kt +++ b/js/js.translator/testData/typescript-export/methods/methods.kt @@ -8,7 +8,8 @@ package foo -external interface RegExpMatchArray +@JsExport +external interface SomeExternalInterface @JsExport class Test { @@ -41,7 +42,7 @@ class Test { fun genericWithMultipleConstraints(x: T): T where T : Comparable, - T : RegExpMatchArray, + T : SomeExternalInterface, T : Throwable = x fun generic3(a: A, b: B, c: C, d: D): E? = null diff --git a/js/js.translator/testData/typescript-export/module-systems-in-exported-file/commonjs.d.ts b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/commonjs.d.ts new file mode 100644 index 00000000000..ae765fd8c67 --- /dev/null +++ b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/commonjs.d.ts @@ -0,0 +1,10 @@ +type Nullable = T | null | undefined +export namespace foo { + const prop: number; + class C { + constructor(x: number); + get x(): number; + doubleX(): number; + } + function box(): string; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/module-systems-in-exported-file/commonjs.kt b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/commonjs.kt new file mode 100644 index 00000000000..3ea53129847 --- /dev/null +++ b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/commonjs.kt @@ -0,0 +1,24 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// MODULE_KIND: COMMON_JS +// FILE: commonjs.kt + +@file:JsExport + +package foo + + +val prop = 10 + + +class C(val x: Int) { + fun doubleX() = x * 2 +} + + +fun box(): String = "OK" \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/module-systems-in-exported-file/plain.d.ts b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/plain.d.ts new file mode 100644 index 00000000000..64afdef3c5e --- /dev/null +++ b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/plain.d.ts @@ -0,0 +1,12 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + const prop: number; + class C { + constructor(x: number); + get x(): number; + doubleX(): number; + } + function box(): string; + } +} diff --git a/js/js.translator/testData/typescript-export/module-systems-in-exported-file/plain.kt b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/plain.kt new file mode 100644 index 00000000000..65082da1c3d --- /dev/null +++ b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/plain.kt @@ -0,0 +1,23 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: plain.kt + +@file:JsExport + +package foo + + +val prop = 10 + + +class C(val x: Int) { + fun doubleX() = x * 2 +} + + +fun box(): String = "OK" \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/module-systems-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..e69de29bb2d diff --git a/js/js.translator/testData/typescript-export/module-systems-in-exported-file/umd.d.ts b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/umd.d.ts new file mode 100644 index 00000000000..c5113307e26 --- /dev/null +++ b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/umd.d.ts @@ -0,0 +1,11 @@ +type Nullable = T | null | undefined +export namespace foo { + const prop: number; + class C { + constructor(x: number); + get x(): number; + doubleX(): number; + } + function box(): string; +} +export as namespace JS_TESTS; \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/module-systems-in-exported-file/umd.kt b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/umd.kt new file mode 100644 index 00000000000..c3bf7df062f --- /dev/null +++ b/js/js.translator/testData/typescript-export/module-systems-in-exported-file/umd.kt @@ -0,0 +1,24 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// MODULE_KIND: UMD +// FILE: umd.kt + +@file:JsExport + +package foo + + +val prop = 10 + + +class C(val x: Int) { + fun doubleX() = x * 2 +} + + +fun box(): String = "OK" \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/module-systems/commonjs.kt b/js/js.translator/testData/typescript-export/module-systems/commonjs.kt index 03e8ad739c0..56d08ef17a3 100644 --- a/js/js.translator/testData/typescript-export/module-systems/commonjs.kt +++ b/js/js.translator/testData/typescript-export/module-systems/commonjs.kt @@ -6,14 +6,15 @@ // MODULE_KIND: COMMON_JS // FILE: commonjs.kt -@file:JsExport - package foo +@JsExport val prop = 10 +@JsExport class C(val x: Int) { fun doubleX() = x * 2 } +@JsExport fun box(): String = "OK" \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/module-systems/plain.kt b/js/js.translator/testData/typescript-export/module-systems/plain.kt index 34e9d94b32d..0f7e57b51f3 100644 --- a/js/js.translator/testData/typescript-export/module-systems/plain.kt +++ b/js/js.translator/testData/typescript-export/module-systems/plain.kt @@ -5,14 +5,15 @@ // MODULE: JS_TESTS // FILE: plain.kt -@file:JsExport - package foo +@JsExport val prop = 10 +@JsExport class C(val x: Int) { fun doubleX() = x * 2 } +@JsExport fun box(): String = "OK" \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/module-systems/umd.kt b/js/js.translator/testData/typescript-export/module-systems/umd.kt index c0b5d432349..e94b26f97b5 100644 --- a/js/js.translator/testData/typescript-export/module-systems/umd.kt +++ b/js/js.translator/testData/typescript-export/module-systems/umd.kt @@ -6,14 +6,15 @@ // MODULE_KIND: UMD // FILE: umd.kt -@file:JsExport - package foo +@JsExport val prop = 10 +@JsExport class C(val x: Int) { fun doubleX() = x * 2 } +@JsExport fun box(): String = "OK" \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces.d.ts b/js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces.d.ts new file mode 100644 index 00000000000..8c5483b0bf1 --- /dev/null +++ b/js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces.d.ts @@ -0,0 +1,37 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo.bar.baz { + class C1 { + constructor(value: string); + get value(): string; + component1(): string; + copy(value?: string): foo.bar.baz.C1; + toString(): string; + hashCode(): number; + equals(other: Nullable): boolean; + } + function f(x1: foo.bar.baz.C1, x2: a.b.C2, x3: C3): string; + } + namespace a.b { + class C2 { + constructor(value: string); + get value(): string; + component1(): string; + copy(value?: string): a.b.C2; + toString(): string; + hashCode(): number; + equals(other: Nullable): boolean; + } + function f(x1: foo.bar.baz.C1, x2: a.b.C2, x3: C3): string; + } + class C3 { + constructor(value: string); + get value(): string; + component1(): string; + copy(value?: string): C3; + toString(): string; + hashCode(): number; + equals(other: Nullable): boolean; + } + function f(x1: foo.bar.baz.C1, x2: a.b.C2, x3: C3): string; +} diff --git a/js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces.kt b/js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces.kt new file mode 100644 index 00000000000..abd5be232f4 --- /dev/null +++ b/js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces.kt @@ -0,0 +1,56 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE + +// MODULE: JS_TESTS +// FILE: file1.kt + +@file:JsExport + +package foo.bar.baz + +import a.b.* +import C3 + + +data class C1(val value: String) + + +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.* + + +data class C3(val value: String) + + +fun f(x1: C1, x2: C2, x3: C3): String { + return "f($x1, $x2, $x3)" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces__main.js b/js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces__main.js new file mode 100644 index 00000000000..599108f9f09 --- /dev/null +++ b/js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces__main.js @@ -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"; +} diff --git a/js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces__main.ts b/js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces__main.ts new file mode 100644 index 00000000000..f5168a7478f --- /dev/null +++ b/js/js.translator/testData/typescript-export/namespaces-in-exported-file/namespaces__main.ts @@ -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"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/namespaces-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/namespaces-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/namespaces-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/namespaces/namespaces.kt b/js/js.translator/testData/typescript-export/namespaces/namespaces.kt index d13be42a6ba..d7ae45ba160 100644 --- a/js/js.translator/testData/typescript-export/namespaces/namespaces.kt +++ b/js/js.translator/testData/typescript-export/namespaces/namespaces.kt @@ -22,22 +22,20 @@ fun f(x1: C1, x2: C2, x3: C3): String { // FILE: file2.kt -@file:JsExport - package a.b import foo.bar.baz.* import C3 +@JsExport data class C2(val value: String) +@JsExport 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.* diff --git a/js/js.translator/testData/typescript-export/objects-in-exported-file/objects.d.ts b/js/js.translator/testData/typescript-export/objects-in-exported-file/objects.d.ts new file mode 100644 index 00000000000..9de9e3184dc --- /dev/null +++ b/js/js.translator/testData/typescript-export/objects-in-exported-file/objects.d.ts @@ -0,0 +1,46 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + const O0: { + }; + const O: { + get x(): number; + foo(): number; + }; + function takesO(o: typeof foo.O): number; + abstract class Parent { + private constructor(); + } + namespace Parent { + abstract class Nested1 extends _objects_.foo$Parent$Nested1 { + private constructor(); + } + namespace Nested1 { + class Nested2 { + constructor(); + } + namespace Nested2 { + abstract class Companion { + private constructor(); + } + namespace Companion { + class Nested3 { + constructor(); + } + } + } + } + } + function getParent(): typeof foo.Parent; + function createNested1(): typeof foo.Parent.Nested1; + function createNested2(): foo.Parent.Nested1.Nested2; + function createNested3(): foo.Parent.Nested1.Nested2.Companion.Nested3; + } + namespace _objects_ { + const foo$Parent$Nested1: { + get value(): string; + } & { + new(): any; + }; + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/objects-in-exported-file/objects.kt b/js/js.translator/testData/typescript-export/objects-in-exported-file/objects.kt new file mode 100644 index 00000000000..e3b486f9507 --- /dev/null +++ b/js/js.translator/testData/typescript-export/objects-in-exported-file/objects.kt @@ -0,0 +1,58 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: objects.kt + +@file:JsExport + +package foo + + +object O0 + + +object O { + val x = 10 + fun foo() = 20 +} + + +fun takesO(o: O): Int = + O.x + O.foo() + + +object Parent { + object Nested1 { + val value: String = "Nested1" + class Nested2 { + companion object { + class Nested3 + } + } + } +} + + +fun getParent(): Parent { + return Parent +} + + +fun createNested1(): Parent.Nested1 { + return Parent.Nested1 +} + + +fun createNested2(): Parent.Nested1.Nested2 { + return Parent.Nested1.Nested2() +} + + +fun createNested3(): Parent.Nested1.Nested2.Companion.Nested3 { + return Parent.Nested1.Nested2.Companion.Nested3() +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/objects-in-exported-file/objects__main.js b/js/js.translator/testData/typescript-export/objects-in-exported-file/objects__main.js new file mode 100644 index 00000000000..4b843859922 --- /dev/null +++ b/js/js.translator/testData/typescript-export/objects-in-exported-file/objects__main.js @@ -0,0 +1,31 @@ +"use strict"; +var O = JS_TESTS.foo.O; +var O0 = JS_TESTS.foo.O0; +var Parent = JS_TESTS.foo.Parent; +var takesO = JS_TESTS.foo.takesO; +var getParent = JS_TESTS.foo.getParent; +var createNested1 = JS_TESTS.foo.createNested1; +var createNested2 = JS_TESTS.foo.createNested2; +var createNested3 = JS_TESTS.foo.createNested3; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + assert(typeof O0 === "object" && O0 != null); + assert(O.x === 10); + assert(O.foo() === 20); + assert(takesO(O) === 30); + // Do not strip types from those test cases (it is a check of nested objects types usability) + var parent = Parent; + var nested1 = Parent.Nested1; + var nested2 = new Parent.Nested1.Nested2(); + var nested3 = new Parent.Nested1.Nested2.Companion.Nested3(); + assert(nested1.value === "Nested1"); + assert(getParent() === parent); + assert(createNested1() === nested1); + assert(createNested2() !== nested2 && createNested2() instanceof Parent.Nested1.Nested2); + assert(createNested3() !== nested3 && createNested3() instanceof Parent.Nested1.Nested2.Companion.Nested3); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/objects-in-exported-file/objects__main.ts b/js/js.translator/testData/typescript-export/objects-in-exported-file/objects__main.ts new file mode 100644 index 00000000000..4d615540a4e --- /dev/null +++ b/js/js.translator/testData/typescript-export/objects-in-exported-file/objects__main.ts @@ -0,0 +1,34 @@ +import O = JS_TESTS.foo.O; +import O0 = JS_TESTS.foo.O0; +import Parent = JS_TESTS.foo.Parent; +import takesO = JS_TESTS.foo.takesO; +import getParent = JS_TESTS.foo.getParent; +import createNested1 = JS_TESTS.foo.createNested1; +import createNested2 = JS_TESTS.foo.createNested2; +import createNested3 = JS_TESTS.foo.createNested3; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + assert(typeof O0 === "object" && O0 != null); + assert(O.x === 10); + assert(O.foo() === 20); + assert(takesO(O) === 30) + + // Do not strip types from those test cases (it is a check of nested objects types usability) + const parent: typeof Parent = Parent + const nested1: typeof Parent.Nested1 = Parent.Nested1 + const nested2: Parent.Nested1.Nested2 = new Parent.Nested1.Nested2() + const nested3: Parent.Nested1.Nested2.Companion.Nested3 = new Parent.Nested1.Nested2.Companion.Nested3() + + assert(nested1.value === "Nested1") + assert(getParent() === parent) + assert(createNested1() === nested1) + assert(createNested2() !== nested2 && createNested2() instanceof Parent.Nested1.Nested2) + assert(createNested3() !== nested3 && createNested3() instanceof Parent.Nested1.Nested2.Companion.Nested3) + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/objects-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/objects-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/objects-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives.d.ts b/js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives.d.ts new file mode 100644 index 00000000000..b55d9e8c4b1 --- /dev/null +++ b/js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives.d.ts @@ -0,0 +1,49 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + const _any: any; + 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; + const _array_short: Array; + const _array_int: Array; + const _array_float: Array; + const _array_double: Array; + const _array_string: Array; + const _array_boolean: Array; + const _array_array_string: Array>; + const _array_array_int_array: Array>; + 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; + const _n_nothing: Nullable; + const _n_throwable: Nullable; + const _n_string: Nullable; + const _n_boolean: Nullable; + const _n_byte: Nullable; + const _n_short_array: Nullable; + const _n_array_int: Nullable>; + const _array_n_int: Array>; + const _n_array_n_int: Nullable>>; + const _array_n_array_string: Array>>; + const _fun_n_int_unit: (p0: Nullable) => void; + const _fun_n_boolean_n_int_n_string_n_intarray: (p0: Nullable, p1: Nullable, p2: Nullable) => Nullable; + const _n_curried_fun: (p0: Nullable) => (p0: Nullable) => (p0: Nullable) => Nullable; + const _n_higher_order_fun: (p0: (p0: Nullable) => Nullable, p1: (p0: Nullable) => Nullable) => (p0: Nullable) => Nullable; + function _nothing(): never; + } +} diff --git a/js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives.kt b/js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives.kt new file mode 100644 index 00000000000..a4eeedac12c --- /dev/null +++ b/js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives.kt @@ -0,0 +1,142 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: primitives.kt + +@file:JsExport + +package foo + + +val _any: Any = Any() + + +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 = emptyArray() + +val _array_short: Array = emptyArray() + +val _array_int: Array = emptyArray() + +val _array_float: Array = emptyArray() + +val _array_double: Array = emptyArray() + +val _array_string: Array = emptyArray() + +val _array_boolean: Array = emptyArray() + +val _array_array_string: Array> = arrayOf(emptyArray()) + +val _array_array_int_array: Array> = 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? = emptyArray() + +val _array_n_int: Array = emptyArray() + +val _n_array_n_int: Array? = emptyArray() + + +val _array_n_array_string: Array?> = 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)) } } diff --git a/js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives__main.js b/js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives__main.js new file mode 100644 index 00000000000..cff2e278c5b --- /dev/null +++ b/js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives__main.js @@ -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"; +} diff --git a/js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives__main.ts b/js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives__main.ts new file mode 100644 index 00000000000..e3035eb5f3d --- /dev/null +++ b/js/js.translator/testData/typescript-export/primitives-in-exported-file/primitives__main.ts @@ -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"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/primitives-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/primitives-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/primitives-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/primitives/primitives.kt b/js/js.translator/testData/typescript-export/primitives/primitives.kt index 267359641fa..8757b201619 100644 --- a/js/js.translator/testData/typescript-export/primitives/primitives.kt +++ b/js/js.translator/testData/typescript-export/primitives/primitives.kt @@ -6,90 +6,133 @@ // MODULE: JS_TESTS // FILE: primitives.kt -@file:JsExport - package foo +@JsExport val _any: Any = Any() +@JsExport fun _nothing(): Nothing { throw Throwable() } +@JsExport val _throwable: Throwable = Throwable() +@JsExport val _string: String = "ZZZ" +@JsExport val _boolean: Boolean = true +@JsExport val _byte: Byte = 1.toByte() +@JsExport val _short: Short = 1.toShort() +@JsExport val _int: Int = 1 +@JsExport val _float: Float = 1.0f +@JsExport val _double: Double = 1.0 // TODO: Char and Long +@JsExport val _byte_array: ByteArray = byteArrayOf() +@JsExport val _short_array: ShortArray = shortArrayOf() +@JsExport val _int_array: IntArray = intArrayOf() +@JsExport val _float_array: FloatArray = floatArrayOf() +@JsExport val _double_array: DoubleArray = doubleArrayOf() +@JsExport val _array_byte: Array = emptyArray() +@JsExport val _array_short: Array = emptyArray() +@JsExport val _array_int: Array = emptyArray() +@JsExport val _array_float: Array = emptyArray() +@JsExport val _array_double: Array = emptyArray() +@JsExport val _array_string: Array = emptyArray() +@JsExport val _array_boolean: Array = emptyArray() +@JsExport val _array_array_string: Array> = arrayOf(emptyArray()) +@JsExport val _array_array_int_array: Array> = arrayOf(arrayOf(intArrayOf())) +@JsExport val _fun_unit: () -> Unit = { } +@JsExport val _fun_int_unit: (Int) -> Unit = { x -> } +@JsExport val _fun_boolean_int_string_intarray: (Boolean, Int, String) -> IntArray = { b, i, s -> intArrayOf(b.toString().length, i, s.length) } +@JsExport val _curried_fun: (Int) -> (Int) -> (Int) -> (Int) -> (Int) -> Int = { x1 -> { x2 -> { x3 -> { x4 -> { x5 -> x1 + x2 + x3 + x4 + x5 } } } } } +@JsExport val _higher_order_fun: ((Int) -> String, (String) -> Int) -> ((Int) -> Int) = { f1, f2 -> { x -> f2(f1(x)) } } // Nullable types +@JsExport val _n_any: Any? = Any() // TODO: // val _n_unit: Unit? = Unit +@JsExport val _n_nothing: Nothing? = null +@JsExport val _n_throwable: Throwable? = Throwable() +@JsExport val _n_string: String? = "ZZZ" +@JsExport val _n_boolean: Boolean? = true +@JsExport val _n_byte: Byte? = 1.toByte() // TODO: Char and Long +@JsExport val _n_short_array: ShortArray? = shortArrayOf() +@JsExport val _n_array_int: Array? = emptyArray() +@JsExport val _array_n_int: Array = emptyArray() +@JsExport val _n_array_n_int: Array? = emptyArray() +@JsExport val _array_n_array_string: Array?> = arrayOf(arrayOf(":)")) +@JsExport val _fun_n_int_unit: (Int?) -> Unit = { x -> } +@JsExport val _fun_n_boolean_n_int_n_string_n_intarray: (Boolean?, Int?, String?) -> IntArray? = { b, i, s -> null } +@JsExport val _n_curried_fun: (Int?) -> (Int?) -> (Int?) -> Int? = { x1 -> { x2 -> { x3 -> (x1 ?: 0) + (x2 ?: 0) + (x3 ?: 0) } } } + +@JsExport val _n_higher_order_fun: ((Int?) -> String?, (String?) -> Int?) -> ((Int?) -> Int?) = { f1, f2 -> { x -> f2(f1(x)) } } diff --git a/js/js.translator/testData/typescript-export/properties-in-exported-file/properties.d.ts b/js/js.translator/testData/typescript-export/properties-in-exported-file/properties.d.ts new file mode 100644 index 00000000000..7e01df49060 --- /dev/null +++ b/js/js.translator/testData/typescript-export/properties-in-exported-file/properties.d.ts @@ -0,0 +1,12 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + const _val: number; + let _var: number; + const _valCustomWithField: number; + let _varCustomWithField: number; + const _const_val: number; + const _valCustom: number; + let _varCustom: number; + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/properties-in-exported-file/properties.kt b/js/js.translator/testData/typescript-export/properties-in-exported-file/properties.kt new file mode 100644 index 00000000000..6102d2045d1 --- /dev/null +++ b/js/js.translator/testData/typescript-export/properties-in-exported-file/properties.kt @@ -0,0 +1,40 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: properties.kt + +@file:JsExport + +package foo + + +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 } \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/properties-in-exported-file/properties__main.js b/js/js.translator/testData/typescript-export/properties-in-exported-file/properties__main.js new file mode 100644 index 00000000000..66d306e3883 --- /dev/null +++ b/js/js.translator/testData/typescript-export/properties-in-exported-file/properties__main.js @@ -0,0 +1,27 @@ +"use strict"; +var _const_val = JS_TESTS.foo._const_val; +var _val = JS_TESTS.foo._val; +var _var = JS_TESTS.foo._var; +var _valCustom = JS_TESTS.foo._valCustom; +var _valCustomWithField = JS_TESTS.foo._valCustomWithField; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + assert(_const_val === 1); + assert(_val === 1); + assert(_var === 1); + JS_TESTS.foo._var = 1000; + assert(JS_TESTS.foo._var === 1000); + assert(_valCustom === 1); + assert(_valCustomWithField === 2); + assert(JS_TESTS.foo._varCustom === 1); + JS_TESTS.foo._varCustom = 20; + assert(JS_TESTS.foo._varCustom === 1); + assert(JS_TESTS.foo._varCustomWithField === 10); + JS_TESTS.foo._varCustomWithField = 10; + assert(JS_TESTS.foo._varCustomWithField === 1000); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/properties-in-exported-file/properties__main.ts b/js/js.translator/testData/typescript-export/properties-in-exported-file/properties__main.ts new file mode 100644 index 00000000000..69d23c2d87e --- /dev/null +++ b/js/js.translator/testData/typescript-export/properties-in-exported-file/properties__main.ts @@ -0,0 +1,33 @@ +import _const_val = JS_TESTS.foo._const_val; +import _val = JS_TESTS.foo._val; +import _var = JS_TESTS.foo._var; +import _valCustom = JS_TESTS.foo._valCustom; +import _valCustomWithField = JS_TESTS.foo._valCustomWithField; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + assert(_const_val === 1); + assert(_val === 1); + assert(_var === 1); + + JS_TESTS.foo._var = 1000; + assert(JS_TESTS.foo._var === 1000); + + assert(_valCustom === 1); + assert(_valCustomWithField === 2); + + assert(JS_TESTS.foo._varCustom === 1); + JS_TESTS.foo._varCustom = 20; + assert(JS_TESTS.foo._varCustom === 1); + + assert(JS_TESTS.foo._varCustomWithField === 10); + JS_TESTS.foo._varCustomWithField = 10; + assert(JS_TESTS.foo._varCustomWithField === 1000); + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/properties-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/properties-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/properties-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes.d.ts b/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes.d.ts new file mode 100644 index 00000000000..18006f325fc --- /dev/null +++ b/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes.d.ts @@ -0,0 +1,42 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + class A { + constructor(); + } + class A1 { + constructor(x: number); + get x(): number; + } + class A2 { + constructor(x: string, y: boolean); + get x(): string; + get y(): boolean; + set y(value: boolean); + } + class A3 { + constructor(); + get x(): number; + } + class A4 { + constructor(value: T); + get value(): T; + test(): T; + } + class A5 { + constructor(); + static get Companion(): { + get x(): number; + }; + } + class A6 { + constructor(); + then(): number; + catch(): number; + } + class GenericClassWithConstraint { + constructor(test: T); + get test(): T; + } + } +} diff --git a/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes.kt b/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes.kt new file mode 100644 index 00000000000..4e911e59e88 --- /dev/null +++ b/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes.kt @@ -0,0 +1,47 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: regular-classes.kt + +@file:JsExport + +package foo + + +class A + + +class A1(val x: Int) + + +class A2(val x: String, var y: Boolean) + + +class A3 { + val x: Int = 100 +} + + +class A4(val value: T) { + fun test(): T = value +} + +class A5 { + companion object { + val x = 10 + } +} + + +open class A6 { + fun then(): Int = 42 + fun catch(): Int = 24 +} + + +class GenericClassWithConstraint(val test: T) diff --git a/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes__main.js b/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes__main.js new file mode 100644 index 00000000000..0f6caabe882 --- /dev/null +++ b/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes__main.js @@ -0,0 +1,26 @@ +"use strict"; +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 A4 = JS_TESTS.foo.A4; +var A5 = JS_TESTS.foo.A5; +var A6 = JS_TESTS.foo.A6; +var GenericClassWithConstraint = JS_TESTS.foo.GenericClassWithConstraint; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + new A(); + assert(new A1(10).x === 10); + assert(new A2("10", true).x === "10"); + assert(new A3().x === 100); + assert(new A4("Hello").test() === "Hello"); + assert(A5.Companion.x === 10); + assert(new A6().then() === 42); + assert(new A6().catch() === 24); + assert(new GenericClassWithConstraint(new A6()).test.catch() === 24); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes__main.ts b/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes__main.ts new file mode 100644 index 00000000000..8ff265da629 --- /dev/null +++ b/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/regular-classes__main.ts @@ -0,0 +1,28 @@ +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 A4 = JS_TESTS.foo.A4; +import A5 = JS_TESTS.foo.A5; +import A6 = JS_TESTS.foo.A6; +import GenericClassWithConstraint = JS_TESTS.foo.GenericClassWithConstraint; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + new A(); + assert(new A1(10).x === 10); + assert(new A2("10", true).x === "10"); + assert(new A3().x === 100); + assert(new A4("Hello").test() === "Hello"); + assert(A5.Companion.x === 10); + assert(new A6().then() === 42); + assert(new A6().catch() === 24); + assert(new GenericClassWithConstraint(new A6()).test.catch() === 24) + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/regular-classes-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes.d.ts b/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes.d.ts new file mode 100644 index 00000000000..c81e17fd2b8 --- /dev/null +++ b/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes.d.ts @@ -0,0 +1,19 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + namespace foo { + abstract class TestSealed { + protected constructor(name: string); + get name(): string; + } + namespace TestSealed { + class AA extends foo.TestSealed { + constructor(); + bar(): string; + } + class BB extends foo.TestSealed { + constructor(); + baz(): string; + } + } + } +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes.kt b/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes.kt new file mode 100644 index 00000000000..d0892bedb38 --- /dev/null +++ b/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes.kt @@ -0,0 +1,24 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE +// MODULE: JS_TESTS +// FILE: sealed-classes.kt + +@file:JsExport + +package foo + +// See KT-47376, KT-39364 + +sealed class TestSealed(val name: String) { + class AA : TestSealed("AA") { + fun bar(): String = "bar" + } + class BB : TestSealed("BB") { + fun baz(): String = "baz" + } +} diff --git a/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes__main.js b/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes__main.js new file mode 100644 index 00000000000..ac37bc7917d --- /dev/null +++ b/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes__main.js @@ -0,0 +1,14 @@ +"use strict"; +var TestSealed = JS_TESTS.foo.TestSealed; +function assert(condition) { + if (!condition) { + throw "Assertion failed"; + } +} +function box() { + assert(new TestSealed.AA().name == "AA"); + assert(new TestSealed.AA().bar() == "bar"); + assert(new TestSealed.BB().name == "BB"); + assert(new TestSealed.BB().baz() == "baz"); + return "OK"; +} diff --git a/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes__main.ts b/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes__main.ts new file mode 100644 index 00000000000..7fb339e44d9 --- /dev/null +++ b/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/sealed-classes__main.ts @@ -0,0 +1,16 @@ +import TestSealed = JS_TESTS.foo.TestSealed; + +function assert(condition: boolean) { + if (!condition) { + throw "Assertion failed"; + } +} + +function box(): string { + assert(new TestSealed.AA().name == "AA"); + assert(new TestSealed.AA().bar() == "bar"); + assert(new TestSealed.BB().name == "BB"); + assert(new TestSealed.BB().baz() == "baz"); + + return "OK"; +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/sealed-classes-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/strictImplicitExport/declarations.d.ts b/js/js.translator/testData/typescript-export/strict-implicit-export/strict-implicit-export.d.ts similarity index 100% rename from js/js.translator/testData/typescript-export/strictImplicitExport/declarations.d.ts rename to js/js.translator/testData/typescript-export/strict-implicit-export/strict-implicit-export.d.ts diff --git a/js/js.translator/testData/typescript-export/strictImplicitExport/declarations.kt b/js/js.translator/testData/typescript-export/strict-implicit-export/strict-implicit-export.kt similarity index 100% rename from js/js.translator/testData/typescript-export/strictImplicitExport/declarations.kt rename to js/js.translator/testData/typescript-export/strict-implicit-export/strict-implicit-export.kt diff --git a/js/js.translator/testData/typescript-export/strictImplicitExport/declarations__main.js b/js/js.translator/testData/typescript-export/strict-implicit-export/strict-implicit-export__main.js similarity index 100% rename from js/js.translator/testData/typescript-export/strictImplicitExport/declarations__main.js rename to js/js.translator/testData/typescript-export/strict-implicit-export/strict-implicit-export__main.js diff --git a/js/js.translator/testData/typescript-export/strictImplicitExport/declarations__main.ts b/js/js.translator/testData/typescript-export/strict-implicit-export/strict-implicit-export__main.ts similarity index 100% rename from js/js.translator/testData/typescript-export/strictImplicitExport/declarations__main.ts rename to js/js.translator/testData/typescript-export/strict-implicit-export/strict-implicit-export__main.ts diff --git a/js/js.translator/testData/typescript-export/strict-implicit-export/tsconfig.json b/js/js.translator/testData/typescript-export/strict-implicit-export/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/strict-implicit-export/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/visibility-in-exported-file/tsconfig.json b/js/js.translator/testData/typescript-export/visibility-in-exported-file/tsconfig.json new file mode 100644 index 00000000000..17612c56c9d --- /dev/null +++ b/js/js.translator/testData/typescript-export/visibility-in-exported-file/tsconfig.json @@ -0,0 +1,4 @@ +{ + "include": [ "./*" ], + "extends": "../common.tsconfig.json" +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility.d.ts b/js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility.d.ts new file mode 100644 index 00000000000..7b68095a664 --- /dev/null +++ b/js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility.d.ts @@ -0,0 +1,49 @@ +declare namespace JS_TESTS { + type Nullable = T | null | undefined + interface publicInterface { + } + const publicVal: number; + function publicFun(): number; + class publicClass { + constructor(); + } + class Class { + constructor(); + protected get protectedVal(): number; + protected protectedFun(): number; + get publicVal(): number; + publicFun(): number; + protected static get protectedNestedObject(): { + }; + protected static get Companion(): { + get companionObjectProp(): number; + }; + } + namespace Class { + class protectedClass { + constructor(); + } + class classWithProtectedConstructors { + protected constructor(); + protected static createWithString(arg: string): Class.classWithProtectedConstructors; + } + class publicClass { + constructor(); + } + } + abstract class EnumClass { + private constructor(); + static get EC1(): EnumClass & { + get name(): "EC1"; + get ordinal(): 0; + }; + static get EC2(): EnumClass & { + get name(): "EC2"; + get ordinal(): 1; + }; + static values(): Array; + static valueOf(value: string): EnumClass; + get name(): "EC1" | "EC2"; + get ordinal(): 0 | 1; + } +} diff --git a/js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility.kt b/js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility.kt new file mode 100644 index 00000000000..9d17d4e98bd --- /dev/null +++ b/js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility.kt @@ -0,0 +1,78 @@ +/** This file is generated by {@link :js:js.test:generateJsExportOnFileTestFilesForTS} task. DO NOT MODIFY MANUALLY */ + +// CHECK_TYPESCRIPT_DECLARATIONS +// RUN_PLAIN_BOX_FUNCTION +// SKIP_MINIFICATION +// SKIP_NODE_JS +// INFER_MAIN_MODULE + +// TODO fix statics export in DCE-driven mode +// SKIP_DCE_DRIVEN + +// MODULE: JS_TESTS +// FILE: visibility.kt + +@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 {} + protected object protectedNestedObject {} + protected companion object { + val companionObjectProp = 10 + } + + public class classWithProtectedConstructors protected constructor() { + + @JsName("createWithString") + protected constructor(arg: String): this() + } + + public val publicVal = 10 + @JsName("publicFun") // TODO: Should work without JsName + public fun publicFun() = 10 + public class publicClass +} + + +enum class EnumClass { + EC1, + EC2 +} \ No newline at end of file diff --git a/js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility__main.js b/js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility__main.js new file mode 100644 index 00000000000..162373ce09d --- /dev/null +++ b/js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility__main.js @@ -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"; +} diff --git a/js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility__main.ts b/js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility__main.ts new file mode 100644 index 00000000000..3d7897071df --- /dev/null +++ b/js/js.translator/testData/typescript-export/visibility-in-exported-file/visibility__main.ts @@ -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"; +} diff --git a/js/js.translator/testData/typescript-export/visibility/visibility.kt b/js/js.translator/testData/typescript-export/visibility/visibility.kt index b7b7a5d8934..4571ffd01d4 100644 --- a/js/js.translator/testData/typescript-export/visibility/visibility.kt +++ b/js/js.translator/testData/typescript-export/visibility/visibility.kt @@ -10,23 +10,34 @@ // MODULE: JS_TESTS // FILE: visibility.kt -@file:JsExport - +@JsExport internal val internalVal = 10 +@JsExport internal fun internalFun() = 10 +@JsExport internal class internalClass +@JsExport internal external interface internalInterface +@JsExport private val privateVal = 10 +@JsExport private fun privateFun() = 10 +@JsExport private class privateClass +@JsExport private external interface privateInterface +@JsExport public val publicVal = 10 +@JsExport public fun publicFun() = 10 +@JsExport public class publicClass +@JsExport public external interface publicInterface +@JsExport open class Class { internal val internalVal = 10 internal fun internalFun() = 10 @@ -56,6 +67,7 @@ open class Class { public class publicClass } +@JsExport enum class EnumClass { EC1, EC2