Skip to content

Commit

Permalink
scalameta 4.10.1
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Sep 28, 2024
1 parent 67f3481 commit 3ff7709
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 52 deletions.
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
)
)

Expand Down
13 changes: 10 additions & 3 deletions core/src/main/scala/scalameta_ast/AfterExtractor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
)
}
8 changes: 6 additions & 2 deletions core/src/main/scala/scalameta_ast/ScalametaAST.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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" - {
Expand All @@ -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 = "",
Expand Down Expand Up @@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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)
}
}
}
31 changes: 0 additions & 31 deletions core/src/test/scala/scalameta_ast/ScalametaASTSpec.scala
Original file line number Diff line number Diff line change
@@ -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" - {
Expand Down Expand Up @@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down
15 changes: 7 additions & 8 deletions localServer/src/test/scala/scalameta_ast/IntegrationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
)
Expand All @@ -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""",
""" )""",
""")""",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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 =>
Expand Down
2 changes: 1 addition & 1 deletion localServer/src/test/scala/scalameta_ast/ScalametaV.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions sources/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;

Expand Down Expand Up @@ -518,7 +518,7 @@ const App = () => {
scalafix 0.10.x compatible ${scalametaV1}
</option>
<option value="latest">
scalafix 0.11.x compatible ${scalametaV2}
scalafix 0.13.x compatible ${scalametaV2}
</option>
</select>
</div>
Expand Down

0 comments on commit 3ff7709

Please sign in to comment.