Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support JSX fragments with jsxFragmentFactory compiler option and @jsxFrag pragma#38720

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

nojvek
Copy link
Contributor

@nojveknojvek commentedMay 21, 2020
edited
Loading

Reviving:#35392 (which was closed due to inactivity)

Checklist

Problem:

Currently<><Foo /></> only works with"jsx": "react". Using an inline pragma for jsxFactory/** @jsx dom */ or config defined"jsxFactory": "h" throws an error thatJSX fragment is not supported when using --jsxFactory

The issue has been open for almost 3 years now.

Proposal Fix:

Very much inspired from babel to keep ecosystem consistent.

https://babeljs.io/docs/en/babel-plugin-transform-react-jsx

  1. jsxFragmentFactory compiler option.

As suggested and reviewed by@weswigham in previous PR.

Babel plugin-transform-react-jsx supports following options

{"plugins":[["@babel/plugin-transform-react-jsx",{"pragma":"Preact.h",// default pragma is React.createElement"pragmaFrag":"Preact.Fragment",// default is React.Fragment"throwIfNamespace":false// defaults to true}]]}

Typescript already supportsjsxFactory compiler option, this PR adds another optionaljsxFragmentFactory compiler option for similar developer UX.

{"compilerOptions": {"target":"esnext","module":"commonjs","jsx":"react","jsxFactory":"h","jsxFragmentFactory":"Fragment"  }}
  1. support for@jsxFrag pragma. This code would work in both typescript and babel without changes. TS will need jsx:react for emit though.
/**@jsx Preact.h *//**@jsxFrag Preact.Fragment */importPreactfrom'preact';vardescriptions=items.map(item=>(<><dt>{item.name}</dt><dd>{item.value}</dd></>));

weswigham, marvinhagemeister, ahuglajbclajep, pvcresin, acid-chicken, mariuslundgard, and aduth reacted with heart emojibrussee reacted with rocket emojibrainkim and uhyo reacted with eyes emoji
@nojveknojvekforce-pushed thenojvek-jsx-fragment-factory branch from4010afc to975e7b8CompareMay 22, 2020 00:38
@nojvek
Copy link
ContributorAuthor

@weswigham - would appreciate a review when you get a chance.

Thanks!

@nojvek
Copy link
ContributorAuthor

@weswigham I added a type elision test like you mentioned. Did a bit of debugging but still have little idea how to make the emmiter emit jsxFrag import so we don't end up with this, where snabbdom doesn't have a correspondingrequire

//// [mix-n-match.js]"use strict";exports.__esModule=true;/*@jsx h *//*@jsxFrag Frag */varpreact_1=require("./preact");preact_1.h(snabbdom_1.Frag,null,preact_1.h("span",null));

@weswigham
Copy link
Member

You'll need to mark it asreferenced when a fragment that uses it ischeck'ed in the checker -checkJsxOpeningLikeElementOrOpeningFragment does this. It needs to swap the name it resolves and marks when it's looking at a fragment.

nojvek reacted with thumbs up emoji

@nojveknojvekforce-pushed thenojvek-jsx-fragment-factory branch from30a8f17 todf5a194CompareMay 22, 2020 15:48
@nojvek
Copy link
ContributorAuthor

Sweet! I have the type elision scenario passing as a test.

@weswigham, ready for a review 👀 when you are.

@nojvek
Copy link
ContributorAuthor

@typescript-bot pack this

@nojvek
Copy link
ContributorAuthor

I guess@typescript-bot only listens to typescript team 🤷‍♂️

@weswigham
Copy link
Member

@typescript-bot pack this :P

nojvek and marvinhagemeister reacted with laugh emoji

@typescript-bot
Copy link
Collaborator

typescript-bot commentedMay 23, 2020
edited
Loading

Heya@weswigham, I've started to run the tarball bundle task on this PR atdf5a194. You can monitor the buildhere.

@nojvek
Copy link
ContributorAuthor

Please tell me that when a TS team member types@typescript-bot sudo make me a 🥪, something really cool happens. If not, you need to seriously evaluate priorities in the roadmap. Ha!

@typescript-bot
Copy link
Collaborator

typescript-bot commentedMay 23, 2020
edited
Loading

Hey@weswigham, I've packed this intoan installable tgz. You can install it for testing by referencing it in yourpackage.json like so:

{    "devDependencies": {        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/74777/artifacts?artifactName=tgz&fileId=4E617F10A295CC8B5DD8371C8F44C745356B0A4C8893BB6AD7964773498EA80F02&fileName=/typescript-4.0.0-insiders.20200523.tgz"    }}

and then runningnpm install.


There is also a playgroundfor this build.

nojvek and marvinhagemeister reacted with thumbs up emoji

@nojvek
Copy link
ContributorAuthor

@weswigham do you have any ETA when you'll review this or whether it's likely to land in next TS version ?

Copy link
Member

@weswighamweswigham left a comment

Choose a reason for hiding this comment

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

I think this looks pretty good now (small note above). I'd like to get another pair of eyes, just to be prudent, and confirm this is OK to merge with@DanielRosenwasser.

nojvek reacted with thumbs up emoji
@nojvek
Copy link
ContributorAuthor

Kind ping@DanielRosenwasser for 👀

marvinhagemeister reacted with thumbs up emoji

@nojvek
Copy link
ContributorAuthor

Kind ping again@DanielRosenwasser for review 👀 ^

marvinhagemeister reacted with thumbs up emoji

@nojvek
Copy link
ContributorAuthor

Another kind ping@DanielRosenwasser ^

@weswigham is there anyone else in the TS team that can review this for merge? I have a feeling that this could be a PR that sits for months and eventually ends up being closed. This is my 3rd try trying to make a PR for jsxFragments over the last 2 years.

Please please please don't leave this hanging in limbo.

marvinhagemeister reacted with thumbs up emoji

@DanielRosenwasser
Copy link
Member

Hey, I checked in with a couple of other people on the team. I'm going to raise it for the design meeting agenda tomorrow, but if there's nothing else controversial I think we can get it in by next week for the release.

nojvek and marvinhagemeister reacted with hooray emoji

@nojvek
Copy link
ContributorAuthor

You are the best@DanielRosenwasser. Thank you 🙏

@weswigham
Copy link
Member

@andrewbranch you wanna give this a second review and help get this merged?

Copy link
Member

@andrewbranchandrewbranch left a comment

Choose a reason for hiding this comment

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

Approved, with grammar note. Thanks@nojvek!

"category": "Error",
"code": 17016
},
"JSX fragmentisnot supportedwhen using aninline JSX factory pragma": {
"An @jsxFrag pragmaisrequiredwhen using an@jsx pragma with JSX fragments.": {
Copy link
Member

Choose a reason for hiding this comment

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

Hopefully this doesn’t turn into the GIF pronunciation debate, but I don’t pronounce the@ character so I think these articles should be “a,” not “an” 🙃

DanielRosenwasser and bensaufley reacted with thumbs up emoji

Choose a reason for hiding this comment

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

Pretty glad we moved away from "working @microsoft" to "working at @microsoft"

nojvek reacted with laugh emoji
Copy link
Member

Choose a reason for hiding this comment

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

... I pronounce the@. 😆

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

When@weswigham first mentioned this as PR comment, I didn't fully agree with him, but when I read it over many times I was internally conflicted which way is the right way. In the end I chose to appease@weswigham 🤷

const jsxFactoryNamespace = getJsxNamespace(node);
const jsxFactoryLocation = isNodeOpeningLikeElement ? (<JsxOpeningLikeElement>node).tagName : node;

// allow null as jsxFragmentFactory
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, what’s the utility of this? I couldn’t find anything about usingnull in the babel transform docs.

DanielRosenwasser reacted with thumbs up emoji
Copy link
Member

@weswighamweswighamJun 15, 2020
edited
Loading

Choose a reason for hiding this comment

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

I think the idea is that some libraries may use anull tag name to indicate a fragment, rather than some specific fragment object.Mithril actually uses'[' as the fragment sentinel nowadays, so we should actually consider supporting arbitrary simple expressions here...

nojvek and vincehi reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

snabbdom-jsx-lite uses null.https://github.com/nojvek/snabbdom-jsx-lite/blob/master/tsconfig.json#L8

Mostly because if

is compiled toh('div', null). null meaning no attrs,

<> compiles toh(null, null) meaning it's no named tag i.e Fragment. This avoids an extra function call for evaluation of fragment function, which in most cases convert the children to an array.

@weswigham
Copy link
Member

@nojvek would you be able to do a quick resync withmaster?

nojvek reacted with thumbs up emoji

@nojveknojvekforce-pushed thenojvek-jsx-fragment-factory branch from6a7a8c7 to2d7372aCompareJune 16, 2020 02:08
@nojveknojvekforce-pushed thenojvek-jsx-fragment-factory branch from2d7372a tob950086CompareJune 18, 2020 02:07
@nojvek
Copy link
ContributorAuthor

FYI@weswigham, merged with latest master and ensured tests pass locally.

marvinhagemeister, weswigham, Yegorich555, nojvek, and acid-chicken reacted with thumbs up emoji

@weswighamweswigham merged commitf697d26 intomicrosoft:masterJun 18, 2020
@nojveknojvek deleted the nojvek-jsx-fragment-factory branchJune 18, 2020 14:42
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@DanielRosenwasserDanielRosenwasserDanielRosenwasser left review comments

@weswighamweswighamweswigham approved these changes

@andrewbranchandrewbranchandrewbranch approved these changes

Assignees

@andrewbranchandrewbranch

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Support JSX-Fragments with custom jsxFactory
5 participants
@nojvek@weswigham@typescript-bot@DanielRosenwasser@andrewbranch

[8]ページ先頭

©2009-2025 Movatter.jp