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

[jsx] add jsx support to playground #319

Merged
merged 35 commits into from
Jun 15, 2022
Merged

Conversation

taylor-vann
Copy link
Contributor

Add JSX support to playground to support the Lit Labs React package.

@taylor-vann taylor-vann marked this pull request as draft June 8, 2022 22:28
@taylor-vann taylor-vann self-assigned this Jun 8, 2022
@taylor-vann taylor-vann removed the request for review from justinfagnani June 9, 2022 22:04
@taylor-vann taylor-vann marked this pull request as ready for review June 14, 2022 17:01
src/test/playground-ide_test.ts Show resolved Hide resolved
</body>
</script>
<script type="sample/tsx" filename="howdy.tsx">
const howdy: string = "Howdy TSX!";
Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to verify that this is getting interpreted as TSX, and not regular TS, since there's nothing TSX specific in this example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

totally. i think that's leading to my real question, which is how to mock react in this playground? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if stuff imports auto-magically like the real playground then we should be good

Copy link
Collaborator

Choose a reason for hiding this comment

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

A script tag that pulls in React from a local node_modules path should define the window.React global.

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't typescript emit import ... from "react" though?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Since React isn't distributed as modules that doesn't work. You can import type ... though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'll give that a shot. thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mocked the react api with mock-react.ts. It adds a text node to the body of the test.
We could use preact if we need more from an integration test.

src/typescript-worker/language-service-context.ts Outdated Show resolved Hide resolved
@taylor-vann
Copy link
Contributor Author

excellent :) i think this is ready for a review, next up syntax highlighting

Copy link
Member

@aomarks aomarks left a comment

Choose a reason for hiding this comment

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

Looking good! Please also update the README and CHANGELOG files.

E.g. here: https://github.com/google/playground-elements/#typescript

src/test/playground-ide_test.ts Outdated Show resolved Hide resolved
src/test/typescript-worker_test.ts Show resolved Hide resolved
CHANGELOG.md Outdated
@@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

<!-- ## Unreleased -->

## [0.17.0] - 2021-08-09
Copy link
Member

Choose a reason for hiding this comment

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

Keep it under "Unreleased". There's a commented header above that you can uncomment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think i did it this time around

src/test/typescript-worker_test.ts Outdated Show resolved Hide resolved
CHANGELOG.md Outdated
@@ -25,6 +25,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Added support for compiling `jsx` and `tsx` modules in the playground.

### Changed

- Updated the tsconfig in `language-service-context.ts` to include `allowJs` and `jsx`.
Copy link
Member

Choose a reason for hiding this comment

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

This file is to be consumed by users, not so much us, so I think this is too much detail. The user only cares that tsx and jsx files are now compiled.

@taylor-vann taylor-vann merged commit 71ac36c into main Jun 15, 2022
@taylor-vann taylor-vann deleted the playground__add_jsx_support branch June 15, 2022 23:46
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.

3 participants