Skip to content

Commit

Permalink
chore: fix code
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Nov 27, 2024
1 parent d55a596 commit be1ddbd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
8 changes: 4 additions & 4 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -906,12 +906,12 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
// will be populated in order they are used by entry points
const dynamicImports = new Set<string>()

function collect(chunk: OutputChunk | OutputAsset) {
if (chunk.type !== 'chunk' || collected.has(chunk)) return
function collect(chunk: OutputChunk | OutputAsset | undefined) {
if (!chunk || chunk.type !== 'chunk' || collected.has(chunk)) return
collected.add(chunk)

// First collect all styles from the synchronous imports (lowest priority)
chunk.imports.forEach((importName) => collect(bundle[importName]!))
chunk.imports.forEach((importName) => collect(bundle[importName]))
// Save dynamic imports in deterministic order to add the styles later (to have the highest priority)
chunk.dynamicImports.forEach((importName) =>
dynamicImports.add(importName),
Expand All @@ -929,7 +929,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
}
// Now collect the dynamic chunks, this is done last to have the styles overwrite the previous ones
for (const chunkName of dynamicImports) {
collect(bundle[chunkName]!)
collect(bundle[chunkName])
}

// Finally, if there's any extracted CSS, we emit the asset
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export function esbuildPlugin(config: ResolvedConfig): Plugin {
},
}

let server: ViteDevServer
let server: ViteDevServer | undefined

return {
name: 'vite:esbuild',
Expand All @@ -280,7 +280,7 @@ export function esbuildPlugin(config: ResolvedConfig): Plugin {
transformOptions,
undefined,
config,
server.watcher,
server?.watcher,
)
if (result.warnings.length) {
result.warnings.forEach((m) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
throw e
})

if (!resolved || resolved.meta['vite:alias']?.noResolved) {
// resolved.meta does not exist in dev
if (!resolved || resolved.meta?.['vite:alias']?.noResolved) {
// in ssr, we should let node handle the missing modules
if (ssr) {
return [url, url]
Expand Down
10 changes: 5 additions & 5 deletions packages/vite/src/node/server/pluginContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ class PluginContext implements Omit<RollupPluginContext, 'cache'> {
typeof err.loc.column === 'number'
) {
const rawSourceMap = this._getCombinedSourcemap()
if ('version' in rawSourceMap) {
if (rawSourceMap && 'version' in rawSourceMap) {
const traced = new TraceMap(rawSourceMap as any)
const { source, line, column } = originalPositionFor(traced, {
line: Number(err.loc.line),
Expand Down Expand Up @@ -847,7 +847,7 @@ class TransformPluginContext
}
}

_getCombinedSourcemap(): SourceMap | { mappings: '' } {
_getCombinedSourcemap(): SourceMap | { mappings: '' } | null {
if (
debugSourcemapCombine &&
debugSourcemapCombineFilter &&
Expand Down Expand Up @@ -909,20 +909,20 @@ class TransformPluginContext
this.combinedMap = combinedMap
this.sourcemapChain.length = 0
}
return this.combinedMap!
return this.combinedMap
}

getCombinedSourcemap(): SourceMap {
const map = this._getCombinedSourcemap()
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- extra check for safety
if (!('version' in map) && map.mappings === '') {
if (!map || (!('version' in map) && map.mappings === '')) {
return new MagicString(this.originalCode).generateMap({
includeContent: true,
hires: 'boundary',
source: cleanUrl(this.filename),
})
}
return map
return map as SourceMap
}

_updateActiveInfo(plugin: Plugin, id: string, code: string): void {
Expand Down
12 changes: 6 additions & 6 deletions packages/vite/src/node/ssr/ssrTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,10 @@ function walk(
return
}
;(eswalk as any)(p.type === 'AssignmentPattern' ? p.left : p, {
enter(child: Node, parent: Node) {
enter(child: Node, parent: Node | undefined) {
// skip params default value of destructure
if (
parent.type === 'AssignmentPattern' &&
parent?.type === 'AssignmentPattern' &&
parent.right === child
) {
return this.skip()
Expand All @@ -582,9 +582,9 @@ function walk(
// do not record if this is a default value
// assignment of a destructuring variable
if (
(parent.type === 'TemplateLiteral' &&
(parent?.type === 'TemplateLiteral' &&
parent.expressions.includes(child)) ||
(parent.type === 'CallExpression' && parent.callee === child)
(parent?.type === 'CallExpression' && parent.callee === child)
) {
return
}
Expand Down Expand Up @@ -708,8 +708,8 @@ function isRefIdentifier(id: Identifier, parent: _Node, parentStack: _Node[]) {
const isStaticProperty = (node: _Node): node is Property =>
node.type === 'Property' && !node.computed

const isStaticPropertyKey = (node: _Node, parent: _Node) =>
isStaticProperty(parent) && parent.key === node
const isStaticPropertyKey = (node: _Node, parent: _Node | undefined) =>
parent && isStaticProperty(parent) && parent.key === node

const functionNodeTypeRE = /Function(?:Expression|Declaration)$|Method$/
function isFunction(node: _Node): node is FunctionNode {
Expand Down

0 comments on commit be1ddbd

Please sign in to comment.