Skip to content

Commit

Permalink
fix(import-analysis): escape quotes (#9729)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Aug 18, 2022
1 parent d04784b commit 21515f1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,9 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
rewriteDone = true
}
if (!rewriteDone) {
str().overwrite(start, end, isDynamicImport ? `'${url}'` : url, {
let rewrittenUrl = JSON.stringify(url)
if (!isDynamicImport) rewrittenUrl = rewrittenUrl.slice(1, -1)
str().overwrite(start, end, rewrittenUrl, {
contentOnly: true
})
}
Expand Down
13 changes: 5 additions & 8 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,11 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
rewriteDone = true
}
if (!rewriteDone) {
str().overwrite(
start,
end,
isDynamicImport ? `'${file}'` : file,
{
contentOnly: true
}
)
let rewrittenUrl = JSON.stringify(file)
if (!isDynamicImport) rewrittenUrl = rewrittenUrl.slice(1, -1)
str().overwrite(start, end, rewrittenUrl, {
contentOnly: true
})
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions playground/glob-import/__tests__/glob-import.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const filteredResult = {
},
'./foo.js': {
msg: 'foo'
},
"./quote'.js": {
msg: 'single-quote'
}
}

Expand Down Expand Up @@ -62,6 +65,9 @@ const allResult = {
'../baz.json': json
},
msg: 'bar'
},
"/dir/quote'.js": {
msg: 'single-quote'
}
}

Expand Down
1 change: 1 addition & 0 deletions playground/glob-import/dir/quote'.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const msg = 'single-quote'

0 comments on commit 21515f1

Please sign in to comment.