Repository: scalameta/scalameta (scala)

Issue:
invalid tokens for xml quasiquotes
When using quasiquotes, In the tokens, the parts are surrounded by double quotes.

scalameta: 3.7.4

obtained:

```scala
q"<h1>a{b}</h1>".parts.map(_.tokens)
// List(  
//     Tokens(BOF [0..0), "<h1>a" [0..7), EOF [7..7)),
//                        ^-----^
//     Tokens(BOF [0..0), "</h1>" [0..7), EOF [7..7))
//                        ^-----^
// )
```

expected:

```scala
"<h1>a{b}</h1>".parse[Term].get.asInstanceOf[Term.Xml].parts.map(_.tokens)
// List(
//   Tokens(<h1>a [0..5)),  
//   Tokens(</h1> [8..13))
// )
```

Pull request description:
Fixes #1596.

Patch:
diff --git a/scalameta/trees/shared/src/main/scala/scala/meta/internal/trees/InternalTrees.scala b/scalameta/trees/shared/src/main/scala/scala/meta/internal/trees/InternalTrees.scala
index 79a81ea871..86ee7b2b8b 100644
--- a/scalameta/trees/shared/src/main/scala/scala/meta/internal/trees/InternalTrees.scala
+++ b/scalameta/trees/shared/src/main/scala/scala/meta/internal/trees/InternalTrees.scala
@@ -69,7 +69,13 @@ trait InternalTree extends Product {
         val tokens = dialect(input).tokenize.get
         tokens.slice(pos.start, pos.end)
       case _ =>
-        dialect(Input.VirtualFile("<InternalTrees.tokens>", this.syntax)).tokenize.get
+        this match {
+          case Lit.String(value) =>
+            val input = Input.VirtualFile("<InternalTrees.tokens>", value)
+            Tokens(Array(Constant.String(input, dialect, 0, value.length, value)))
+          case _ =>
+            dialect(Input.VirtualFile("<InternalTrees.tokens>", this.syntax)).tokenize.get
+        }
     }
   }
 


Test patch:
diff --git a/tests/shared/src/test/scala/scala/meta/tests/prettyprinters/SyntacticSuite.scala b/tests/shared/src/test/scala/scala/meta/tests/prettyprinters/SyntacticSuite.scala
index 3696c5efa3..2c1a44b154 100644
--- a/tests/shared/src/test/scala/scala/meta/tests/prettyprinters/SyntacticSuite.scala
+++ b/tests/shared/src/test/scala/scala/meta/tests/prettyprinters/SyntacticSuite.scala
@@ -1288,6 +1288,42 @@ class SyntacticSuite extends scala.meta.tests.parsers.ParseSuite {
     )
   }
 
+  test("#1596") {
+    val tree: Term.Xml = q"<h1>a{b}</h1>"
+    checkTree(
+      tree,
+      Term.Xml(List(Lit.String("<h1>a"), Lit.String("</h1>")), List(Term.Name("b")))
+    )
+    val dialect = implicitly[Dialect]
+    val Term.Xml(part1 :: part2 :: Nil, arg1 :: Nil) = tree
+
+    val inputPart1 = Input.VirtualFile(path = "<InternalTrees.tokens>", value = "<h1>a")
+    assertEquals(
+      part1.tokens.toList,
+      List(
+        Token.Constant.String(inputPart1, dialect, 0, 5, "<h1>a")
+      )
+    )
+
+    val inputArg1 = Input.VirtualFile(path = "<InternalTrees.tokens>", value = "b")
+    assertEquals(
+      arg1.tokens.toList,
+      List(
+        Token.BOF(inputArg1, dialect, 0),
+        Token.Ident(inputArg1, dialect, 0, 1, "b"),
+        Token.EOF(inputArg1, dialect, 1)
+      )
+    )
+
+    val inputPart2 = Input.VirtualFile(path = "<InternalTrees.tokens>", value = "</h1>")
+    assertEquals(
+      part2.tokens.toList,
+      List(
+        Token.Constant.String(inputPart2, dialect, 0, 5, "</h1>")
+      )
+    )
+  }
+
   test("#1063 original") {
     checkTree(
       q"def withJsoup(html: Html)(cleaners: HtmlCleaner*): Html = withJsoup(html.body) { cleaners: _* }",