Skip to content

Commit 86404de

Browse files
committed
fix(bundler-utils): parenthesize public path expression
1 parent 77d9b3b commit 86404de

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

packages/bundler-utils/src/generate.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe('bundler-utils', () => {
153153
publicPathExpression: '__webpack_public_path__'
154154
}))
155155

156-
expect(module).toContain('const url = __webpack_public_path__ + "/images/image.jpg";')
156+
expect(module).toContain('const url = (__webpack_public_path__) + "/images/image.jpg";')
157157
})
158158

159159
it('should fall back to the output path url without a public path expression', async () => {

packages/bundler-utils/src/module.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('bundler-utils', () => {
4040
[createEntry('jpg', 320), createEntry('webp', 320), createEntry('webp', 640)]
4141
)
4242

43-
expect(module).toContain('const url = __webpack_public_path__ + "image@320w.webp";')
43+
expect(module).toContain('const url = (__webpack_public_path__) + "image@320w.webp";')
4444
})
4545

4646
it('should select default variant by multiplier', () => {
@@ -52,7 +52,7 @@ describe('bundler-utils', () => {
5252
[createEntry('jpg', 640, 1), createEntry('jpg', 320, 0.5)]
5353
)
5454

55-
expect(module).toContain('const url = __webpack_public_path__ + "image@320w.jpg";')
55+
expect(module).toContain('const url = (__webpack_public_path__) + "image@320w.jpg";')
5656
})
5757

5858
it('should select default variant by id', () => {
@@ -63,7 +63,7 @@ describe('bundler-utils', () => {
6363
[createEntry('jpg', 320), createEntry('webp', 640)]
6464
)
6565

66-
expect(module).toContain('const url = __webpack_public_path__ + "image@640w.webp";')
66+
expect(module).toContain('const url = (__webpack_public_path__) + "image@640w.webp";')
6767
})
6868

6969
it('should fall back to first variant', () => {
@@ -75,7 +75,7 @@ describe('bundler-utils', () => {
7575
[createEntry('jpg', 320), createEntry('webp', 640)]
7676
)
7777

78-
expect(module).toContain('const url = __webpack_public_path__ + "image@320w.jpg";')
78+
expect(module).toContain('const url = (__webpack_public_path__) + "image@320w.jpg";')
7979
})
8080

8181
it('should create empty module without variants', () => {
@@ -140,7 +140,7 @@ describe('bundler-utils', () => {
140140
[createEntry('jpg', 320), createEntry('webp', 640)]
141141
)
142142

143-
expect(module).toContain('"webp640": __webpack_public_path__ + "image@640w.webp"')
143+
expect(module).toContain('"webp640": (__webpack_public_path__) + "image@640w.webp"')
144144
})
145145
})
146146
})

packages/bundler-utils/src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function toUrlExpression(url: string | SrcSetImagePaths) {
3636

3737
const outputPath = JSON.stringify(url.outputPath)
3838

39-
return url.publicPathExpression ? `${url.publicPathExpression} + ${outputPath}` : outputPath
39+
return url.publicPathExpression ? `(${url.publicPathExpression}) + ${outputPath}` : outputPath
4040
}
4141

4242
function findDefaultIndex(select: SrcSetEntrySelect, srcSet: SrcSetModuleEntry[]) {

0 commit comments

Comments
 (0)