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

Improve transform-react-jsx typings #13820

Merged
merged 7 commits into from Oct 7, 2021

Conversation

@JLHwung
Copy link
Contributor

@JLHwung JLHwung commented Oct 6, 2021

Q                       A
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This PR starts by improving typings of transform-react-jsx, the type checker catches unreachable statements in

for (const attr of path.get("attributes")) {
if (!attr.isJSXElement()) continue;
const { name } = attr.node.name;
if (name === "__source" || name === "__self") {
throw path.buildCodeFrameError(
`__source and __self should not be defined in props and are reserved for internal usage.`,
);
}

The guard should have been !attr.isJSXAttribute(). However, since we have already thrown selfSourceError in automatic runtime

if (found[name]) throw sourceSelfError(path, name);

and we allow multiple __self and __source in classical runtime. I think current behavior is ok so we can simply remove the unreachable statements.

This PR also exports a PluginPass type from @babel/core, which can be used by plugin authors.

@babel-bot
Copy link
Collaborator

@babel-bot babel-bot commented Oct 6, 2021

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/49085/

@codesandbox
Copy link

@codesandbox codesandbox bot commented Oct 6, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c487241:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@JLHwung JLHwung marked this pull request as draft Oct 6, 2021
@JLHwung JLHwung force-pushed the improve-transform-react-jsx-typings branch from db5f158 to cca951b Oct 6, 2021
@JLHwung JLHwung marked this pull request as ready for review Oct 6, 2021
packages/babel-core/src/index.ts Outdated Show resolved Hide resolved
hzoo
hzoo approved these changes Oct 7, 2021
@JLHwung JLHwung merged commit c2f747c into babel:main Oct 7, 2021
3 of 6 checks passed
@JLHwung JLHwung deleted the improve-transform-react-jsx-typings branch Oct 7, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants