idlize

Форк
0
/
webidl2-utils.ts 
82 строки · 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
import { IDLEntity } from "../idl";
19

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

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

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
31
}
32

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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