From 03b38576088c15f125032bda3a53a613f684af30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Scarcella?= Date: Thu, 22 Feb 2024 17:26:52 -0300 Subject: [PATCH] Fixing linter --- deploy/createTypesPackages.js | 10 +- deploy/deployChangedPackages.js | 10 +- deploy/migrate.js | 8 +- deploy/versionChangelog.js | 2 +- src/build.ts | 34 ++--- src/build/bcd.ts | 4 +- src/build/bcd/mapper.ts | 16 +-- src/build/bcd/stable.ts | 2 +- src/build/emitter.ts | 216 ++++++++++++++++---------------- src/build/expose.ts | 37 +++--- src/build/helpers.ts | 22 ++-- src/build/legacy-namespace.ts | 4 +- src/build/utils/fs.ts | 2 +- src/build/utils/map.ts | 4 +- src/build/utils/record.ts | 2 +- src/build/webref/css.ts | 4 +- src/build/webref/elements.ts | 4 +- src/build/widlprocess.ts | 50 ++++---- src/changelog.ts | 16 +-- src/test.ts | 30 ++--- 20 files changed, 238 insertions(+), 239 deletions(-) diff --git a/deploy/createTypesPackages.js b/deploy/createTypesPackages.js index 3e1e6896e..30705d159 100644 --- a/deploy/createTypesPackages.js +++ b/deploy/createTypesPackages.js @@ -86,7 +86,7 @@ const go = async () => { pkg.files.forEach((fileRef) => { fs.copyFileSync( new URL(fileRef.from, import.meta.url), - new URL(fileRef.to, packagePath), + new URL(fileRef.to, packagePath) ); }); @@ -120,7 +120,7 @@ async function updatePackageJSON(pkg, packagePath) { let version = "0.0.1"; try { const npmResponse = await fetch( - `https://registry.npmjs.org/${packageJSON.name}`, + `https://registry.npmjs.org/${packageJSON.name}` ); /** @type {*} */ const npmPackage = await npmResponse.json(); @@ -145,7 +145,7 @@ async function updatePackageJSON(pkg, packagePath) { pkgJSONPath, await format(JSON.stringify(packageJSON), { filepath: fileURLToPath(pkgJSONPath), - }), + }) ); return packageJSON; @@ -167,7 +167,7 @@ function copyREADME(pkg, pkgJSON, writePath) { .replace("{{version}}", pkgJSON.version) .replace( "{{release_href}}", - `https://github.com/microsoft/TypeScript-DOM-lib-generator/releases/tag/${htmlEncodedTag}`, + `https://github.com/microsoft/TypeScript-DOM-lib-generator/releases/tag/${htmlEncodedTag}` ); fs.writeFileSync(writePath, readme); @@ -200,7 +200,7 @@ export function postProcessDTSFiles(pkg, packagePath) { iterateThroughFiles((content) => { return content.replace( "abort(reason?: any): AbortSignal;", - "// abort(reason?: any): AbortSignal; - To be re-added in the future", + "// abort(reason?: any): AbortSignal; - To be re-added in the future" ); }); diff --git a/deploy/deployChangedPackages.js b/deploy/deployChangedPackages.js index 1f9943c6f..8b5db38b3 100644 --- a/deploy/deployChangedPackages.js +++ b/deploy/deployChangedPackages.js @@ -61,7 +61,7 @@ for (const dirName of fs.readdirSync(generatedDir)) { try { const oldFile = await getFileFromUnpkg( - `${pkgJSON.name}@${olderVersion}/${filemap.to}`, + `${pkgJSON.name}@${olderVersion}/${filemap.to}` ); console.log(` - ${file}`); if (oldFile !== generatedDTSContent) @@ -100,13 +100,13 @@ Assuming that this means we need to upload this package.`); await createRelease( `${pkgJSON.name}@${pkgJSON.version}`, - releaseNotes.join("\n\n"), + releaseNotes.join("\n\n") ); } } else { console.log( "Wanting to run: 'npm publish --access public' in " + - fileURLToPath(packageDir), + fileURLToPath(packageDir) ); } @@ -148,7 +148,7 @@ async function createRelease(tag, body) { }); } catch (error) { console.error( - "Creating the GitHub release failed, this is likely due to re-running the deploy.", + "Creating the GitHub release failed, this is likely due to re-running the deploy." ); } } @@ -157,7 +157,7 @@ function verify() { const authToken = process.env.GITHUB_TOKEN || process.env.GITHUB_API_TOKEN; if (!authToken) { throw new Error( - "There isn't an ENV var set up for creating a GitHub release, expected GITHUB_TOKEN.", + "There isn't an ENV var set up for creating a GitHub release, expected GITHUB_TOKEN." ); } } diff --git a/deploy/migrate.js b/deploy/migrate.js index f15ac8dd8..a3b0d1da7 100644 --- a/deploy/migrate.js +++ b/deploy/migrate.js @@ -14,19 +14,19 @@ const tscWD = maybeTSWorkingDir.find((wd) => existsSync(wd)); if (!tscWD) throw new Error( - "Could not find a TypeScript clone to put the generated files in.", + "Could not find a TypeScript clone to put the generated files in." ); const generatedFiles = readdirSync("generated"); const filesToSend = generatedFiles.filter( - (file) => file.includes("dom.") || file.includes("webworker."), + (file) => file.includes("dom.") || file.includes("webworker.") ); const generatedDir = new URL("../generated/", import.meta.url); postProcessDTSFiles( /** @type {any} */ ({ files: filesToSend.map((f) => ({ to: f })) }), - generatedDir, + generatedDir ); filesToSend.forEach((file) => { @@ -38,5 +38,5 @@ filesToSend.forEach((file) => { console.log( `Moved ${filesToSend .map((f) => f.replace(".generated", "")) - .join(", ")} to '${tscWD}/src/lib'.`, + .join(", ")} to '${tscWD}/src/lib'.` ); diff --git a/deploy/versionChangelog.js b/deploy/versionChangelog.js index fc120d82d..97cf6be3b 100644 --- a/deploy/versionChangelog.js +++ b/deploy/versionChangelog.js @@ -9,7 +9,7 @@ import { basename } from "path"; const [name, before, to] = process.argv.slice(2); if (!name || !before || !to) { throw new Error( - "Expected three arguments: package name, version before, version to", + "Expected three arguments: package name, version before, version to" ); } diff --git a/src/build.ts b/src/build.ts index faf5772d4..99672a9ad 100644 --- a/src/build.ts +++ b/src/build.ts @@ -41,7 +41,7 @@ interface EmitOptions { async function emitFlavor( webidl: Browser.WebIdl, forceKnownTypes: Set, - options: EmitOptions, + options: EmitOptions ) { const exposed = getExposedTypes(webidl, options.global, forceKnownTypes); mergeNamesakes(exposed); @@ -49,22 +49,22 @@ async function emitFlavor( const result = emitWebIdl(exposed, options.global[0], ""); await fs.writeFile( new URL(`${options.name}.generated.d.ts`, options.outputFolder), - result, + result ); const iterators = emitWebIdl(exposed, options.global[0], "sync"); await fs.writeFile( new URL(`${options.name}.iterable.generated.d.ts`, options.outputFolder), - iterators, + iterators ); const asyncIterators = emitWebIdl(exposed, options.global[0], "async"); await fs.writeFile( new URL( `${options.name}.asynciterable.generated.d.ts`, - options.outputFolder, + options.outputFolder ), - asyncIterators, + asyncIterators ); } @@ -118,7 +118,7 @@ async function emitDom() { const transferables = widlStandardTypes.flatMap((st) => { return Object.values(st.browser.interfaces?.interface ?? {}).filter( - (i) => i.transferable, + (i) => i.transferable ); }); @@ -152,12 +152,12 @@ async function emitDom() { function mergeApiDescriptions( idl: Browser.WebIdl, - descriptions: Record, + descriptions: Record ) { const namespaces = arrayToMap( idl.namespaces!, (i) => i.name, - (i) => i, + (i) => i ); for (const [key, value] of Object.entries(descriptions)) { const target = idl.interfaces!.interface[key] || namespaces[key]; @@ -170,12 +170,12 @@ async function emitDom() { function mergeDeprecatedMessage( idl: Browser.WebIdl, - descriptions: Record, + descriptions: Record ) { const namespaces = arrayToMap( idl.namespaces!, (i) => i.name, - (i) => i, + (i) => i ); for (const [key, value] of Object.entries(descriptions)) { const target = idl.interfaces!.interface[key] || namespaces[key]; @@ -301,7 +301,7 @@ async function emitDom() { function prune( obj: Browser.WebIdl, - template: Partial, + template: Partial ): Browser.WebIdl { return filterByNull(obj, template); @@ -312,13 +312,13 @@ async function emitDom() { if (!obj[k]) { console.warn( `removedTypes.json has a redundant field ${k} in ${JSON.stringify( - template, - ).slice(0, 100)}`, + template + ).slice(0, 100)}` ); } else if (Array.isArray(template[k])) { if (!Array.isArray(obj[k])) { throw new Error( - `Removal template ${k} is an array but the original field is not`, + `Removal template ${k} is an array but the original field is not` ); } // template should include strings @@ -328,10 +328,10 @@ async function emitDom() { }); if (filtered[k].length !== obj[k].length - template[k].length) { const differences = template[k].filter( - (t: any) => !obj[k].includes(t), + (t: any) => !obj[k].includes(t) ); console.warn( - `removedTypes.json has redundant array items: ${differences}`, + `removedTypes.json has redundant array items: ${differences}` ); } } else if (template[k] !== null) { @@ -339,7 +339,7 @@ async function emitDom() { } else { if (obj[k].exposed === "") { console.warn( - `removedTypes.json removes ${k} that has already been disabled by BCD.`, + `removedTypes.json removes ${k} that has already been disabled by BCD.` ); } delete filtered[k]; diff --git a/src/build/bcd.ts b/src/build/bcd.ts index e6bc633f3..c7e787428 100644 --- a/src/build/bcd.ts +++ b/src/build/bcd.ts @@ -10,7 +10,7 @@ import { hasStableImplementation } from "./bcd/stable.js"; function hasMultipleImplementations(support: SupportBlock, prefix?: string) { const hasStableImpl = ( - browser: SimpleSupportStatement | SimpleSupportStatement[] | undefined, + browser: SimpleSupportStatement | SimpleSupportStatement[] | undefined ) => hasStableImplementation(browser, prefix); let count = 0; if (hasStableImpl(support.chrome) || hasStableImpl(support.chrome_android)) { @@ -32,7 +32,7 @@ function isSuitable( key: string, compat?: CompatStatement, parentKey?: string, - prefix?: string, + prefix?: string ) { const forceAlive = parentKey ? forceKeepAlive[parentKey]?.includes(key) diff --git a/src/build/bcd/mapper.ts b/src/build/bcd/mapper.ts index fd50b1041..8a6e52605 100644 --- a/src/build/bcd/mapper.ts +++ b/src/build/bcd/mapper.ts @@ -35,7 +35,7 @@ function mergeCompatStatements(data?: Identifier): CompatStatement | undefined { const base = Object.fromEntries( Object.keys(statements[0].support).map((key) => { return [key, [] as SimpleSupportStatement[]]; - }), + }) ); for (const statement of statements) { @@ -56,13 +56,13 @@ function mergeCompatStatements(data?: Identifier): CompatStatement | undefined { function mapInterfaceLike( name: string, i: Browser.Interface, - mapper: (data: DataToMap) => any, + mapper: (data: DataToMap) => any ) { const data = i.mixin ? api.__mixins[name] : i.legacyNamespace - ? api[i.legacyNamespace][name] - : api[name]; + ? api[i.legacyNamespace][name] + : api[name]; const intCompat = data?.__compat; const mapped = mapper({ key: name, compat: intCompat, mixin: !!i.mixin }); if (!data) { @@ -87,7 +87,7 @@ function mapInterfaceLike( const properties = filterMapRecord( i.properties?.property, recordMapper, - i.namespace, + i.namespace ); if (i.iterator) { @@ -96,7 +96,7 @@ function mapInterfaceLike( // for iterable methods such as values(). Use that as a fallback. // See also: https://github.com/mdn/browser-compat-data/issues/6367 const iteratorCompat = mergeCompatStatements( - data[iteratorKey] ?? data["values"], + data[iteratorKey] ?? data["values"] ); const iteratorMapped = mapper({ key: iteratorKey, @@ -122,7 +122,7 @@ function mapInterfaceLike( export function mapToBcdCompat( webidl: Browser.WebIdl, - mapper: (data: DataToMap) => any, + mapper: (data: DataToMap) => any ): Browser.WebIdl | undefined { const map = (name: string, i: Browser.Interface) => mapInterfaceLike(name, i, mapper); @@ -130,7 +130,7 @@ export function mapToBcdCompat( const interfaces = filterMapRecord(webidl.interfaces?.interface, map); const mixins = filterMapRecord(webidl.mixins?.mixin, map); const namespaces = mapDefined(webidl.namespaces, (n) => - mapInterfaceLike(n.name, n, mapper), + mapInterfaceLike(n.name, n, mapper) ); if ( !isEmptyRecord(interfaces) || diff --git a/src/build/bcd/stable.ts b/src/build/bcd/stable.ts index 759448bc9..8a054336c 100644 --- a/src/build/bcd/stable.ts +++ b/src/build/bcd/stable.ts @@ -2,7 +2,7 @@ import { SimpleSupportStatement } from "@mdn/browser-compat-data/types"; export function hasStableImplementation( browser: SimpleSupportStatement | SimpleSupportStatement[] | undefined, - prefix?: string, + prefix?: string ): boolean { if (!browser) { return false; diff --git a/src/build/emitter.ts b/src/build/emitter.ts index ff59e865d..06bafba56 100644 --- a/src/build/emitter.ts +++ b/src/build/emitter.ts @@ -50,7 +50,7 @@ function adjustParamName(name: string) { function getElements( a: Record> | undefined, - k: K, + k: K ): T[] { return a ? mapToArray(a[k]) : []; } @@ -136,27 +136,27 @@ function isEventHandler(p: Browser.Property) { export function emitWebIdl( webidl: Browser.WebIdl, global: string, - iterator: "" | "sync" | "async", + iterator: "" | "sync" | "async" ): string { // Global print target const printer = createTextWriter("\n"); const polluter = getElements(webidl.interfaces, "interface").find( - (i) => !!i.global, + (i) => !!i.global ); const allNonCallbackInterfaces = getElements( webidl.interfaces, - "interface", + "interface" ).concat(getElements(webidl.mixins, "mixin")); const allInterfaces = getElements(webidl.interfaces, "interface").concat( getElements(webidl.callbackInterfaces, "interface"), - getElements(webidl.mixins, "mixin"), + getElements(webidl.mixins, "mixin") ); const allInterfacesMap = toNameMap(allInterfaces); const allLegacyWindowAliases = allInterfaces.flatMap( - (i) => i.legacyWindowAlias, + (i) => i.legacyWindowAlias ); const allDictionariesMap = webidl.dictionaries?.dictionary ?? {}; const allEnumsMap = webidl.enums ? webidl.enums.enum : {}; @@ -177,7 +177,7 @@ export function emitWebIdl( const iNameToIDependList = arrayToMap( allNonCallbackInterfaces, (i) => i.name, - (i) => getExtendList(i.name).concat(getImplementList(i.name)), + (i) => getExtendList(i.name).concat(getImplementList(i.name)) ); /// Distinct event type list, used in the "createEvent" function @@ -187,10 +187,10 @@ export function emitWebIdl( .concat( allNonCallbackInterfaces .filter( - (i) => i.extends?.endsWith("Event") && i.name.endsWith("Event"), + (i) => i.extends?.endsWith("Event") && i.name.endsWith("Event") ) - .map((i) => i.name), - ), + .map((i) => i.name) + ) ).sort(); /// Interface name to its related eventhandler name list map @@ -205,30 +205,30 @@ export function emitWebIdl( (i) => { const fromProperties = mapDefined( mapToArray(i.properties?.property), - (p) => p.eventHandler, + (p) => p.eventHandler ); const fromEvents = (i.events?.event ?? []).map((e) => e.name); return distinct([...fromProperties, ...fromEvents]).sort(); - }, + } ); const iNameToConstList = arrayToMap( allInterfaces, (i) => i.name, - (i) => (!i.constants ? [] : mapToArray(i.constants.constant)), + (i) => (!i.constants ? [] : mapToArray(i.constants.constant)) ); // Map of interface.Name -> List of base interfaces with event handlers const iNameToEhParents = arrayToMap( allInterfaces, (i) => i.name, - getParentsWithEventHandler, + getParentsWithEventHandler ); const iNameToConstParents = arrayToMap( allInterfaces, (i) => i.name, - getParentsWithConstant, + getParentsWithConstant ); switch (iterator) { @@ -275,7 +275,7 @@ export function emitWebIdl( } function getParentsWithEventHandler( - i: Browser.Interface, + i: Browser.Interface ): Browser.Interface[] { function getParentEventHandler(i: Browser.Interface): Browser.Interface[] { const hasEventListener = iNameToEhList[i.name]?.length; @@ -299,7 +299,7 @@ export function emitWebIdl( getParentEventHandler(allInterfacesMap[iExtends])) || []; const mixinsWithEventHandler = getImplementList(i.name).flatMap((i) => - getParentEventHandler(allInterfacesMap[i]), + getParentEventHandler(allInterfacesMap[i]) ); return distinct(parentWithEventHandler.concat(mixinsWithEventHandler)); @@ -312,7 +312,7 @@ export function emitWebIdl( } const mixinsWithConstant = getImplementList(i.name).flatMap((i) => - getParentConstant(allInterfacesMap[i]), + getParentConstant(allInterfacesMap[i]) ); return distinct(mixinsWithConstant); @@ -476,7 +476,7 @@ export function emitWebIdl( m: Browser.Method, expectedMName: string, expectedMType: string, - expectedParamType: string | string[], + expectedParamType: string | string[] ) { if (!Array.isArray(expectedParamType)) { expectedParamType = [expectedParamType]; @@ -488,14 +488,14 @@ export function emitWebIdl( convertDomTypeToTsType(m.signature[0]) === expectedMType && m.signature[0].param?.length === expectedParamType.length && expectedParamType.every( - (pt, idx) => convertDomTypeToTsType(m.signature[0].param![idx]) === pt, + (pt, idx) => convertDomTypeToTsType(m.signature[0].param![idx]) === pt ) ); } function getNameWithTypeParameter( typeParameters: Browser.TypeParameter[] | undefined, - name: string, + name: string ) { function typeParameterWithDefault(type: Browser.TypeParameter) { return ( @@ -522,14 +522,14 @@ export function emitWebIdl( ]) ) { printer.printLine( - "createElement(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K];", + "createElement(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K];" ); printer.printLine("/** @deprecated */"); printer.printLine( - "createElement(tagName: K, options?: ElementCreationOptions): HTMLElementDeprecatedTagNameMap[K];", + "createElement(tagName: K, options?: ElementCreationOptions): HTMLElementDeprecatedTagNameMap[K];" ); printer.printLine( - "createElement(tagName: string, options?: ElementCreationOptions): HTMLElement;", + "createElement(tagName: string, options?: ElementCreationOptions): HTMLElement;" ); } } @@ -541,21 +541,21 @@ export function emitWebIdl( m, "getElementsByTagName", "HTMLCollection", - "string", + "string" ) ) { const paramName = m.signature[0].param![0].name; for (const mapName of tagNameMapNames) { printer.printLine( - `getElementsByTagName(${paramName}: K): HTMLCollectionOf<${mapName}[K]>;`, + `getElementsByTagName(${paramName}: K): HTMLCollectionOf<${mapName}[K]>;` ); } printer.printLine("/** @deprecated */"); printer.printLine( - `getElementsByTagName(${paramName}: K): HTMLCollectionOf;`, + `getElementsByTagName(${paramName}: K): HTMLCollectionOf;` ); printer.printLine( - `getElementsByTagName(${paramName}: string): HTMLCollectionOf;`, + `getElementsByTagName(${paramName}: string): HTMLCollectionOf;` ); } } @@ -568,15 +568,15 @@ export function emitWebIdl( const paramName = m.signature[0].param![0].name; for (const mapName of tagNameMapNames) { printer.printLine( - `querySelector(${paramName}: K): ${mapName}[K] | null;`, + `querySelector(${paramName}: K): ${mapName}[K] | null;` ); } printer.printLine("/** @deprecated */"); printer.printLine( - `querySelector(${paramName}: K): HTMLElementDeprecatedTagNameMap[K] | null;`, + `querySelector(${paramName}: K): HTMLElementDeprecatedTagNameMap[K] | null;` ); printer.printLine( - `querySelector(${paramName}: string): E | null;`, + `querySelector(${paramName}: string): E | null;` ); } } @@ -589,15 +589,15 @@ export function emitWebIdl( const paramName = m.signature[0].param![0].name; for (const mapName of tagNameMapNames) { printer.printLine( - `querySelectorAll(${paramName}: K): NodeListOf<${mapName}[K]>;`, + `querySelectorAll(${paramName}: K): NodeListOf<${mapName}[K]>;` ); } printer.printLine("/** @deprecated */"); printer.printLine( - `querySelectorAll(${paramName}: K): NodeListOf;`, + `querySelectorAll(${paramName}: K): NodeListOf;` ); printer.printLine( - `querySelectorAll(${paramName}: string): NodeListOf;`, + `querySelectorAll(${paramName}: string): NodeListOf;` ); } } @@ -615,10 +615,10 @@ export function emitWebIdl( function emitDeprecatedHTMLOrSVGElementTagNameMap() { printer.printLine( - "/** @deprecated Directly use HTMLElementTagNameMap or SVGElementTagNameMap as appropriate, instead. */", + "/** @deprecated Directly use HTMLElementTagNameMap or SVGElementTagNameMap as appropriate, instead. */" ); printer.printLine( - "type ElementTagNameMap = HTMLElementTagNameMap & Pick>;", + "type ElementTagNameMap = HTMLElementTagNameMap & Pick>;" ); printer.printLine(""); } @@ -705,7 +705,7 @@ export function emitWebIdl( ? convertDomTypeToTsReturnType(overload) : "void"; printer.printLine( - `type ${i.name} = ((${paramsString}) => ${returnType}) | { ${m.name}(${paramsString}): ${returnType}; };`, + `type ${i.name} = ((${paramsString}) => ${returnType}) | { ${m.name}(${paramsString}): ${returnType}; };` ); printer.printLine(""); @@ -723,7 +723,7 @@ export function emitWebIdl( function emitCallBackFunction(cb: Browser.CallbackFunction) { printer.printLine( - `interface ${getNameWithTypeParameter(cb.typeParameters, cb.name)} {`, + `interface ${getNameWithTypeParameter(cb.typeParameters, cb.name)} {` ); printer.increaseIndent(); emitSignatures(cb, "", "", printer.printLine, true); @@ -741,7 +741,7 @@ export function emitWebIdl( function emitEnum(e: Browser.Enum) { const values = e.value.slice().sort(); printer.printLine( - `type ${e.name} = ${values.map((v) => `"${v}"`).join(" | ")};`, + `type ${e.name} = ${values.map((v) => `"${v}"`).join(" | ")};` ); } @@ -767,7 +767,7 @@ export function emitWebIdl( return ( isEventHandler(p) && iNameToEhParents[i.name].some((parent) => - parent.properties?.property.hasOwnProperty(p.name), + parent.properties?.property.hasOwnProperty(p.name) ) ); } @@ -776,7 +776,7 @@ export function emitWebIdl( prefix: string, i: Browser.Interface, emitScope: EmitScope, - p: Browser.Property, + p: Browser.Property ) { emitComments(p, printer.printLine); @@ -819,15 +819,15 @@ export function emitWebIdl( throw new Error("Couldn't find [PutForwards]"); } const setterType = `${convertDomTypeToTsType( - forwardingProperty, + forwardingProperty )} | ${pType}`; printer.printLine( - `set ${p.name}${optionalModifier}(${p.putForwards}: ${setterType});`, + `set ${p.name}${optionalModifier}(${p.putForwards}: ${setterType});` ); } else { const readOnlyModifier = p.readonly && prefix === "" ? "readonly " : ""; printer.printLine( - `${prefix}${readOnlyModifier}${p.name}${optionalModifier}: ${pType};`, + `${prefix}${readOnlyModifier}${p.name}${optionalModifier}: ${pType};` ); } } @@ -844,15 +844,15 @@ export function emitWebIdl( secureContext?: boolean; mdnUrl?: string; }, - print: (s: string) => void, + print: (s: string) => void ) { const comments = entity.comment?.split("\n") ?? []; const deprecated = typeof entity.deprecated === "string" ? `@deprecated ${entity.deprecated}` : entity.deprecated - ? "@deprecated" - : null; + ? "@deprecated" + : null; if (deprecated) { comments.push(deprecated); } @@ -876,7 +876,7 @@ export function emitWebIdl( function emitProperties( prefix: string, emitScope: EmitScope, - i: Browser.Interface, + i: Browser.Interface ) { if (i.properties) { mapToArray(i.properties.property) @@ -890,7 +890,7 @@ export function emitWebIdl( function emitMethod( prefix: string, m: Browser.Method, - conflictedMembers: Set, + conflictedMembers: Set ) { function printLine(content: string) { if (m.name && conflictedMembers.has(m.name)) { @@ -923,7 +923,7 @@ export function emitWebIdl( prefix: string | undefined, name: string | undefined, printLine: (s: string) => void, - shouldResolvePromise?: boolean, + shouldResolvePromise?: boolean ) { const paramsString = s.param ? paramsToString(s.param) : ""; const resolved = shouldResolvePromise ? resolvePromise(s) : s; @@ -932,8 +932,8 @@ export function emitWebIdl( printLine( `${prefix || ""}${getNameWithTypeParameter( s.typeParameters, - name || "", - )}(${paramsString}): ${returnType};`, + name || "" + )}(${paramsString}): ${returnType};` ); } @@ -942,14 +942,14 @@ export function emitWebIdl( prefix: string, name: string, printLine: (s: string) => void, - shouldResolvePromise?: boolean, + shouldResolvePromise?: boolean ) { if (method.overrideSignatures) { method.overrideSignatures!.forEach((s) => printLine(`${prefix}${s};`)); } else if (method.signature) { method.additionalSignatures?.forEach((s) => printLine(`${prefix}${s};`)); method.signature.forEach((sig) => - emitSignature(sig, prefix, name, printLine, shouldResolvePromise), + emitSignature(sig, prefix, name, printLine, shouldResolvePromise) ); } } @@ -958,7 +958,7 @@ export function emitWebIdl( prefix: string, emitScope: EmitScope, i: Browser.Interface, - conflictedMembers: Set, + conflictedMembers: Set ) { // If prefix is not empty, then this is the global declare function addEventListener, we want to override this // Otherwise, this is EventTarget.addEventListener, we want to keep that. @@ -971,7 +971,7 @@ export function emitWebIdl( prefix !== "" && (m.name === "addEventListener" || m.name === "removeEventListener") - ), + ) ) .filter((m) => { // Already covered by `extends`. @@ -1012,13 +1012,13 @@ export function emitWebIdl( subtype.length > 1 ? subtype[0] : i.iterator.kind === "iterable" - ? "number" - : value; + ? "number" + : value; const name = i.typeParameters ? `${i.name}<${i.typeParameters!.map((p) => p.name).join(", ")}>` : i.name; printer.printLine( - `forEach(callbackfn: (value: ${value}, key: ${key}, parent: ${name}) => void, thisArg?: any): void;`, + `forEach(callbackfn: (value: ${value}, key: ${key}, parent: ${name}) => void, thisArg?: any): void;` ); } @@ -1026,7 +1026,7 @@ export function emitWebIdl( function emitMembers( prefix: string, emitScope: EmitScope, - i: Browser.Interface, + i: Browser.Interface ) { const conflictedMembers = extendConflictsBaseTypes[i.name] ? extendConflictsBaseTypes[i.name].memberNames @@ -1067,12 +1067,12 @@ export function emitWebIdl( if (i.name === "EventSource") { printer.printLine( - `${fPrefix}${addOrRemove}EventListener(type: string, listener: (this: EventSource, event: MessageEvent) => any, options?: boolean | ${optionsType}): void;`, + `${fPrefix}${addOrRemove}EventListener(type: string, listener: (this: EventSource, event: MessageEvent) => any, options?: boolean | ${optionsType}): void;` ); } printer.printLine( - `${fPrefix}${addOrRemove}EventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ${optionsType}): void;`, + `${fPrefix}${addOrRemove}EventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | ${optionsType}): void;` ); } } @@ -1083,22 +1083,22 @@ export function emitWebIdl( prefix: string, addOrRemove: string, iParent: Browser.Interface, - optionsType: string, + optionsType: string ) { printer.printLine( `${prefix}${addOrRemove}EventListener(type: K, listener: (this: ${nameWithForwardedTypes( - i, + i )}, ev: ${ iParent.name - }EventMap[K]) => any, options?: boolean | ${optionsType}): void;`, + }EventMap[K]) => any, options?: boolean | ${optionsType}): void;` ); } function tryEmitTypedEventHandlerForInterface( addOrRemove: string, - optionsType: string, + optionsType: string ) { const hasEventListener = iNameToEhList[i.name]?.length; const ehParentCount = iNameToEhParents[i.name]?.length; @@ -1170,8 +1170,8 @@ export function emitWebIdl( printer.increaseIndent(); nc.signature.forEach((s) => printer.printLine( - `new(${s.param ? paramsToString(s.param) : ""}): ${i.name};`, - ), + `new(${s.param ? paramsToString(s.param) : ""}): ${i.name};` + ) ); printer.decreaseIndent(); printer.printLine(`};`); @@ -1196,8 +1196,8 @@ export function emitWebIdl( printer.printLineToStack( `interface ${getNameWithTypeParameter( i.typeParameters, - i.name, - )} extends ${processedIName} {`, + i.name + )} extends ${processedIName} {` ); } @@ -1237,7 +1237,7 @@ export function emitWebIdl( /// To decide if a given method is an indexer and should be emitted function shouldEmitIndexerSignature( i: Browser.Interface, - m: Browser.AnonymousMethod, + m: Browser.AnonymousMethod ) { if (m.getter && m.signature[0]?.param?.length === 1) { // TypeScript array indexer can only be number or string @@ -1254,18 +1254,18 @@ export function emitWebIdl( const mTypes = distinct( mapValues( i.methods?.method, - (m) => m.signature?.[0].type || "void", - ).filter((t) => t !== "void") || [], + (m) => m.signature?.[0].type || "void" + ).filter((t) => t !== "void") || [] ); const amTypes = distinct( i.anonymousMethods?.method .map((m) => m.signature[0].type) - .filter((t) => t !== "void") || [], + .filter((t) => t !== "void") || [] ); // |> Array.distinct const pTypes = distinct( mapValues(i.properties?.property, (m) => m.type).filter( - (t) => t !== "void", - ) || [], + (t) => t !== "void" + ) || [] ); // |> Array.distinct if ( @@ -1310,20 +1310,20 @@ export function emitWebIdl( mapToArray(i.methods?.method) .concat(i.anonymousMethods?.method || []) .filter( - (m) => shouldEmitIndexerSignature(i, m) && matchScope(emitScope, m), + (m) => shouldEmitIndexerSignature(i, m) && matchScope(emitScope, m) ) .forEach((m) => { const indexer = m.signature?.[0].param?.[0]; if (indexer) { printer.printLine( `[${indexer.name}: ${convertDomTypeToTsType( - indexer, + indexer )}]: ${convertDomTypeToTsType({ type: m.signature[0].type, overrideType: m.signature[0].overrideType, subtype: m.signature[0].subtype, nullable: undefined, - })};`, + })};` ); } }); @@ -1333,7 +1333,7 @@ export function emitWebIdl( function emitInterfaceEventMap(i: Browser.Interface) { function emitInterfaceEventMapEntry(eventName: string) { printer.printLine( - `"${eventName}": ${getEventTypeInInterface(eventName, i)};`, + `"${eventName}": ${getEventTypeInInterface(eventName, i)};` ); } @@ -1431,15 +1431,15 @@ export function emitWebIdl( printer.printLine( `interface ${getNameWithTypeParameter( dict.typeParameters, - dict.name, - )} {`, + dict.name + )} {` ); } else { printer.printLine( `interface ${getNameWithTypeParameter( dict.typeParameters, - dict.name, - )} extends ${dict.extends} {`, + dict.name + )} extends ${dict.extends} {` ); } printer.increaseIndent(); @@ -1449,7 +1449,7 @@ export function emitWebIdl( .forEach((m) => { emitComments(m, printer.printLine); printer.printLine( - `${m.name}${m.required ? "" : "?"}: ${convertDomTypeToTsType(m)};`, + `${m.name}${m.required ? "" : "?"}: ${convertDomTypeToTsType(m)};` ); }); } @@ -1473,8 +1473,8 @@ export function emitWebIdl( printer.printLine( `type ${getNameWithTypeParameter( typeDef.typeParameters, - typeDef.name, - )} = ${convertDomTypeToTsType(typeDef)};`, + typeDef.name + )} = ${convertDomTypeToTsType(typeDef)};` ); } @@ -1511,16 +1511,16 @@ export function emitWebIdl( if (global === "Window") { emitElementTagNameMap( "HTMLElementTagNameMap", - tagNameToEleName.htmlResult, + tagNameToEleName.htmlResult ); emitElementTagNameMap( "HTMLElementDeprecatedTagNameMap", - tagNameToEleName.htmlDeprecatedResult, + tagNameToEleName.htmlDeprecatedResult ); emitElementTagNameMap("SVGElementTagNameMap", tagNameToEleName.svgResult); emitElementTagNameMap( "MathMLElementTagNameMap", - tagNameToEleName.mathMLResult, + tagNameToEleName.mathMLResult ); emitDeprecatedHTMLOrSVGElementTagNameMap(); emitNamedConstructors(); @@ -1554,7 +1554,7 @@ export function emitWebIdl( function findIterableGetter() { const anonymousGetter = i.anonymousMethods?.method.find( - isIndexedPropertyGetter, + isIndexedPropertyGetter ); if (anonymousGetter) return anonymousGetter; @@ -1584,7 +1584,7 @@ export function emitWebIdl( function emitIterableDeclarationMethods( i: Browser.Interface, - subtypes: string[], + subtypes: string[] ) { let [keyType, valueType] = subtypes; if (!valueType) { @@ -1617,7 +1617,7 @@ export function emitWebIdl( function getIteratorExtends( iterator?: Browser.Iterator, - subtypes?: string[], + subtypes?: string[] ) { if (!iterator || !subtypes) { return ""; @@ -1626,8 +1626,8 @@ export function emitWebIdl( iterator.kind === "maplike" ? `Map<${subtypes[0]}, ${subtypes[1]}>` : iterator.kind === "setlike" - ? `Set<${subtypes[0]}>` - : undefined; + ? `Set<${subtypes[0]}>` + : undefined; if (!base) { return ""; } @@ -1643,12 +1643,12 @@ export function emitWebIdl( return type === "sequence" || !!sequenceTypedefMap[type]; } return s.param?.some( - (p) => !p.overrideType && typeIncludesSequence(p.type), + (p) => !p.overrideType && typeIncludesSequence(p.type) ); } function replaceTypedefsInSignatures( - signatures: Browser.Signature[], + signatures: Browser.Signature[] ): Browser.Signature[] { return signatures.map((s) => { const params = s.param!.map((p) => { @@ -1670,25 +1670,25 @@ export function emitWebIdl( .map((typedef) => ({ ...typedef, type: (typedef.type as Browser.Typed[]).filter( - (t) => t.type === "sequence", + (t) => t.type === "sequence" ), })) .filter((typedef) => typedef.type.length); const sequenceTypedefMap = arrayToMap( sequenceTypedefs, (t) => t.name, - (t) => t, + (t) => t ); const subtypes = getIteratorSubtypes(); const methodsWithSequence: Browser.Method[] = mapToArray( - i.methods ? i.methods.method : {}, + i.methods ? i.methods.method : {} ) .filter((m) => m.signature && !m.overrideSignatures) .map((m) => ({ ...m, signature: replaceTypedefsInSignatures( - m.signature.filter(hasSequenceArgument), + m.signature.filter(hasSequenceArgument) ), })) .filter((m) => m.signature.length) @@ -1701,7 +1701,7 @@ export function emitWebIdl( const iteratorExtends = getIteratorExtends(i.iterator, subtypes); const name = getNameWithTypeParameter( i.typeParameters, - extendConflictsBaseTypes[i.name] ? `${i.name}Base` : i.name, + extendConflictsBaseTypes[i.name] ? `${i.name}Base` : i.name ); printer.printLine(""); printer.printLine(`interface ${name} ${iteratorExtends}{`); @@ -1712,8 +1712,8 @@ export function emitWebIdl( if (subtypes && !iteratorExtends) { printer.printLine( `[Symbol.iterator](): IterableIterator<${stringifySingleOrTupleTypes( - subtypes, - )}>;`, + subtypes + )}>;` ); } if (i.iterator?.kind === "iterable" && subtypes) { @@ -1736,7 +1736,7 @@ export function emitWebIdl( function emitAsyncIterableDeclarationMethods( i: Browser.Interface, subtypes: string[], - paramsString: string, + paramsString: string ) { let methods; if (subtypes.length === 1) { @@ -1782,7 +1782,7 @@ export function emitWebIdl( const name = getNameWithTypeParameter( i.typeParameters, - extendConflictsBaseTypes[i.name] ? `${i.name}Base` : i.name, + extendConflictsBaseTypes[i.name] ? `${i.name}Base` : i.name ); const paramsString = i.iterator!.param ? paramsToString(i.iterator!.param) @@ -1793,8 +1793,8 @@ export function emitWebIdl( printer.printLine( `[Symbol.asyncIterator](${paramsString}): AsyncIterableIterator<${stringifySingleOrTupleTypes( - subtypes, - )}>;`, + subtypes + )}>;` ); emitAsyncIterableDeclarationMethods(i, subtypes, paramsString); diff --git a/src/build/expose.ts b/src/build/expose.ts index 0031d256c..8fcbeb4e2 100644 --- a/src/build/expose.ts +++ b/src/build/expose.ts @@ -29,7 +29,7 @@ class LoggedSet extends Set { export function getExposedTypes( webidl: Browser.WebIdl, target: string[], - forceKnownTypes: Set, + forceKnownTypes: Set ): Browser.WebIdl { const forceKnownTypesLogged = new LoggedSet(forceKnownTypes); @@ -38,10 +38,10 @@ export function getExposedTypes( if (webidl.interfaces) { filtered.interfaces!.interface = deepFilter( webidl.interfaces.interface, - (o) => exposesTo(o, target), + (o) => exposesTo(o, target) ); const unexposedInterfaces = mapToArray(webidl.interfaces.interface).filter( - (i) => !exposesTo(i, target), + (i) => !exposesTo(i, target) ); for (const i of unexposedInterfaces) { unexposedTypes.add(i.name); @@ -49,7 +49,7 @@ export function getExposedTypes( } if (webidl.namespaces) { filtered.namespaces = deepFilter(webidl.namespaces, (o) => - exposesTo(o, target), + exposesTo(o, target) ); } @@ -60,13 +60,12 @@ export function getExposedTypes( const mixins = deepFilter(webidl.mixins.mixin, (o) => exposesTo(o, target)); filtered.mixins!.mixin = filterProperties( mixins, - (m: Browser.Interface) => - allIncludes.includes(m.name) && !isEmptyMixin(m), + (m: Browser.Interface) => allIncludes.includes(m.name) && !isEmptyMixin(m) ); for (const value of Object.values(filtered.interfaces!.interface || {})) { if (value.implements) { value.implements = value.implements.filter( - (i) => !!filtered.mixins!.mixin[i], + (i) => !!filtered.mixins!.mixin[i] ); } } @@ -79,8 +78,8 @@ export function getExposedTypes( arrayToMap( filtered.namespaces!, (i) => i.name, - (i) => i, - ), + (i) => i + ) ), ]); const isKnownName = (o: { name: string }) => @@ -88,7 +87,7 @@ export function getExposedTypes( if (webidl.typedefs) { const referenced = webidl.typedefs.typedef.filter( - (t) => knownIDLTypes.has(t.name) || forceKnownTypesLogged.has(t.name), + (t) => knownIDLTypes.has(t.name) || forceKnownTypesLogged.has(t.name) ); const { exposed, removed } = filterTypedefs(referenced, unexposedTypes); removed.forEach((s) => unexposedTypes.add(s)); @@ -98,17 +97,17 @@ export function getExposedTypes( if (webidl.callbackFunctions) filtered.callbackFunctions!.callbackFunction = filterProperties( webidl.callbackFunctions!.callbackFunction, - isKnownName, + isKnownName ); if (webidl.callbackInterfaces) filtered.callbackInterfaces!.interface = filterProperties( webidl.callbackInterfaces!.interface, - isKnownName, + isKnownName ); if (webidl.dictionaries) filtered.dictionaries!.dictionary = filterProperties( webidl.dictionaries.dictionary, - isKnownName, + isKnownName ); if (webidl.enums) filtered.enums!.enum = filterProperties(webidl.enums.enum, isKnownName); @@ -128,7 +127,7 @@ export function getExposedTypes( */ function filterTypedefs( typedefs: Browser.TypeDef[], - unexposedTypes: Set, + unexposedTypes: Set ): { exposed: Browser.TypeDef[]; removed: Set } { const exposed: Browser.TypeDef[] = []; const removed = new Set(); @@ -148,7 +147,7 @@ function filterTypedefs( } else if (Array.isArray(typedef.type)) { const filteredType = filterUnexposedTypeFromUnion( typedef.type, - unexposedTypes, + unexposedTypes ); if (!filteredType.length) { removed.add(typedef.name); @@ -170,7 +169,7 @@ function filterTypedefs( */ function deepFilterUnexposedTypes( webidl: Browser.WebIdl, - unexposedTypes: Set, + unexposedTypes: Set ) { return deepClone(webidl, (o) => { if (Array.isArray(o.type)) { @@ -225,12 +224,12 @@ function deepFilterUnexposedTypes( function filterUnexposedType( type: T, - unexposedTypes: Set, + unexposedTypes: Set ) { if (Array.isArray(type.type)) { const filteredUnion = filterUnexposedTypeFromUnion( type.type, - unexposedTypes, + unexposedTypes ); if (filteredUnion.length) { return { ...type, type: flattenType(filteredUnion) }; @@ -242,7 +241,7 @@ function filterUnexposedType( function filterUnexposedTypeFromUnion( union: Browser.Typed[], - unexposedTypes: Set, + unexposedTypes: Set ): Browser.Typed[] { const result: Browser.Typed[] = []; for (const type of union) { diff --git a/src/build/helpers.ts b/src/build/helpers.ts index 827c4baa6..bd17be32a 100644 --- a/src/build/helpers.ts +++ b/src/build/helpers.ts @@ -66,12 +66,12 @@ export const genericEventSupertypes = new Set(["UIEvent", "MouseEvent"]); export function deepFilter( obj: T, - fn: (o: any, n: string | undefined) => boolean, + fn: (o: any, n: string | undefined) => boolean ): T { if (typeof obj === "object") { if (Array.isArray(obj)) { return mapDefined(obj, (e) => - fn(e, undefined) ? deepFilter(e, fn) : undefined, + fn(e, undefined) ? deepFilter(e, fn) : undefined ) as any as T; } else { const result: any = {}; @@ -88,7 +88,7 @@ export function deepFilter( export function filterProperties( obj: Record, - fn: (o: T) => boolean, + fn: (o: T) => boolean ): Record { const result: Record = {}; for (const e in obj) { @@ -133,7 +133,7 @@ export function merge(target: T, src: T, shallow?: boolean): T { } else { if (targetProp === srcProp && k !== "name") { console.warn( - `Redundant merge value ${targetProp} in ${JSON.stringify(src)}`, + `Redundant merge value ${targetProp} in ${JSON.stringify(src)}` ); } target[k] = merge(targetProp, srcProp, shallow); @@ -149,7 +149,7 @@ export function merge(target: T, src: T, shallow?: boolean): T { function mergeNamedArrays( srcProp: T[], - targetProp: T[], + targetProp: T[] ) { const map: any = {}; for (const e1 of srcProp) { @@ -180,7 +180,7 @@ export function mapToArray(m?: Record): T[] { export function arrayToMap( array: ReadonlyArray, makeKey: (value: T) => string, - makeValue: (value: T) => U, + makeValue: (value: T) => U ): Record { const result: Record = {}; for (const value of array) { @@ -191,14 +191,14 @@ export function arrayToMap( export function mapValues( obj: Record | undefined, - fn: (o: T) => U, + fn: (o: T) => U ): U[] { return Object.keys(obj || {}).map((k) => fn(obj![k])); } export function mapDefined( array: ReadonlyArray | undefined, - mapFn: (x: T, i: number) => U | undefined, + mapFn: (x: T, i: number) => U | undefined ): U[] { const result: U[] = []; if (array) { @@ -213,7 +213,7 @@ export function mapDefined( } export function toNameMap( - array: T[], + array: T[] ): Record { const result: Record = {}; for (const value of array) { @@ -256,7 +256,7 @@ export function getEmptyWebIDL(): Browser.WebIdl { export function resolveExposure( obj: Record, exposure: string, - override?: boolean, + override?: boolean ): void { if (!exposure) { throw new Error("No exposure set"); @@ -310,7 +310,7 @@ function getNonValueTypeMap(webidl: Browser.WebIdl) { export function followTypeReferences( webidl: Browser.WebIdl, - filteredInterfaces: Record, + filteredInterfaces: Record ): Set { const set = new Set(); const map = getNonValueTypeMap(webidl); diff --git a/src/build/legacy-namespace.ts b/src/build/legacy-namespace.ts index 6000ae6c8..c4caaae83 100644 --- a/src/build/legacy-namespace.ts +++ b/src/build/legacy-namespace.ts @@ -2,7 +2,7 @@ import * as Browser from "./types.js"; import { mapToArray, arrayToMap } from "./helpers.js"; export function collectLegacyNamespaceTypes( - webidl: Browser.WebIdl, + webidl: Browser.WebIdl ): Browser.Interface[] { if (!webidl.namespaces) { return []; @@ -11,7 +11,7 @@ export function collectLegacyNamespaceTypes( const namespaceMap: Record = arrayToMap( webidl.namespaces, (i) => i.name, - (i) => i, + (i) => i ); for (const i of mapToArray(webidl.interfaces!.interface)) { if (i.legacyNamespace) { diff --git a/src/build/utils/fs.ts b/src/build/utils/fs.ts index d4c149b1e..0e344aaa8 100644 --- a/src/build/utils/fs.ts +++ b/src/build/utils/fs.ts @@ -1,7 +1,7 @@ import { readFile } from "fs/promises"; export async function tryReadFile( - path: string | URL, + path: string | URL ): Promise { try { return await readFile(path, "utf-8"); diff --git a/src/build/utils/map.ts b/src/build/utils/map.ts index 552d48429..3da754691 100644 --- a/src/build/utils/map.ts +++ b/src/build/utils/map.ts @@ -1,7 +1,7 @@ export function addToArrayMap( map: Map, name: string, - value: T, + value: T ): void { const array = map.get(name) || []; array.push(value); @@ -11,7 +11,7 @@ export function addToArrayMap( export function addToStringMap( map: Map, name: string, - value: string, + value: string ): void { const old = map.get(name) || ""; map.set(name, `${old}\n${value}\n`); diff --git a/src/build/utils/record.ts b/src/build/utils/record.ts index 522ac2648..078733f56 100644 --- a/src/build/utils/record.ts +++ b/src/build/utils/record.ts @@ -1,7 +1,7 @@ export function filterMapRecord( object: Record | undefined, mapper: (key: string, value: T) => V | undefined, - forNamespace?: boolean, + forNamespace?: boolean ): Record | undefined { if (!object) { return; diff --git a/src/build/webref/css.ts b/src/build/webref/css.ts index 37f9203f6..26e47facc 100644 --- a/src/build/webref/css.ts +++ b/src/build/webref/css.ts @@ -10,8 +10,8 @@ export function generateWebIdlFromCssProperties(properties: string[]): string { .map( (property) => `\n [CEReactions] attribute [LegacyNullToEmptyString] CSSOMString ${hyphenToCamelCase( - property, - )};`, + property + )};` ) .join("")}\n};`; } diff --git a/src/build/webref/elements.ts b/src/build/webref/elements.ts index 7e2b6ed44..0f519a029 100644 --- a/src/build/webref/elements.ts +++ b/src/build/webref/elements.ts @@ -26,8 +26,8 @@ export async function getInterfaceElementMergeData(): Promise { const namespace = key.startsWith("SVG") ? "SVG" : key.startsWith("MathML") - ? "MathML" - : undefined; + ? "MathML" + : undefined; data.interfaces!.interface[key] = { element: elements.map((el) => ({ namespace, diff --git a/src/build/widlprocess.ts b/src/build/widlprocess.ts index 675344e1a..bc64e525a 100644 --- a/src/build/widlprocess.ts +++ b/src/build/widlprocess.ts @@ -43,7 +43,7 @@ export function convert(text: string, commentMap: Record) { addComments( browser.callbackFunctions!.callbackFunction[rootType.name], commentMap, - rootType.name, + rootType.name ); } else if (rootType.type === "dictionary") { const converted = convertDictionary(rootType, commentMap); @@ -95,7 +95,7 @@ function getExtAttr(extAttrs: webidl2.ExtendedAttribute[], name: string) { function getExtAttrConcatenated( extAttrs: webidl2.ExtendedAttribute[], - name: string, + name: string ) { const extAttr = getExtAttr(extAttrs, name); if (extAttr.length) { @@ -105,7 +105,7 @@ function getExtAttrConcatenated( function convertInterface( i: webidl2.InterfaceType, - commentMap: Record, + commentMap: Record ) { const result = convertInterfaceCommon(i, commentMap); if (i.inheritance) { @@ -116,7 +116,7 @@ function convertInterface( function convertInterfaceMixin( i: webidl2.InterfaceMixinType, - commentMap: Record, + commentMap: Record ) { const result = convertInterfaceCommon(i, commentMap); result.mixin = true; @@ -128,7 +128,7 @@ function addComments( obj: any, commentMap: Record, container: string, - member?: string, + member?: string ) { const key = container.toLowerCase() + (member ? "-" + member.toLowerCase() : ""); @@ -142,7 +142,7 @@ function convertInterfaceCommon( | webidl2.InterfaceType | webidl2.InterfaceMixinType | webidl2.CallbackInterfaceType, - commentMap: Record, + commentMap: Record ) { const result: Browser.Interface = { name: i.name, @@ -174,7 +174,7 @@ function convertInterfaceCommon( result.constants!.constant[member.name], commentMap, i.name, - member.name, + member.name ); } else if (member.type === "attribute") { const { properties } = result; @@ -223,7 +223,7 @@ function convertInterfaceCommon( function getConstructor( members: webidl2.IDLInterfaceMemberType[], - parent: string, + parent: string ) { const constructor: Browser.Constructor = { signature: [], @@ -243,7 +243,7 @@ function getConstructor( function getOldStyleConstructor( extAttrs: webidl2.ExtendedAttribute[], - parent: string, + parent: string ) { const constructor: Browser.Constructor = { signature: [], @@ -263,7 +263,7 @@ function getOldStyleConstructor( function getLegacyFactoryFunction( extAttrs: webidl2.ExtendedAttribute[], - parent: string, + parent: string ): Browser.NamedConstructor | undefined { for (const extAttr of extAttrs) { if ( @@ -288,14 +288,14 @@ function getLegacyFactoryFunction( function convertOperation( operation: webidl2.OperationMemberType, - inheritedExposure: string | undefined, + inheritedExposure: string | undefined ): Browser.AnonymousMethod | Browser.Method { const isStringifier = operation.special === "stringifier"; const type = operation.idlType ? convertIdlType(operation.idlType) : isStringifier - ? { type: "DOMString" } - : undefined; + ? { type: "DOMString" } + : undefined; if (!type) { throw new Error("Unexpected anonymous operation"); } @@ -318,7 +318,7 @@ function convertOperation( } function convertCallbackFunctions( - c: webidl2.CallbackType, + c: webidl2.CallbackType ): Browser.CallbackFunction { return { name: c.name, @@ -346,7 +346,7 @@ function convertArgument(arg: webidl2.Argument): Browser.Param { function convertAttribute( attribute: webidl2.AttributeMemberType, - inheritedExposure: string | undefined, + inheritedExposure: string | undefined ): Browser.Property { const isEventHandler = typeof attribute.idlType.idlType === "string" && @@ -367,7 +367,7 @@ function convertAttribute( } function convertConstantMember( - constant: webidl2.ConstantMemberType, + constant: webidl2.ConstantMemberType ): Browser.Constant { return { name: constant.name, @@ -398,7 +398,7 @@ function convertConstantValue(value: webidl2.ValueDescription): string { function convertNamespace( namespace: webidl2.NamespaceType, - commentMap: Record, + commentMap: Record ) { const result: Browser.Interface = { name: namespace.name, @@ -412,13 +412,13 @@ function convertNamespace( if (member.type === "attribute") { result.properties!.property[member.name] = convertAttribute( member, - result.exposed, + result.exposed ); addComments( result.properties!.property[member.name], commentMap, namespace.name, - member.name, + member.name ); } else if (member.type === "operation" && member.idlType) { const operation = convertOperation(member, result.exposed); @@ -433,7 +433,7 @@ function convertNamespace( method[member.name], commentMap, namespace.name, - member.name, + member.name ); } } @@ -444,7 +444,7 @@ function convertNamespace( function convertDictionary( dictionary: webidl2.DictionaryType, - commentsMap: Record, + commentsMap: Record ) { const result: Browser.Dictionary = { name: dictionary.name, @@ -459,7 +459,7 @@ function convertDictionary( result.members.member[member.name], commentsMap, dictionary.name, - member.name, + member.name ); } addComments(result, commentsMap, dictionary.name); @@ -467,7 +467,7 @@ function convertDictionary( } function convertDictionaryMember( - member: webidl2.DictionaryMemberType, + member: webidl2.DictionaryMemberType ): Browser.Member { return { name: member.name, @@ -504,8 +504,8 @@ function convertIdlType(i: webidl2.IDLTypeDescription): Browser.Typed { subtype: !Array.isArray(i.idlType) ? convertIdlType(i.idlType) : i.idlType.length === 1 - ? convertIdlType(i.idlType[0]) - : i.idlType.map(convertIdlType), + ? convertIdlType(i.idlType[0]) + : i.idlType.map(convertIdlType), nullable: i.nullable, }; } diff --git a/src/changelog.ts b/src/changelog.ts index 14fe82edf..5a53f8add 100644 --- a/src/changelog.ts +++ b/src/changelog.ts @@ -17,7 +17,7 @@ function mapInterfaceToMembers(interfaces: ts.InterfaceDeclaration[]) { for (const decl of interfaces) { interfaceToMemberMap.set( decl.name.text, - decl.members.map((m) => m.name?.getText()).filter((n) => n) as string[], + decl.members.map((m) => m.name?.getText()).filter((n) => n) as string[] ); } return interfaceToMemberMap; @@ -28,7 +28,7 @@ function extractTypesFromFile(file: string) { "dom", file, ts.ScriptTarget.ES2015, - /*setParentNodes */ true, + /*setParentNodes */ true ); const interfaceNames = source.statements @@ -36,10 +36,10 @@ function extractTypesFromFile(file: string) { .map((v) => v.declarationList.declarations[0].name.getText(source)); const tsInterfacedecls = source.statements.filter(ts.isInterfaceDeclaration); const idlInterfaceDecls = tsInterfacedecls.filter((i) => - interfaceNames.includes(i.name.text), + interfaceNames.includes(i.name.text) ); const otherDecls = tsInterfacedecls.filter( - (i) => !interfaceNames.includes(i.name.text), + (i) => !interfaceNames.includes(i.name.text) ); const interfaceToMemberMap = mapInterfaceToMembers(idlInterfaceDecls); @@ -74,11 +74,11 @@ function compareSet(x: Set, y: Set) { function diffTypes(previous: string, current: string) { function diff( previousMap: Map, - currentMap: Map, + currentMap: Map ) { const { added, removed, common } = compareSet( new Set(previousMap.keys()), - new Set(currentMap.keys()), + new Set(currentMap.keys()) ); const modified = new Map< string, @@ -101,7 +101,7 @@ function diffTypes(previous: string, current: string) { return { interfaces: diff( previousTypes.interfaceToMemberMap, - currentTypes.interfaceToMemberMap, + currentTypes.interfaceToMemberMap ), others: diff(previousTypes.otherToMemberMap, currentTypes.otherToMemberMap), }; @@ -150,7 +150,7 @@ export function generateDefaultFromRecentTag(): string { export function generateChangelogFrom( previous: string, - current: string, + current: string ): string { const { interfaces: { added, removed, modified }, diff --git a/src/test.ts b/src/test.ts index c490a53d2..6a5a7e6f9 100644 --- a/src/test.ts +++ b/src/test.ts @@ -7,7 +7,7 @@ const baselineFolder = new URL("../baselines/", import.meta.url); const outputFolder = new URL("../generated/", import.meta.url); const tscPath = new URL( "../node_modules/typescript/lib/tsc.js", - import.meta.url, + import.meta.url ); function normalizeLineEndings(text: string): string { @@ -21,10 +21,10 @@ function compareToBaselines() { } const baseline = normalizeLineEndings( - fs.readFileSync(new URL(file, baselineFolder)).toString(), + fs.readFileSync(new URL(file, baselineFolder)).toString() ); const generated = normalizeLineEndings( - fs.readFileSync(new URL(file, outputFolder)).toString(), + fs.readFileSync(new URL(file, outputFolder)).toString() ); if (baseline !== generated) { console.error(`Test failed: '${file}' is different from baseline file.`); @@ -39,10 +39,10 @@ function compileGeneratedFiles(lib: string, ...files: string[]) { try { child_process.execSync( `node ${fileURLToPath( - tscPath, + tscPath )} --strict --lib ${lib} --types --noEmit ${files .map((file) => fileURLToPath(new URL(file, outputFolder))) - .join(" ")}`, + .join(" ")}` ); } catch (e: any) { console.error(`Test failed: could not compile '${files.join(",")}':`); @@ -60,56 +60,56 @@ function test() { compileGeneratedFiles( "es6", "dom.generated.d.ts", - "dom.iterable.generated.d.ts", + "dom.iterable.generated.d.ts" ) && compileGeneratedFiles( "es2018", "dom.generated.d.ts", - "dom.asynciterable.generated.d.ts", + "dom.asynciterable.generated.d.ts" ) && compileGeneratedFiles("es5", "webworker.generated.d.ts") && compileGeneratedFiles( "es6", "webworker.generated.d.ts", - "webworker.iterable.generated.d.ts", + "webworker.iterable.generated.d.ts" ) && compileGeneratedFiles( "es2018", "webworker.generated.d.ts", - "webworker.asynciterable.generated.d.ts", + "webworker.asynciterable.generated.d.ts" ) && compileGeneratedFiles("es5", "sharedworker.generated.d.ts") && compileGeneratedFiles( "es6", "sharedworker.generated.d.ts", - "sharedworker.iterable.generated.d.ts", + "sharedworker.iterable.generated.d.ts" ) && compileGeneratedFiles( "es2018", "sharedworker.generated.d.ts", - "sharedworker.asynciterable.generated.d.ts", + "sharedworker.asynciterable.generated.d.ts" ) && compileGeneratedFiles("es5", "serviceworker.generated.d.ts") && compileGeneratedFiles( "es6", "serviceworker.generated.d.ts", - "serviceworker.iterable.generated.d.ts", + "serviceworker.iterable.generated.d.ts" ) && compileGeneratedFiles( "es2018", "serviceworker.generated.d.ts", - "serviceworker.asynciterable.generated.d.ts", + "serviceworker.asynciterable.generated.d.ts" ) && compileGeneratedFiles("es5", "audioworklet.generated.d.ts") && compileGeneratedFiles( "es6", "audioworklet.generated.d.ts", - "audioworklet.iterable.generated.d.ts", + "audioworklet.iterable.generated.d.ts" ) && compileGeneratedFiles( "es2018", "audioworklet.generated.d.ts", - "audioworklet.asynciterable.generated.d.ts", + "audioworklet.asynciterable.generated.d.ts" ) ) { console.log("All tests passed.");