Skip to content

Commit eb7eb95

Browse files
authored
fix: do not escape & characters (#333)
1 parent ad62437 commit eb7eb95

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

.changeset/two-lobsters-report.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/compiler': patch
3+
---
4+
5+
Parse: fix escaping of `&` characters in AST output

internal/printer/print-to-json.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ func escapeForJSON(value string) string {
4141
value = newlines.ReplaceAllString(value, `\n`)
4242
doublequotes := regexp.MustCompile(`"`)
4343
value = doublequotes.ReplaceAllString(value, `\"`)
44-
amp := regexp.MustCompile(`&`)
45-
value = amp.ReplaceAllString(value, `\&`)
4644
r := regexp.MustCompile(`\r`)
4745
value = r.ReplaceAllString(value, `\r`)
4846
t := regexp.MustCompile(`\t`)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { test } from 'uvu';
2+
import * as assert from 'uvu/assert';
3+
import { parse } from '@astrojs/compiler';
4+
5+
const STYLE = `div { & span { color: red; }}`;
6+
const FIXTURE = `<style>${STYLE}</style>`;
7+
8+
test('ampersand', async () => {
9+
const result = await parse(FIXTURE);
10+
assert.ok(result.ast, 'Expected an AST to be generated');
11+
const [
12+
{
13+
children: [{ value: output }],
14+
},
15+
] = result.ast.children;
16+
assert.equal(output, STYLE, `Expected AST style to equal input`);
17+
});
18+
19+
test.run();

0 commit comments

Comments
 (0)