Skip to content
Merged
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
24 changes: 18 additions & 6 deletions deploy/createTypesPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ const go = async () => {

// Migrate in the template files
for (const templateFile of fs.readdirSync(templateDir)) {
if (templateFile.startsWith(".")) continue;
if (templateFile.startsWith(".")) {
continue;
}

const templatedFile = new URL(templateFile, templateDir);
fs.copyFileSync(templatedFile, new URL(templateFile, packagePath));
Expand Down Expand Up @@ -242,15 +244,21 @@ function prependAutoImports(pkg, packagePath) {
const groups = new Map();
for (const file of pkg.files) {
let files = groups.get(file.group);
if (!files) groups.set(file.group, (files = []));
if (!files) {
groups.set(file.group, (files = []));
}
files.push(file);
}
for (const files of groups.values()) {
const indexFile = files.find((file) => file.index);
if (!indexFile) continue;
if (!indexFile) {
continue;
}

const index = new URL(indexFile.to, packagePath);
if (!fs.existsSync(index)) continue;
if (!fs.existsSync(index)) {
continue;
}

const toPrepend = files
.filter((f) => !!f.autoImport)
Expand All @@ -270,8 +278,12 @@ function prependAutoImports(pkg, packagePath) {
* @param {URL} to
*/
function relativeUrl(from, to) {
if (from.origin !== to.origin) return to.toString();
if (!from.pathname.endsWith("/")) from = new URL("./", from);
if (from.origin !== to.origin) {
return to.toString();
}
if (!from.pathname.endsWith("/")) {
from = new URL("./", from);
}
const relative = path.posix.relative(from.pathname, to.pathname);
return path.isAbsolute(relative) ||
relative.startsWith("../") ||
Expand Down
3 changes: 2 additions & 1 deletion deploy/deployChangedPackages.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ for (const dirName of fs.readdirSync(generatedDir)) {
`${pkgJSON.name}@${olderVersion}/${filemap.to}`,
);
console.log(` - ${file}`);
if (oldFile !== generatedDTSContent)
if (oldFile !== generatedDTSContent) {
printUnifiedDiff(oldFile, generatedDTSContent);
}

const title = `## \`${file}\``;
const notes = generateChangelogFrom(oldFile, generatedDTSContent);
Expand Down
3 changes: 2 additions & 1 deletion deploy/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import { join } from "path";
const maybeTSWorkingDir = [process.argv[2], "../TypeScript", "TypeScript"];
const tscWD = maybeTSWorkingDir.find((wd) => existsSync(wd));

if (!tscWD)
if (!tscWD) {
throw new Error(
"Could not find a TypeScript clone to put the generated files in.",
);
}

const generatedFiles = readdirSync("generated");
const filesToSend = generatedFiles.filter(
Expand Down
3 changes: 2 additions & 1 deletion deploy/versionChangelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ const go = () => {
// We'll need to map back from the filename in the npm package to the
// generated file in baselines inside the git tag
const thisPackageMeta = packages.find((p) => p.name === name);
if (!thisPackageMeta)
if (!thisPackageMeta) {
throw new Error(`Could not find ${name} in ${packages.map((p) => p.name)}`);
}

for (const file of thisPackageMeta.files) {
const filename = `baselines/${basename(file.from)}`;
Expand Down
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default typescriptEslint.config(
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/no-var-requires": 0,
"curly": ["error", "all"],
},
},
);
20 changes: 15 additions & 5 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ async function emitDom() {

for (const [key, target] of Object.entries(namespaces)) {
const descObject = descriptions.interfaces.interface[key];
if (!descObject) continue;
if (!descObject) {
continue;
}

merge(target, descObject, { optional: true });
}
Expand Down Expand Up @@ -183,7 +185,9 @@ async function emitDom() {
webidl.interfaces!.interface[partial.name] ||
webidl.mixins!.mixin[partial.name];
if (base) {
if (base.exposed) resolveExposure(partial, base.exposed);
if (base.exposed) {
resolveExposure(partial, base.exposed);
}
merge(base.constants, partial.constants, { shallow: true });
merge(base.methods, partial.methods, { shallow: true });
merge(base.properties, partial.properties, { shallow: true });
Expand All @@ -192,7 +196,9 @@ async function emitDom() {
for (const partial of w.partialMixins) {
const base = webidl.mixins!.mixin[partial.name];
if (base) {
if (base.exposed) resolveExposure(partial, base.exposed);
if (base.exposed) {
resolveExposure(partial, base.exposed);
}
merge(base.constants, partial.constants, { shallow: true });
merge(base.methods, partial.methods, { shallow: true });
merge(base.properties, partial.properties, { shallow: true });
Expand All @@ -207,7 +213,9 @@ async function emitDom() {
for (const partial of w.partialNamespaces) {
const base = webidl.namespaces?.find((n) => n.name === partial.name);
if (base) {
if (base.exposed) resolveExposure(partial, base.exposed);
if (base.exposed) {
resolveExposure(partial, base.exposed);
}
merge(base.methods, partial.methods, { shallow: true });
merge(base.properties, partial.properties, { shallow: true });
}
Expand Down Expand Up @@ -351,7 +359,9 @@ async function emitDom() {
return filterByNull(obj, template);

function filterByNull(obj: any, template: any) {
if (!template) return obj;
if (!template) {
return obj;
}
const filtered = Array.isArray(obj) ? obj.slice(0) : { ...obj };
for (const k in template) {
if (!obj[k]) {
Expand Down
55 changes: 39 additions & 16 deletions src/build/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,11 @@ export function emitWebIdl(

function getExtendList(iName: string): string[] {
const i = allInterfacesMap[iName];
if (!i || !i.extends || i.extends === "Object") return [];
else return getExtendList(i.extends).concat(i.extends);
if (!i || !i.extends || i.extends === "Object") {
return [];
} else {
return getExtendList(i.extends).concat(i.extends);
}
}

function getImplementList(iName: string) {
Expand Down Expand Up @@ -377,8 +380,9 @@ export function emitWebIdl(
if (obj.overrideType) {
return obj.nullable ? makeNullable(obj.overrideType) : obj.overrideType;
}
if (!obj.type)
if (!obj.type) {
throw new Error("Missing 'type' field in " + JSON.stringify(obj));
}
let type = convertDomTypeToTsTypeWorker(obj, forReturn);
if (type === "Promise<undefined>") {
type = "Promise<void>";
Expand Down Expand Up @@ -501,7 +505,9 @@ export function emitWebIdl(
return objDomType;
}
// Name of a type alias. Just return itself
if (allTypedefsMap[objDomType]) return objDomType;
if (allTypedefsMap[objDomType]) {
return objDomType;
}

throw new Error("Unknown DOM type: " + objDomType);
}
Expand All @@ -522,9 +528,15 @@ export function emitWebIdl(
function nameWithForwardedTypes(i: Browser.Interface) {
const typeParameters = i.typeParameters;

if (i.overrideThis) return i.overrideThis;
if (!typeParameters) return i.name;
if (!typeParameters.length) return i.name;
if (i.overrideThis) {
return i.overrideThis;
}
if (!typeParameters) {
return i.name;
}
if (!typeParameters.length) {
return i.name;
}

return `${i.name}<${typeParameters.map((t) => t.name)}>`;
}
Expand Down Expand Up @@ -971,7 +983,9 @@ 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("");
}
comments.push(`[MDN Reference](${entity.mdnUrl})`);
}

Expand Down Expand Up @@ -1384,30 +1398,34 @@ export function emitWebIdl(
mTypes.length === 0 &&
amTypes.length === 1 &&
pTypes.length === 0
)
) {
return amTypes[0] === sig.type;
}
if (
mTypes.length === 1 &&
amTypes.length === 1 &&
pTypes.length === 0
)
) {
return mTypes[0] === amTypes[0] && amTypes[0] === sig.type;
}
if (
mTypes.length === 0 &&
amTypes.length === 1 &&
pTypes.length === 1
)
) {
return amTypes[0] === pTypes[0] && amTypes[0] === sig.type;
}
if (
mTypes.length === 1 &&
amTypes.length === 1 &&
pTypes.length === 1
)
) {
return (
mTypes[0] === amTypes[0] &&
amTypes[0] === pTypes[0] &&
amTypes[0] === sig.type
);
}
}
}
}
Expand Down Expand Up @@ -1674,7 +1692,9 @@ export function emitWebIdl(
}

function emitSelfIterator(i: Browser.Interface) {
if (!compilerBehavior.useIteratorObject) return;
if (!compilerBehavior.useIteratorObject) {
return;
}
const async = i.iterator?.kind === "async_iterable";
const name = getName(i);
const iteratorBaseType = `${async ? "Async" : ""}IteratorObject`;
Expand Down Expand Up @@ -1770,10 +1790,13 @@ export function emitWebIdl(
isIndexedPropertyGetter,
);

if (anonymousGetter) return anonymousGetter;
else if (i.methods)
if (anonymousGetter) {
return anonymousGetter;
} else if (i.methods) {
return mapToArray(i.methods.method).find(isIndexedPropertyGetter);
else return undefined;
} else {
return undefined;
}
}

function getIteratorSubtypes() {
Expand Down
12 changes: 8 additions & 4 deletions src/build/expose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,27 @@ export function getExposedTypes(
filtered.typedefs!.typedef = exposed;
}

if (webidl.callbackFunctions)
if (webidl.callbackFunctions) {
filtered.callbackFunctions!.callbackFunction = filterProperties(
webidl.callbackFunctions!.callbackFunction,
isKnownName,
);
if (webidl.callbackInterfaces)
}
if (webidl.callbackInterfaces) {
filtered.callbackInterfaces!.interface = filterProperties(
webidl.callbackInterfaces!.interface,
isKnownName,
);
if (webidl.dictionaries)
}
if (webidl.dictionaries) {
filtered.dictionaries!.dictionary = filterProperties(
webidl.dictionaries.dictionary,
isKnownName,
);
if (webidl.enums)
}
if (webidl.enums) {
filtered.enums!.enum = filterProperties(webidl.enums.enum, isKnownName);
}

for (const unvisited of forceKnownTypesLogged.unvisitedValues()) {
console.warn(`${unvisited} is redundant in knownTypes.json (${target})`);
Expand Down
8 changes: 6 additions & 2 deletions src/build/mdn-comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ async function walkDirectory(dir: URL): Promise<URL[]> {

for (const entry of entries) {
if (entry.isDirectory()) {
if (entry.name === parentDirName) continue;
if (entry.name === parentDirName) {
continue;
}
const subDir = new URL(`${entry.name}/`, dir);
results = results.concat(await walkDirectory(subDir));
} else if (entry.isFile() && entry.name === "index.md") {
Expand Down Expand Up @@ -139,7 +141,9 @@ export async function generateDescriptions(): Promise<{
const content = await fs.readFile(fileURL, "utf-8");
const slug = extractSlug(content);
const generatedPath = generatePath(content);
if (!slug.length || !generatedPath) return;
if (!slug.length || !generatedPath) {
return;
}

const summary = extractSummary(content);
insertComment(results, slug, summary, generatedPath);
Expand Down
4 changes: 3 additions & 1 deletion src/build/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ function handleTyped(type: Node): Typed {
}

function handleTypeParameters(value: Value) {
if (!value) return {};
if (!value) {
return {};
}
return {
typeParameters: [
{
Expand Down