idlize

Форк
0
/
webidl2-utils.ts 
84 строки · 2.9 Кб
1
/*
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
6
 *
7
 * http://www.apache.org/licenses/LICENSE-2.0
8
 *
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.
14
 */
15

16
import * as webidl2 from "webidl2"
17
import { ExtendedAttribute } from "webidl2";
18

19
export function isEnum(node: webidl2.IDLRootType): node is webidl2.EnumType {
20
    return node.type === "enum"
21
}
22

23
export function isInterface(node: webidl2.IDLRootType): node is webidl2.InterfaceType {
24
    return node.type === "interface"
25
}
26

27
export function isClass(node: webidl2.IDLRootType): node is webidl2.InterfaceType {
28
    return isInterface(node)
29
        && node.extAttrs
30
            .map((it: ExtendedAttribute) => it.name)
31
            .map((it) => it.toLowerCase())
32
            .includes("class")
33
}
34

35
export function isCallback(node: webidl2.IDLRootType): node is webidl2.CallbackType {
36
    return node.type === "callback"
37
}
38

39
export function isTypedef(node: webidl2.IDLRootType): node is webidl2.TypedefType {
40
    return node.type === "typedef"
41
}
42

43
export function isDictionary(node: webidl2.IDLRootType): node is webidl2.DictionaryType {
44
    return node.type === "dictionary"
45
}
46

47
export function isAttribute(node: webidl2.IDLInterfaceMemberType): node is webidl2.AttributeMemberType {
48
    return node.type === "attribute"
49
}
50

51
export function isOperation(node: webidl2.IDLInterfaceMemberType): node is webidl2.OperationMemberType {
52
    return node.type === "operation"
53
}
54

55
export function isConstructor(node: webidl2.IDLInterfaceMemberType): node is webidl2.ConstructorMemberType {
56
    return node.type === "constructor"
57
}
58

59
export function isUnionTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.UnionTypeDescription {
60
    return node.union
61
}
62

63
export function isSingleTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.SingleTypeDescription {
64
    return (typeof node.idlType === "string")
65
}
66

67
export function isSequenceTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.SequenceTypeDescription {
68
    return node.generic === "sequence"
69
}
70

71
export function isPromiseTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.PromiseTypeDescription {
72
    return node.generic === "Promise"
73
}
74

75
export function isRecordTypeDescription(node: webidl2.IDLTypeDescription): node is webidl2.RecordTypeDescription {
76
    return node.generic === "record"
77
}
78

79
export function isOptional(node: webidl2.AttributeMemberType): boolean {
80
    return node.extAttrs
81
        .map((it: ExtendedAttribute) => it.name)
82
        .map((it) => it.toLowerCase())
83
        .includes("optional")
84
}
85

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.