From 1638ebd655f44020e95d7a4147191a935cc5facb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Sun, 2 Apr 2023 08:09:11 +0900 Subject: [PATCH] fix(import-analysis): escape quotes correctly (#12688) --- packages/vite/src/node/plugins/importAnalysis.ts | 7 ++++--- packages/vite/src/node/plugins/importAnalysisBuild.ts | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysis.ts b/packages/vite/src/node/plugins/importAnalysis.ts index 0c41d7791ecf0e..acd85a1402aa2a 100644 --- a/packages/vite/src/node/plugins/importAnalysis.ts +++ b/packages/vite/src/node/plugins/importAnalysis.ts @@ -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, }) } diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index 0f49bb44d10b71..8913ff5970dbc9 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -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) } } }