Skip to content

Add more comments #1993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
61d9bfe
refactor: optimize file system operations by removing async/await for…
Bashamega Apr 23, 2025
7b92b7d
chore: better naming
Bashamega Apr 23, 2025
746f705
feat: extract summary from MDN comments for better documentation
Bashamega Apr 23, 2025
9521a10
generate
Bashamega Apr 23, 2025
a995e00
remove comments
Bashamega Apr 23, 2025
ca08f27
Remove hashing
Bashamega Apr 23, 2025
7f82e1f
regenerate
Bashamega Apr 23, 2025
9afe136
-
Bashamega Apr 23, 2025
a2b7a93
feat: comments for iterator
Bashamega Apr 24, 2025
d6d08f7
Merge branch 'microsoft:main' into descriptions
Bashamega Apr 24, 2025
d65d812
generate
Bashamega Apr 24, 2025
04ba40c
-
Bashamega Apr 24, 2025
7da9e85
-
Bashamega Apr 24, 2025
576b872
-
Bashamega Apr 24, 2025
16ef393
-
Bashamega Apr 24, 2025
5110391
-
Bashamega Apr 24, 2025
63c359d
generate
Bashamega Apr 24, 2025
7a40173
clean
Bashamega Apr 24, 2025
fdddfa6
remove await
Bashamega Apr 25, 2025
968a4e4
simplify
Bashamega Apr 25, 2025
0123276
refactor: extract title generation logic into a separate function
Bashamega Apr 25, 2025
e146dfe
refactor: remove descriptions parameter from emitFlavor and emitWebId…
Bashamega Apr 27, 2025
d97bcb7
-
Bashamega Apr 27, 2025
de83ebc
Merge branch 'microsoft:main' into descriptions
Bashamega Apr 27, 2025
7386df6
generate
Bashamega Apr 27, 2025
619d3c2
merge branches
Bashamega Apr 28, 2025
7d3c431
refactor: optimize file processing in generateDescriptions function u…
Bashamega Apr 28, 2025
3c7d15a
Merge branches
Bashamega Apr 29, 2025
ebfc8c4
Merge branch 'microsoft:main' into descriptions
Bashamega May 4, 2025
ff14106
Update
Bashamega May 4, 2025
88daf24
-
Bashamega May 4, 2025
09a8071
merge
Bashamega May 14, 2025
53d05d3
-
Bashamega May 14, 2025
155f013
-
Bashamega May 14, 2025
fae5ec1
-
Bashamega May 14, 2025
3130a7a
.
Bashamega May 15, 2025
79d9131
use leaf
Bashamega May 15, 2025
615bdb5
Merge branch 'microsoft:main' into descriptions
Bashamega May 17, 2025
ea052dc
-
Bashamega May 21, 2025
bff888b
Merge branch 'descriptions' of https://github.com/Bashamega/TypeScrip…
May 21, 2025
11d8d3e
Update mdn-comments.ts
Bashamega May 21, 2025
94d22b9
Refactor merge function to support optional parameter and update merg…
Bashamega May 28, 2025
d2ee6f5
Merge branch 'descriptions' of https://github.com/Bashamega/TypeScrip…
Bashamega May 28, 2025
241a83c
format
Bashamega May 28, 2025
9e7d2f9
-
Bashamega May 29, 2025
32fee24
Update emitNonCallbackInterfaces to include interfaces without names …
Bashamega May 29, 2025
12a3cb9
-
Bashamega May 29, 2025
262a699
-
Bashamega May 29, 2025
63c7cdb
-
Bashamega May 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ If you are familiar with Web IDL, you may also want to check whether the upstrea
- `addedTypes.jsonc`: types that should exist but are missing from the spec data.
- `overridingTypes.jsonc`: types that are defined in the spec but have TypeScript-friendly modifications in the json files.
- `removedTypes.jsonc`: types that are defined in the spec but should be removed.
- `comments.json`: comment strings to be embedded in the generated .js files.
- `deprecatedMessage.json`: the reason why one type is deprecated. The reason why it is a separate file rather than merge in comment.json is mdn/apiDescriptions.json would also possibly be deprecated.

## Deployment to TypeScript
Expand Down
781 changes: 646 additions & 135 deletions baselines/audioworklet.generated.d.ts

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions baselines/audioworklet.iterable.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ interface URLSearchParamsIterator<T> extends IteratorObject<T, BuiltinIteratorRe

