Skip to content

Commit f6df9f4

Browse files
committed
Remove redundant helper functions
1 parent f45dc9f commit f6df9f4

File tree

3 files changed

+7
-30
lines changed

3 files changed

+7
-30
lines changed

src/emitter.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Browser from "./types";
2-
import { mapToArray, distinct, map, toNameMap, mapDefined, arrayToMap, flatMap, integerTypes, baseTypeConversionMap } from "./helpers";
2+
import { mapToArray, distinct, map, toNameMap, mapDefined, arrayToMap, integerTypes, baseTypeConversionMap } from "./helpers";
33
import { collectLegacyNamespaceTypes } from "./legacy-namespace";
44

55
export const enum Flavor {
@@ -131,14 +131,14 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
131131
getElements(webidl.mixins, "mixin"));
132132

133133
const allInterfacesMap = toNameMap(allInterfaces);
134-
const allLegacyWindowAliases = flatMap(allInterfaces, i => i["legacy-window-alias"]);
134+
const allLegacyWindowAliases = allInterfaces.flatMap(i => i["legacy-window-alias"]);
135135
const allDictionariesMap = webidl.dictionaries ? webidl.dictionaries.dictionary : {};
136136
const allEnumsMap = webidl.enums ? webidl.enums.enum : {};
137137
const allCallbackFunctionsMap = webidl["callback-functions"] ? webidl["callback-functions"]!["callback-function"] : {};
138138
const allTypeDefsMap = new Set(webidl.typedefs && webidl.typedefs.typedef.map(td => td["new-type"]));
139139

140140
/// Event name to event type map
141-
const eNameToEType = arrayToMap(flatMap(allNonCallbackInterfaces, i => i.events ? i.events.event : []), e => e.name, e => eventTypeMap[e.name] || e.type);
141+
const eNameToEType = arrayToMap(allNonCallbackInterfaces.flatMap(i => i.events ? i.events.event : []), e => e.name, e => eventTypeMap[e.name] || e.type);
142142

143143
/// Tag name to element name map
144144
const tagNameToEleName = getTagNameToElementNameMap();
@@ -149,7 +149,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
149149

150150
/// Distinct event type list, used in the "createEvent" function
151151
const distinctETypeList = distinct(
152-
flatMap(allNonCallbackInterfaces, i => i.events ? i.events.event.map(e => e.type) : [])
152+
allNonCallbackInterfaces.flatMap(i => i.events ? i.events.event.map(e => e.type) : [])
153153
.concat(allNonCallbackInterfaces.filter(i => i.extends && i.extends.endsWith("Event") && i.name.endsWith("Event")).map(i => i.name))
154154
).sort();
155155

@@ -235,7 +235,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
235235

236236
const iExtends = i.extends && i.extends.replace(/<.*>$/, '');
237237
const parentWithEventHandler = allInterfacesMap[iExtends] && getParentEventHandler(allInterfacesMap[iExtends]) || [];
238-
const mixinsWithEventHandler = flatMap(i.implements || [], i => getParentEventHandler(allInterfacesMap[i]));
238+
const mixinsWithEventHandler = (i.implements || []).flatMap(i => getParentEventHandler(allInterfacesMap[i]));
239239

240240
return distinct(parentWithEventHandler.concat(mixinsWithEventHandler));
241241
}
@@ -246,7 +246,7 @@ export function emitWebIdl(webidl: Browser.WebIdl, flavor: Flavor, iterator: boo
246246
return (hasConst ? [i] : []).concat(getParentsWithConstant(i));
247247
}
248248

249-
const mixinsWithConstant = flatMap(i.implements || [], i => getParentConstant(allInterfacesMap[i]));
249+
const mixinsWithConstant = (i.implements || []).flatMap(i => getParentConstant(allInterfacesMap[i]));
250250

251251
return distinct(mixinsWithConstant);
252252
}

src/helpers.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -147,29 +147,6 @@ export function toNameMap<T extends { name: string }>(array: T[]) {
147147
return result;
148148
}
149149

150-
export function isArray(value: any): value is ReadonlyArray<{}> {
151-
return Array.isArray ? Array.isArray(value) : value instanceof Array;
152-
}
153-
154-
export function flatMap<T, U>(array: ReadonlyArray<T> | undefined, mapfn: (x: T, i: number) => U | ReadonlyArray<U> | undefined): U[] {
155-
let result: U[] | undefined;
156-
if (array) {
157-
result = [];
158-
for (let i = 0; i < array.length; i++) {
159-
const v = mapfn(array[i], i);
160-
if (v) {
161-
if (isArray(v)) {
162-
result.push(...v);
163-
}
164-
else {
165-
result.push(v);
166-
}
167-
}
168-
}
169-
}
170-
return result || [];
171-
}
172-
173150
export function concat<T>(a: T[] | undefined, b: T[] | undefined): T[] {
174151
return !a ? b || [] : a.concat(b || []);
175152
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es2017",
3+
"target": "es2019",
44
"module": "commonjs",
55
"outDir": "./lib",
66
"strict": true,

0 commit comments

Comments
 (0)