Skip to content

Commit 17ac2ac

Browse files
Bashamegasaschanaz
andauthored
Comments for css (microsoft#2218)
Co-authored-by: Kagami Sascha Rosylight <saschanaz@outlook.com>
1 parent 7179603 commit 17ac2ac

File tree

7 files changed

+11691
-1803
lines changed

7 files changed

+11691
-1803
lines changed

baselines/dom.generated.d.ts

Lines changed: 2248 additions & 448 deletions
Large diffs are not rendered by default.

baselines/ts5.5/dom.generated.d.ts

Lines changed: 2248 additions & 448 deletions
Large diffs are not rendered by default.

baselines/ts5.6/dom.generated.d.ts

Lines changed: 2248 additions & 448 deletions
Large diffs are not rendered by default.

baselines/ts5.9/dom.generated.d.ts

Lines changed: 2248 additions & 448 deletions
Large diffs are not rendered by default.

inputfiles/mdn.json

Lines changed: 2680 additions & 0 deletions
Large diffs are not rendered by default.

scripts/fetch-mdn.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ const filtered = Object.values(data)
1717
const path = entry.mdn_url;
1818
return (
1919
path.startsWith("/en-US/docs/Web/API/") ||
20-
path.startsWith("/en-US/docs/WebAssembly/Reference/JavaScript_interface/")
20+
path.startsWith(
21+
"/en-US/docs/WebAssembly/Reference/JavaScript_interface/",
22+
) ||
23+
path.startsWith("/en-US/docs/Web/CSS/Reference/Properties/")
2124
);
2225
})
2326
.map(({ mdn_url, pageType, summary }) => ({

src/build/mdn-comments.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { readFile } from "fs/promises";
2+
import { hyphenToCamelCase } from "./utils/css.js";
23

34
const inputFile = new URL("../../inputfiles/mdn.json", import.meta.url);
45

56
// Valid subdirectories for our use case
67
const subdirectories = [
78
"Web/API/",
89
"WebAssembly/Reference/JavaScript_interface/",
10+
"Web/CSS/Reference/Properties/",
911
];
1012

1113
const paths: Record<string, string[]> = {
14+
"css-property": ["CSSStyleProperties", "properties", "property"],
15+
"css-shorthand-property": ["CSSStyleProperties", "properties", "property"],
1216
"web-api-instance-property": ["properties", "property"],
1317
"web-api-static-property": ["properties", "property"],
1418
"web-api-instance-method": ["methods", "method"],
@@ -49,15 +53,10 @@ function insertComment(
4953
slug: string[],
5054
summary: string,
5155
path: string[],
56+
name: string,
5257
) {
53-
if (!path.length) {
54-
const iface = ensureLeaf(root, slug);
55-
iface.comment = summary;
56-
} else {
57-
const [ifaceName, memberName] = slug;
58-
const target = ensureLeaf(root, [ifaceName, ...path, memberName]);
59-
target.comment = summary;
60-
}
58+
const target = ensureLeaf(root, [...slug.slice(0, -1), ...path, name]);
59+
target.comment = summary;
6160
}
6261

6362
function generateComment(summary: string, name: string): string | undefined {
@@ -91,11 +90,17 @@ export async function generateDescriptions(): Promise<{
9190
if (!slugArr.length || !path) {
9291
continue;
9392
}
94-
const comment = generateComment(entry.summary, slugArr.at(-1)!);
93+
const leaf = slugArr.at(-1)!;
94+
const name = ["css-property", "css-shorthand-property"].includes(
95+
entry.pageType,
96+
)
97+
? hyphenToCamelCase(leaf)
98+
: leaf;
99+
const comment = generateComment(entry.summary, name);
95100
if (!comment) {
96101
continue;
97102
}
98-
insertComment(results, slugArr, comment, path);
103+
insertComment(results, slugArr, comment, path, name);
99104
}
100105
return { interfaces: { interface: results } };
101106
}

0 commit comments

Comments
 (0)