JS: repair serialization of type aliases
This commit is contained in:
+6
-24
@@ -497,31 +497,13 @@ class DescriptorSerializer private constructor(
|
|||||||
|
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun packageProto(
|
fun packageProto(
|
||||||
fragments: Collection<PackageFragmentDescriptor>, skip: ((DeclarationDescriptor) -> Boolean)? = null
|
fragments: Collection<PackageFragmentDescriptor>,
|
||||||
|
skip: (DeclarationDescriptor) -> Boolean = { false }
|
||||||
): ProtoBuf.Package.Builder {
|
): ProtoBuf.Package.Builder {
|
||||||
val builder = ProtoBuf.Package.newBuilder()
|
val members = fragments
|
||||||
|
.flatMap { fragment -> DescriptorUtils.getAllDescriptors(fragment.getMemberScope()) }
|
||||||
val members = fragments.flatMap { fragment ->
|
.filter { !skip(it) }
|
||||||
DescriptorUtils.getAllDescriptors(fragment.getMemberScope())
|
return packagePartProto(members)
|
||||||
}
|
|
||||||
|
|
||||||
for (declaration in sort(members)) {
|
|
||||||
if (skip?.invoke(declaration) == true) continue
|
|
||||||
|
|
||||||
when (declaration) {
|
|
||||||
is PropertyDescriptor -> builder.addProperty(propertyProto(declaration))
|
|
||||||
is FunctionDescriptor -> builder.addFunction(functionProto(declaration))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val typeTableProto = typeTable.serialize()
|
|
||||||
if (typeTableProto != null) {
|
|
||||||
builder.typeTable = typeTableProto
|
|
||||||
}
|
|
||||||
|
|
||||||
extension.serializePackage(builder)
|
|
||||||
|
|
||||||
return builder
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun packagePartProto(members: Collection<DeclarationDescriptor>): ProtoBuf.Package.Builder {
|
fun packagePartProto(members: Collection<DeclarationDescriptor>): ProtoBuf.Package.Builder {
|
||||||
|
|||||||
+1
-1
@@ -135,7 +135,7 @@ object KotlinJavascriptSerializationUtil {
|
|||||||
val packageStream = ByteArrayOutputStream()
|
val packageStream = ByteArrayOutputStream()
|
||||||
val fragments = packageView.fragments
|
val fragments = packageView.fragments
|
||||||
val packageProto = serializer.packageProto(fragments, skip).build() ?: error("Package fragments not serialized: $fragments")
|
val packageProto = serializer.packageProto(fragments, skip).build() ?: error("Package fragments not serialized: $fragments")
|
||||||
if (packageProto.functionCount > 0 || packageProto.propertyCount > 0) {
|
if (packageProto.functionCount > 0 || packageProto.propertyCount > 0 || packageProto.typeAliasCount > 0) {
|
||||||
packageProto.writeTo(packageStream)
|
packageProto.writeTo(packageStream)
|
||||||
writeFun(KotlinJavascriptSerializedResourcePaths.getPackageFilePath(fqName), packageStream.toByteArray())
|
writeFun(KotlinJavascriptSerializedResourcePaths.getPackageFilePath(fqName), packageStream.toByteArray())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,12 @@ public class MultiModuleTestGenerated extends AbstractMultiModuleTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typealiases")
|
||||||
|
public void testTypealiases() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/multiModule/cases/typealiases/");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("useElementsFromDefaultPackageInAnotherModule")
|
@TestMetadata("useElementsFromDefaultPackageInAnotherModule")
|
||||||
public void testUseElementsFromDefaultPackageInAnotherModule() throws Exception {
|
public void testUseElementsFromDefaultPackageInAnotherModule() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/multiModule/cases/useElementsFromDefaultPackageInAnotherModule/");
|
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/multiModule/cases/useElementsFromDefaultPackageInAnotherModule/");
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
lib->
|
||||||
|
main->lib
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
object O {
|
||||||
|
val x = "O"
|
||||||
|
|
||||||
|
val y = "K"
|
||||||
|
}
|
||||||
|
|
||||||
|
class C {
|
||||||
|
typealias B = O
|
||||||
|
}
|
||||||
|
|
||||||
|
typealias A = O
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
import lib.*
|
||||||
|
|
||||||
|
fun box() = A.x + C.B.y
|
||||||
Reference in New Issue
Block a user