Skip to content

Commit edea223

Browse files
committed
helpers.getEmptyWebIDL
1 parent ae361a4 commit edea223

File tree

3 files changed

+31
-40
lines changed

3 files changed

+31
-40
lines changed

src/helpers.ts

+28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as Browser from "./types";
2+
13
export function filter(obj: any, fn: (o: any, n: string | undefined) => boolean): any {
24
if (typeof obj === "object") {
35
if (Array.isArray(obj)) {
@@ -145,3 +147,29 @@ export function flatMap<T, U>(array: ReadonlyArray<T> | undefined, mapfn: (x: T,
145147
export function concat<T>(a: T[] | undefined, b: T[] | undefined): T[] {
146148
return !a ? b || [] : a.concat(b || []);
147149
}
150+
151+
export function getEmptyWebIDL(): Browser.WebIdl {
152+
return {
153+
"callback-functions": {
154+
"callback-function": {}
155+
},
156+
"callback-interfaces": {
157+
"interface": {}
158+
},
159+
"dictionaries": {
160+
"dictionary": {}
161+
},
162+
"enums": {
163+
"enum": {}
164+
},
165+
"interfaces": {
166+
"interface": {}
167+
},
168+
"mixins": {
169+
"mixin": {}
170+
},
171+
"typedefs": {
172+
"typedef": []
173+
}
174+
}
175+
}

src/index.ts

+1-27
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as Browser from "./types";
22
import * as fs from "fs";
33
import * as path from "path";
4-
import { filter, merge, filterProperties } from "./helpers";
4+
import { filter, merge, filterProperties, getEmptyWebIDL } from "./helpers";
55
import { Flavor, emitWebIDl } from "./emitter";
66
import { convert } from "./widlprocess";
77

@@ -37,32 +37,6 @@ function emitES6DomIterators(webidl: Browser.WebIdl, tsWebES6Output: string) {
3737
fs.writeFileSync(tsWebES6Output, emitWebIDl(webidl, Flavor.ES6Iterators));
3838
}
3939

40-
function getEmptyWebIDL(): Browser.WebIdl {
41-
return {
42-
"callback-functions": {
43-
"callback-function": {}
44-
},
45-
"callback-interfaces": {
46-
"interface": {}
47-
},
48-
"dictionaries": {
49-
"dictionary": {}
50-
},
51-
"enums": {
52-
"enum": {}
53-
},
54-
"interfaces": {
55-
"interface": {}
56-
},
57-
"mixins": {
58-
"mixin": {}
59-
},
60-
"typedefs": {
61-
"typedef": []
62-
}
63-
}
64-
}
65-
6640
function emitDom() {
6741
const __SOURCE_DIRECTORY__ = __dirname;
6842
const inputFolder = path.join(__SOURCE_DIRECTORY__, "../", "inputfiles");

src/widlprocess.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import * as webidl2 from "webidl2";
22
import * as Browser from "./types";
3+
import { getEmptyWebIDL } from "./helpers";
34

45
export function convert(text: string) {
56
const rootTypes = webidl2.parse(text);
67
const partialInterfaces: Browser.Interface[] = [];
7-
const browser = createEmptyBrowserWebidl();
8+
const browser = getEmptyWebIDL();
89
for (const rootType of rootTypes) {
910
if (rootType.type === "interface") {
1011
const converted = convertInterface(rootType);
@@ -226,15 +227,3 @@ function convertIdlType(i: webidl2.IDLTypeDescription): Browser.Typed {
226227
}
227228
throw new Error("Unsupported IDL type structure");
228229
}
229-
230-
function createEmptyBrowserWebidl(): Browser.WebIdl {
231-
return {
232-
"callback-functions": { "callback-function": {} },
233-
"callback-interfaces": { interface: {} },
234-
dictionaries: { dictionary: {} },
235-
enums: { enum: {} },
236-
interfaces: { interface: {} },
237-
mixins: { mixin: {} },
238-
typedefs: { typedef: [] }
239-
}
240-
}

0 commit comments

Comments
 (0)