From 3ff7709c041b12496ea7039f9906774bc6df5269 Mon Sep 17 00:00:00 2001 From: xuwei-k <6b656e6a69@gmail.com> Date: Sat, 28 Sep 2024 14:01:52 +0900 Subject: [PATCH] scalameta 4.10.1 --- build.sbt | 5 +-- .../scala/scalameta_ast/AfterExtractor.scala | 13 +++++-- .../scala/scalameta_ast/ScalametaAST.scala | 8 +++-- .../scalameta_ast/ScalametaASTSpec2.scala | 35 +++++++++++++++++-- .../scalameta_ast/ScalametaASTSpec2.scala | 29 +++++++++++++++ .../scalameta_ast/ScalametaASTSpec.scala | 31 ---------------- .../scalameta_ast/AfterExtractorsSpec.scala | 4 ++- .../scala/scalameta_ast/IntegrationTest.scala | 15 ++++---- .../test/scala/scalameta_ast/ScalametaV.scala | 2 +- sources/main.js | 4 +-- 10 files changed, 94 insertions(+), 52 deletions(-) diff --git a/build.sbt b/build.sbt index 45099cd..6110cb8 100644 --- a/build.sbt +++ b/build.sbt @@ -39,7 +39,8 @@ lazy val `scalameta-ast` = projectMatrix settings = Def.settings( metaVersion := (LocalProject("scalameta-ast-latestJS") / metaVersion).value, testBuildInfo, - libraryDependencies += "org.scalameta" %%% "scalafmt-core" % "3.7.14", + libraryDependencies += "org.scalameta" %%% "scalameta" % "4.10.1", + libraryDependencies += "org.scalameta" %%% "scalafmt-core" % "3.8.3", libraryDependencies += "com.google.inject" % "guice" % "7.0.0" % Test, Test / resourceGenerators += Def.task { val v1 = (LocalProject("scalameta-ast-latestJS") / metaTreesSource).value @@ -68,7 +69,7 @@ lazy val `scalameta-ast` = projectMatrix settings = Def.settings( jsProjectSettings, libraryDependencies += "org.ekrich" %%% "sconfig" % "1.7.0", - libraryDependencies += ("com.github.xuwei-k" %%% "scalafmt-core" % "3.7.14-fork-1").withSources(), + libraryDependencies += ("com.github.xuwei-k" %%% "scalafmt-core" % "3.8.3-fork-1").withSources(), ) ) diff --git a/core/src/main/scala/scalameta_ast/AfterExtractor.scala b/core/src/main/scala/scalameta_ast/AfterExtractor.scala index ad62ac6..1db0334 100644 --- a/core/src/main/scala/scalameta_ast/AfterExtractor.scala +++ b/core/src/main/scala/scalameta_ast/AfterExtractor.scala @@ -18,7 +18,7 @@ object AfterExtractor extends AfterExtractorEnable { val values: List[AfterExtractor] = List( E2("Ctor", "Primary", "After_4_6_0"), - E2("Ctor", "Secondary", "After_4_6_0"), + E2("Ctor", "Secondary", "After_4_9_9"), E2("Decl", "Def", "After_4_7_3"), E2("Decl", "Given", "After_4_6_0"), E2("Decl", "Type", "After_4_6_0"), @@ -36,23 +36,30 @@ object AfterExtractor extends AfterExtractorEnable { E1("Init", "After_4_6_0"), E2("Pat", "Extract", "After_4_6_0"), E2("Pat", "ExtractInfix", "After_4_6_0"), - E1("Template", "After_4_4_0"), + E1("Pkg", "After_4_9_9"), + E1("Template", "After_4_9_9"), E2("Term", "Apply", "After_4_6_0"), E2("Term", "ApplyInfix", "After_4_6_0"), E2("Term", "ApplyType", "After_4_6_0"), E2("Term", "ApplyUsing", "After_4_6_0"), E2("Term", "ContextFunction", "After_4_6_0"), + E2("Term", "For", "After_4_9_9"), + E2("Term", "ForYield", "After_4_9_9"), E2("Term", "Function", "After_4_6_0"), E2("Term", "If", "After_4_4_0"), - E2("Term", "Match", "After_4_4_5"), + E2("Term", "Match", "After_4_9_9"), E2("Term", "PolyFunction", "After_4_6_0"), + E2("Term", "Try", "After_4_9_9"), E2("Type", "Apply", "After_4_6_0"), E2("Type", "ContextFunction", "After_4_6_0"), + E2("Type", "Existential", "After_4_9_9"), E2("Type", "Function", "After_4_6_0"), E2("Type", "Lambda", "After_4_6_0"), + E2("Type", "Match", "After_4_9_9"), E2("Type", "Method", "After_4_6_0"), E2("Type", "Param", "After_4_6_0"), E2("Type", "PolyFunction", "After_4_6_0"), + E2("Type", "Refine", "After_4_9_9"), E2("Type", "TypedParam", "After_4_7_8"), ) } diff --git a/core/src/main/scala/scalameta_ast/ScalametaAST.scala b/core/src/main/scala/scalameta_ast/ScalametaAST.scala index c25d10a..b4390e8 100644 --- a/core/src/main/scala/scalameta_ast/ScalametaAST.scala +++ b/core/src/main/scala/scalameta_ast/ScalametaAST.scala @@ -161,8 +161,12 @@ class ScalametaAST { t.pos -> e } case t @ Term.Name(x1) => - AfterExtractor.values.collect { case AfterExtractor.E1(`x1`, e) => - t.pos -> e + if (Set("Template", "Pkg").apply(x1) && str.splitAt(t.pos.end)._2.startsWith(".Body")) { + Nil + } else { + AfterExtractor.values.collect { case AfterExtractor.E1(`x1`, e) => + t.pos -> e + } } }.flatten.sortBy(_._1.start) diff --git a/core/src/test/scala-latest-js/scalameta_ast/ScalametaASTSpec2.scala b/core/src/test/scala-latest-js/scalameta_ast/ScalametaASTSpec2.scala index 9aafb9d..06ca0ee 100644 --- a/core/src/test/scala-latest-js/scalameta_ast/ScalametaASTSpec2.scala +++ b/core/src/test/scala-latest-js/scalameta_ast/ScalametaASTSpec2.scala @@ -1,6 +1,11 @@ package scalameta_ast import org.scalatest.freespec.AnyFreeSpec +import scala.meta.inputs.Input +import scala.meta.Defn +import scala.meta.Pkg +import scala.meta.Tree +import scala.meta.dialects class ScalametaASTSpec2 extends AnyFreeSpec { "ScalametaAST" - { @@ -27,7 +32,7 @@ class ScalametaASTSpec2 extends AnyFreeSpec { "Term.Match" in { val expect = - """Term.Match.After_4_4_5(Term.Name("a"), List(Case(Pat.Var(Term.Name("b")), None, Term.Block(Nil))), List(Mod.Inline()))""" + """Term.Match.After_4_9_9(Term.Name("a"), Term.CasesBlock(List(Case(Pat.Var(Term.Name("b")), None, Term.Block(Nil)))), List(Mod.Inline()))""" val result = main.convert( src = """inline a match { case b => }""", outputType = "", @@ -80,8 +85,34 @@ class ScalametaASTSpec2 extends AnyFreeSpec { ) val expect = - """Defn.Class.After_4_6_0(Nil, Type.Name("A"), Type.ParamClause(Nil), Ctor.Primary.After_4_6_0(Nil, Name.Anonymous(), Nil), Template.After_4_4_0(Nil, Nil, Self(Name.Anonymous(), None), Nil, List(Type.Name("B"))))""" + """Defn.Class.After_4_6_0(Nil, Type.Name("A"), Type.ParamClause(Nil), Ctor.Primary.After_4_6_0(Nil, Name.Anonymous(), Nil), Template.After_4_9_9(None, Nil, Template.Body(None, Nil), List(Type.Name("B"))))""" + assert(result.result == expect) } + + "top level scalameta classes" in { + val src = TestCompat.scalametaTreeFile(0) + val parsed = + implicitly[scala.meta.parsers.Parse[scala.meta.Source]].apply(Input.String(src), dialects.Scala213Source3).get + + def topLevel(t: Tree): Boolean = + t.parent.exists { + case _: Pkg.Body => + true + case _ => + false + } + + val values = parsed.collect { + case c: Defn.Class if topLevel(c) => + c.name.value + case c: Defn.Trait if topLevel(c) => + c.name.value + case c: Defn.Object if topLevel(c) => + c.name.value + }.toSet -- Set("All", "Quasi") + val expect = main.topLevelScalametaDefinitions.map(_.getSimpleName).toSet + assert(values == expect) + } } } diff --git a/core/src/test/scala-scalafix_compat-js/scalameta_ast/ScalametaASTSpec2.scala b/core/src/test/scala-scalafix_compat-js/scalameta_ast/ScalametaASTSpec2.scala index d581d25..4798571 100644 --- a/core/src/test/scala-scalafix_compat-js/scalameta_ast/ScalametaASTSpec2.scala +++ b/core/src/test/scala-scalafix_compat-js/scalameta_ast/ScalametaASTSpec2.scala @@ -1,6 +1,11 @@ package scalameta_ast import org.scalatest.freespec.AnyFreeSpec +import scala.meta.inputs.Input +import scala.meta.Defn +import scala.meta.Pkg +import scala.meta.Tree +import scala.meta.dialects class ScalametaASTSpec2 extends AnyFreeSpec { private case class TestArg(initial: Boolean, remove: Boolean) @@ -135,5 +140,29 @@ class ScalametaASTSpec2 extends AnyFreeSpec { } } + "top level scalameta classes" in { + val src = TestCompat.scalametaTreeFile(1) + val parsed = + implicitly[scala.meta.parsers.Parse[scala.meta.Source]].apply(Input.String(src), dialects.Scala213Source3).get + + def topLevel(t: Tree): Boolean = + t.parent.exists { + case _: Pkg => + true + case _ => + false + } + + val values = parsed.collect { + case c: Defn.Class if topLevel(c) => + c.name.value + case c: Defn.Trait if topLevel(c) => + c.name.value + case c: Defn.Object if topLevel(c) => + c.name.value + }.toSet -- Set("All", "Quasi") + val expect = main.topLevelScalametaDefinitions.map(_.getSimpleName).toSet + assert(values == expect) + } } } diff --git a/core/src/test/scala/scalameta_ast/ScalametaASTSpec.scala b/core/src/test/scala/scalameta_ast/ScalametaASTSpec.scala index c716a7b..b1279be 100644 --- a/core/src/test/scala/scalameta_ast/ScalametaASTSpec.scala +++ b/core/src/test/scala/scalameta_ast/ScalametaASTSpec.scala @@ -1,11 +1,6 @@ package scalameta_ast import org.scalatest.freespec.AnyFreeSpec -import scala.meta.Defn -import scala.meta.Tree -import scala.meta.Pkg -import scala.meta.dialects -import scala.meta.inputs.Input class ScalametaASTSpec extends AnyFreeSpec { "ScalametaAST" - { @@ -149,31 +144,5 @@ class ScalametaASTSpec extends AnyFreeSpec { assert(result.result == expect) } - (0 to 1).foreach { i => - s"top level scalameta classes ${i}" in { - val src = TestCompat.scalametaTreeFile(i) - val parsed = - implicitly[scala.meta.parsers.Parse[scala.meta.Source]].apply(Input.String(src), dialects.Scala213Source3).get - - def topLevel(t: Tree): Boolean = - t.parent.exists { - case p: Pkg => - p.name.value == "meta" - case _ => - false - } - - val values = parsed.collect { - case c: Defn.Class if topLevel(c) => - c.name.value - case c: Defn.Trait if topLevel(c) => - c.name.value - case c: Defn.Object if topLevel(c) => - c.name.value - }.toSet - val expect = main.topLevelScalametaDefinitions.map(_.getSimpleName).toSet - assert(values == expect) - } - } } } diff --git a/core/src/test/scalajvm/scalameta_ast/AfterExtractorsSpec.scala b/core/src/test/scalajvm/scalameta_ast/AfterExtractorsSpec.scala index ba1d765..1cd948c 100644 --- a/core/src/test/scalajvm/scalameta_ast/AfterExtractorsSpec.scala +++ b/core/src/test/scalajvm/scalameta_ast/AfterExtractorsSpec.scala @@ -24,7 +24,9 @@ class AfterExtractorsSpec extends AnyFreeSpec { assert(v.size == 1, k) } val values = findAllClasses { info => - info.getName.contains("After_") && info.getPackageName.contains("scala.meta") + info.getName.contains("After_") && info.getPackageName.contains("scala.meta") && !info.getName.contains( + "LowPriority" + ) } val expect = values .map(c => diff --git a/localServer/src/test/scala/scalameta_ast/IntegrationTest.scala b/localServer/src/test/scala/scalameta_ast/IntegrationTest.scala index 2921094..55ab72c 100644 --- a/localServer/src/test/scala/scalameta_ast/IntegrationTest.scala +++ b/localServer/src/test/scala/scalameta_ast/IntegrationTest.scala @@ -194,7 +194,7 @@ abstract class IntegrationTest( v match { case ScalametaV.V_0_10 => "scalafix" - case ScalametaV.V_0_11 => + case ScalametaV.V_0_13 => "latest" } ) @@ -212,11 +212,10 @@ abstract class IntegrationTest( """ Type.ParamClause(Nil),""", """ Ctor.Primary""", """ .After_4_6_0(Nil, Name.Anonymous(), Nil),""", - """ Template.After_4_4_0(""", - """ Nil,""", - """ Nil,""", - """ Self(Name.Anonymous(), None),""", + """ Template.After_4_9_9(""", + """ None,""", """ Nil,""", + """ Template.Body(None, Nil),""", """ Nil""", """ )""", """)""", @@ -378,7 +377,7 @@ abstract class IntegrationTest( "scalameta version" in withBrowser { page => changeOutputType(page, "raw") - changeScalametaVersion(page, ScalametaV.V_0_11) + changeScalametaVersion(page, ScalametaV.V_0_13) assert(output(page).textContent().contains("Defn.Def.After_4_7_3(")) changeScalametaVersion(page, ScalametaV.V_0_10) @@ -493,7 +492,7 @@ abstract class IntegrationTest( initialExtractor(page).check() assert(outSingleLine() == """Term.If.Initial(Term.Name("a"), Lit.Int(2), Lit.Int(3))""") - changeScalametaVersion(page, ScalametaV.V_0_11) + changeScalametaVersion(page, ScalametaV.V_0_13) assert(!removeNewFields(page).isEnabled()) assert(!initialExtractor(page).isEnabled()) } @@ -596,7 +595,7 @@ abstract class IntegrationTest( "invalid input" in withBrowser { page => setInput(page, "def") assert(infoElem(page).getAttribute("class") == "alert alert-danger") - assert(infoElem(page).textContent() contains "error: identifier expected but end of file found") + assert(infoElem(page).textContent() contains "error: `identifier` expected but `end of file` found") } "copy button" in withBrowser { page => diff --git a/localServer/src/test/scala/scalameta_ast/ScalametaV.scala b/localServer/src/test/scala/scalameta_ast/ScalametaV.scala index 75cb3d9..d870e94 100644 --- a/localServer/src/test/scala/scalameta_ast/ScalametaV.scala +++ b/localServer/src/test/scala/scalameta_ast/ScalametaV.scala @@ -4,5 +4,5 @@ sealed abstract class ScalametaV extends Product with Serializable object ScalametaV { case object V_0_10 extends ScalametaV - case object V_0_11 extends ScalametaV + case object V_0_13 extends ScalametaV } diff --git a/sources/main.js b/sources/main.js index c6dae57..71a82fa 100644 --- a/sources/main.js +++ b/sources/main.js @@ -239,7 +239,7 @@ const App = () => { result = hljs.highlight(r.ast, { language: "scala", }).value; - const scalafixVersion = scalameta == "latest" ? "0.11.1" : "0.10.4"; + const scalafixVersion = scalameta == "latest" ? "0.13.0" : "0.10.4"; const scalafixUrl = (s) => `https://github.com/scalacenter/scalafix/blob/v${scalafixVersion}/scalafix-core/src/main/scala/scalafix/${s}.scala`; @@ -518,7 +518,7 @@ const App = () => { scalafix 0.10.x compatible ${scalametaV1}