Skip to content

Suggestion: output of JSXChildren #31462

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

Closed
5 tasks done
magic-akari opened this issue May 19, 2019 · 6 comments
Closed
5 tasks done

Suggestion: output of JSXChildren #31462

magic-akari opened this issue May 19, 2019 · 6 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@magic-akari
Copy link
Contributor

Search Terms

  • JSX
  • JSXChildren
  • JSX code generation

Suggestion

Therefore, it is better to allow the output of JSXChildren to be configured.

There will of course be a lot more details when we get started for real, but these sketches should give us a rough idea of the design.

We could add an option to tsconfig.json such as compilerOptions.JSXChildren:

compilerOptions.JSXChildren : "classic" | "onechild" | "array"
"classic" "onechild" "array"
what tsc is doing now what React is actually doing what Vue accepts

Use Cases

It will improve compatibility with some JSX libraries.

Examples

input

const App = () => {
    return (
        <div className="app">
            <main>
                <header />
                <section />
                <footer />
            </main>
        </div>
    );
};

compilerOptions.JSXChildren : "classic"

const App = () => {
    return React.createElement(
        "div",
        { className: "app" },
        React.createElement(
            "main",
            null,
            React.createElement("header", null),
            React.createElement("section", null),
            React.createElement("footer", null),
        ),
    );
};

compilerOptions.JSXChildren : "onechild"

const App = () => {
    return React.createElement(
        "div",
        { className: "app" },
        React.createElement("main", null, [
            React.createElement("header", null),
            React.createElement("section", null),
            React.createElement("footer", null),
        ]),
    );
};

compilerOptions.JSXChildren : "array"

const App = () => {
    return React.createElement("div", { className: "app" }, [
        React.createElement("main", null, [
            React.createElement("header", null),
            React.createElement("section", null),
            React.createElement("footer", null),
        ]),
    ]);
};

Please ignore the format style :)

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@magic-akari
Copy link
Contributor Author

For consistency, maybe compilerOptions.jsxChildren is better.

Discussion is welcome.

@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Jun 12, 2019
@RyanCavanaugh
Copy link
Member

We'd probably expose this via a configuration type in the JSX namespace rather than a compiler option (since it's the framework that decides, not the program author). I think React is actually thinking about moving to Vue's behavior anyway.

@magic-akari
Copy link
Contributor Author

Sounds great. But does it mean emitting different JS based on the types of the expressions?

@magic-akari
Copy link
Contributor Author

Related issue #34547

@plusgut
Copy link

plusgut commented Jan 20, 2020

Another related issue #30918
To be able to configure that in the JSX-namespace would be my favorite and would solve lots of issues I have.

@magic-akari
Copy link
Contributor Author

Close issue by #39199 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants