Skip to content

Commit

Permalink
refactor: seal -> freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Jul 6, 2021
1 parent 8e097ef commit 5fd7f87
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/lib/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function getEntryPointsForPackages(
return;
}
results.push({
displayName: packageJson.name as string,
displayName: packageJson["name"] as string,
path: packageEntryPoint,
program,
sourceFile,
Expand Down Expand Up @@ -287,7 +287,7 @@ export class Application extends ChildableComponent<
public convert(): ProjectReflection | undefined {
// We seal here rather than in the Converter class since TypeDoc's tests reuse the Application
// with a few different settings.
this.options.seal();
this.options.freeze();
this.logger.verbose(
`Using TypeScript ${this.getTypeScriptVersion()} from ${this.getTypeScriptPath()}`
);
Expand Down Expand Up @@ -358,7 +358,7 @@ export class Application extends ChildableComponent<
public convertAndWatch(
success: (project: ProjectReflection) => Promise<void>
): void {
this.options.seal();
this.options.freeze();
if (
!this.options.getValue("preserveWatchOutput") &&
this.logger instanceof ConsoleLogger
Expand Down
16 changes: 8 additions & 8 deletions src/lib/utils/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ export class Options {
/**
* Marks the options as readonly, enables caching when fetching options, which improves performance.
*/
seal() {
Object.seal(this._values);
freeze() {
Object.freeze(this._values);
}

/**
* Checks if the options object has been sealed, preventing future changes to option values.
* Checks if the options object has been frozen, preventing future changes to option values.
*/
isSealed() {
return Object.isSealed(this._values);
isFrozen() {
return Object.isFrozen(this._values);
}

/**
Expand Down Expand Up @@ -274,7 +274,7 @@ export class Options {
configPath?: NeverIfInternal<string>
): void;
setValue(name: string, value: unknown, configPath?: string): void {
if (this.isSealed()) {
if (this.isFrozen()) {
throw new Error(
"Tried to modify an option value after options have been sealed."
);
Expand Down Expand Up @@ -325,7 +325,7 @@ export class Options {
options: ts.CompilerOptions,
projectReferences: readonly ts.ProjectReference[] | undefined
) {
if (this.isSealed()) {
if (this.isFrozen()) {
throw new Error(
"Tried to modify an option value after options have been sealed."
);
Expand Down Expand Up @@ -383,7 +383,7 @@ export function BindOption(name: string) {
"options" in this ? this.options : this.application.options;
const value = options.getValue(name as keyof TypeDocOptions);

if (options.isSealed()) {
if (options.isFrozen()) {
Object.defineProperty(this, key, { value });
}

Expand Down
22 changes: 13 additions & 9 deletions src/lib/utils/package-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,23 @@ function getPackagePaths(
packageJSON: Record<string, unknown>
): string[] | undefined {
if (
Array.isArray(packageJSON.workspaces) &&
packageJSON.workspaces.every((i) => typeof i === "string")
Array.isArray(packageJSON["workspaces"]) &&
packageJSON["workspaces"].every((i) => typeof i === "string")
) {
return packageJSON.workspaces;
return packageJSON["workspaces"];
}
if (
typeof packageJSON.workspaces === "object" &&
packageJSON.workspaces != null &&
hasOwnProperty(packageJSON.workspaces, "packages") &&
Array.isArray(packageJSON.workspaces.packages) &&
packageJSON.workspaces.packages.every((i) => typeof i === "string")
typeof packageJSON["workspaces"] === "object" &&
packageJSON["workspaces"] != null
) {
return packageJSON.workspaces.packages;
const workspaces = packageJSON["workspaces"];
if (
hasOwnProperty(workspaces, "packages") &&
Array.isArray(workspaces["packages"]) &&
workspaces["packages"].every((i) => typeof i === "string")
) {
return workspaces["packages"];
}
}
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/converter2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ describe("Converter2", () => {
tsconfig: join(base, "tsconfig.json"),
plugin: [],
});
app.options.seal();
app.options.freeze();

let program: ts.Program;
before("Compiles", () => {
Expand Down
8 changes: 4 additions & 4 deletions src/test/utils/options/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ describe("Options", () => {
throws(() => options.isSet("does not exist" as never));
});

it("Throws if sealed and a value is set", () => {
it("Throws if frozen and a value is set", () => {
const options = new Options(new Logger());
options.addDefaultDeclarations();
options.seal();
options.freeze();

throws(() => options.setValue("emit", true));
throws(() => options.setCompilerOptions([], {}, []));
Expand Down Expand Up @@ -147,14 +147,14 @@ describe("BindOption", () => {
equal(container.emit, true);
});

it("Caches set options when sealed", () => {
it("Caches set options when frozen", () => {
const options = new Options(new Logger());
options.addDefaultDeclarations();

const container = new Container(options);

options.setValue("emit", true);
options.seal();
options.freeze();
equal(container.emit, true);

const prop = Object.getOwnPropertyDescriptor(container, "emit")!;
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"sourceMap": true,
"isolatedModules": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,

// Output
"outDir": "dist/",
Expand Down

0 comments on commit 5fd7f87

Please sign in to comment.