[K/JS] Add @deprecated commentary if @Deprecated annotation exists on a declaration.
^KT-56405 Fixed
This commit is contained in:
@@ -10,7 +10,13 @@ import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.serialization.js.ModuleKind
|
||||
|
||||
sealed class ExportedDeclaration
|
||||
sealed class ExportedDeclaration {
|
||||
val attributes = mutableListOf<ExportedAttribute>()
|
||||
}
|
||||
|
||||
sealed class ExportedAttribute {
|
||||
class DeprecatedAttribute(val message: String): ExportedAttribute()
|
||||
}
|
||||
|
||||
data class ExportedModule(
|
||||
val name: String,
|
||||
|
||||
+12
-5
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.ir.backend.js.export
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ir.isExpect
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.config.CommonConfigurationKeys
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
|
||||
@@ -61,7 +62,7 @@ class ExportModelGenerator(val context: JsIrBackendContext, val generateNamespac
|
||||
is IrClass -> exportClass(candidate)
|
||||
is IrField -> null
|
||||
else -> error("Can't export declaration $candidate")
|
||||
}
|
||||
}?.withAttributesFor(candidate)
|
||||
}
|
||||
|
||||
private fun exportClass(candidate: IrClass): ExportedDeclaration? {
|
||||
@@ -315,16 +316,16 @@ class ExportModelGenerator(val context: JsIrBackendContext, val generateNamespac
|
||||
|
||||
when (candidate) {
|
||||
is IrSimpleFunction ->
|
||||
members.addIfNotNull(exportFunction(candidate))
|
||||
members.addIfNotNull(exportFunction(candidate)?.withAttributesFor(candidate))
|
||||
|
||||
is IrConstructor ->
|
||||
members.addIfNotNull(exportConstructor(candidate))
|
||||
members.addIfNotNull(exportConstructor(candidate)?.withAttributesFor(candidate))
|
||||
|
||||
is IrProperty ->
|
||||
members.addIfNotNull(exportProperty(candidate))
|
||||
members.addIfNotNull(exportProperty(candidate)?.withAttributesFor(candidate))
|
||||
|
||||
is IrClass -> {
|
||||
val ec = exportClass(candidate)
|
||||
val ec = exportClass(candidate)?.withAttributesFor(candidate)
|
||||
if (ec is ExportedClass) {
|
||||
nestedClasses.add(ec)
|
||||
} else {
|
||||
@@ -549,6 +550,12 @@ class ExportModelGenerator(val context: JsIrBackendContext, val generateNamespac
|
||||
)
|
||||
}
|
||||
|
||||
private fun ExportedDeclaration.withAttributesFor(declaration: IrDeclaration): ExportedDeclaration {
|
||||
declaration.getDeprecated()?.let { attributes.add(ExportedAttribute.DeprecatedAttribute(it)) }
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
private fun exportType(type: IrType, shouldCalculateExportedSupertypeForImplicit: Boolean = true): ExportedType {
|
||||
if (type is IrDynamicType)
|
||||
return ExportedType.Primitive.Any
|
||||
|
||||
+16
-1
@@ -96,7 +96,7 @@ class ExportModelToTsDeclarations {
|
||||
joinToString("") { it.toTypeScript(indent) + "\n" }
|
||||
|
||||
private fun ExportedDeclaration.toTypeScript(indent: String, prefix: String = "", esModules: Boolean = false): String =
|
||||
indent + when (this) {
|
||||
attributes.toTypeScript(indent) + indent + when (this) {
|
||||
is ErrorDeclaration -> generateTypeScriptString()
|
||||
is ExportedConstructor -> generateTypeScriptString(indent)
|
||||
is ExportedConstructSignature -> generateTypeScriptString(indent)
|
||||
@@ -107,6 +107,17 @@ class ExportModelToTsDeclarations {
|
||||
is ExportedObject -> generateTypeScriptString(indent, prefix, esModules)
|
||||
}
|
||||
|
||||
private fun Iterable<ExportedAttribute>.toTypeScript(indent: String): String {
|
||||
return joinToString("\n") { it.toTypeScript(indent) }
|
||||
.run { if (isNotEmpty()) plus("\n") else this }
|
||||
}
|
||||
|
||||
private fun ExportedAttribute.toTypeScript(indent: String): String {
|
||||
return when (this) {
|
||||
is ExportedAttribute.DeprecatedAttribute -> indent + tsDeprecated(message)
|
||||
}
|
||||
}
|
||||
|
||||
private fun ErrorDeclaration.generateTypeScriptString(): String {
|
||||
return "/* ErrorDeclaration: $message */"
|
||||
}
|
||||
@@ -479,4 +490,8 @@ class ExportModelToTsDeclarations {
|
||||
private fun tsIgnore(reason: String): String {
|
||||
return "/* @ts-ignore: $reason */"
|
||||
}
|
||||
|
||||
private fun tsDeprecated(message: String): String {
|
||||
return "/** @deprecated $message */"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.backend.js.utils
|
||||
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationWithName
|
||||
@@ -48,6 +49,9 @@ fun IrAnnotationContainer.getJsQualifier(): String? =
|
||||
fun IrAnnotationContainer.getJsName(): String? =
|
||||
getAnnotation(JsAnnotations.jsNameFqn)?.getSingleConstStringArgument()
|
||||
|
||||
fun IrAnnotationContainer.getDeprecated(): String? =
|
||||
getAnnotation(StandardNames.FqNames.deprecated)?.getSingleConstStringArgument()
|
||||
|
||||
fun IrAnnotationContainer.hasJsPolyfill(): Boolean =
|
||||
hasAnnotation(JsAnnotations.JsPolyfillFqn)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user