[K/JS] feat: add logic under the flag for strict implicit export generating inside d.ts files.

This commit is contained in:
Artem Kobzar
2022-08-09 16:48:59 +00:00
committed by Space
parent 8fcbe9902c
commit 87038e7d8a
23 changed files with 641 additions and 25 deletions
@@ -41,5 +41,6 @@ declare namespace JS_TESTS {
function bar(): Error;
const console: Console;
const error: WebAssembly.CompileError;
function functionWithTypeAliasInside(x: any/* foo.NonExportedGenericInterface<foo.NonExportedType> */): any/* foo.NonExportedGenericInterface<foo.NonExportedType> */;
}
}
@@ -85,4 +85,11 @@ val console: Console
@JsExport
val error: CompileError
get() = js("{}")
get() = js("{}")
typealias NotExportedTypeAlias = NonExportedGenericInterface<NonExportedType>
@JsExport
fun functionWithTypeAliasInside(x: NotExportedTypeAlias): NotExportedTypeAlias {
return x
}
@@ -18,4 +18,4 @@ declare namespace JS_TESTS {
inlineFun(x: number, callback: (p0: number) => void): void;
}
}
}
}
@@ -0,0 +1,147 @@
declare namespace JS_TESTS {
type Nullable<T> = T | null | undefined
namespace foo {
const forth: foo.Forth;
interface ExportedInterface {
readonly __doNotUseOrImplementIt: {
readonly "foo.ExportedInterface": unique symbol;
};
}
function producer(value: number): foo.NonExportedType;
function consumer(value: foo.NonExportedType): number;
function childProducer(value: number): foo.NotExportedChildClass;
function childConsumer(value: foo.NotExportedChildClass): number;
function genericChildProducer<T extends foo.NonExportedGenericType<number>>(value: T): foo.NotExportedChildGenericClass<T>;
function genericChildConsumer<T extends foo.NonExportedGenericType<number>>(value: foo.NotExportedChildGenericClass<T>): T;
class A implements foo.NonExportedParent.NonExportedSecond.NonExportedUsedChild {
constructor(value: foo.NonExportedType);
get value(): foo.NonExportedType;
set value(value: foo.NonExportedType);
increment<T extends foo.NonExportedType>(t: T): foo.NonExportedType;
getNonExportedUserChild(): foo.NonExportedParent.NonExportedSecond.NonExportedUsedChild;
readonly __doNotUseOrImplementIt: foo.NonExportedParent.NonExportedSecond.NonExportedUsedChild["__doNotUseOrImplementIt"];
}
class B implements foo.NonExportedType {
constructor(v: number);
readonly __doNotUseOrImplementIt: foo.NonExportedType["__doNotUseOrImplementIt"];
}
class C implements foo.NonExportedInterface {
constructor();
readonly __doNotUseOrImplementIt: foo.NonExportedInterface["__doNotUseOrImplementIt"];
}
class D implements foo.NonExportedInterface, foo.ExportedInterface {
constructor();
readonly __doNotUseOrImplementIt: foo.NonExportedInterface["__doNotUseOrImplementIt"] & foo.ExportedInterface["__doNotUseOrImplementIt"];
}
class E implements foo.NonExportedType, foo.ExportedInterface {
constructor();
readonly __doNotUseOrImplementIt: foo.NonExportedType["__doNotUseOrImplementIt"] & foo.ExportedInterface["__doNotUseOrImplementIt"];
}
class F extends foo.A implements foo.NonExportedInterface {
constructor();
readonly __doNotUseOrImplementIt: foo.A["__doNotUseOrImplementIt"] & foo.NonExportedInterface["__doNotUseOrImplementIt"];
}
class G implements foo.NonExportedGenericInterface<foo.NonExportedType> {
constructor();
readonly __doNotUseOrImplementIt: foo.NonExportedGenericInterface<foo.NonExportedType>["__doNotUseOrImplementIt"];
}
class H implements foo.NonExportedGenericType<foo.NonExportedType> {
constructor();
readonly __doNotUseOrImplementIt: foo.NonExportedGenericType<foo.NonExportedType>["__doNotUseOrImplementIt"];
}
class I implements foo.NotExportedChildClass {
constructor();
readonly __doNotUseOrImplementIt: foo.NotExportedChildClass["__doNotUseOrImplementIt"];
}
class J implements foo.NotExportedChildGenericClass<foo.NonExportedType> {
constructor();
readonly __doNotUseOrImplementIt: foo.NotExportedChildGenericClass<foo.NonExportedType>["__doNotUseOrImplementIt"];
}
function baz(a: number): Promise<number>;
function bar(): Error;
function pep<T extends foo.NonExportedInterface & foo.NonExportedGenericInterface<number>>(x: T): void;
const console: Console;
const error: WebAssembly.CompileError;
interface IA {
readonly __doNotUseOrImplementIt: {
readonly "foo.IA": unique symbol;
};
}
class Third extends /* foo.Second */ foo.First {
constructor();
}
class Sixth extends /* foo.Fifth */ foo.Third implements foo.Forth, foo.IC {
constructor();
readonly __doNotUseOrImplementIt: foo.Forth["__doNotUseOrImplementIt"] & foo.IC["__doNotUseOrImplementIt"];
}
class First {
constructor();
}
function acceptForthLike<T extends foo.Forth>(forth: T): void;
function acceptMoreGenericForthLike<T extends foo.IB & foo.IC & foo.Third>(forth: T): void;
interface NonExportedParent {
readonly __doNotUseOrImplementIt: {
readonly "foo.NonExportedParent": unique symbol;
};
}
namespace NonExportedParent {
interface NonExportedSecond {
readonly __doNotUseOrImplementIt: {
readonly "foo.NonExportedParent.NonExportedSecond": unique symbol;
};
}
namespace NonExportedSecond {
interface NonExportedUsedChild {
readonly __doNotUseOrImplementIt: {
readonly "foo.NonExportedParent.NonExportedSecond.NonExportedUsedChild": unique symbol;
};
}
}
}
interface NonExportedInterface {
readonly __doNotUseOrImplementIt: {
readonly "foo.NonExportedInterface": unique symbol;
};
}
interface NonExportedGenericInterface<T> {
readonly __doNotUseOrImplementIt: {
readonly "foo.NonExportedGenericInterface": unique symbol;
};
}
interface NonExportedType {
readonly __doNotUseOrImplementIt: {
readonly "foo.NonExportedType": unique symbol;
};
}
interface NonExportedGenericType<T> {
readonly __doNotUseOrImplementIt: {
readonly "foo.NonExportedGenericType": unique symbol;
};
}
interface NotExportedChildClass extends foo.NonExportedInterface, foo.NonExportedType {
readonly __doNotUseOrImplementIt: {
readonly "foo.NotExportedChildClass": unique symbol;
} & foo.NonExportedInterface["__doNotUseOrImplementIt"] & foo.NonExportedType["__doNotUseOrImplementIt"];
}
interface NotExportedChildGenericClass<T> extends foo.NonExportedInterface, foo.NonExportedGenericInterface<T>, foo.NonExportedGenericType<T> {
readonly __doNotUseOrImplementIt: {
readonly "foo.NotExportedChildGenericClass": unique symbol;
} & foo.NonExportedInterface["__doNotUseOrImplementIt"] & foo.NonExportedGenericInterface<T>["__doNotUseOrImplementIt"] & foo.NonExportedGenericType<T>["__doNotUseOrImplementIt"];
}
interface IB extends foo.IA {
readonly __doNotUseOrImplementIt: {
readonly "foo.IB": unique symbol;
} & foo.IA["__doNotUseOrImplementIt"];
}
interface IC extends foo.IB {
readonly __doNotUseOrImplementIt: {
readonly "foo.IC": unique symbol;
} & foo.IB["__doNotUseOrImplementIt"];
}
interface Forth extends foo.Third, foo.IB, foo.IC {
readonly __doNotUseOrImplementIt: {
readonly "foo.Forth": unique symbol;
} & foo.IB["__doNotUseOrImplementIt"] & foo.IC["__doNotUseOrImplementIt"];
}
}
}
@@ -0,0 +1,169 @@
// CHECK_TYPESCRIPT_DECLARATIONS
// RUN_PLAIN_BOX_FUNCTION
// SKIP_MINIFICATION
// SKIP_NODE_JS
// KJS_WITH_FULL_RUNTIME
// INFER_MAIN_MODULE
// GENERATE_STRICT_IMPLICIT_EXPORT
// MODULE: JS_TESTS
// FILE: qualified.kt
@file:JsQualifier("WebAssembly")
package qualified
external interface CompileError
// FILE: notQualified.kt
package notQualified
external interface Console
// FILE: declarations.kt
package foo
import notQualified.Console
import qualified.CompileError
interface NeverUsedInsideExportedDeclarationsType
open class NonExportedParent {
open class NonExportedSecond {
open class NonExportedUsedChild
open class NonExportedUnusedChild
}
}
interface NonExportedInterface
interface NonExportedGenericInterface<T>
open class NonExportedType(val value: Int)
open class NonExportedGenericType<T>(val value: T)
open class NotExportedChildClass : NonExportedInterface, NeverUsedInsideExportedDeclarationsType, NonExportedType(322)
open class NotExportedChildGenericClass<T>(value: T) : NonExportedInterface, NeverUsedInsideExportedDeclarationsType, NonExportedGenericInterface<T>, NonExportedGenericType<T>(value)
@JsExport
interface ExportedInterface
@JsExport
fun producer(value: Int): NonExportedType {
return NonExportedType(value)
}
@JsExport
fun consumer(value: NonExportedType): Int {
return value.value
}
@JsExport
fun childProducer(value: Int): NotExportedChildClass {
return NotExportedChildClass()
}
@JsExport
fun childConsumer(value: NotExportedChildClass): Int {
return value.value
}
@JsExport
fun <T: NonExportedGenericType<Int>> genericChildProducer(value: T): NotExportedChildGenericClass<T> {
return NotExportedChildGenericClass<T>(value)
}
@JsExport
fun <T: NonExportedGenericType<Int>> genericChildConsumer(value: NotExportedChildGenericClass<T>): T {
return value.value
}
@JsExport
open class A(var value: NonExportedType): NonExportedParent.NonExportedSecond.NonExportedUsedChild() {
fun <T: NonExportedType> increment(t: T): NonExportedType {
return NonExportedType(value = t.value + 1)
}
fun getNonExportedUserChild(): NonExportedParent.NonExportedSecond.NonExportedUsedChild {
return this
}
}
@JsExport
class B(v: Int) : NonExportedType(v)
@JsExport
class C : NonExportedInterface
@JsExport
class D : NonExportedInterface, ExportedInterface
@JsExport
class E : NonExportedType(42), ExportedInterface
@JsExport
class F : A(NonExportedType(42)), NonExportedInterface
@JsExport
class G : NonExportedGenericInterface<NonExportedType>
@JsExport
class H : NonExportedGenericType<NonExportedType>(NonExportedType(42))
@JsExport
class I : NotExportedChildClass()
@JsExport
class J : NotExportedChildGenericClass<NonExportedType>(NonExportedType(322))
@JsExport
fun baz(a: Int): kotlin.js.Promise<Int> {
return kotlin.js.Promise<Int> { res, rej -> res(a) }
}
@JsExport
fun bar(): Throwable {
return Throwable("Test Error")
}
@JsExport
fun <T> pep(x: T) where T: NonExportedInterface,
T: NonExportedGenericInterface<Int>
{}
@JsExport
val console: Console
get() = js("console")
@JsExport
val error: CompileError
get() = js("{}")
// Save hierarhy
@JsExport
interface IA
interface IB : IA
interface IC : IB
@JsExport
open class Third: Second()
open class Forth: Third(), IB, IC
open class Fifth: Forth()
@JsExport
class Sixth: Fifth(), IC
@JsExport
open class First
open class Second: First()
@JsExport
fun <T : Forth> acceptForthLike(forth: T) {}
@JsExport
fun <T> acceptMoreGenericForthLike(forth: T) where T: IB, T: IC, T: Third {}
@JsExport
val forth = Forth()
@@ -0,0 +1,28 @@
"use strict";
var producer = JS_TESTS.foo.producer;
var consumer = JS_TESTS.foo.consumer;
var A = JS_TESTS.foo.A;
var B = JS_TESTS.foo.B;
var childProducer = JS_TESTS.foo.childProducer;
var childConsumer = JS_TESTS.foo.childConsumer;
var genericChildProducer = JS_TESTS.foo.genericChildProducer;
var genericChildConsumer = JS_TESTS.foo.genericChildConsumer;
function assert(condition) {
if (!condition) {
throw "Assertion failed";
}
}
function box() {
var nonExportedType = producer(42);
var a = new A(nonExportedType);
var b = new B(43);
assert(consumer(nonExportedType) == 42);
a.value = producer(24);
assert(consumer(b) == 43);
assert(consumer(a.value) == 24);
assert(consumer(a.increment(nonExportedType)) == 43);
var oneMoreNonExportedType = childProducer(322);
assert(consumer(oneMoreNonExportedType) == 322);
assert(childConsumer(oneMoreNonExportedType) == 322);
return "OK";
}
@@ -0,0 +1,33 @@
import producer = JS_TESTS.foo.producer;
import consumer = JS_TESTS.foo.consumer;
import A = JS_TESTS.foo.A;
import B = JS_TESTS.foo.B;
import childProducer = JS_TESTS.foo.childProducer;
import childConsumer = JS_TESTS.foo.childConsumer;
import genericChildProducer = JS_TESTS.foo.genericChildProducer;
import genericChildConsumer = JS_TESTS.foo.genericChildConsumer;
function assert(condition: boolean) {
if (!condition) {
throw "Assertion failed";
}
}
function box(): string {
const nonExportedType = producer(42)
const a = new A(nonExportedType)
const b = new B(43)
assert(consumer(nonExportedType) == 42)
a.value = producer(24)
assert(consumer(b) == 43)
assert(consumer(a.value) == 24)
assert(consumer(a.increment(nonExportedType)) == 43)
const oneMoreNonExportedType = childProducer(322)
assert(consumer(oneMoreNonExportedType) == 322)
assert(childConsumer(oneMoreNonExportedType) == 322)
return "OK";
}
@@ -0,0 +1,4 @@
{
"include": [ "./*" ],
"extends": "../common.tsconfig.json"
}