@idlizer/core 2.1.10-arktscgen-5 → 2.1.10-arktscgen-7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/build/lib/src/Language.js +1 -1
  2. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +16 -6
  3. package/build/lib/src/LanguageWriters/ArgConvertors.js +80 -92
  4. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +8 -7
  5. package/build/lib/src/LanguageWriters/LanguageWriter.js +35 -22
  6. package/build/lib/src/LanguageWriters/common.d.ts +1 -0
  7. package/build/lib/src/LanguageWriters/common.js +2 -1
  8. package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +7 -1
  9. package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +53 -15
  10. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -0
  11. package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +10 -8
  12. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -1
  13. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +26 -14
  14. package/build/lib/src/LanguageWriters/index.d.ts +4 -3
  15. package/build/lib/src/LanguageWriters/index.js +9 -11
  16. package/build/lib/src/LanguageWriters/nameConvertor.d.ts +2 -0
  17. package/build/lib/src/LanguageWriters/nameConvertor.js +11 -0
  18. package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +1 -1
  19. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +2 -22
  20. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +34 -113
  21. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +3 -0
  22. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +33 -9
  23. package/build/lib/src/config.d.ts +2 -1461
  24. package/build/lib/src/config.js +16 -32
  25. package/build/lib/src/configMerge.d.ts +3 -0
  26. package/build/lib/src/configMerge.js +63 -0
  27. package/build/lib/src/diagnostictypes.d.ts +1 -5
  28. package/build/lib/src/diagnostictypes.js +1 -27
  29. package/build/lib/src/from-idl/DtsPrinter.js +12 -5
  30. package/build/lib/src/from-idl/IDLLinter.d.ts +3 -4
  31. package/build/lib/src/from-idl/IDLLinter.js +30 -32
  32. package/build/lib/src/from-idl/deserialize.d.ts +3 -4
  33. package/build/lib/src/from-idl/deserialize.js +29 -641
  34. package/build/lib/src/from-idl/parser.d.ts +20 -2
  35. package/build/lib/src/from-idl/parser.js +97 -29
  36. package/build/lib/src/idl/builders.d.ts +43 -0
  37. package/build/lib/src/idl/builders.js +135 -0
  38. package/build/lib/src/idl/discriminators.d.ts +53 -0
  39. package/build/lib/src/idl/discriminators.js +232 -0
  40. package/build/lib/src/idl/dump.d.ts +48 -0
  41. package/build/lib/src/idl/dump.js +327 -0
  42. package/build/lib/src/idl/index.d.ts +9 -0
  43. package/build/lib/src/idl/index.js +23 -0
  44. package/build/lib/src/idl/keywords.d.ts +2 -0
  45. package/build/lib/src/{options.js → idl/keywords.js} +7 -3
  46. package/build/lib/src/idl/node.d.ts +233 -0
  47. package/build/lib/src/idl/node.js +103 -0
  48. package/build/lib/src/idl/stdlib.d.ts +34 -0
  49. package/build/lib/src/idl/stdlib.js +54 -0
  50. package/build/lib/src/idl/utils.d.ts +44 -0
  51. package/build/lib/src/idl/utils.js +215 -0
  52. package/build/lib/src/idl/visitors.d.ts +15 -0
  53. package/build/lib/src/idl/visitors.js +593 -0
  54. package/build/lib/src/index.d.ts +4 -2
  55. package/build/lib/src/index.js +5 -3
  56. package/build/lib/src/inputPaths.d.ts +11 -0
  57. package/build/lib/src/inputPaths.js +81 -0
  58. package/build/lib/src/languageSpecificKeywords.d.ts +0 -1
  59. package/build/lib/src/languageSpecificKeywords.js +0 -5
  60. package/build/lib/src/peer-generation/LayoutManager.d.ts +1 -1
  61. package/build/lib/src/peer-generation/Materialized.d.ts +8 -2
  62. package/build/lib/src/peer-generation/Materialized.js +24 -12
  63. package/build/lib/src/peer-generation/PeerLibrary.d.ts +10 -15
  64. package/build/lib/src/peer-generation/PeerLibrary.js +35 -215
  65. package/build/lib/src/peer-generation/ReferenceResolver.d.ts +6 -1
  66. package/build/lib/src/peer-generation/ReferenceResolver.js +93 -2
  67. package/build/lib/src/peer-generation/idl/common.d.ts +6 -2
  68. package/build/lib/src/peer-generation/idl/common.js +7 -7
  69. package/build/lib/src/peer-generation/isMaterialized.js +2 -3
  70. package/build/lib/src/peer-generation/modules.js +2 -0
  71. package/build/lib/src/peer-generation/toDeclaration.d.ts +4 -0
  72. package/build/lib/src/peer-generation/toDeclaration.js +53 -0
  73. package/build/lib/src/peer-generation/unions.d.ts +1 -1
  74. package/build/lib/src/peer-generation/unions.js +15 -7
  75. package/build/lib/src/resolveNamedNode.d.ts +1 -0
  76. package/build/lib/src/resolveNamedNode.js +7 -0
  77. package/build/lib/src/transformers/FqnTransformer.d.ts +1 -1
  78. package/build/lib/src/transformers/FqnTransformer.js +20 -12
  79. package/build/lib/src/transformers/GenericTransformer.d.ts +4 -3
  80. package/build/lib/src/transformers/GenericTransformer.js +252 -158
  81. package/build/lib/src/transformers/IdlTransformer.d.ts +6 -0
  82. package/build/lib/src/transformers/IdlTransformer.js +7 -0
  83. package/build/lib/src/transformers/NullTransformer.d.ts +1 -1
  84. package/build/lib/src/transformers/NullTransformer.js +27 -21
  85. package/build/lib/src/transformers/OnSerializeTransformer.d.ts +1 -1
  86. package/build/lib/src/transformers/OnSerializeTransformer.js +28 -13
  87. package/build/lib/src/util.d.ts +5 -0
  88. package/build/lib/src/util.js +25 -0
  89. package/package.json +6 -7
  90. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +0 -37
  91. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +0 -210
  92. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +0 -85
  93. package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +0 -306
  94. package/build/lib/src/from-idl/webidl2-utils.d.ts +0 -21
  95. package/build/lib/src/from-idl/webidl2-utils.js +0 -87
  96. package/build/lib/src/idl.d.ts +0 -444
  97. package/build/lib/src/idl.js +0 -1385
  98. package/build/lib/src/idlize.d.ts +0 -25
  99. package/build/lib/src/idlize.js +0 -198
  100. package/build/lib/src/options.d.ts +0 -13
  101. package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -20
  102. package/build/lib/src/peer-generation/BuilderClass.js +0 -68
  103. package/webidl2.js/dist/webidl2.js +0 -4622
  104. package/webidl2.js/package.json +0 -55
