Skip to content
This repository was archived by the owner on Feb 7, 2023. It is now read-only.

Commit a50eac0

Browse files
author
Jacob
committed
Prettier ran on all files
- Updated Prettier to handle newer TypeScript features - Ran Prettier with --write command and check, ran test
1 parent 6afbdea commit a50eac0

17 files changed

+660
-218
lines changed

CHANGELOG.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,25 @@
7676

7777
- **Add AVIF Format for Image Resizing - [@GregBrimble], [pull/59]**
7878

79-
[@GregBrimble]: https://github.com/GregBrimble
79+
[@gregbrimble]: https://github.com/GregBrimble
8080
[pull/59]: https://github.com/cloudflare/workers-types/pull/59
8181

8282
- **Add metadata typings for KV - [@GregBrimble], [pull/54]**
8383
Adds the [new metadata](https://developers.cloudflare.com/workers/runtime-apis/kv#metadata) types to the getWithMetadata, put and list methods on a KV namespace.
8484

85-
[@GregBrimble]: https://github.com/GregBrimble
85+
[@gregbrimble]: https://github.com/GregBrimble
8686
[pull/54]: https://github.com/cloudflare/workers-types/pull/54
8787

8888
- **Complete Image Resizing properties - [@GregBrimble], [pull/50]**
8989
Adds missing options for the Image Resizing API.
9090

91-
[@GregBrimble]: https://github.com/GregBrimble
91+
[@gregbrimble]: https://github.com/GregBrimble
9292
[pull/50]: https://github.com/cloudflare/workers-types/pull/50
9393

9494
- **Add API for async handlers and end handler - [@ObsidianMinor], [pull/48]**
9595
Types for [HTML Rewriter](https://developers.cloudflare.com/workers/runtime-apis/html-rewriter#end) end of document append method
9696

97-
[@ObsidianMinor]: https://github.com/ObsidianMinor
97+
[@obsidianminor]: https://github.com/ObsidianMinor
9898
[pull/48]: https://github.com/cloudflare/workers-types/pull/48
9999

100100
### Bugfixes

export/docs.ts

+18-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ interface CommentedDeclaration {
1919

2020
// Get files to build docs from
2121
const docsDir = path.join(__dirname, "..", "docs");
22-
const filePaths = fs.readdirSync(docsDir).map((fileName) => path.join(docsDir, fileName));
22+
const filePaths = fs
23+
.readdirSync(docsDir)
24+
.map((fileName) => path.join(docsDir, fileName));
2325

2426
// Maps fenced code-block languages to those recognised by declaration renderers
2527
const exampleLangRenames = {
@@ -33,7 +35,10 @@ function trimComment(comment?: Comment) {
3335
if (comment === undefined) return;
3436
comment.text = comment.text.trim();
3537
if (comment.params) {
36-
comment.params = comment.params.map(({ name, text }) => ({ name, text: text.trim() }));
38+
comment.params = comment.params.map(({ name, text }) => ({
39+
name,
40+
text: text.trim(),
41+
}));
3742
}
3843
if (comment.returns) {
3944
comment.returns = comment.returns.trim();
@@ -94,7 +99,12 @@ for (const filePath of filePaths) {
9499
// New field
95100
pushField();
96101
// token.text === "`Declaration.field`" or "`Declaration#field`"
97-
field = { name: token.text.substring(1 + declaration.name.length + 1, token.text.length - 1) };
102+
field = {
103+
name: token.text.substring(
104+
1 + declaration.name.length + 1,
105+
token.text.length - 1
106+
),
107+
};
98108
continue;
99109
}
100110

@@ -106,7 +116,11 @@ for (const filePath of filePaths) {
106116
}
107117
}
108118

109-
if (field && fieldState === FieldState.Parameters && token.type === "list") {
119+
if (
120+
field &&
121+
fieldState === FieldState.Parameters &&
122+
token.type === "list"
123+
) {
110124
// Field parameters
111125
field.comment ??= { text: "" };
112126
field.comment.params ??= [];

export/overrides.ts

+74-19
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,31 @@ import * as assert from "assert";
33
import * as fs from "fs";
44
import * as path from "path";
55
import * as ts from "typescript";
6-
import { Type, TypeParam, Comment, Field, Class, Struct, TypeDef, Function, Variable } from "./types";
6+
import {
7+
Type,
8+
TypeParam,
9+
Comment,
10+
Field,
11+
Class,
12+
Struct,
13+
TypeDef,
14+
Function,
15+
Variable,
16+
} from "./types";
717

818
// Get files to build overrides from
919
const publicOverridesDir = path.join(__dirname, "..", "overrides");
10-
const filePaths = fs.readdirSync(publicOverridesDir).map((fileName) => path.join(publicOverridesDir, fileName));
20+
const filePaths = fs
21+
.readdirSync(publicOverridesDir)
22+
.map((fileName) => path.join(publicOverridesDir, fileName));
1123
// Additional internal overrides
1224
const additionalOverridesDir = process.argv[2] && path.resolve(process.argv[2]);
13-
if(additionalOverridesDir) {
14-
filePaths.push(...fs.readdirSync(additionalOverridesDir).map((fileName) => path.join(additionalOverridesDir, fileName)))
25+
if (additionalOverridesDir) {
26+
filePaths.push(
27+
...fs
28+
.readdirSync(additionalOverridesDir)
29+
.map((fileName) => path.join(additionalOverridesDir, fileName))
30+
);
1531
}
1632

1733
// Parse file into AST
@@ -81,7 +97,10 @@ for (const filePath of filePaths) {
8197
name: "typeof",
8298
args: [{ name: type.exprName.getText(sourceFile) }],
8399
};
84-
} else if (ts.isTypeOperatorNode(type) && type.operator === ts.SyntaxKind.KeyOfKeyword) {
100+
} else if (
101+
ts.isTypeOperatorNode(type) &&
102+
type.operator === ts.SyntaxKind.KeyOfKeyword
103+
) {
85104
return {
86105
name: "keyof",
87106
args: [{ name: type.type.getText(sourceFile) }],
@@ -97,7 +116,9 @@ for (const filePath of filePaths) {
97116
} else if (ts.isParenthesizedTypeNode(type)) {
98117
return convertType(type.type);
99118
}
100-
throw new TypeError(`unrecognised type at ${getPos(type.pos)}: ${type.getText(sourceFile)}`);
119+
throw new TypeError(
120+
`unrecognised type at ${getPos(type.pos)}: ${type.getText(sourceFile)}`
121+
);
101122
}
102123

103124
function convertTupleMember(node: ts.TypeNode | ts.NamedTupleMember): Field {
@@ -111,15 +132,19 @@ for (const filePath of filePaths) {
111132
}
112133
}
113134

114-
function convertTypeParams(nodes?: ts.NodeArray<ts.TypeParameterDeclaration>): TypeParam[] | undefined {
135+
function convertTypeParams(
136+
nodes?: ts.NodeArray<ts.TypeParameterDeclaration>
137+
): TypeParam[] | undefined {
115138
return nodes?.map((node) => ({
116139
name: node.name.getText(sourceFile),
117140
constraint: node.constraint && convertType(node.constraint),
118141
default: node.default && convertType(node.default),
119142
}));
120143
}
121144

122-
function convertCommentText(text?: string | ts.NodeArray<ts.JSDocText | ts.JSDocLink>): string | undefined {
145+
function convertCommentText(
146+
text?: string | ts.NodeArray<ts.JSDocText | ts.JSDocLink>
147+
): string | undefined {
123148
if (text === undefined || typeof text === "string") {
124149
return text?.toString();
125150
} else {
@@ -186,7 +211,11 @@ for (const filePath of filePaths) {
186211
}
187212

188213
function convertMethod(
189-
node: ts.MethodSignature | ts.MethodDeclaration | ts.FunctionDeclaration | ts.ConstructSignatureDeclaration
214+
node:
215+
| ts.MethodSignature
216+
| ts.MethodDeclaration
217+
| ts.FunctionDeclaration
218+
| ts.ConstructSignatureDeclaration
190219
): Field {
191220
const defaultName = ts.isConstructSignatureDeclaration(node) ? "new" : "";
192221
const name = node.name?.getText(sourceFile) ?? defaultName;
@@ -199,7 +228,9 @@ for (const filePath of filePaths) {
199228
return { name, type, ...meta, typeparams };
200229
}
201230

202-
function convertProperty(node: ts.PropertySignature | ts.PropertyDeclaration): Field {
231+
function convertProperty(
232+
node: ts.PropertySignature | ts.PropertyDeclaration
233+
): Field {
203234
const name = node.name.getText(sourceFile);
204235
const type = convertType(node.type);
205236
type.optional = node.questionToken && true;
@@ -218,7 +249,11 @@ for (const filePath of filePaths) {
218249
if (ts.isConstructorDeclaration(node)) {
219250
return convertConstructor(node);
220251
}
221-
if (ts.isMethodSignature(node) || ts.isMethodDeclaration(node) || ts.isConstructSignatureDeclaration(node)) {
252+
if (
253+
ts.isMethodSignature(node) ||
254+
ts.isMethodDeclaration(node) ||
255+
ts.isConstructSignatureDeclaration(node)
256+
) {
222257
return convertMethod(node);
223258
}
224259
if (ts.isPropertySignature(node) || ts.isPropertyDeclaration(node)) {
@@ -227,7 +262,9 @@ for (const filePath of filePaths) {
227262
if (ts.isIndexSignatureDeclaration(node)) {
228263
return convertIndexSignature(node);
229264
}
230-
throw new TypeError(`unrecognised member at ${getPos(node.pos)}: ${node.getText(sourceFile)}`);
265+
throw new TypeError(
266+
`unrecognised member at ${getPos(node.pos)}: ${node.getText(sourceFile)}`
267+
);
231268
}
232269

233270
function convertHeritageClause(node: ts.HeritageClause): Type[] {
@@ -237,7 +274,9 @@ for (const filePath of filePaths) {
237274
}));
238275
}
239276

240-
function convertHeritageClauses(nodes?: ts.NodeArray<ts.HeritageClause>): Pick<Class, "extends" | "implements"> {
277+
function convertHeritageClauses(
278+
nodes?: ts.NodeArray<ts.HeritageClause>
279+
): Pick<Class, "extends" | "implements"> {
241280
const heritage: Pick<Class, "extends" | "implements"> = {};
242281
for (const node of nodes ?? []) {
243282
if (node.token === ts.SyntaxKind.ExtendsKeyword) {
@@ -337,7 +376,11 @@ for (const filePath of filePaths) {
337376
} else if (ts.isVariableStatement(node)) {
338377
return convertVariable(node);
339378
}
340-
throw new TypeError(`unrecognised statement at ${getPos(node.pos)}: ${node.getText(sourceFile)}`);
379+
throw new TypeError(
380+
`unrecognised statement at ${getPos(node.pos)}: ${node.getText(
381+
sourceFile
382+
)}`
383+
);
341384
}
342385

343386
/**
@@ -355,20 +398,28 @@ for (const filePath of filePaths) {
355398
assert.strictEqual(node1.name, node2.name);
356399

357400
if (node1.kind !== node2.kind) {
358-
throw new TypeError(`Conflicting types for ${node1.name}: ${node1.kind} vs ${node2.kind}`);
401+
throw new TypeError(
402+
`Conflicting types for ${node1.name}: ${node1.kind} vs ${node2.kind}`
403+
);
359404
}
360405
switch (node1.kind) {
361406
case "typedef":
362407
case "function":
363408
case "variable":
364-
throw new TypeError(`Two ${node1.kind}s with the same name ${node1.name}`);
409+
throw new TypeError(
410+
`Two ${node1.kind}s with the same name ${node1.name}`
411+
);
365412
case "struct":
366413
case "class":
367414
if (node1.extends !== node2.extends) {
368-
throw new TypeError(`Conflicting extends values for multiple overrides of ${node1.name}`);
415+
throw new TypeError(
416+
`Conflicting extends values for multiple overrides of ${node1.name}`
417+
);
369418
}
370419
if (node1.implements !== node2.implements) {
371-
throw new TypeError(`Conflicting extends values for multiple overrides of ${node1.name}`);
420+
throw new TypeError(
421+
`Conflicting extends values for multiple overrides of ${node1.name}`
422+
);
372423
}
373424
for (const memberToMerge of node2.members) {
374425
node1.members.push(memberToMerge);
@@ -398,4 +449,8 @@ for (const filePath of filePaths) {
398449
}
399450
}
400451

401-
fs.writeFileSync("overrides.json", JSON.stringify(declarations, null, 2), "utf8");
452+
fs.writeFileSync(
453+
"overrides.json",
454+
JSON.stringify(declarations, null, 2),
455+
"utf8"
456+
);

0 commit comments

Comments
 (0)