-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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: JSX Support #3038
feat: JSX Support #3038
Conversation
@keroxp JSX support is desirable - but is it necessary to add these top level methods to Deno? renderToString, Component, etc... Those seem like framework level needs. Also, please add an integration test to |
@ry Not necessary but may be convenient for developers. Ok I'll remove default jsx factories from this PR anyway. |
cli/tests/046_jsx_test.tsx
Outdated
@@ -0,0 +1,7 @@ | |||
function h(factory, props, ...children) { | |||
return {factory, props, children} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not linted properly. We should ensure the linting covers these files as well.
tsconfig.json
Outdated
@@ -17,6 +17,8 @@ | |||
"sourceMap": true, | |||
"strict": true, | |||
"target": "esnext", | |||
"jsx": "react", | |||
"jsxFactory": "h", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am concerned we are not using the default here of React.createElement
. I can understand why, but it will be potentially surprising to users that we aren't using the default. At the very least I would like to see updates to the manual along with this PR before we merge it explaining how it is anticipated to be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either is OK. React.creaetElement
may rather be useful for real use. react
and react-dom/server
can be imported in Deno via dev.jspm.io
.
cli/state.rs
Outdated
state_.ts_compiler.compile_async(state_.clone(), &out) | ||
} | ||
msg::MediaType::JavaScript => { | ||
msg::MediaType::JavaScript | msg::MediaType::JSX => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure about this. This will leave the .jsx
untouched if the checkJs
compiler flag is not set. I can't see that being desirable.
We should have tests around .jsx
and we should have an expected behaviour of how they are handled. We also need it consistent with how the compiler behaves, where by default we have allow JS but not check JS, so how does that effect the emit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I absolutely forgot it. Hmm... should we compile .jsx
files as TSX?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, not compile as TSX, more that we will always attempt to transpile them, move it to the previous match clause, but I would check that that works as expected, when the checkJs
compiler flag is not enabled (which is the default), which the integration test should prove.
@ry Added integration tests for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - i look forward to doing react in deno
JSX was the last thing I expected in Deno core. Highly disappointed ((( Wish you luck! |
@PopovMP Deno doesn't include React - JSX support is part of the TypeScript compiler - this is just exposing that feature. If you notice this PR only added 61 lines (which is mostly the integration tests). |
Does it increase compile time for non-JSX files as well ? |
@GrosSacASac No - we did not observe any change in our compile time benchmarks. |
@GrosSacASac it basically allowed something through that we didn't allow before. The capability has always been there in the TypeScript compiler, basically all that needed to be done was to interpret the media types properly. While this feature doesn't make sense in and of itself for server side workloads, it does in the context of server side rendering. Of course end users could load a transpiler for JSX/TSX in the runtime and deal with all the module resolution, or we could just enable a feature already there. It makes sense to do the latter. I personally strongly dislike JSX, but it would be stilly to specifically hobble the compiler support to enforce that opinion on others. We plan to support a public compiler API (see: #1739) and that would have allowed people to support it directly in Deno anyways, though some sort of custom compiler. Again it would be silly to force users to do that when it is already natively supported. |
PR for #3037
Added JSX support feature. Now
.jsx
.tsx
files can be imported.By default, there is no jsxFactory function at runtime. Default
jsxFactory
value oftsconfig.json
isReact.createElement
. To use jsx/tsx in Deno, define or importreact
before JSX expression or define your ownReact.createElement
or use customjsxFactory
with tsconfig.json: