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(scan): do not match 'export default' in comments #4602

Merged
merged 3 commits into from Aug 16, 2021

Conversation

ygj6
Copy link
Member

@ygj6 ygj6 commented Aug 14, 2021

fix #4598

Description

If the script code happens to contain export default in comments, then export default {} will not be added at the end of line.
Just like the issue #4598 :

<script setup>
import { provide } from 'vue'

// const count = ref(1)
// const plusOne = computed(() => count.value + 1)
// export default {
//     computed: {
//         notification_width: function () {
//             return Math.min(600, Math.max(document.documentElement.clientWidth, window.innerWidth || 0)) || 'px' //fit on mobile
//         }
//     },

</script>

if (!js.includes(`export default`)) {
js += `\nexport default {}`
}

My current solution refers to PR: #4088 . Empty the singleline & multiline comments first, using the code without comments to match.

Additional context

I have considered adding test cases, but meanwhile I noticed that current unit tests are only for regular expressions, so I don't add them at the moment.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@ygj6 ygj6 changed the title fix(scan): No matching 'export default' in comments fix(scan): Not match 'export default' in comments Aug 14, 2021
@Shinigami92 Shinigami92 added p3-minor-bug An edge case that only affects very specific usage (priority) needs test labels Aug 14, 2021
@antfu antfu changed the title fix(scan): Not match 'export default' in comments fix(scan): do not match 'export default' in comments Aug 16, 2021
@antfu antfu merged commit 8b85f5f into vitejs:main Aug 16, 2021
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

error: No matching export in "App.vue" for import "default" caused by commented // export default {
3 participants