-
Notifications
You must be signed in to change notification settings - Fork 36
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
feat(findExports): use acorn tokenizer to filter false positive exports #56
Conversation
We can also use strip-literal by @antfu. However, downside is that it involves full AST parsing and sloweer. I think this is last tested version based on regex. @antfu Can you please explain finally what were limitations regex couldn't support? Did you migrate unimport for a specific reason or avoiding possible edge cases in the future? |
Here are the cases that regexp can't possibly handle correctly (either incompletely removed, or overkill with quotes unmatched. Context:
In addition:
|
Using export { foobar } from 'foo2'; After export { foobar } from ' '; Expected [{
type: 'named',
exports: ' bar ',
specifier: 'foo2',
code: "export { bar } from 'foo2';",
start: 121,
end: 148,
names: [ 'bar' ]
}] Received [{
type: 'named',
exports: ' bar ',
specifier: undefined,
code: 'export { bar }',
start: 794,
end: 808,
names: [ 'bar' ]
}]
|
I have found that the presence of an export statement in the string also affects the result. example: const test1 = "export { ba1 } from 'foo2'"
const test2 = "testexport { bar2 } from 'foo2'"
const test3 = "test export { bar3 } from 'foo2'"
const test4 = "export { bar4 } from 'foo2' test"
const test5 = \`
test1
export { bar4 } from 'foo2' test
test2
` expected regexp matching is too cumbersome and perhaps AST is an option (but only if performance is accepted). |
Thanks for information @antfu. I guess performance would be reasonable and we can introduce two versions of find* utils for a regex-only extractor when performance/bundle is matter. Can we maybe support a filter function from strip-literal? We want to avoid stripping strings that do not include an import for mlly case. |
While we could do it, I am not sure if there is a good way to detect whether a string should be kept or striped. Since |
@antfu This is a great idea, I've been trying to figure out how to parse and filter out the export statements in the strings all morning and still haven't had a good result. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice changes!
@pi0 Is there any progress on this PR? |
Codecov Report
@@ Coverage Diff @@
## main #56 +/- ##
==========================================
+ Coverage 52.52% 52.89% +0.36%
==========================================
Files 13 13
Lines 2115 2159 +44
Branches 171 179 +8
==========================================
+ Hits 1111 1142 +31
- Misses 842 847 +5
- Partials 162 170 +8
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Thanks for working on this PR @hubvue <3 |
@pi0 I feel very happy to be able to contribute to an open source project. 😄 |
This PR is designed to address this issue #34
example:
The expected length of matches should be "2", but instead we get "17".
'\b' does not solve such problems, its semantics is the junction of words and non-words. Apparently the following code is also semantically correct.
// (\b is here)export { foo } from 'foo1';
Solutions:filter out comments before matching to avoid them affecting the matching process.