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: import order #459

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

fix: import order #459

wants to merge 4 commits into from

Conversation

shaodahong
Copy link
Contributor

@shaodahong shaodahong commented Jun 4, 2020

Resolve #423

@shaodahong shaodahong changed the title [WIP] fix: import order fix: import order Jun 5, 2020
@afc163 afc163 requested a review from sorrycc September 2, 2020 14:45
@afc163
Copy link
Contributor

afc163 commented Sep 2, 2020

@sorrycc 看看这个。

}
}

Property(path, state) {
Copy link
Member

Choose a reason for hiding this comment

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

这些为啥删了?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

统一都在 ImportDeclaration 处理掉了

Copy link
Member

Choose a reason for hiding this comment

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

那就是按 import 来算,而不是按使用来算,那和之前的逻辑不一样了吧,比如 import * as antd from antd, <antd.Button /> 这种逻辑还能覆盖吗?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这种 import 在 ImportDeclaration 确实处理不到, 但是属于 MemberExpression,所以 MemberExpression 保留了

Copy link
Member

Choose a reason for hiding this comment

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

只有 MemberExpression 不够,之前加的东西都是有场景用上的。

Copy link
Member

Choose a reason for hiding this comment

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

我觉得解这个问题的思路应该是记录删除的 import 的位置,然后再在相应的位置加回去。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

以前的思路是找到使用的地方然后 remove -> unshift,现在 babel 提供了 replace refactor 的工具函数 replaceWithMultiple ,改掉 import 那么作用域的内的都会替换

只有 MemberExpression 不够,之前加的东西都是有场景用上的。

跑完测试感觉是没什么大问题的,可能以前的一些修改没加测试用例就不好说

@sorrycc sorrycc mentioned this pull request Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

break imports order
3 participants