Skip to content
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 version 1.1 - non-breaking changes #117

Open
kunukn opened this issue Jun 2, 2019 · 1 comment
Open

JSX version 1.1 - non-breaking changes #117

kunukn opened this issue Jun 2, 2019 · 1 comment
Labels
Proposal Living Proposals considerable for the living JSX Proposal Proposals (haven't confirmed)

Comments

@kunukn
Copy link

kunukn commented Jun 2, 2019

Some features has been proposed before, but nothing seems to be happening even though they get upvoted.

Would it be easier if we think in terms of non-breaking changes to update the JSX specification?

E.g. I believe this is a non-breaking addition to the JSX specification.

<Foo bar=2 />
#64

In JSX 1.1 you would then have the options

<Foo bar=2 />
<Foo bar={2} />

JSX 1.0 (current version) you have the option

<Foo bar={2} />


Option 1: <Foo bar=2 /> this could be evaluated to an AssignmentExpression without the { }

The generated AST should be identical for

<Foo bar=2 /> and <Foo bar={2} />


Option 2: We could extend allowed values for JSXAttributeValue
https://facebook.github.io/jsx/

JSXAttributeValue :

  • JSXNumber
  • JSXDoubleStringCharacters "
  • JSXSingleStringCharacters '
  • AssignmentExpression {}
  • JSXElement <
  • JSXFragment <

The definition of JSXNumber could be typeof number

e.g.

2, 0x10, NaN


Could this be generalised?
Allow non-breaking changes where we omit the brackets for JSXAttributeValue?

e.g.

<Button 
  onClick = { onCreate } 
  id = { 123 } 
  zIndex = { 1 } 
  onMouseOver = { onMouseOverCreateButton }>
    Create
</Button>

Could also be

<Button 
  onClick = onCreate  
  id = 123  
  zIndex = 1 
  onMouseOver = onMouseOverCreateButton>
    Create
</Button>

Languages evolves and gets updated.

I see JSX as an essential part of React that makes it popular and loved.
I hope the JSX specification evolves over time. Even if is small minor syntax sugar improvements.

@thers
Copy link

thers commented Mar 17, 2020

When adding sugar for raw number isn't hard from parser perspective, support for omitting {} around AssignmentExpression adds ambiguity for parser.

Consider this <div onClick={ foo } />
The onClick attribute could be parsed as both ObjectLiteral with foo property shorthand and as AssignmentExpression of foo identifier.

The only way for omitting curly braces is to restrict possible expressions eliminating ambiguity.

@Huxpro Huxpro added Proposal Proposals (haven't confirmed) Proposal Living Proposals considerable for the living JSX labels Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Proposal Living Proposals considerable for the living JSX Proposal Proposals (haven't confirmed)
Projects
None yet
Development

No branches or pull requests

3 participants