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

refactor: Split analyzer/types/mod.rs #1091

Merged
merged 4 commits into from
Sep 22, 2023
Merged

refactor: Split analyzer/types/mod.rs #1091

merged 4 commits into from
Sep 22, 2023

Conversation

sunrabbit123
Copy link
Collaborator

@sunrabbit123 sunrabbit123 commented Sep 22, 2023

Description:
Separate file about normalize intersection type

and

some code edit

I will show changeset at code review

BREAKING CHANGE:

Related issue (if exists):

@changeset-bot
Copy link

changeset-bot bot commented Sep 22, 2023

⚠️ No Changeset found

Latest commit: c471484

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link

github-actions bot commented Sep 22, 2023

Thank you for the PR!
Commit: c471484

Files to check

These are files which is affected by the current PR, but not reflected. If there's no file below this message, please ignore this message.

You can run ./scripts/auto-unignore.sh from crates/stc_ts_file_analyzer for typescript files, and ./scripts/check.sh from crates/stc_ts_type_checker for *.stats.rust-debug files.

use super::NormalizeTypeOpts;
use crate::{analyzer::Analyzer, VResult};

macro_rules! never {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

first, extract never macro

}

#[inline]
fn enum_variant(span: Span, def: ArcCow<Enum>, name: JsWord) -> Type {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

second, extract feature what generate EnumVariant type

}
for elem in normalized_types.iter() {
if let Type::EnumVariant(ref ev) = elem.normalize() {
match &ev.name {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

3rd, change if let to match expression

self.flat_intersection_type(span, normalized_types)
}

fn flat_intersection_type(&mut self, span: Span, mut normalized_types: Vec<Type>) -> VResult<Option<Type>> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

4th, I split function what flatten intersection type

if let TypeElement::Property(prev) = prev {
if prev.key.type_eq(&p.key) {
let prev_type = prev.type_ann.clone().map(|v| *v).unwrap_or(Type::any(span, Default::default()));
let other = p.type_ann.clone().map(|v| *v).unwrap_or(Type::any(span, Default::default()));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

6th, change method unwrap_or_else to unwrap_or

let prev_type = prev
    .type_ann
    .clone()
    .map(|v| *v)
    .unwrap_or_else(|| Type::any(span,KeywordTypeMetadata { ..Default::default() }));

to

this

@kdy1 kdy1 changed the title refactor: Separate files at analyzer/types/mod.rs refactor: Split analyzer/types/mod.rs Sep 22, 2023
@kdy1 kdy1 changed the title refactor: Split analyzer/types/mod.rs refactor: Split analyzer/types/mod.rs Sep 22, 2023
@kdy1 kdy1 enabled auto-merge (squash) September 22, 2023 22:40
@kdy1 kdy1 merged commit 21a0da5 into dudykr:main Sep 22, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants