Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TSX] Fix multiline quoted attribute mapping #829

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lazy-bats-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

[TSX] fix sourcemaps for quoted attributes that span multiple lines
5 changes: 4 additions & 1 deletion internal/printer/print-to-tsx.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ declare const Astro: Readonly<import('astro').AstroGlobal<%s>>`, props.Ident)
p.print("=")
if len(a.Val) > 0 {
p.addSourceMapping(loc.Loc{Start: a.ValLoc.Start - 1})
p.print(`"` + encodeDoubleQuote(a.Val) + `"`)
p.print(`"`)
p.printTextWithSourcemap(encodeDoubleQuote(a.Val), loc.Loc{Start: a.ValLoc.Start})
p.addSourceMapping(loc.Loc{Start: a.ValLoc.Start + len(a.Val)})
p.print(`"`)
endLoc = a.ValLoc.Start + len(a.Val) + 1
} else {
p.addSourceMapping(loc.Loc{Start: a.ValLoc.Start - 1})
Expand Down
14 changes: 14 additions & 0 deletions packages/compiler/test/tsx-sourcemaps/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,18 @@ test('template literal attribute', async () => {
});
});

test('multiline quoted attribute', async () => {
const input = `<path d="M 0
C100 0
Z" />`;

const output = await testTSXSourcemap(input, 'Z');
assert.equal(output, {
source: 'index.astro',
line: 3,
column: 1,
name: null,
});
});

test.run();
Loading