Skip to content

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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Ailrun
Copy link

@Ailrun Ailrun commented Feb 11, 2019

Resolves #2156.

Copy link
Member

@ljharb ljharb left a 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"
Copy link
Member

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?

Copy link
Author

@Ailrun Ailrun Feb 11, 2019

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.

Copy link
Member

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)?

Copy link
Author

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.

Copy link
Member

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?

Copy link
Author

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.

Copy link
Author

@Ailrun Ailrun Feb 12, 2019

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

  1. A case with custom element creator. (should use jsxPragma)
    import { jsx } from 'my-jsx';
    import React from 'react';
    
    <><div /></>
  2. A case with different local name for React. (should use localName)
    import R from 'react';
    
    <><div /></>
  3. A case with different library with Fragment support. (should use jsxFragPragma)
    import O from 'other-jsx-library-supports-fragment';
    
    <><div /></>
  4. Cases with mixes of others.

Copy link
Member

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:

  1. currently not supported - createElement is hardcoded off of the pragma.
  2. currently uses pragma; localName is fine to also support via an inline comment, but pragma should remain the only way to configure this in settings.
  3. currently uses fragment in getFragmentFromContext, and then pairs that here with pragma - if jsxFragPragma should override both, then that's fine to support as an inline comment, and maybe we could make the fragment setting be either a string (paired with pragma), or an object where either is supported?
  4. 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"
Copy link
Member

Choose a reason for hiding this comment

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

similarly, why deprecate this?

@Ailrun
Copy link
Author

Ailrun commented Jan 15, 2020

I don't have enough time to manage this PR, so I close this.

@Ailrun Ailrun closed this Jan 15, 2020
@ljharb
Copy link
Member

ljharb commented Jan 15, 2020

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)

@ljharb ljharb reopened this Jan 15, 2020
@ljharb ljharb marked this pull request as draft October 15, 2020 17:58
@ljharb ljharb force-pushed the master branch 6 times, most recently from 59af733 to 865ed16 Compare November 11, 2022 02:45
@ljharb ljharb force-pushed the master branch 4 times, most recently from 069314a to 181c68f Compare November 18, 2022 17:19
@ljharb ljharb force-pushed the master branch 2 times, most recently from 380e32c to 51d342b Compare July 4, 2024 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

jsx-uses-react rule does not detect jsxFrag rule
2 participants