Skip to content

Commit 0b68831

Browse files
committed
fix: support backquotes
OXC minifier generates backquotes now
1 parent abd2558 commit 0b68831

File tree

9 files changed

+37
-31
lines changed

9 files changed

+37
-31
lines changed

packages/vite/src/node/plugins/css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ export function getEmptyChunkReplacer(
12451245
const emptyChunkRE = new RegExp(
12461246
outputFormat === 'es'
12471247
? `\\bimport\\s*["'][^"']*(?:${emptyChunkFiles})["'];`
1248-
: `(\\b|,\\s*)require\\(\\s*["'][^"']*(?:${emptyChunkFiles})["']\\)(;|,)`,
1248+
: `(\\b|,\\s*)require\\(\\s*["'\`][^"'\`]*(?:${emptyChunkFiles})["'\`]\\)(;|,)`,
12491249
'g',
12501250
)
12511251

packages/vite/src/node/plugins/importAnalysisBuild.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,10 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): [Plugin] {
454454
let url = name
455455
if (!url) {
456456
const rawUrl = code.slice(start, end)
457-
if (rawUrl[0] === `"` && rawUrl[rawUrl.length - 1] === `"`)
457+
if (
458+
(rawUrl[0] === `"` && rawUrl[rawUrl.length - 1] === `"`) ||
459+
(rawUrl[0] === '`' && rawUrl[rawUrl.length - 1] === '`')
460+
)
458461
url = rawUrl.slice(1, -1)
459462
}
460463
if (!url) continue
@@ -531,7 +534,10 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): [Plugin] {
531534
let url = name
532535
if (!url) {
533536
const rawUrl = code.slice(start, end)
534-
if (rawUrl[0] === `"` && rawUrl[rawUrl.length - 1] === `"`)
537+
if (
538+
(rawUrl[0] === `"` && rawUrl[rawUrl.length - 1] === `"`) ||
539+
(rawUrl[0] === '`' && rawUrl[rawUrl.length - 1] === '`')
540+
)
535541
url = rawUrl.slice(1, -1)
536542
}
537543
const deps = new Set<string>()

playground/lib/__tests__/lib.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ describe.runIf(isBuild)('build', () => {
6464
expect(code).not.toMatch('__vitePreload')
6565

6666
// Test that library chunks are hashed
67-
expect(code).toMatch(/await import\("\.\/message-[-\w]{8}.js"\)/)
67+
expect(code).toMatch(/await import\(`\.\/message-[-\w]{8}.js`\)/)
6868
})
6969

7070
test('Library mode does not have any reference to pure CSS chunks', async () => {
7171
const code = readFile('dist/lib/dynamic-import-message.es.mjs')
7272

7373
// Does not import pure CSS chunks and replaced by `Promise.resolve({})` instead
74-
expect(code).not.toMatch(/await import\("\.\/dynamic-[-\w]{8}.js"\)/)
74+
expect(code).not.toMatch(/await import\(`\.\/dynamic-[-\w]{8}.js`\)/)
7575
expect(code).toMatch(/await Promise.resolve\(\{.*\}\)/)
7676
})
7777

playground/worker/__tests__/es/worker-es.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,17 @@ describe.runIf(isBuild)('build', () => {
107107
expect(workerContent).not.toMatch(/import\s*["(]/)
108108
expect(workerContent).not.toMatch(/\bexport\b/)
109109
// chunk
110-
expect(content).toMatch(`new Worker("/es/assets`)
111-
expect(content).toMatch(`new SharedWorker("/es/assets`)
110+
expect(content).toMatch('new Worker(`/es/assets')
111+
expect(content).toMatch('new SharedWorker(`/es/assets')
112112
// inlined worker
113113
expect(content).toMatch(`(self.URL||self.webkitURL).createObjectURL`)
114114
expect(content).toMatch(`self.Blob`)
115115
expect(content).toMatch(
116-
/try\{if\(\w+=\w+&&\(self\.URL\|\|self\.webkitURL\)\.createObjectURL\(\w+\),!\w+\)throw""/,
116+
/try\{if\(\w+=\w+&&\(self\.URL\|\|self\.webkitURL\)\.createObjectURL\(\w+\),!\w+\)throw``/,
117117
)
118118
// inlined shared worker
119119
expect(content).toMatch(
120-
`return new SharedWorker("data:text/javascript;charset=utf-8,"+`,
120+
'return new SharedWorker(`data:text/javascript;charset=utf-8,`+',
121121
)
122122
})
123123

playground/worker/__tests__/iife/worker-iife.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ describe.runIf(isBuild)('build', () => {
9494
expect(workerContent).not.toMatch(`import`)
9595
expect(workerContent).not.toMatch(/\bexport\b/)
9696
// chunk
97-
expect(content).toMatch(`new Worker("/iife/assets`)
98-
expect(content).toMatch(`new SharedWorker("/iife/assets`)
97+
expect(content).toMatch('new Worker(`/iife/assets')
98+
expect(content).toMatch('new SharedWorker(`/iife/assets')
9999
// inlined
100100
expect(content).toMatch(`(self.URL||self.webkitURL).createObjectURL`)
101101
expect(content).toMatch(`self.Blob`)

playground/worker/__tests__/relative-base/worker-relative-base.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ describe.runIf(isBuild)('build', () => {
7878
expect(workerContent).not.toMatch(/import\s*["(]/)
7979
expect(workerContent).not.toMatch(/\bexport\b/)
8080
// chunk
81-
expect(content).toMatch(`new Worker(""+new URL("../worker-entries/`)
82-
expect(content).toMatch(`new SharedWorker(""+new URL("../worker-entries/`)
81+
expect(content).toMatch('new Worker(``+new URL(`../worker-entries/')
82+
expect(content).toMatch('new SharedWorker(``+new URL(`../worker-entries/')
8383
// inlined
8484
expect(content).toMatch(`(self.URL||self.webkitURL).createObjectURL`)
8585
expect(content).toMatch(`self.Blob`)

playground/worker/__tests__/sourcemap-hidden/worker-sourcemap-hidden.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,25 +92,25 @@ describe.runIf(isBuild)('build', () => {
9292

9393
// chunk
9494
expect(content).toMatch(
95-
`new Worker("/iife-sourcemap-hidden/assets/my-worker`,
95+
'new Worker(`/iife-sourcemap-hidden/assets/my-worker',
9696
)
97-
expect(content).toMatch(`new Worker("data:text/javascript;charset=utf-8,"+`)
97+
expect(content).toMatch('new Worker(`data:text/javascript;charset=utf-8,`+')
9898
expect(content).toMatch(
99-
`new Worker("/iife-sourcemap-hidden/assets/possible-ts-output-worker`,
99+
'new Worker(`/iife-sourcemap-hidden/assets/possible-ts-output-worker',
100100
)
101101
expect(content).toMatch(
102-
`new Worker("/iife-sourcemap-hidden/assets/worker-nested-worker`,
102+
'new Worker(`/iife-sourcemap-hidden/assets/worker-nested-worker',
103103
)
104104
expect(content).toMatch(
105-
`new SharedWorker("/iife-sourcemap-hidden/assets/my-shared-worker`,
105+
'new SharedWorker(`/iife-sourcemap-hidden/assets/my-shared-worker',
106106
)
107107

108108
// inlined
109109
expect(content).toMatch(`(self.URL||self.webkitURL).createObjectURL`)
110110
expect(content).toMatch(`self.Blob`)
111111

112112
expect(workerNestedWorkerContent).toMatch(
113-
`new Worker("/iife-sourcemap-hidden/assets/sub-worker`,
113+
'new Worker(`/iife-sourcemap-hidden/assets/sub-worker',
114114
)
115115
})
116116
})

playground/worker/__tests__/sourcemap-inline/worker-sourcemap-inline.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,25 @@ describe.runIf(isBuild)('build', () => {
7373

7474
// chunk
7575
expect(content).toMatch(
76-
`new Worker("/iife-sourcemap-inline/assets/my-worker`,
76+
'new Worker(`/iife-sourcemap-inline/assets/my-worker',
7777
)
78-
expect(content).toMatch(`new Worker("data:text/javascript;charset=utf-8,"+`)
78+
expect(content).toMatch('new Worker(`data:text/javascript;charset=utf-8,`+')
7979
expect(content).toMatch(
80-
`new Worker("/iife-sourcemap-inline/assets/possible-ts-output-worker`,
80+
'new Worker(`/iife-sourcemap-inline/assets/possible-ts-output-worker',
8181
)
8282
expect(content).toMatch(
83-
`new Worker("/iife-sourcemap-inline/assets/worker-nested-worker`,
83+
'new Worker(`/iife-sourcemap-inline/assets/worker-nested-worker',
8484
)
8585
expect(content).toMatch(
86-
`new SharedWorker("/iife-sourcemap-inline/assets/my-shared-worker`,
86+
'new SharedWorker(`/iife-sourcemap-inline/assets/my-shared-worker',
8787
)
8888

8989
// inlined
9090
expect(content).toMatch(`(self.URL||self.webkitURL).createObjectURL`)
9191
expect(content).toMatch(`self.Blob`)
9292

9393
expect(workerNestedWorkerContent).toMatch(
94-
`new Worker("/iife-sourcemap-inline/assets/sub-worker`,
94+
'new Worker(`/iife-sourcemap-inline/assets/sub-worker',
9595
)
9696
})
9797
})

playground/worker/__tests__/sourcemap/worker-sourcemap.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,24 @@ describe.runIf(isBuild)('build', () => {
9494
expect(sharedWorkerContent).not.toMatch(`export`)
9595

9696
// chunk
97-
expect(content).toMatch(`new Worker("/iife-sourcemap/assets/my-worker`)
98-
expect(content).toMatch(`new Worker("data:text/javascript;charset=utf-8,"+`)
97+
expect(content).toMatch('new Worker(`/iife-sourcemap/assets/my-worker')
98+
expect(content).toMatch('new Worker(`data:text/javascript;charset=utf-8,`+')
9999
expect(content).toMatch(
100-
`new Worker("/iife-sourcemap/assets/possible-ts-output-worker`,
100+
'new Worker(`/iife-sourcemap/assets/possible-ts-output-worker',
101101
)
102102
expect(content).toMatch(
103-
`new Worker("/iife-sourcemap/assets/worker-nested-worker`,
103+
'new Worker(`/iife-sourcemap/assets/worker-nested-worker',
104104
)
105105
expect(content).toMatch(
106-
`new SharedWorker("/iife-sourcemap/assets/my-shared-worker`,
106+
'new SharedWorker(`/iife-sourcemap/assets/my-shared-worker',
107107
)
108108

109109
// inlined
110110
expect(content).toMatch(`(self.URL||self.webkitURL).createObjectURL`)
111111
expect(content).toMatch(`self.Blob`)
112112

113113
expect(workerNestedWorkerContent).toMatch(
114-
`new Worker("/iife-sourcemap/assets/sub-worker`,
114+
'new Worker(`/iife-sourcemap/assets/sub-worker',
115115
)
116116
})
117117
})

0 commit comments

Comments
 (0)