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

fix: noUndeclaredVariables no longer errors on this in JSX tags (attempt 2) #2656

Closed
wants to merge 1 commit into from

Conversation

printfn
Copy link
Contributor

@printfn printfn commented Apr 30, 2024

Summary

Attempt 2 at fixing #2636. Relates to #2647.

I've added JsThisExpression as a new child node of AnyJsxElementName/AnyJsxObjectName, and changed the parser to no longer call p.re_lex(JsReLexContext::JsxIdentifier); when encountering a THIS_KW.

@Conaclos

Test Plan

I've added additional tests. It now seems to be correctly turning <this.foo /> into:

                        name: JsxMemberName {
                            object: JsThisExpression {
                                this_token: [email protected] "this" [] [],
                            },
                            dot_token: [email protected] "." [] [],
                            member: JsName {
                                value_token: [email protected] "foo" [] [],
                            },
                        },

@github-actions github-actions bot added A-Linter Area: linter A-Parser Area: parser A-Formatter Area: formatter A-Tooling Area: internal tools L-JavaScript Language: JavaScript and super languages labels Apr 30, 2024
Copy link

codspeed-hq bot commented Apr 30, 2024

CodSpeed Performance Report

Merging #2656 will not alter performance

Comparing printfn:fix-jsx-this-bogus-nodes (9df96ee) with main (520cef0)

Summary

✅ 84 untouched benchmarks

@Conaclos
Copy link
Member

Thanks for the quick PR!

I need some time to think about that: should we add a specific node JsxThis or choose the approach you took, ...

@printfn
Copy link
Contributor Author

printfn commented Apr 30, 2024

I was thinking that it might make sense to try and stick closer to what the JSX gets transformed to.

Input:

<foo />;
<this.foo />;
<foo.bar />;

New JSX transform:

import { jsx as _jsx } from "react/jsx-runtime";
_jsx("foo", {});
_jsx(this.foo, {});
_jsx(foo.bar, {});

Old JSX transform:

import React from 'react';
React.createElement("foo", null);
React.createElement(this.foo, null);
React.createElement(foo.bar, null);

So I think it'd make sense to represent it similar to how this.foo etc. gets represented in normal JS. But there might be other considerations here that I'm missing.

@Conaclos
Copy link
Member

Conaclos commented May 1, 2024

I need some time to think about that: should we add a specific node JsxThis or choose the approach you took, ...

@denbezrukov Any opinion?

@ematipico
Copy link
Member

I think we should keep the CST the same. I checked with Babel, and they do nothing in particular here. Instead, maybe, we should make an exception in our semantic model.

@Conaclos
Copy link
Member

Closing in favor of #2636

@Conaclos Conaclos closed this May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Formatter Area: formatter A-Linter Area: linter A-Parser Area: parser A-Tooling Area: internal tools L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants