@idlizer/core 2.1.5 → 2.1.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.
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +0 -1
- package/build/lib/src/LanguageWriters/ArgConvertors.js +8 -3
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +9 -4
- package/build/lib/src/LanguageWriters/LanguageWriter.js +4 -4
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +16 -6
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.d.ts +1 -0
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +55 -54
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.d.ts +1 -1
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +2 -2
- package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +1 -0
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.d.ts +4 -2
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +44 -9
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +7 -2
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +24 -10
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +3 -0
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +32 -7
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +6 -3
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +11 -9
- package/build/lib/src/config.d.ts +607 -44
- package/build/lib/src/config.js +18 -0
- package/build/lib/src/configDescriber.d.ts +1 -1
- package/build/lib/src/configDescriber.js +2 -2
- package/build/lib/src/from-idl/DtsPrinter.js +3 -2
- package/build/lib/src/from-idl/IDLLinter.js +1 -1
- package/build/lib/src/from-idl/deserialize.d.ts +7 -1
- package/build/lib/src/from-idl/deserialize.js +79 -33
- package/build/lib/src/idl.d.ts +4 -2
- package/build/lib/src/idl.js +64 -33
- package/build/lib/src/peer-generation/Materialized.js +1 -1
- package/build/lib/src/peer-generation/PeerLibrary.js +4 -4
- package/build/lib/src/peer-generation/idl/common.d.ts +1 -0
- package/build/lib/src/peer-generation/idl/common.js +8 -2
- package/build/lib/src/peer-generation/isMaterialized.js +4 -0
- package/build/lib/src/peer-generation/unions.js +1 -1
- package/build/lib/src/util.d.ts +2 -1
- package/build/lib/src/util.js +8 -3
- package/build/lib/src/visitor.d.ts +2 -0
- package/build/lib/src/visitor.js +108 -0
- package/package.json +2 -2
- package/webidl2.js/dist/webidl2.js +62 -16
package/build/lib/src/config.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
import { D } from "./configDescriber";
|
|
16
|
+
import { capitalize } from "./util";
|
|
16
17
|
const T = {
|
|
17
18
|
stringArray: () => D.array(D.string())
|
|
18
19
|
};
|
|
@@ -21,6 +22,9 @@ export const ModuleConfigurationSchema = D.object({
|
|
|
21
22
|
packages: T.stringArray(),
|
|
22
23
|
useFoldersLayout: D.maybe(D.boolean()),
|
|
23
24
|
});
|
|
25
|
+
export const HookMethodSchema = D.object({
|
|
26
|
+
hookName: D.string(),
|
|
27
|
+
});
|
|
24
28
|
export const CoreConfigurationSchema = D.object({
|
|
25
29
|
TypePrefix: D.string(),
|
|
26
30
|
LibraryPrefix: D.string(),
|
|
@@ -34,6 +38,8 @@ export const CoreConfigurationSchema = D.object({
|
|
|
34
38
|
forceCallback: D.map(D.string(), T.stringArray()).onMerge('replace'),
|
|
35
39
|
forceResource: T.stringArray(),
|
|
36
40
|
forceContext: T.stringArray(),
|
|
41
|
+
hooks: D.map(D.string(), D.map(D.string(), HookMethodSchema)).onMerge('replace'),
|
|
42
|
+
externalModuleTypes: D.map(D.string(), D.string()).onMerge('replace'),
|
|
37
43
|
moduleName: D.string(),
|
|
38
44
|
modules: D.map(D.string(), ModuleConfigurationSchema).onMerge('replace'),
|
|
39
45
|
globalPackages: T.stringArray()
|
|
@@ -51,6 +57,8 @@ export const defaultCoreConfiguration = {
|
|
|
51
57
|
forceCallback: new Map(),
|
|
52
58
|
forceResource: [],
|
|
53
59
|
forceContext: [],
|
|
60
|
+
hooks: new Map(),
|
|
61
|
+
externalModuleTypes: new Map(),
|
|
54
62
|
moduleName: "",
|
|
55
63
|
modules: new Map(),
|
|
56
64
|
globalPackages: []
|
|
@@ -69,4 +77,14 @@ export function generatorTypePrefix() {
|
|
|
69
77
|
const conf = generatorConfiguration();
|
|
70
78
|
return `${conf.TypePrefix}${conf.LibraryPrefix}`;
|
|
71
79
|
}
|
|
80
|
+
export function generatorHookName(className, methodName) {
|
|
81
|
+
var _a;
|
|
82
|
+
const hookMethods = generatorConfiguration().hooks.get(className);
|
|
83
|
+
if (!hookMethods)
|
|
84
|
+
return undefined;
|
|
85
|
+
const hook = hookMethods.get(methodName);
|
|
86
|
+
if (!hook)
|
|
87
|
+
return undefined;
|
|
88
|
+
return (_a = hook.hookName) !== null && _a !== void 0 ? _a : `hook${className}${capitalize(methodName)}`;
|
|
89
|
+
}
|
|
72
90
|
//# sourceMappingURL=config.js.map
|
|
@@ -49,7 +49,7 @@ declare class ValidationBox<T> {
|
|
|
49
49
|
static fail<T>(errorMessage: string): ValidationBox<T>;
|
|
50
50
|
static ok<T>(value: T): ValidationBox<T>;
|
|
51
51
|
success(): boolean;
|
|
52
|
-
unwrap(): T;
|
|
52
|
+
unwrap(message?: string): T;
|
|
53
53
|
error(): string;
|
|
54
54
|
get(): ValidationResult<T>;
|
|
55
55
|
or<U>(x: U): ValidationBox<U | T>;
|
|
@@ -26,11 +26,11 @@ class ValidationBox {
|
|
|
26
26
|
success() {
|
|
27
27
|
return this.box.success;
|
|
28
28
|
}
|
|
29
|
-
unwrap() {
|
|
29
|
+
unwrap(message) {
|
|
30
30
|
if (this.box.success) {
|
|
31
31
|
return this.box.value;
|
|
32
32
|
}
|
|
33
|
-
throw new Error(
|
|
33
|
+
throw new Error(message !== null && message !== void 0 ? message : 'panic');
|
|
34
34
|
}
|
|
35
35
|
error() {
|
|
36
36
|
if (!this.box.success) {
|
|
@@ -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, 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";
|
|
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, IDLObjectType } from "../idl";
|
|
17
17
|
import { resolveSyntheticType, toIDLFile } from "./deserialize";
|
|
18
18
|
import { Language } from "../Language";
|
|
19
19
|
import { warn } from "../util";
|
|
@@ -283,6 +283,7 @@ export class CustomPrintVisitor {
|
|
|
283
283
|
case IDLNumberType:
|
|
284
284
|
return "number";
|
|
285
285
|
case IDLAnyType: return "any";
|
|
286
|
+
case IDLObjectType: return "Object";
|
|
286
287
|
case IDLUnknownType: return "unknown";
|
|
287
288
|
case IDLBufferType: return "ArrayBuffer";
|
|
288
289
|
case IDLBooleanType: return "boolean";
|
|
@@ -355,7 +356,7 @@ export class CustomPrintVisitor {
|
|
|
355
356
|
}
|
|
356
357
|
export function idlToDtsString(name, content) {
|
|
357
358
|
let printer = new CustomPrintVisitor(resolveSyntheticType, Language.TS);
|
|
358
|
-
const [idlFile] = toIDLFile(name, content);
|
|
359
|
+
const [idlFile] = toIDLFile(name, { content });
|
|
359
360
|
printer.printPackage(idlFile);
|
|
360
361
|
linearizeNamespaceMembers(idlFile.entries).forEach(it => {
|
|
361
362
|
transformMethodsAsync2ReturnPromise(it);
|
|
@@ -67,7 +67,7 @@ export class IDLLinter {
|
|
|
67
67
|
}
|
|
68
68
|
enter(node) {
|
|
69
69
|
var _a, _b;
|
|
70
|
-
if (idl.isInterface(node) || idl.isTypedef(node) || idl.isMethod(node) || idl.isCallable(node)) {
|
|
70
|
+
if (idl.isInterface(node) || idl.isTypedef(node) || idl.isMethod(node) || idl.isCallable(node) || idl.isCallback(node)) {
|
|
71
71
|
this.context.enter({ typeParameters: new Set((_b = (_a = node.typeParameters) === null || _a === void 0 ? void 0 : _a.map(parseTypeParameter)) !== null && _b !== void 0 ? _b : []) });
|
|
72
72
|
return () => this.context.leave();
|
|
73
73
|
}
|
|
@@ -4,5 +4,11 @@ export type WebIDLTokenCollection = Record<string, webidl2.Token | null | undefi
|
|
|
4
4
|
export type IDLTokenInfoMap = Map<unknown, WebIDLTokenCollection>;
|
|
5
5
|
export declare function addSyntheticType(name: string, type: idl.IDLEntry): void;
|
|
6
6
|
export declare function resolveSyntheticType(type: idl.IDLReferenceType): idl.IDLEntry | undefined;
|
|
7
|
-
|
|
7
|
+
type IDLInheritanceMode = 'single' | 'multiple';
|
|
8
|
+
interface ToIDLFileProps {
|
|
9
|
+
inheritanceMode?: IDLInheritanceMode;
|
|
10
|
+
content?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function toIDLFile(fileName: string, { content, inheritanceMode }?: ToIDLFileProps): [idl.IDLFile, IDLTokenInfoMap];
|
|
13
|
+
export {};
|
|
8
14
|
//# sourceMappingURL=deserialize.d.ts.map
|
|
@@ -33,8 +33,12 @@ export function resolveSyntheticType(type) {
|
|
|
33
33
|
return syntheticTypes.get(type.name);
|
|
34
34
|
}
|
|
35
35
|
class IDLDeserializer {
|
|
36
|
-
|
|
36
|
+
enterGenericScope(generics) {
|
|
37
|
+
this.genericsScopes.push(new Set(generics !== null && generics !== void 0 ? generics : []));
|
|
38
|
+
}
|
|
39
|
+
constructor(info, inheritanceMode = 'multiple') {
|
|
37
40
|
this.info = info;
|
|
41
|
+
this.inheritanceMode = inheritanceMode;
|
|
38
42
|
this.namespacePathNames = [];
|
|
39
43
|
this.currentPackage = [];
|
|
40
44
|
this.genericsScopes = [];
|
|
@@ -61,7 +65,7 @@ class IDLDeserializer {
|
|
|
61
65
|
}
|
|
62
66
|
extractGenerics(extAttrs) {
|
|
63
67
|
var _a, _b;
|
|
64
|
-
return
|
|
68
|
+
return (_b = (_a = this.findExtendedAttribute(extAttrs, idl.IDLExtendedAttributes.TypeParameters)) === null || _a === void 0 ? void 0 : _a.split(",")) === null || _b === void 0 ? void 0 : _b.map(it => this.sanitizeTypeParameter(it));
|
|
65
69
|
}
|
|
66
70
|
///
|
|
67
71
|
toIDLNode(file, node) {
|
|
@@ -107,7 +111,6 @@ class IDLDeserializer {
|
|
|
107
111
|
throw new Error(`unexpected node type: ${toString(node)}`);
|
|
108
112
|
}
|
|
109
113
|
toIDLImport(node) {
|
|
110
|
-
// console.log(node)
|
|
111
114
|
return this.withInfo(node, idl.createImport(node.clause.split("."), node.alias || undefined));
|
|
112
115
|
}
|
|
113
116
|
interfaceSubkind(node) {
|
|
@@ -122,19 +125,38 @@ class IDLDeserializer {
|
|
|
122
125
|
return idl.IDLInterfaceSubkind.Interface;
|
|
123
126
|
}
|
|
124
127
|
toIDLInterface(file, node) {
|
|
125
|
-
var _a;
|
|
126
128
|
const generics = this.extractGenerics(node.extAttrs);
|
|
127
|
-
this.
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
if (!node.inheritance)
|
|
129
|
+
this.enterGenericScope(generics);
|
|
130
|
+
const subkind = this.interfaceSubkind(node);
|
|
131
|
+
const result = idl.createInterface(node.name, subkind, (() => {
|
|
132
|
+
if (!node.inheritance) {
|
|
131
133
|
return [];
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
}
|
|
135
|
+
const implementations = [];
|
|
136
|
+
let extension = undefined;
|
|
137
|
+
node.inheritance.forEach(it => {
|
|
138
|
+
var _a;
|
|
139
|
+
const attributes = it.extAttrs;
|
|
140
|
+
const parentTypeArgs = this.extractTypeArguments(file, attributes !== null && attributes !== void 0 ? attributes : [], idl.IDLExtendedAttributes.TypeArguments);
|
|
141
|
+
const attrs = (_a = this.toExtendedAttributes(attributes !== null && attributes !== void 0 ? attributes : [])) === null || _a === void 0 ? void 0 : _a.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments);
|
|
142
|
+
const baseClass = attrs === null || attrs === void 0 ? void 0 : attrs.find(it => it.name === idl.IDLExtendedAttributes.Extends);
|
|
143
|
+
const ref = idl.createReferenceType(it.inheritance, parentTypeArgs, {
|
|
144
|
+
extendedAttributes: attrs
|
|
145
|
+
});
|
|
146
|
+
if (baseClass) {
|
|
147
|
+
extension = ref;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
implementations.push(ref);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
if (subkind === idl.IDLInterfaceSubkind.Class && extension === undefined && this.inheritanceMode === 'multiple') {
|
|
154
|
+
extension = idl.IDLTopType;
|
|
155
|
+
}
|
|
156
|
+
if (extension) {
|
|
157
|
+
return [extension, ...implementations];
|
|
158
|
+
}
|
|
159
|
+
return implementations;
|
|
138
160
|
})(), node.members
|
|
139
161
|
.filter(isConstructor)
|
|
140
162
|
.map(it => this.toIDLConstructor(file, it)), [], node.members
|
|
@@ -145,7 +167,7 @@ class IDLDeserializer {
|
|
|
145
167
|
.map(it => this.toIDLMethod(file, it, false)), node.members
|
|
146
168
|
.filter(isOperation)
|
|
147
169
|
.filter(it => this.isCallable(it))
|
|
148
|
-
.map(it => this.toIDLCallable(file, it)),
|
|
170
|
+
.map(it => this.toIDLCallable(file, it)), generics, {
|
|
149
171
|
fileName: file,
|
|
150
172
|
documentation: this.makeDocs(node),
|
|
151
173
|
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
@@ -158,7 +180,7 @@ class IDLDeserializer {
|
|
|
158
180
|
}
|
|
159
181
|
return result;
|
|
160
182
|
}
|
|
161
|
-
toIDLType(file, type, extAttrs) {
|
|
183
|
+
toIDLType(file, type, extAttrs, suggestedName) {
|
|
162
184
|
var _a;
|
|
163
185
|
if (typeof type === "string") {
|
|
164
186
|
// is it IDLStringType?
|
|
@@ -178,7 +200,7 @@ class IDLDeserializer {
|
|
|
178
200
|
types = types.filter(it => it !== idl.IDLUndefinedType);
|
|
179
201
|
return this.withInfo(type, idl.createOptionalType(collapseTypes(types)));
|
|
180
202
|
}
|
|
181
|
-
const name = generateSyntheticUnionName(types);
|
|
203
|
+
const name = suggestedName !== null && suggestedName !== void 0 ? suggestedName : generateSyntheticUnionName(types);
|
|
182
204
|
return this.withInfo(type, idl.createUnionType(types, name));
|
|
183
205
|
}
|
|
184
206
|
if (isSingleTypeDescription(type)) {
|
|
@@ -233,12 +255,12 @@ class IDLDeserializer {
|
|
|
233
255
|
throw new Error(`unexpected type: ${toString(type)}`);
|
|
234
256
|
}
|
|
235
257
|
toIDLCallable(file, node) {
|
|
236
|
-
var _a
|
|
258
|
+
var _a;
|
|
237
259
|
if (!node.idlType) {
|
|
238
260
|
throw new Error(`method with no type ${toString(node)}`);
|
|
239
261
|
}
|
|
240
262
|
const generics = this.extractGenerics(node.extAttrs);
|
|
241
|
-
this.
|
|
263
|
+
this.enterGenericScope(generics);
|
|
242
264
|
const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
|
|
243
265
|
if (idl.isReferenceType(returnType)) {
|
|
244
266
|
const returnTypeArgs = this.extractTypeArguments(file, node.extAttrs, idl.IDLExtendedAttributes.TypeArguments);
|
|
@@ -250,17 +272,17 @@ class IDLDeserializer {
|
|
|
250
272
|
}, {
|
|
251
273
|
documentation: this.makeDocs(node),
|
|
252
274
|
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
253
|
-
},
|
|
275
|
+
}, generics));
|
|
254
276
|
this.genericsScopes.pop();
|
|
255
277
|
return result;
|
|
256
278
|
}
|
|
257
279
|
toIDLMethod(file, node, isFree = false) {
|
|
258
|
-
var _a
|
|
280
|
+
var _a;
|
|
259
281
|
if (!node.idlType) {
|
|
260
282
|
throw new Error(`method with no type ${toString(node)}`);
|
|
261
283
|
}
|
|
262
284
|
const generics = this.extractGenerics(node.extAttrs);
|
|
263
|
-
this.
|
|
285
|
+
this.enterGenericScope(generics);
|
|
264
286
|
const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
|
|
265
287
|
if (idl.isReferenceType(returnType))
|
|
266
288
|
returnType.typeArguments = this.extractTypeArguments(file, node.extAttrs, idl.IDLExtendedAttributes.TypeArguments);
|
|
@@ -272,7 +294,7 @@ class IDLDeserializer {
|
|
|
272
294
|
}, {
|
|
273
295
|
documentation: this.makeDocs(node),
|
|
274
296
|
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
275
|
-
},
|
|
297
|
+
}, generics));
|
|
276
298
|
this.genericsScopes.pop();
|
|
277
299
|
return result;
|
|
278
300
|
}
|
|
@@ -287,22 +309,24 @@ class IDLDeserializer {
|
|
|
287
309
|
}));
|
|
288
310
|
}
|
|
289
311
|
toIDLCallback(file, node) {
|
|
312
|
+
const generics = this.extractGenerics(node.extAttrs);
|
|
313
|
+
this.enterGenericScope(generics);
|
|
290
314
|
const result = idl.createCallback(node.name, node.arguments.map(it => this.toIDLParameter(file, it)), this.toIDLType(file, node.idlType, undefined), {
|
|
291
315
|
fileName: file,
|
|
292
316
|
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
293
317
|
documentation: this.makeDocs(node),
|
|
294
|
-
});
|
|
318
|
+
}, generics);
|
|
295
319
|
if (node.extAttrs.find(it => it.name === "Synthetic")) {
|
|
296
320
|
const fqName = this.currentPackage.concat(this.namespacePathNames).concat([node.name]).join('.');
|
|
297
321
|
addSyntheticType(fqName, result);
|
|
298
322
|
}
|
|
323
|
+
this.genericsScopes.pop();
|
|
299
324
|
return this.withInfo(node, result);
|
|
300
325
|
}
|
|
301
326
|
toIDLTypedef(file, node) {
|
|
302
|
-
var _a;
|
|
303
327
|
const generics = this.extractGenerics(node.extAttrs);
|
|
304
|
-
this.
|
|
305
|
-
const result = this.withInfo(node, idl.createTypedef(node.name, this.toIDLType(file, node.idlType, undefined
|
|
328
|
+
this.enterGenericScope(generics);
|
|
329
|
+
const result = this.withInfo(node, idl.createTypedef(node.name, this.toIDLType(file, node.idlType, undefined, node.name), generics, {
|
|
306
330
|
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
307
331
|
documentation: this.makeDocs(node),
|
|
308
332
|
fileName: file,
|
|
@@ -358,7 +382,7 @@ class IDLDeserializer {
|
|
|
358
382
|
initializer = undefined;
|
|
359
383
|
}
|
|
360
384
|
else {
|
|
361
|
-
throw new Error(`Not representable enum initializer: ${node.default}`);
|
|
385
|
+
throw new Error(`Not representable enum initializer: ${JSON.stringify(node.default)}. Found in ${file}`);
|
|
362
386
|
}
|
|
363
387
|
return this.withInfo(node, idl.createEnumMember(node.name, parent, this.toIDLType(file, node.idlType, undefined), initializer, {
|
|
364
388
|
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
@@ -401,17 +425,39 @@ class IDLDeserializer {
|
|
|
401
425
|
return node.type === 'import';
|
|
402
426
|
}
|
|
403
427
|
isCallable(node) {
|
|
404
|
-
return node.extAttrs.some(it => it.name ==
|
|
428
|
+
return node.extAttrs.some(it => it.name == idl.IDLExtendedAttributes.CallSignature);
|
|
405
429
|
}
|
|
406
430
|
///
|
|
431
|
+
splitTypeArguments(line) {
|
|
432
|
+
let buffer = "";
|
|
433
|
+
let brackets = 0;
|
|
434
|
+
const result = [];
|
|
435
|
+
for (const letter of line) {
|
|
436
|
+
if (letter === ',' && brackets === 0) {
|
|
437
|
+
result.push(buffer);
|
|
438
|
+
buffer = '';
|
|
439
|
+
continue;
|
|
440
|
+
}
|
|
441
|
+
if (letter === '<') {
|
|
442
|
+
brackets += 1;
|
|
443
|
+
}
|
|
444
|
+
if (letter === '>') {
|
|
445
|
+
brackets -= 1;
|
|
446
|
+
}
|
|
447
|
+
buffer += letter;
|
|
448
|
+
}
|
|
449
|
+
if (buffer.length) {
|
|
450
|
+
result.push(buffer);
|
|
451
|
+
}
|
|
452
|
+
return result;
|
|
453
|
+
}
|
|
407
454
|
extractTypeArguments(file, extAttrs, attribute) {
|
|
408
455
|
var _a;
|
|
409
456
|
const attr = extAttrs === null || extAttrs === void 0 ? void 0 : extAttrs.find(it => it.name === attribute);
|
|
410
457
|
if (!attr)
|
|
411
458
|
return undefined;
|
|
412
459
|
let value = this.toExtendedAttributeValue(attr);
|
|
413
|
-
return (_a = value === null ||
|
|
414
|
-
) === null || _a === void 0 ? void 0 : _a.map(it => { var _a; return this.toIDLType(file, (_a = webidl2.parseType(it, file)) !== null && _a !== void 0 ? _a : it); });
|
|
460
|
+
return (_a = this.splitTypeArguments(value)) === null || _a === void 0 ? void 0 : _a.map(it => { var _a; return this.toIDLType(file, (_a = webidl2.parseType(it.replaceAll('\'', '"'), file)) !== null && _a !== void 0 ? _a : it); });
|
|
415
461
|
}
|
|
416
462
|
constantValue(node) {
|
|
417
463
|
switch (node.value.type) {
|
|
@@ -480,9 +526,9 @@ class IDLDeserializer {
|
|
|
480
526
|
return attr ? this.toExtendedAttributeValue(attr) : undefined;
|
|
481
527
|
}
|
|
482
528
|
}
|
|
483
|
-
export function toIDLFile(fileName, content) {
|
|
529
|
+
export function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
|
|
484
530
|
const lexicalInfo = new Map();
|
|
485
|
-
const deserializer = new IDLDeserializer(lexicalInfo);
|
|
531
|
+
const deserializer = new IDLDeserializer(lexicalInfo, inheritanceMode);
|
|
486
532
|
if (undefined === content)
|
|
487
533
|
content = fs.readFileSync(fileName).toString();
|
|
488
534
|
let packageClause = [];
|
package/build/lib/src/idl.d.ts
CHANGED
|
@@ -44,6 +44,7 @@ export declare enum IDLExtendedAttributes {
|
|
|
44
44
|
DtsName = "DtsName",
|
|
45
45
|
DtsTag = "DtsTag",
|
|
46
46
|
Entity = "Entity",
|
|
47
|
+
Extends = "Extends",
|
|
47
48
|
Import = "Import",
|
|
48
49
|
DefaultExport = "DefaultExport",
|
|
49
50
|
IndexSignature = "IndexSignature",
|
|
@@ -281,7 +282,7 @@ export declare const IDLStringType: IDLPrimitiveType;
|
|
|
281
282
|
export declare const IDLAnyType: IDLPrimitiveType;
|
|
282
283
|
export declare const IDLUndefinedType: IDLPrimitiveType;
|
|
283
284
|
export declare const IDLUnknownType: IDLPrimitiveType;
|
|
284
|
-
export declare const IDLObjectType:
|
|
285
|
+
export declare const IDLObjectType: IDLPrimitiveType;
|
|
285
286
|
export declare const IDLThisType: IDLPrimitiveType;
|
|
286
287
|
export declare const IDLDate: IDLPrimitiveType;
|
|
287
288
|
export declare const IDLBufferType: IDLPrimitiveType;
|
|
@@ -333,13 +334,14 @@ export type IDLCallableInitializer = {
|
|
|
333
334
|
isAsync: boolean;
|
|
334
335
|
isStatic: boolean;
|
|
335
336
|
};
|
|
336
|
-
export declare function createCallable(name: string, parameters: IDLParameter[], returnType: IDLType, callableInitializer: IDLCallableInitializer, nodeInitializer
|
|
337
|
+
export declare function createCallable(name: string, parameters: IDLParameter[], returnType: IDLType, callableInitializer: IDLCallableInitializer, nodeInitializer?: IDLNodeInitializer, typeParameters?: string[]): IDLCallable;
|
|
337
338
|
export declare function createConstructor(parameters: IDLParameter[], returnType: IDLType | undefined, nodeInitializer?: IDLNodeInitializer): IDLConstructor;
|
|
338
339
|
export declare function createCallback(name: string, parameters: IDLParameter[], returnType: IDLType, nodeInitializer?: IDLNodeInitializer, typeParameters?: string[]): IDLCallback;
|
|
339
340
|
export declare function createTypeParameterReference(name: string, nodeInitializer?: IDLNodeInitializer): IDLTypeParameterType;
|
|
340
341
|
export declare function createTypedef(name: string, type: IDLType, typeParameters?: string[], nodeInitializer?: IDLNodeInitializer): IDLTypedef;
|
|
341
342
|
export declare function createConstant(name: string, type: IDLType, value: string, nodeInitializer?: IDLNodeInitializer): IDLConstant;
|
|
342
343
|
export declare function clone<T extends IDLNode>(node: T): T;
|
|
344
|
+
export declare function hasTypeParameters(entry: IDLEntry): boolean;
|
|
343
345
|
export declare function escapeIDLKeyword(name: string): string;
|
|
344
346
|
export declare function unescapeKeyword(name: string): string;
|
|
345
347
|
type PrintedIndentInc = "[[indent-inc]]";
|