Skip to content

Commit 955b479

Browse files
broadwaylambSpace Team
authored andcommitted
[JS] Export parameter names in function types in .d.ts files
^KT-82327 Fixed
1 parent 8ab919b commit 955b479

File tree

14 files changed

+27
-23
lines changed

14 files changed

+27
-23
lines changed

compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/tsexport/ExportModelGenerator.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import org.jetbrains.kotlin.descriptors.ClassKind
1212
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
1313
import org.jetbrains.kotlin.descriptors.DescriptorVisibility
1414
import org.jetbrains.kotlin.descriptors.Modality
15-
import org.jetbrains.kotlin.ir.backend.js.*
15+
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
16+
import org.jetbrains.kotlin.ir.backend.js.JsLoweredDeclarationOrigin
17+
import org.jetbrains.kotlin.ir.backend.js.correspondingEnumEntry
18+
import org.jetbrains.kotlin.ir.backend.js.initEntryInstancesFun
1619
import org.jetbrains.kotlin.ir.backend.js.lower.ES6_BOX_PARAMETER
1720
import org.jetbrains.kotlin.ir.backend.js.lower.coroutines.isPromisifiedWrapper
1821
import org.jetbrains.kotlin.ir.backend.js.lower.isBoxParameter
@@ -650,7 +653,7 @@ class ExportModelGenerator(val context: JsIrBackendContext, val generateNamespac
650653
nonNullType.isFunction() -> ExportedType.Function(
651654
parameters = nonNullType.arguments.dropLast(1).memoryOptimizedMap {
652655
ExportedParameter(
653-
name = null,
656+
name = (it as? IrTypeProjection)?.type?.getAnnotationArgumentValue(StandardNames.FqNames.parameterName, "name"),
654657
type = exportTypeArgument(it, typeOwner),
655658
)
656659
},

compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/export/ExportModelGenerator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package org.jetbrains.kotlin.backend.wasm.export
77

88
import org.jetbrains.kotlin.backend.wasm.WasmBackendContext
9+
import org.jetbrains.kotlin.builtins.StandardNames
910
import org.jetbrains.kotlin.config.CommonConfigurationKeys
1011
import org.jetbrains.kotlin.descriptors.ClassKind
1112
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
@@ -206,7 +207,7 @@ class ExportModelGenerator(val context: WasmBackendContext) {
206207
nonNullType.isFunction() -> ExportedType.Function(
207208
parameters = nonNullType.arguments.dropLast(1).memoryOptimizedMap {
208209
ExportedParameter(
209-
name = null,
210+
name = (it as? IrTypeProjection)?.type?.getAnnotationArgumentValue(StandardNames.FqNames.parameterName, "name"),
210211
type = exportTypeArgument(it),
211212
)
212213
},

compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,11 @@ internal fun IrConstructorCall.getAnnotationValueOrNullImpl(name: String): Any?
363363
return (argument as IrConst?)?.value
364364
}
365365

366-
inline fun <reified T> IrDeclaration.getAnnotationArgumentValue(fqName: FqName, argumentName: String): T? =
366+
inline fun <reified T> IrAnnotationContainer.getAnnotationArgumentValue(fqName: FqName, argumentName: String): T? =
367367
getAnnotationArgumentValueImpl(fqName, argumentName) as T?
368368

369369
@PublishedApi
370-
internal fun IrDeclaration.getAnnotationArgumentValueImpl(fqName: FqName, argumentName: String): Any? {
370+
internal fun IrAnnotationContainer.getAnnotationArgumentValueImpl(fqName: FqName, argumentName: String): Any? {
371371
val annotation = this.annotations.findAnnotation(fqName) ?: return null
372372
for (parameter in annotation.symbol.owner.parameters) {
373373
if (parameter.name.asString() == argumentName) {

js/js.translator/testData/typescript-export/js/functions-in-exported-file/functions.aa.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ declare namespace JS_TESTS {
3636
function concatWithContextParameters(scope1: foo.Scope1, scope2: foo.Scope2): string;
3737
function concatWithExtensionAndContextParameter(scope1: foo.Scope1, _this_: foo.Scope2): string;
3838
function getWithExtension(_this_: foo.Scope1): string;
39-
function allParameters<A, B, C, D, R>(a: A, b: B, c: C, d: D, block: (p0: A, p1: B, p2: C, p3: D) => R): R;
39+
function allParameters<A, B, C, D, R>(a: A, b: B, c: C, d: D, block: (p0: A, p1: B, _this_: C, d: D) => R): R;
4040
/* ErrorDeclaration: Class declarations are not implemented yet */
4141
/* ErrorDeclaration: Class declarations are not implemented yet */
4242
/* ErrorDeclaration: Class declarations are not implemented yet */

js/js.translator/testData/typescript-export/js/functions-in-exported-file/functions.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ declare namespace JS_TESTS {
6868
function concatWithContextParameters(scope1: foo.Scope1, scope2: foo.Scope2): string;
6969
function concatWithExtensionAndContextParameter(scope1: foo.Scope1, _this_: foo.Scope2): string;
7070
function getWithExtension(_this_: foo.Scope1): string;
71-
function allParameters<A, B, C, D, R>(a: A, b: B, c: C, d: D, block: (p0: A, p1: B, p2: C, p3: D) => R): R;
71+
function allParameters<A, B, C, D, R>(a: A, b: B, c: C, d: D, block: (p0: A, p1: B, p2: C, d: D) => R): R;
7272
}
7373
}

js/js.translator/testData/typescript-export/js/functions/functions.aa.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ declare namespace JS_TESTS {
3636
function concatWithContextParameters(scope1: foo.Scope1, scope2: foo.Scope2): string;
3737
function concatWithExtensionAndContextParameter(scope1: foo.Scope1, _this_: foo.Scope2): string;
3838
function getWithExtension(_this_: foo.Scope1): string;
39-
function allParameters<A, B, C, D, R>(a: A, b: B, c: C, d: D, block: (p0: A, p1: B, p2: C, p3: D) => R): R;
39+
function allParameters<A, B, C, D, R>(a: A, b: B, c: C, d: D, block: (p0: A, p1: B, _this_: C, d: D) => R): R;
4040
/* ErrorDeclaration: Class declarations are not implemented yet */
4141
/* ErrorDeclaration: Class declarations are not implemented yet */
4242
/* ErrorDeclaration: Class declarations are not implemented yet */

js/js.translator/testData/typescript-export/js/functions/functions.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@ declare namespace JS_TESTS {
6868
function concatWithContextParameters(scope1: foo.Scope1, scope2: foo.Scope2): string;
6969
function concatWithExtensionAndContextParameter(scope1: foo.Scope1, _this_: foo.Scope2): string;
7070
function getWithExtension(_this_: foo.Scope1): string;
71-
function allParameters<A, B, C, D, R>(a: A, b: B, c: C, d: D, block: (p0: A, p1: B, p2: C, p3: D) => R): R;
71+
function allParameters<A, B, C, D, R>(a: A, b: B, c: C, d: D, block: (p0: A, p1: B, p2: C, d: D) => R): R;
7272
}
7373
}

js/js.translator/testData/typescript-export/js/primitives-in-exported-file/primitives.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ declare namespace JS_TESTS {
5353
const _array_n_int: Array<Nullable<number>>;
5454
const _n_array_n_int: Nullable<Array<Nullable<number>>>;
5555
const _array_n_array_string: Array<Nullable<Array<string>>>;
56-
const _fun_n_int_unit: (p0: Nullable<number>) => void;
57-
const _fun_n_int_unit_class: (p0: Nullable<number>) => void;
56+
const _fun_n_int_unit: (int: Nullable<number>) => void;
57+
const _fun_n_int_unit_class: (int: Nullable<number>) => void;
5858
const _kfun_n_int_unit: any/* kotlin.reflect.KFunction1<Nullable<number>, void> */;
5959
const _fun_n_int_unit_suspend: any /*Suspend functions are not supported*/;
6060
const _fun_n_int_unit_suspend_class: any /*Suspend functions are not supported*/;

js/js.translator/testData/typescript-export/js/primitives/primitives.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ declare namespace JS_TESTS {
5353
const _array_n_int: Array<Nullable<number>>;
5454
const _n_array_n_int: Nullable<Array<Nullable<number>>>;
5555
const _array_n_array_string: Array<Nullable<Array<string>>>;
56-
const _fun_n_int_unit: (p0: Nullable<number>) => void;
57-
const _fun_n_int_unit_class: (p0: Nullable<number>) => void;
56+
const _fun_n_int_unit: (int: Nullable<number>) => void;
57+
const _fun_n_int_unit_class: (int: Nullable<number>) => void;
5858
const _kfun_n_int_unit: any/* kotlin.reflect.KFunction1<Nullable<number>, void> */;
5959
const _fun_n_int_unit_suspend: any /*Suspend functions are not supported*/;
6060
const _fun_n_int_unit_suspend_class: any /*Suspend functions are not supported*/;

js/js.translator/testData/typescript-export/wasm/nullablePrimitives/index.d.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ export declare function consumeInt(x: Nullable<number>): Nullable<string>;
1515
export declare function consumeLong(x: Nullable<bigint>): Nullable<string>;
1616
export declare function consumeChar(x: Nullable<number>): Nullable<string>;
1717
export declare function consumeString(x: Nullable<string>): Nullable<string>;
18-
export declare function consumeFunction(fn: Nullable<(p0: string) => number>): Nullable<number>;
18+
export declare function consumeFunction(fn: Nullable<(string: string) => number>): Nullable<number>;

0 commit comments

Comments
 (0)