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(import-analysis): escape quotes #9729

Merged
merged 2 commits into from Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
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
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
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
@@ -0,0 +1 @@
export const msg = 'single-quote'