-
Notifications
You must be signed in to change notification settings - Fork 26
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(dts): transform vue script setup if no type-only macros #210
base: main
Are you sure you want to change the base?
feat(dts): transform vue script setup if no type-only macros #210
Conversation
Would you be able to look at the failing test? π |
Codecov ReportAll modified and coverable lines are covered by tests β
Additional details and impacted files@@ Coverage Diff @@
## main #210 +/- ##
==========================================
- Coverage 82.86% 74.50% -8.37%
==========================================
Files 12 12
Lines 852 753 -99
Branches 133 147 +14
==========================================
- Hits 706 561 -145
- Misses 144 190 +46
Partials 2 2 β View full report in Codecov by Sentry. |
src/loaders/vue.ts
Outdated
return false; | ||
} | ||
|
||
const CODE_COMMENT_RE = /\/\/.*\n|\/\*[\S\s]*?\*\//g; |
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.
Perhaps we could use strip-literal
?
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.
I am not sure if that would increase the accuracy. But, it will be slower as it will have to parse the whole document first.
So, if performance is not really a concern and/or accuracy is more important, then I think using js-tokens
would be better. strip-literal
uses js-tokens
to filter the comment and literal related stuff. We would use it to check for identifiers(the macro names in this case). Since it's iterator-based, we won't have to parse the whole document when there is a macro. So, it will be better in terms of performance compared to strip-literal
. It would also simplify the code as we would no longer need regexes.
Please let me know if we should keep it like this or go with the js-tokens
approach.
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.
sure - let's use js-tokens
then!
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.
Done π Just to give a rough statistic, executing the exclude
method went from ~0.1ms to ~1ms on my machine(Apple M1).
π Linked issue
Resolves #209
β Type of change
π Description
Some macros in
<script setup>
have a type-only variant:defineProps
defineEmits
defineSlots
defineModel
As long as their type-only variant is NOT used, they can safely be transformed into JS. So, this PR improves the exclusion logic to exclude
<script setup>
only if the file contains some type-only macro usage.π Checklist