Skip to content

Commit eba9b42

Browse files
bluwygtm-nayanjulienv3sapphi-red
authored
chore: cherry pick more v4 bug fixes to v3 (#11189)
* fix: glob import parsing (#10949) (#11056) closes #10949 closes #11051 * fix: import.meta.env and process.env undefined variable replacement (fix #8663) (#10958) Co-authored-by: bluwy <[email protected]> fix #8663 * fix(esbuild): handle inline sourcemap option (#11120) * fix(importGlob): preserve line count for sourcemap (#11122) * fix: Dev SSR dep optimization + respect optimizeDeps.include (#11123) * fix: reset global regex before match (#11132) * chore: fix test Co-authored-by: gtmnayan <[email protected]> Co-authored-by: julienv3 <[email protected]> Co-authored-by: 翠 / green <[email protected]>
1 parent c93a526 commit eba9b42

File tree

20 files changed

+219
-53
lines changed

20 files changed

+219
-53
lines changed

package.json

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@
121121
"peerDependencies": {
122122
"postcss": "*"
123123
}
124+
},
125+
"acorn-walk": {
126+
"peerDependencies": {
127+
"acorn": "*"
128+
}
124129
}
125130
}
126131
}

packages/vite/LICENSE.md

+29
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,35 @@ Repository: https://github.com/acornjs/acorn.git
566566
567567
---------------------------------------
568568

569+
## acorn-walk
570+
License: MIT
571+
By: Marijn Haverbeke, Ingvar Stepanyan, Adrian Heine
572+
Repository: https://github.com/acornjs/acorn.git
573+
574+
> MIT License
575+
>
576+
> Copyright (C) 2012-2020 by various contributors (see AUTHORS)
577+
>
578+
> Permission is hereby granted, free of charge, to any person obtaining a copy
579+
> of this software and associated documentation files (the "Software"), to deal
580+
> in the Software without restriction, including without limitation the rights
581+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
582+
> copies of the Software, and to permit persons to whom the Software is
583+
> furnished to do so, subject to the following conditions:
584+
>
585+
> The above copyright notice and this permission notice shall be included in
586+
> all copies or substantial portions of the Software.
587+
>
588+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
589+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
590+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
591+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
592+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
593+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
594+
> THE SOFTWARE.
595+
596+
---------------------------------------
597+
569598
## ansi-regex
570599
License: MIT
571600
By: Sindre Sorhus

packages/vite/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"@rollup/plugin-typescript": "^8.5.0",
8080
"@rollup/pluginutils": "^4.2.1",
8181
"acorn": "^8.8.1",
82+
"acorn-walk": "^8.2.0",
8283
"cac": "^6.7.14",
8384
"chokidar": "^3.5.3",
8485
"connect": "^3.7.0",

