Skip to content

Commit

Permalink
chore: preloadMarkerWithQuote => preloadMarkerRE
Browse files Browse the repository at this point in the history
  • Loading branch information
pengbo43 committed May 1, 2024
1 parent 0f0a1cf commit 3dbe36f
Showing 1 changed file with 5 additions and 8 deletions.
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 @@ -37,7 +37,7 @@ export const preloadMarker = `__VITE_PRELOAD__`
export const preloadBaseMarker = `__VITE_PRELOAD_BASE__`

export const preloadHelperId = '\0vite/preload-helper.js'
const preloadMarkerWithQuote = new RegExp(preloadMarker, 'g')
const preloadMarkerRE = new RegExp(preloadMarker, 'g')

const dynamicImportPrefixRE = /import\s*\(/

Expand Down Expand Up @@ -419,15 +419,12 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {

let markerStartPos = indexOfMatchInSlice(
code,
preloadMarkerWithQuote,
preloadMarkerRE,
end,
)
// fix issue #3051
if (markerStartPos === -1 && imports.length === 1) {
markerStartPos = indexOfMatchInSlice(
code,
preloadMarkerWithQuote,
)
markerStartPos = indexOfMatchInSlice(code, preloadMarkerRE)
}

if (markerStartPos > 0) {
Expand Down Expand Up @@ -526,7 +523,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {

// there may still be markers due to inlined dynamic imports, remove
// all the markers regardless
let markerStartPos = indexOfMatchInSlice(code, preloadMarkerWithQuote)
let markerStartPos = indexOfMatchInSlice(code, preloadMarkerRE)
while (markerStartPos >= 0) {
if (!rewroteMarkerStartPos.has(markerStartPos)) {
s.update(
Expand All @@ -537,7 +534,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin {
}
markerStartPos = indexOfMatchInSlice(
code,
preloadMarkerWithQuote,
preloadMarkerRE,
markerStartPos + preloadMarker.length,
)
}
Expand Down

0 comments on commit 3dbe36f

Please sign in to comment.