[K/JS] Support companion objects in external and exported declarations
This commit is contained in:
@@ -22,7 +22,7 @@ object JsPlatformConfigurator : PlatformConfiguratorBase(
|
||||
additionalDeclarationCheckers = listOf(
|
||||
NativeInvokeChecker(), NativeGetterChecker(), NativeSetterChecker(),
|
||||
JsNameChecker, JsModuleChecker, JsExternalFileChecker,
|
||||
JsExternalChecker, JsInheritanceChecker, JsMultipleInheritanceChecker,
|
||||
JsInheritanceChecker, JsMultipleInheritanceChecker,
|
||||
JsExternalInheritorOnlyChecker,
|
||||
JsRuntimeAnnotationChecker,
|
||||
JsDynamicDeclarationChecker,
|
||||
@@ -51,7 +51,8 @@ object JsPlatformConfigurator : PlatformConfiguratorBase(
|
||||
container.useInstance(ExtensionFunctionToExternalIsInlinable)
|
||||
container.useInstance(JsQualifierChecker)
|
||||
container.useInstance(JsNativeDiagnosticSuppressor)
|
||||
container.useInstance(JsExportDeclarationChecker(includeUnsignedNumbers = false))
|
||||
container.useInstance(JsExternalChecker(allowCompanionInInterface = true))
|
||||
container.useInstance(JsExportDeclarationChecker(allowCompanionInInterface = true, includeUnsignedNumbers = false))
|
||||
}
|
||||
|
||||
override fun configureModuleDependentCheckers(container: StorageComponentContainer) {
|
||||
|
||||
+3
@@ -34,6 +34,9 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
put(ErrorsJs.INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING, "Using value classes as parameter type or return type of external declarations is experimental")
|
||||
put(ErrorsJs.ENUM_CLASS_IN_EXTERNAL_DECLARATION_WARNING, "Using enum classes with an `external` qualifier becomes deprecated and will be an error in future releases")
|
||||
|
||||
put(ErrorsJs.NAMED_COMPANION_IN_EXTERNAL_INTERFACE, "Named companions are not allowed inside external interfaces")
|
||||
put(ErrorsJs.NAMED_COMPANION_IN_EXPORTED_INTERFACE, "Named companions are not allowed inside exported interfaces")
|
||||
|
||||
put(ErrorsJs.JS_NAME_CLASH, "JavaScript name ({0}) generated for this declaration clashes with another declaration: {1}",
|
||||
STRING, Renderers.COMPACT)
|
||||
put(ErrorsJs.JS_FAKE_NAME_CLASH, "JavaScript name {0} is generated for different inherited members: {1} and {2}",
|
||||
|
||||
@@ -36,6 +36,8 @@ public interface ErrorsJs {
|
||||
DiagnosticFactory0<KtElement> INLINE_CLASS_IN_EXTERNAL_DECLARATION = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory0<KtElement> ENUM_CLASS_IN_EXTERNAL_DECLARATION_WARNING = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory0<KtElement> INLINE_CLASS_IN_EXTERNAL_DECLARATION_WARNING = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory0<KtElement> NAMED_COMPANION_IN_EXTERNAL_INTERFACE = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory0<KtElement> NAMED_COMPANION_IN_EXPORTED_INTERFACE = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
|
||||
DiagnosticFactory2<KtElement, String, DeclarationDescriptor> JS_NAME_CLASH = DiagnosticFactory2.create(
|
||||
ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.js.resolve.diagnostics
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.js.resolve.diagnostics.JsExternalChecker.DEFINED_EXTERNALLY_PROPERTY_NAMES
|
||||
import org.jetbrains.kotlin.js.resolve.diagnostics.JsExternalChecker.Companion.DEFINED_EXTERNALLY_PROPERTY_NAMES
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||
|
||||
+10
-2
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.js.common.SPECIAL_KEYWORDS
|
||||
import org.jetbrains.kotlin.js.naming.NameSuggestion
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT
|
||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
@@ -35,7 +36,10 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.isDynamic
|
||||
import org.jetbrains.kotlin.types.typeUtil.*
|
||||
|
||||
class JsExportDeclarationChecker(private val includeUnsignedNumbers: Boolean) : DeclarationChecker {
|
||||
class JsExportDeclarationChecker(
|
||||
private val includeUnsignedNumbers: Boolean,
|
||||
private val allowCompanionInInterface: Boolean
|
||||
) : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
val trace = context.trace
|
||||
val bindingContext = trace.bindingContext
|
||||
@@ -130,11 +134,15 @@ class JsExportDeclarationChecker(private val includeUnsignedNumbers: Boolean) :
|
||||
descriptor.isInlineClass() -> "${if (descriptor.isInline) "inline " else ""}${if (descriptor.isValue) "value " else ""}class"
|
||||
else -> null
|
||||
}
|
||||
else -> if (descriptor.isInsideInterface) {
|
||||
else -> if (descriptor.isInsideInterface && (!allowCompanionInInterface || !descriptor.isCompanionObject)) {
|
||||
"${if (descriptor.isCompanionObject) "companion object" else "nested/inner declaration"} inside exported interface"
|
||||
} else null
|
||||
}
|
||||
|
||||
if (allowCompanionInInterface && descriptor.isCompanionObject && descriptor.isInsideInterface && descriptor.name != DEFAULT_NAME_FOR_COMPANION_OBJECT) {
|
||||
trace.report(ErrorsJs.NAMED_COMPANION_IN_EXPORTED_INTERFACE.on(declaration))
|
||||
}
|
||||
|
||||
if (wrongDeclaration != null) {
|
||||
reportWrongExportedDeclaration(wrongDeclaration)
|
||||
return
|
||||
|
||||
+13
-6
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.js.PredefinedAnnotation
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.JsStandardClassIds
|
||||
import org.jetbrains.kotlin.name.SpecialNames.DEFAULT_NAME_FOR_COMPANION_OBJECT
|
||||
import org.jetbrains.kotlin.platform.isWasm
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -28,9 +29,11 @@ import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
|
||||
object JsExternalChecker : DeclarationChecker {
|
||||
val DEFINED_EXTERNALLY_PROPERTY_NAMES = JsStandardClassIds.Callables.definedExternallyPropertyNames
|
||||
.map { it.asSingleFqName().toUnsafe() }
|
||||
class JsExternalChecker(private val allowCompanionInInterface: Boolean) : DeclarationChecker {
|
||||
companion object {
|
||||
val DEFINED_EXTERNALLY_PROPERTY_NAMES = JsStandardClassIds.Callables.definedExternallyPropertyNames
|
||||
.map { it.asSingleFqName().toUnsafe() }
|
||||
}
|
||||
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
if (!AnnotationsUtils.isNativeObject(descriptor)) return
|
||||
@@ -68,12 +71,16 @@ object JsExternalChecker : DeclarationChecker {
|
||||
trace.report(ErrorsJs.WRONG_EXTERNAL_DECLARATION.on(declaration, "private member of class"))
|
||||
}
|
||||
|
||||
if (descriptor is ClassDescriptor && descriptor.kind != ClassKind.INTERFACE &&
|
||||
descriptor.containingDeclaration.let { it is ClassDescriptor && it.kind == ClassKind.INTERFACE }
|
||||
) {
|
||||
val containingDeclarationsIsInterface = descriptor.containingDeclaration.let { it is ClassDescriptor && it.kind == ClassKind.INTERFACE }
|
||||
|
||||
if (descriptor is ClassDescriptor && descriptor.kind != ClassKind.INTERFACE && (!allowCompanionInInterface || !descriptor.isCompanionObject) && containingDeclarationsIsInterface) {
|
||||
trace.report(ErrorsJs.NESTED_CLASS_IN_EXTERNAL_INTERFACE.on(declaration))
|
||||
}
|
||||
|
||||
if (allowCompanionInInterface && descriptor.isCompanionObject() && containingDeclarationsIsInterface && descriptor.name != DEFAULT_NAME_FOR_COMPANION_OBJECT) {
|
||||
trace.report(ErrorsJs.NAMED_COMPANION_IN_EXTERNAL_INTERFACE.on(declaration))
|
||||
}
|
||||
|
||||
if (descriptor !is PropertyAccessorDescriptor && descriptor.isExtension) {
|
||||
val target = when (descriptor) {
|
||||
is FunctionDescriptor -> "extension function"
|
||||
|
||||
+8
-1
@@ -17,6 +17,9 @@
|
||||
package org.jetbrains.kotlin.js.inline.clean
|
||||
|
||||
import org.jetbrains.kotlin.js.backend.ast.*
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.SideEffectKind
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.constant
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.sideEffects
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.synthetic
|
||||
import org.jetbrains.kotlin.js.inline.util.collectFreeVariables
|
||||
|
||||
@@ -55,7 +58,8 @@ internal class RedundantVariableDeclarationElimination(private val root: JsState
|
||||
object : JsVisitorWithContextImpl() {
|
||||
override fun endVisit(x: JsVars, ctx: JsContext<*>) {
|
||||
if (x.synthetic) {
|
||||
if (x.vars.removeAll { it.initExpression == null && it.name !in usages }) {
|
||||
if (
|
||||
x.vars.removeAll { it.initExpression.isPure && it.name !in usages }) {
|
||||
hasChanges = true
|
||||
}
|
||||
if (x.vars.isEmpty()) {
|
||||
@@ -65,6 +69,9 @@ internal class RedundantVariableDeclarationElimination(private val root: JsState
|
||||
super.endVisit(x, ctx)
|
||||
}
|
||||
|
||||
private val JsExpression?.isPure: Boolean
|
||||
get() = this == null || constant || sideEffects == SideEffectKind.PURE
|
||||
|
||||
override fun visit(x: JsFunction, ctx: JsContext<*>) = false
|
||||
}.accept(root)
|
||||
}
|
||||
|
||||
+30
@@ -2605,6 +2605,12 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest {
|
||||
runTest("js/js.translator/testData/box/esModules/jsExport/exportedDefaultStub.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfaceWithCompanion.kt")
|
||||
public void testInterfaceWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/esModules/jsExport/interfaceWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportInClass.kt")
|
||||
public void testJsExportInClass() {
|
||||
@@ -2699,6 +2705,12 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest {
|
||||
runTest("js/js.translator/testData/box/esModules/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/esModules/jsModule/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExternalInheritorsOnly.kt")
|
||||
public void testJsExternalInheritorsOnly() {
|
||||
@@ -7524,6 +7536,12 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest {
|
||||
runTest("js/js.translator/testData/box/jsExport/exportedDefaultStub.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfaceWithCompanion.kt")
|
||||
public void testInterfaceWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsExport/interfaceWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportInClass.kt")
|
||||
public void testJsExportInClass() {
|
||||
@@ -7660,6 +7678,12 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest {
|
||||
runTest("js/js.translator/testData/box/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsModule/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt39378.kt")
|
||||
public void testKt39378() {
|
||||
@@ -7836,6 +7860,12 @@ public class FirJsES6BoxTestGenerated extends AbstractFirJsES6BoxTest {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() {
|
||||
|
||||
Generated
+30
@@ -2499,6 +2499,12 @@ public class FirLightTreeJsBoxTestGenerated extends AbstractFirLightTreeJsBoxTes
|
||||
runTest("js/js.translator/testData/box/esModules/jsExport/exportedDefaultStub.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfaceWithCompanion.kt")
|
||||
public void testInterfaceWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/esModules/jsExport/interfaceWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportInClass.kt")
|
||||
public void testJsExportInClass() {
|
||||
@@ -2593,6 +2599,12 @@ public class FirLightTreeJsBoxTestGenerated extends AbstractFirLightTreeJsBoxTes
|
||||
runTest("js/js.translator/testData/box/esModules/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/esModules/jsModule/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExternalInheritorsOnly.kt")
|
||||
public void testJsExternalInheritorsOnly() {
|
||||
@@ -7418,6 +7430,12 @@ public class FirLightTreeJsBoxTestGenerated extends AbstractFirLightTreeJsBoxTes
|
||||
runTest("js/js.translator/testData/box/jsExport/exportedDefaultStub.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfaceWithCompanion.kt")
|
||||
public void testInterfaceWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsExport/interfaceWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportInClass.kt")
|
||||
public void testJsExportInClass() {
|
||||
@@ -7554,6 +7572,12 @@ public class FirLightTreeJsBoxTestGenerated extends AbstractFirLightTreeJsBoxTes
|
||||
runTest("js/js.translator/testData/box/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsModule/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt39378.kt")
|
||||
public void testKt39378() {
|
||||
@@ -7730,6 +7754,12 @@ public class FirLightTreeJsBoxTestGenerated extends AbstractFirLightTreeJsBoxTes
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() {
|
||||
|
||||
+30
@@ -2499,6 +2499,12 @@ public class FirPsiJsBoxTestGenerated extends AbstractFirPsiJsBoxTest {
|
||||
runTest("js/js.translator/testData/box/esModules/jsExport/exportedDefaultStub.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfaceWithCompanion.kt")
|
||||
public void testInterfaceWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/esModules/jsExport/interfaceWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportInClass.kt")
|
||||
public void testJsExportInClass() {
|
||||
@@ -2593,6 +2599,12 @@ public class FirPsiJsBoxTestGenerated extends AbstractFirPsiJsBoxTest {
|
||||
runTest("js/js.translator/testData/box/esModules/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/esModules/jsModule/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExternalInheritorsOnly.kt")
|
||||
public void testJsExternalInheritorsOnly() {
|
||||
@@ -7418,6 +7430,12 @@ public class FirPsiJsBoxTestGenerated extends AbstractFirPsiJsBoxTest {
|
||||
runTest("js/js.translator/testData/box/jsExport/exportedDefaultStub.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfaceWithCompanion.kt")
|
||||
public void testInterfaceWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsExport/interfaceWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportInClass.kt")
|
||||
public void testJsExportInClass() {
|
||||
@@ -7554,6 +7572,12 @@ public class FirPsiJsBoxTestGenerated extends AbstractFirPsiJsBoxTest {
|
||||
runTest("js/js.translator/testData/box/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsModule/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt39378.kt")
|
||||
public void testKt39378() {
|
||||
@@ -7730,6 +7754,12 @@ public class FirPsiJsBoxTestGenerated extends AbstractFirPsiJsBoxTest {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() {
|
||||
|
||||
+30
@@ -2605,6 +2605,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
||||
runTest("js/js.translator/testData/box/esModules/jsExport/exportedDefaultStub.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfaceWithCompanion.kt")
|
||||
public void testInterfaceWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/esModules/jsExport/interfaceWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportInClass.kt")
|
||||
public void testJsExportInClass() {
|
||||
@@ -2699,6 +2705,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
||||
runTest("js/js.translator/testData/box/esModules/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/esModules/jsModule/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExternalInheritorsOnly.kt")
|
||||
public void testJsExternalInheritorsOnly() {
|
||||
@@ -7524,6 +7536,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
||||
runTest("js/js.translator/testData/box/jsExport/exportedDefaultStub.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfaceWithCompanion.kt")
|
||||
public void testInterfaceWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsExport/interfaceWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportInClass.kt")
|
||||
public void testJsExportInClass() {
|
||||
@@ -7660,6 +7678,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
||||
runTest("js/js.translator/testData/box/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsModule/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt39378.kt")
|
||||
public void testKt39378() {
|
||||
@@ -7836,6 +7860,12 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() {
|
||||
|
||||
+30
@@ -2499,6 +2499,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/esModules/jsExport/exportedDefaultStub.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfaceWithCompanion.kt")
|
||||
public void testInterfaceWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/esModules/jsExport/interfaceWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportInClass.kt")
|
||||
public void testJsExportInClass() {
|
||||
@@ -2593,6 +2599,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/esModules/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/esModules/jsModule/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExternalInheritorsOnly.kt")
|
||||
public void testJsExternalInheritorsOnly() {
|
||||
@@ -7418,6 +7430,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/jsExport/exportedDefaultStub.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfaceWithCompanion.kt")
|
||||
public void testInterfaceWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsExport/interfaceWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("jsExportInClass.kt")
|
||||
public void testJsExportInClass() {
|
||||
@@ -7554,6 +7572,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/jsModule/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsModule/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt39378.kt")
|
||||
public void testKt39378() {
|
||||
@@ -7730,6 +7754,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfaces.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("interfacesWithCompanion.kt")
|
||||
public void testInterfacesWithCompanion() {
|
||||
runTest("js/js.translator/testData/box/jsQualifier/interfacesWithCompanion.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// SKIP_MINIFICATION
|
||||
// ES_MODULES
|
||||
|
||||
// FILE: api.kt
|
||||
package api
|
||||
|
||||
@JsExport
|
||||
interface A {
|
||||
companion object {
|
||||
fun ok() = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
external interface JsResult {
|
||||
val res: String
|
||||
}
|
||||
|
||||
@JsModule("./interfaceWithCompanion.mjs")
|
||||
external fun jsBox(): JsResult
|
||||
|
||||
fun box(): String {
|
||||
return jsBox().res
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import * as api from "./interfaceWithCompanion_v5.mjs";
|
||||
|
||||
export default function() {
|
||||
return {
|
||||
"res": api.A.getInstance().ok()
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// TARGET_BACKEND: JS_IR_ES6
|
||||
// EXPECTED_REACHABLE_NODES: 1238
|
||||
// ES_MODULES
|
||||
// FILE: bar.kt
|
||||
@file:JsModule("./interfacesWithCompanion.mjs")
|
||||
package bar
|
||||
|
||||
external interface Bar {
|
||||
companion object {
|
||||
fun ok(): String
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
import bar.Bar
|
||||
|
||||
fun box(): String {
|
||||
return Bar.ok()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export const Bar = {
|
||||
ok() { return "OK" }
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
$kotlin_test_internal$.beginModule();
|
||||
|
||||
module.exports = function() {
|
||||
var { A } = require("main").api
|
||||
|
||||
return {
|
||||
"res": A.ok()
|
||||
};
|
||||
};
|
||||
|
||||
$kotlin_test_internal$.endModule("lib");
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// MODULE_KIND: COMMON_JS
|
||||
// SKIP_MINIFICATION
|
||||
|
||||
// FILE: api.kt
|
||||
package api
|
||||
|
||||
@JsExport
|
||||
interface A {
|
||||
companion object {
|
||||
fun ok() = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
external interface JsResult {
|
||||
val res: String
|
||||
}
|
||||
|
||||
@JsModule("lib")
|
||||
external fun jsBox(): JsResult
|
||||
|
||||
fun box(): String {
|
||||
return jsBox().res
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
define("bar", [], function() {
|
||||
return {
|
||||
Bar: {
|
||||
ok() { return "OK" }
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// TARGET_BACKEND: JS_IR_ES6
|
||||
// EXPECTED_REACHABLE_NODES: 1238
|
||||
// MODULE_KIND: AMD
|
||||
// FILE: bar.kt
|
||||
@file:JsModule("bar")
|
||||
package bar
|
||||
|
||||
external interface Bar {
|
||||
companion object {
|
||||
fun ok(): String
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
import bar.Bar
|
||||
|
||||
inline fun Bar.Companion.test() = "CHECK"
|
||||
|
||||
fun box(): String {
|
||||
Bar.test()
|
||||
return Bar.ok()
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// TARGET_BACKEND: JS_IR_ES6
|
||||
// EXPECTED_REACHABLE_NODES: 1238
|
||||
// FILE: bar.kt
|
||||
@file:JsQualifier("bar")
|
||||
package bar
|
||||
|
||||
external interface Bar {
|
||||
companion object {
|
||||
fun ok(): String
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
import bar.Bar
|
||||
|
||||
fun box(): String {
|
||||
return Bar.ok()
|
||||
}
|
||||
|
||||
// FILE: test.js
|
||||
var bar = function() {
|
||||
var Bar = {
|
||||
ok() {
|
||||
return "OK"
|
||||
}
|
||||
};
|
||||
return {
|
||||
Bar: Bar
|
||||
}
|
||||
}();
|
||||
+10
-1
@@ -30,6 +30,15 @@ declare namespace JS_TESTS {
|
||||
readonly __doNotUseOrImplementIt: foo.TestInterfaceImpl["__doNotUseOrImplementIt"] & foo.AnotherExportedInterface["__doNotUseOrImplementIt"];
|
||||
}
|
||||
function processInterface(test: foo.TestInterface): string;
|
||||
interface WithTheCompanion {
|
||||
readonly interfaceField: string;
|
||||
readonly __doNotUseOrImplementIt: {
|
||||
readonly "foo.WithTheCompanion": unique symbol;
|
||||
};
|
||||
}
|
||||
const WithTheCompanion: {
|
||||
companionFunction(): string;
|
||||
};
|
||||
function processOptionalInterface(a: foo.OptionalFieldsInterface): string;
|
||||
interface InterfaceWithCompanion {
|
||||
readonly __doNotUseOrImplementIt: {
|
||||
@@ -37,4 +46,4 @@ declare namespace JS_TESTS {
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -43,6 +43,15 @@ external interface OptionalFieldsInterface {
|
||||
}
|
||||
|
||||
|
||||
interface WithTheCompanion {
|
||||
val interfaceField: String
|
||||
|
||||
companion object {
|
||||
fun companionFunction(): String = "FUNCTION"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun processOptionalInterface(a: OptionalFieldsInterface): String {
|
||||
return "${a.required}${a.notRequired ?: "unknown"}"
|
||||
}
|
||||
@@ -52,6 +61,7 @@ fun processOptionalInterface(a: OptionalFieldsInterface): String {
|
||||
interface InterfaceWithCompanion {
|
||||
// Emulate added by plugin companion like kotlinx.serialization does
|
||||
@Suppress("WRONG_EXPORTED_DECLARATION")
|
||||
@JsExport.Ignore
|
||||
companion object {
|
||||
fun foo() = "String"
|
||||
}
|
||||
|
||||
Vendored
+3
@@ -2,6 +2,7 @@ import TestInterfaceImpl = JS_TESTS.foo.TestInterfaceImpl;
|
||||
import ChildTestInterfaceImpl = JS_TESTS.foo.ChildTestInterfaceImpl;
|
||||
import processInterface = JS_TESTS.foo.processInterface;
|
||||
import processOptionalInterface = JS_TESTS.foo.processOptionalInterface;
|
||||
import WithTheCompanion = JS_TESTS.foo.WithTheCompanion;
|
||||
|
||||
function assert(condition: boolean) {
|
||||
if (!condition) {
|
||||
@@ -20,5 +21,7 @@ function box(): string {
|
||||
assert(processOptionalInterface({ required: 4, notRequired: null }) == "4unknown")
|
||||
assert(processOptionalInterface({ required: 4, notRequired: 5 }) == "45")
|
||||
|
||||
assert(WithTheCompanion.companionFunction() == "FUNCTION")
|
||||
|
||||
return "OK";
|
||||
}
|
||||
@@ -30,6 +30,15 @@ declare namespace JS_TESTS {
|
||||
readonly __doNotUseOrImplementIt: foo.TestInterfaceImpl["__doNotUseOrImplementIt"] & foo.AnotherExportedInterface["__doNotUseOrImplementIt"];
|
||||
}
|
||||
function processInterface(test: foo.TestInterface): string;
|
||||
interface WithTheCompanion {
|
||||
readonly interfaceField: string;
|
||||
readonly __doNotUseOrImplementIt: {
|
||||
readonly "foo.WithTheCompanion": unique symbol;
|
||||
};
|
||||
}
|
||||
const WithTheCompanion: {
|
||||
companionFunction(): string;
|
||||
};
|
||||
function processOptionalInterface(a: foo.OptionalFieldsInterface): string;
|
||||
interface InterfaceWithCompanion {
|
||||
readonly __doNotUseOrImplementIt: {
|
||||
@@ -37,4 +46,4 @@ declare namespace JS_TESTS {
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,15 @@ external interface OptionalFieldsInterface {
|
||||
val notRequired: Int?
|
||||
}
|
||||
|
||||
@JsExport
|
||||
interface WithTheCompanion {
|
||||
val interfaceField: String
|
||||
|
||||
companion object {
|
||||
fun companionFunction(): String = "FUNCTION"
|
||||
}
|
||||
}
|
||||
|
||||
@JsExport
|
||||
fun processOptionalInterface(a: OptionalFieldsInterface): String {
|
||||
return "${a.required}${a.notRequired ?: "unknown"}"
|
||||
@@ -48,6 +57,7 @@ fun processOptionalInterface(a: OptionalFieldsInterface): String {
|
||||
interface InterfaceWithCompanion {
|
||||
// Emulate added by plugin companion like kotlinx.serialization does
|
||||
@Suppress("WRONG_EXPORTED_DECLARATION")
|
||||
@JsExport.Ignore
|
||||
companion object {
|
||||
fun foo() = "String"
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import TestInterfaceImpl = JS_TESTS.foo.TestInterfaceImpl;
|
||||
import ChildTestInterfaceImpl = JS_TESTS.foo.ChildTestInterfaceImpl;
|
||||
import processInterface = JS_TESTS.foo.processInterface;
|
||||
import processOptionalInterface = JS_TESTS.foo.processOptionalInterface;
|
||||
import WithTheCompanion = JS_TESTS.foo.WithTheCompanion;
|
||||
|
||||
function assert(condition: boolean) {
|
||||
if (!condition) {
|
||||
@@ -20,5 +21,7 @@ function box(): string {
|
||||
assert(processOptionalInterface({ required: 4, notRequired: null }) == "4unknown")
|
||||
assert(processOptionalInterface({ required: 4, notRequired: 5 }) == "45")
|
||||
|
||||
assert(WithTheCompanion.companionFunction() == "FUNCTION")
|
||||
|
||||
return "OK";
|
||||
}
|
||||
Reference in New Issue
Block a user