Skip to content

Conversation

@kamijin-fanta
Copy link
Member

@kamijin-fanta kamijin-fanta commented Feb 1, 2019

I am a beginner in rust language. I tried writing it.

ref #82

@maciejhirsz
Copy link
Member

maciejhirsz commented Mar 1, 2019

Hey @kamijin-fanta! Sorry for not picking this up sooner, I'll review asap.

Copy link
Member

@maciejhirsz maciejhirsz left a comment

Choose a reason for hiding this comment

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

This looks pretty cool! I'll try to make suggestions as a PR back to your branch.

return
}

for spec in self.specifiers {
Copy link
Member

Choose a reason for hiding this comment

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

There is probably a way to make this more DRY.

Could try using gen.write_list here with a filter or filter_map iterators if the inner types got ToCode implemented for them. This would also avoid having to keep track of the tail boolean, which seems like an easy thing to get wrong if this ever gets refactored.

Copy link
Member Author

@kamijin-fanta kamijin-fanta Mar 6, 2019

Choose a reason for hiding this comment

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

gen.write_list does not seem to accept Vec<ForImportSpecifier>.
How can I implement it?

I thought of such a code.

let specs = self.specifiers.iter().filter_map(|spec| { match spec.item { ForImportSpecifier::ImportDefaultSpecifier(_) | ForImportSpecifier::ImportNamespaceSpecifier(_) => Some(spec.item), _ => None } }).collect::<Vec<_>>(); gen.write_list(specs);
Copy link
Member

Choose a reason for hiding this comment

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

write_list operates on IntoInterator types, so you can skip collecting to Vec part:

let specs = self.specifiers.iter().filter_map(|spec| { match spec.item { ForImportSpecifier::ImportDefaultSpecifier(_) | ForImportSpecifier::ImportNamespaceSpecifier(_) => Some(spec.item), _ => None } }); gen.write_list(specs);
}
}
let mut need_close = false;
for spec in self.specifiers {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto about this loop, though here it's a bit more complicated due to the opening and closing brace. I'll write some suggestions for the code.

S: Serializer,
{
self.in_loc(serializer, "ImportDeclaration", 1, |state| {
// state.serialize_field("specifiers", &self.specifiers)?;
Copy link
Member

Choose a reason for hiding this comment

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

Seems like stale code? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm sorry. I forgot to implement astgen. I implemented it now.

@kamijin-fanta
Copy link
Member Author

I did rewrite it to using write_list.
It became code to use filter and collect to refer to length.

@kamijin-fanta
Copy link
Member Author

@maciejhirsz Is there anything I can do? I want to support this project through PR.

@maciejhirsz maciejhirsz merged commit e55a131 into ratel-rust:master Dec 17, 2019
@maciejhirsz
Copy link
Member

@kamijin-fanta I haven't worked on this for a very long time now. Would you like to be added to the organization so you can do PRs without approval?

@kamijin-fanta
Copy link
Member Author

@maciejhirsz Thank you for the merge! It is nice idea! But I can't make much time like you...

@maciejhirsz
Copy link
Member

Sent you an invite. It's better if someone works on this, even if just with a tiny amount of tine, than for this repo to sit here stale :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants