-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add jsx frag pragma support #2158
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
base: master
Are you sure you want to change the base?
Conversation
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.
The values in "settings" have no need to be the same as the inline jsdoc comment names; why deprecate the nice ones?
"localName": "React" // Local name of React import, default to "<setttings.react.pragma>" | ||
"jsxPragma": "React.createElement" // JSX Pragma to use, default to "<settings.react.pragma>.createElement" | ||
"jsxFragPragma": "React.Fragment" // JSX Fragment Pragma to use, default to "<settings.react.pragma>.<settings.react.fragment>" | ||
"pragma": "React", // *Deprecated* Pragma to use, default to "React" |
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'm confused, why would this be deprecated?
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.
Since semantics changed, I think new settings should be provided (not to break existing settings of current users)
If you think just breaking those (and probably update major version) is better, I will update this PR.
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.
How have the semantics changed (for users who haven't added the new pragma settings)?
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 mean, if old users use pragma
with React
, originally rules will detect <pragma>.createElement
. With jsxPragma
, rules detect <jsxPragma>
so that its behavior aligns with babel's.
Therefore, if I just use pragma
and do not add new settings, it will break existing settings.
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.
Right but why would jsxPragma
even exist in the common case for users of this plugin, if it doesn't do anything for them?
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.
@ljharb Could you tell me your suggestion for the setting combination?
I don't get the right point I need to explain, so I think that would be easier to me.
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.
@ljharb FYI, what I considered are
- A case with custom element creator. (should use
jsxPragma
)import { jsx } from 'my-jsx'; import React from 'react'; <><div /></>
- A case with different local name for React. (should use
localName
)import R from 'react'; <><div /></>
- A case with different library with Fragment support. (should use
jsxFragPragma
)import O from 'other-jsx-library-supports-fragment'; <><div /></>
- Cases with mixes of others.
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.
OK, so. To support your first 3 cases:
- currently not supported -
createElement
is hardcoded off of thepragma
. - currently uses
pragma
;localName
is fine to also support via an inline comment, butpragma
should remain the only way to configure this in settings. - currently uses
fragment
ingetFragmentFromContext
, and then pairs that here withpragma
- ifjsxFragPragma
should override both, then that's fine to support as an inline comment, and maybe we could make thefragment
setting be either a string (paired with pragma), or an object where either is supported? - without specifics i'm not sure what we need to do here.
It seems like we should maybe do these new features as separate PRs.
The first one seems to be 3 - ie, add support for an alternative schema in fragment
, that inline jsxFrag
comments hook into.
"jsxPragma": "React.createElement" // JSX Pragma to use, default to "<settings.react.pragma>.createElement" | ||
"jsxFragPragma": "React.Fragment" // JSX Fragment Pragma to use, default to "<settings.react.pragma>.<settings.react.fragment>" | ||
"pragma": "React", // *Deprecated* Pragma to use, default to "React" | ||
"fragment": "Fragment", // *Deprecated* Element of Pragment to use as Fragment, default to "Fragment" |
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.
similarly, why deprecate this?
I don't have enough time to manage this PR, so I close this. |
If it’s ok, I’d prefer to keep it open in case someone else can help by posting a link to a branch (not an additional PR, please) |
59af733
to
865ed16
Compare
069314a
to
181c68f
Compare
380e32c
to
51d342b
Compare
Resolves #2156.