Skip to content

Commit

Permalink
fix(import-analysis): escape quotes correctly (#12688)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Apr 1, 2023
1 parent a3150ee commit 1638ebd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,10 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
rewriteDone = true
}
if (!rewriteDone) {
let rewrittenUrl = JSON.stringify(url)
if (!isDynamicImport) rewrittenUrl = rewrittenUrl.slice(1, -1)
str().overwrite(start, end, rewrittenUrl, {
const rewrittenUrl = JSON.stringify(url)
const s = isDynamicImport ? start : start - 1
const e = isDynamicImport ? end : end + 1
str().overwrite(s, e, rewrittenUrl, {
contentOnly: true,
})
}
Expand Down
7 changes: 4 additions & 3 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,10 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
rewriteDone = true
}
if (!rewriteDone) {
let rewrittenUrl = JSON.stringify(file)
if (!isDynamicImport) rewrittenUrl = rewrittenUrl.slice(1, -1)
str().update(start, end, rewrittenUrl)
const rewrittenUrl = JSON.stringify(file)
const s = isDynamicImport ? start : start - 1
const e = isDynamicImport ? end : end + 1
str().update(s, e, rewrittenUrl)
}
}
}
Expand Down

0 comments on commit 1638ebd

Please sign in to comment.