packages/vite/src/client/overlay.ts

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export class ErrorOverlay extends HTMLElement {
178178
} else {
179179
let curIndex = 0
180180
let match: RegExpExecArray | null
181+
fileRE.lastIndex = 0
181182
while ((match = fileRE.exec(text))) {
182183
const { 0: file, index } = match
183184
if (index != null) {

packages/vite/src/node/__tests__/plugins/esbuild.spec.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { describe, expect, test } from 'vitest'
22
import type { ResolvedConfig, UserConfig } from '../../config'
3-
import { resolveEsbuildTranspileOptions } from '../../plugins/esbuild'
3+
import {
4+
ESBuildTransformResult,
5+
resolveEsbuildTranspileOptions,
6+
transformWithEsbuild
7+
} from '../../plugins/esbuild'
48

59
describe('resolveEsbuildTranspileOptions', () => {
610
test('resolve default', () => {
@@ -230,6 +234,16 @@ describe('resolveEsbuildTranspileOptions', () => {
230234
})
231235
})
232236

237+
describe('transformWithEsbuild', () => {
238+
test('not throw on inline sourcemap', async () => {
239+
const result = await transformWithEsbuild(`const foo = 'bar'`, '', {
240+
sourcemap: 'inline'
241+
})
242+
expect(result?.code).toBeTruthy()
243+
expect(result?.map).toBeTruthy()
244+
})
245+
})
246+
233247
/**
234248
* Helper for `resolveEsbuildTranspileOptions` to created resolved config with types.
235249
* Note: The function only uses `build.target`, `build.minify` and `esbuild` options.

packages/vite/src/node/__tests__/plugins/importGlob/__snapshots__/fixture.test.ts.snap

+84-22
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,100 @@
33
exports[`fixture > transform 1`] = `
44
"import * as __vite_glob_1_0 from \\"./modules/a.ts\\";import * as __vite_glob_1_1 from \\"./modules/b.ts\\";import * as __vite_glob_1_2 from \\"./modules/index.ts\\";import { name as __vite_glob_3_0 } from \\"./modules/a.ts\\";import { name as __vite_glob_3_1 } from \\"./modules/b.ts\\";import { name as __vite_glob_3_2 } from \\"./modules/index.ts\\";import { default as __vite_glob_5_0 } from \\"./modules/a.ts?raw\\";import { default as __vite_glob_5_1 } from \\"./modules/b.ts?raw\\";import \\"types/importMeta\\";
55
export const basic = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"),\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\")});
6-
export const basicEager = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": __vite_glob_1_0,\\"./modules/b.ts\\": __vite_glob_1_1,\\"./modules/index.ts\\": __vite_glob_1_2});
6+
export const basicEager = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": __vite_glob_1_0,\\"./modules/b.ts\\": __vite_glob_1_1,\\"./modules/index.ts\\": __vite_glob_1_2
7+
8+
});
79
export const ignore = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\")});
8-
export const namedEager = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": __vite_glob_3_0,\\"./modules/b.ts\\": __vite_glob_3_1,\\"./modules/index.ts\\": __vite_glob_3_2});
9-
export const namedDefault = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\").then(m => m[\\"default\\"]),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\").then(m => m[\\"default\\"]),\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\").then(m => m[\\"default\\"])});
10-
export const eagerAs = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": __vite_glob_5_0,\\"./modules/b.ts\\": __vite_glob_5_1});
11-
export const rawImportModule = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts?raw\\"),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts?raw\\")});
12-
export const excludeSelf = /* #__PURE__ */ Object.assign({\\"./sibling.ts\\": () => import(\\"./sibling.ts\\")});
10+
export const namedEager = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": __vite_glob_3_0,\\"./modules/b.ts\\": __vite_glob_3_1,\\"./modules/index.ts\\": __vite_glob_3_2
11+
12+
13+
});
14+
export const namedDefault = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\").then(m => m[\\"default\\"]),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\").then(m => m[\\"default\\"]),\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\").then(m => m[\\"default\\"])
15+
16+
});
17+
export const eagerAs = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": __vite_glob_5_0,\\"./modules/b.ts\\": __vite_glob_5_1
18+
19+
20+
});
21+
export const rawImportModule = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts?raw\\"),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts?raw\\")
22+
23+
24+
});
25+
export const excludeSelf = /* #__PURE__ */ Object.assign({\\"./sibling.ts\\": () => import(\\"./sibling.ts\\")
26+
27+
});
1328
export const customQueryString = /* #__PURE__ */ Object.assign({\\"./sibling.ts\\": () => import(\\"./sibling.ts?custom\\")});
14-
export const customQueryObject = /* #__PURE__ */ Object.assign({\\"./sibling.ts\\": () => import(\\"./sibling.ts?foo=bar&raw=true\\")});
15-
export const parent = /* #__PURE__ */ Object.assign({});
16-
export const rootMixedRelative = /* #__PURE__ */ Object.assign({\\"/css.spec.ts\\": () => import(\\"../../css.spec.ts?url\\").then(m => m[\\"default\\"]),\\"/define.spec.ts\\": () => import(\\"../../define.spec.ts?url\\").then(m => m[\\"default\\"]),\\"/esbuild.spec.ts\\": () => import(\\"../../esbuild.spec.ts?url\\").then(m => m[\\"default\\"]),\\"/import.spec.ts\\": () => import(\\"../../import.spec.ts?url\\").then(m => m[\\"default\\"]),\\"/importGlob/fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts?url\\").then(m => m[\\"default\\"]),\\"/importGlob/fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts?url\\").then(m => m[\\"default\\"]),\\"/importGlob/fixture-b/index.ts\\": () => import(\\"../fixture-b/index.ts?url\\").then(m => m[\\"default\\"])});
17-
export const cleverCwd1 = /* #__PURE__ */ Object.assign({\\"./node_modules/framework/pages/hello.page.js\\": () => import(\\"./node_modules/framework/pages/hello.page.js\\")});
18-
export const cleverCwd2 = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"),\\"../fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts\\"),\\"../fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts\\")});
29+
export const customQueryObject = /* #__PURE__ */ Object.assign({\\"./sibling.ts\\": () => import(\\"./sibling.ts?foo=bar&raw=true\\")
30+
31+
32+
33+
34+
});
35+
export const parent = /* #__PURE__ */ Object.assign({
36+
37+
});
38+
export const rootMixedRelative = /* #__PURE__ */ Object.assign({\\"/css.spec.ts\\": () => import(\\"../../css.spec.ts?url\\").then(m => m[\\"default\\"]),\\"/define.spec.ts\\": () => import(\\"../../define.spec.ts?url\\").then(m => m[\\"default\\"]),\\"/esbuild.spec.ts\\": () => import(\\"../../esbuild.spec.ts?url\\").then(m => m[\\"default\\"]),\\"/import.spec.ts\\": () => import(\\"../../import.spec.ts?url\\").then(m => m[\\"default\\"]),\\"/importGlob/fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts?url\\").then(m => m[\\"default\\"]),\\"/importGlob/fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts?url\\").then(m => m[\\"default\\"]),\\"/importGlob/fixture-b/index.ts\\": () => import(\\"../fixture-b/index.ts?url\\").then(m => m[\\"default\\"])
39+
40+
41+
});
42+
export const cleverCwd1 = /* #__PURE__ */ Object.assign({\\"./node_modules/framework/pages/hello.page.js\\": () => import(\\"./node_modules/framework/pages/hello.page.js\\")
43+
44+
});
45+
export const cleverCwd2 = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"),\\"../fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts\\"),\\"../fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts\\")
46+
47+
48+
49+
});
1950
"
2051
`;
2152

2253
exports[`fixture > transform with restoreQueryExtension 1`] = `
2354
"import * as __vite_glob_1_0 from \\"./modules/a.ts\\";import * as __vite_glob_1_1 from \\"./modules/b.ts\\";import * as __vite_glob_1_2 from \\"./modules/index.ts\\";import { name as __vite_glob_3_0 } from \\"./modules/a.ts\\";import { name as __vite_glob_3_1 } from \\"./modules/b.ts\\";import { name as __vite_glob_3_2 } from \\"./modules/index.ts\\";import { default as __vite_glob_5_0 } from \\"./modules/a.ts?raw\\";import { default as __vite_glob_5_1 } from \\"./modules/b.ts?raw\\";import \\"types/importMeta\\";
2455
export const basic = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"),\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\")});
25-
export const basicEager = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": __vite_glob_1_0,\\"./modules/b.ts\\": __vite_glob_1_1,\\"./modules/index.ts\\": __vite_glob_1_2});
56+
export const basicEager = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": __vite_glob_1_0,\\"./modules/b.ts\\": __vite_glob_1_1,\\"./modules/index.ts\\": __vite_glob_1_2
57+
58+
});
2659
export const ignore = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\")});
27-
export const namedEager = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": __vite_glob_3_0,\\"./modules/b.ts\\": __vite_glob_3_1,\\"./modules/index.ts\\": __vite_glob_3_2});
28-
export const namedDefault = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\").then(m => m[\\"default\\"]),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\").then(m => m[\\"default\\"]),\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\").then(m => m[\\"default\\"])});
29-
export const eagerAs = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": __vite_glob_5_0,\\"./modules/b.ts\\": __vite_glob_5_1});
30-
export const rawImportModule = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts?raw\\"),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts?raw\\")});
31-
export const excludeSelf = /* #__PURE__ */ Object.assign({\\"./sibling.ts\\": () => import(\\"./sibling.ts\\")});
60+
export const namedEager = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": __vite_glob_3_0,\\"./modules/b.ts\\": __vite_glob_3_1,\\"./modules/index.ts\\": __vite_glob_3_2
61+
62+
63+
});
64+
export const namedDefault = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\").then(m => m[\\"default\\"]),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\").then(m => m[\\"default\\"]),\\"./modules/index.ts\\": () => import(\\"./modules/index.ts\\").then(m => m[\\"default\\"])
65+
66+
});
67+
export const eagerAs = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": __vite_glob_5_0,\\"./modules/b.ts\\": __vite_glob_5_1
68+
69+
70+
});
71+
export const rawImportModule = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts?raw\\"),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts?raw\\")
72+
73+
74+
});
75+
export const excludeSelf = /* #__PURE__ */ Object.assign({\\"./sibling.ts\\": () => import(\\"./sibling.ts\\")
76+
77+
});
3278
export const customQueryString = /* #__PURE__ */ Object.assign({\\"./sibling.ts\\": () => import(\\"./sibling.ts?custom&lang.ts\\")});
33-
export const customQueryObject = /* #__PURE__ */ Object.assign({\\"./sibling.ts\\": () => import(\\"./sibling.ts?foo=bar&raw=true&lang.ts\\")});
34-
export const parent = /* #__PURE__ */ Object.assign({});
35-
export const rootMixedRelative = /* #__PURE__ */ Object.assign({\\"/css.spec.ts\\": () => import(\\"../../css.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]),\\"/define.spec.ts\\": () => import(\\"../../define.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]),\\"/esbuild.spec.ts\\": () => import(\\"../../esbuild.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]),\\"/import.spec.ts\\": () => import(\\"../../import.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]),\\"/importGlob/fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts?url&lang.ts\\").then(m => m[\\"default\\"]),\\"/importGlob/fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts?url&lang.ts\\").then(m => m[\\"default\\"]),\\"/importGlob/fixture-b/index.ts\\": () => import(\\"../fixture-b/index.ts?url&lang.ts\\").then(m => m[\\"default\\"])});
36-
export const cleverCwd1 = /* #__PURE__ */ Object.assign({\\"./node_modules/framework/pages/hello.page.js\\": () => import(\\"./node_modules/framework/pages/hello.page.js\\")});
37-
export const cleverCwd2 = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"),\\"../fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts\\"),\\"../fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts\\")});
79+
export const customQueryObject = /* #__PURE__ */ Object.assign({\\"./sibling.ts\\": () => import(\\"./sibling.ts?foo=bar&raw=true&lang.ts\\")
80+
81+
82+
83+
84+
});
85+
export const parent = /* #__PURE__ */ Object.assign({
86+
87+
});
88+
export const rootMixedRelative = /* #__PURE__ */ Object.assign({\\"/css.spec.ts\\": () => import(\\"../../css.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]),\\"/define.spec.ts\\": () => import(\\"../../define.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]),\\"/esbuild.spec.ts\\": () => import(\\"../../esbuild.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]),\\"/import.spec.ts\\": () => import(\\"../../import.spec.ts?url&lang.ts\\").then(m => m[\\"default\\"]),\\"/importGlob/fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts?url&lang.ts\\").then(m => m[\\"default\\"]),\\"/importGlob/fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts?url&lang.ts\\").then(m => m[\\"default\\"]),\\"/importGlob/fixture-b/index.ts\\": () => import(\\"../fixture-b/index.ts?url&lang.ts\\").then(m => m[\\"default\\"])
89+
90+
91+
});
92+
export const cleverCwd1 = /* #__PURE__ */ Object.assign({\\"./node_modules/framework/pages/hello.page.js\\": () => import(\\"./node_modules/framework/pages/hello.page.js\\")
93+
94+
});
95+
export const cleverCwd2 = /* #__PURE__ */ Object.assign({\\"./modules/a.ts\\": () => import(\\"./modules/a.ts\\"),\\"./modules/b.ts\\": () => import(\\"./modules/b.ts\\"),\\"../fixture-b/a.ts\\": () => import(\\"../fixture-b/a.ts\\"),\\"../fixture-b/b.ts\\": () => import(\\"../fixture-b/b.ts\\")
96+
97+
98+
99+
});
38100
"
39101
`;
40102

packages/vite/src/node/__tests__/plugins/importGlob/fixture.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ describe('fixture', async () => {
2222
).toMatchSnapshot()
2323
})
2424

25+
it('preserve line count', async () => {
26+
const getTransformedLineCount = async (code: string) =>
27+
(await transformGlobImport(code, 'virtual:module', root, resolveId))?.s
28+
.toString()
29+
.split('\n').length
30+
31+
expect(await getTransformedLineCount("import.meta.glob('./*.js')")).toBe(1)
32+
expect(
33+
await getTransformedLineCount(
34+
`
35+
import.meta.glob(
36+
'./*.js'
37+
)
38+
`.trim()
39+
)
40+
).toBe(3)
41+
})
42+
2543
it('virtual modules', async () => {
2644
const root = resolve(__dirname, './fixture-a')
2745
const code = [

packages/vite/src/node/optimizer/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ export async function addManuallyIncludedOptimizeDeps(
708708
const resolve = config.createResolver({
709709
asSrc: false,
710710
scan: true,
711-
ssrOptimizeCheck: ssr
711+
ssrOptimizeCheck: ssr,
712+
ssrConfig: config.ssr
712713
})
713714
for (const id of [...optimizeDepsInclude, ...extra]) {
714715
// normalize 'foo >bar` as 'foo > bar' to prevent same id being added

