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

Transform JSX to string #8326

Closed
Longwelwind opened this issue Apr 27, 2016 · 4 comments
Closed

Transform JSX to string #8326

Longwelwind opened this issue Apr 27, 2016 · 4 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@Longwelwind
Copy link

Longwelwind commented Apr 27, 2016

Hi !

Could it be possible to add a transformer for JSX that outputs a Javascript "normal" string ?
For example, this:

let foo = "Hello world !";
let bar = (
    <div>
        {foo}
    </div>
);

would be transformed to:

let foo = "Hello world";
let test = "<div>" +  foo + "</div>";

I'm not sure if it goes into the scope of the project, since one could use the preserve option and use an additional transpiler, but I think it could help users write components & templates for any library (Vuejs, Ractive, ...), instead of just React.

@basarat
Copy link
Contributor

basarat commented Apr 27, 2016

Could it be possible to add a transformer for JSX that outputs a Javascript "normal" string

You could do it externally and only after the [Transformer] style emitter of the TypeScript is complete.

That said, why not just use a template string? : https://basarat.gitbooks.io/typescript/content/docs/template-strings.html

let bar = (
    `<div>
        ${foo}
    </div>`
);

Also ReactServer.renderToString has a similar outcome 🌹

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Apr 27, 2016
@mikeyoon
Copy link

I wonder if a special transformer could be used for supporting strong typing in AngularJS templates.

@mhegazy
Copy link
Contributor

mhegazy commented Apr 28, 2016

see #5470

@mhegazy mhegazy closed this as completed Apr 28, 2016
@developit
Copy link

@Longwelwind hate to resurrect this issue since it's fairly old now, but it seems like you're looking for vhtml.

@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
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

6 participants