Skip to content

Commit

Permalink
stricter types, use more readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Jan 23, 2022
1 parent a9dc596 commit 9489802
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/Bundle.ts
Expand Up @@ -104,7 +104,7 @@ export default class Bundle {
}

private async addManualChunks(
manualChunks: Record<string, string[]>
manualChunks: Record<string, readonly string[]>
): Promise<Map<Module, string>> {
const manualChunkAliasByEntry = new Map<Module, string>();
const chunkEntries = await Promise.all(
Expand Down
14 changes: 7 additions & 7 deletions src/Chunk.ts
Expand Up @@ -165,13 +165,13 @@ export default class Chunk {
private strictFacade = false;
private usedModules: Module[] = undefined as never;
constructor(
private readonly orderedModules: Module[],
private readonly orderedModules: readonly Module[],
private readonly inputOptions: NormalizedInputOptions,
private readonly outputOptions: NormalizedOutputOptions,
private readonly unsetOptions: Set<string>,
private readonly unsetOptions: ReadonlySet<string>,
private readonly pluginDriver: PluginDriver,
private readonly modulesById: Map<string, Module | ExternalModule>,
private readonly chunkByModule: Map<Module, Chunk>,
private readonly modulesById: ReadonlyMap<string, Module | ExternalModule>,
private readonly chunkByModule: ReadonlyMap<Module, Chunk>,
private readonly facadeChunkByModule: Map<Module, Chunk>,
private readonly includedNamespaces: Set<Module>,
private readonly manualChunkAlias: string | null
Expand Down Expand Up @@ -209,10 +209,10 @@ export default class Chunk {
private static generateFacade(
inputOptions: NormalizedInputOptions,
outputOptions: NormalizedOutputOptions,
unsetOptions: Set<string>,
unsetOptions: ReadonlySet<string>,
pluginDriver: PluginDriver,
modulesById: Map<string, Module | ExternalModule>,
chunkByModule: Map<Module, Chunk>,
modulesById: ReadonlyMap<string, Module | ExternalModule>,
chunkByModule: ReadonlyMap<Module, Chunk>,
facadeChunkByModule: Map<Module, Chunk>,
includedNamespaces: Set<Module>,
facadedModule: Module,
Expand Down
8 changes: 4 additions & 4 deletions src/ast/scopes/ChildScope.ts
Expand Up @@ -51,8 +51,8 @@ export default class ChildScope extends Scope {
addUsedOutsideNames(
usedNames: Set<string>,
format: InternalModuleFormat,
exportNamesByVariable: ReadonlyMap<Variable, string[]>,
accessedGlobalsByScope: ReadonlyMap<ChildScope, Set<string>>
exportNamesByVariable: ReadonlyMap<Variable, readonly string[]>,
accessedGlobalsByScope: ReadonlyMap<ChildScope, ReadonlySet<string>>
): void {
for (const variable of this.accessedOutsideVariables.values()) {
if (variable.included) {
Expand All @@ -76,8 +76,8 @@ export default class ChildScope extends Scope {

deconflict(
format: InternalModuleFormat,
exportNamesByVariable: ReadonlyMap<Variable, string[]>,
accessedGlobalsByScope: ReadonlyMap<ChildScope, Set<string>>
exportNamesByVariable: ReadonlyMap<Variable, readonly string[]>,
accessedGlobalsByScope: ReadonlyMap<ChildScope, ReadonlySet<string>>
): void {
const usedNames = new Set<string>();
this.addUsedOutsideNames(usedNames, format, exportNamesByVariable, accessedGlobalsByScope);
Expand Down
4 changes: 2 additions & 2 deletions src/ast/scopes/ModuleScope.ts
Expand Up @@ -33,8 +33,8 @@ export default class ModuleScope extends ChildScope {

deconflict(
format: InternalModuleFormat,
exportNamesByVariable: ReadonlyMap<Variable, string[]>,
accessedGlobalsByScope: ReadonlyMap<ChildScope, Set<string>>
exportNamesByVariable: ReadonlyMap<Variable, readonly string[]>,
accessedGlobalsByScope: ReadonlyMap<ChildScope, ReadonlySet<string>>
): void {
// all module level variables are already deconflicted when deconflicting the chunk
for (const scope of this.children)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/PluginDriver.ts
Expand Up @@ -83,7 +83,7 @@ export class PluginDriver {
private readonly fileEmitter: FileEmitter;
private readonly pluginCache: Record<string, SerializablePluginCache> | undefined;
private readonly pluginContexts = new Map<Plugin, PluginContext>();
private readonly plugins: Plugin[];
private readonly plugins: readonly Plugin[];

constructor(
private readonly graph: Graph,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/chunkAssignment.ts
Expand Up @@ -29,7 +29,7 @@ export function getChunkAssignments(

function assignEntryToStaticDependencies(
entry: Module,
dynamicDependentEntryPoints: Set<Module> | null
dynamicDependentEntryPoints: ReadonlySet<Module> | null
) {
const modulesToHandle = new Set([entry]);
for (const module of modulesToHandle) {
Expand Down
30 changes: 15 additions & 15 deletions src/utils/deconflictChunk.ts
Expand Up @@ -15,21 +15,21 @@ import {
import { getSafeName } from './safeName';

export interface DependenciesToBeDeconflicted {
deconflictedDefault: Set<ExternalModule>;
deconflictedNamespace: Set<ExternalModule | Chunk>;
dependencies: Set<ExternalModule | Chunk>;
deconflictedDefault: ReadonlySet<ExternalModule>;
deconflictedNamespace: ReadonlySet<ExternalModule | Chunk>;
dependencies: ReadonlySet<ExternalModule | Chunk>;
}

const DECONFLICT_IMPORTED_VARIABLES_BY_FORMAT: {
[format in InternalModuleFormat]: (
usedNames: Set<string>,
imports: Set<Variable>,
imports: ReadonlySet<Variable>,
dependenciesToBeDeconflicted: DependenciesToBeDeconflicted,
interop: GetInterop,
preserveModules: boolean,
externalLiveBindings: boolean,
chunkByModule: Map<Module, Chunk>,
syntheticExports: Set<SyntheticNamedExportVariable>
chunkByModule: ReadonlyMap<Module, Chunk>,
syntheticExports: ReadonlySet<SyntheticNamedExportVariable>
) => void;
} = {
amd: deconflictImportsOther,
Expand All @@ -43,16 +43,16 @@ const DECONFLICT_IMPORTED_VARIABLES_BY_FORMAT: {
export function deconflictChunk(
modules: readonly Module[],
dependenciesToBeDeconflicted: DependenciesToBeDeconflicted,
imports: Set<Variable>,
imports: ReadonlySet<Variable>,
usedNames: Set<string>,
format: InternalModuleFormat,
interop: GetInterop,
preserveModules: boolean,
externalLiveBindings: boolean,
chunkByModule: Map<Module, Chunk>,
syntheticExports: Set<SyntheticNamedExportVariable>,
exportNamesByVariable: ReadonlyMap<Variable, string[]>,
accessedGlobalsByScope: ReadonlyMap<ChildScope, Set<string>>,
chunkByModule: ReadonlyMap<Module, Chunk>,
syntheticExports: ReadonlySet<SyntheticNamedExportVariable>,
exportNamesByVariable: ReadonlyMap<Variable, readonly string[]>,
accessedGlobalsByScope: ReadonlyMap<ChildScope, ReadonlySet<string>>,
includedNamespaces: ReadonlySet<Module>
): void {
const reversedModules = modules.slice().reverse();
Expand Down Expand Up @@ -88,8 +88,8 @@ function deconflictImportsEsmOrSystem(
_interop: GetInterop,
preserveModules: boolean,
_externalLiveBindings: boolean,
chunkByModule: Map<Module, Chunk>,
syntheticExports: Set<SyntheticNamedExportVariable>
chunkByModule: ReadonlyMap<Module, Chunk>,
syntheticExports: ReadonlySet<SyntheticNamedExportVariable>
) {
// This is needed for namespace reexports
for (const dependency of dependenciesToBeDeconflicted.dependencies) {
Expand Down Expand Up @@ -128,12 +128,12 @@ function deconflictImportsEsmOrSystem(

function deconflictImportsOther(
usedNames: Set<string>,
imports: Set<Variable>,
imports: ReadonlySet<Variable>,
{ deconflictedDefault, deconflictedNamespace, dependencies }: DependenciesToBeDeconflicted,
interop: GetInterop,
preserveModules: boolean,
externalLiveBindings: boolean,
chunkByModule: Map<Module, Chunk>
chunkByModule: ReadonlyMap<Module, Chunk>
): void {
for (const chunkOrExternalModule of dependencies) {
chunkOrExternalModule.variableName = getSafeName(
Expand Down

0 comments on commit 9489802

Please sign in to comment.