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(plugin-vue): add newline character before class components #2933

Merged
merged 1 commit into from Apr 10, 2021

Conversation

ygj6
Copy link
Member

@ygj6 ygj6 commented Apr 10, 2021

Description

fix #2787

This issue is caused by 2900a9a.

var str =  `import { Vue, Options } from "vue-class-component";

export default class ClassComponent extends Vue {
  counter = 0
}`;

After replace, it will become:

import { Vue, Options } from "vue-class-component"class ClassComponent extends Vue {
  counter = 0
}

At first I plan to optimize exportDefaultClassRE expression:

-const exportDefaultClassRE = /(?:(?:^|\n|;)\s*)export\s+default\s+class\s+([\w$]+)/
+const exportDefaultClassRE = /(^|\n|;)\s*export\s+default\s+class\s+([\w$]+)/ 

-script.content.replace(exportDefaultClassRE, `class $1`)
+script.content.replace(exportDefaultClassRE, `$1 class $2`)

the above solution could solve both #2787 and #2277, but I am worried that there are other cases that have not been considered, so I think it is better to add \n before class:

scriptCode = script.content.replace(exportDefaultClassRE, `\nclass $1`)

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.

@Shinigami92 Shinigami92 added the p3-minor-bug An edge case that only affects very specific usage (priority) label Apr 10, 2021
@patak-dev patak-dev merged commit 8fe828e into vitejs:main Apr 10, 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.

Using Class Components without @Options annotation leads to "Transform failed"
3 participants