Skip to content

Commit 8131c51

Browse files
broadwaylambSpace Team
authored andcommitted
[JS] Fix exporting some primitive types via Analysis API
1 parent 8eede38 commit 8131c51

File tree

6 files changed

+34
-30
lines changed

6 files changed

+34
-30
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ declare namespace JS_TESTS {
1111
const _ulong: bigint;
1212
const _long_array: BigInt64Array;
1313
const _ulong_array: Array<bigint>;
14-
const _array_long: BigInt64Array;
14+
const _array_long: Array<bigint>;
1515
const _array_ulong: Array<bigint>;
1616
let myVar: bigint;
1717
const _n_long: Nullable<bigint>;

js/js.translator/testData/typescript-export/js/long-type/long-type.aa.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ declare namespace JS_TESTS {
1111
const _ulong: bigint;
1212
const _long_array: BigInt64Array;
1313
const _ulong_array: Array<bigint>;
14-
const _array_long: BigInt64Array;
14+
const _array_long: Array<bigint>;
1515
const _array_ulong: Array<bigint>;
1616
let myVar: bigint;
1717
const _n_long: Nullable<bigint>;

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ declare namespace JS_TESTS {
3030
const _ubyte_array: Array<any/* kotlin.UByte */>;
3131
const _ushort_array: Array<any/* kotlin.UShort */>;
3232
const _uint_array: Array<any/* kotlin.UInt */>;
33-
const _array_byte: Int8Array;
34-
const _array_short: Int16Array;
35-
const _array_int: Int32Array;
36-
const _array_float: Float32Array;
37-
const _array_double: Float64Array;
33+
const _array_byte: Array<number>;
34+
const _array_short: Array<number>;
35+
const _array_int: Array<number>;
36+
const _array_float: Array<number>;
37+
const _array_double: Array<number>;
3838
const _array_string: Array<string>;
39-
const _array_boolean: any /*BooleanArray*/;
39+
const _array_boolean: Array<boolean>;
4040
const _array_array_string: Array<Array<string>>;
4141
const _array_array_int_array: Array<Array<Int32Array>>;
4242
const _array_ubyte: Array<any/* kotlin.UByte */>;
@@ -54,16 +54,16 @@ declare namespace JS_TESTS {
5454
const _n_boolean: Nullable<boolean>;
5555
const _n_byte: Nullable<number>;
5656
const _n_short_array: Nullable<Int16Array>;
57-
const _n_array_int: Nullable<Int32Array>;
57+
const _n_array_int: Nullable<Array<number>>;
5858
const _array_n_int: Array<Nullable<number>>;
5959
const _n_array_n_int: Nullable<Array<Nullable<number>>>;
6060
const _array_n_array_string: Array<Nullable<Array<string>>>;
6161
const _fun_n_int_unit: (int: Nullable<number>) => void;
6262
const _fun_n_int_unit_class: (int: Nullable<number>) => void;
63-
const _kfun_n_int_unit: (p0: Nullable<number>) => void;
64-
const _fun_n_int_unit_suspend: any /*Suspend function types are not supported*/;
65-
const _fun_n_int_unit_suspend_class: any /*Suspend function types are not supported*/;
66-
const _kfun_n_int_unit_suspend: any /*Suspend function types are not supported*/;
63+
const _kfun_n_int_unit: any/* kotlin.reflect.KFunction1<Nullable<number>, void> */;
64+
const _fun_n_int_unit_suspend: any /*Suspend functions are not supported*/;
65+
const _fun_n_int_unit_suspend_class: any /*Suspend functions are not supported*/;
66+
const _kfun_n_int_unit_suspend: any/* kotlin.reflect.KSuspendFunction1<Nullable<number>, void> */;
6767
const _fun_n_boolean_n_int_n_string_n_intarray: (p0: Nullable<boolean>, p1: Nullable<number>, p2: Nullable<string>) => Nullable<Int32Array>;
6868
const _n_curried_fun: (p0: Nullable<number>) => (p0: Nullable<number>) => (p0: Nullable<number>) => Nullable<number>;
6969
const _n_higher_order_fun: (p0: (p0: Nullable<number>) => Nullable<string>, p1: (p0: Nullable<string>) => Nullable<number>) => (p0: Nullable<number>) => Nullable<number>;

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ declare namespace JS_TESTS {
3030
const _ubyte_array: Array<any/* kotlin.UByte */>;
3131
const _ushort_array: Array<any/* kotlin.UShort */>;
3232
const _uint_array: Array<any/* kotlin.UInt */>;
33-
const _array_byte: Int8Array;
34-
const _array_short: Int16Array;
35-
const _array_int: Int32Array;
36-
const _array_float: Float32Array;
37-
const _array_double: Float64Array;
33+
const _array_byte: Array<number>;
34+
const _array_short: Array<number>;
35+
const _array_int: Array<number>;
36+
const _array_float: Array<number>;
37+
const _array_double: Array<number>;
3838
const _array_string: Array<string>;
39-
const _array_boolean: any /*BooleanArray*/;
39+
const _array_boolean: Array<boolean>;
4040
const _array_array_string: Array<Array<string>>;
4141
const _array_array_int_array: Array<Array<Int32Array>>;
4242
const _array_ubyte: Array<any/* kotlin.UByte */>;
@@ -54,16 +54,16 @@ declare namespace JS_TESTS {
5454
const _n_boolean: Nullable<boolean>;
5555
const _n_byte: Nullable<number>;
5656
const _n_short_array: Nullable<Int16Array>;
57-
const _n_array_int: Nullable<Int32Array>;
57+
const _n_array_int: Nullable<Array<number>>;
5858
const _array_n_int: Array<Nullable<number>>;
5959
const _n_array_n_int: Nullable<Array<Nullable<number>>>;
6060
const _array_n_array_string: Array<Nullable<Array<string>>>;
6161
const _fun_n_int_unit: (int: Nullable<number>) => void;
6262
const _fun_n_int_unit_class: (int: Nullable<number>) => void;
63-
const _kfun_n_int_unit: (p0: Nullable<number>) => void;
64-
const _fun_n_int_unit_suspend: any /*Suspend function types are not supported*/;
65-
const _fun_n_int_unit_suspend_class: any /*Suspend function types are not supported*/;
66-
const _kfun_n_int_unit_suspend: any /*Suspend function types are not supported*/;
63+
const _kfun_n_int_unit: any/* kotlin.reflect.KFunction1<Nullable<number>, void> */;
64+
const _fun_n_int_unit_suspend: any /*Suspend functions are not supported*/;
65+
const _fun_n_int_unit_suspend_class: any /*Suspend functions are not supported*/;
66+
const _kfun_n_int_unit_suspend: any/* kotlin.reflect.KSuspendFunction1<Nullable<number>, void> */;
6767
const _fun_n_boolean_n_int_n_string_n_intarray: (p0: Nullable<boolean>, p1: Nullable<number>, p2: Nullable<string>) => Nullable<Int32Array>;
6868
const _n_curried_fun: (p0: Nullable<number>) => (p0: Nullable<number>) => (p0: Nullable<number>) => Nullable<number>;
6969
const _n_higher_order_fun: (p0: (p0: Nullable<number>) => Nullable<string>, p1: (p0: Nullable<string>) => Nullable<number>) => (p0: Nullable<number>) => Nullable<number>;

js/typescript-export-standalone/src/org/jetbrains/kotlin/js/tsexport/ExportModelGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ internal class ExportModelGenerator(private val config: TypeScriptExportConfig)
129129
}
130130
for (parameter in function.valueParameters) {
131131
val type = if (parameter.isVararg) {
132-
TypeExporter(config).exportArrayWithElementType(parameter.returnType)
132+
TypeExporter(config).exportSpecializedArrayWithElementType(parameter.returnType)
133133
} else {
134134
exportType(parameter.returnType)
135135
}

js/typescript-export-standalone/src/org/jetbrains/kotlin/js/tsexport/TypeExporter.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ internal class TypeExporter(private val config: TypeScriptExportConfig) {
5757
}
5858

5959
context(_: KaSession)
60-
internal fun exportArrayWithElementType(type: KaType): ExportedType = with(type) {
60+
internal fun exportSpecializedArrayWithElementType(type: KaType): ExportedType = with(type) {
6161
when {
6262
isMarkedNullable -> Array(exportType(type))
6363
isByteType -> Primitive.ByteArray
@@ -89,13 +89,17 @@ internal class TypeExporter(private val config: TypeScriptExportConfig) {
8989
if (type.isNothingType)
9090
return Primitive.Nothing
9191
type.arrayElementType?.let {
92-
return exportArrayWithElementType(it)
92+
return if (type.isClassType(StandardClassIds.Array)) {
93+
Array(exportType(it))
94+
} else {
95+
exportSpecializedArrayWithElementType(it)
96+
}
9397
}
9498
if (type.isClassType(StandardClassIds.Throwable))
9599
return Primitive.Throwable
96-
if (type is KaFunctionType) {
100+
if (type is KaFunctionType && !type.isKFunctionType && !type.isKSuspendFunctionType) {
97101
return if (type.isSuspend) {
98-
ErrorType("Suspend function types are not supported")
102+
ErrorType("Suspend functions are not supported")
99103
} else {
100104
Function(
101105
parameters = buildList {
@@ -127,7 +131,7 @@ internal class TypeExporter(private val config: TypeScriptExportConfig) {
127131
if (type is KaTypeParameterType) {
128132
return TypeParameter(type.name.identifier)
129133
}
130-
if (type is KaUsualClassType) {
134+
if (type is KaClassType) {
131135
val symbol = type.symbol
132136
val isExported = shouldDeclarationBeExportedImplicitlyOrExplicitly(symbol)
133137
return when (symbol) {

0 commit comments

Comments
 (0)