Skip to content

Commit

Permalink
chore: apply Prettier's new formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
uhyo committed Mar 24, 2024
1 parent 1bd8216 commit 5394ba9
Show file tree
Hide file tree
Showing 32 changed files with 269 additions and 252 deletions.
32 changes: 16 additions & 16 deletions build/logic/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function generate(
tsLibDir: string,
targetFile: string,
sourceFile: string,
{ emitOriginalAsComment = false, emitNoDefaultLib = false }: GenerateOptions
{ emitOriginalAsComment = false, emitNoDefaultLib = false }: GenerateOptions,
): string | undefined {
const tsLibFile = path.join(tsLibDir, sourceFile);
const originalProgram = ts.createProgram([tsLibFile], {});
Expand Down Expand Up @@ -60,7 +60,7 @@ export function generate(
if (!ts.isInterfaceDeclaration(statement)) {
// Find the replacement target of same kind.
const replacementTargetOfSameKind = replacementTarget.flatMap((target) =>
target.type === "non-interface" ? [target] : []
target.type === "non-interface" ? [target] : [],
);
if (replacementTargetOfSameKind.length === 0) {
result += statement.getFullText(originalFile);
Expand All @@ -79,7 +79,7 @@ export function generate(
continue;
}
const replaceInterfaces = replacementTarget.flatMap((target) =>
target.type === "interface" ? [target] : []
target.type === "interface" ? [target] : [],
);
if (
replaceInterfaces.some(
Expand All @@ -88,8 +88,8 @@ export function generate(
statement,
originalFile,
target.originalStatement,
target.sourceFile
)
target.sourceFile,
),
)
) {
// This needs to be a full replacement
Expand Down Expand Up @@ -197,7 +197,7 @@ type ReplacementTarget = (
*/
function scanBetterFile(
printer: ts.Printer,
targetFile: string
targetFile: string,
): Map<string, ReplacementTarget[]> {
const replacementTargets = new Map<string, ReplacementTarget[]>();
{
Expand All @@ -224,7 +224,7 @@ function scanBetterFile(
const memberName = member.name?.getText(betterFile) ?? "";
upsert(members, memberName, (members = []) => {
const leadingSpacesMatch = /^\s*/.exec(
member.getFullText(betterFile)
member.getFullText(betterFile),
);
const leadingSpaces =
leadingSpacesMatch !== null ? leadingSpacesMatch[0] : "";
Expand All @@ -235,7 +235,7 @@ function scanBetterFile(
printer.printNode(
ts.EmitHint.Unspecified,
member,
betterFile
betterFile,
),
});
return members;
Expand Down Expand Up @@ -274,7 +274,7 @@ function isPartialReplacement(
interfaceDecl: ts.InterfaceDeclaration,
originalFile: ts.SourceFile,
replacementDecl: ts.InterfaceDeclaration,
betterFile: ts.SourceFile
betterFile: ts.SourceFile,
): boolean {
// Compare type parameters and herigate using full text.
if (
Expand Down Expand Up @@ -334,7 +334,7 @@ function printInterface(
printer: ts.Printer,
originalNode: ts.InterfaceDeclaration,
members: readonly { text: string }[],
originalSourceFile: ts.SourceFile
originalSourceFile: ts.SourceFile,
): string {
let result = originalNode
.getFullText(originalSourceFile)
Expand All @@ -343,27 +343,27 @@ function printInterface(
result += printer.printNode(
ts.EmitHint.Unspecified,
mod,
originalSourceFile
originalSourceFile,
);
}
result += "interface ";
result += printer.printNode(
ts.EmitHint.Unspecified,
originalNode.name,
originalSourceFile
originalSourceFile,
);
if (originalNode.typeParameters) {
result += printer.printList(
ts.ListFormat.TypeParameters,
originalNode.typeParameters,
originalSourceFile
originalSourceFile,
);
}
if (originalNode.heritageClauses) {
result += printer.printList(
ts.ListFormat.HeritageClauses,
originalNode.heritageClauses,
originalSourceFile
originalSourceFile,
);
}
result += "{\n";
Expand Down Expand Up @@ -402,7 +402,7 @@ function commentOut(code: string): string {

function replaceAliases(
statement: ts.Statement,
typeMap: Map<string, string>
typeMap: Map<string, string>,
): ts.Statement {
if (typeMap.size === 0) return statement;
return ts.transform(statement, [
Expand All @@ -416,7 +416,7 @@ function replaceAliases(
return ts.factory.updateTypeReferenceNode(
node,
ts.factory.createIdentifier(replacementType),
node.typeArguments
node.typeArguments,
);
}
return ts.visitEachChild(node, visitor, context);
Expand Down
2 changes: 1 addition & 1 deletion build/logic/getLibFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export const getLibFiles = async () => {
const sourceFile = `${lib}.d.ts`;
const targetFile = paths[lib] || `lib.${sourceFile}`;
return [targetFile, sourceFile];
})
}),
);
};
22 changes: 11 additions & 11 deletions build/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function main() {
const packageTemplateFiles = await readdir(templateDir);

const libFiles = (await readdir(libDir)).filter((libFile) =>
/\.d\.ts$/.test(libFile)
/\.d\.ts$/.test(libFile),
);

const packageNames = new Set<string>();
Expand All @@ -49,7 +49,7 @@ async function main() {
const packageJsonPath = path.join(
packageDir,
packageName,
"package.json"
"package.json",
);
await writeToPackageJson(packageJsonPath, () => ({
name: toScopedPackageName(packageName),
Expand All @@ -73,7 +73,7 @@ async function main() {
// copy root README to main package
await writeFile(
path.join(mainPackageDir, "README.md"),
await readFile(path.join(projectDir, "README.md"))
await readFile(path.join(projectDir, "README.md")),
);
// update package.json
const packageJsonPath = path.join(mainPackageDir, "package.json");
Expand All @@ -85,13 +85,13 @@ async function main() {
[...packageNames].map((packageName) => [
`@typescript/lib-${packageName}`,
`npm:${toScopedPackageName(packageName)}@${version}`,
])
]),
),
}));
// prepare symlink to dist
await symlink(
path.join(projectDir, "dist"),
path.join(mainPackageDir, "dist")
path.join(mainPackageDir, "dist"),
);
}
// update package.json in "tests" folder
Expand All @@ -105,9 +105,9 @@ async function main() {
`@typescript/lib-${packageName}`,
`file:${path.relative(
path.dirname(packageJsonPath),
path.join(packageDir, packageName)
path.join(packageDir, packageName),
)}`,
])
]),
),
},
}));
Expand All @@ -119,12 +119,12 @@ async function main() {
const filePath = path.join(templateDir, file);
const targetPath = path.join(dir, file);
return writeFile(targetPath, await readFile(filePath));
})
}),
);
}
async function writeToPackageJson(
packageJsonPath: string,
updates: (original: any) => Record<string, unknown>
updates: (original: any) => Record<string, unknown>,
) {
const original = JSON.parse(await readFile(packageJsonPath, "utf-8"));
return writeFile(
Expand All @@ -135,8 +135,8 @@ async function main() {
...updates(original),
},
null,
2
) + "\n"
2,
) + "\n",
);
}
function toScopedPackageName(packageName: string) {
Expand Down
6 changes: 3 additions & 3 deletions build/util/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const alias = new Map(
[originalType, replacement],
[`${originalType}Constructor`, `${replacement}Constructor`],
]),
])
]),
),
],
[
Expand All @@ -39,8 +39,8 @@ export const alias = new Map(
[originalType, replacement],
[`${originalType}Constructor`, `${replacement}Constructor`],
]),
])
]),
),
],
])
]),
);
2 changes: 1 addition & 1 deletion build/util/upsert.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function upsert<K, V>(
map: Map<K, V>,
key: K,
update: (value: V | undefined) => V
update: (value: V | undefined) => V,
) {
const value = map.get(key);
map.set(key, update(value));
Expand Down
10 changes: 5 additions & 5 deletions lib/lib.es2015.collection.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ interface Map<K, V> {
*/
forEach<This = undefined>(
callbackfn: (this: This, value: V, key: K, map: this) => void,
thisArg?: This
thisArg?: This,
): void;
}

Expand All @@ -15,15 +15,15 @@ interface MapConstructor {

interface WeakMapConstructor {
new <K extends WeakKey, V>(
entries?: readonly (readonly [K, V])[] | null
entries?: readonly (readonly [K, V])[] | null,
): WeakMap<K, V>;
readonly prototype: WeakMap<WeakKey, unknown>;
}

interface ReadonlyMap<K, V> {
forEach<This = undefined>(
callbackfn: (this: This, value: V, key: K, map: this) => void,
thisArg?: This
thisArg?: This,
): void;
}

Expand All @@ -33,7 +33,7 @@ interface Set<T> {
*/
forEach<This = undefined>(
callbackfn: (this: This, value: T, value2: T, set: this) => void,
thisArg?: This
thisArg?: This,
): void;
}

Expand All @@ -45,6 +45,6 @@ interface SetConstructor {
interface ReadonlySet<T> {
forEach<This = undefined>(
callbackfn: (this: This, value: T, value2: T, set: this) => void,
thisArg?: This
thisArg?: This,
): void;
}
14 changes: 7 additions & 7 deletions lib/lib.es2015.core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Array<T> {
*/
find<S extends T, This = undefined>(
predicate: (this: This, value: T, index: number, obj: this) => value is S,
thisArg?: This
thisArg?: This,
): S | undefined;

/**
Expand All @@ -24,7 +24,7 @@ interface Array<T> {
*/
find<This = undefined>(
predicate: (this: This, value: T, index: number, obj: this) => boolean,
thisArg?: This
thisArg?: This,
): T | undefined;

/**
Expand All @@ -38,7 +38,7 @@ interface Array<T> {
*/
findIndex<This = undefined>(
predicate: (this: This, value: T, index: number, obj: this) => boolean,
thisArg?: This
thisArg?: This,
): number;
}

Expand All @@ -58,7 +58,7 @@ interface ArrayConstructor {
from<T, U, This = undefined>(
source: ArrayLike<T>,
mapfn: (this: This, v: T, k: number) => U,
thisArg?: This
thisArg?: This,
): U[];
}

Expand Down Expand Up @@ -114,7 +114,7 @@ interface ReadonlyArray<T> {
*/
find<S extends T, This = undefined>(
predicate: (this: This, value: T, index: number, obj: this) => value is S,
thisArg?: This
thisArg?: This,
): S | undefined;

/**
Expand All @@ -128,7 +128,7 @@ interface ReadonlyArray<T> {
*/
find<This = undefined>(
predicate: (this: This, value: T, index: number, obj: this) => boolean,
thisArg?: This
thisArg?: This,
): T | undefined;

/**
Expand All @@ -142,7 +142,7 @@ interface ReadonlyArray<T> {
*/
findIndex<This = undefined>(
predicate: (this: This, value: T, index: number, obj: this) => boolean,
thisArg?: This
thisArg?: This,
): number;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/lib.es2015.iterable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface ArrayConstructor {
from<T, U, This = undefined>(
iterable: Iterable<T> | ArrayLike<T>,
mapfn: (this: This, v: T, k: number) => U,
thisArg?: This
thisArg?: This,
): U[];
}

Expand Down Expand Up @@ -71,6 +71,6 @@ interface TypedNumberArrayConstructor {
from<T, This = undefined>(
iterable: Iterable<T> | ArrayLike<T>,
mapfn: (this: This, v: T, k: number) => number,
thisArg?: This
thisArg?: This,
): TypedNumberArray;
}
4 changes: 2 additions & 2 deletions lib/lib.es2015.promise.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ interface PromiseConstructor {
resolve: undefined extends T
? (value?: T | PromiseLike<T>) => void
: (value: T | PromiseLike<T>) => void,
reject: (reason?: any) => void
) => void
reject: (reason?: any) => void,
) => void,
): Promise<T>;

/**
Expand Down
Loading

0 comments on commit 5394ba9

Please sign in to comment.