Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_js_semantic): simple globals resolution #3354

Merged
merged 2 commits into from
Oct 6, 2022

Conversation

xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Oct 6, 2022

Summary

This PR implements a simple global resolution for the semantic model.

Test Plan

> cargo test -p rome_js_semantic -- ok_semantic_model_globals

@netlify
Copy link

netlify bot commented Oct 6, 2022

Deploy Preview for rometools canceled.

Name Link
🔨 Latest commit fc47db9
🔍 Latest deploy log https://app.netlify.com/sites/rometools/deploys/633eea0cf005a30008a5c797

@xunilrj xunilrj temporarily deployed to netlify-playground October 6, 2022 14:45 Inactive
@xunilrj xunilrj changed the title Feature/semantic model globals feat(rome_js_semantic): simple globals resolution Oct 6, 2022
@github-actions
Copy link

github-actions bot commented Oct 6, 2022

@@ -1041,7 +1109,7 @@ mod test {
FileId::zero(),
SourceType::js_module(),
);
let model = semantic_model(&r.tree());
let model = semantic_model(&r.tree(), SemanticModelOptions::default());
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we fill the globals with the ones that we have inside globals/mod.rs? At least with the ones we use inside noUndeclaredVariables.

And maybe, while we are at it, we can change the rule to use the new API, so we know it works 100%

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shouldn't we fill the globals with the ones that we have inside globals/mod.rs?

Yes, but it should be done at crates\rome_js_analyze\src\lib.rs:76 where you have info from the file being analyzed and can choose the globals.

#[derive(Default)]
/// Extra options for the [SemanticModel] creation.
pub struct SemanticModelOptions {
/// All the allowed globals names
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// All the allowed globals names
/// All the allowed global names

/// Extra options for the [SemanticModel] creation.
pub struct SemanticModelOptions {
/// All the allowed globals names
pub globals: HashSet<String>,
Copy link
Contributor

Choose a reason for hiding this comment

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

How does HashSet compare in performance against using a pre-sorted Vec of strings and a binary search ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer to merge this like it is, and we can bench in a real case later. I did a similar test while ago tough: #2975

@xunilrj xunilrj merged commit 879811c into main Oct 6, 2022
@xunilrj xunilrj deleted the feature/semantic-model-globals branch October 6, 2022 19:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants