-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
174 additions
and
19 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
compiler/test/data/typescript/stdlib/arrayWithoutParam.d.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// [test] arrayWithoutParam.kt | ||
@file:Suppress("INTERFACE_WITH_SUPERCLASS", "OVERRIDING_FINAL_MEMBER", "RETURN_TYPE_MISMATCH_ON_OVERRIDE", "CONFLICTING_OVERLOADS") | ||
|
||
import kotlin.js.* | ||
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.* | ||
|
||
typealias Table = Array<Any> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
declare class Table extends Array { | ||
constructor(); | ||
toString(): string; | ||
static version: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
typescript/ts-lowerings/src/org/jetbrains/dukat/tsLowerings/ProcessConstructorInterfaces.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.jetbrains.dukat.tsLowerings | ||
|
||
import org.jetbrains.dukat.astCommon.IdentifierEntity | ||
import org.jetbrains.dukat.ownerContext.NodeOwner | ||
import org.jetbrains.dukat.tsmodel.ClassLikeDeclaration | ||
import org.jetbrains.dukat.tsmodel.ConstructSignatureDeclaration | ||
import org.jetbrains.dukat.tsmodel.HeritageClauseDeclaration | ||
import org.jetbrains.dukat.tsmodel.InterfaceDeclaration | ||
import org.jetbrains.dukat.tsmodel.ModuleDeclaration | ||
import org.jetbrains.dukat.tsmodel.ParameterOwnerDeclaration | ||
import org.jetbrains.dukat.tsmodel.SourceSetDeclaration | ||
import org.jetbrains.dukat.tsmodel.VariableDeclaration | ||
import org.jetbrains.dukat.tsmodel.types.ParameterValueDeclaration | ||
import org.jetbrains.dukat.tsmodel.types.TypeDeclaration | ||
|
||
private class ReplaceTypesLowering(private val typesToReplace: Map<String, ParameterValueDeclaration>, private val depth: Int) : DeclarationLowering { | ||
private val newTypesToReplace = mutableMapOf<String, ParameterValueDeclaration>() | ||
|
||
private fun findNewType(type: ParameterValueDeclaration): ParameterValueDeclaration? { | ||
if (type is TypeDeclaration && type.typeReference != null) { | ||
val uid = type.typeReference!!.uid | ||
if (typesToReplace.containsKey(uid)) { | ||
return typesToReplace.getValue(uid) | ||
} | ||
} | ||
return null | ||
} | ||
|
||
override fun lowerParameterValue( | ||
declaration: ParameterValueDeclaration, | ||
owner: NodeOwner<ParameterOwnerDeclaration>? | ||
): ParameterValueDeclaration { | ||
return findNewType(declaration) ?: declaration | ||
} | ||
|
||
override fun lowerHeritageClause( | ||
heritageClause: HeritageClauseDeclaration, | ||
owner: NodeOwner<ClassLikeDeclaration>? | ||
): HeritageClauseDeclaration { | ||
val reference = heritageClause.typeReference | ||
if (reference != null && typesToReplace.containsKey(reference.uid)) { | ||
val newType = typesToReplace.getValue(reference.uid) | ||
if (newType is TypeDeclaration) { | ||
return heritageClause.copy(name = newType.value, typeArguments = newType.params, typeReference = newType.typeReference) | ||
} | ||
} | ||
return heritageClause | ||
} | ||
|
||
override fun lowerVariableDeclaration(declaration: VariableDeclaration, owner: NodeOwner<ModuleDeclaration>?): VariableDeclaration { | ||
val newType = findNewType(declaration.type) | ||
if (newType != null) { | ||
newTypesToReplace[declaration.uid] = newType | ||
return declaration.copy(type = newType) | ||
} | ||
return declaration | ||
} | ||
|
||
override fun lower(source: SourceSetDeclaration): SourceSetDeclaration { | ||
val newSource = super.lower(source) | ||
return if (depth == 0) { | ||
ReplaceTypesLowering(newTypesToReplace, depth + 1).lower(newSource) | ||
} else { | ||
newSource | ||
} | ||
} | ||
} | ||
|
||
private class ProcessConstructorInterfacesLowering : DeclarationLowering { | ||
|
||
private val typesToReplace = mutableMapOf<String, ParameterValueDeclaration>() | ||
|
||
private fun determineCommonReturnType(constructors: List<ConstructSignatureDeclaration>): ParameterValueDeclaration? { | ||
return constructors[0].type | ||
} | ||
|
||
override fun lowerInterfaceDeclaration( | ||
declaration: InterfaceDeclaration, | ||
owner: NodeOwner<ModuleDeclaration>? | ||
): InterfaceDeclaration { | ||
val constructSignatures = declaration.members.filterIsInstance<ConstructSignatureDeclaration>() | ||
if (constructSignatures.isEmpty()) { | ||
return declaration | ||
} | ||
val commonReturnType = determineCommonReturnType(constructSignatures) | ||
if (commonReturnType is TypeDeclaration && commonReturnType.value == IdentifierEntity("Array")) { | ||
typesToReplace[declaration.uid] = commonReturnType | ||
} | ||
return declaration | ||
} | ||
|
||
override fun lower(source: SourceSetDeclaration): SourceSetDeclaration { | ||
val newSource = super.lower(source) | ||
return ReplaceTypesLowering(typesToReplace, 0).lower(newSource) | ||
} | ||
} | ||
|
||
class ProcessConstructorInterfaces : TsLowering { | ||
override fun lower(source: SourceSetDeclaration): SourceSetDeclaration { | ||
return ProcessConstructorInterfacesLowering().lower(source) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters