-
Notifications
You must be signed in to change notification settings - Fork 2
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
4 changed files
with
86 additions
and
59 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
core/src/main/scala-latest-js/scalameta_ast/RemoveNewFields.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,9 @@ | ||
package scalameta_ast | ||
|
||
import scala.annotation.unused | ||
import scala.meta.Term | ||
import scala.meta.Tree | ||
|
||
object RemoveNewFields { | ||
def remove(@unused tree: Tree, @unused parsed: Term, str: String): String = str | ||
} |
67 changes: 67 additions & 0 deletions
67
core/src/main/scala-scalafix_compat-js/scalameta_ast/RemoveNewFields.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,67 @@ | ||
package scalameta_ast | ||
|
||
import scala.meta.Defn | ||
import scala.meta.Template | ||
import scala.meta.Term | ||
import scala.meta.Tree | ||
import scala.meta.contrib._ | ||
import scala.meta.tokens.Token | ||
|
||
object RemoveNewFields { | ||
def remove(tree: Tree, parsed: Term, str: String): String = { | ||
if ( | ||
tree.collectFirst { | ||
case _: Term.If => () | ||
case _: Term.Match => () | ||
case _: Defn.Type => () | ||
case _: Template => () | ||
}.nonEmpty | ||
) { | ||
val positions = parsed.collect { | ||
case x @ Term.Apply( | ||
Term.Select( | ||
Term.Name("Term"), | ||
Term.Name("If") | ||
), | ||
_ :: _ :: _ :: last :: Nil | ||
) => | ||
(x.tokens, last) | ||
case x @ Term.Apply( | ||
Term.Select( | ||
Term.Name("Term"), | ||
Term.Name("Match") | ||
), | ||
_ :: _ :: last :: Nil | ||
) => | ||
(x.tokens, last) | ||
case x @ Term.Apply( | ||
Term.Select( | ||
Term.Name("Defn"), | ||
Term.Name("Type") | ||
), | ||
_ :: _ :: _ :: _ :: last :: Nil | ||
) => | ||
(x.tokens, last) | ||
case x @ Term.Apply( | ||
Term.Name("Template"), | ||
_ :: _ :: _ :: _ :: last :: Nil | ||
) => | ||
(x.tokens, last) | ||
}.flatMap { case (tokens, toRemove) => | ||
val startOpt = | ||
tokens.reverseIterator.filter(_.is[Token.Comma]).find(_.pos.start < toRemove.pos.start).map(_.start) | ||
val endOpt = | ||
tokens.reverseIterator.find(_.is[Token.RightParen]).map(_.pos.end - 1) | ||
startOpt.zip(endOpt) | ||
} | ||
|
||
str.zipWithIndex.flatMap { case (char, pos) => | ||
Option.unless(positions.exists { case (start, end) => start <= pos && pos < end }) { | ||
char | ||
} | ||
}.mkString | ||
} else { | ||
str | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package scalameta_ast | ||
|
||
import scala.annotation.unused | ||
import scala.meta.Term | ||
import scala.meta.Tree | ||
|
||
object RemoveNewFields { | ||
def remove(@unused tree: Tree, @unused parsed: Term, str: String): String = str | ||
} |