-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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 Support #2673
JSX Support #2673
Conversation
Hi @fdecampredon, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
@fdecampredon, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR. |
Thanks for the PR, I'll take a look later tomorrow. |
@fdecampredon Great stuff I'm not sure how, but it would be nice to see this solved as general template string: ///<template name="jsx" compile="myFactory" />
jsx`<div />`
// typechecked as :
myFactory("div", {}); |
@@ -316,6 +316,20 @@ module ts { | |||
return visitNode(cbNode, (<ExternalModuleReference>node).expression); | |||
case SyntaxKind.MissingDeclaration: | |||
return visitNodes(cbNodes, node.decorators); | |||
case SyntaxKind.JSXElement: | |||
return visitNode(cbNode, (<JSXElement>node).openingElement) || visitNodes(cbNodes, (<JSXElement>node).children) || visitNode(cbNode, (<JSXElement>node).closingElement); |
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.
wrap these to keep things consistent with the rest of this function.
I'm concerned about the incremental parsing issues here. If you have: var v = <book>x;
var y;
var z; And you add something at the end like We'll need to track (in the parse tree) where type assertions are used. And then, during incremental parsing, we'll have to walk into anything that has a type assertion, and see if that type assertion could match a close tag that follows it in the file. If so, we'll have to consider the node ineligible for incremental reuse. |
@CyrusNajmabadi |
The typechecking using the factory seems problematic as a general solution, and there is no clean consensus at this point what the right direction is... can you remove the type-checking from the PR and for now type things as 'any'. I'm aware of the limitations, and agree we should do something else in the future. Just not sure what... |
|
We should come up with a design for typing things before we actually release this and make changes based on that. But we should focus on a solid (and performant) parsing story first. First walk, then run etc... Thanks for all the work! |
I would definitely want the incremental parsing issue resolved before merging. Otherwise, we could end up in a state where you're editing, but invalid parse trees. We want to avoid that like the plague, else we will have many hard to track down bugs. Here would be my preferred order of work:
This allows the work to be spread into much smaller pieces, and allows us to make sure that things are working properly before going on to the next stages. Thanks! |
also notice that some tags should omit their close tag |
How about using double angle brackets for XML-like syntax in typescript? This should avoids conflict with type assertion:
I think even if the TS compiler/IDEs are smart enough to recognize single-angle-bracket XML tags, it is harder for human eyes to quickly distinguish single-angle-bracket XML tags and type assertions and generics. |
Too verbose. There have been other simpler recommendations like That said I strongly prefer what @fdecampredon has done and it would be awesome to have in TS core. |
@basarat Yes double angle bracket is verbose, but personally I think it is more pretty-looking than something like P.S., smart code editors may autocomplete double angle brackets, e.g., after you type |
Did you imagine every level or just first level? <<div>>
<<div>>
<</div>>
<</div>> |
Probably every level, because TS codes may be mixed inside XML elements. |
Any chances that TypeScript will get official support and this PR will be merged? I want to migrate my project to TypeScript, but JSX support is essential for me. |
last time I chatted with @fdecampredon he was busy moving, So hopefully we can get in soon :) |
+1 on getting this in soon. |
I would consider Typescript as well for my next project if it can support JSX. So please asap! 👍 |
I want to set some expectations here. We won't be able to get this in the 1.5 release, however we're moving as fast as we can. |
@fdecampredon could you please look at #3022 ? I would like to have your thoughts on it. I know that you commented before that you didn't expect the TS team to include JSX and thus created your own fork because you thought it "was the right way", seems like they changed their mind now. |
@fdecampredon @CyrusNajmabadi How about using |
@CyrusNajmabadi @paulvanbrenk would you mind if I completely rewrite the git history, it's a bit a mess now and a lot of things has been added then removed (especially in scanner). |
Would be nice if it could also work with |
I'll rather prefer .tsx or jsx.ts Sent from my iPhone On May 7, 2015, at 4:56 AM, Konstantin Tarkus notifications@github.com Would be nice if it could also work with .react.ts as well as the default — |
Is there a good reason to have a special file extension? I don't think so, if it's part of TypeScript it should be allowed to use JSX in every *.ts file. JSX uses *.jsx to differentiate from *.js but TypeScript is allready differentiated from *.js by using *.ts, so there is no need for a special file extension... |
Really looking forward for this! |
I'm ok with you rewriting things. @paulvanbrenk are you ok with this? |
Go right ahead. |
@paulvanbrenk @CyrusNajmabadi I tried to address all your feedbacks except for incremental parsing. |
Hi @fdecampredon . I would wait on 'as' to get merged in, and i would remove all the disambiguation logic you have. With TSX, we'll be requiring that you use 'as' for type assertions, and things like This does mean that .ts code can't simply be dropped into a .tsx file, but c'est la vie. Because of these changes, i don't believe there is any work you will need to do for incremental parsing anymore. The problem with incremental parsing was the ambiguity with So yaay, everything gets simpler. |
This work has been folded in to a future PR |
Following the discussion in #296, here is a PR that adds support for JSX constructs.
And some details about the implementation/spec :
///<jsx factory="myFactory" />
For this purpose, types for JSXElement call are only inferred from the first argument (the tag).
The service integration is minimal and ported from my old version of jsx-typescript, so not well tested.