packages/vite/src/node/optimizer/scan.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,8 @@ function extractImportPaths(code: string) {
531531

532532
let js = ''
533533
let m
534+
importsRE.lastIndex = 0
534535
while ((m = importsRE.exec(code)) != null) {
535-
// This is necessary to avoid infinite loops with zero-width matches
536-
if (m.index === importsRE.lastIndex) {
537-
importsRE.lastIndex++
538-
}
539536
js += `\nimport ${m[1]}`
540537
}
541538
return js

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

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export function renderAssetUrlInJS(
7575

7676
// In both cases, the wrapping should already be fine
7777

78+
assetUrlRE.lastIndex = 0
7879
while ((match = assetUrlRE.exec(code))) {
7980
s ||= new MagicString(code)
8081
const [full, hash, postfix = ''] = match
@@ -101,6 +102,7 @@ export function renderAssetUrlInJS(
101102
// Replace __VITE_PUBLIC_ASSET__5aa0ddc0__ with absolute paths
102103

103104
const publicAssetUrlMap = publicAssetUrlCache.get(config)!
105+
publicAssetUrlRE.lastIndex = 0
104106
while ((match = publicAssetUrlRE.exec(code))) {
105107
s ||= new MagicString(code)
106108
const [full, hash] = match

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function definePlugin(config: ResolvedConfig): Plugin {
8585
.join('|') +
8686
// Mustn't be followed by a char that can be part of an identifier
8787
// or an assignment (but allow equality operators)
88-
')(?![\\p{L}\\p{N}_$]|\\s*?=[^=])',
88+
')(?:(?<=\\.)|(?![\\p{L}\\p{N}_$]|\\s*?=[^=]))',
8989
'gu'
9090
)
9191
: null

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,10 @@ export async function transformWithEsbuild(
145145
inMap as RawSourceMap
146146
]) as SourceMap
147147
} else {
148-
map = resolvedOptions.sourcemap
149-
? JSON.parse(result.map)
150-
: { mappings: '' }
148+
map =
149+
resolvedOptions.sourcemap && resolvedOptions.sourcemap !== 'inline'
150+
? JSON.parse(result.map)
151+
: { mappings: '' }
151152
}
152153
if (Array.isArray(map.sources)) {
153154
map.sources = map.sources.map((it) => toUpperCaseDriveLetter(it))

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

+2
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
396396
const cleanCode = stripLiteral(scriptNode.value)
397397

398398
let match: RegExpExecArray | null
399+
inlineImportRE.lastIndex = 0
399400
while ((match = inlineImportRE.exec(cleanCode))) {
400401
const { 1: url, index } = match
401402
const startUrl = cleanCode.indexOf(url, index)
@@ -777,6 +778,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
777778
// no use assets plugin because it will emit file
778779
let match: RegExpExecArray | null
779780
let s: MagicString | undefined
781+
inlineCSSRE.lastIndex = 0
780782
while ((match = inlineCSSRE.exec(result))) {
781783
s ||= new MagicString(result)
782784
const { 0: full, 1: scopedName } = match

0 commit comments

Comments
 (0)