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

feat(tsx): Prefix tsx output with a JSX pragma #917

Merged
merged 4 commits into from
Jan 2, 2024
Merged

Conversation

Princesseuh
Copy link
Member

@Princesseuh Princesseuh commented Dec 20, 2023

Changes

Add /** @jsxImportSource astro */ to our TSX output so it uses the newly exported types at withastro/astro#9501, this is all to attempt to fix withastro/language-tools#727

Testing

Adjusted tests

Docs

N/A

Copy link

changeset-bot bot commented Dec 20, 2023

🦋 Changeset detected

Latest commit: 9a69bbf

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

@Princesseuh
Copy link
Member Author

!preview tsx-prefix

Copy link
Contributor

 > [email protected] release /home/runner/work/compiler/compiler > changeset publish "--tag" "next--tsx-prefix" 🦋 warn ===============================IMPORTANT!=============================== 🦋 warn Packages will be released under the next--tsx-prefix tag 🦋 warn ---------------------------------------------------------------------- 🦋 info npm info @astrojs/compiler 🦋 info @astrojs/compiler is being published because our local version (0.0.0-tsx-prefix-20231221053005) has not been published on npm 🦋 info Publishing "@astrojs/compiler" at "0.0.0-tsx-prefix-20231221053005" 🦋 success packages published successfully: 🦋 @astrojs/[email protected] 🦋 Creating git tag... 🦋 New tag: @astrojs/[email protected]

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

Looks fine to me!

internal/printer/print-to-tsx.go Show resolved Hide resolved
@Princesseuh Princesseuh marked this pull request as ready for review December 29, 2023 05:34
char := rune(buf[len(buf)-1:][0])
// If the existing buffer ends with any character other than ;, we need to add a `;`
if char != ';' {
p.addNilSourceMapping()
p.print("\"\";")
p.print("{};")
Copy link
Member Author

@Princesseuh Princesseuh Dec 29, 2023

Choose a reason for hiding this comment

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

From my tests, this seemed fine as a replacement of "";, but I feel like there must be a reason I went for ""; back in the day. Can't remember it, though. I also wonder if TypeScript didn't fix a lot of those issues in the past 2 years...

(When I first joined Astro, it was ;//, from withastro/language-tools#59 )

@Princesseuh
Copy link
Member Author

!preview tsx-prefix

Copy link
Contributor

 > [email protected] release /home/runner/work/compiler/compiler > changeset publish "--tag" "next--tsx-prefix" 🦋 warn ===============================IMPORTANT!=============================== 🦋 warn Packages will be released under the next--tsx-prefix tag 🦋 warn ---------------------------------------------------------------------- 🦋 info npm info @astrojs/compiler 🦋 info @astrojs/compiler is being published because our local version (0.0.0-tsx-prefix-20231229054418) has not been published on npm 🦋 info Publishing "@astrojs/compiler" at "0.0.0-tsx-prefix-20231229054418" 🦋 success packages published successfully: 🦋 @astrojs/[email protected] 🦋 Creating git tag... 🦋 New tag: @astrojs/[email protected]

Copy link
Member

@MoustaphaDev MoustaphaDev left a comment

Choose a reason for hiding this comment

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

The code looks good to me, but I wonder why "" was replaced by {} after frontmatter closing?

@Princesseuh
Copy link
Member Author

The code looks good to me, but I wonder why "" was replaced by {} after frontmatter closing?

Ah, I forgot to mention the justification, it's because it's seen as a string pragma (like use client, use strict) and so TypeScript will attempt to move it at the top of the file, which messes with imports

@MoustaphaDev
Copy link
Member

Ah ok, makes sense now

@Princesseuh Princesseuh merged commit c5bcbd0 into main Jan 2, 2024
5 checks passed
@Princesseuh Princesseuh deleted the fix/tsx-prefix branch January 2, 2024 13:37
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: astro check reports incorrect errors on HTMLAttributes
3 participants