Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,9 @@ __pycache__/
# !tools/packages.config

generated/
lib/
inputfiles/browser.webidl.json
.vscode/*
!.vscode/launch.template.json
yarn.lock
TypeScript
deploy/generated
deploy/generated
2 changes: 1 addition & 1 deletion deploy/deployChangedPackages.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should really just move these to src tbh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't properly review this at the moment but should be able to do so in a few days

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not strictly needed here and can happen separately IMO

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as path from "path";
import { spawnSync } from "child_process";
import { Octokit } from "@octokit/rest";
import { printUnifiedDiff } from "print-diff";
import { generateChangelogFrom } from "../lib/changelog.js";
import { generateChangelogFrom } from "../src/changelog.ts";
import { packages } from "./createTypesPackages.js";
import { fileURLToPath } from "node:url";
import fetch from "node-fetch";
Expand Down
3 changes: 2 additions & 1 deletion deploy/jsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"module": "esnext", // es2022
"moduleResolution": "node",
"strict": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"allowImportingTsExtensions": true
}
}
2 changes: 1 addition & 1 deletion deploy/versionChangelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// npm run ts-changelog @types/web 0.0.1 0.0.3

import { gitShowFile, generateChangelogFrom } from "../lib/changelog.js";
import { gitShowFile, generateChangelogFrom } from "../src/changelog.ts";
import { packages } from "./createTypesPackages.js";
import { basename } from "path";

Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "@typescript/dom-lib-generator",
"version": "0.0.1",
"private": true,
"engines": {
"node": ">= 22.18.0"
},
"description": "Provides TypeScript types for the latest web APIs.",
"keywords": [
"typescript",
Expand All @@ -12,15 +15,15 @@
"worklet"
],
"scripts": {
"build": "tsc && node ./lib/build.js",
"build": "node ./src/build.ts",
"baseline-accept": "cpx \"generated\\**\" baselines\\",
"lint": "eslint --max-warnings 0 src deploy/*.js scripts && tsc -p deploy/jsconfig.json",
"lint-fix": "eslint --max-warnings 0 src deploy/*.js scripts --fix",
"test": "npm run build && npm run lint && node ./lib/test.js && node ./unittests/index.js",
"changelog": "tsc && node ./lib/changelog.js",
"test": "npm run build && npm run lint && node ./src/test.ts && node ./unittests/index.js",
"changelog": "node ./src/changelog.ts",
"ts-changelog": "node ./deploy/versionChangelog.js",
"migrate": "node ./deploy/migrate.js",
"version": "npm i && tsc && node ./lib/version.js",
"version": "npm i && node ./src/version.ts",
"generate": "npm run build && npm run baseline-accept"
},
"author": {
Expand Down
22 changes: 11 additions & 11 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as Browser from "./build/types.js";
import type * as Browser from "./build/types.ts";
import { promises as fs } from "fs";
import { merge, resolveExposure, arrayToMap } from "./build/helpers.js";
import { type CompilerBehavior, emitWebIdl } from "./build/emitter.js";
import { convert } from "./build/widlprocess.js";
import { getExposedTypes } from "./build/expose.js";
import { merge, resolveExposure, arrayToMap } from "./build/helpers.ts";
import { type CompilerBehavior, emitWebIdl } from "./build/emitter.ts";
import { convert } from "./build/widlprocess.ts";
import { getExposedTypes } from "./build/expose.ts";
import {
getDeprecationData,
getDocsData,
getRemovalData,
} from "./build/bcd.js";
import { getInterfaceElementMergeData } from "./build/webref/elements.js";
import { getInterfaceToEventMap } from "./build/webref/events.js";
import { getWebidls } from "./build/webref/idl.js";
} from "./build/bcd.ts";
import { getInterfaceElementMergeData } from "./build/webref/elements.ts";
import { getInterfaceToEventMap } from "./build/webref/events.ts";
import { getWebidls } from "./build/webref/idl.ts";
import jsonc from "jsonc-parser";
import { generateDescriptions } from "./build/mdn-comments.js";
import readPatches from "./build/patches.js";
import { generateDescriptions } from "./build/mdn-comments.ts";
import readPatches from "./build/patches.ts";

function mergeNamesakes(filtered: Browser.WebIdl) {
const targets = [
Expand Down
10 changes: 5 additions & 5 deletions src/build/bcd.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as Browser from "./types.js";
import {
import * as Browser from "./types.ts";
import type {
CompatStatement,
SimpleSupportStatement,
SupportBlock,
} from "@mdn/browser-compat-data/types";
import { forceKeepAlive } from "./bcd/keep-alive.js";
import { mapToBcdCompat } from "./bcd/mapper.js";
import { hasStableImplementation } from "./bcd/stable.js";
import { forceKeepAlive } from "./bcd/keep-alive.ts";
import { mapToBcdCompat } from "./bcd/mapper.ts";
import { hasStableImplementation } from "./bcd/stable.ts";

function hasMultipleImplementations(support: SupportBlock, prefix?: string) {
const hasStableImpl = (
Expand Down
10 changes: 5 additions & 5 deletions src/build/bcd/mapper.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
import type {
BrowserName,
CompatStatement,
Identifier,
SimpleSupportStatement,
} from "bcd-idl-mapper";
import api from "bcd-idl-mapper";
import * as Browser from "../types.js";
import { filterMapRecord, isEmptyRecord } from "../utils/record.js";
import { mapDefined } from "../helpers.js";
import { hasStableImplementation } from "./stable.js";
import type * as Browser from "../types.ts";
import { filterMapRecord, isEmptyRecord } from "../utils/record.ts";
import { mapDefined } from "../helpers.ts";
import { hasStableImplementation } from "./stable.ts";

interface DataToMap {
key: string;
Expand Down
2 changes: 1 addition & 1 deletion src/build/bcd/stable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SimpleSupportStatement } from "@mdn/browser-compat-data/types";
import type { SimpleSupportStatement } from "@mdn/browser-compat-data/types";

export function hasStableImplementation(
browser: SimpleSupportStatement | SimpleSupportStatement[] | undefined,
Expand Down
34 changes: 14 additions & 20 deletions src/build/emitter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Browser from "./types.js";
import * as Browser from "./types.ts";
import {
mapToArray,
distinct,
Expand All @@ -10,15 +10,11 @@ import {
baseTypeConversionMap,
assertUnique,
arrayBufferViewTypes,
} from "./helpers.js";
import { collectLegacyNamespaceTypes } from "./legacy-namespace.js";
} from "./helpers.ts";
import { collectLegacyNamespaceTypes } from "./legacy-namespace.ts";

/// Decide which members of a function to emit
enum EmitScope {
StaticOnly,
InstanceOnly,
All,
}
type EmitScope = "StaticOnly" | "InstanceOnly" | "All";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just use an as const object and the keyof typeof trick

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmmmmmmmmmmmmmm..................... I kinda prefer this way as it's simpler and it's what we do in web APIs 🤔


const tsKeywords = new Set(["default", "delete", "continue"]);
const extendConflictsBaseTypes: Record<
Expand All @@ -38,9 +34,7 @@ const namespacesAsInterfaces = ["console"];
// Used to decide if a member should be emitted given its static property and
// the intended scope level.
function matchScope(scope: EmitScope, x: { static?: boolean }) {
return (
scope === EmitScope.All || (scope === EmitScope.StaticOnly) === !!x.static
);
return scope === "All" || (scope === "StaticOnly") === !!x.static;
}

/// Parameter cannot be named "default" in JavaScript/Typescript so we need to rename it.
Expand Down Expand Up @@ -900,7 +894,7 @@ export function emitWebIdl(
if (
p.name === "name" &&
i.name === "Window" &&
emitScope === EmitScope.InstanceOnly &&
emitScope === "InstanceOnly" &&
prefix === "declare var "
) {
printer.printLine("/** @deprecated */");
Expand Down Expand Up @@ -1114,7 +1108,7 @@ export function emitWebIdl(
.sort(compareName)
.forEach((m) => emitMethod(prefix, m, conflictedMembers));
}
if (i.anonymousMethods && emitScope === EmitScope.InstanceOnly) {
if (i.anonymousMethods && emitScope === "InstanceOnly") {
const stringifier = i.anonymousMethods.method.find((m) => m.stringifier);
if (stringifier) {
printer.printLine("toString(): string;");
Expand Down Expand Up @@ -1163,15 +1157,15 @@ export function emitWebIdl(
? "declare function "
: "";
emitMethods(methodPrefix, emitScope, i, conflictedMembers);
if (emitScope === EmitScope.InstanceOnly) {
if (emitScope === "InstanceOnly") {
emitIteratorForEach(i);
}
}

/// Emit all members of every interfaces at the root level.
/// Called only once on the global polluter object
function emitAllMembers(i: Browser.Interface) {
emitMembers(/*prefix*/ "declare var ", EmitScope.InstanceOnly, i);
emitMembers(/*prefix*/ "declare var ", "InstanceOnly", i);

for (const relatedIName of iNameToIDependList[i.name]) {
const i = allInterfacesMap[relatedIName];
Expand Down Expand Up @@ -1275,7 +1269,7 @@ export function emitWebIdl(
emitConstants(parent);
}
}
emitMembers(/*prefix*/ "", EmitScope.StaticOnly, i);
emitMembers(/*prefix*/ "", "StaticOnly", i);

printer.decreaseIndent();
printer.printLine("};");
Expand Down Expand Up @@ -1493,10 +1487,10 @@ export function emitWebIdl(
emitInterfaceDeclaration(i);
printer.increaseIndent();

emitMembers(/*prefix*/ "", EmitScope.InstanceOnly, i);
emitMembers(/*prefix*/ "", "InstanceOnly", i);
emitConstants(i);
emitEventHandlers(/*prefix*/ "", i);
emitIndexers(EmitScope.InstanceOnly, i);
emitIndexers("InstanceOnly", i);

printer.decreaseIndent();
printer.printLine("}");
Expand Down Expand Up @@ -1556,8 +1550,8 @@ export function emitWebIdl(
namespace.nested.typedefs.sort(compareName).forEach(emitTypeDef);
}

emitProperties("var ", EmitScope.InstanceOnly, namespace);
emitMethods("function ", EmitScope.InstanceOnly, namespace, new Set());
emitProperties("var ", "InstanceOnly", namespace);
emitMethods("function ", "InstanceOnly", namespace, new Set());

printer.decreaseIndent();
printer.printLine("}");
Expand Down
6 changes: 3 additions & 3 deletions src/build/expose.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Browser from "./types.js";
import * as Browser from "./types.ts";
import {
getEmptyWebIDL,
deepFilter,
Expand All @@ -7,8 +7,8 @@ import {
filterProperties,
mapToArray,
arrayToMap,
} from "./helpers.js";
import { isEmptyRecord } from "./utils/record.js";
} from "./helpers.ts";
import { isEmptyRecord } from "./utils/record.ts";

class LoggedSet extends Set<string> {
private unvisited: Set<string>;
Expand Down
2 changes: 1 addition & 1 deletion src/build/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Browser from "./types.js";
import * as Browser from "./types.ts";

// Extended types used but not defined in the spec
export const arrayBufferViewTypes = new Set([
Expand Down
4 changes: 2 additions & 2 deletions src/build/legacy-namespace.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Browser from "./types.js";
import { mapToArray, arrayToMap } from "./helpers.js";
import * as Browser from "./types.ts";
import { mapToArray, arrayToMap } from "./helpers.ts";

export function collectLegacyNamespaceTypes(
webidl: Browser.WebIdl,
Expand Down
2 changes: 1 addition & 1 deletion src/build/mdn-comments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFile } from "fs/promises";
import { hyphenToCamelCase } from "./utils/css.js";
import { hyphenToCamelCase } from "./utils/css.ts";

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

Expand Down
6 changes: 3 additions & 3 deletions src/build/patches.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parse, type Value, type Node, Document } from "kdljs";
import { parse, type Value, type Node, type Document } from "kdljs";
import type {
Enum,
Event,
Expand All @@ -11,9 +11,9 @@ import type {
Dictionary,
Member,
Signature,
} from "./types.js";
} from "./types.ts";
import { readdir, readFile } from "fs/promises";
import { merge } from "./helpers.js";
import { merge } from "./helpers.ts";

type DeepPartial<T> = T extends object
? { [K in keyof T]?: DeepPartial<T[K]> }
Expand Down
2 changes: 1 addition & 1 deletion src/build/webref/css.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hyphenToCamelCase } from "../utils/css.js";
import { hyphenToCamelCase } from "../utils/css.ts";

export function generateWebIdlFromCssProperties(properties: string[]): string {
return `partial interface CSSStyleProperties {${properties
Expand Down
6 changes: 3 additions & 3 deletions src/build/webref/elements.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { listAll, Element as WebrefElement } from "@webref/elements";
import { Interface, WebIdl } from "../types.js";
import { addToArrayMap } from "../utils/map.js";
import { listAll, type Element as WebrefElement } from "@webref/elements";
import type { Interface, WebIdl } from "../types.ts";
import { addToArrayMap } from "../utils/map.ts";

async function getInterfaceToElementMap(): Promise<
Map<string, WebrefElement[]>
Expand Down
2 changes: 1 addition & 1 deletion src/build/webref/events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { listAll } from "@webref/events";
import { addToNestedMap } from "../utils/map.js";
import { addToNestedMap } from "../utils/map.ts";

export async function getInterfaceToEventMap(): Promise<
Map<string, Map<string, string>>
Expand Down
2 changes: 1 addition & 1 deletion src/build/webref/idl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { listAll as listAllIdl } from "@webref/idl";
import { listAll as listAllCss } from "@webref/css";
import { generateWebIdlFromCssProperties } from "./css.js";
import { generateWebIdlFromCssProperties } from "./css.ts";

export async function getWebidls(): Promise<Map<string, string>> {
const idl = await listAllIdl();
Expand Down
4 changes: 2 additions & 2 deletions src/build/widlprocess.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as webidl2 from "webidl2";
import * as Browser from "./types.js";
import { getEmptyWebIDL } from "./helpers.js";
import * as Browser from "./types.ts";
import { getEmptyWebIDL } from "./helpers.ts";

export function convert(text: string, commentMap: Record<string, string>) {
const rootTypes = webidl2.parse(text);
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execSync } from "child_process";
import { readFile, writeFile } from "fs/promises";
import { generateDefaultFromRecentTag } from "./changelog.js";
import { generateDefaultFromRecentTag } from "./changelog.ts";

const output = generateDefaultFromRecentTag();

Expand Down
30 changes: 15 additions & 15 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"compilerOptions": {
"target": "es2022",
"module": "nodenext",
"moduleResolution": "nodenext",
"outDir": "./lib",
"strict": true,
"esModuleInterop": true,
"sourceMap": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true
},
"include": [
"./src"
]
"compilerOptions": {
"target": "es2022",
"module": "nodenext",
"moduleResolution": "nodenext",
"outDir": "./lib",
"strict": true,
"esModuleInterop": true,
"sourceMap": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"noEmit": true,
},
"include": ["./src"],
}