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(vite-import): fix the issue of escaping comment code in on-demand packaging plugin #2726

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internals/vue-vite-import/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ const transformDefaultImport = (matchRes: string, opt: PluginInnerOption) => {
return `import ${matchRes} from '${importName}'`
}

// 排除注释代码
const getCompRegExp = (libraryName: any) =>
new RegExp(`import\\s+?{*([\\w ,\\s]+)}*\\s+?from\\s+?('|")${libraryName}('|")`, 'g')
new RegExp(`(?<!//\\s*)import\\s+?{*([\\w ,\\s]+)}*\\s+?from\\s+?('|")${libraryName}('|")`, 'g')

Choose a reason for hiding this comment

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

The updated regular expression now correctly excludes lines that are comments from being matched as import statements. This change prevents potential issues where commented-out code could be mistakenly processed, leading to errors in the on-demand packaging plugin.


function transformCode(code: string, plgOptions: PluginInnerOptions): string {
let resultCode = code
Expand Down
Loading