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

Maintain whitespace before tag close #822

Merged
merged 3 commits into from
Jul 10, 2023
Merged

Maintain whitespace before tag close #822

merged 3 commits into from
Jul 10, 2023

Conversation

natemoo-re
Copy link
Member

Changes

Testing

Two tests added

Docs

N/A, bug fix only

@changeset-bot
Copy link

changeset-bot bot commented Jul 7, 2023

🦋 Changeset detected

Latest commit: a889dd8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/compiler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@@ -375,15 +375,13 @@ declare const Astro: Readonly<import('astro').AstroGlobal<%s>>`, props.Ident)
p.print(`:`)
p.addSourceMapping(loc.Loc{Start: eqStart + 1})
p.print(`"` + encodeDoubleQuote(a.Val) + `"`)
endLoc = eqStart + 1 + len(a.Val) + 2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out these would mess up the endLoc because they could be out of order

Comment on lines 435 to 437
} else if unicode.IsSpace(rune(c)) {
hasLeadingSpace = true
endLoc++
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we find a space before the >, we flag it

Comment on lines 446 to 449
if hasLeadingSpace {
p.addSourceMapping(loc.Loc{Start: endLoc - 1})
p.print(" ")
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if we have the flag, we print an extra " " character

Copy link
Member

@Princesseuh Princesseuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic seems fine to me, but I have one question, what happens if there's multiple spaces?

<Button      >

Will they all get mapped to the first space that was created, since only one space is created?

@natemoo-re
Copy link
Member Author

Great question @Princesseuh! I just pushed a change to make the mapping a bit more clear for that case—that one space technically gets mapped back to the whole block of spaces in the source file. I think TypeScript should handle this just fine, but we can adjust if that's not the case.

@natemoo-re natemoo-re merged commit 3d69f4e into main Jul 10, 2023
5 checks passed
@natemoo-re natemoo-re deleted the fix/801--plt-564 branch July 10, 2023 20:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: [TSX] Spaces in tag names are not preserved unless there's an attribute
2 participants