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

Allow TypeScript in hoisted scripts #3665

Merged
merged 4 commits into from
Jun 22, 2022
Merged

Allow TypeScript in hoisted scripts #3665

merged 4 commits into from
Jun 22, 2022

Conversation

matthewp
Copy link
Contributor

Changes

  • Appends &lang.ts to the module id of hoisted scripts. This makes it so that Vite treats these are TypeScript.

Testing

  • Test added

Docs

N/A, bug fix.

@changeset-bot
Copy link

changeset-bot bot commented Jun 21, 2022

🦋 Changeset detected

Latest commit: c209c8a

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

This PR includes changesets to release 1 package
Name Type
astro 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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jun 21, 2022
@Princesseuh
Copy link
Member

Not sure if needed, but I think a test for importing files with various extensions (no extension, js extension for ts file etc) should be added since that's been a common issue inside the frontmatter

Comment on lines +2 to +7
interface Props {
name: string;
}
Copy link
Member

Choose a reason for hiding this comment

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

Ooh is the compiler ready for this? We follow 4.12.1.3 so I think generics should be fine...

Would be nice to test! LMK if you think that should be in the compiler rather than here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure I follow, this is tested, this file is a test file.

@matthewp
Copy link
Contributor Author

@Princesseuh added tests for imports. Thanks for suggesting that, needed to make that work.

@@ -1,3 +1,11 @@
<script>
console.log('some content here.');
import '../scripts/some-files/one';
import '../scripts/some-files/two.ts';
Copy link
Member

@Princesseuh Princesseuh Jun 21, 2022

Choose a reason for hiding this comment

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

Missing a .js import for a ts file (ex, one.js for one.ts)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

Copy link
Contributor

@tony-sull tony-sull left a comment

Choose a reason for hiding this comment

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

Nice, looks good to me! Clever fix just being able to tell Vite lang="ts" 👍

@matthewp
Copy link
Contributor Author

Need to check something in the rollup docs before merging this.

@matthewp matthewp merged commit 9a81326 into main Jun 22, 2022
@matthewp matthewp deleted the ts-script-tag branch June 22, 2022 16:47
@github-actions github-actions bot mentioned this pull request Jun 22, 2022
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* Allow TypeScript in hoisted scripts

* Pass skipSelf

* Fix linting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants