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(linter): jsx no undef match scope should check with ancestors #2027

Merged
merged 1 commit into from
Jan 27, 2024
Merged

fix(linter): jsx no undef match scope should check with ancestors #2027

merged 1 commit into from
Jan 27, 2024

Conversation

xxleyi
Copy link
Contributor

@xxleyi xxleyi commented Jan 14, 2024

when check undef in jsx-no-undef rule, the match one should be scope of current jsx or the ancestors scope of current jsx. cause I just begin to learn rust, I am not sure the code style and performance can be better, if there is any, I would change

@github-actions github-actions bot added A-linter Area - Linter A-semantic Area - Semantic labels Jan 14, 2024
@xxleyi xxleyi marked this pull request as ready for review January 16, 2024 00:53
@xxleyi xxleyi changed the title fix(lint): jsx no undef match scope should check with ancestors fix(linter): jsx no undef match scope should check with ancestors Jan 16, 2024
@Boshen Boshen requested a review from camc314 January 16, 2024 04:47
Copy link

codspeed-hq bot commented Jan 16, 2024

CodSpeed Performance Report

Merging #2027 will not alter performance

⚠️ No base runs were found

Falling back to comparing xxleyi:fix-lint-jsx-no-undef (880b46f) with main (ab8a311)

Summary

✅ 17 untouched benchmarks

@Boshen Boshen requested a review from Dunqing January 17, 2024 03:24
@Boshen
Copy link
Member

Boshen commented Jan 17, 2024

I'm not sure whether enumerating the symbol table is a good idea, @Dunqing can you double check and find a better way?

@Dunqing
Copy link
Member

Dunqing commented Jan 17, 2024

If too many symbols with the same name in the symbol table, enumerating the symbol table will affect performance. Instead, we should need to access the ancestor of the node's scope_id.

Look like this

for scope_id in ctx.scopes().ancestors(jsx_scope_id) {
    if ctx.scopes().has_binding(scope_id, &ident.name) {
        return;
    }
}
ctx.diagnostic(JsxNoUndefDiagnostic(ident.name.clone(), ident.span));

Usually, the Component is defined or imported from other files in the root scope, So we can do a small optimization by checking if the binding is present in the root scope first.

Also, your test case is incorrect, the App variable is defined in terms of var, so the App variable can be accessed after { var App; }.

var React; { var App; }; React.render(<App />);

You should change the var App; to let App;

@xxleyi

This comment was marked as outdated.

@xxleyi
Copy link
Contributor Author

xxleyi commented Jan 27, 2024

If too many symbols with the same name in the symbol table, enumerating the symbol table will affect performance. Instead, we should need to access the ancestor of the node's scope_id.

Look like this

for scope_id in ctx.scopes().ancestors(jsx_scope_id) {
    if ctx.scopes().has_binding(scope_id, &ident.name) {
        return;
    }
}
ctx.diagnostic(JsxNoUndefDiagnostic(ident.name.clone(), ident.span));

Usually, the Component is defined or imported from other files in the root scope, So we can do a small optimization by checking if the binding is present in the root scope first.

Also, your test case is incorrect, the App variable is defined in terms of var, so the App variable can be accessed after { var App; }.

var React; { var App; }; React.render(<App />);

You should change the var App; to let App;

Oh, I got your explanation, will change my PR.

Copy link
Member

@Dunqing Dunqing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@Dunqing Dunqing merged commit f32228e into oxc-project:main Jan 27, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter A-semantic Area - Semantic
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants