From f0dfde28e1ac662c10efc7bab4a9ae51afde6687 Mon Sep 17 00:00:00 2001
From: "Jules Sam. Randolph" <jules.sam.randolph@gmail.com>
Date: Tue, 27 Apr 2021 09:19:25 -0300
Subject: [PATCH 1/3] fix: XML entities should be decoded in string literals

fix #516
---
 packages/hast-util-to-babel-ast/package.json      |  3 ++-
 packages/hast-util-to-babel-ast/src/handlers.js   |  3 ++-
 packages/hast-util-to-babel-ast/src/index.test.js | 14 ++++++++++++++
 yarn.lock                                         |  5 +++++
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/packages/hast-util-to-babel-ast/package.json b/packages/hast-util-to-babel-ast/package.json
index 49a193de..86e9e820 100644
--- a/packages/hast-util-to-babel-ast/package.json
+++ b/packages/hast-util-to-babel-ast/package.json
@@ -31,6 +31,7 @@
     "prepublishOnly": "yarn run build"
   },
   "dependencies": {
-    "@babel/types": "^7.15.4"
+    "@babel/types": "^7.15.4",
+    "entities": "^2.2.0"
   }
 }
diff --git a/packages/hast-util-to-babel-ast/src/handlers.js b/packages/hast-util-to-babel-ast/src/handlers.js
index 7c218e52..c0365c91 100644
--- a/packages/hast-util-to-babel-ast/src/handlers.js
+++ b/packages/hast-util-to-babel-ast/src/handlers.js
@@ -1,4 +1,5 @@
 import * as t from '@babel/types'
+import { decodeXML } from 'entities'
 import all from './all'
 import getAttributes from './getAttributes'
 import { ELEMENT_TAG_NAME_MAPPING } from './mappings'
@@ -24,7 +25,7 @@ export const text = (h, node, parent) => {
     return null
   }
 
-  return t.jsxExpressionContainer(t.stringLiteral(node.value))
+  return t.jsxExpressionContainer(t.stringLiteral(decodeXML(node.value)))
 }
 
 export const element = (h, node, parent) => {
diff --git a/packages/hast-util-to-babel-ast/src/index.test.js b/packages/hast-util-to-babel-ast/src/index.test.js
index 4a12e906..6d610177 100644
--- a/packages/hast-util-to-babel-ast/src/index.test.js
+++ b/packages/hast-util-to-babel-ast/src/index.test.js
@@ -69,4 +69,18 @@ describe('hast-util-to-babel-ast', () => {
 
     expect(transform(code)).toMatchSnapshot()
   })
+
+  it('string litterals children of text nodes should have decoded XML entities', () => {
+    const code = `<svg><text>&lt;</text></svg>`
+    expect(transform(code)).toMatchInlineSnapshot(
+      `"<svg><text>{\\"<\\"}</text></svg>;"`,
+    )
+  })
+
+  it('string litterals children of tspan nodes should have decoded XML entities', () => {
+    const code = `<svg><text><tspan>&lt;</tspan></text></svg>`
+    expect(transform(code)).toMatchInlineSnapshot(
+      `"<svg><text><tspan>{\\"<\\"}</tspan></text></svg>;"`,
+    )
+  })
 })
diff --git a/yarn.lock b/yarn.lock
index 53e548a0..b5f856c4 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4890,6 +4890,11 @@ entities@^2.0.0:
   resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55"
   integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==
 
+entities@^2.2.0:
+  version "2.2.0"
+  resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55"
+  integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==
+
 env-paths@^2.2.0:
   version "2.2.1"
   resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-2.2.1.tgz#420399d416ce1fbe9bc0a07c62fa68d67fd0f8f2"

From 758fa184d4e3bd23c2ae22b836ece7ff3ea74441 Mon Sep 17 00:00:00 2001
From: "Jules Sam. Randolph" <jules.sam.randolph@gmail.com>
Date: Mon, 28 Jun 2021 07:50:42 -0300
Subject: [PATCH 2/3] test: fix typo

Co-authored-by: Michel Jung <michel.jung89@gmail.com>
---
 packages/hast-util-to-babel-ast/src/index.test.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/hast-util-to-babel-ast/src/index.test.js b/packages/hast-util-to-babel-ast/src/index.test.js
index 6d610177..7669ddc2 100644
--- a/packages/hast-util-to-babel-ast/src/index.test.js
+++ b/packages/hast-util-to-babel-ast/src/index.test.js
@@ -70,7 +70,7 @@ describe('hast-util-to-babel-ast', () => {
     expect(transform(code)).toMatchSnapshot()
   })
 
-  it('string litterals children of text nodes should have decoded XML entities', () => {
+  it('string literals children of text nodes should have decoded XML entities', () => {
     const code = `<svg><text>&lt;</text></svg>`
     expect(transform(code)).toMatchInlineSnapshot(
       `"<svg><text>{\\"<\\"}</text></svg>;"`,

From 7b8cc96f6f218b53201a570e9e8415b138b11c2b Mon Sep 17 00:00:00 2001
From: "Jules Sam. Randolph" <jules.sam.randolph@gmail.com>
Date: Mon, 28 Jun 2021 07:50:50 -0300
Subject: [PATCH 3/3] test: fix typo

Co-authored-by: Michel Jung <michel.jung89@gmail.com>
---
 packages/hast-util-to-babel-ast/src/index.test.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/hast-util-to-babel-ast/src/index.test.js b/packages/hast-util-to-babel-ast/src/index.test.js
index 7669ddc2..53b40092 100644
--- a/packages/hast-util-to-babel-ast/src/index.test.js
+++ b/packages/hast-util-to-babel-ast/src/index.test.js
@@ -77,7 +77,7 @@ describe('hast-util-to-babel-ast', () => {
     )
   })
 
-  it('string litterals children of tspan nodes should have decoded XML entities', () => {
+  it('string literals children of tspan nodes should have decoded XML entities', () => {
     const code = `<svg><text><tspan>&lt;</tspan></text></svg>`
     expect(transform(code)).toMatchInlineSnapshot(
       `"<svg><text><tspan>{\\"<\\"}</tspan></text></svg>;"`,