2
* Copyright (c) 2024 Huawei Device Co., Ltd.
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
16
import * as webidl2 from "webidl2"
17
import { ExtendedAttribute } from "webidl2";
18
import { IDLEntity } from "../idl";
20
export function isEnum(node: webidl2.IDLRootType): node is webidl2.EnumType {
21
return node.type === "enum"
24
export function isInterface(node: webidl2.IDLRootType): node is webidl2.InterfaceType {
25
return node.type === "interface"
28
export function isClass(node: webidl2.IDLRootType): node is webidl2.InterfaceType {
29
return isInterface(node)
30
&& node.extAttrs.find(it => it.name === "Entity")?.rhs?.value === IDLEntity.Class
33
export function isCallback(node: webidl2.IDLRootType): node is webidl2.CallbackType {
34
return node.type === "callback"
37
export function isTypedef(node: webidl2.IDLRootType): node is webidl2.TypedefType {
38
return node.type === "typedef"
41
export function isDictionary(node: webidl2.IDLRootType): node is webidl2.DictionaryType {
42
return node.type === "dictionary"
45
export function isAttribute(node: webidl2.IDLInterfaceMemberType): node is webidl2.AttributeMemberType {
46
return node.type === "attribute"
49
export function isOperation(node: webidl2.IDLInterfaceMemberType): node is webidl2.OperationMemberType {
50
return node.type === "operation"
53
export function isConstructor(node: webidl2.IDLInterfaceMemberType): node is webidl2.ConstructorMemberType {
54
return node.type === "constructor"
57
export function isUnionTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.UnionTypeDescription {
61
export function isSingleTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.SingleTypeDescription {
62
return (typeof node.idlType === "string")
65
export function isSequenceTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.SequenceTypeDescription {
66
return node.generic === "sequence"
69
export function isPromiseTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.PromiseTypeDescription {
70
return node.generic === "Promise"
73
export function isRecordTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.RecordTypeDescription {
74
return node.generic === "record"
77
export function isOptional(node: webidl2.AttributeMemberType | webidl2.OperationMemberType): boolean {
79
.map((it: ExtendedAttribute) => it.name)
80
.map((it) => it.toLowerCase())