diff --git a/browser/resolveId.ts b/browser/resolveId.ts index 945768fb94f..6eccc297b11 100644 --- a/browser/resolveId.ts +++ b/browser/resolveId.ts @@ -13,9 +13,9 @@ export async function resolveId( importer: string | undefined, customOptions: CustomPluginOptions | undefined, isEntry: boolean | undefined, - skip: { importer: string | undefined; plugin: Plugin; source: string }[] | null + skip: readonly { importer: string | undefined; plugin: Plugin; source: string }[] | null ) => Promise, - skip: { importer: string | undefined; plugin: Plugin; source: string }[] | null, + skip: readonly { importer: string | undefined; plugin: Plugin; source: string }[] | null, customOptions: CustomPluginOptions | undefined, isEntry: boolean ): Promise { diff --git a/src/Chunk.ts b/src/Chunk.ts index 1f218cf595a..ffe876bc8cc 100644 --- a/src/Chunk.ts +++ b/src/Chunk.ts @@ -108,7 +108,7 @@ function getGlobalName( globals: GlobalsOption, hasExports: boolean, warn: WarningHandler -) { +): string | undefined { const globalName = typeof globals === 'function' ? globals(module.id) : globals[module.id]; if (globalName) { return globalName; @@ -126,7 +126,7 @@ function getGlobalName( } export default class Chunk { - entryModules: Module[] = []; + readonly entryModules: Module[] = []; execIndex: number; exportMode: 'none' | 'named' | 'default' = 'named'; facadeModule: Module | null = null; @@ -136,27 +136,27 @@ export default class Chunk { suggestedVariableName: string; variableName = ''; - private accessedGlobalsByScope = new Map>(); + private readonly accessedGlobalsByScope = new Map>(); private dependencies = new Set(); - private dynamicDependencies = new Set(); - private dynamicEntryModules: Module[] = []; + private readonly dynamicDependencies = new Set(); + private readonly dynamicEntryModules: Module[] = []; private dynamicName: string | null = null; - private exportNamesByVariable = new Map(); - private exports = new Set(); - private exportsByName: Record = Object.create(null); + private readonly exportNamesByVariable = new Map(); + private readonly exports = new Set(); + private readonly exportsByName: Record = Object.create(null); private fileName: string | null = null; private implicitEntryModules: Module[] = []; - private implicitlyLoadedBefore = new Set(); - private imports = new Set(); + private readonly implicitlyLoadedBefore = new Set(); + private readonly imports = new Set(); private indentString: string = undefined as never; - private readonly isEmpty: boolean = true; + private isEmpty = true; private name: string | null = null; private renderedDependencies: Map | null = null; private renderedExports: ChunkExports | null = null; - private renderedHash: string = undefined as never; - private renderedModuleSources = new Map(); - private renderedModules: { + private renderedHash: string | undefined = undefined; + private readonly renderedModuleSources = new Map(); + private readonly renderedModules: { [moduleId: string]: RenderedModule; } = Object.create(null); private renderedSource: MagicStringBundle | null = null; @@ -251,7 +251,7 @@ export default class Chunk { return chunk; } - canModuleBeFacade(module: Module, exposedVariables: Set): boolean { + canModuleBeFacade(module: Module, exposedVariables: ReadonlySet): boolean { const moduleExportNamesByVariable = module.getExportNamesByVariable(); for (const exposedVariable of this.exports) { if (!moduleExportNamesByVariable.has(exposedVariable)) { @@ -429,9 +429,9 @@ export default class Chunk { preserveModulesRelativeDir: string, options: NormalizedOutputOptions, existingNames: Record, - unsetOptions: Set + unsetOptions: ReadonlySet ): string { - const id = this.orderedModules[0].id; + const [{ id }] = this.orderedModules; const sanitizedId = this.outputOptions.sanitizeFileName(id); let path: string; @@ -641,7 +641,7 @@ export default class Chunk { this.renderedSource = magicString.trim(); } - this.renderedHash = undefined as never; + this.renderedHash = undefined; if (this.isEmpty && this.getExportNames().length === 0 && this.dependencies.size === 0) { const chunkName = this.getChunkName(); @@ -811,9 +811,9 @@ export default class Chunk { } private addDependenciesToChunk( - moduleDependencies: Set, + moduleDependencies: ReadonlySet, chunkDependencies: Set - ) { + ): void { for (const module of moduleDependencies) { if (module instanceof Module) { const chunk = this.chunkByModule.get(module); @@ -826,7 +826,7 @@ export default class Chunk { } } - private assignFacadeName({ fileName, name }: FacadeName, facadedModule: Module) { + private assignFacadeName({ fileName, name }: FacadeName, facadedModule: Module): void { if (fileName) { this.fileName = fileName; } else { @@ -870,7 +870,7 @@ export default class Chunk { hash.update( [addons.intro, addons.outro, addons.banner, addons.footer].map(addon => addon || '').join(':') ); - hash.update(options.format as string); + hash.update(options.format); const dependenciesForHashing = new Set([this]); for (const current of dependenciesForHashing) { if (current instanceof ExternalModule) { @@ -1306,7 +1306,7 @@ export default class Chunk { break; } } - const usedNames = new Set(['Object', 'Promise']); + const usedNames = new Set(['Object', 'Promise']); if (this.needsExportsShim) { usedNames.add(MISSING_EXPORT_SHIM_VARIABLE); } diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index 92e602d2e13..0c01e039e1b 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -176,7 +176,7 @@ export class ModuleLoader { importer: string | undefined, customOptions: CustomPluginOptions | undefined, isEntry: boolean | undefined, - skip: { importer: string | undefined; plugin: Plugin; source: string }[] | null = null + skip: readonly { importer: string | undefined; plugin: Plugin; source: string }[] | null = null ): Promise => { return this.addDefaultsToResolvedId( this.getNormalizedResolvedIdWithoutDefaults( diff --git a/src/utils/PluginDriver.ts b/src/utils/PluginDriver.ts index 1c0d347a333..def22bb9dcf 100644 --- a/src/utils/PluginDriver.ts +++ b/src/utils/PluginDriver.ts @@ -69,19 +69,19 @@ function throwInvalidHookError(hookName: string, pluginName: string) { } export class PluginDriver { - public emitFile: EmitFile; + public readonly emitFile: EmitFile; public finaliseAssets: () => void; public getFileName: (fileReferenceId: string) => string; - public setOutputBundle: ( + public readonly setOutputBundle: ( outputBundle: OutputBundleWithPlaceholders, outputOptions: NormalizedOutputOptions, facadeChunkByModule: Map ) => void; - private fileEmitter: FileEmitter; - private pluginCache: Record | undefined; - private pluginContexts = new Map(); - private plugins: Plugin[]; + private readonly fileEmitter: FileEmitter; + private readonly pluginCache: Record | undefined; + private readonly pluginContexts = new Map(); + private readonly plugins: Plugin[]; constructor( private readonly graph: Graph, diff --git a/src/utils/commondir.ts b/src/utils/commondir.ts index 42619d84f36..95a705d2e4f 100644 --- a/src/utils/commondir.ts +++ b/src/utils/commondir.ts @@ -1,9 +1,9 @@ -import * as path from './path'; +import { dirname } from './path'; // ported from https://github.com/substack/node-commondir export default function commondir(files: readonly string[]): string { if (files.length === 0) return '/'; - if (files.length === 1) return path.dirname(files[0]); + if (files.length === 1) return dirname(files[0]); const commonSegments = files.slice(1).reduce((commonSegments, file) => { const pathSegements = file.split(/\/+|\\+/); let i; diff --git a/src/utils/getOriginalLocation.ts b/src/utils/getOriginalLocation.ts index 692888dd472..fb615b0a397 100644 --- a/src/utils/getOriginalLocation.ts +++ b/src/utils/getOriginalLocation.ts @@ -1,7 +1,7 @@ import { DecodedSourceMapOrMissing, ExistingDecodedSourceMap } from '../rollup/types'; export function getOriginalLocation( - sourcemapChain: DecodedSourceMapOrMissing[], + sourcemapChain: readonly DecodedSourceMapOrMissing[], location: { column: number; line: number; name?: string; source?: string } ): { column: number; line: number } { const filteredSourcemapChain = sourcemapChain.filter( diff --git a/src/utils/getStaticDependencies.ts b/src/utils/getStaticDependencies.ts index 5d3a447c9f5..173206e1a78 100644 --- a/src/utils/getStaticDependencies.ts +++ b/src/utils/getStaticDependencies.ts @@ -4,8 +4,8 @@ import Module from '../Module'; export function getStaticDependencies( chunk: Chunk, - orderedModules: Module[], - chunkByModule: Map + orderedModules: readonly Module[], + chunkByModule: ReadonlyMap ): Set { const staticDependencyBlocks: (Chunk | ExternalModule)[][] = []; const handledDependencies = new Set(); @@ -31,7 +31,7 @@ function addStaticDependencies( staticDependencies: (Chunk | ExternalModule)[], handledModules: Set, chunk: Chunk, - chunkByModule: Map + chunkByModule: ReadonlyMap ): void { const dependencies = module.getDependenciesToBeIncluded(); for (const dependency of dependencies) { diff --git a/src/utils/resolveId.ts b/src/utils/resolveId.ts index c6a908f926f..221cab3f79b 100644 --- a/src/utils/resolveId.ts +++ b/src/utils/resolveId.ts @@ -14,9 +14,9 @@ export async function resolveId( importer: string | undefined, customOptions: CustomPluginOptions | undefined, isEntry: boolean | undefined, - skip: { importer: string | undefined; plugin: Plugin; source: string }[] | null + skip: readonly { importer: string | undefined; plugin: Plugin; source: string }[] | null ) => Promise, - skip: { importer: string | undefined; plugin: Plugin; source: string }[] | null, + skip: readonly { importer: string | undefined; plugin: Plugin; source: string }[] | null, customOptions: CustomPluginOptions | undefined, isEntry: boolean ): Promise { diff --git a/src/utils/resolveIdViaPlugins.ts b/src/utils/resolveIdViaPlugins.ts index 23a14a332d6..20d177e6bc2 100644 --- a/src/utils/resolveIdViaPlugins.ts +++ b/src/utils/resolveIdViaPlugins.ts @@ -17,9 +17,9 @@ export function resolveIdViaPlugins( importer: string | undefined, customOptions: CustomPluginOptions | undefined, isEntry: boolean | undefined, - skip: { importer: string | undefined; plugin: Plugin; source: string }[] | null + skip: readonly { importer: string | undefined; plugin: Plugin; source: string }[] | null ) => Promise, - skip: { importer: string | undefined; plugin: Plugin; source: string }[] | null, + skip: readonly { importer: string | undefined; plugin: Plugin; source: string }[] | null, customOptions: CustomPluginOptions | undefined, isEntry: boolean ): Promise {