Skip to content

Commit 1776cdd

Browse files
author
Orta Therox
authored
Merge pull request #988 from saschanaz/microsoft-helpers
Remove redundant helper functions
2 parents f45dc9f + 08af139 commit 1776cdd

File tree

6 files changed

+19
-35
lines changed

6 files changed

+19
-35
lines changed

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ jobs:
88
steps:
99
- uses: actions/checkout@v2
1010
- uses: actions/setup-node@v1
11+
with:
12+
node-version: '15'
1113

1214
- run: npm install
1315
- run: npm run build

.github/workflows/test_typescript.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ jobs:
88
steps:
99
- uses: actions/checkout@v2
1010
- uses: actions/setup-node@v1
11+
with:
12+
node-version: '15'
1113

12-
- name: Run TypeScript Compiler Tests with new dom.d.ts
14+
- name: Run TypeScript Compiler Tests with new dom.d.ts
1315
run: |
1416
# Get local dependencies
1517
npm install
@@ -24,17 +26,17 @@ jobs:
2426
2527
cd TypeScript
2628
npm i
27-
29+
2830
2931
# Run TypeScript's tests with the new DOM libs, but don't fail
3032
npm test || true
3133
gulp baseline-accept
3234
33-
# The git diff now is the difference between tests
35+
# The git diff now is the difference between tests
3436
git diff > baseline-changes.diff
3537
3638
- name: Danger
3739
run: npm run danger -- ci
38-
env:
40+
env:
3941
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4042

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
2-
"name": "tsjs-lib-generator",
2+
"name": "typescript-dom-lib-generator",
33
"private": true,
4+
"engines": {
5+
"node": ">=15"
6+
},
47
"scripts": {
58
"build": "tsc -p ./tsconfig.json && node ./lib/index.js",
69
"fetch-idl": "tsc -p ./tsconfig.json && node ./lib/idlfetcher.js",

src/emitter.ts

+6-6
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

-23
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

+1-1
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)