You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I acknowledge that the old JSX 2.0 proposal (#65) had way too many comments to keep up a discussion and is closed for discussion.
This proposal tries to accomodate many existing issues. It is based on the existing JSX 2.0 proposal by @sebmarkbage.
Guiding principles
Simpler and closer to existing JavaScript syntax. JSX is an extension of Javascript.
Incorporate less of the html quirks.
What this proposal isn't
No special behavior for control structures like if, else e.g special behavior for <If> tags. JSX semantics should only focus on expressing the tree structure of tags and expressions. The logic structure should be dictated by existing JS syntax e.g ternary x ? y : z and someArray.map to iterate over arrays. When do expressions make it to ES spec, they can focus on more expressive logic semantics.
Concerned with how jsx gets transpiled and emitted. This proposal purely focuses on syntax. i.e no special syntax for event handler binding.
The proposal purely focuses on parser level semantics
#4 - Drop HTML encoding in text and attributes. #21 - Computed attribute names. #23 - Object short hand notation. #25, #51, #64 - Drop the need for curlies around attribute values if they're a single literal, or parenthesis. #35, #8 - Crazy Idea: Deprecate JSXText? #68 - Make JSX even more like JS #7 - Comments in JSXElement #117 - non-breaking changes for attribute values #108 - Computed attribute names #103 - Curly braces for attribute expressions are pointless and ugly #76 - Destructuring #53 - Remove JSXElement from JSXAttributeValue production
The major breaking changes to existing spec
Parens to specify expressions like JS instead of curly braces e.g {...} -> (...)
JSXChildren are either JSXElements, ParensExpression or Literals.
There is no JSXText. No special entity encoding or implicit whitespace to deal with.
Shorthand - <div x y> evaluated like JS object shorthand as <div x=x y=y, instead of current behavior <div x=true y=true>. Maps to JS object syntax: jsx('div', {x, y}).
Spread - <div ...props> instead of current div {...props}. Maps to JS object syntax: jsx('div', {...props})
JSXFragment - Removed: Use x=(<></>) instead of x=<></>
JSXElement - Removed: Use x=(<div/>) instead of x=<div/>. Typescript to-date hasn't support this production. It's support is lacking amongst diffent tools and is needlesly complex. It can be echieved with just two extra characters. See Remove JSXElement from JSXAttributeValue production? #53
ParensExpression: (expr) replaces {expr} as expression syntax since JS already understands (...). For x={{hello:world}}, { has double meaning. The first use is to signify expression, and the next use is the object initializer.
x=((((((1)))))) still means an expression, no matter how many parentheses.
JSXChild
JSXElement | JSXFragment - No changes
JSXText - Removed. Have to use explicit strings instead e.g <div>"Hello World"</div>. Whitespace can be explicitly noted e.g <div> " Hello World " </div>
Literal | TemplateLiteral | Identifier - <div> 1 foobar true null "SomeStr" `Hello ${world}`</div>. Any space separated literals work.
ParensExpression - <div>(user.isLoggedIn() > 0 ? <Login/> : <Home/>)</div> - Replaces {} as the expression with ()
SingleLineComment | MultilineComment - // or /* */
I acknowledge that the old JSX 2.0 proposal (#65) had way too many comments to keep up a discussion and is closed for discussion.
This proposal tries to accomodate many existing issues. It is based on the existing JSX 2.0 proposal by @sebmarkbage.
Guiding principles
What this proposal isn't
No special behavior for control structures like if, else e.g special behavior for
<If>
tags. JSX semantics should only focus on expressing the tree structure of tags and expressions. The logic structure should be dictated by existing JS syntax e.g ternaryx ? y : z
andsomeArray.map
to iterate over arrays. Whendo
expressions make it to ES spec, they can focus on more expressive logic semantics.Concerned with how jsx gets transpiled and emitted. This proposal purely focuses on syntax. i.e no special syntax for event handler binding.
Issues taken into consideration
The proposal purely focuses on parser level semantics
#4 - Drop HTML encoding in text and attributes.
#21 - Computed attribute names.
#23 - Object short hand notation.
#25, #51, #64 - Drop the need for curlies around attribute values if they're a single literal, or parenthesis.
#35, #8 - Crazy Idea: Deprecate JSXText?
#68 - Make JSX even more like JS
#7 - Comments in JSXElement
#117 - non-breaking changes for attribute values
#108 - Computed attribute names
#103 - Curly braces for attribute expressions are pointless and ugly
#76 - Destructuring
#53 - Remove
JSXElement
fromJSXAttributeValue
productionThe major breaking changes to existing spec
{...}
->(...)
JSX Elements
JSXElement remains as is. No changes here.
<div></div>
</br/>
<Context.Provider></Context.Provider>
-<hello:world></hello:world>
<> </>
JSXAttribute
<div x y>
evaluated like JS object shorthand as<div x=x y=y
, instead of current behavior<div x=true y=true>
. Maps to JS object syntax:jsx('div', {x, y})
.<div ...props>
instead of currentdiv {...props}
. Maps to JS object syntax:jsx('div', {...props})
<div ['hello' + 2]='world'>
. Maps to JS object syntaxjsx('div', {['hello' + 2]: 'world'})
x=y
maps to{x:y}
in JS object syntax.JSXAttributeValue
x="hello"
,x='hello'
,x=2
,x=true
,x=null
x=`some ${value}`
x=foo_ba$r23
x=(1+2)
,x=({key: val})
,x=(<div/>)
JSXFragment- Removed: Usex=(<></>)
instead ofx=<></>
JSXElement- Removed: Usex=(<div/>)
instead ofx=<div/>
. Typescript to-date hasn't support this production. It's support is lacking amongst diffent tools and is needlesly complex. It can be echieved with just two extra characters. See RemoveJSXElement
fromJSXAttributeValue
production? #53ParensExpression:
(expr)
replaces{expr}
as expression syntax since JS already understands(...)
. Forx={{hello:world}}
,{
has double meaning. The first use is to signify expression, and the next use is the object initializer.x=((((((1))))))
still means an expression, no matter how many parentheses.JSXChild
JSXText- Removed. Have to use explicit strings instead e.g<div>"Hello World"</div>
. Whitespace can be explicitly noted e.g<div> " Hello World " </div>
<div> 1 foobar true null "SomeStr" `Hello ${world}`</div>
. Any space separated literals work.<div>(user.isLoggedIn() > 0 ? <Login/> : <Home/>)</div>
- Replaces{}
as the expression with()
//
or/* */
Complex Example:
The text was updated successfully, but these errors were encountered: