Skip to content

Commit

Permalink
Use KLIBROOT prefix in fqName for any entities we resolve as "ours"
Browse files Browse the repository at this point in the history
this fixes #306
  • Loading branch information
Schahen committed Jun 10, 2020
1 parent abcc083 commit 482060f
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ external interface RS {

external open class R : RS {
open fun unshift(chunk: Any, encoding: String /* "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" */ = definedExternally)
override fun unshift(chunk: String, encoding: String /* "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" */)
override fun shouldNotBeCopied(a: String): Array<String>
override fun shouldNotBeCopied(a: Array<String>): Array<String>
override fun unshift(chunk: String, encoding: String /* "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" */)
override fun unshift(chunk: Uint8Array, encoding: String /* "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" */)
override fun unshift(chunk: Array<Number>, encoding: String /* "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" */)
}
Expand Down
23 changes: 23 additions & 0 deletions compiler/test/data/typescript/unionType/literalWithBasicType.d.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS", "EXTERNAL_DELEGATION")

import kotlin.js.*
import kotlin.js.Json
import org.khronos.webgl.*
import org.w3c.dom.*
import org.w3c.dom.events.*
import org.w3c.dom.parsing.*
import org.w3c.dom.svg.*
import org.w3c.dom.url.*
import org.w3c.fetch.*
import org.w3c.files.*
import org.w3c.notifications.*
import org.w3c.performance.*
import org.w3c.workers.*
import org.w3c.xhr.*

external interface Locale {
fun ping(key: String /* 'sameDay' | 'nextDay' | 'lastDay' | 'nextWeek' | 'lastWeek' | 'sameElse' */ = definedExternally): String
fun pong(key: Number /* 1 | 2 | 3 */ = definedExternally): String
fun ping(): String
fun pong(): String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type AlphaKey = 'sameDay' | 'nextDay' | 'lastDay' | 'nextWeek' | 'lastWeek' | 'sameElse' | string;
type NumKey = 1 | 2 | 3 | number;

interface Locale {
ping(key?: AlphaKey): string;
pong(key?: NumKey): string;
}


Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ open class CoreSetCliTests {
@MethodSource("coreSet")
open fun withValueSource(name: String, tsPath: String, ktPath: String, tsConfig: String) {
assertContentEqualsBinary(name, tsPath, ktPath, if (tsConfig.isEmpty()) null else tsConfig)
assertContentEqualsBinary(name, tsPath, ktPath, if (tsConfig.isEmpty()) null else tsConfig)
}

open fun getTranslator(): CliTranslator = createStandardCliTranslator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package org.jetbrains.dukat.model.commonLowerings
import org.jetbrains.dukat.astCommon.IdentifierEntity
import org.jetbrains.dukat.astCommon.NameEntity
import org.jetbrains.dukat.astCommon.QualifierEntity
import org.jetbrains.dukat.astCommon.appendLeft
import org.jetbrains.dukat.astModel.CallableModel
import org.jetbrains.dukat.astModel.CallableParameterModel
import org.jetbrains.dukat.astModel.ClassLikeModel
Expand All @@ -16,13 +15,12 @@ import org.jetbrains.dukat.astModel.MethodModel
import org.jetbrains.dukat.astModel.ModuleModel
import org.jetbrains.dukat.astModel.PropertyModel
import org.jetbrains.dukat.astModel.SourceSetModel
import org.jetbrains.dukat.astModel.TopLevelModel
import org.jetbrains.dukat.astModel.TypeModel
import org.jetbrains.dukat.astModel.TypeParameterModel
import org.jetbrains.dukat.astModel.TypeParameterReferenceModel
import org.jetbrains.dukat.astModel.TypeValueModel
import org.jetbrains.dukat.astModel.modifiers.InheritanceModifierModel
import org.jetbrains.dukat.stdlib.TSLIBROOT
import org.jetbrains.dukat.stdlib.KLIBROOT

private fun TypeModel.isAny(): Boolean {
return this is TypeValueModel && value == IdentifierEntity("Any")
Expand Down Expand Up @@ -242,7 +240,7 @@ private class ClassLikeOverrideResolver(private val context: ModelContext, priva

private fun NameEntity.withLibPrefix(): NameEntity {
return when (this) {
is IdentifierEntity -> QualifierEntity(TSLIBROOT, this)
is IdentifierEntity -> QualifierEntity(KLIBROOT, this)
is QualifierEntity -> this
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@ private class NameVisitor(private val name: NameEntity, private val importContex
}

override fun lowerIdentifierExpressionModel(ownerContext: NodeOwner<IdentifierExpressionModel>): IdentifierExpressionModel {

// TODO: enable it when we figure out correct approach to star imports

/*val node = ownerContext.node
return getNewName(node.identifier)?.let { node.copy(identifier = it) } ?: node*/

return ownerContext.node
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,6 @@ val KotlinBuiltInEntities = setOf(

fun isStdLibEntity(fqName: NameEntity): Boolean {
val leftMost = fqName.leftMost()
val isLib = leftMost == IdentifierEntity("<ROOT>") || fqName.isTsStdlibPrefixed()
val isLib = leftMost == IdentifierEntity("<ROOT>") || fqName.isTsStdlibPrefixed() || fqName.isKotlinStdlibPrefixed()
return isLib && KotlinStdlibEntities.contains(fqName.rightMost())
}
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ private class LowerDeclarationsToNodes(
),
MethodNode(
"set",
convertParameters(declaration.indexTypes.toMutableList() + listOf(ParameterDeclaration("value", declaration.returnType.convertToNodeNullable() ?: declaration.returnType, null, false, false))),
convertParameters(declaration.indexTypes + listOf(ParameterDeclaration("value", declaration.returnType.convertToNodeNullable() ?: declaration.returnType, null, false, false))),
TypeValueNode(IdentifierEntity("Unit"), emptyList()),
emptyList(),
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import org.jetbrains.dukat.astModel.statements.ReturnStatementModel
import org.jetbrains.dukat.astModel.statements.StatementModel
import org.jetbrains.dukat.logger.Logging
import org.jetbrains.dukat.panic.raiseConcern
import org.jetbrains.dukat.stdlib.KLIBROOT
import org.jetbrains.dukat.stdlib.KotlinStdlibEntities
import org.jetbrains.dukat.stdlib.TSLIBROOT
import org.jetbrains.dukat.translatorString.translate
Expand Down Expand Up @@ -166,7 +167,7 @@ internal class DocumentConverter(private val moduleNode: ModuleNode, private val

private fun TypeValueNode.getFqName(): NameEntity? {
return typeReference?.getFqName() ?: if (KotlinStdlibEntities.contains(value)) {
TSLIBROOT.appendLeft(value)
KLIBROOT.appendLeft(value)
} else null
}

Expand Down Expand Up @@ -216,16 +217,19 @@ internal class DocumentConverter(private val moduleNode: ModuleNode, private val
fun TypeNode.process(context: TranslationContext = TranslationContext.IRRELEVANT): TypeModel {
val dynamicName = IdentifierEntity("dynamic")
return when (this) {
is LiteralUnionNode -> TypeValueModel(
when (kind) {
UnionLiteralKind.NUMBER -> IdentifierEntity("Number")
else -> IdentifierEntity("String")
},
emptyList(),
params.joinToString(" | "),
null,
context == TranslationContext.PROPERTY(true)
)
is LiteralUnionNode -> {
val value = when (kind) {
UnionLiteralKind.NUMBER -> IdentifierEntity("Number")
else -> IdentifierEntity("String")
}
TypeValueModel(
value,
emptyList(),
params.joinToString(" | "),
KLIBROOT.appendLeft(value),
context == TranslationContext.PROPERTY(true)
)
}
is UnionTypeNode -> TypeValueModel(
dynamicName,
emptyList(),
Expand Down Expand Up @@ -684,7 +688,6 @@ internal class DocumentConverter(private val moduleNode: ModuleNode, private val
}

private fun MethodNode.process(override: NameEntity? = null): MethodModel {
// TODO: how ClassModel end up here?
return MethodModel(
name = IdentifierEntity(name),
parameters = parameters.map { param -> param.process() },
Expand Down

0 comments on commit 482060f

Please sign in to comment.