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

Customizable JSX/TSX mode #5546

Closed
Deathspike opened this issue Nov 6, 2015 · 5 comments
Closed

Customizable JSX/TSX mode #5546

Deathspike opened this issue Nov 6, 2015 · 5 comments
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@Deathspike
Copy link

We currently have two jsx modes, preserve and react. Using preserve leaves the <Something /> for an additional compilation step, and react ties you into using the React library. I want to propose a compiler option which allows you to define the emitted types. For example setting:

"jsx": {createElement: "el"}

Which would transform this code:

let test = <div><span /><span /></div>;

Into this result:

var test = el("div", null, el("span", null), el("span", null));

Essentially, replacing React.createElement with el. Now I can define an el function like:

(name: string, properties: {[key: string]: string}, ...children: MyElement[]) => MyElement

To implement an own library. Why? Because some of us don't like being forced into using React, and this would allow us to either create our own libraries or use an existing DSL such as virtual-hyperscript (perhaps with some minor modifications there).

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Nov 6, 2015
@Lenne231
Copy link

There are more and more frameworks using JSX coming up, i.e. https://github.com/garbles/yolk. So this would be very useful.

@bungcip
Copy link

bungcip commented Jan 13, 2016

Yes, I want this feature. However, not all library have same convention like react. So, simple renaming createElement to "el" name like @Deathspike example will not work for some library.

msx (https://github.com/insin/msx) will transform

<div id="example">
  <h1>Test</h1>
  <Uploader onchange={ctrl.files}/>
  <my-element name="test"/>
</div>

to like this.

{tag: "div", attrs: {id:"example"}, children: [
  m.component(Uploader, {onchange:ctrl.files}),
  {tag: "h1", attrs: {}, children: ["Test"]},
  {tag: "my-element", attrs: {name:"test"}}
]}

@basarat
Copy link
Contributor

basarat commented Jan 13, 2016

@bungcip : As a quick workaround you can wrap the JSX -> React.createElement generated js with another runtime javascript function that returns an object literal of the desired structure (or am I wrong?) 🌹

@mhegazy
Copy link
Contributor

mhegazy commented Jan 13, 2016

To follow up on this issue. this issue has been discussed

@mhegazy
Copy link
Contributor

mhegazy commented Jan 13, 2016

sorry hit comment too soon.

this issue has been discussed in #3788. you can find the current decesion at: #6146 (comment)

with #6146, --reactNamespace option allows you to define alternative JSX factories to React.

anything more involved will need to wait for #5595.

this issue seems to be a duplicate of #3788 and is fixed by #6146 now.

@mhegazy mhegazy closed this as completed Jan 13, 2016
@mhegazy mhegazy added Duplicate An existing issue was already created and removed In Discussion Not yet reached consensus labels Jan 13, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants