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 to string could be acheived as a transpiler plugin #4

Open
odinhb opened this issue Mar 12, 2024 · 0 comments
Open

JSX to string could be acheived as a transpiler plugin #4

odinhb opened this issue Mar 12, 2024 · 0 comments

Comments

@odinhb
Copy link
Collaborator

odinhb commented Mar 12, 2024

In these modern times when we commonly transpile our frontend javascript (which we have to do anyway to go from jsx -> h()) we might as well produce template strings or string concatenation code from the JSX/TSX source code instead of calling into a "JSX reviver" like stringjsx at runtime.

The only thing that needs to be shipped at runtime from the stringjsx package would be the sanitization logic.

To illustrate, the transpiler would (in the most basic case) take this:

const userProvidedText = 'i am very smart';
const myHtml = <div>
  <span class="comment-header">Comment</span>
  <p>{userProvidedText}</p>
</div>

and turn it into this:

import { sanitize } from 'stringjsx';

const userProvidedText = 'i am very smart';
let myHtml = '';
myHtml += '<div>';
myHtml += '<span';
myHtml += ' class="comment-header">';
// ... etc snip
myHtml += '<p>' + sanitize(userProvidedText) + '</p>';
myHtml += '</div>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant