@idlizer/core 2.1.2 → 2.1.5
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.
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +3 -3
- package/build/lib/src/LanguageWriters/ArgConvertors.js +36 -30
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +26 -13
- package/build/lib/src/LanguageWriters/LanguageWriter.js +26 -52
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +2 -1
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +16 -5
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +4 -2
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +20 -12
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +7 -17
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.d.ts +4 -2
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +9 -3
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.d.ts +2 -1
- package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +24 -4
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -2
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +47 -28
- package/build/lib/src/LanguageWriters/nameConvertor.d.ts +3 -1
- package/build/lib/src/LanguageWriters/nameConvertor.js +5 -1
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +12 -9
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +10 -37
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.d.ts +4 -1
- package/build/lib/src/LanguageWriters/writers/CLikeLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +9 -9
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +15 -24
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +14 -8
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +18 -18
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.d.ts +4 -6
- package/build/lib/src/LanguageWriters/writers/JavaLanguageWriter.js +15 -14
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +7 -5
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +22 -43
- package/build/lib/src/LibraryInterface.d.ts +1 -4
- package/build/lib/src/config.d.ts +206 -66
- package/build/lib/src/config.js +7 -3
- package/build/lib/src/configDescriber.d.ts +30 -3
- package/build/lib/src/configDescriber.js +99 -1
- package/build/lib/src/from-idl/DtsPrinter.js +30 -18
- package/build/lib/src/from-idl/IDLLinter.d.ts +40 -7
- package/build/lib/src/from-idl/IDLLinter.js +211 -25
- package/build/lib/src/from-idl/common.js +1 -1
- package/build/lib/src/from-idl/deserialize.d.ts +4 -1
- package/build/lib/src/from-idl/deserialize.js +434 -346
- package/build/lib/src/idl.d.ts +25 -17
- package/build/lib/src/idl.js +363 -109
- package/build/lib/src/idlize.d.ts +2 -1
- package/build/lib/src/idlize.js +82 -26
- package/build/lib/src/index.d.ts +4 -3
- package/build/lib/src/index.js +3 -2
- package/build/lib/src/options.d.ts +1 -1
- package/build/lib/src/peer-generation/BuilderClass.d.ts +0 -2
- package/build/lib/src/peer-generation/BuilderClass.js +0 -8
- package/build/lib/src/peer-generation/LayoutManager.d.ts +10 -3
- package/build/lib/src/peer-generation/LayoutManager.js +3 -2
- package/build/lib/src/peer-generation/Materialized.d.ts +1 -1
- package/build/lib/src/peer-generation/Materialized.js +2 -2
- package/build/lib/src/peer-generation/PeerClass.d.ts +3 -8
- package/build/lib/src/peer-generation/PeerClass.js +0 -1
- package/build/lib/src/peer-generation/PeerFile.d.ts +1 -2
- package/build/lib/src/peer-generation/PeerFile.js +1 -1
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +12 -7
- package/build/lib/src/peer-generation/PeerLibrary.js +129 -65
- package/build/lib/src/peer-generation/ReferenceResolver.d.ts +1 -1
- package/build/lib/src/peer-generation/ReferenceResolver.js +2 -2
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.d.ts +1 -0
- package/build/lib/src/peer-generation/idl/IdlNameConvertor.js +6 -2
- package/build/lib/src/peer-generation/idl/common.d.ts +2 -1
- package/build/lib/src/peer-generation/idl/common.js +13 -2
- package/build/lib/src/peer-generation/isMaterialized.js +25 -8
- package/build/lib/src/peer-generation/unions.d.ts +3 -2
- package/build/lib/src/peer-generation/unions.js +6 -2
- package/build/lib/src/resolveNamedNode.d.ts +3 -0
- package/build/lib/src/resolveNamedNode.js +105 -0
- package/build/lib/src/util.d.ts +6 -0
- package/build/lib/src/util.js +33 -0
- package/build/lib/src/visitor.d.ts +0 -1
- package/build/lib/src/visitor.js +1 -7
- package/package.json +2 -2
- package/webidl2.js/LICENSE +21 -0
- package/webidl2.js/README.md +827 -0
- package/webidl2.js/dist/package.json +3 -0
- package/webidl2.js/dist/webidl2.js +35 -7
package/build/lib/src/config.js
CHANGED
|
@@ -31,10 +31,12 @@ export const CoreConfigurationSchema = D.object({
|
|
|
31
31
|
ignoreMaterialized: T.stringArray(),
|
|
32
32
|
builderClasses: T.stringArray(),
|
|
33
33
|
forceMaterialized: T.stringArray(),
|
|
34
|
-
forceCallback: T.stringArray(),
|
|
34
|
+
forceCallback: D.map(D.string(), T.stringArray()).onMerge('replace'),
|
|
35
|
+
forceResource: T.stringArray(),
|
|
35
36
|
forceContext: T.stringArray(),
|
|
36
37
|
moduleName: D.string(),
|
|
37
|
-
modules: D.map(D.string(), ModuleConfigurationSchema)
|
|
38
|
+
modules: D.map(D.string(), ModuleConfigurationSchema).onMerge('replace'),
|
|
39
|
+
globalPackages: T.stringArray()
|
|
38
40
|
});
|
|
39
41
|
export const defaultCoreConfiguration = {
|
|
40
42
|
TypePrefix: "",
|
|
@@ -46,10 +48,12 @@ export const defaultCoreConfiguration = {
|
|
|
46
48
|
ignoreMaterialized: [],
|
|
47
49
|
builderClasses: [],
|
|
48
50
|
forceMaterialized: [],
|
|
49
|
-
forceCallback:
|
|
51
|
+
forceCallback: new Map(),
|
|
52
|
+
forceResource: [],
|
|
50
53
|
forceContext: [],
|
|
51
54
|
moduleName: "",
|
|
52
55
|
modules: new Map(),
|
|
56
|
+
globalPackages: []
|
|
53
57
|
};
|
|
54
58
|
let currentConfig = defaultCoreConfiguration;
|
|
55
59
|
export function setDefaultConfiguration(config) {
|
|
@@ -8,6 +8,12 @@ export interface JsonSchemaArray extends JsonSchemaLeaf {
|
|
|
8
8
|
export interface JsonSchemaTuple extends JsonSchemaLeaf {
|
|
9
9
|
items: JsonSchemaNode[];
|
|
10
10
|
}
|
|
11
|
+
export interface JsonSchemaUnion extends JsonSchemaLeaf {
|
|
12
|
+
oneOf: JsonSchemaNode[];
|
|
13
|
+
}
|
|
14
|
+
export interface JsonSchemaLiteral extends JsonSchemaLeaf {
|
|
15
|
+
'const': string | number | boolean | null;
|
|
16
|
+
}
|
|
11
17
|
export interface JsonSchemaMap extends JsonSchemaLeaf {
|
|
12
18
|
additionalProperties: JsonSchemaNode;
|
|
13
19
|
}
|
|
@@ -16,7 +22,7 @@ export interface JsonSchemaObject extends JsonSchemaLeaf {
|
|
|
16
22
|
required: string[];
|
|
17
23
|
additionalProperties: boolean;
|
|
18
24
|
}
|
|
19
|
-
export type JsonSchemaNode = JsonSchemaLeaf | JsonSchemaArray | JsonSchemaTuple | JsonSchemaMap | JsonSchemaObject;
|
|
25
|
+
export type JsonSchemaNode = JsonSchemaLeaf | JsonSchemaArray | JsonSchemaTuple | JsonSchemaMap | JsonSchemaObject | JsonSchemaUnion | JsonSchemaLiteral;
|
|
20
26
|
export interface JsonSchema {
|
|
21
27
|
$ref: string;
|
|
22
28
|
$schema: string;
|
|
@@ -27,6 +33,7 @@ type ObjectDescriptionToType<T extends {}> = {
|
|
|
27
33
|
readonly [x in keyof T]: UnwrapConfigDescriberLeaf<T[x]>;
|
|
28
34
|
};
|
|
29
35
|
type TraverseTuple<Ts extends any[]> = Ts extends [] ? [] : Ts extends [infer Head, ...infer Rest] ? [UnwrapConfigDescriberLeaf<Head>, ...TraverseTuple<Rest>] : never;
|
|
36
|
+
type TraverseUnion<Ts extends any[]> = Ts extends [] ? never : Ts extends [infer Head, ...infer Rest] ? UnwrapConfigDescriberLeaf<Head> | TraverseUnion<Rest> : never;
|
|
30
37
|
export interface ValidationSuccess<T> {
|
|
31
38
|
success: true;
|
|
32
39
|
value: T;
|
|
@@ -47,7 +54,14 @@ declare class ValidationBox<T> {
|
|
|
47
54
|
get(): ValidationResult<T>;
|
|
48
55
|
or<U>(x: U): ValidationBox<U | T>;
|
|
49
56
|
}
|
|
50
|
-
|
|
57
|
+
export interface ConfigDescriberBaseConfig {
|
|
58
|
+
mergeStrategy: 'replace' | 'merge';
|
|
59
|
+
}
|
|
60
|
+
declare class ConfigDescriberBase {
|
|
61
|
+
$: ConfigDescriberBaseConfig;
|
|
62
|
+
onMerge(strategy: ConfigDescriberBaseConfig['mergeStrategy']): this;
|
|
63
|
+
}
|
|
64
|
+
declare class ConfigDescriberLeaf<T> extends ConfigDescriberBase {
|
|
51
65
|
validate: (x: unknown) => ValidationBox<T>;
|
|
52
66
|
printSchema: () => JsonSchemaNode;
|
|
53
67
|
constructor(validate: (x: unknown) => ValidationBox<T>, printSchema: () => JsonSchemaNode);
|
|
@@ -60,6 +74,12 @@ declare class ConfigDescriberObjectLeaf<T> extends ConfigDescriberLeaf<T> {
|
|
|
60
74
|
constructor(validate: (x: unknown) => ValidationBox<T>, printSchema: () => JsonSchemaNode, schema: Record<string, ConfigDescriberLeaf<T>>);
|
|
61
75
|
}
|
|
62
76
|
export type ConfigSchema<T> = ConfigDescriberLeaf<T>;
|
|
77
|
+
export interface ConfigDescriberFieldInfo {
|
|
78
|
+
mergeStrategy: ConfigDescriberBaseConfig['mergeStrategy'];
|
|
79
|
+
}
|
|
80
|
+
export declare function inspectSchema(schema: ConfigDescriberLeaf<any>): {
|
|
81
|
+
inspectPath(name: string): ConfigDescriberFieldInfo | undefined;
|
|
82
|
+
};
|
|
63
83
|
export interface CommonBuilderConfig<T> {
|
|
64
84
|
default?: T;
|
|
65
85
|
description?: string;
|
|
@@ -77,8 +97,15 @@ export declare const D: {
|
|
|
77
97
|
array<T_2>(type: ConfigDescriberLeaf<T_2>, initAsEmpty?: boolean): ConfigDescriberLeaf<T_2[]>;
|
|
78
98
|
map<K_1, V>(keySchema: ConfigDescriberLeaf<K_1>, valSchema: ConfigDescriberLeaf<V>): ConfigDescriberLeaf<Map<K_1, V>>;
|
|
79
99
|
tuple<Ts extends ConfigDescriberLeaf<any>[]>(...items: Ts): ConfigDescriberLeaf<TraverseTuple<Ts>>;
|
|
100
|
+
union<Ts_1 extends ConfigDescriberLeaf<any>[]>(...items: Ts_1): ConfigDescriberLeaf<TraverseUnion<Ts_1>>;
|
|
101
|
+
literal: {
|
|
102
|
+
string<T_3 extends string>(x: T_3): ConfigDescriberLeaf<T_3>;
|
|
103
|
+
number<T_4 extends number>(x: T_4): ConfigDescriberLeaf<T_4>;
|
|
104
|
+
boolean<T_5 extends boolean>(x: T_5): ConfigDescriberLeaf<T_5>;
|
|
105
|
+
null(x: null): ConfigDescriberLeaf<null>;
|
|
106
|
+
};
|
|
80
107
|
combine<A, B>(a: ConfigDescriberObjectLeaf<A>, b: ConfigDescriberObjectLeaf<B>): ConfigDescriberObjectLeaf<A & B>;
|
|
81
|
-
printJSONSchema<
|
|
108
|
+
printJSONSchema<T_6>(schema: ConfigDescriberLeaf<T_6>): string;
|
|
82
109
|
};
|
|
83
110
|
export type ConfigTypeInfer<T> = UnwrapConfigDescriberLeaf<T>;
|
|
84
111
|
export {};
|
|
@@ -51,8 +51,20 @@ class ValidationBox {
|
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
class
|
|
54
|
+
class ConfigDescriberBase {
|
|
55
|
+
constructor() {
|
|
56
|
+
this.$ = {
|
|
57
|
+
mergeStrategy: 'merge'
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
onMerge(strategy) {
|
|
61
|
+
this.$.mergeStrategy = strategy;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
class ConfigDescriberLeaf extends ConfigDescriberBase {
|
|
55
66
|
constructor(validate, printSchema) {
|
|
67
|
+
super();
|
|
56
68
|
this.validate = validate;
|
|
57
69
|
this.printSchema = printSchema;
|
|
58
70
|
}
|
|
@@ -66,6 +78,27 @@ class ConfigDescriberObjectLeaf extends ConfigDescriberLeaf {
|
|
|
66
78
|
this.schema = schema;
|
|
67
79
|
}
|
|
68
80
|
}
|
|
81
|
+
export function inspectSchema(schema) {
|
|
82
|
+
return {
|
|
83
|
+
inspectPath(name) {
|
|
84
|
+
if (name === '') {
|
|
85
|
+
return {
|
|
86
|
+
mergeStrategy: schema.$.mergeStrategy
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
const path = name.split('.');
|
|
90
|
+
let leaf = schema;
|
|
91
|
+
while (leaf instanceof ConfigDescriberObjectLeaf && path.length > 0) {
|
|
92
|
+
const key = path.shift();
|
|
93
|
+
leaf = leaf.schema[key];
|
|
94
|
+
if (!leaf) {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { mergeStrategy: leaf.$.mergeStrategy };
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
69
102
|
function mk(typeName, check, config) {
|
|
70
103
|
return new ConfigDescriberLeaf(x => {
|
|
71
104
|
if (check(x)) {
|
|
@@ -262,6 +295,71 @@ export const D = {
|
|
|
262
295
|
};
|
|
263
296
|
});
|
|
264
297
|
},
|
|
298
|
+
union(...items) {
|
|
299
|
+
return new ConfigDescriberLeaf(xs => {
|
|
300
|
+
for (const item of items) {
|
|
301
|
+
const r = item.validate(xs);
|
|
302
|
+
if (r.success()) {
|
|
303
|
+
return r;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
return ValidationBox.fail('Not matched');
|
|
307
|
+
}, () => {
|
|
308
|
+
return {
|
|
309
|
+
oneOf: items.map(it => it.printSchema())
|
|
310
|
+
};
|
|
311
|
+
});
|
|
312
|
+
},
|
|
313
|
+
literal: {
|
|
314
|
+
string(x) {
|
|
315
|
+
return new ConfigDescriberLeaf(xs => {
|
|
316
|
+
if (typeof xs === 'string' && x === xs) {
|
|
317
|
+
return ValidationBox.ok(xs);
|
|
318
|
+
}
|
|
319
|
+
return ValidationBox.fail('Not matched');
|
|
320
|
+
}, () => {
|
|
321
|
+
return {
|
|
322
|
+
'const': x
|
|
323
|
+
};
|
|
324
|
+
});
|
|
325
|
+
},
|
|
326
|
+
number(x) {
|
|
327
|
+
return new ConfigDescriberLeaf(xs => {
|
|
328
|
+
if (typeof xs === 'number' && x === xs) {
|
|
329
|
+
return ValidationBox.ok(xs);
|
|
330
|
+
}
|
|
331
|
+
return ValidationBox.fail('Not matched');
|
|
332
|
+
}, () => {
|
|
333
|
+
return {
|
|
334
|
+
'const': x
|
|
335
|
+
};
|
|
336
|
+
});
|
|
337
|
+
},
|
|
338
|
+
boolean(x) {
|
|
339
|
+
return new ConfigDescriberLeaf(xs => {
|
|
340
|
+
if (typeof xs === 'boolean' && x === xs) {
|
|
341
|
+
return ValidationBox.ok(xs);
|
|
342
|
+
}
|
|
343
|
+
return ValidationBox.fail('Not matched');
|
|
344
|
+
}, () => {
|
|
345
|
+
return {
|
|
346
|
+
'const': x
|
|
347
|
+
};
|
|
348
|
+
});
|
|
349
|
+
},
|
|
350
|
+
null(x) {
|
|
351
|
+
return new ConfigDescriberLeaf(xs => {
|
|
352
|
+
if (typeof xs === 'object' && xs === null) {
|
|
353
|
+
return ValidationBox.ok(null);
|
|
354
|
+
}
|
|
355
|
+
return ValidationBox.fail('Expected null');
|
|
356
|
+
}, () => {
|
|
357
|
+
return {
|
|
358
|
+
'const': null
|
|
359
|
+
};
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
},
|
|
265
363
|
////////////////////////////////////////
|
|
266
364
|
// Utils
|
|
267
365
|
combine(a, b) {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
import { indentedBy, isInNamespace } from "../util";
|
|
16
|
-
import { IDLEntity, IDLKind, getExtAttribute, getVerbatimDts, hasExtAttribute, isCallback, isConstructor, isContainerType, isEnum, isInterface, isMethod, isPrimitiveType, isProperty, isReferenceType, isSyntheticEntry, isTypeParameterType, isTypedef, isUnionType, isImport, isVersion, isNamespace, IDLExtendedAttributes, IDLAccessorAttribute, IDLVoidType, IDLStringType, IDLUndefinedType, isCallable, getSuperType, IDLAnyType, IDLContainerUtils, DebugUtils, mixMethodParametersAndTags, createReferenceType, transformMethodsAsync2ReturnPromise, isNamedNode, IDLThisType, isOptionalType, IDLI8Type, IDLU8Type, IDLI16Type, IDLU16Type, IDLI32Type, IDLU32Type, IDLI64Type, IDLU64Type, IDLF16Type, IDLF32Type, IDLF64Type, IDLBufferType, isUnspecifiedGenericType, IDLUnknownType, IDLBooleanType, IDLNumberType, IDLPointerType, IDLInterfaceSubkind, escapeIDLKeyword, getNamespacesPathFor, IDLBigintType, IDLDate } from "../idl";
|
|
16
|
+
import { IDLEntity, IDLKind, getExtAttribute, getVerbatimDts, hasExtAttribute, isCallback, isConstructor, isContainerType, isEnum, isInterface, isMethod, isPrimitiveType, isProperty, isReferenceType, isSyntheticEntry, isTypeParameterType, isTypedef, isUnionType, isImport, isVersion, isNamespace, IDLExtendedAttributes, IDLAccessorAttribute, IDLVoidType, IDLStringType, IDLUndefinedType, isCallable, getSuperType, IDLAnyType, IDLContainerUtils, DebugUtils, mixMethodParametersAndTags, createReferenceType, transformMethodsAsync2ReturnPromise, linearizeNamespaceMembers, isNamedNode, IDLThisType, isOptionalType, IDLI8Type, IDLU8Type, IDLI16Type, IDLU16Type, IDLI32Type, IDLU32Type, IDLI64Type, IDLU64Type, IDLF16Type, IDLF32Type, IDLF64Type, IDLBufferType, isUnspecifiedGenericType, IDLUnknownType, IDLBooleanType, IDLNumberType, IDLPointerType, IDLInterfaceSubkind, escapeIDLKeyword, getNamespacesPathFor, IDLBigintType, IDLDate, IDLFunctionType, getQualifiedName } from "../idl";
|
|
17
17
|
import { resolveSyntheticType, toIDLFile } from "./deserialize";
|
|
18
18
|
import { Language } from "../Language";
|
|
19
19
|
import { warn } from "../util";
|
|
@@ -64,7 +64,7 @@ export class CustomPrintVisitor {
|
|
|
64
64
|
else {
|
|
65
65
|
throw new Error(`Unexpected node kind: ${IDLKind[node.kind]}`);
|
|
66
66
|
}
|
|
67
|
-
for (const
|
|
67
|
+
for (const _ of namespacesPath) {
|
|
68
68
|
this.popIndent();
|
|
69
69
|
this.print("}");
|
|
70
70
|
}
|
|
@@ -86,9 +86,6 @@ export class CustomPrintVisitor {
|
|
|
86
86
|
printInterface(node) {
|
|
87
87
|
var _a;
|
|
88
88
|
let typeSpec = this.toTypeName(node);
|
|
89
|
-
// Workaround for an SDK declaration clash between `WrappedBuilder` and `ContentModifier`
|
|
90
|
-
if (node.name === "WrappedBuilder")
|
|
91
|
-
typeSpec = "WrappedBuilder<Args extends any[]>";
|
|
92
89
|
const entity = (_a = getExtAttribute(node, IDLExtendedAttributes.Entity)) !== null && _a !== void 0 ? _a : IDLEntity.Interface;
|
|
93
90
|
if (entity === IDLEntity.Literal) {
|
|
94
91
|
this.print(`${isInNamespace(node) ? "" : "declare "}type ${typeSpec} = ${this.literal(node, false, true)}`);
|
|
@@ -99,6 +96,9 @@ export class CustomPrintVisitor {
|
|
|
99
96
|
else if (entity === IDLEntity.NamedTuple) {
|
|
100
97
|
this.print(`${isInNamespace(node) ? "" : "declare "}type ${typeSpec} = ${this.literal(node, true, true)}`);
|
|
101
98
|
}
|
|
99
|
+
else if (entity === IDLEntity.Intersection) {
|
|
100
|
+
this.print(`${isInNamespace(node) ? "" : "declare "}type ${typeSpec} = ${node.inheritance.map(it => this.printTypeForTS(it)).join(' & ')}`);
|
|
101
|
+
}
|
|
102
102
|
else {
|
|
103
103
|
let interfaces = node.inheritance;
|
|
104
104
|
let keyword = "extends";
|
|
@@ -152,8 +152,11 @@ export class CustomPrintVisitor {
|
|
|
152
152
|
}
|
|
153
153
|
paramText(paramOrTag) {
|
|
154
154
|
const param = paramOrTag;
|
|
155
|
-
if (param.kind === IDLKind.Parameter)
|
|
156
|
-
|
|
155
|
+
if (param.kind === IDLKind.Parameter) {
|
|
156
|
+
const dots = param.isVariadic ? "..." : "";
|
|
157
|
+
const brackets = param.isVariadic ? "[]" : "";
|
|
158
|
+
return `${dots}${getName(param)}${param.isOptional ? "?" : ""}: ${this.printTypeForTS(param.type)}${brackets}`;
|
|
159
|
+
}
|
|
157
160
|
const tag = paramOrTag;
|
|
158
161
|
return `${tag.name}: ${tag.value}`;
|
|
159
162
|
}
|
|
@@ -290,6 +293,7 @@ export class CustomPrintVisitor {
|
|
|
290
293
|
case IDLBigintType:
|
|
291
294
|
case IDLPointerType: return "number|bigint";
|
|
292
295
|
case IDLDate: return "Date";
|
|
296
|
+
case IDLFunctionType: return "Function";
|
|
293
297
|
default: throw new Error(`Unknown primitive type ${DebugUtils.debugPrintType(type)}`);
|
|
294
298
|
}
|
|
295
299
|
}
|
|
@@ -311,15 +315,21 @@ export class CustomPrintVisitor {
|
|
|
311
315
|
toTypeName(node) {
|
|
312
316
|
var _a, _b;
|
|
313
317
|
if (isReferenceType(node)) {
|
|
314
|
-
const
|
|
315
|
-
if (
|
|
316
|
-
if (
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
318
|
+
const decl = this.resolver(node);
|
|
319
|
+
if (decl) {
|
|
320
|
+
if (isSyntheticEntry(decl)) {
|
|
321
|
+
if (isInterface(decl)) {
|
|
322
|
+
const isTuple = getExtAttribute(decl, IDLExtendedAttributes.Entity) === IDLEntity.Tuple;
|
|
323
|
+
return this.literal(decl, isTuple, !isTuple);
|
|
324
|
+
}
|
|
325
|
+
if (isCallback(decl)) {
|
|
326
|
+
return this.callback(decl);
|
|
327
|
+
}
|
|
322
328
|
}
|
|
329
|
+
let typeSpec = getQualifiedName(decl, "namespace.name");
|
|
330
|
+
if (node.typeArguments)
|
|
331
|
+
typeSpec = `${typeSpec}<${node.typeArguments.map(it => this.printTypeForTS(it))}>`;
|
|
332
|
+
return typeSpec;
|
|
323
333
|
}
|
|
324
334
|
}
|
|
325
335
|
if (hasExtAttribute(node, IDLExtendedAttributes.Import)) {
|
|
@@ -329,7 +339,7 @@ export class CustomPrintVisitor {
|
|
|
329
339
|
if ((isInterface(node) || isCallback(node) || isTypedef(node)) && ((_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.length))
|
|
330
340
|
typeSpec = `${typeSpec}<${(_b = node.typeParameters) === null || _b === void 0 ? void 0 : _b.join(",")}>`;
|
|
331
341
|
if (isReferenceType(node) && node.typeArguments)
|
|
332
|
-
typeSpec = `${typeSpec}<${node.typeArguments.map(it => this.
|
|
342
|
+
typeSpec = `${typeSpec}<${node.typeArguments.map(it => this.printTypeForTS(it))}>`;
|
|
333
343
|
return typeSpec;
|
|
334
344
|
}
|
|
335
345
|
callback(node) {
|
|
@@ -345,10 +355,12 @@ export class CustomPrintVisitor {
|
|
|
345
355
|
}
|
|
346
356
|
export function idlToDtsString(name, content) {
|
|
347
357
|
let printer = new CustomPrintVisitor(resolveSyntheticType, Language.TS);
|
|
348
|
-
const idlFile = toIDLFile(name, content);
|
|
358
|
+
const [idlFile] = toIDLFile(name, content);
|
|
349
359
|
printer.printPackage(idlFile);
|
|
350
|
-
idlFile.entries.forEach(it => {
|
|
360
|
+
linearizeNamespaceMembers(idlFile.entries).forEach(it => {
|
|
351
361
|
transformMethodsAsync2ReturnPromise(it);
|
|
362
|
+
});
|
|
363
|
+
idlFile.entries.forEach(it => {
|
|
352
364
|
printer.visit(it);
|
|
353
365
|
});
|
|
354
366
|
return printer.output.join("\n");
|
|
@@ -1,24 +1,57 @@
|
|
|
1
1
|
import * as idl from "../idl";
|
|
2
2
|
import { ReferenceResolver } from "../peer-generation/ReferenceResolver";
|
|
3
|
+
import { IDLTokenInfoMap } from "./deserialize";
|
|
4
|
+
export declare enum IDLValidationDiagnosticsCode {
|
|
5
|
+
INVALID_EXTENDED_ATTRIBUTE = 1000,
|
|
6
|
+
ENUM_IS_NOT_CONSISTENT = 1001,
|
|
7
|
+
REFERENCE_IS_NOT_RESOLVED = 1002
|
|
8
|
+
}
|
|
9
|
+
type IDLValidationErrorDescriptionBox = Record<IDLValidationDiagnosticsCode, string>;
|
|
10
|
+
export declare const IDLValidationErrorDescription: {
|
|
11
|
+
en_EN: IDLValidationErrorDescriptionBox;
|
|
12
|
+
};
|
|
3
13
|
export interface IDLLinterOptions {
|
|
4
14
|
validEntryAttributes: Map<idl.IDLKind, string[]>;
|
|
5
15
|
checkEnumsConsistency: boolean;
|
|
6
16
|
checkReferencesResolved: boolean;
|
|
7
17
|
}
|
|
18
|
+
interface IDLLinterContextRecord {
|
|
19
|
+
typeParameters: Set<string>;
|
|
20
|
+
}
|
|
21
|
+
declare class IDLLinterContext {
|
|
22
|
+
private stack;
|
|
23
|
+
constructor();
|
|
24
|
+
enter(rec: IDLLinterContextRecord): void;
|
|
25
|
+
leave(): void;
|
|
26
|
+
get current(): IDLLinterContextRecord;
|
|
27
|
+
hasTypeParameter(name: string): boolean;
|
|
28
|
+
}
|
|
8
29
|
export declare class IDLLinter {
|
|
9
|
-
protected
|
|
30
|
+
protected file: idl.IDLFile;
|
|
10
31
|
protected resolver: ReferenceResolver;
|
|
11
32
|
protected options: IDLLinterOptions;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
visit():
|
|
33
|
+
protected info?: IDLTokenInfoMap | undefined;
|
|
34
|
+
protected context: IDLLinterContext;
|
|
35
|
+
diagnostics: IDLLinterDiagnosticsSummary[];
|
|
36
|
+
constructor(file: idl.IDLFile, resolver: ReferenceResolver, options: IDLLinterOptions, info?: IDLTokenInfoMap | undefined);
|
|
37
|
+
visit(): IDLLinterDiagnosticsSummary[];
|
|
38
|
+
protected enter(node: idl.IDLNode): (() => void) | undefined;
|
|
17
39
|
protected check(node: idl.IDLNode): void;
|
|
18
40
|
protected checkValidAttributes(entry: idl.IDLEntry, validAttributes: string[]): void;
|
|
19
41
|
protected checkEnumConsistency(entry: idl.IDLEnum): void;
|
|
20
42
|
private static builtinReferences;
|
|
21
43
|
protected checkReferenceResolved(reference: idl.IDLReferenceType): void;
|
|
22
44
|
}
|
|
23
|
-
|
|
45
|
+
interface IDLLinterDiagnosticsSummary {
|
|
46
|
+
code: IDLValidationDiagnosticsCode;
|
|
47
|
+
message: string;
|
|
48
|
+
file: string;
|
|
49
|
+
position: [number, number];
|
|
50
|
+
}
|
|
51
|
+
export declare class IDLLinterError extends Error {
|
|
52
|
+
size: number;
|
|
53
|
+
constructor(message: string, size: number);
|
|
54
|
+
}
|
|
55
|
+
export declare function verifyIDLLinter(file: idl.IDLFile, resolver: ReferenceResolver, options: IDLLinterOptions, info?: IDLTokenInfoMap): true;
|
|
56
|
+
export {};
|
|
24
57
|
//# sourceMappingURL=IDLLinter.d.ts.map
|