Skip to content

Commit

Permalink
chore: replace some ?. with !. to reduce diff
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Dec 6, 2024
1 parent a941c47 commit a8c2ad4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function renderAssetUrlInJS(
s ||= new MagicString(code)
const [full, referenceId, postfix = ''] = match
const file = pluginContext.getFileName(referenceId)
chunk.viteMetadata?.importedAssets.add(cleanUrl(file))
chunk.viteMetadata!.importedAssets.add(cleanUrl(file))
const filename = file + postfix
const replacement = toOutputFilePathInJS(
environment,
Expand Down
10 changes: 5 additions & 5 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
// replace asset url references with resolved url.
chunkCSS = chunkCSS.replace(assetUrlRE, (_, fileHash, postfix = '') => {
const filename = this.getFileName(fileHash) + postfix
chunk.viteMetadata?.importedAssets.add(cleanUrl(filename))
chunk.viteMetadata!.importedAssets.add(cleanUrl(filename))
return encodeURIPath(
toOutputFilePathInCss(
filename,
Expand Down Expand Up @@ -802,7 +802,7 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
generatedAssets.set(referenceId, { originalFileName })

const filename = this.getFileName(referenceId)
chunk.viteMetadata?.importedAssets.add(cleanUrl(filename))
chunk.viteMetadata!.importedAssets.add(cleanUrl(filename))
const replacement = toOutputFilePathInJS(
this.environment,
filename,
Expand Down Expand Up @@ -858,7 +858,7 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
source: chunkCSS,
})
generatedAssets.set(referenceId, { originalFileName, isEntry })
chunk.viteMetadata?.importedCss.add(this.getFileName(referenceId))
chunk.viteMetadata!.importedCss.add(this.getFileName(referenceId))
} else if (this.environment.config.consumer === 'client') {
// legacy build and inline css

Expand Down Expand Up @@ -1013,10 +1013,10 @@ export function cssPostPlugin(config: ResolvedConfig): RolldownPlugin {
bundle[file] as OutputChunk
).viteMetadata!
importedCss.forEach((file) =>
chunk.viteMetadata?.importedCss.add(file),
chunk.viteMetadata!.importedCss.add(file),
)
importedAssets.forEach((file) =>
chunk.viteMetadata?.importedAssets.add(file),
chunk.viteMetadata!.importedAssets.add(file),
)
chunkImportsPureCssChunk = true
return false
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): RolldownPlugin {
})
}

chunk.viteMetadata?.importedCss.forEach((file) => {
chunk.viteMetadata!.importedCss.forEach((file) => {
if (!seen.has(file)) {
seen.add(file)
tags.push({
Expand Down Expand Up @@ -972,7 +972,7 @@ export function buildHtmlPlugin(config: ResolvedConfig): RolldownPlugin {
result = result.replace(assetUrlRE, (_, fileHash, postfix = '') => {
const file = this.getFileName(fileHash)
if (chunk) {
chunk.viteMetadata?.importedAssets.add(cleanUrl(file))
chunk.viteMetadata!.importedAssets.add(cleanUrl(file))
}
return encodeURIPath(toOutputAssetFilePath(file)) + postfix
})
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/plugins/importAnalysisBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): [Plugin] {
chunk.imports.forEach(addDeps)
// Ensure that the css imported by current chunk is loaded after the dependencies.
// So the style of current chunk won't be overwritten unexpectedly.
chunk.viteMetadata?.importedCss.forEach((file) => {
chunk.viteMetadata!.importedCss.forEach((file) => {
deps.add(file)
})
}
Expand All @@ -568,8 +568,8 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): [Plugin] {
removedPureCssFilesCache.get(config)!
const chunk = removedPureCssFiles.get(filename)
if (chunk) {
if (chunk.viteMetadata?.importedCss.size) {
chunk.viteMetadata?.importedCss.forEach((file) => {
if (chunk.viteMetadata!.importedCss.size) {
chunk.viteMetadata!.importedCss.forEach((file) => {
deps.add(file)
})
hasRemovedPureCssChunk = true
Expand Down
6 changes: 3 additions & 3 deletions packages/vite/src/node/ssr/ssrManifestPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export function ssrManifestPlugin(): Plugin {
mappedChunks.push(joinUrlSegments(base, chunk.fileName))
// <link> tags for entry chunks are already generated in static HTML,
// so we only need to record info for non-entry chunks.
chunk.viteMetadata?.importedCss.forEach((file) => {
chunk.viteMetadata!.importedCss.forEach((file) => {
mappedChunks.push(joinUrlSegments(base, file))
})
}
chunk.viteMetadata?.importedAssets.forEach((file) => {
chunk.viteMetadata!.importedAssets.forEach((file) => {
mappedChunks.push(joinUrlSegments(base, file))
})
}
Expand Down Expand Up @@ -86,7 +86,7 @@ export function ssrManifestPlugin(): Plugin {
analyzed.add(filename)
const chunk = bundle[filename] as OutputChunk | undefined
if (chunk) {
chunk.viteMetadata?.importedCss.forEach((file) => {
chunk.viteMetadata!.importedCss.forEach((file) => {
deps.push(joinUrlSegments(base, file))
})
chunk.imports.forEach(addDeps)
Expand Down

0 comments on commit a8c2ad4

Please sign in to comment.