interface URLSearchParams {
[Symbol.iterator](): URLSearchParamsIterator<[string, string]>;
/** Returns an array of key, value pairs for every entry in the search params. */
entries(): URLSearchParamsIterator<[string, string]>;
/** Returns a list of keys in the search params. */
keys(): URLSearchParamsIterator<string>;
/** Returns a list of values in the search params. */
values(): URLSearchParamsIterator<string>;
}
22,926 changes: 18,500 additions & 4,426 deletions baselines/dom.generated.d.ts

Large diffs are not rendered by default.

405 changes: 325 additions & 80 deletions baselines/dom.iterable.generated.d.ts

Large diffs are not rendered by default.

6,467 changes: 5,381 additions & 1,086 deletions baselines/serviceworker.generated.d.ts

Large diffs are not rendered by default.

363 changes: 295 additions & 68 deletions baselines/serviceworker.iterable.generated.d.ts

Large diffs are not rendered by default.

6,141 changes: 5,110 additions & 1,031 deletions baselines/sharedworker.generated.d.ts

Large diffs are not rendered by default.

363 changes: 295 additions & 68 deletions baselines/sharedworker.iterable.generated.d.ts

Large diffs are not rendered by default.

781 changes: 646 additions & 135 deletions baselines/ts5.5/audioworklet.generated.d.ts

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions baselines/ts5.5/audioworklet.iterable.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ interface MessageEvent<T = any> {

interface URLSearchParams {
[Symbol.iterator](): IterableIterator<[string, string]>;
/** Returns an array of key, value pairs for every entry in the search params. */
entries(): IterableIterator<[string, string]>;
/** Returns a list of keys in the search params. */
keys(): IterableIterator<string>;
/** Returns a list of values in the search params. */
values(): IterableIterator<string>;
}
22,924 changes: 18,499 additions & 4,425 deletions baselines/ts5.5/dom.generated.d.ts

Large diffs are not rendered by default.

405 changes: 325 additions & 80 deletions baselines/ts5.5/dom.iterable.generated.d.ts

Large diffs are not rendered by default.

6,467 changes: 5,381 additions & 1,086 deletions baselines/ts5.5/serviceworker.generated.d.ts

Large diffs are not rendered by default.

363 changes: 295 additions & 68 deletions baselines/ts5.5/serviceworker.iterable.generated.d.ts

Large diffs are not rendered by default.

6,141 changes: 5,110 additions & 1,031 deletions baselines/ts5.5/sharedworker.generated.d.ts

Large diffs are not rendered by default.

363 changes: 295 additions & 68 deletions baselines/ts5.5/sharedworker.iterable.generated.d.ts

Large diffs are not rendered by default.

7,291 changes: 6,067 additions & 1,224 deletions baselines/ts5.5/webworker.generated.d.ts

Large diffs are not rendered by default.

363 changes: 295 additions & 68 deletions baselines/ts5.5/webworker.iterable.generated.d.ts

Large diffs are not rendered by default.

781 changes: 646 additions & 135 deletions baselines/ts5.6/audioworklet.generated.d.ts

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions baselines/ts5.6/audioworklet.iterable.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ interface URLSearchParamsIterator<T> extends IteratorObject<T, BuiltinIteratorRe

interface URLSearchParams {
[Symbol.iterator](): URLSearchParamsIterator<[string, string]>;
/** Returns an array of key, value pairs for every entry in the search params. */
entries(): URLSearchParamsIterator<[string, string]>;
/** Returns a list of keys in the search params. */
keys(): URLSearchParamsIterator<string>;
/** Returns a list of values in the search params. */
values(): URLSearchParamsIterator<string>;
}
22,926 changes: 18,500 additions & 4,426 deletions baselines/ts5.6/dom.generated.d.ts

Large diffs are not rendered by default.

405 changes: 325 additions & 80 deletions baselines/ts5.6/dom.iterable.generated.d.ts

Large diffs are not rendered by default.

6,467 changes: 5,381 additions & 1,086 deletions baselines/ts5.6/serviceworker.generated.d.ts

Large diffs are not rendered by default.

363 changes: 295 additions & 68 deletions baselines/ts5.6/serviceworker.iterable.generated.d.ts

Large diffs are not rendered by default.

6,141 changes: 5,110 additions & 1,031 deletions baselines/ts5.6/sharedworker.generated.d.ts

Large diffs are not rendered by default.

363 changes: 295 additions & 68 deletions baselines/ts5.6/sharedworker.iterable.generated.d.ts

Large diffs are not rendered by default.

7,291 changes: 6,067 additions & 1,224 deletions baselines/ts5.6/webworker.generated.d.ts

Large diffs are not rendered by default.

363 changes: 295 additions & 68 deletions baselines/ts5.6/webworker.iterable.generated.d.ts

Large diffs are not rendered by default.

7,291 changes: 6,067 additions & 1,224 deletions baselines/webworker.generated.d.ts

Large diffs are not rendered by default.

363 changes: 295 additions & 68 deletions baselines/webworker.iterable.generated.d.ts

Large diffs are not rendered by default.

1,824 changes: 0 additions & 1,824 deletions inputfiles/comments.json

This file was deleted.

12 changes: 5 additions & 7 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getInterfaceElementMergeData } from "./build/webref/elements.js";
import { getInterfaceToEventMap } from "./build/webref/events.js";
import { getWebidls } from "./build/webref/idl.js";
import jsonc from "jsonc-parser";
import { generateDescription } from "./build/mdn-comments.js";
import { generateDescriptions } from "./build/mdn-comments.js";