@@ -0,0 +1,232 @@
1
+ /*
2
+ * Copyright (c) 2025 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
+ import { isDefined } from "../util";
16
+ import { IDLKind, IDLInterfaceSubkind, IDLExtendedAttributes } from "./node";
17
+ /////////////////////////////////////////////////////////////////
18
+ // BASICS
19
+ export function isFile(node) {
20
+ return node.kind === IDLKind.File;
21
+ }
22
+ export function isPrimitiveType(type) {
23
+ return type.kind == IDLKind.PrimitiveType;
24
+ }
25
+ export function isContainerType(type) {
26
+ return type.kind == IDLKind.ContainerType;
27
+ }
28
+ export function isReferenceType(type) {
29
+ return type.kind == IDLKind.ReferenceType;
30
+ }
31
+ export function isEnum(type) {
32
+ return type.kind == IDLKind.Enum;
33
+ }
34
+ export function isEnumMember(type) {
35
+ return type.kind == IDLKind.EnumMember;
36
+ }
37
+ export function isUnionType(type) {
38
+ return type.kind == IDLKind.UnionType;
39
+ }
40
+ export function isTypeParameterType(type) {
41
+ return type.kind == IDLKind.TypeParameterType;
42
+ }
43
+ export function isInterface(node) {
44
+ return node.kind === IDLKind.Interface;
45
+ }
46
+ export function isImport(type) {
47
+ return type.kind == IDLKind.Import;
48
+ }
49
+ export function isCallable(node) {
50
+ return node.kind === IDLKind.Callable;
51
+ }
52
+ export function isMethod(node) {
53
+ return node.kind === IDLKind.Method;
54
+ }
55
+ export function isParameter(node) {
56
+ return node.kind === IDLKind.Parameter;
57
+ }
58
+ export function isConstructor(node) {
59
+ return node.kind === IDLKind.Constructor;
60
+ }
61
+ export function isProperty(node) {
62
+ return node.kind === IDLKind.Property;
63
+ }
64
+ export function isCallback(node) {
65
+ return node.kind === IDLKind.Callback;
66
+ }
67
+ export function isInterfaceSubkind(idl) {
68
+ return idl.subkind === IDLInterfaceSubkind.Interface;
69
+ }
70
+ export function isClassSubkind(idl) {
71
+ return idl.subkind === IDLInterfaceSubkind.Class;
72
+ }
73
+ export function isConstant(node) {
74
+ return node.kind === IDLKind.Const;
75
+ }
76
+ export function isTypedef(node) {
77
+ return node.kind === IDLKind.Typedef;
78
+ }
79
+ export function isType(node) {
80
+ return "_idlTypeBrand" in node;
81
+ }
82
+ export function isEntry(node) {
83
+ return "_idlEntryBrand" in node;
84
+ }
85
+ export function isNamespace(node) {
86
+ return node.kind === IDLKind.Namespace;
87
+ }
88
+ export function isSyntheticEntry(node) {
89
+ var _a;
90
+ return isDefined((_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find(it => it.name === IDLExtendedAttributes.Synthetic));
91
+ }
92
+ export function isOptionalType(type) {
93
+ return type.kind === IDLKind.OptionalType;
94
+ }
95
+ export function isVersion(node) {
96
+ return node.kind === IDLKind.Version;
97
+ }
98
+ export function isNamedNode(type) {
99
+ return "_idlNamedNodeBrand" in type;
100
+ }
101
+ export const IDLContainerUtils = {
102
+ isRecord: (x) => isContainerType(x) && x.containerKind === 'record',
103
+ isSequence: (x) => isContainerType(x) && x.containerKind === 'sequence',
104
+ isPromise: (x) => isContainerType(x) && x.containerKind === 'Promise'
105
+ };
106
+ /////////////////////////////////////////////////////////////////
107
+ // EXTENDED ATTRIBUTES
108
+ export function hasExtAttribute(node, attribute) {
109
+ var _a;
110
+ return ((_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find((it) => it.name == attribute)) != undefined;
111
+ }
112
+ export function getExtAttribute(node, name) {
113
+ var _a, _b;
114
+ return (_b = (_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find(it => it.name === name)) === null || _b === void 0 ? void 0 : _b.value;
115
+ }
116
+ export function removeExtAttribute(node, name) {
117
+ if (node.extendedAttributes) {
118
+ node.extendedAttributes = node.extendedAttributes.filter(it => it.name !== name);
119
+ }
120
+ }
121
+ export function getExtAttributeTypesValue(node, name) {
122
+ var _a, _b;
123
+ return (_b = (_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find(it => it.name === name)) === null || _b === void 0 ? void 0 : _b.typesValue;
124
+ }
125
+ export function updateExtAttribute(node, name, value) {
126
+ var _a;
127
+ removeExtAttribute(node, name);
128
+ (_a = node.extendedAttributes) !== null && _a !== void 0 ? _a : (node.extendedAttributes = []);
129
+ node.extendedAttributes.push({ name, value });
130
+ }
131
+ /////////////////////////////////////////////////////////////////
132
+ // ADVANCED
133
+ export function getNamespacesPathFor(node) {
134
+ let iterator = node.parent;
135
+ const result = [];
136
+ while (iterator) {
137
+ if (isNamespace(iterator))
138
+ result.unshift(iterator);
139
+ iterator = iterator.parent;
140
+ }
141
+ return result;
142
+ }
143
+ const nodesWithoutIDLFiles = new Set();
144
+ export function getFileFor(node) {
145
+ let iterator = node;
146
+ while (iterator) {
147
+ if (isFile(iterator))
148
+ return iterator;
149
+ iterator = iterator.parent;
150
+ }
151
+ const name = getQualifiedName(node, "namespace.name");
152
+ if (!nodesWithoutIDLFiles.has(name)) {
153
+ console.warn(`Node ${name} does not have IDLFile in parents`);
154
+ nodesWithoutIDLFiles.add(name);
155
+ }
156
+ return undefined;
157
+ }
158
+ export function getPackageClause(node) {
159
+ var _a;
160
+ const file = getFileFor(node);
161
+ if (!file)
162
+ throw new Error(`Can not find parent file for node ${node.kind}`);
163
+ return (_a = file === null || file === void 0 ? void 0 : file.packageClause) !== null && _a !== void 0 ? _a : [];
164
+ }
165
+ export function getPackageName(node) {
166
+ return getPackageClause(node).join(".");
167
+ }
168
+ export function getPackageNameSafe(node) {
169
+ try {
170
+ return getPackageName(node);
171
+ }
172
+ catch (_) {
173
+ return undefined;
174
+ }
175
+ }
176
+ export function isInPackage(entry, packageName, exactMatch = false) {
177
+ const entryPackageName = getPackageName(entry);
178
+ return exactMatch
179
+ ? entryPackageName === packageName
180
+ : entryPackageName.startsWith(packageName);
181
+ }
182
+ export function getNamespaceName(a) {
183
+ return getNamespacesPathFor(a).map(it => it.name).join('.');
184
+ }
185
+ export function deriveQualifiedNameFrom(name, from) {
186
+ return [...getPackageClause(from), ...getNamespacesPathFor(from).map(it => it.name), name].join(".");
187
+ }
188
+ export function getQualifiedName(a, pattern) {
189
+ const result = [];
190
+ if ("package.namespace.name" === pattern)
191
+ result.push(...getPackageClause(a), ...getNamespacesPathFor(a).map(it => it.name));
192
+ else if ("namespace.name" === pattern)
193
+ result.push(...getNamespacesPathFor(a).map(it => it.name));
194
+ const ownName = (node) => {
195
+ if (!node || isFile(node))
196
+ return [];
197
+ if (isNamespace(node))
198
+ return node === a ? [node.name] : [];
199
+ if (isInterface(node) || isTypedef(node) || isCallback(node) || isEnum(node))
200
+ return [node.name];
201
+ if (isProperty(node) || isMethod(node) || isConstant(node))
202
+ return [...ownName(node.parent), node.name];
203
+ if (isCallable(node))
204
+ return [...ownName(node.parent), "invoke"];
205
+ if (isConstructor(node))
206
+ return [...ownName(node.parent), "constructor"];
207
+ throw new Error(`Can not calculate own name for node ${node.kind}`);
208
+ };
209
+ result.push(...ownName(a));
210
+ return result.join(".");
211
+ }
212
+ export function getFQName(a) {
213
+ return getQualifiedName(a, "package.namespace.name");
214
+ }
215
+ export function getFQNameSafe(a) {
216
+ try {
217
+ return getFQName(a);
218
+ }
219
+ catch (_) {
220
+ return undefined;
221
+ }
222
+ }
223
+ export function fetchNamespaceFrom(pointOfView) {
224
+ let node = pointOfView;
225
+ while (node) {
226
+ if (isNamespace(node))
227
+ return node;
228
+ node = node.parent;
229
+ }
230
+ return undefined;
231
+ }
232
+ //# sourceMappingURL=discriminators.js.map
@@ -0,0 +1,48 @@
1
+ import { IndentedPrinter } from "../IndentedPrinter";
2
+ import { stringOrNone } from "../util";
3
+ import { IDLType, IDLInterface, IDLParameter, IDLConstructor, IDLVariable, IDLConstant, IDLProperty, IDLNode, IDLTypedef, IDLExtendedAttribute, IDLFunction, IDLMethod, IDLFile, IDLImport, IDLNamespace, IDLCallback, IDLEntry, IDLEnumMember, IDLEnum } from "./node";
4
+ export declare function escapeIDLKeyword(name: string): string;
5
+ export declare function unescapeKeyword(name: string): string;
6
+ type PrintTypeOptions = {
7
+ [key: string]: any;
8
+ };
9
+ export declare function printType(type: IDLType | IDLInterface | undefined, options?: PrintTypeOptions): string;
10
+ export declare function nameWithType(idl: IDLVariable, isVariadic?: boolean, isOptional?: boolean): string;
11
+ export declare function quoteAttributeValues(attributes?: IDLExtendedAttribute[]): stringOrNone;
12
+ export declare class IDLWriter {
13
+ protected printer: IndentedPrinter;
14
+ constructor(printer: IndentedPrinter);
15
+ print(line: stringOrNone): this;
16
+ pushIndent(): this;
17
+ popIndent(): this;
18
+ getOutput(): string[];
19
+ printReturnType(type: IDLType | IDLInterface | undefined): string;
20
+ printParameters(parameters: IDLParameter[]): string;
21
+ printConstructor(idl: IDLConstructor): this;
22
+ printConstant(idl: IDLConstant): this;
23
+ printProperty(idl: IDLProperty): this;
24
+ printExtendedAttributes(idl: IDLNode): this;
25
+ printSpacedTypeParameters(params: string[] | undefined): string;
26
+ printFunction(idl: IDLFunction): this;
27
+ printMethod(idl: IDLMethod): this;
28
+ printPackage(idl: IDLFile): this;
29
+ printImport(idl: IDLImport): this;
30
+ printNamespace(idl: IDLNamespace): this;
31
+ printCallback(idl: IDLCallback): this;
32
+ printScoped(idl: IDLEntry): this;
33
+ printInterfaceInherit(idl: IDLInterface): string;
34
+ printInterfaceHead(decl: IDLInterface): this;
35
+ printInterface(idl: IDLInterface): this;
36
+ printEnumMember(idl: IDLEnumMember): this;
37
+ printEnum(idl: IDLEnum, skipInitializers: boolean): this;
38
+ printTypedef(idl: IDLTypedef): this;
39
+ printIDL(idl: IDLNode, options?: Partial<IDLPrintOptions>): this;
40
+ }
41
+ export interface IDLPrintOptions {
42
+ verifyIdl: boolean;
43
+ disableEnumInitializers: boolean;
44
+ allowUnknownKinds: boolean;
45
+ }
46
+ export declare function toIDLString(file: IDLFile, options: Partial<IDLPrintOptions>): string;
47
+ export {};
48
+ //# sourceMappingURL=dump.d.ts.map
@@ -0,0 +1,327 @@
1
+ /*
2
+ * Copyright (c) 2025 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
+ import { IndentedPrinter } from "../IndentedPrinter";
16
+ import { isInterface, isOptionalType, isPrimitiveType, isContainerType, isReferenceType, isUnionType, isTypeParameterType, hasExtAttribute } from "./discriminators";
17
+ import { IDLKeywords } from "./keywords";
18
+ import { IDLExtendedAttributes, IDLKind } from "./node";
19
+ import { IDLNullTypeName, IDLUndefinedType, IDLStringType } from "./stdlib";
20
+ export function escapeIDLKeyword(name) {
21
+ return name + (IDLKeywords.has(name) ? "_" : "");
22
+ }
23
+ export function unescapeKeyword(name) {
24
+ if (name.endsWith("_")) {
25
+ const unwrapped = name.slice(0, -1);
26
+ if (IDLKeywords.has(unwrapped))
27
+ return unwrapped;
28
+ }
29
+ return name;
30
+ }
31
+ export function printType(type, options) {
32
+ if (!type)
33
+ throw new Error("Missing type");
34
+ if (isInterface(type))
35
+ return type.name;
36
+ if (isOptionalType(type)) {
37
+ if (hasExtAttribute(type, IDLExtendedAttributes.UnionOnlyNull))
38
+ return `(${printType(type.type)} or ${IDLNullTypeName})`;
39
+ else if (hasExtAttribute(type, IDLExtendedAttributes.UnionWithNull))
40
+ return `(${printType(type.type)} or ${IDLUndefinedType.name} or ${IDLNullTypeName})`;
41
+ else
42
+ return `(${printType(type.type)} or ${IDLUndefinedType.name})`;
43
+ }
44
+ if (isPrimitiveType(type))
45
+ return type.name;
46
+ if (isContainerType(type))
47
+ return `${type.containerKind}<${type.elementType.map(it => printType(it)).join(", ")}>`;
48
+ if (isReferenceType(type)) {
49
+ const maybeExtendedAttributes = type.extendedAttributes && type.extendedAttributes.length
50
+ ? `[${quoteAttributeValues(type.extendedAttributes)}] `
51
+ : '';
52
+ const maybeTypeArguments = type.typeArguments && type.typeArguments.length
53
+ ? '<' + type.typeArguments.map(t => printType(t)).join(', ') + '>'
54
+ : '';
55
+ let res = `${maybeExtendedAttributes}${type.name}${maybeTypeArguments}`;
56
+ if (maybeExtendedAttributes.length && (options === null || options === void 0 ? void 0 : options.bracketsAroundReferenceTypeWithExtAttrs))
57
+ return `(${res})`;
58
+ return res;
59
+ }
60
+ if (isUnionType(type))
61
+ return `(${type.types.map(it => printType(it)).join(" or ")})`;
62
+ if (isTypeParameterType(type))
63
+ return type.name;
64
+ throw new Error(`Cannot map type: ${IDLKind[type.kind]}`);
65
+ }
66
+ export function nameWithType(idl, isVariadic = false, isOptional = false) {
67
+ const type = printType(idl.type);
68
+ const variadic = isVariadic ? "..." : "";
69
+ const optional = isOptional ? "optional " : "";
70
+ return `${optional}${type}${variadic} ${escapeIDLKeyword(idl.name)}`;
71
+ }
72
+ const attributesToQuote = new Set([
73
+ IDLExtendedAttributes.Documentation,
74
+ IDLExtendedAttributes.DtsName,
75
+ IDLExtendedAttributes.DtsTag,
76
+ IDLExtendedAttributes.Import,
77
+ IDLExtendedAttributes.Interfaces,
78
+ IDLExtendedAttributes.TraceKey,
79
+ IDLExtendedAttributes.TypeParametersDefaults,
80
+ ]);
81
+ export function quoteAttributeValues(attributes) {
82
+ return attributes === null || attributes === void 0 ? void 0 : attributes.map(it => {
83
+ let attr = it.name;
84
+ if (it.value) {
85
+ let value = it.value;
86
+ if (value.includes('"') && !value.includes("'"))
87
+ value = value.replaceAll('"', "'");
88
+ value = value.replaceAll('\\', '\\\\').replaceAll('"', '\\"');
89
+ attr += `=${attributesToQuote.has(it.name) ? `"${value}"` : it.value}`;
90
+ }
91
+ return attr;
92
+ }).join(", ");
93
+ }
94
+ export class IDLWriter {
95
+ constructor(printer) {
96
+ this.printer = printer;
97
+ }
98
+ print(line) {
99
+ this.printer.print(line);
100
+ return this;
101
+ }
102
+ pushIndent() {
103
+ this.printer.pushIndent();
104
+ return this;
105
+ }
106
+ popIndent() {
107
+ this.printer.popIndent();
108
+ return this;
109
+ }
110
+ getOutput() {
111
+ return this.printer.getOutput();
112
+ }
113
+ printReturnType(type) {
114
+ return printType(type, { bracketsAroundReferenceTypeWithExtAttrs: true });
115
+ }
116
+ printParameters(parameters) {
117
+ var _a, _b;
118
+ return (_b = (_a = parameters === null || parameters === void 0 ? void 0 : parameters.map(it => nameWithType(it, it.isVariadic, it.isOptional))) === null || _a === void 0 ? void 0 : _a.join(", ")) !== null && _b !== void 0 ? _b : "";
119
+ }
120
+ printConstructor(idl) {
121
+ return this.printExtendedAttributes(idl)
122
+ .print(`constructor(${this.printParameters(idl.parameters)});`);
123
+ }
124
+ printConstant(idl) {
125
+ return this.printExtendedAttributes(idl)
126
+ .print(`const ${nameWithType(idl)}${idl.value ? ` = ${idl.value}` : ``};`);
127
+ }
128
+ printProperty(idl) {
129
+ const staticMod = idl.isStatic ? "static " : "";
130
+ const readonlyMod = idl.isReadonly ? "readonly " : "";
131
+ return this.printExtendedAttributes(idl)
132
+ .print(`${staticMod}${readonlyMod}attribute ${nameWithType(idl)};`);
133
+ }
134
+ printExtendedAttributes(idl) {
135
+ var _a;
136
+ let typeParameters;
137
+ let typeArguments;
138
+ switch (idl.kind) {
139
+ case IDLKind.Interface:
140
+ typeParameters = idl.typeParameters;
141
+ break;
142
+ case IDLKind.Callback:
143
+ case IDLKind.Method:
144
+ case IDLKind.Callable:
145
+ case IDLKind.Constructor:
146
+ typeParameters = idl.typeParameters;
147
+ break;
148
+ case IDLKind.Typedef:
149
+ typeParameters = idl.typeParameters;
150
+ break;
151
+ case IDLKind.ReferenceType:
152
+ typeArguments = idl.typeArguments;
153
+ break;
154
+ }
155
+ const attributes = Array.from((_a = idl.extendedAttributes) !== null && _a !== void 0 ? _a : []);
156
+ if (idl.documentation) {
157
+ let docs = {
158
+ name: IDLExtendedAttributes.Documentation,
159
+ value: idl.documentation
160
+ };
161
+ attributes.unshift(docs);
162
+ }
163
+ // Deduplicate
164
+ const names = new Set();
165
+ const actualAttributes = [];
166
+ for (const attr of attributes) {
167
+ if (names.has(attr.name)) {
168
+ continue;
169
+ }
170
+ names.add(attr.name);
171
+ actualAttributes.push(attr);
172
+ }
173
+ if (actualAttributes.length == 0) {
174
+ return this;
175
+ }
176
+ const attrSpec = quoteAttributeValues(actualAttributes);
177
+ if (attrSpec)
178
+ this.print(`[${attrSpec}]`);
179
+ return this;
180
+ }
181
+ printSpacedTypeParameters(params) {
182
+ return params && params.length
183
+ ? '<' + params.join(', ') + '> '
184
+ : '';
185
+ }
186
+ printFunction(idl) {
187
+ var _a;
188
+ if ((_a = idl.name) === null || _a === void 0 ? void 0 : _a.startsWith("__")) {
189
+ console.log(`Ignore ${idl.name}`);
190
+ return this;
191
+ }
192
+ return this.printExtendedAttributes(idl)
193
+ .print(`${idl.isAsync ? "async " : ""}` +
194
+ `${this.printReturnType(idl.returnType)} ${idl.name}` +
195
+ `(${this.printParameters(idl.parameters)});`);
196
+ }
197
+ printMethod(idl) {
198
+ var _a;
199
+ if ((_a = idl.name) === null || _a === void 0 ? void 0 : _a.startsWith("__")) {
200
+ console.log(`Ignore ${idl.name}`);
201
+ return this;
202
+ }
203
+ return this.printExtendedAttributes(idl)
204
+ .print(`${idl.isStatic ? "static " : ""}${idl.isAsync ? "async " : ""}` +
205
+ `${this.printSpacedTypeParameters(idl.typeParameters)}` +
206
+ `${this.printReturnType(idl.returnType)} ${idl.name}` +
207
+ `(${this.printParameters(idl.parameters)});`);
208
+ }
209
+ printPackage(idl) {
210
+ const effectiveClause = idl.packageClause.filter(it => !!it);
211
+ if (!effectiveClause.length) {
212
+ return this;
213
+ }
214
+ return this.print(`package ${effectiveClause.join(".")};`);
215
+ }
216
+ printImport(idl) {
217
+ const effectiveClause = idl.clause.filter(it => !!it);
218
+ return this.print(`import ${effectiveClause.join(".") || "NULL_IMPORT"}${idl.name ? " as " : ""}${idl.name};`);
219
+ }
220
+ printNamespace(idl) {
221
+ this.printExtendedAttributes(idl)
222
+ .print(`namespace ${idl.name} {`)
223
+ .pushIndent();
224
+ idl.members.forEach(member => this.printIDL(member));
225
+ return this.popIndent().print("};");
226
+ }
227
+ printCallback(idl) {
228
+ return this.printExtendedAttributes(idl)
229
+ .print(`callback ${this.printSpacedTypeParameters(idl.typeParameters)}${idl.name} = ` +
230
+ `${this.printReturnType(idl.returnType)} (${this.printParameters(idl.parameters)});`);
231
+ }
232
+ printScoped(idl) {
233
+ if (idl.kind == IDLKind.Callback)
234
+ return this.printCallback(idl);
235
+ if (idl.kind === IDLKind.Interface)
236
+ return this.printInterface(idl);
237
+ throw new Error(`Unexpected scoped: ${idl.kind} ${idl.name}`);
238
+ }
239
+ printInterfaceInherit(idl) {
240
+ if (idl.inheritance.length === 0) {
241
+ return "";
242
+ }
243
+ const types = idl.inheritance.map(type => printType(type));
244
+ return ": " + types.join(', ');
245
+ }
246
+ printInterfaceHead(decl) {
247
+ return this.print('interface ' +
248
+ this.printSpacedTypeParameters(decl.typeParameters) +
249
+ `${decl.name}${this.printInterfaceInherit(decl)} {`);
250
+ }
251
+ printInterface(idl) {
252
+ this.printExtendedAttributes(idl)
253
+ .printInterfaceHead(idl)
254
+ .pushIndent();
255
+ idl.constructors.forEach(it => this.printConstructor(it));
256
+ idl.constants.forEach(it => this.printConstant(it));
257
+ idl.properties.forEach(it => this.printProperty(it));
258
+ idl.methods.forEach(it => this.printMethod(it));
259
+ idl.callables.forEach(it => this.printFunction(it));
260
+ return this.popIndent().print("};");
261
+ }
262
+ printEnumMember(idl) {
263
+ const type = printType(idl.type);
264
+ const initializer = idl.initializer === undefined
265
+ ? ''
266
+ : ' = ' + (type === IDLStringType.name
267
+ ? `"${String(idl.initializer).replaceAll('"', "'")}"`
268
+ : idl.initializer);
269
+ return this.print(idl.documentation)
270
+ .printExtendedAttributes(idl)
271
+ .print(`${type} ${idl.name}${initializer};`);
272
+ }
273
+ printEnum(idl, skipInitializers) {
274
+ this.print(idl.documentation)
275
+ .printExtendedAttributes(idl);
276
+ if (skipInitializers) {
277
+ this.print(`enum ${idl.name} {`)
278
+ .pushIndent();
279
+ idl.elements.forEach(it => this.print(`${it.name} ${(it.initializer !== undefined ? " /* " + it.initializer + " */" : "")}`));
280
+ return this.popIndent().print("};");
281
+ }
282
+ else {
283
+ this.print(`dictionary ${idl.name} {`)
284
+ .pushIndent();
285
+ idl.elements.forEach(it => this.printEnumMember(it));
286
+ return this.popIndent().print("};");
287
+ }
288
+ }
289
+ printTypedef(idl) {
290
+ return this.print(idl.documentation)
291
+ .printExtendedAttributes(idl)
292
+ .print(`typedef ${this.printSpacedTypeParameters(idl.typeParameters)}${idl.name} = ` +
293
+ `${printType(idl.type)};`);
294
+ }
295
+ printIDL(idl, options) {
296
+ var _a;
297
+ if (idl.kind == IDLKind.Interface)
298
+ return this.printInterface(idl);
299
+ if (idl.kind == IDLKind.Enum)
300
+ return this.printEnum(idl, (_a = options === null || options === void 0 ? void 0 : options.disableEnumInitializers) !== null && _a !== void 0 ? _a : false);
301
+ if (idl.kind == IDLKind.Typedef)
302
+ return this.printTypedef(idl);
303
+ if (idl.kind == IDLKind.Callback)
304
+ return this.printCallback(idl);
305
+ if (idl.kind == IDLKind.Import)
306
+ return this.printImport(idl);
307
+ if (idl.kind == IDLKind.Namespace)
308
+ return this.printNamespace(idl);
309
+ if (idl.kind == IDLKind.Method)
310
+ return this.printMethod(idl);
311
+ if (idl.kind == IDLKind.Const)
312
+ return this.printConstant(idl);
313
+ if (options === null || options === void 0 ? void 0 : options.allowUnknownKinds) {
314
+ return this.print(`${IDLKind[idl.kind]} ${"name" in idl ? idl.name : ""}`);
315
+ }
316
+ else {
317
+ throw new Error(`unexpected kind: ${idl.kind}`);
318
+ }
319
+ }
320
+ }
321
+ export function toIDLString(file, options) {
322
+ const writer = new IDLWriter(new IndentedPrinter());
323
+ writer.printPackage(file);
324
+ file.entries.forEach(it => writer.printIDL(it, options));
325
+ return writer.getOutput().join("\n");
326
+ }
327
+ //# sourceMappingURL=dump.js.map
@@ -0,0 +1,9 @@
1
+ export * from './builders';
2
+ export * from './discriminators';
3
+ export * from './dump';
4
+ export * from './keywords';
5
+ export * from './node';
6
+ export * from './stdlib';
7
+ export * from './utils';
8
+ export * from './visitors';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (c) 2025 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
+ export * from './builders';
16
+ export * from './discriminators';
17
+ export * from './dump';
18
+ export * from './keywords';
19
+ export * from './node';
20
+ export * from './stdlib';
21
+ export * from './utils';
22
+ export * from './visitors';
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export declare const IDLKeywords: Set<string>;
2
+ //# sourceMappingURL=keywords.d.ts.map
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (c) 2024 Huawei Device Co., Ltd.
2
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
3
3
  * Licensed under the Apache License, Version 2.0 (the "License");
4
4
  * you may not use this file except in compliance with the License.
5
5
  * You may obtain a copy of the License at
@@ -12,5 +12,9 @@
12
12
  * See the License for the specific language governing permissions and
13
13
  * limitations under the License.
14
14
  */
15
- export {};
16
- //# sourceMappingURL=options.js.map
15
+ export const IDLKeywords = new Set([
16
+ "attribute", "callback", "object", "toString",
17
+ 'sequence', 'record', 'or', 'Int8Array',
18
+ 'interface', 'number', 'undefined'
19
+ ]);
20
+ //# sourceMappingURL=keywords.js.map