@idlizer/core 2.0.37 → 2.0.40

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.
@@ -16,7 +16,7 @@ import * as idl from "../idl";
16
16
  import { Language } from "../Language";
17
17
  import { PrintHint, BlockStatement, StringExpression } from "./LanguageWriter";
18
18
  import { RuntimeType } from "./common";
19
- import { generatorConfiguration, generatorTypePrefix } from "../config";
19
+ import { generatorTypePrefix } from "../config";
20
20
  import { hashCodeFromString, warn } from "../util";
21
21
  import { UnionRuntimeTypeChecker } from "../peer-generation/unions";
22
22
  import { CppNameConvertor } from "./convertors/CppConvertors";
@@ -509,7 +509,7 @@ export class ArrayConvertor extends BaseArgConvertor {
509
509
  const statements = [];
510
510
  const arrayType = this.idlType;
511
511
  statements.push(writer.makeAssign(lengthBuffer, idl.IDLI32Type, writer.makeString(`${deserializerName}.readInt32()`), true));
512
- statements.push(writer.makeAssign(bufferName, arrayType, writer.makeArrayInit(this.type), true, false));
512
+ statements.push(writer.makeAssign(bufferName, arrayType, writer.makeArrayInit(this.type, lengthBuffer), true, false));
513
513
  statements.push(writer.makeArrayResize(bufferName, writer.getNodeName(arrayType), lengthBuffer, deserializerName));
514
514
  statements.push(writer.makeLoop(counterBuffer, lengthBuffer, this.elementConvertor.convertorDeserialize(`${bufferName}_buf`, deserializerName, (expr) => {
515
515
  return writer.makeAssign(writer.makeArrayAccess(bufferName, counterBuffer).asString(), undefined, expr, false);
@@ -549,7 +549,7 @@ export class MapConvertor extends BaseArgConvertor {
549
549
  convertorSerialize(param, value, printer) {
550
550
  // Map size.
551
551
  const mapSize = printer.makeMapSize(value);
552
- printer.writeMethodCall(`${param}Serializer`, "writeInt32", [mapSize.asString()]);
552
+ printer.writeMethodCall(`${param}Serializer`, "writeInt32", [printer.castToInt(mapSize.asString(), 32)]);
553
553
  printer.writeStatement(printer.makeMapForEach(value, `${value}_key`, `${value}_value`, () => {
554
554
  this.keyConvertor.convertorSerialize(param, `${value}_key`, printer);
555
555
  this.valueConvertor.convertorSerialize(param, `${value}_value`, printer);
@@ -750,12 +750,7 @@ export class OptionConvertor extends BaseArgConvertor {
750
750
  const statements = [];
751
751
  statements.push(writer.makeAssign(runtimeBufferName, undefined, writer.makeCast(writer.makeString(`${deserializerName}.readInt8()`), writer.getRuntimeType()), true));
752
752
  const bufferType = this.nativeType();
753
- if (writer.language == Language.CJ) {
754
- statements.push(writer.makeAssign(bufferName, bufferType, idl.isOptionalType(bufferType) ? writer.makeString('Option.None') : undefined, true, false));
755
- }
756
- else {
757
- statements.push(writer.makeAssign(bufferName, bufferType, undefined, true, false));
758
- }
753
+ statements.push(writer.makeAssign(bufferName, bufferType, writer.language == Language.CJ ? writer.makeNull() : undefined, true, false));
759
754
  const thenStatement = new BlockStatement([
760
755
  this.typeConvertor.convertorDeserialize(`${bufferName}_`, deserializerName, (expr) => {
761
756
  const receiver = writer.language === Language.CPP
@@ -894,7 +889,7 @@ export class MaterializedClassConvertor extends BaseArgConvertor {
894
889
  convertorArg(param, writer) {
895
890
  switch (writer.language) {
896
891
  case Language.CPP:
897
- return `static_cast<${generatorConfiguration().TypePrefix}${this.declaration.name}>(${param})`;
892
+ return `static_cast<${generatorTypePrefix()}${this.declaration.name}>(${param})`;
898
893
  case Language.JAVA:
899
894
  case Language.CJ:
900
895
  return `MaterializedBase.toPeerPtr(${param})`;
@@ -249,7 +249,7 @@ export declare abstract class LanguageWriter {
249
249
  abstract writePrintLog(message: string): void;
250
250
  abstract makeUndefined(): LanguageExpression;
251
251
  makeUnwrapOptional(expression: LanguageExpression): LanguageExpression;
252
- abstract makeArrayInit(type: idl.IDLContainerType, size?: number): LanguageExpression;
252
+ abstract makeArrayInit(type: idl.IDLContainerType, size?: number | string): LanguageExpression;
253
253
  abstract makeClassInit(type: idl.IDLType, paramenters: LanguageExpression[]): LanguageExpression;
254
254
  abstract makeMapInit(type: idl.IDLType): LanguageExpression;
255
255
  abstract makeMapInsert(keyAccessor: string, key: string, valueAccessor: string, value: string): LanguageStatement;
@@ -336,7 +336,7 @@ export declare abstract class LanguageWriter {
336
336
  makeDiscriminatorFromFields(convertor: {
337
337
  targetType: (writer: LanguageWriter) => string;
338
338
  }, value: string, accessors: string[], duplicates: Set<string>): LanguageExpression;
339
- makeCallIsResource(value: string): LanguageExpression;
339
+ makeIsTypeCall(value: string, decl: idl.IDLInterface): LanguageExpression;
340
340
  makeEnumEntity(enumEntity: idl.IDLEnum, isExport: boolean): LanguageStatement;
341
341
  makeFieldModifiersList(modifiers: FieldModifier[] | undefined, customFieldFilter?: (field: FieldModifier) => boolean): string;
342
342
  escapeKeyword(keyword: string): string;
@@ -349,7 +349,6 @@ export declare abstract class LanguageWriter {
349
349
  castToInt(value: string, bitness: 8 | 32): string;
350
350
  castToBoolean(value: string): string;
351
351
  makeCallIsObject(value: string): LanguageExpression;
352
- makeCallIsArrayBuffer(value: string): LanguageExpression;
353
352
  instanceOf(convertor: ArgConvertor, value: string, _duplicateMembers?: Set<string>): LanguageExpression;
354
353
  typeInstanceOf(type: idl.IDLEntry, value: string, members?: string[]): LanguageExpression;
355
354
  makeLengthSerializer(serializer: string, value: string): LanguageStatement | undefined;
@@ -619,8 +619,8 @@ export class LanguageWriter {
619
619
  makeDiscriminatorFromFields(convertor, value, accessors, duplicates) {
620
620
  return this.makeString(`(${this.makeNaryOp("||", accessors.map(it => this.makeString(`${value}!.hasOwnProperty("${it}")`))).asString()})`);
621
621
  }
622
- makeCallIsResource(value) {
623
- return this.makeString(`isResource(${value})`);
622
+ makeIsTypeCall(value, decl) {
623
+ return this.makeString(`is${decl.name}(${value})`);
624
624
  }
625
625
  makeEnumEntity(enumEntity, isExport) {
626
626
  return new TsEnumEntityStatement(enumEntity, isExport);
@@ -666,9 +666,6 @@ export class LanguageWriter {
666
666
  makeCallIsObject(value) {
667
667
  return this.makeString(`typeof ${value} === "object"`);
668
668
  }
669
- makeCallIsArrayBuffer(value) {
670
- return this.makeString(`${value} instanceof ArrayBuffer`);
671
- }
672
669
  instanceOf(convertor, value, _duplicateMembers) {
673
670
  return this.makeString(`${value} instanceof ${this.getNodeName(convertor.idlType)}`);
674
671
  }
@@ -37,6 +37,9 @@ export class CJTypeNameConvertor {
37
37
  const stringes = type.elementType.slice(0, 2).map(it => convertType(this, it));
38
38
  return `Map<${stringes[0]}, ${stringes[1]}>`;
39
39
  }
40
+ if (idl.IDLContainerUtils.isPromise(type)) {
41
+ return `Any`;
42
+ }
40
43
  throw new Error(`IDL type ${idl.DebugUtils.debugPrintType(type)} not supported`);
41
44
  }
42
45
  convertNamespace(node) {
@@ -106,13 +109,14 @@ export class CJTypeNameConvertor {
106
109
  case idl.IDLF64Type: return 'Float64';
107
110
  case idl.IDLPointerType: return 'UInt64';
108
111
  case idl.IDLVoidType: return 'Unit';
109
- case idl.IDLBufferType:
112
+ case idl.IDLBufferType: return 'Array<UInt8>';
110
113
  case idl.IDLInteropReturnBufferType: return 'Array<UInt8>';
114
+ case idl.IDLBigintType: return 'Int64';
111
115
  }
112
116
  throw new Error(`Unsupported IDL primitive ${idl.DebugUtils.debugPrintType(type)}`);
113
117
  }
114
118
  callbackType(decl) {
115
- const params = decl.parameters.map(it => `${it.name}: ${it.isOptional ? "?" : ""}${this.convert(it.type)}`);
119
+ const params = decl.parameters.map(it => `${it.name}: ${this.convert(it.type)}`);
116
120
  return `((${params.join(", ")}) -> ${this.convert(decl.returnType)})`;
117
121
  }
118
122
  productType(decl, isTuple, includeFieldNames) {
@@ -126,6 +130,7 @@ export class CJIDLTypeToForeignStringConvertor extends CJTypeNameConvertor {
126
130
  if (idl.isPrimitiveType(type)) {
127
131
  switch (type) {
128
132
  case idl.IDLStringType: return 'CString';
133
+ case idl.IDLInteropReturnBufferType: return 'KInteropReturnBuffer';
129
134
  }
130
135
  }
131
136
  if (idl.isContainerType(type)) {
@@ -30,6 +30,7 @@ export declare class GenericCppConvertor implements NodeConvertor<ConvertResult>
30
30
  }
31
31
  export declare class CppConvertor extends GenericCppConvertor implements IdlNameConvertor {
32
32
  private unwrap;
33
+ private isPrimitiveOrPrimitiveAlias;
33
34
  convert(node: idl.IDLNode): string;
34
35
  }
35
36
  export declare class CppNameConvertor implements IdlNameConvertor {
@@ -178,9 +178,23 @@ export class CppConvertor extends GenericCppConvertor {
178
178
  const typePrefix = conf.TypePrefix;
179
179
  // TODO remove this ugly hack for CustomObject's
180
180
  const convertedToCustomObject = result.text === idl.IDLCustomObjectType.name;
181
- const libPrefix = idl.isPrimitiveType(type) || convertedToCustomObject ? "" : conf.LibraryPrefix;
181
+ const libPrefix = this.isPrimitiveOrPrimitiveAlias(type) || convertedToCustomObject ? "" : conf.LibraryPrefix;
182
182
  return `${typePrefix}${libPrefix}${result.text}`;
183
183
  }
184
+ isPrimitiveOrPrimitiveAlias(type) {
185
+ if (!idl.isType(type))
186
+ return false;
187
+ const { resolver } = this;
188
+ while (type && idl.isReferenceType(type)) {
189
+ const resolved = resolver.resolveTypeReference(type);
190
+ if (!resolved)
191
+ return false;
192
+ if (!idl.isTypedef(resolved))
193
+ break;
194
+ type = resolved.type;
195
+ }
196
+ return idl.isPrimitiveType(type);
197
+ }
184
198
  convert(node) {
185
199
  return this.unwrap(node, this.convertNode(node));
186
200
  }
@@ -60,11 +60,11 @@ export class InteropReturnTypeConvertor {
60
60
  case idl.IDLBooleanType: return PrimitiveTypesInstance.Boolean.getText();
61
61
  case idl.IDLBigintType: return PrimitiveTypesInstance.Int64.getText();
62
62
  case idl.IDLAnyType:
63
- case idl.IDLBufferType:
64
63
  case idl.IDLThisType:
65
64
  case idl.IDLUndefinedType:
66
65
  case idl.IDLUnknownType:
67
66
  case idl.IDLVoidType: return idl.IDLVoidType.name;
67
+ case idl.IDLBufferType: return KInteropReturnBuffer; /* ArkTS can not return buffer as language object yet */
68
68
  case idl.IDLStringType: return PrimitiveTypesInstance.String.getText();
69
69
  case idl.IDLPointerType: return PrimitiveTypesInstance.NativePointer.getText();
70
70
  }
@@ -152,7 +152,7 @@ class CJMapForEachStatement {
152
152
  this.op = op;
153
153
  }
154
154
  write(writer) {
155
- writer.print(`for ((key, value) in ${this.map}) {`);
155
+ writer.print(`for ((${this.key}, ${this.value}) in ${this.map}) {`);
156
156
  writer.pushIndent();
157
157
  this.op();
158
158
  writer.popIndent();
@@ -266,7 +266,9 @@ export class CJLanguageWriter extends LanguageWriter {
266
266
  return new CJLanguageWriter(new IndentedPrinter(), (_a = options === null || options === void 0 ? void 0 : options.resolver) !== null && _a !== void 0 ? _a : this.resolver, this.typeConvertor, this.typeForeignConvertor);
267
267
  }
268
268
  getNodeName(type) {
269
- return this.typeConvertor.convert(type);
269
+ // rework for proper namespace logic
270
+ let name = this.typeConvertor.convert(type).split('.');
271
+ return name[name.length - 1];
270
272
  }
271
273
  writeClass(name, op, superClass, interfaces, generics) {
272
274
  let extendsClause = superClass ? `${superClass}` : undefined;
@@ -417,7 +419,7 @@ export class CJLanguageWriter extends LanguageWriter {
417
419
  throw new Error(`makeClassInit`);
418
420
  }
419
421
  makeArrayInit(type, size) {
420
- return this.makeString(`ArrayList<${this.getNodeName(type.elementType[0])}>(${size !== null && size !== void 0 ? size : ''})`);
422
+ return this.makeString(`ArrayList<${this.getNodeName(type.elementType[0])}>(Int64(${size !== null && size !== void 0 ? size : ''}))`);
421
423
  }
422
424
  makeMapInit(type) {
423
425
  throw new Error(`TBD`);
@@ -491,7 +493,7 @@ export class CJLanguageWriter extends LanguageWriter {
491
493
  return this.makeString("Option.None");
492
494
  }
493
495
  makeUnwrapOptional(expression) {
494
- return new CJMatchExpression(expression, [this.makeString('Some(serializer)')], [this.makeString('serializer')], this.indentDepth());
496
+ return new CJMatchExpression(expression, [this.makeString(`Some(unwrap_value)`)], [this.makeString(`unwrap_value`)], this.indentDepth());
495
497
  }
496
498
  makeValueFromOption(value, destinationConvertor) {
497
499
  return this.makeString(`${value}`);
@@ -50,7 +50,7 @@ export declare class ETSLanguageWriter extends TSLanguageWriter {
50
50
  targetType: (writer: LanguageWriter) => string;
51
51
  }, value: string, accessors: string[], duplicates: Set<string>): LanguageExpression;
52
52
  makeValueFromOption(value: string, destinationConvertor: ArgConvertor): LanguageExpression;
53
- makeCallIsResource(value: string): LanguageExpression;
53
+ makeIsTypeCall(value: string, decl: idl.IDLInterface): LanguageExpression;
54
54
  makeEnumEntity(enumEntity: IDLEnum, isExport: boolean): LanguageStatement;
55
55
  getObjectAccessor(convertor: ArgConvertor, value: string, args?: ObjectArgs): string;
56
56
  writeMethodCall(receiver: string, method: string, params: string[], nullable?: boolean): void;
@@ -210,8 +210,8 @@ export class ETSLanguageWriter extends TSLanguageWriter {
210
210
  }
211
211
  return super.makeValueFromOption(value, destinationConvertor);
212
212
  }
213
- makeCallIsResource(value) {
214
- return this.makeString(`isResource(${value})`);
213
+ makeIsTypeCall(value, decl) {
214
+ return makeInterfaceTypeCheckerCall(value, decl.name, decl.properties.map(it => it.name), new Set(), this);
215
215
  }
216
216
  makeEnumEntity(enumEntity, isExport) {
217
217
  return new ArkTSEnumEntityStatement(enumEntity, isExport);
@@ -234,7 +234,8 @@ export class ETSLanguageWriter extends TSLanguageWriter {
234
234
  if (!idl.isEnum(decl)) {
235
235
  throwException(`Declaration type must be Enum`);
236
236
  }
237
- return this.makeCast(this.makeString(`${value}${idl.isStringEnum(decl) ? "" : ".valueOf()"}`), IDLI32Type).asString();
237
+ // ((value as Axis) as int) - in case when Axis was casted to Object in Map<Axis, Smth>
238
+ return this.makeCast(this.makeCast(this.makeString(value), convertor.idlType), IDLI32Type).asString();
238
239
  }
239
240
  makeUnionVariantCondition(convertor, valueName, valueType, type, convertorIndex, runtimeTypeIndex) {
240
241
  if (idl.isEnum(this.resolver.toDeclaration(convertor.nativeType()))) {
@@ -315,18 +316,7 @@ export class ETSLanguageWriter extends TSLanguageWriter {
315
316
  return new TSCastExpression(value, `${this.getNodeName(type)}`, (_a = options === null || options === void 0 ? void 0 : options.unsafe) !== null && _a !== void 0 ? _a : false);
316
317
  }
317
318
  }
318
- const builtInInterfaceTypes = new Map([
319
- ["Resource",
320
- (writer, value) => writer.makeCallIsResource(value)],
321
- ["Object",
322
- (writer, value) => writer.makeCallIsObject(value)],
323
- ["ArrayBuffer",
324
- (writer, value) => writer.makeCallIsArrayBuffer(value)]
325
- ]);
326
319
  function makeInterfaceTypeCheckerCall(valueAccessor, interfaceName, allFields, duplicates, writer) {
327
- if (builtInInterfaceTypes.has(interfaceName)) {
328
- return builtInInterfaceTypes.get(interfaceName)(writer, valueAccessor);
329
- }
330
320
  return writer.makeMethodCall("TypeChecker", generateTypeCheckerName(interfaceName), [writer.makeString(valueAccessor),
331
321
  ...allFields.map(it => {
332
322
  return writer.makeString(duplicates.has(it) ? "true" : "false");
@@ -364,7 +364,7 @@ export class TSLanguageWriter extends LanguageWriter {
364
364
  return this.makeAssign(receiver, undefined, this.makeString(`[${fields.map(it => `${it}!`).join(",")}]`), false);
365
365
  }
366
366
  get supportedModifiers() {
367
- return [MethodModifier.PUBLIC, MethodModifier.PRIVATE, MethodModifier.STATIC];
367
+ return [MethodModifier.PUBLIC, MethodModifier.PRIVATE, MethodModifier.PROTECTED, MethodModifier.STATIC];
368
368
  }
369
369
  get supportedFieldModifiers() {
370
370
  return [FieldModifier.PUBLIC, FieldModifier.PRIVATE, FieldModifier.PROTECTED, FieldModifier.READONLY, FieldModifier.STATIC];
@@ -8,6 +8,7 @@ export interface CoreConfiguration {
8
8
  readonly ignoreMaterialized: string[];
9
9
  readonly builderClasses: string[];
10
10
  readonly forceMaterialized: string[];
11
+ readonly forceCallback: string[];
11
12
  }
12
13
  export declare const defaultCoreConfuguration: CoreConfiguration;
13
14
  export declare function setDefaultConfiguration<T extends CoreConfiguration>(config: T): void;
@@ -22,6 +22,7 @@ export const defaultCoreConfuguration = {
22
22
  ignoreMaterialized: [],
23
23
  builderClasses: [],
24
24
  forceMaterialized: [],
25
+ forceCallback: [],
25
26
  };
26
27
  let currentConfig = defaultCoreConfuguration;
27
28
  export function setDefaultConfiguration(config) {
@@ -0,0 +1,2 @@
1
+ export declare function deepMergeConfig<T extends object>(defaults: T, custom: Partial<T>): T;
2
+ //# sourceMappingURL=configMerge.d.ts.map
@@ -0,0 +1,42 @@
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
+ function isObject(i) {
16
+ if (typeof i !== 'object')
17
+ return false;
18
+ if (Array.isArray(i))
19
+ return false;
20
+ return true;
21
+ }
22
+ export function deepMergeConfig(defaults, custom) {
23
+ if (custom === undefined)
24
+ return defaults;
25
+ const result = Object.assign({}, defaults);
26
+ for (const key in custom) {
27
+ if (Object.prototype.hasOwnProperty.call(custom, key)) {
28
+ const defaultValue = result[key];
29
+ const customValue = custom[key];
30
+ if (isObject(defaultValue) && isObject(customValue)) {
31
+ Object.assign(result, { [key]: deepMergeConfig(defaultValue, customValue) });
32
+ }
33
+ else {
34
+ if (isObject(defaultValue))
35
+ throw new Error("Replacing default object value with custom non-object");
36
+ Object.assign(result, { [key]: customValue });
37
+ }
38
+ }
39
+ }
40
+ return result;
41
+ }
42
+ //# sourceMappingURL=configMerge.js.map
@@ -113,8 +113,6 @@ function toIDLInterface(file, node) {
113
113
  documentation: makeDocs(node),
114
114
  extendedAttributes: toExtendedAttributes(node.extAttrs),
115
115
  });
116
- if (result.inheritance.length && idl.isReferenceType(result.inheritance[0]))
117
- result.inheritance[0].typeArguments = extractTypeArguments(file, node.extAttrs, idl.IDLExtendedAttributes.TypeArguments);
118
116
  if (node.extAttrs.find(it => it.name === "Synthetic"))
119
117
  addSyntheticType(node.name, result);
120
118
  return result;
@@ -20,10 +20,19 @@ export declare class ETSDeclarationNameConvertor extends DeclarationNameConverto
20
20
  convertEnum(decl: idl.IDLEnum): string;
21
21
  static readonly I: ETSDeclarationNameConvertor;
22
22
  }
23
+ export declare class CJDeclarationNameConvertor extends DeclarationNameConvertor {
24
+ convertInterface(decl: idl.IDLInterface): string;
25
+ convertEnum(decl: idl.IDLEnum): string;
26
+ static readonly I: CJDeclarationNameConvertor;
27
+ }
23
28
  export declare class ETSFeatureNameConvertor extends DeclarationNameConvertor {
24
29
  convertEnum(decl: idl.IDLEnum): string;
25
30
  static readonly I: ETSFeatureNameConvertor;
26
31
  }
32
+ export declare class CJFeatureNameConvertor extends DeclarationNameConvertor {
33
+ convertEnum(decl: idl.IDLEnum): string;
34
+ static readonly I: CJFeatureNameConvertor;
35
+ }
27
36
  export declare function createDeclarationNameConvertor(language: Language): DeclarationNameConvertor;
28
37
  export declare function createFeatureNameConvertor(language: Language): DeclarationNameConvertor;
29
38
  //# sourceMappingURL=IdlNameConvertor.d.ts.map
@@ -57,6 +57,15 @@ export class ETSDeclarationNameConvertor extends DeclarationNameConvertor {
57
57
  }
58
58
  }
59
59
  ETSDeclarationNameConvertor.I = new ETSDeclarationNameConvertor();
60
+ export class CJDeclarationNameConvertor extends DeclarationNameConvertor {
61
+ convertInterface(decl) {
62
+ return decl.name;
63
+ }
64
+ convertEnum(decl) {
65
+ return decl.name;
66
+ }
67
+ }
68
+ CJDeclarationNameConvertor.I = new CJDeclarationNameConvertor();
60
69
  export class ETSFeatureNameConvertor extends DeclarationNameConvertor {
61
70
  convertEnum(decl) {
62
71
  const namespace = idl.getNamespacesPathFor(decl).map(it => it.name);
@@ -66,13 +75,19 @@ export class ETSFeatureNameConvertor extends DeclarationNameConvertor {
66
75
  }
67
76
  }
68
77
  ETSFeatureNameConvertor.I = new ETSFeatureNameConvertor();
78
+ export class CJFeatureNameConvertor extends DeclarationNameConvertor {
79
+ convertEnum(decl) {
80
+ return decl.name;
81
+ }
82
+ }
83
+ CJFeatureNameConvertor.I = new CJFeatureNameConvertor();
69
84
  export function createDeclarationNameConvertor(language) {
70
85
  switch (language) {
71
86
  case Language.ARKTS: return ETSDeclarationNameConvertor.I;
72
87
  case Language.JAVA:
73
88
  case Language.CPP:
74
- case Language.CJ:
75
89
  case Language.TS: return DeclarationNameConvertor.I;
90
+ case Language.CJ: CJDeclarationNameConvertor.I;
76
91
  default: throw new Error(`Language ${language.toString()} is not supported`);
77
92
  }
78
93
  }
@@ -81,8 +96,8 @@ export function createFeatureNameConvertor(language) {
81
96
  case Language.ARKTS: return ETSFeatureNameConvertor.I;
82
97
  case Language.JAVA:
83
98
  case Language.CPP:
84
- case Language.CJ:
85
99
  case Language.TS: return TSFeatureNameConvertor.I;
100
+ case Language.CJ: return CJFeatureNameConvertor.I;
86
101
  default: throw new Error(`Language ${language.toString()} is not supported`);
87
102
  }
88
103
  }
@@ -24,6 +24,9 @@ export function isMaterialized(declaration, resolver) {
24
24
  if (declaration.name == forceMaterialized)
25
25
  return true;
26
26
  }
27
+ if (generatorConfiguration().forceCallback.includes(declaration.name)) {
28
+ return false;
29
+ }
27
30
  for (const ignore of generatorConfiguration().ignoreMaterialized) {
28
31
  if (declaration.name.endsWith(ignore))
29
32
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idlizer/core",
3
- "version": "2.0.37",
3
+ "version": "2.0.40",
4
4
  "description": "",
5
5
  "types": "build/lib/src/index.d.ts",
6
6
  "exports": {
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Robin Berjon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,827 @@
1
+ # webidl2.js
2
+
3
+ [![NPM version](https://badge.fury.io/js/webidl2.svg)](http://badge.fury.io/js/webidl2) [![Known Vulnerabilities](https://snyk.io/test/github/w3c/webidl2.js/badge.svg)](https://snyk.io/test/github/w3c/webidl2.js/)
4
+ [![Financial Contributors on Open Collective](https://opencollective.com/webidl2js/all/badge.svg?label=financial+contributors)](https://opencollective.com/webidl2js)
5
+
6
+ ## Purpose
7
+
8
+ This is a parser for [Web IDL](https://heycam.github.io/webidl/), a language
9
+ [to specify web APIs in interoperable way](https://heycam.github.io/webidl/#introduction).
10
+ This library supports both Node.js and the browser environment.
11
+
12
+ Try the online checker [here](https://w3c.github.io/webidl2.js/checker/).
13
+
14
+ ## Installation
15
+
16
+ Just the usual. For Node:
17
+
18
+ ```Bash
19
+ npm install webidl2
20
+ ```
21
+
22
+ In the browser without module support:
23
+
24
+ ```HTML
25
+ <script src='./webidl2/dist/webidl2.js'></script>
26
+ ```
27
+
28
+ ## Documentation
29
+
30
+ WebIDL2 provides two functions: `parse` and `write`.
31
+
32
+ * `parse`: Converts a WebIDL string into a syntax tree.
33
+ * `write`: Converts a syntax tree into a WebIDL string. Useful for programmatic code
34
+ modification.
35
+
36
+ In Node, that happens with:
37
+
38
+ ```JS
39
+ const { parse, write, validate } = require("webidl2");
40
+ const tree = parse("string of WebIDL");
41
+ const text = write(tree);
42
+ const validation = validate(tree);
43
+ ```
44
+
45
+ In the browser:
46
+ ```HTML
47
+ <script>
48
+ const tree = WebIDL2.parse("string of WebIDL");
49
+ const text = WebIDL2.write(tree);
50
+ const validation = WebIDL2.validate(tree);
51
+ </script>
52
+
53
+ <!-- Or when module is supported -->
54
+ <script type="module">
55
+ import { parse, write, validate } from "./webidl2/index.js";
56
+ const tree = parse("string of WebIDL");
57
+ const text = write(tree);
58
+ const validation = validate(tree);
59
+ </script>
60
+ ```
61
+
62
+ `parse()` optionally takes an option bag with the following fields:
63
+
64
+ * `concrete`: Boolean indicating whether the result should include [EOF](#end-of-file)
65
+ node or not.
66
+ * `productions`: An array with custom production functions. See [Custom productions](docs/custom-productions.md) for more information.
67
+ * `sourceName`: The source name, typically a filename. [Errors](#errors) and validation
68
+ objects can indicate their origin if you pass a value.
69
+
70
+ `write()` optionally takes a "templates" object, whose properties are functions that process input in different ways (depending on what is needed for output). Every property is optional. Each property is documented below:
71
+
72
+ ```js
73
+ var result = WebIDL2.write(tree, {
74
+ templates: {
75
+ /**
76
+ * A function that receives syntax strings plus anything the templates returned.
77
+ * The items are guaranteed to be ordered.
78
+ * The returned value may be again passed to any template functions,
79
+ * or it may also be the final return value of `write()`.
80
+ * @param {any[]} items
81
+ */
82
+ wrap: items => items.join(""),
83
+ /**
84
+ * @param {string} t A trivia string, which includes whitespaces and comments.
85
+ */
86
+ trivia: t => t,
87
+ /**
88
+ * The identifier for a container type. For example, the `Foo` part of `interface Foo {};`.
89
+ * @param {string} escaped The escaped raw name of the definition.
90
+ * @param data The definition with the name
91
+ * @param parent The parent of the definition, undefined if absent
92
+ */
93
+ name: (escaped, { data, parent }) => escaped,
94
+ /**
95
+ * Called for each type referece, e.g. `Window`, `DOMString`, or `unsigned long`.
96
+ * @param escaped The referenced name. Typically string, but may also be the return
97
+ * value of `wrap()` if the name contains whitespace.
98
+ * @param unescaped Unescaped reference.
99
+ */
100
+ reference: (escaped, unescaped) => escaped,
101
+ /**
102
+ * Called for each generic-form syntax, e.g. `sequence`, `Promise`, or `maplike`.
103
+ * @param {string} name The keyword for syntax
104
+ */
105
+ generic: name => name,
106
+ /**
107
+ * Called for each nameless members, e.g. `stringifier` for `stringifier;` and `constructor` for `constructor();`
108
+ * @param {string} name The keyword for syntax
109
+ */
110
+ nameless: (keyword, { data, parent }) => keyword,
111
+ /**
112
+ * Called only once for each types, e.g. `Document`, `Promise<DOMString>`, or `sequence<long>`.
113
+ * @param type The `wrap()`ed result of references and syntatic bracket strings.
114
+ */
115
+ type: type => type,
116
+ /**
117
+ * Receives the return value of `reference()`. String if it's absent.
118
+ */
119
+ inheritance: inh => inh,
120
+ /**
121
+ * Called for each IDL type definition, e.g. an interface, an operation, or a typedef.
122
+ * @param content The wrapped value of everything the definition contains.
123
+ * @param data The original definition object
124
+ * @param parent The parent of the definition, undefined if absent
125
+ */
126
+ definition: (content, { data, parent }) => content,
127
+ /**
128
+ * Called for each extended attribute annotation.
129
+ * @param content The wrapped value of everything the annotation contains.
130
+ */
131
+ extendedAttribute: content => content,
132
+ /**
133
+ * The `Foo` part of `[Foo=Whatever]`.
134
+ * @param ref The name of the referenced extended attribute name.
135
+ */
136
+ extendedAttributeReference: ref => ref
137
+ }
138
+ });
139
+ ```
140
+
141
+ "Wrapped value" here will all be raw strings when the `wrap()` callback is absent.
142
+
143
+ `validate()` receives an AST or an array of AST, and returns semantic errors as an
144
+ array of objects. Their fields are same as [errors](#errors) have, with one addition:
145
+
146
+ * `level`: `"error"` or `"warning"`.
147
+
148
+ ```js
149
+ const validations = validate(tree);
150
+ for (const validation of validations) {
151
+ console.log(validation.message);
152
+ }
153
+ // Validation error on line X: ...
154
+ // Validation error on line Y: ...
155
+ ```
156
+
157
+ The validator function may provide an autofix function that modifies AST. You can
158
+ optionally call it to skip manual fixes, but make sure you review the result.
159
+
160
+ ```js
161
+ const validations = validate(tree);
162
+ for (const validation of validations) {
163
+ if (validation.autofix) {
164
+ validation.autofix();
165
+ }
166
+ }
167
+ write(tree); // magic!
168
+ ```
169
+
170
+ ### Errors
171
+
172
+ When there is a syntax error in the WebIDL, it throws an exception object with the following
173
+ properties:
174
+
175
+ * `message`: the error message with its context. Below is what it looks like.
176
+ ```
177
+ Syntax error at line 1 in callback-noparen.webidl, since `callback YourCall`:
178
+ callback YourCall = undefined;
179
+ ^ Callback lacks parentheses for arguments
180
+ ```
181
+ * `bareMessage`: the error message without any context description like below.
182
+ ```
183
+ Callback lacks parentheses for arguments
184
+ ```
185
+ * `line`: the line at which the error occurred.
186
+ * `sourceName`: the source name you passed to `parse()`.
187
+ * `level`: `"error"` by default, can be `"warning"` for some validations for e.g. potential future deprecations.
188
+ * `ruleName`: Only for validations. Currently the followings are supported:
189
+ * `attr-invalid-type`: Attributes cannot have sequences, records, nor dictionaries.
190
+ * `dict-arg-default`: Optional dictionary type arguments must have a default value of `{}`.
191
+ * `dict-arg-optional`: Dictionary type arguments must be optional if the type does not include a required field.
192
+ * `no-nullable-dict-arg`: Dictionary arguments cannot be nullable.
193
+ * `no-nullable-union-dict`: Nullable unions cannot include a dictionary type.
194
+ * `constructor-member`: Constructors must use newer `constructor()` syntax.
195
+ * `no-duplicate`: Types cannot have identical names.
196
+ * `require-exposed`: Interfaces must explicitly expose themselves to specific contexts by `[Exposed]`.
197
+ * `incomplete-op`: Regular or static operations must have both a return type and an identifier.
198
+ * `no-cross-overload`: Overloading must be done within a single interface or namespace.
199
+ * `no-constructible-global`: Interfaces with `[Global]` cannot have constructors.
200
+ * `renamed-legacy`: Legacy extended attributes must use their new names.
201
+ * `replace-void`: `void` type is replaced by `undefined` type.
202
+ * `migrate-allowshared`: `[AllowShared] BufferSource` is replaced by `AllowSharedBufferSource`.
203
+ * `input`: a short peek at the text at the point where the error happened
204
+ * `tokens`: the five tokens at the point of error, as understood by the tokeniser
205
+ (this is the same content as `input`, but seen from the tokeniser's point of view)
206
+
207
+ The exception also has a `toString()` method that hopefully should produce a decent
208
+ error message.
209
+
210
+ ### AST (Abstract Syntax Tree)
211
+
212
+ The `parse()` method returns a tree object representing the parse tree of the IDL.
213
+ Comment and white space are not represented in the AST.
214
+
215
+ The root of this object is always an array of definitions (where definitions are
216
+ any of interfaces, dictionaries, callbacks, etc. — anything that can occur at the root
217
+ of the IDL).
218
+
219
+ ### IDL Type
220
+
221
+ This structure is used in many other places (operation return types, argument types, etc.).
222
+ It captures a WebIDL type with a number of options. Types look like this and are typically
223
+ attached to a field called `idlType`:
224
+
225
+ ```JS
226
+ {
227
+ "type": "attribute-type",
228
+ "generic": "",
229
+ "idlType": "unsigned short",
230
+ "nullable": false,
231
+ "union": false,
232
+ "extAttrs": [...]
233
+ }
234
+ ```
235
+
236
+ Where the fields are as follows:
237
+
238
+ * `type`: String indicating where this type is used. Can be `null` if not applicable.
239
+ * `generic`: String indicating the generic type (e.g. "Promise", "sequence").
240
+ * `idlType`: String indicating the type name, or array of subtypes if the type is
241
+ generic or a union.
242
+ * `nullable`: `true` if the type is nullable.
243
+ * `union`: Boolean indicating whether this is a union type or not.
244
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
245
+
246
+ ### Interface
247
+
248
+ Interfaces look like this:
249
+
250
+ ```JS
251
+ {
252
+ "type": "interface",
253
+ "name": "Animal",
254
+ "partial": false,
255
+ "members": [...],
256
+ "inheritance": null,
257
+ "extAttrs": [...]
258
+ }, {
259
+ "type": "interface",
260
+ "name": "Human",
261
+ "partial": false,
262
+ "members": [...],
263
+ "inheritance": "Animal",
264
+ "extAttrs": [...]
265
+ }
266
+ ```
267
+
268
+ The fields are as follows:
269
+
270
+ * `type`: Always "interface".
271
+ * `name`: The name of the interface.
272
+ * `partial`: `true` if the type is a partial interface.
273
+ * `members`: An array of interface members (attributes, operations, etc.). Empty if there are none.
274
+ * `inheritance`: The name of an interface this one inherits from, `null` otherwise.
275
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
276
+
277
+ ### Interface mixins
278
+
279
+ Interfaces mixins look like this:
280
+
281
+ ```JS
282
+ {
283
+ "type": "interface mixin",
284
+ "name": "Animal",
285
+ "inheritance": null,
286
+ "partial": false,
287
+ "members": [...],
288
+ "extAttrs": [...]
289
+ }, {
290
+ "type": "interface mixin",
291
+ "name": "Human",
292
+ "inheritance": null,
293
+ "partial": false,
294
+ "members": [...],
295
+ "extAttrs": [...]
296
+ }
297
+ ```
298
+
299
+ The fields are as follows:
300
+
301
+ * `type`: Always "interface mixin".
302
+ * `name`: The name of the interface mixin.
303
+ * `inheritance`: Always `null`.
304
+ * `partial`: `true if the type is a partial interface mixin.
305
+ * `members`: An array of interface members (attributes, operations, etc.). Empty if there are none.
306
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
307
+
308
+ ### Namespace
309
+
310
+ Namespaces look like this:
311
+
312
+ ```JS
313
+ {
314
+ "type": "namespace",
315
+ "name": "console",
316
+ "inheritance": null,
317
+ "partial": false,
318
+ "members": [...],
319
+ "extAttrs": [...]
320
+ }
321
+ ```
322
+
323
+ The fields are as follows:
324
+
325
+ * `type`: Always "namespace".
326
+ * `name`: The name of the namespace.
327
+ * `inheritance`: Always `null`.
328
+ * `partial`: `true if the type is a partial namespace.
329
+ * `members`: An array of namespace members (attributes, constants, and operations). Empty if there are none.
330
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
331
+
332
+ ### Callback Interfaces
333
+
334
+ These are captured by the same structure as [Interfaces](#interface) except that
335
+ their `type` field is "callback interface".
336
+
337
+ ### Callback
338
+
339
+ A callback looks like this:
340
+
341
+ ```JS
342
+ {
343
+ "type": "callback",
344
+ "name": "AsyncOperationCallback",
345
+ "idlType": {
346
+ "type": "return-type",
347
+ "generic": "",
348
+ "nullable": false,
349
+ "union": false,
350
+ "idlType": "undefined",
351
+ "extAttrs": []
352
+ },
353
+ "arguments": [...],
354
+ "extAttrs": []
355
+ }
356
+ ```
357
+
358
+ The fields are as follows:
359
+
360
+ * `type`: Always "callback".
361
+ * `name`: The name of the callback.
362
+ * `idlType`: An [IDL Type](#idl-type) describing what the callback returns.
363
+ * `arguments`: A list of [arguments](#arguments), as in function paramters.
364
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
365
+
366
+ ### Dictionary
367
+
368
+ A dictionary looks like this:
369
+
370
+ ```JS
371
+ {
372
+ "type": "dictionary",
373
+ "name": "PaintOptions",
374
+ "partial": false,
375
+ "members": [{
376
+ "type": "field",
377
+ "name": "fillPattern",
378
+ "required": false,
379
+ "idlType": {
380
+ "type": "dictionary-type",
381
+ "generic": "",
382
+ "nullable": true
383
+ "union": false,
384
+ "idlType": "DOMString",
385
+ "extAttrs": []
386
+ },
387
+ "extAttrs": [],
388
+ "default": {
389
+ "type": "string",
390
+ "value": "black"
391
+ }
392
+ }],
393
+ "inheritance": null,
394
+ "extAttrs": []
395
+ }
396
+ ```
397
+
398
+ The fields are as follows:
399
+
400
+ * `type`: Always "dictionary".
401
+ * `name`: The dictionary name.
402
+ * `partial`: `true` if the type is a partial dictionary.
403
+ * `members`: An array of members (see below).
404
+ * `inheritance`: An object indicating which dictionary is being inherited from, `null` otherwise.
405
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
406
+
407
+ All the members are fields as follows:
408
+
409
+ * `type`: Always "field".
410
+ * `name`: The name of the field.
411
+ * `required`: `true` if the field is required.
412
+ * `idlType`: An [IDL Type](#idl-type) describing what field's type.
413
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
414
+ * `default`: A [default value](#default-and-const-values), or `null` if there is none.
415
+
416
+ ### Enum
417
+
418
+ An enum looks like this:
419
+
420
+ ```JS
421
+ {
422
+ "type": "enum",
423
+ "name": "MealType",
424
+ "values": [
425
+ {
426
+ "type": "enum-value",
427
+ "value": "rice"
428
+ },
429
+ {
430
+ "type": "enum-value",
431
+ "value": "noodles"
432
+ },
433
+ {
434
+ "type": "enum-value",
435
+ "value": "other"
436
+ }
437
+ ]
438
+ "extAttrs": []
439
+ }
440
+ ```
441
+
442
+ The fields are as follows:
443
+
444
+ * `type`: Always "enum".
445
+ * `name`: The enum's name.
446
+ * `values`: An array of values. The type of value is "enum-value".
447
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
448
+
449
+ ### Typedef
450
+
451
+ A typedef looks like this:
452
+
453
+ ```JS
454
+ {
455
+ "type": "typedef",
456
+ "idlType": {
457
+ "type": "typedef-type",
458
+ "generic": "sequence",
459
+ "nullable": false,
460
+ "union": false,
461
+ "idlType": [
462
+ {
463
+ "type": "typedef-type",
464
+ "generic": "",
465
+ "nullable": false,
466
+ "union": false,
467
+ "idlType": "Point",
468
+ "extAttrs": [...]
469
+ }
470
+ ],
471
+ "extAttrs": [...]
472
+ },
473
+ "name": "PointSequence",
474
+ "extAttrs": []
475
+ }
476
+ ```
477
+
478
+
479
+ The fields are as follows:
480
+
481
+ * `type`: Always "typedef".
482
+ * `name`: The typedef's name.
483
+ * `idlType`: An [IDL Type](#idl-type) describing what typedef's type.
484
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
485
+
486
+ ### Includes
487
+
488
+ An includes definition looks like this:
489
+
490
+ ```JS
491
+ {
492
+ "type": "includes",
493
+ "target": "Node",
494
+ "includes": "EventTarget",
495
+ "extAttrs": []
496
+ }
497
+ ```
498
+
499
+ The fields are as follows:
500
+
501
+ * `type`: Always "includes".
502
+ * `target`: The interface that includes an interface mixin.
503
+ * `includes`: The interface mixin that is being included by the target.
504
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
505
+
506
+ ### Operation Member
507
+
508
+ An operation looks like this:
509
+
510
+ ```JS
511
+ {
512
+ "type": "operation",
513
+ "special": "",
514
+ "idlType": {
515
+ "type": "return-type",
516
+ "generic": "",
517
+ "nullable": false,
518
+ "union": false,
519
+ "idlType": "undefined",
520
+ "extAttrs": []
521
+ },
522
+ "name": "intersection",
523
+ "arguments": [{
524
+ "default": null,
525
+ "optional": false,
526
+ "variadic": true,
527
+ "extAttrs": [],
528
+ "idlType": {
529
+ "type": "argument-type",
530
+ "generic": "",
531
+ "nullable": false,
532
+ "union": false,
533
+ "idlType": "long",
534
+ "extAttrs": [...]
535
+ },
536
+ "name": "ints"
537
+ }],
538
+ "extAttrs": [],
539
+ "parent": { ... }
540
+ }
541
+ ```
542
+
543
+ The fields are as follows:
544
+
545
+ * `type`: Always "operation".
546
+ * `special`: One of `"getter"`, `"setter"`, `"deleter"`, `"static"`, `"stringifier"`, or `""`.
547
+ * `idlType`: An [IDL Type](#idl-type) of what the operation returns, if exists.
548
+ * `name`: The name of the operation if exists.
549
+ * `arguments`: An array of [arguments](#arguments) for the operation.
550
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
551
+ * `parent`: The container of this type as an Object.
552
+
553
+ ### Constructor Operation Member
554
+
555
+ A constructor operation member looks like this:
556
+
557
+ ```JS
558
+ {
559
+ "type": "constructor",
560
+ "arguments": [{
561
+ "default": null,
562
+ "optional": false,
563
+ "variadic": true,
564
+ "extAttrs": [],
565
+ "idlType": {
566
+ "type": "argument-type",
567
+ "generic": "",
568
+ "nullable": false,
569
+ "union": false,
570
+ "idlType": "long",
571
+ "extAttrs": [...]
572
+ },
573
+ "name": "ints"
574
+ }],
575
+ "extAttrs": [],
576
+ "parent": { ... }
577
+ }
578
+ ```
579
+
580
+ The fields are as follows:
581
+
582
+ * `type`: Always "constructor".
583
+ * `arguments`: An array of [arguments](#arguments) for the constructor operation.
584
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
585
+ * `parent`: The container of this type as an Object.
586
+
587
+ ### Attribute Member
588
+
589
+ An attribute member looks like this:
590
+
591
+ ```JS
592
+ {
593
+ "type": "attribute",
594
+ "special": "",
595
+ "readonly": false,
596
+ "idlType": {
597
+ "type": "attribute-type",
598
+ "generic": "",
599
+ "nullable": false,
600
+ "union": false,
601
+ "idlType": "any",
602
+ "extAttrs": [...]
603
+ },
604
+ "name": "regexp",
605
+ "extAttrs": [],
606
+ "parent": { ... }
607
+ }
608
+ ```
609
+
610
+ The fields are as follows:
611
+
612
+ * `type`: Always "attribute".
613
+ * `name`: The attribute's name.
614
+ * `special`: One of `"static"`, `"stringifier"`, `"inherit"`, or `""`.
615
+ * `readonly`: `true` if the attribute is read-only.
616
+ * `idlType`: An [IDL Type](#idl-type) for the attribute.
617
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
618
+ * `parent`: The container of this type as an Object.
619
+
620
+ ### Constant Member
621
+
622
+ A constant member looks like this:
623
+
624
+ ```JS
625
+ {
626
+ "type": "const",
627
+ "idlType": {
628
+ "type": "const-type",
629
+ "generic": "",
630
+ "nullable": false,
631
+ "union": false,
632
+ "idlType": "boolean",
633
+ "extAttrs": []
634
+ },
635
+ "name": "DEBUG",
636
+ "value": {
637
+ "type": "boolean",
638
+ "value": false
639
+ },
640
+ "extAttrs": [],
641
+ "parent": { ... }
642
+ }
643
+ ```
644
+
645
+ The fields are as follows:
646
+
647
+ * `type`: Always "const".
648
+ * `idlType`: An [IDL Type](#idl-type) of the constant that represents a simple type, the type name.
649
+ * `name`: The name of the constant.
650
+ * `value`: The constant value as described by [Const Values](#default-and-const-values)
651
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
652
+ * `parent`: The container of this type as an Object.
653
+
654
+ ### Arguments
655
+
656
+ The arguments (e.g. for an operation) look like this:
657
+
658
+ ```JS
659
+ {
660
+ "arguments": [{
661
+ "type": "argument",
662
+ "default": null,
663
+ "optional": false,
664
+ "variadic": true
665
+ "extAttrs": []
666
+ "idlType": {
667
+ "type": "argument-type",
668
+ "generic": "",
669
+ "nullable": false,
670
+ "union": false,
671
+ "idlType": "float",
672
+ "extAttrs": [...]
673
+ },
674
+ "name": "ints",
675
+ "parent": { ... }
676
+ }]
677
+ }
678
+ ```
679
+
680
+ The fields are as follows:
681
+
682
+ * `default`: A [default value](#default-and-const-values), or `null` if there is none.
683
+ * `optional`: `true` if the argument is optional.
684
+ * `variadic`: `true` if the argument is variadic.
685
+ * `idlType`: An [IDL Type](#idl-type) describing the type of the argument.
686
+ * `name`: The argument's name.
687
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
688
+ * `parent`: The container of this type as an Object.
689
+
690
+ ### Extended Attributes
691
+
692
+ Extended attribute container look like this:
693
+
694
+ ```JS
695
+ {
696
+ "extAttrs": [{
697
+ "name": "PutForwards",
698
+ "arguments": [...],
699
+ "type": "extended-attribute",
700
+ "rhs": {
701
+ "type": "identifier",
702
+ "value": "foo"
703
+ },
704
+ "parent": { ... }
705
+ }]
706
+ }
707
+ ```
708
+
709
+ The fields are as follows:
710
+
711
+ * `items`: An array of extended attributes.
712
+
713
+ Extended attributes look like this:
714
+
715
+ * `name`: The extended attribute's name.
716
+ * `arguments`: An array of [arguments](#arguments), if the extended
717
+ attribute has a signature (e.g. `[Foo()]`) or if its right-hand side does (e.g.
718
+ `[LegacyFactoryFunction=Name(DOMString blah)]`).
719
+ * `type`: Always `"extended-attribute"`.
720
+ * `rhs`: If there is a right-hand side, this will capture its `type` and `value`. The
721
+ type can be one of the following:
722
+ * `"identifier"`
723
+ * `"identifier-list"`
724
+ * `"string"`
725
+ * `"string-list"`
726
+ * `"decimal"`
727
+ * `"decimal-list"`
728
+ * `"integer"`
729
+ * `"integer-list"`
730
+ * `"*"`
731
+ * `parent`: The container of this type as an Object.
732
+
733
+ ### Default and Const Values
734
+
735
+ Dictionary fields and operation arguments can take default values, and constants take
736
+ values, all of which have the following fields:
737
+
738
+ * `type`: One of `"string"`, `"number"`, `"boolean"`, `"null"`, `"Infinity"`, `"NaN"`, `"sequence"` or `"dictionary"`.
739
+
740
+ For `"boolean"`, `"string"`, `"number"`, and `"sequence"`:
741
+
742
+ * `value`: The value of the given type. For string and number types, the value is given as a string. For booleans, the possible values are `true` and `false`. For sequence, the only possible value is `[]`.
743
+
744
+ For `"Infinity"`:
745
+
746
+ * `negative`: Boolean indicating whether this is negative Infinity or not.
747
+
748
+ ### `iterable<>`, `async iterable<>`, `maplike<>`, and `setlike<>` declarations
749
+
750
+ These appear as members of interfaces that look like this:
751
+
752
+ ```JS
753
+ {
754
+ "type": "maplike", // or "iterable" / "setlike"
755
+ "idlType": /* One or two types */ ,
756
+ "readonly": false, // only for maplike and setlike
757
+ "async": false, // iterable can be async
758
+ "arguments": [], // only for async iterable
759
+ "extAttrs": [],
760
+ "parent": { ... }
761
+ }
762
+ ```
763
+
764
+ The fields are as follows:
765
+
766
+ * `type`: Always one of "iterable", "maplike" or "setlike".
767
+ * `idlType`: An array with one or more [IDL Types](#idl-type) representing the declared type arguments.
768
+ * `readonly`: `true` if the maplike or setlike is declared as read only.
769
+ * `async`: `true` if the type is async iterable.
770
+ * `arguments`: An array of arguments if exists, empty otherwise. Currently only `async iterable` supports the syntax.
771
+ * `extAttrs`: An array of [extended attributes](#extended-attributes).
772
+ * `parent`: The container of this type as an Object.
773
+
774
+ ### End of file
775
+
776
+ ```js
777
+ {
778
+ "type": "eof",
779
+ "value": ""
780
+ }
781
+ ```
782
+
783
+ This type only appears as the last item of parser results, only if options.concrete is `true`.
784
+ This is needed for the writer to keep any comments or whitespaces at the end of file.
785
+
786
+ The fields are as follows:
787
+
788
+ * `type`: Always "eof"
789
+ * `value`: Always an empty string.
790
+
791
+ ## Testing
792
+
793
+ ### Running
794
+
795
+ The test runs with mocha and expect.js. Normally, running `npm test` in the root directory
796
+ should be enough once you're set up.
797
+
798
+
799
+ ## Contributors
800
+
801
+ ### Code Contributors
802
+
803
+ This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
804
+ <a href="https://github.com/w3c/webidl2.js/graphs/contributors"><img src="https://opencollective.com/webidl2js/contributors.svg?width=890&button=false" /></a>
805
+
806
+ ### Financial Contributors
807
+
808
+ Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/webidl2js/contribute)]
809
+
810
+ #### Individuals
811
+
812
+ <a href="https://opencollective.com/webidl2js"><img src="https://opencollective.com/webidl2js/individuals.svg?width=890"></a>
813
+
814
+ #### Organizations
815
+
816
+ Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/webidl2js/contribute)]
817
+
818
+ <a href="https://opencollective.com/webidl2js/organization/0/website"><img src="https://opencollective.com/webidl2js/organization/0/avatar.svg"></a>
819
+ <a href="https://opencollective.com/webidl2js/organization/1/website"><img src="https://opencollective.com/webidl2js/organization/1/avatar.svg"></a>
820
+ <a href="https://opencollective.com/webidl2js/organization/2/website"><img src="https://opencollective.com/webidl2js/organization/2/avatar.svg"></a>
821
+ <a href="https://opencollective.com/webidl2js/organization/3/website"><img src="https://opencollective.com/webidl2js/organization/3/avatar.svg"></a>
822
+ <a href="https://opencollective.com/webidl2js/organization/4/website"><img src="https://opencollective.com/webidl2js/organization/4/avatar.svg"></a>
823
+ <a href="https://opencollective.com/webidl2js/organization/5/website"><img src="https://opencollective.com/webidl2js/organization/5/avatar.svg"></a>
824
+ <a href="https://opencollective.com/webidl2js/organization/6/website"><img src="https://opencollective.com/webidl2js/organization/6/avatar.svg"></a>
825
+ <a href="https://opencollective.com/webidl2js/organization/7/website"><img src="https://opencollective.com/webidl2js/organization/7/avatar.svg"></a>
826
+ <a href="https://opencollective.com/webidl2js/organization/8/website"><img src="https://opencollective.com/webidl2js/organization/8/avatar.svg"></a>
827
+ <a href="https://opencollective.com/webidl2js/organization/9/website"><img src="https://opencollective.com/webidl2js/organization/9/avatar.svg"></a>
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }