Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize type references to classes to point to the parent class as…
… long as name and type parameters are the same.
- Loading branch information
1 parent
69157a7
commit 759d141
Showing
16 changed files
with
58 additions
and
25 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
...in/scala/org/scalablytyped/converter/internal/scalajs/transforms/GeneralizeTypeRefs.scala
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,32 @@ | ||
package org.scalablytyped.converter.internal | ||
package scalajs | ||
package transforms | ||
|
||
object GeneralizeTypeRefs extends TreeTransformation { | ||
override def leaveTypeRef(scope: TreeScope)(tr: TypeRef): TypeRef = | ||
generalize(scope)(tr) | ||
|
||
def generalize(scope: TreeScope)(tr: TypeRef): TypeRef = | ||
if (scope.isAbstract(tr)) tr | ||
else | ||
FollowAliases(scope)(tr) match { | ||
case dealiasedTr if dealiasedTr.name === tr.name => | ||
scope | ||
._lookup(dealiasedTr.typeName.parts) | ||
.collectFirst { | ||
case (cls: ClassTree, newScope) if cls.tparams.length === tr.targs.length => | ||
val newCls = FillInTParams(cls, newScope, dealiasedTr.targs, Empty) | ||
newCls.parents match { | ||
case IArray.exactlyOne(p) if p.name === tr.name => | ||
// commit at this point | ||
generalize(newScope)(p) | ||
case _ => | ||
tr | ||
} | ||
case _ => tr | ||
} | ||
.getOrElse(tr) | ||
|
||
case _ => tr | ||
} | ||
} |
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
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
2 changes: 1 addition & 1 deletion
2
tests/sax/check/n/node/src/main/scala/typings/node/streamMod/internal.scala
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
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