function mergeNamesakes(filtered: Browser.WebIdl) {
const targets = [
Expand Down Expand Up @@ -50,7 +50,7 @@ async function emitFlavor(
mergeNamesakes(exposed);
exposed.events = webidl.events;

const result = emitWebIdl(
const result = await emitWebIdl(
exposed,
options.global[0],
"",
Expand All @@ -61,7 +61,7 @@ async function emitFlavor(
result,
);

const iterators = emitWebIdl(
const iterators = await emitWebIdl(
exposed,
options.global[0],
"sync",
Expand All @@ -72,7 +72,7 @@ async function emitFlavor(
iterators,
);

const asyncIterators = emitWebIdl(
const asyncIterators = await emitWebIdl(
exposed,
options.global[0],
"async",
Expand All @@ -93,9 +93,8 @@ async function emitDom() {

const overriddenItems = await readInputJSON("overridingTypes.jsonc");
const addedItems = await readInputJSON("addedTypes.jsonc");
const comments = await readInputJSON("comments.json");
const deprecatedInfo = await readInputJSON("deprecatedMessage.json");
const documentationFromMDN = await generateDescription();
const documentationFromMDN = await generateDescriptions();
const removedItems = await readInputJSON("removedTypes.jsonc");

async function readInputJSON(filename: string) {
Expand Down Expand Up @@ -227,7 +226,6 @@ async function emitDom() {
webidl = mergeApiDescriptions(webidl, documentationFromMDN);
webidl = merge(webidl, addedItems);
webidl = merge(webidl, overriddenItems);
webidl = merge(webidl, comments);
webidl = mergeDeprecatedMessage(webidl, deprecatedInfo);
for (const name in webidl.interfaces!.interface) {
const i = webidl.interfaces!.interface[name];
Expand Down
6 changes: 5 additions & 1 deletion src/build/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
arrayBufferViewTypes,
} from "./helpers.js";
import { collectLegacyNamespaceTypes } from "./legacy-namespace.js";
import { extractSummaryFromFile } from "./mdn-comments.js";

/// Decide which members of a function to emit
enum EmitScope {
Expand Down Expand Up @@ -906,7 +907,10 @@ export function emitWebIdl(
comments.push("Available only in secure contexts.");
}
if (entity.mdnUrl) {
if (comments.length > 0) comments.push("");
if (comments.length == 0) {
comments.push(extractSummaryFromFile(entity.mdnUrl));
}
comments.push("");
comments.push(`[MDN Reference](${entity.mdnUrl})`);
}

Expand Down
25 changes: 24 additions & 1 deletion src/build/mdn-comments.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { readFileSync } from "fs";
import fs from "fs/promises";
import { basename } from "path";

Expand Down Expand Up @@ -92,7 +93,7 @@ async function getIndexMdContents(
return results;
}

export async function generateDescription(): Promise<Record<string, string>> {
export async function generateDescriptions(): Promise<Record<string, string>> {
const stats = await fs.stat(basePath);
if (!stats.isDirectory()) {
throw new Error(
Expand All @@ -110,3 +111,25 @@ export async function generateDescription(): Promise<Record<string, string>> {

return {};
}
export function extractSummaryFromFile(url: string): string {
const relativePath = url
.replace("https://developer.mozilla.org/docs/", "")
.split("#")[0]
.toLowerCase();

const filePath = new URL(
`../../inputfiles/mdn/files/en-us/${relativePath}/index.md`,
import.meta.url,
);

try {
const content = readFileSync(filePath, "utf-8");
return extractSummary(content);
} catch (error) {
console.error(
`Failed to read or extract summary from: ${filePath.href}`,
error,
);
return "";
}
}