This commit is contained in:
Kagami Sascha Rosylight 2018-03-09 13:47:33 +09:00
parent cc5ee919e4
commit 3246586fee
2 changed files with 79 additions and 74 deletions

View File

@ -1,9 +1,9 @@
// Type definitions for webidl2.js
// Type definitions for webidl2.js 10.2
// Project: https://github.com/w3c/webidl2.js/
// Definitions by: Kagama Sascha Rosylight <https://github.com/saschanaz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export declare function parse(str: string, options?: ParseOptions): IDLRootType[];
export function parse(str: string, options?: ParseOptions): IDLRootType[];
export type IDLRootType = InterfaceType | InterfaceMixinType | NamespaceType | CallbackType | DictionaryType | EnumType | TypedefType | ImplementsType | IncludesType;
@ -29,6 +29,7 @@ export interface WebIDLParseError {
toString(): string;
}
// tslint:disable-next-line interface-name
export interface IDLTypeDescription {
type: string;
/** Boolean indicating if it is a sequence. Same as generic === "sequence" */
@ -39,10 +40,12 @@ export interface IDLTypeDescription {
nullable: boolean;
/** Boolean indicating whether this is a union type or not. */
union: boolean;
/** In most cases, this will just be a string with the type name.
If the type is a union, then this contains an array of the types it unites.
If it is a generic type, it contains the IDL type description for the type in the sequence,
the eventual value of the promise, etc. */
/**
* In most cases, this will just be a string with the type name.
* If the type is a union, then this contains an array of the types it unites.
* If it is a generic type, it contains the IDL type description for the type in the sequence,
* the eventual value of the promise, etc.
*/
idlType: string | IDLTypeDescription | IDLTypeDescription[];
}
@ -134,7 +137,7 @@ export interface EnumType {
/** The enum's name. */
name: string;
/** An array of values (strings). */
values: { type: "string", value: string }[];
values: Array<{ type: "string", value: string }>;
/** A list of extended attributes. */
extAttrs: ExtendedAttributes[];
}
@ -257,7 +260,7 @@ export interface ExtendedAttributeRightHandSideIdentifier {
}
export interface ExtendedAttributeRightHandSideIdentifierList {
type: "identifier-list"
type: "identifier-list";
value: string[];
}

View File

@ -6,48 +6,50 @@ for (const rootType of parsed) {
if (rootType.type !== "implements" && rootType.type !== "includes") {
console.log(rootType.name);
}
if (rootType.type === "interface") {
console.log(rootType.inheritance);
logMembers(rootType.members);
console.log(rootType.partial);
}
else if (rootType.type === "interface mixin") {
logMembers(rootType.members);
console.log(rootType.partial);
}
else if (rootType.type === "namespace") {
console.log(rootType.partial);
logNamespaceMembers(rootType.members);
}
else if (rootType.type === "callback interface") {
logMembers(rootType.members);
console.log(rootType.partial);
}
else if (rootType.type === "callback") {
logArguments(rootType.arguments);
}
else if (rootType.type === "dictionary") {
console.log(rootType.inheritance);
for (const member of rootType.members) {
console.log(member.required, member.default);
}
}
else if (rootType.type === "enum") {
for (const v of rootType.values) {
console.log(v.type);
console.log(v.value);
}
}
else if (rootType.type === "typedef") {
logIdlType(rootType.idlType);
}
else if (rootType.type === "implements") {
console.log(rootType.target);
console.log(rootType.implements);
}
else if (rootType.type === "includes") {
console.log(rootType.target);
console.log(rootType.includes);
switch (rootType.type) {
case "interface":
console.log(rootType.inheritance);
logMembers(rootType.members);
console.log(rootType.partial);
break;
case "interface mixin":
logMembers(rootType.members);
console.log(rootType.partial);
break;
case "namespace":
console.log(rootType.partial);
logNamespaceMembers(rootType.members);
break;
case "callback interface":
logMembers(rootType.members);
console.log(rootType.partial);
break;
case "callback":
logArguments(rootType.arguments);
break;
case "dictionary":
console.log(rootType.inheritance);
for (const member of rootType.members) {
console.log(member.required, member.default);
}
break;
case "enum":
for (const v of rootType.values) {
console.log(v.type);
console.log(v.value);
}
break;
case "typedef":
logIdlType(rootType.idlType);
break;
case "implements":
console.log(rootType.target);
console.log(rootType.implements);
break;
case "includes":
console.log(rootType.target);
console.log(rootType.includes);
break;
}
logExtAttrs(rootType.extAttrs);
@ -55,27 +57,29 @@ for (const rootType of parsed) {
function logMembers(members: webidl2.IDLInterfaceMemberType[]) {
for (const member of members) {
if (member.type === "operation" || member.type === "attribute") {
logNamespaceMembers([member]);
switch (member.type) {
case "operation":
case "attribute":
logNamespaceMembers([member]);
break;
case "const":
console.log(member.name);
console.log(member.value);
console.log(member.nullable);
break;
case "iterable":
console.log(member.readonly);
break;
case "legacyiterable":
console.log(member.readonly);
break;
case "setlike":
console.log(member.readonly);
break;
case "maplike":
console.log(member.readonly);
break;
}
else if (member.type === "const") {
console.log(member.name);
console.log(member.value);
console.log(member.nullable);
}
else if (member.type === "iterable") {
console.log(member.readonly);
}
else if (member.type === "legacyiterable") {
console.log(member.readonly);
}
else if (member.type === "setlike") {
console.log(member.readonly);
}
else if (member.type === "maplike") {
console.log(member.readonly);
}
logIdlType(member.idlType);
logExtAttrs(member.extAttrs);
}
@ -87,8 +91,7 @@ function logNamespaceMembers(members: webidl2.IDLNamespaceMemberType[]) {
console.log(member.name);
console.log(member.getter, member.setter, member.deleter);
console.log(member.static, member.stringifier);
}
else if (member.type === "attribute") {
} else if (member.type === "attribute") {
console.log(member.name);
console.log(member.static, member.stringifier, member.readonly, member.inherit);
}
@ -101,8 +104,7 @@ function logExtAttrs(extAttrs: webidl2.ExtendedAttributes[]) {
const { rhs } = extAttrs[0];
if (rhs.type === "identifier") {
console.log(rhs);
}
else {
} else {
for (const v of rhs.value) {
console.log(v);
}