[K/JS] Add ability to exclude declarations from export by a new annotation @JsExport.Ignore.

This commit is contained in:
Artem Kobzar
2022-10-03 11:07:25 +00:00
committed by Space Team
parent 917c8606f5
commit eb2326eabb
49 changed files with 970 additions and 42 deletions
@@ -5,7 +5,6 @@
package org.jetbrains.kotlin.js.resolve
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.container.StorageComponentContainer
import org.jetbrains.kotlin.container.useImpl
import org.jetbrains.kotlin.container.useInstance
@@ -25,7 +24,7 @@ object JsPlatformConfigurator : PlatformConfiguratorBase(
JsRuntimeAnnotationChecker,
JsDynamicDeclarationChecker,
JsExportAnnotationChecker,
JsExportDeclarationChecker,
JsExportDeclarationChecker
),
additionalCallCheckers = listOf(
JsModuleCallChecker,
@@ -107,6 +107,7 @@ public interface ErrorsJs {
DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
DiagnosticFactory0<PsiElement> NESTED_JS_EXPORT = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<KtExpression, String> WRONG_EXPORTED_DECLARATION = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
DiagnosticFactory2<PsiElement, String, KotlinType> NON_EXPORTABLE_TYPE = DiagnosticFactory2.create(WARNING, DECLARATION_SIGNATURE_OR_DEFAULT);
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.js.PredefinedAnnotation;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.KtAnnotationEntry;
@@ -41,6 +42,7 @@ import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt.isEf
public final class AnnotationsUtils {
public static final FqName JS_NAME = new FqName("kotlin.js.JsName");
private static final FqName JS_EXPORT = new FqName("kotlin.js.JsExport");
private static final FqName JS_EXPORT_IGNORE = new FqName("kotlin.js.JsExport.Ignore");
public static final FqName JS_MODULE_ANNOTATION = new FqName("kotlin.js.JsModule");
private static final FqName JS_NON_MODULE_ANNOTATION = new FqName("kotlin.js.JsNonModule");
public static final FqName JS_QUALIFIER_ANNOTATION = new FqName("kotlin.js.JsQualifier");
@@ -122,6 +124,7 @@ public final class AnnotationsUtils {
if (memberDescriptor.getVisibility() != DescriptorVisibilities.PUBLIC) return false;
}
if (hasAnnotationOrInsideAnnotatedClass(descriptor, JS_EXPORT_IGNORE)) return false;
if (hasAnnotationOrInsideAnnotatedClass(descriptor, JS_EXPORT)) return true;
if (CollectionsKt.any(getContainingFileAnnotations(bindingContext, descriptor), annotation ->
-1
View File
@@ -156,7 +156,6 @@ val unzipJsShell by task<Copy> {
val testDataDir = project(":js:js.translator").projectDir.resolve("testData")
val typescriptTestsDir = testDataDir.resolve("typescript-export")
val installTsDependencies = task<NpmTask>("installTsDependencies") {
workingDir.set(testDataDir)
args.set(listOf("install"))
@@ -2118,6 +2118,24 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
runTest("js/js.translator/testData/box/export/defaultInlineClassConstructorParamInExportedFile.kt");
}
@Test
@TestMetadata("excludeMembersFromExport.kt")
public void testExcludeMembersFromExport() throws Exception {
runTest("js/js.translator/testData/box/export/excludeMembersFromExport.kt");
}
@Test
@TestMetadata("excludeTopLevelFromExport.kt")
public void testExcludeTopLevelFromExport() throws Exception {
runTest("js/js.translator/testData/box/export/excludeTopLevelFromExport.kt");
}
@Test
@TestMetadata("excludeTopLevelFromExportWithoutFileJsExport.kt")
public void testExcludeTopLevelFromExportWithoutFileJsExport() throws Exception {
runTest("js/js.translator/testData/box/export/excludeTopLevelFromExportWithoutFileJsExport.kt");
}
@Test
@TestMetadata("exportAllFile.kt")
public void testExportAllFile() throws Exception {
@@ -2590,6 +2590,24 @@ public class FirJsTestGenerated extends AbstractFirJsTest {
runTest("js/js.translator/testData/box/export/defaultInlineClassConstructorParamInExportedFile.kt");
}
@Test
@TestMetadata("excludeMembersFromExport.kt")
public void testExcludeMembersFromExport() throws Exception {
runTest("js/js.translator/testData/box/export/excludeMembersFromExport.kt");
}
@Test
@TestMetadata("excludeTopLevelFromExport.kt")
public void testExcludeTopLevelFromExport() throws Exception {
runTest("js/js.translator/testData/box/export/excludeTopLevelFromExport.kt");
}
@Test
@TestMetadata("excludeTopLevelFromExportWithoutFileJsExport.kt")
public void testExcludeTopLevelFromExportWithoutFileJsExport() throws Exception {
runTest("js/js.translator/testData/box/export/excludeTopLevelFromExportWithoutFileJsExport.kt");
}
@Test
@TestMetadata("exportAllFile.kt")
public void testExportAllFile() throws Exception {
@@ -2590,6 +2590,24 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
runTest("js/js.translator/testData/box/export/defaultInlineClassConstructorParamInExportedFile.kt");
}
@Test
@TestMetadata("excludeMembersFromExport.kt")
public void testExcludeMembersFromExport() throws Exception {
runTest("js/js.translator/testData/box/export/excludeMembersFromExport.kt");
}
@Test
@TestMetadata("excludeTopLevelFromExport.kt")
public void testExcludeTopLevelFromExport() throws Exception {
runTest("js/js.translator/testData/box/export/excludeTopLevelFromExport.kt");
}
@Test
@TestMetadata("excludeTopLevelFromExportWithoutFileJsExport.kt")
public void testExcludeTopLevelFromExportWithoutFileJsExport() throws Exception {
runTest("js/js.translator/testData/box/export/excludeTopLevelFromExportWithoutFileJsExport.kt");
}
@Test
@TestMetadata("exportAllFile.kt")
public void testExportAllFile() throws Exception {
@@ -185,6 +185,38 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp
}
}
@Nested
@TestMetadata("js/js.translator/testData/typescript-export/excluded-exported-declarations")
@TestDataPath("$PROJECT_ROOT")
public class Excluded_exported_declarations {
@Test
public void testAllFilesPresentInExcluded_exported_declarations() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/excluded-exported-declarations"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("excluded-exported-declarations.kt")
public void testExcluded_exported_declarations() throws Exception {
runTest("js/js.translator/testData/typescript-export/excluded-exported-declarations/excluded-exported-declarations.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/typescript-export/excluded-exported-declarations-in-exported-file")
@TestDataPath("$PROJECT_ROOT")
public class Excluded_exported_declarations_in_exported_file {
@Test
public void testAllFilesPresentInExcluded_exported_declarations_in_exported_file() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/excluded-exported-declarations-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("excluded-exported-declarations.kt")
public void testExcluded_exported_declarations() throws Exception {
runTest("js/js.translator/testData/typescript-export/excluded-exported-declarations-in-exported-file/excluded-exported-declarations.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/typescript-export/functions")
@TestDataPath("$PROJECT_ROOT")
@@ -497,6 +529,38 @@ public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExp
}
}
@Nested
@TestMetadata("js/js.translator/testData/typescript-export/not-exported-declarations")
@TestDataPath("$PROJECT_ROOT")
public class Not_exported_declarations {
@Test
public void testAllFilesPresentInNot_exported_declarations() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/not-exported-declarations"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("not-exported-declarations.kt")
public void testNot_exported_declarations() throws Exception {
runTest("js/js.translator/testData/typescript-export/not-exported-declarations/not-exported-declarations.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/typescript-export/not-exported-declarations-in-exported-file")
@TestDataPath("$PROJECT_ROOT")
public class Not_exported_declarations_in_exported_file {
@Test
public void testAllFilesPresentInNot_exported_declarations_in_exported_file() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/not-exported-declarations-in-exported-file"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true);
}
@Test
@TestMetadata("not-exported-declarations.kt")
public void testNot_exported_declarations() throws Exception {
runTest("js/js.translator/testData/typescript-export/not-exported-declarations-in-exported-file/not-exported-declarations.kt");
}
}
@Nested
@TestMetadata("js/js.translator/testData/typescript-export/objects")
@TestDataPath("$PROJECT_ROOT")
@@ -0,0 +1,52 @@
// RUN_PLAIN_BOX_FUNCTION
// IGNORE_BACKEND: JS
// MODULE: lib
// FILE: lib.kt
@JsExport
class Bar(val value: String) {
@JsExport.Ignore
constructor(): this("SECONDARY")
@JsExport.Ignore
val excludedValue: Int = 42
fun foo(): String = "FOO"
@JsExport.Ignore
fun excludedFun(): String = "EXCLUDED_FUN"
class Nested
@JsExport.Ignore
class ExcludedNested {
fun doSomething(): String = "SOMETHING"
}
companion object {
fun baz(): String = "BAZ"
@JsExport.Ignore
fun excludedFun(): String = "STATIC EXCLUDED_FUN"
}
}
// FILE: main.js
function box() {
var Bar = this.lib.Bar;
var bar = new Bar("TEST");
if (bar.value !== "TEST") return "Error: exported property was not exported"
if (bar.excludedValue === 42) return "Error: not exported property was exported"
if (bar.foo() !== "FOO") return "Error: exported function was not exported"
if (typeof bar.excludedFun === "function") return "Error: not exported function was exported"
if (typeof Bar.Nested !== "function") return "Error: exported nested class was not exported"
if (typeof Bar.ExcludedNested === "function") return "Error: not exported nested class was exported"
if (Bar.Companion.baz() !== "BAZ") return "Error: exported companion function was not exported"
if (typeof Bar.Companion.excludedFun === "function") return "Error: not exported companion function was exported"
return "OK"
}
@@ -0,0 +1,49 @@
// RUN_PLAIN_BOX_FUNCTION
// IGNORE_BACKEND: JS
// MODULE: lib
// FILE: lib.kt
@file:JsExport
val value: String = "TEST"
@JsExport.Ignore
val excludedValue: Int = 42
fun foo(): String = "FOO"
@JsExport.Ignore
fun excludedFun(): String = "EXCLUDED_FUN"
class SomeClass
@JsExport.Ignore
class ExcludedSomeClass {
fun doSomething(): String = "SOMETHING"
}
object Companion {
fun baz(): String = "BAZ"
@JsExport.Ignore
fun excludedFun(): String = "STATIC EXCLUDED_FUN"
}
// FILE: main.js
function box() {
var lib = this.lib;
if (lib.value !== "TEST") return "Error: exported property was not exported"
if (lib.excludedValue === 42) return "Error: not exported property was exported"
if (lib.foo() !== "FOO") return "Error: exported function was not exported"
if (typeof lib.excludedFun === "function") return "Error: not exported function was exported"
if (typeof lib.SomeClass !== "function") return "Error: exported nested class was not exported"
if (typeof lib.ExcludedSomeClass === "function") return "Error: not exported nested class was exported"
if (lib.Companion.baz() !== "BAZ") return "Error: exported companion function was not exported"
if (typeof lib.Companion.excludedFun === "function") return "Error: not exported companion function was exported"
return "OK"
}
@@ -0,0 +1,55 @@
// RUN_PLAIN_BOX_FUNCTION
// IGNORE_BACKEND: JS
// MODULE: lib
// FILE: lib.kt
@JsExport
val value: String = "TEST"
@JsExport
@JsExport.Ignore
val excludedValue: Int = 42
@JsExport
fun foo(): String = "FOO"
@JsExport
@JsExport.Ignore
fun excludedFun(): String = "EXCLUDED_FUN"
@JsExport
class SomeClass
@JsExport.Ignore
@JsExport
class ExcludedSomeClass {
fun doSomething(): String = "SOMETHING"
}
@JsExport
object Companion {
fun baz(): String = "BAZ"
@JsExport.Ignore
fun excludedFun(): String = "STATIC EXCLUDED_FUN"
}
// FILE: main.js
function box() {
var lib = this.lib;
if (lib.value !== "TEST") return "Error: exported property was not exported"
if (lib.excludedValue === 42) return "Error: not exported property was exported"
if (lib.foo() !== "FOO") return "Error: exported function was not exported"
if (typeof lib.excludedFun === "function") return "Error: not exported function was exported"
if (typeof lib.SomeClass !== "function") return "Error: exported nested class was not exported"
if (typeof lib.ExcludedSomeClass === "function") return "Error: not exported nested class was exported"
if (lib.Companion.baz() !== "BAZ") return "Error: exported companion function was not exported"
if (typeof lib.Companion.excludedFun === "function") return "Error: not exported companion function was exported"
return "OK"
}
@@ -0,0 +1,7 @@
declare namespace JS_TESTS {
type Nullable<T> = T | null | undefined
namespace foo {
const foo: string;
function bar(): string;
}
}
@@ -0,0 +1,63 @@
/** 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
// WITH_STDLIB
// FILE: declarations.kt
@file:JsExport
package foo
@JsExport.Ignore
val baz: String = "Baz"
@JsExport.Ignore
fun inter(): String = "inter"
@JsExport.Ignore
class NotExportableNestedInsideInterface
@JsExport.Ignore
object Comanion {
val foo: String ="FOO"
}
val foo: String = "Foo"
fun bar() = "Bar"
@JsExport.Ignore
inline fun <A, reified B> A.notExportableReified(): Boolean = this is B
@JsExport.Ignore
suspend fun notExportableSuspend(): String = "SuspendResult"
@JsExport.Ignore
fun notExportableReturn(): List<String> = listOf("1", "2")
@JsExport.Ignore
val String.notExportableExentsionProperty: String
get() = "notExportableExentsionProperty"
@JsExport.Ignore
annotation class NotExportableAnnotation
@JsExport.Ignore
value class NotExportableInlineClass(val value: Int)
@@ -0,0 +1,33 @@
"use strict";
var foo = JS_TESTS.foo;
function assert(condition, message) {
if (message === void 0) { message = "Assertion failed"; }
if (!condition) {
throw message;
}
}
function box() {
assert(foo.foo === "Foo", "Error in property 'foo'");
assert(foo.bar() === "Bar", "Error in property 'bar'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.baz === undefined, "Error in property 'baz'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.inter === undefined, "Error in method 'inter'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.NotExportableNestedInsideInterface === undefined, "Error in class 'NotExportableNestedInsideInterface'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.Companion === undefined, "Error in object 'Companion'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableReified === undefined, "Error in method 'notExportableReified'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableSuspend === undefined, "Error in method 'notExportableSuspend'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableReturn === undefined, "Error in method 'notExportableReturn'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableExentsionProperty === undefined, "Error in method 'notExportableExentsionProperty'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.NotExportableAnnotation === undefined, "Error in nested class 'NotExportableAnnotation'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.NotExportableInlineClass === undefined, "Error in nested class 'NotExportableInlineClass'");
return "OK";
}
@@ -0,0 +1,36 @@
import foo = JS_TESTS.foo;
function assert(condition: boolean, message: string = "Assertion failed") {
if (!condition) {
throw message;
}
}
function box(): string {
assert(foo.foo === "Foo", "Error in property 'foo'")
assert(foo.bar() === "Bar", "Error in property 'bar'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.baz === undefined, "Error in property 'baz'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.inter === undefined, "Error in method 'inter'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.NotExportableNestedInsideInterface === undefined, "Error in class 'NotExportableNestedInsideInterface'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.Companion === undefined, "Error in object 'Companion'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableReified === undefined, "Error in method 'notExportableReified'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableSuspend === undefined, "Error in method 'notExportableSuspend'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableReturn === undefined, "Error in method 'notExportableReturn'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableExentsionProperty === undefined, "Error in method 'notExportableExentsionProperty'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.NotExportableAnnotation === undefined, "Error in nested class 'NotExportableAnnotation'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.NotExportableInlineClass === undefined, "Error in nested class 'NotExportableInlineClass'")
return "OK";
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -0,0 +1,7 @@
declare namespace JS_TESTS {
type Nullable<T> = T | null | undefined
namespace foo {
const foo: string;
function bar(): string;
}
}
@@ -0,0 +1,59 @@
// CHECK_TYPESCRIPT_DECLARATIONS
// RUN_PLAIN_BOX_FUNCTION
// SKIP_MINIFICATION
// SKIP_NODE_JS
// INFER_MAIN_MODULE
// MODULE: JS_TESTS
// WITH_STDLIB
// FILE: declarations.kt
package foo
@JsExport
@JsExport.Ignore
val baz: String = "Baz"
@JsExport
@JsExport.Ignore
fun inter(): String = "inter"
@JsExport
@JsExport.Ignore
class NotExportableNestedInsideInterface
@JsExport.Ignore
@JsExport
object Comanion {
val foo: String ="FOO"
}
@JsExport
val foo: String = "Foo"
@JsExport
fun bar() = "Bar"
@JsExport.Ignore
@JsExport
inline fun <A, reified B> A.notExportableReified(): Boolean = this is B
@JsExport.Ignore
@JsExport
suspend fun notExportableSuspend(): String = "SuspendResult"
@JsExport
@JsExport.Ignore
fun notExportableReturn(): List<String> = listOf("1", "2")
@JsExport
@JsExport.Ignore
val String.notExportableExentsionProperty: String
get() = "notExportableExentsionProperty"
@JsExport
@JsExport.Ignore
annotation class NotExportableAnnotation
@JsExport
@JsExport.Ignore
value class NotExportableInlineClass(val value: Int)
@@ -0,0 +1,33 @@
"use strict";
var foo = JS_TESTS.foo;
function assert(condition, message) {
if (message === void 0) { message = "Assertion failed"; }
if (!condition) {
throw message;
}
}
function box() {
assert(foo.foo === "Foo", "Error in property 'foo'");
assert(foo.bar() === "Bar", "Error in property 'bar'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.baz === undefined, "Error in property 'baz'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.inter === undefined, "Error in method 'inter'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.NotExportableNestedInsideInterface === undefined, "Error in class 'NotExportableNestedInsideInterface'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.Companion === undefined, "Error in object 'Companion'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableReified === undefined, "Error in method 'notExportableReified'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableSuspend === undefined, "Error in method 'notExportableSuspend'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableReturn === undefined, "Error in method 'notExportableReturn'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableExentsionProperty === undefined, "Error in method 'notExportableExentsionProperty'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.NotExportableAnnotation === undefined, "Error in nested class 'NotExportableAnnotation'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.NotExportableInlineClass === undefined, "Error in nested class 'NotExportableInlineClass'");
return "OK";
}
@@ -0,0 +1,36 @@
import foo = JS_TESTS.foo;
function assert(condition: boolean, message: string = "Assertion failed") {
if (!condition) {
throw message;
}
}
function box(): string {
assert(foo.foo === "Foo", "Error in property 'foo'")
assert(foo.bar() === "Bar", "Error in property 'bar'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.baz === undefined, "Error in property 'baz'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.inter === undefined, "Error in method 'inter'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.NotExportableNestedInsideInterface === undefined, "Error in class 'NotExportableNestedInsideInterface'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.Companion === undefined, "Error in object 'Companion'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableReified === undefined, "Error in method 'notExportableReified'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableSuspend === undefined, "Error in method 'notExportableSuspend'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableReturn === undefined, "Error in method 'notExportableReturn'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.notExportableExentsionProperty === undefined, "Error in method 'notExportableExentsionProperty'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.NotExportableAnnotation === undefined, "Error in nested class 'NotExportableAnnotation'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(foo.NotExportableInlineClass === undefined, "Error in nested class 'NotExportableInlineClass'")
return "OK";
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -0,0 +1,15 @@
declare namespace JS_TESTS {
type Nullable<T> = T | null | undefined
namespace foo {
interface ExportedInterface {
readonly __doNotUseOrImplementIt: {
readonly "foo.ExportedInterface": unique symbol;
};
}
class OnlyFooParamExported implements foo.ExportedInterface {
constructor(foo: string);
get foo(): string;
readonly __doNotUseOrImplementIt: foo.ExportedInterface["__doNotUseOrImplementIt"];
}
}
}
@@ -0,0 +1,63 @@
/** 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
// WITH_STDLIB
// FILE: declarations.kt
@file:JsExport
package foo
interface ExportedInterface {
@JsExport.Ignore
val baz: String
@JsExport.Ignore
fun inter(): String
@JsExport.Ignore
class NotExportableNestedInsideInterface
@JsExport.Ignore
companion object {
val foo: String ="FOO"
}
}
class OnlyFooParamExported(val foo: String) : ExportedInterface {
@JsExport.Ignore
constructor() : this("TEST")
override val baz = "Baz"
override fun inter(): String = "Inter"
@JsExport.Ignore
val bar = "Bar"
@JsExport.Ignore
inline fun <A, reified B> A.notExportableReified(): Boolean = this is B
@JsExport.Ignore
suspend fun notExportableSuspend(): String = "SuspendResult"
@JsExport.Ignore
fun notExportableReturn(): List<String> = listOf("1", "2")
@JsExport.Ignore
val String.notExportableExentsionProperty: String
get() = "notExportableExentsionProperty"
@JsExport.Ignore
annotation class NotExportableAnnotation
@JsExport.Ignore
value class NotExportableInlineClass(val value: Int)
}
@@ -0,0 +1,32 @@
"use strict";
var OnlyFooParamExported = JS_TESTS.foo.OnlyFooParamExported;
function assert(condition, message) {
if (message === void 0) { message = "Assertion failed"; }
if (!condition) {
throw message;
}
}
function box() {
var onlyFooParamExported = new OnlyFooParamExported("TEST");
assert(OnlyFooParamExported.length === 1, "Error in constructor'");
assert(onlyFooParamExported.foo === "TEST", "Error in property 'foo'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.bar === undefined, "Error in property 'bar'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.baz === undefined, "Error in property 'baz'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.inter === undefined, "Error in method 'inter'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableReified === undefined, "Error in method 'notExportableReified'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableSuspend === undefined, "Error in method 'notExportableSuspend'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableReturn === undefined, "Error in method 'notExportableReturn'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableExentsionProperty === undefined, "Error in method 'notExportableExentsionProperty'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(OnlyFooParamExported.NotExportableAnnotation === undefined, "Error in nested class 'NotExportableAnnotation'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(OnlyFooParamExported.NotExportableInlineClass === undefined, "Error in nested class 'NotExportableInlineClass'");
return "OK";
}
@@ -0,0 +1,35 @@
import OnlyFooParamExported = JS_TESTS.foo.OnlyFooParamExported;
function assert(condition: boolean, message: string = "Assertion failed") {
if (!condition) {
throw message;
}
}
function box(): string {
const onlyFooParamExported = new OnlyFooParamExported("TEST")
assert(OnlyFooParamExported.length === 1, "Error in constructor'")
assert(onlyFooParamExported.foo === "TEST", "Error in property 'foo'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.bar === undefined, "Error in property 'bar'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.baz === undefined, "Error in property 'baz'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.inter === undefined, "Error in method 'inter'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableReified === undefined, "Error in method 'notExportableReified'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableSuspend === undefined, "Error in method 'notExportableSuspend'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableReturn === undefined, "Error in method 'notExportableReturn'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableExentsionProperty === undefined, "Error in method 'notExportableExentsionProperty'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(OnlyFooParamExported.NotExportableAnnotation === undefined, "Error in nested class 'NotExportableAnnotation'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(OnlyFooParamExported.NotExportableInlineClass === undefined, "Error in nested class 'NotExportableInlineClass'")
return "OK";
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}
@@ -0,0 +1,15 @@
declare namespace JS_TESTS {
type Nullable<T> = T | null | undefined
namespace foo {
interface ExportedInterface {
readonly __doNotUseOrImplementIt: {
readonly "foo.ExportedInterface": unique symbol;
};
}
class OnlyFooParamExported implements foo.ExportedInterface {
constructor(foo: string);
get foo(): string;
readonly __doNotUseOrImplementIt: foo.ExportedInterface["__doNotUseOrImplementIt"];
}
}
}
@@ -0,0 +1,59 @@
// CHECK_TYPESCRIPT_DECLARATIONS
// RUN_PLAIN_BOX_FUNCTION
// SKIP_MINIFICATION
// SKIP_NODE_JS
// INFER_MAIN_MODULE
// MODULE: JS_TESTS
// WITH_STDLIB
// FILE: declarations.kt
package foo
@JsExport
interface ExportedInterface {
@JsExport.Ignore
val baz: String
@JsExport.Ignore
fun inter(): String
@JsExport.Ignore
class NotExportableNestedInsideInterface
@JsExport.Ignore
companion object {
val foo: String ="FOO"
}
}
@JsExport
class OnlyFooParamExported(val foo: String) : ExportedInterface {
@JsExport.Ignore
constructor() : this("TEST")
override val baz = "Baz"
override fun inter(): String = "Inter"
@JsExport.Ignore
val bar = "Bar"
@JsExport.Ignore
inline fun <A, reified B> A.notExportableReified(): Boolean = this is B
@JsExport.Ignore
suspend fun notExportableSuspend(): String = "SuspendResult"
@JsExport.Ignore
fun notExportableReturn(): List<String> = listOf("1", "2")
@JsExport.Ignore
val String.notExportableExentsionProperty: String
get() = "notExportableExentsionProperty"
@JsExport.Ignore
annotation class NotExportableAnnotation
@JsExport.Ignore
value class NotExportableInlineClass(val value: Int)
}
@@ -0,0 +1,32 @@
"use strict";
var OnlyFooParamExported = JS_TESTS.foo.OnlyFooParamExported;
function assert(condition, message) {
if (message === void 0) { message = "Assertion failed"; }
if (!condition) {
throw message;
}
}
function box() {
var onlyFooParamExported = new OnlyFooParamExported("TEST");
assert(OnlyFooParamExported.length === 1, "Error in constructor'");
assert(onlyFooParamExported.foo === "TEST", "Error in property 'foo'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.bar === undefined, "Error in property 'bar'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.baz === undefined, "Error in property 'baz'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.inter === undefined, "Error in method 'inter'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableReified === undefined, "Error in method 'notExportableReified'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableSuspend === undefined, "Error in method 'notExportableSuspend'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableReturn === undefined, "Error in method 'notExportableReturn'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableExentsionProperty === undefined, "Error in method 'notExportableExentsionProperty'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(OnlyFooParamExported.NotExportableAnnotation === undefined, "Error in nested class 'NotExportableAnnotation'");
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(OnlyFooParamExported.NotExportableInlineClass === undefined, "Error in nested class 'NotExportableInlineClass'");
return "OK";
}
@@ -0,0 +1,35 @@
import OnlyFooParamExported = JS_TESTS.foo.OnlyFooParamExported;
function assert(condition: boolean, message: string = "Assertion failed") {
if (!condition) {
throw message;
}
}
function box(): string {
const onlyFooParamExported = new OnlyFooParamExported("TEST")
assert(OnlyFooParamExported.length === 1, "Error in constructor'")
assert(onlyFooParamExported.foo === "TEST", "Error in property 'foo'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.bar === undefined, "Error in property 'bar'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.baz === undefined, "Error in property 'baz'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.inter === undefined, "Error in method 'inter'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableReified === undefined, "Error in method 'notExportableReified'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableSuspend === undefined, "Error in method 'notExportableSuspend'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableReturn === undefined, "Error in method 'notExportableReturn'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(onlyFooParamExported.notExportableExentsionProperty === undefined, "Error in method 'notExportableExentsionProperty'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(OnlyFooParamExported.NotExportableAnnotation === undefined, "Error in nested class 'NotExportableAnnotation'")
// @ts-expect-error "the param should not be exported either in TS, or in JS"
assert(OnlyFooParamExported.NotExportableInlineClass === undefined, "Error in nested class 'NotExportableInlineClass'")
return "OK";
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}