@idlizer/core 2.0.31 → 2.0.32
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 -2
- package/build/lib/src/LanguageWriters/ArgConvertors.js +19 -19
- package/build/lib/src/LanguageWriters/convertors/CppConvertors.js +3 -5
- package/build/lib/src/LanguageWriters/convertors/ETSConvertors.js +1 -1
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +2 -2
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +5 -2
- package/build/lib/src/from-idl/DtsPrinter.js +18 -15
- package/build/lib/src/from-idl/deserialize.d.ts +1 -2
- package/build/lib/src/from-idl/deserialize.js +10 -12
- package/build/lib/src/idl.d.ts +18 -8
- package/build/lib/src/idl.js +81 -39
- package/build/lib/src/idlize.d.ts +12 -2
- package/build/lib/src/idlize.js +24 -9
- package/build/lib/src/library.d.ts +5 -10
- package/build/lib/src/library.js +2 -2
- package/build/lib/src/peer-generation/PeerFile.d.ts +4 -3
- package/build/lib/src/peer-generation/PeerFile.js +10 -3
- package/build/lib/src/peer-generation/PeerLibrary.d.ts +4 -6
- package/build/lib/src/peer-generation/PeerLibrary.js +18 -36
- package/build/lib/src/peer-generation/idl/common.js +3 -3
- package/build/lib/src/util.d.ts +2 -0
- package/build/lib/src/util.js +4 -0
- package/build/lib/src/visitor.js +1 -1
- package/package.json +1 -1
- package/webidl2.js/dist/webidl2.js +20 -19
|
@@ -3,6 +3,7 @@ import { Language } from "../Language";
|
|
|
3
3
|
import { LanguageExpression, LanguageStatement, LanguageWriter, ExpressionAssigner } from "./LanguageWriter";
|
|
4
4
|
import { RuntimeType } from "./common";
|
|
5
5
|
import { LibraryInterface } from "../LibraryInterface";
|
|
6
|
+
import { ReferenceResolver } from "../peer-generation/ReferenceResolver";
|
|
6
7
|
export interface ArgConvertor {
|
|
7
8
|
param: string;
|
|
8
9
|
idlType: idl.IDLType;
|
|
@@ -220,7 +221,7 @@ export declare class DateConvertor extends BaseArgConvertor {
|
|
|
220
221
|
}
|
|
221
222
|
export declare class ProxyConvertor extends BaseArgConvertor {
|
|
222
223
|
convertor: ArgConvertor;
|
|
223
|
-
constructor(convertor: ArgConvertor,
|
|
224
|
+
constructor(convertor: ArgConvertor, suggestedReference?: idl.IDLReferenceType);
|
|
224
225
|
convertorArg(param: string, writer: LanguageWriter): string;
|
|
225
226
|
convertorDeserialize(bufferName: string, deserializerName: string, assigneer: ExpressionAssigner, writer: LanguageWriter): LanguageStatement;
|
|
226
227
|
convertorSerialize(param: string, value: string, printer: LanguageWriter): void;
|
|
@@ -323,5 +324,5 @@ export declare function generateCallbackKindName(callback: idl.IDLCallback): str
|
|
|
323
324
|
export declare function generateCallbackKindAccess(callback: idl.IDLCallback, language: Language): string;
|
|
324
325
|
export declare function generateCallbackKindValue(callback: idl.IDLCallback): number;
|
|
325
326
|
export declare function generateCallbackAPIArguments(library: LibraryInterface, callback: idl.IDLCallback): string[];
|
|
326
|
-
export declare function maybeTransformManagedCallback(callback: idl.IDLCallback): idl.IDLCallback | undefined;
|
|
327
|
+
export declare function maybeTransformManagedCallback(callback: idl.IDLCallback, library: ReferenceResolver): idl.IDLCallback | undefined;
|
|
327
328
|
//# sourceMappingURL=ArgConvertors.d.ts.map
|
|
@@ -154,7 +154,7 @@ export class StringConvertor extends BaseArgConvertor {
|
|
|
154
154
|
}
|
|
155
155
|
export class EnumConvertor extends BaseArgConvertor {
|
|
156
156
|
constructor(param, enumEntry) {
|
|
157
|
-
super(idl.createReferenceType(enumEntry
|
|
157
|
+
super(idl.createReferenceType(enumEntry), [idl.isStringEnum(enumEntry) ? RuntimeType.STRING : RuntimeType.NUMBER], false, false, param);
|
|
158
158
|
this.enumEntry = enumEntry;
|
|
159
159
|
}
|
|
160
160
|
convertorArg(param, writer) {
|
|
@@ -163,19 +163,19 @@ export class EnumConvertor extends BaseArgConvertor {
|
|
|
163
163
|
convertorSerialize(param, value, writer) {
|
|
164
164
|
value =
|
|
165
165
|
idl.isStringEnum(this.enumEntry)
|
|
166
|
-
? writer.ordinalFromEnum(writer.makeString(value), idl.createReferenceType(this.enumEntry
|
|
166
|
+
? writer.ordinalFromEnum(writer.makeString(value), idl.createReferenceType(this.enumEntry)).asString()
|
|
167
167
|
: writer.makeEnumCast(value, false, this);
|
|
168
168
|
writer.writeMethodCall(`${param}Serializer`, "writeInt32", [value]);
|
|
169
169
|
}
|
|
170
170
|
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
171
171
|
const readExpr = writer.makeMethodCall(`${deserializerName}`, "readInt32", []);
|
|
172
172
|
const enumExpr = idl.isStringEnum(this.enumEntry)
|
|
173
|
-
? writer.enumFromOrdinal(readExpr, idl.createReferenceType(this.enumEntry
|
|
174
|
-
: writer.makeCast(readExpr, idl.createReferenceType(this.enumEntry
|
|
173
|
+
? writer.enumFromOrdinal(readExpr, idl.createReferenceType(this.enumEntry))
|
|
174
|
+
: writer.makeCast(readExpr, idl.createReferenceType(this.enumEntry));
|
|
175
175
|
return assigneer(enumExpr);
|
|
176
176
|
}
|
|
177
177
|
nativeType() {
|
|
178
|
-
return idl.createReferenceType(this.enumEntry
|
|
178
|
+
return idl.createReferenceType(this.enumEntry);
|
|
179
179
|
}
|
|
180
180
|
interopType() {
|
|
181
181
|
return idl.IDLI32Type;
|
|
@@ -388,7 +388,7 @@ export class AggregateConvertor extends BaseArgConvertor {
|
|
|
388
388
|
return writer.makeCast(writer.makeString(`{${content}}`), this.idlType);
|
|
389
389
|
}
|
|
390
390
|
nativeType() {
|
|
391
|
-
return idl.createReferenceType(this.decl
|
|
391
|
+
return idl.createReferenceType(this.decl);
|
|
392
392
|
}
|
|
393
393
|
interopType() {
|
|
394
394
|
throw new Error("Must never be used");
|
|
@@ -421,7 +421,7 @@ export class TupleConvertor extends AggregateConvertor {
|
|
|
421
421
|
return writer.makeCast(writer.makeString(`[${fields.map(it => it[1].asString()).join(', ')}]`), this.idlType);
|
|
422
422
|
}
|
|
423
423
|
nativeType() {
|
|
424
|
-
return idl.createReferenceType(this.decl
|
|
424
|
+
return idl.createReferenceType(this.decl);
|
|
425
425
|
}
|
|
426
426
|
interopType() {
|
|
427
427
|
throw new Error("Must never be used");
|
|
@@ -439,7 +439,7 @@ export class TupleConvertor extends AggregateConvertor {
|
|
|
439
439
|
}
|
|
440
440
|
export class InterfaceConvertor extends BaseArgConvertor {
|
|
441
441
|
constructor(library, name /* change to IDLReferenceType */, param, declaration) {
|
|
442
|
-
super(idl.createReferenceType(
|
|
442
|
+
super(idl.createReferenceType(declaration), [RuntimeType.OBJECT], false, true, param);
|
|
443
443
|
this.library = library;
|
|
444
444
|
this.declaration = declaration;
|
|
445
445
|
}
|
|
@@ -637,8 +637,8 @@ export class DateConvertor extends BaseArgConvertor {
|
|
|
637
637
|
}
|
|
638
638
|
}
|
|
639
639
|
export class ProxyConvertor extends BaseArgConvertor {
|
|
640
|
-
constructor(convertor,
|
|
641
|
-
super(
|
|
640
|
+
constructor(convertor, suggestedReference) {
|
|
641
|
+
super(suggestedReference ? suggestedReference : convertor.idlType, convertor.runtimeTypes, convertor.isScoped, convertor.useArray, convertor.param);
|
|
642
642
|
this.convertor = convertor;
|
|
643
643
|
}
|
|
644
644
|
convertorArg(param, writer) {
|
|
@@ -668,7 +668,7 @@ export class ProxyConvertor extends BaseArgConvertor {
|
|
|
668
668
|
}
|
|
669
669
|
export class TypeAliasConvertor extends ProxyConvertor {
|
|
670
670
|
constructor(library, param, typedef) {
|
|
671
|
-
super(library.typeConvertor(param, typedef.type), typedef
|
|
671
|
+
super(library.typeConvertor(param, typedef.type), idl.createReferenceType(typedef));
|
|
672
672
|
}
|
|
673
673
|
}
|
|
674
674
|
export class CustomTypeConvertor extends BaseArgConvertor {
|
|
@@ -888,7 +888,7 @@ export class FunctionConvertor extends BaseArgConvertor {
|
|
|
888
888
|
}
|
|
889
889
|
export class MaterializedClassConvertor extends BaseArgConvertor {
|
|
890
890
|
constructor(param, declaration) {
|
|
891
|
-
super(idl.createReferenceType(declaration
|
|
891
|
+
super(idl.createReferenceType(declaration), [RuntimeType.OBJECT], false, true, param);
|
|
892
892
|
this.declaration = declaration;
|
|
893
893
|
}
|
|
894
894
|
convertorArg(param, writer) {
|
|
@@ -900,11 +900,11 @@ export class MaterializedClassConvertor extends BaseArgConvertor {
|
|
|
900
900
|
])));
|
|
901
901
|
}
|
|
902
902
|
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
903
|
-
const readStatement = writer.makeCast(writer.makeMethodCall(`${deserializerName}`, `read${this.declaration.name}`, []), idl.createReferenceType(this.declaration
|
|
903
|
+
const readStatement = writer.makeCast(writer.makeMethodCall(`${deserializerName}`, `read${this.declaration.name}`, []), idl.createReferenceType(this.declaration));
|
|
904
904
|
return assigneer(readStatement);
|
|
905
905
|
}
|
|
906
906
|
nativeType() {
|
|
907
|
-
return idl.createReferenceType(this.declaration
|
|
907
|
+
return idl.createReferenceType(this.declaration);
|
|
908
908
|
}
|
|
909
909
|
interopType() {
|
|
910
910
|
throw new Error("Must never be used");
|
|
@@ -952,7 +952,7 @@ export class ImportTypeConvertor extends BaseArgConvertor {
|
|
|
952
952
|
}
|
|
953
953
|
export class CallbackConvertor extends BaseArgConvertor {
|
|
954
954
|
constructor(library, param, decl) {
|
|
955
|
-
super(idl.createReferenceType(decl
|
|
955
|
+
super(idl.createReferenceType(decl), [RuntimeType.FUNCTION], false, true, param);
|
|
956
956
|
this.library = library;
|
|
957
957
|
this.decl = decl;
|
|
958
958
|
}
|
|
@@ -961,7 +961,7 @@ export class CallbackConvertor extends BaseArgConvertor {
|
|
|
961
961
|
}
|
|
962
962
|
get transformedDecl() {
|
|
963
963
|
var _a;
|
|
964
|
-
return (_a = maybeTransformManagedCallback(this.decl)) !== null && _a !== void 0 ? _a : this.decl;
|
|
964
|
+
return (_a = maybeTransformManagedCallback(this.decl, this.library)) !== null && _a !== void 0 ? _a : this.decl;
|
|
965
965
|
}
|
|
966
966
|
convertorArg(param, writer) {
|
|
967
967
|
throw new Error("Must never be used");
|
|
@@ -998,7 +998,7 @@ export class CallbackConvertor extends BaseArgConvertor {
|
|
|
998
998
|
return assigneer(result);
|
|
999
999
|
}
|
|
1000
1000
|
nativeType() {
|
|
1001
|
-
return idl.createReferenceType(this.
|
|
1001
|
+
return idl.createReferenceType(this.decl);
|
|
1002
1002
|
}
|
|
1003
1003
|
isPointerType() {
|
|
1004
1004
|
return true;
|
|
@@ -1042,9 +1042,9 @@ export function generateCallbackAPIArguments(library, callback) {
|
|
|
1042
1042
|
}
|
|
1043
1043
|
return args;
|
|
1044
1044
|
}
|
|
1045
|
-
export function maybeTransformManagedCallback(callback) {
|
|
1045
|
+
export function maybeTransformManagedCallback(callback, library) {
|
|
1046
1046
|
if (callback.name === "CustomBuilder")
|
|
1047
|
-
return
|
|
1047
|
+
return library.resolveTypeReference(idl.createReferenceType("CustomNodeBuilder"));
|
|
1048
1048
|
return undefined;
|
|
1049
1049
|
}
|
|
1050
1050
|
//# sourceMappingURL=ArgConvertors.js.map
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
15
|
import * as idl from '../../idl';
|
|
16
|
-
import { generatorConfiguration } from "../../config";
|
|
16
|
+
import { generatorConfiguration, generatorTypePrefix } from "../../config";
|
|
17
17
|
import { convertNode, convertType } from "../nameConvertor";
|
|
18
18
|
import { PrimitiveTypesInstance } from '../../peer-generation/PrimitiveType';
|
|
19
19
|
import { InteropArgConvertor } from './InteropConvertors';
|
|
@@ -105,7 +105,7 @@ export class GenericCppConvertor {
|
|
|
105
105
|
}
|
|
106
106
|
let decl = this.resolver.toDeclaration(type);
|
|
107
107
|
if (idl.isCallback(decl)) {
|
|
108
|
-
decl = (_a = maybeTransformManagedCallback(decl)) !== null && _a !== void 0 ? _a : decl;
|
|
108
|
+
decl = (_a = maybeTransformManagedCallback(decl, this.resolver)) !== null && _a !== void 0 ? _a : decl;
|
|
109
109
|
}
|
|
110
110
|
if (idl.isType(decl)) {
|
|
111
111
|
if (idl.isReferenceType(decl)) {
|
|
@@ -239,8 +239,6 @@ export class CppReturnTypeConvertor {
|
|
|
239
239
|
convertPrimitiveType(type) {
|
|
240
240
|
if (type == idl.IDLUndefinedType)
|
|
241
241
|
return 'void';
|
|
242
|
-
if (type == idl.IDLStringType)
|
|
243
|
-
return 'void';
|
|
244
242
|
if (type == idl.IDLNumberType)
|
|
245
243
|
return generatorConfiguration().TypePrefix + 'Int32'; // :(
|
|
246
244
|
return this.convertor.convert(type);
|
|
@@ -251,7 +249,7 @@ export class CppReturnTypeConvertor {
|
|
|
251
249
|
convertTypeReference(type) {
|
|
252
250
|
const decl = this.resolver.resolveTypeReference(type);
|
|
253
251
|
if (decl && idl.isInterface(decl) && isMaterialized(decl, this.resolver)) {
|
|
254
|
-
return
|
|
252
|
+
return generatorTypePrefix() + decl.name;
|
|
255
253
|
}
|
|
256
254
|
return this.convertor.convert(type);
|
|
257
255
|
}
|
|
@@ -28,7 +28,7 @@ export class ETSTypeNameConvertor extends TSTypeNameConvertor {
|
|
|
28
28
|
const types = type.name.split(".");
|
|
29
29
|
if (types.length > 1) {
|
|
30
30
|
// Takes only name without the namespace prefix
|
|
31
|
-
const decl = this.resolver.resolveTypeReference(idl.createReferenceType(types.slice(-1).join()
|
|
31
|
+
const decl = this.resolver.resolveTypeReference(idl.createReferenceType(types.slice(-1).join()));
|
|
32
32
|
if (decl !== undefined) {
|
|
33
33
|
return convertDeclaration(createDeclarationNameConvertor(Language.ARKTS), decl);
|
|
34
34
|
}
|
|
@@ -186,7 +186,7 @@ export class CJEnumWithGetter {
|
|
|
186
186
|
}
|
|
187
187
|
let enumName = this.enumEntity.name;
|
|
188
188
|
writer.writeClass(enumName, () => {
|
|
189
|
-
const enumType = idl.createReferenceType(
|
|
189
|
+
const enumType = idl.createReferenceType(this.enumEntity);
|
|
190
190
|
members.forEach(it => {
|
|
191
191
|
writer.writeFieldDeclaration(it.name, enumType, [FieldModifier.PUBLIC, FieldModifier.STATIC, FieldModifier.FINAL], false, writer.makeString(`${enumName}(${it.numberId})`));
|
|
192
192
|
});
|
|
@@ -243,7 +243,7 @@ export class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
243
243
|
this.print(`#include <${path}>`);
|
|
244
244
|
}
|
|
245
245
|
makeRef(type, options) {
|
|
246
|
-
return createReferenceType(`${this.stringifyTypeWithReceiver(type, options === null || options === void 0 ? void 0 : options.receiver)}
|
|
246
|
+
return createReferenceType(`${this.stringifyTypeWithReceiver(type, options === null || options === void 0 ? void 0 : options.receiver)}&`);
|
|
247
247
|
}
|
|
248
248
|
makeThis() {
|
|
249
249
|
return new StringExpression("*this");
|
|
@@ -113,7 +113,7 @@ export class ETSLambdaExpression extends LambdaExpression {
|
|
|
113
113
|
// Issue: https://rnd-gitlab-msc.huawei.com/rus-os-team/virtual-machines-and-tools/panda/-/issues/21333
|
|
114
114
|
let isRetTypeCallback = idl.isCallback(this.signature.returnType);
|
|
115
115
|
if (idl.isReferenceType(this.signature.returnType)) {
|
|
116
|
-
const resolved = this.resolver.resolveTypeReference(
|
|
116
|
+
const resolved = this.resolver.resolveTypeReference(this.signature.returnType);
|
|
117
117
|
isRetTypeCallback = resolved !== undefined && idl.isCallback(resolved);
|
|
118
118
|
}
|
|
119
119
|
return `(${params.join(", ")})${isRetTypeCallback
|
|
@@ -237,7 +237,7 @@ export class ETSLanguageWriter extends TSLanguageWriter {
|
|
|
237
237
|
? convertor.nativeType().types[runtimeTypeIndex]
|
|
238
238
|
: idl.maybeUnwrapOptionalType(convertor.nativeType());
|
|
239
239
|
if (idlType !== undefined && idl.isReferenceType(idlType)) {
|
|
240
|
-
const resolved = this.resolver.resolveTypeReference(
|
|
240
|
+
const resolved = this.resolver.resolveTypeReference(idlType);
|
|
241
241
|
type = resolved != undefined && idl.isEnum(resolved) ? RuntimeType[RuntimeType.OBJECT] : type;
|
|
242
242
|
}
|
|
243
243
|
}
|
|
@@ -377,12 +377,15 @@ export class TSLanguageWriter extends LanguageWriter {
|
|
|
377
377
|
return TSKeywords.has(keyword) ? keyword + "_" : keyword;
|
|
378
378
|
}
|
|
379
379
|
makeDiscriminatorConvertor(convertor, value, index) {
|
|
380
|
-
const
|
|
380
|
+
const convertorNativeType = convertor.nativeType();
|
|
381
|
+
const decl = this.resolver.resolveTypeReference(idl.isReferenceType(convertorNativeType)
|
|
382
|
+
? convertorNativeType
|
|
383
|
+
: idl.createReferenceType(this.getNodeName(convertorNativeType)));
|
|
381
384
|
if (decl === undefined || !idl.isEnum(decl)) {
|
|
382
385
|
throwException(`The type reference ${decl === null || decl === void 0 ? void 0 : decl.name} must be Enum`);
|
|
383
386
|
}
|
|
384
387
|
const ordinal = idl.isStringEnum(decl)
|
|
385
|
-
? this.ordinalFromEnum(this.makeCast(this.makeString(this.getObjectAccessor(convertor, value)), convertor.idlType), idl.createReferenceType(this.getNodeName(convertor.nativeType())
|
|
388
|
+
? this.ordinalFromEnum(this.makeCast(this.makeString(this.getObjectAccessor(convertor, value)), convertor.idlType), idl.createReferenceType(this.getNodeName(convertor.nativeType())))
|
|
386
389
|
: this.makeUnionVariantCast(this.getObjectAccessor(convertor, value), this.getNodeName(idl.IDLI32Type), convertor, index);
|
|
387
390
|
const { low, high } = idl.extremumOfOrdinals(decl);
|
|
388
391
|
return this.discriminatorFromExpressions(value, convertor.runtimeTypes[0], [
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* See the License for the specific language governing permissions and
|
|
13
13
|
* limitations under the License.
|
|
14
14
|
*/
|
|
15
|
-
import { indentedBy } from "../util";
|
|
16
|
-
import { IDLEntity, IDLKind, getExtAttribute, getVerbatimDts, hasExtAttribute, isCallback, isConstructor, isContainerType, isEnum, isInterface, isMethod, isPrimitiveType, isProperty, isReferenceType, isSyntheticEntry, isTypeParameterType, isTypedef, isUnionType, isPackage, 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 } from "../idl";
|
|
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, isPackage, 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 } from "../idl";
|
|
17
17
|
import * as webidl2 from "webidl2";
|
|
18
18
|
import { resolveSyntheticType, toIDLNode } from "./deserialize";
|
|
19
19
|
import { Language } from "../Language";
|
|
@@ -27,7 +27,8 @@ export class CustomPrintVisitor {
|
|
|
27
27
|
visit(node, wrapNamespaces = false) {
|
|
28
28
|
const namespacesPath = wrapNamespaces ? getNamespacesPathFor(node) : [];
|
|
29
29
|
for (const namespace of namespacesPath) {
|
|
30
|
-
|
|
30
|
+
const isTopmost = namespacesPath[0] === namespace;
|
|
31
|
+
this.print(`${!isTopmost ? "" : "declare "}namespace ${namespace.name} {`);
|
|
31
32
|
this.pushIndent();
|
|
32
33
|
}
|
|
33
34
|
if (hasExtAttribute(node, IDLExtendedAttributes.TSType) && this.language == Language.TS)
|
|
@@ -82,7 +83,7 @@ export class CustomPrintVisitor {
|
|
|
82
83
|
this.print(exports);
|
|
83
84
|
}
|
|
84
85
|
printConstant(node) {
|
|
85
|
-
this.print(`${node
|
|
86
|
+
this.print(`${isInNamespace(node) ? "" : "declare "}const ${node.name} : ${isPrimitiveType(node.type) ? "" : "typeof"} ${this.printTypeForTS(node.type)} = ${node.value}`);
|
|
86
87
|
}
|
|
87
88
|
printInterface(node) {
|
|
88
89
|
var _a;
|
|
@@ -92,13 +93,13 @@ export class CustomPrintVisitor {
|
|
|
92
93
|
typeSpec = "WrappedBuilder<Args extends any[]>";
|
|
93
94
|
const entity = (_a = getExtAttribute(node, IDLExtendedAttributes.Entity)) !== null && _a !== void 0 ? _a : IDLEntity.Interface;
|
|
94
95
|
if (entity === IDLEntity.Literal) {
|
|
95
|
-
this.print(`${node
|
|
96
|
+
this.print(`${isInNamespace(node) ? "" : "declare "}type ${typeSpec} = ${this.literal(node, false, true)}`);
|
|
96
97
|
}
|
|
97
98
|
else if (entity === IDLEntity.Tuple) {
|
|
98
|
-
this.print(`${node
|
|
99
|
+
this.print(`${isInNamespace(node) ? "" : "declare "}type ${typeSpec} = ${this.literal(node, true, false)}`);
|
|
99
100
|
}
|
|
100
101
|
else if (entity === IDLEntity.NamedTuple) {
|
|
101
|
-
this.print(`${node
|
|
102
|
+
this.print(`${isInNamespace(node) ? "" : "declare "}type ${typeSpec} = ${this.literal(node, true, true)}`);
|
|
102
103
|
}
|
|
103
104
|
else {
|
|
104
105
|
// restore globalScope
|
|
@@ -118,7 +119,7 @@ export class CustomPrintVisitor {
|
|
|
118
119
|
}
|
|
119
120
|
if (interfaces.length > 0)
|
|
120
121
|
typeSpec += ` ${keyword} ${interfaces.map(it => this.toTypeName(it)).join(", ")}`;
|
|
121
|
-
this.print(`${node
|
|
122
|
+
this.print(`${isInNamespace(node) ? "" : "declare "}${entity.toLowerCase()} ${typeSpec} {`);
|
|
122
123
|
this.currentInterface = node;
|
|
123
124
|
this.pushIndent();
|
|
124
125
|
node.constructors.map(it => this.visit(it));
|
|
@@ -151,7 +152,8 @@ export class CustomPrintVisitor {
|
|
|
151
152
|
const isFree = isMethod(node) && node.isFree;
|
|
152
153
|
if (isGlobal && !isFree) // TODO: namespace-related-to-rework
|
|
153
154
|
throw new Error("internal error");
|
|
154
|
-
|
|
155
|
+
const inNamespace = getNamespacesPathFor(node).length > 0;
|
|
156
|
+
preamble = `${isFree ? `${isInNamespace(node) ? "" : "declare "}function ` : ""}${isProtected ? "protected " : ""}${isStatic ? "static " : ""}${name}${isOptional ? "?" : ""}`;
|
|
155
157
|
}
|
|
156
158
|
this.print(`${preamble}${typeParams}(${mixMethodParametersAndTags(node).map(p => this.paramText(p)).join(", ")})${returnType};`);
|
|
157
159
|
}
|
|
@@ -187,7 +189,7 @@ export class CustomPrintVisitor {
|
|
|
187
189
|
}
|
|
188
190
|
}
|
|
189
191
|
printEnum(node) {
|
|
190
|
-
this.print(`${node
|
|
192
|
+
this.print(`${isInNamespace(node) ? "" : "declare "}enum ${node.name} {`);
|
|
191
193
|
this.pushIndent();
|
|
192
194
|
node.elements.forEach(it => {
|
|
193
195
|
const initializer = (it.type === IDLStringType ? `"${it.initializer}"` : `${it.initializer}`);
|
|
@@ -204,7 +206,7 @@ export class CustomPrintVisitor {
|
|
|
204
206
|
// Let's skip imported declarations
|
|
205
207
|
if (isTypedef(node) &&
|
|
206
208
|
hasExtAttribute(node, IDLExtendedAttributes.Import)) {
|
|
207
|
-
let definition = this.resolver(createReferenceType(node
|
|
209
|
+
let definition = this.resolver(createReferenceType(node));
|
|
208
210
|
// TODO: handle namespace case better!
|
|
209
211
|
// TODO: namespace-related-to-rework
|
|
210
212
|
throw new Error("not implemented yet");
|
|
@@ -217,7 +219,7 @@ export class CustomPrintVisitor {
|
|
|
217
219
|
: hasExtAttribute(node, IDLExtendedAttributes.Import) ? IDLAnyType.name
|
|
218
220
|
: this.printTypeForTS(node.type);
|
|
219
221
|
const typeParams = node.typeParameters && node.typeParameters.length > 0 ? `<${node.typeParameters.join(",")}>` : "";
|
|
220
|
-
this.print(`${node
|
|
222
|
+
this.print(`${isInNamespace(node) ? '' : 'declare '}type ${getName(node)}${typeParams} = ${text};`);
|
|
221
223
|
}
|
|
222
224
|
printVersion(node) {
|
|
223
225
|
let text = node.value.join(".");
|
|
@@ -229,17 +231,17 @@ export class CustomPrintVisitor {
|
|
|
229
231
|
this.print(verbatimDts);
|
|
230
232
|
return;
|
|
231
233
|
}
|
|
232
|
-
this.print(`${node
|
|
234
|
+
this.print(`${isInNamespace(node) ? "" : "declare "} namespace ${node.name} {`);
|
|
233
235
|
this.pushIndent();
|
|
234
236
|
node.members.forEach(member => this.visit(member));
|
|
235
237
|
this.popIndent();
|
|
236
238
|
this.print("}");
|
|
237
239
|
}
|
|
238
240
|
printImport(node) {
|
|
239
|
-
this.print(`// import ${node.name}`);
|
|
241
|
+
this.print(`// import ${node.clause.join(".")}${node.name ? " as " : ""}${node.name || ""}`);
|
|
240
242
|
}
|
|
241
243
|
printPackage(node) {
|
|
242
|
-
this.print(`// package ${node.
|
|
244
|
+
this.print(`// package ${node.clause.join(".")}`);
|
|
243
245
|
}
|
|
244
246
|
checkVerbatim(node) {
|
|
245
247
|
let verbatim = getExtAttribute(node, IDLExtendedAttributes.VerbatimDts);
|
|
@@ -291,6 +293,7 @@ export class CustomPrintVisitor {
|
|
|
291
293
|
case IDLStringType: return "string";
|
|
292
294
|
case IDLVoidType: return "void";
|
|
293
295
|
case IDLThisType: return "T";
|
|
296
|
+
case IDLBigintType:
|
|
294
297
|
case IDLPointerType: return "number|bigint";
|
|
295
298
|
default: throw new Error(`Unknown primitive type ${DebugUtils.debugPrintType(type)}`);
|
|
296
299
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as webidl2 from "webidl2";
|
|
2
2
|
import * as idl from "../idl";
|
|
3
|
-
import * as lib from "../library";
|
|
4
3
|
export declare function addSyntheticType(name: string, type: idl.IDLEntry): void;
|
|
5
4
|
export declare function resolveSyntheticType(type: idl.IDLReferenceType): idl.IDLEntry | undefined;
|
|
6
5
|
export declare function toIDLNode(file: string, node: webidl2.IDLRootType): idl.IDLEntry;
|
|
7
6
|
export declare function toIDL(file: string): idl.IDLEntry[];
|
|
8
|
-
export declare function toIDLFile(fileName: string):
|
|
7
|
+
export declare function toIDLFile(fileName: string): idl.IDLFile;
|
|
9
8
|
//# sourceMappingURL=deserialize.d.ts.map
|
|
@@ -29,9 +29,7 @@ export function resolveSyntheticType(type) {
|
|
|
29
29
|
return syntheticTypes.get(type.name);
|
|
30
30
|
}
|
|
31
31
|
export function toIDLNode(file, node) {
|
|
32
|
-
|
|
33
|
-
idl.linkNamespacesBack(result);
|
|
34
|
-
return result;
|
|
32
|
+
return toIDLNodeForward(file, node);
|
|
35
33
|
}
|
|
36
34
|
function toIDLNodeForward(file, node) {
|
|
37
35
|
if (isEnum(node)) {
|
|
@@ -88,11 +86,15 @@ function isCallable(node) {
|
|
|
88
86
|
return node.extAttrs.some(it => it.name == "Invoke");
|
|
89
87
|
}
|
|
90
88
|
function toIDLPackage(node) {
|
|
91
|
-
|
|
89
|
+
if (node.clause.startsWith('"')) { // TODO: remove after new schema formation
|
|
90
|
+
//node.clause = node.clause.substring(1, node.clause.length - 1)
|
|
91
|
+
throw new Error("Obsolete IDL-source syntax detected");
|
|
92
|
+
}
|
|
93
|
+
return idl.createPackage(node.clause.split("."));
|
|
92
94
|
}
|
|
93
95
|
function toIDLImport(node) {
|
|
94
96
|
// console.log(node)
|
|
95
|
-
return idl.createImport(node.
|
|
97
|
+
return idl.createImport(node.clause.split("."), node.alias || undefined);
|
|
96
98
|
}
|
|
97
99
|
function toIDLInterface(file, node) {
|
|
98
100
|
var _a;
|
|
@@ -373,12 +375,8 @@ export function toIDL(file) {
|
|
|
373
375
|
}
|
|
374
376
|
export function toIDLFile(fileName) {
|
|
375
377
|
const content = fs.readFileSync(fileName).toString();
|
|
376
|
-
const
|
|
377
|
-
const
|
|
378
|
-
return
|
|
379
|
-
fileName,
|
|
380
|
-
entities,
|
|
381
|
-
package: pack,
|
|
382
|
-
};
|
|
378
|
+
const entries = webidl2.parse(content).map(it => toIDLNode(fileName, it));
|
|
379
|
+
const file = idl.createFile(entries, fileName);
|
|
380
|
+
return idl.linkParentBack(file);
|
|
383
381
|
}
|
|
384
382
|
//# sourceMappingURL=deserialize.js.map
|
package/build/lib/src/idl.d.ts
CHANGED
|
@@ -21,7 +21,8 @@ export declare enum IDLKind {
|
|
|
21
21
|
TypeParameterType = 18,
|
|
22
22
|
OptionalType = 19,
|
|
23
23
|
Version = 20,
|
|
24
|
-
Namespace = 21
|
|
24
|
+
Namespace = 21,
|
|
25
|
+
File = 22
|
|
25
26
|
}
|
|
26
27
|
export declare enum IDLEntity {
|
|
27
28
|
Class = "Class",
|
|
@@ -75,10 +76,15 @@ export interface IDLExtendedAttribute {
|
|
|
75
76
|
export interface IDLNode {
|
|
76
77
|
_idlNodeBrand: any;
|
|
77
78
|
kind: IDLKind;
|
|
79
|
+
parent?: IDLNode;
|
|
78
80
|
fileName?: string;
|
|
79
81
|
extendedAttributes?: IDLExtendedAttribute[];
|
|
80
82
|
documentation?: string;
|
|
81
83
|
}
|
|
84
|
+
export interface IDLFile extends IDLNode {
|
|
85
|
+
entries: IDLEntry[];
|
|
86
|
+
fileName?: string;
|
|
87
|
+
}
|
|
82
88
|
export interface IDLNamedNode extends IDLNode {
|
|
83
89
|
_idlNamedNodeBrand: any;
|
|
84
90
|
name: string;
|
|
@@ -86,7 +92,6 @@ export interface IDLNamedNode extends IDLNode {
|
|
|
86
92
|
export interface IDLEntry extends IDLNode, IDLNamedNode {
|
|
87
93
|
_idlEntryBrand: any;
|
|
88
94
|
comment?: string;
|
|
89
|
-
namespace?: IDLNamespace;
|
|
90
95
|
}
|
|
91
96
|
export interface IDLType extends IDLNode {
|
|
92
97
|
_idlTypeBrand: any;
|
|
@@ -112,7 +117,6 @@ export interface IDLContainerType extends IDLType {
|
|
|
112
117
|
export interface IDLReferenceType extends IDLType, IDLNamedNode {
|
|
113
118
|
kind: IDLKind.ReferenceType;
|
|
114
119
|
typeArguments?: IDLType[];
|
|
115
|
-
namespace?: IDLNamespace;
|
|
116
120
|
}
|
|
117
121
|
export interface IDLUnspecifiedGenericType extends IDLType, IDLNamedNode {
|
|
118
122
|
kind: IDLKind.UnspecifiedGenericType;
|
|
@@ -204,10 +208,11 @@ export interface IDLInterface extends IDLEntry {
|
|
|
204
208
|
}
|
|
205
209
|
export interface IDLPackage extends IDLEntry {
|
|
206
210
|
kind: IDLKind.Package;
|
|
211
|
+
clause: string[];
|
|
207
212
|
}
|
|
208
213
|
export interface IDLImport extends IDLEntry {
|
|
209
214
|
kind: IDLKind.Import;
|
|
210
|
-
|
|
215
|
+
clause: string[];
|
|
211
216
|
}
|
|
212
217
|
export interface IDLNamespace extends IDLEntry {
|
|
213
218
|
kind: IDLKind.Namespace;
|
|
@@ -220,6 +225,7 @@ export interface IDLCallback extends IDLEntry, IDLSignature {
|
|
|
220
225
|
export declare function forEachChild(node: IDLNode, cbEnter: (entry: IDLNode) => void, cbLeave?: (entry: IDLNode) => void): void;
|
|
221
226
|
export declare function isNamedNode(type: IDLNode): type is IDLNamedNode;
|
|
222
227
|
export declare function forceAsNamedNode(type: IDLNode): IDLNamedNode;
|
|
228
|
+
export declare function isFile(node: IDLNode): node is IDLFile;
|
|
223
229
|
export declare function isUndefinedType(type: IDLNode): type is IDLPrimitiveType;
|
|
224
230
|
export declare function isVoidType(type: IDLNode): type is IDLPrimitiveType;
|
|
225
231
|
export declare function isPrimitiveType(type: IDLNode): type is IDLPrimitiveType;
|
|
@@ -294,21 +300,25 @@ export type IDLNodeInitializer = {
|
|
|
294
300
|
documentation?: string;
|
|
295
301
|
};
|
|
296
302
|
export declare function createNamespace(name: string, extendedAttributes?: IDLExtendedAttribute[], fileName?: string): IDLNamespace;
|
|
297
|
-
export declare function
|
|
303
|
+
export declare function linkParentBack<T extends IDLNode>(node: T): T;
|
|
298
304
|
export declare function getNamespacesPathFor(entry: IDLEntry): IDLNamespace[];
|
|
305
|
+
export declare function getFileFor(entry: IDLNode): IDLFile | undefined;
|
|
299
306
|
export declare function isEqualByQualifedName(a?: IDLEntry, b?: IDLEntry): boolean;
|
|
307
|
+
export declare function getPackageClause(entry: IDLFile | IDLEntry): string[];
|
|
308
|
+
export declare function getPackageName(entry: IDLFile | IDLEntry): string;
|
|
300
309
|
export declare function getNamespaceName(a: IDLEntry): string;
|
|
301
310
|
export declare function getFQName(a: IDLEntry): string;
|
|
302
311
|
export declare function createVersion(value: string[], extendedAttributes?: IDLExtendedAttribute[], fileName?: string): IDLVersion;
|
|
303
312
|
export declare function fetchNamespaceFrom(pointOfView?: IDLNode): IDLNamespace | undefined;
|
|
304
|
-
export declare function createReferenceType(name: string, typeArguments?: IDLType[]
|
|
313
|
+
export declare function createReferenceType(name: string, typeArguments?: IDLType[]): IDLReferenceType;
|
|
305
314
|
export declare function createReferenceType(source: IDLEntry, typeArguments?: IDLType[]): IDLReferenceType;
|
|
306
315
|
export declare function createUnspecifiedGenericType(name: string, typeArguments: IDLType[]): IDLUnspecifiedGenericType;
|
|
307
316
|
export declare function entityToType(entity: IDLNode): IDLType;
|
|
308
317
|
export declare function createContainerType(container: IDLContainerKind, element: IDLType[]): IDLContainerType;
|
|
309
318
|
export declare function createUnionType(types: IDLType[], name?: string): IDLUnionType;
|
|
310
|
-
export declare function
|
|
311
|
-
export declare function
|
|
319
|
+
export declare function createFile(entries: IDLEntry[], fileName?: string): IDLFile;
|
|
320
|
+
export declare function createPackage(clause: string[]): IDLPackage;
|
|
321
|
+
export declare function createImport(clause: string[], name?: string, nodeInitializer?: IDLNodeInitializer): IDLImport;
|
|
312
322
|
export declare function createEnum(name: string, elements: IDLEnumMember[], nodeInitializer: IDLNodeInitializer): IDLEnum;
|
|
313
323
|
export declare function createEnumMember(name: string, parent: IDLEnum, type: IDLPrimitiveType, initializer: number | string | undefined, nodeInitializer?: IDLNodeInitializer): IDLEnumMember;
|
|
314
324
|
export declare function createInterface(name: string, subkind: IDLInterfaceSubkind, inheritance?: IDLReferenceType[], constructors?: IDLConstructor[], constants?: IDLConstant[], properties?: IDLProperty[], methods?: IDLMethod[], callables?: IDLCallable[], typeParameters?: string[], nodeInitializer?: IDLNodeInitializer): IDLInterface;
|
package/build/lib/src/idl.js
CHANGED
|
@@ -40,6 +40,7 @@ export var IDLKind;
|
|
|
40
40
|
IDLKind[IDLKind["OptionalType"] = 19] = "OptionalType";
|
|
41
41
|
IDLKind[IDLKind["Version"] = 20] = "Version";
|
|
42
42
|
IDLKind[IDLKind["Namespace"] = 21] = "Namespace";
|
|
43
|
+
IDLKind[IDLKind["File"] = 22] = "File";
|
|
43
44
|
})(IDLKind || (IDLKind = {}));
|
|
44
45
|
export var IDLEntity;
|
|
45
46
|
(function (IDLEntity) {
|
|
@@ -101,6 +102,9 @@ export function forEachChild(node, cbEnter, cbLeave) {
|
|
|
101
102
|
var _a, _b;
|
|
102
103
|
cbEnter(node);
|
|
103
104
|
switch (node.kind) {
|
|
105
|
+
case IDLKind.File:
|
|
106
|
+
node.entries.forEach((value) => forEachChild(value, cbEnter, cbLeave));
|
|
107
|
+
break;
|
|
104
108
|
case IDLKind.Namespace:
|
|
105
109
|
node.members.forEach((value) => forEachChild(value, cbEnter, cbLeave));
|
|
106
110
|
break;
|
|
@@ -187,6 +191,9 @@ export function forceAsNamedNode(type) {
|
|
|
187
191
|
}
|
|
188
192
|
return type;
|
|
189
193
|
}
|
|
194
|
+
export function isFile(node) {
|
|
195
|
+
return node.kind === IDLKind.File;
|
|
196
|
+
}
|
|
190
197
|
export function isUndefinedType(type) {
|
|
191
198
|
return isPrimitiveType(type) && type.name === IDLUndefinedType.name;
|
|
192
199
|
}
|
|
@@ -346,29 +353,41 @@ export function createNamespace(name, extendedAttributes, fileName) {
|
|
|
346
353
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
347
354
|
};
|
|
348
355
|
}
|
|
349
|
-
export function
|
|
350
|
-
|
|
351
|
-
forEachChild(node,
|
|
352
|
-
if (
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
356
|
+
export function linkParentBack(node) {
|
|
357
|
+
const parentStack = [];
|
|
358
|
+
forEachChild(node, (node) => {
|
|
359
|
+
if (isPrimitiveType(node))
|
|
360
|
+
return;
|
|
361
|
+
if (parentStack.length)
|
|
362
|
+
node.parent = parentStack[parentStack.length - 1];
|
|
363
|
+
parentStack.push(node);
|
|
364
|
+
}, (node) => {
|
|
365
|
+
if (isPrimitiveType(node))
|
|
366
|
+
return;
|
|
367
|
+
parentStack.pop();
|
|
361
368
|
});
|
|
369
|
+
return node;
|
|
362
370
|
}
|
|
363
371
|
export function getNamespacesPathFor(entry) {
|
|
364
|
-
let iterator = entry.
|
|
372
|
+
let iterator = entry.parent;
|
|
365
373
|
const result = [];
|
|
366
374
|
while (iterator) {
|
|
367
|
-
|
|
368
|
-
|
|
375
|
+
if (isNamespace(iterator))
|
|
376
|
+
result.unshift(iterator);
|
|
377
|
+
iterator = iterator.parent;
|
|
369
378
|
}
|
|
370
379
|
return result;
|
|
371
380
|
}
|
|
381
|
+
export function getFileFor(entry) {
|
|
382
|
+
let iterator = entry;
|
|
383
|
+
while (iterator) {
|
|
384
|
+
if (isFile(iterator))
|
|
385
|
+
return iterator;
|
|
386
|
+
iterator = iterator.parent;
|
|
387
|
+
}
|
|
388
|
+
console.warn(`Entry ${JSON.stringify(entry)} does not have IDLFile in parents`);
|
|
389
|
+
return undefined;
|
|
390
|
+
}
|
|
372
391
|
export function isEqualByQualifedName(a, b) {
|
|
373
392
|
if (a === b)
|
|
374
393
|
return true;
|
|
@@ -376,17 +395,28 @@ export function isEqualByQualifedName(a, b) {
|
|
|
376
395
|
return false;
|
|
377
396
|
if (a.kind !== b.kind || a.name !== b.name)
|
|
378
397
|
return false;
|
|
379
|
-
return
|
|
398
|
+
return getFQName(a) === getFQName(b);
|
|
399
|
+
}
|
|
400
|
+
export function getPackageClause(entry) {
|
|
401
|
+
let file = getFileFor(entry);
|
|
402
|
+
if (!file)
|
|
403
|
+
return [];
|
|
404
|
+
for (const child of file.entries)
|
|
405
|
+
if (isPackage(child))
|
|
406
|
+
return child.clause;
|
|
407
|
+
// console.warn("Expected to have one IDLPackage inside IDLFile. Using empty package name")
|
|
408
|
+
return [];
|
|
409
|
+
}
|
|
410
|
+
export function getPackageName(entry) {
|
|
411
|
+
return getPackageClause(entry).join(".");
|
|
380
412
|
}
|
|
381
413
|
export function getNamespaceName(a) {
|
|
382
414
|
return getNamespacesPathFor(a).map(it => it.name).join('.');
|
|
383
415
|
}
|
|
384
416
|
export function getFQName(a) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
return ns + a.name;
|
|
417
|
+
// TODO package name is very dirty now, waiting for Alexander Rekunkov PR
|
|
418
|
+
// return [...getPackageClause(a), ...getNamespacesPathFor(a).map(it => it.name), a.name].join('.')
|
|
419
|
+
return [...getNamespacesPathFor(a).map(it => it.name), a.name].join('.');
|
|
390
420
|
}
|
|
391
421
|
export function createVersion(value, extendedAttributes, fileName) {
|
|
392
422
|
return {
|
|
@@ -401,30 +431,26 @@ export function createVersion(value, extendedAttributes, fileName) {
|
|
|
401
431
|
};
|
|
402
432
|
}
|
|
403
433
|
export function fetchNamespaceFrom(pointOfView) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
434
|
+
let node = pointOfView;
|
|
435
|
+
while (node) {
|
|
436
|
+
if (isNamespace(node))
|
|
437
|
+
return node;
|
|
438
|
+
node = node.parent;
|
|
409
439
|
}
|
|
410
440
|
return undefined;
|
|
411
441
|
}
|
|
412
|
-
export function createReferenceType(nameOrSource, typeArguments
|
|
442
|
+
export function createReferenceType(nameOrSource, typeArguments) {
|
|
413
443
|
let name;
|
|
414
|
-
let namespace;
|
|
415
444
|
if (typeof nameOrSource === 'string') {
|
|
416
445
|
name = nameOrSource;
|
|
417
|
-
namespace = fetchNamespaceFrom(pointOfView);
|
|
418
446
|
}
|
|
419
447
|
else {
|
|
420
|
-
name = nameOrSource
|
|
421
|
-
namespace = fetchNamespaceFrom(nameOrSource);
|
|
448
|
+
name = getFQName(nameOrSource);
|
|
422
449
|
}
|
|
423
450
|
return {
|
|
424
451
|
kind: IDLKind.ReferenceType,
|
|
425
452
|
name,
|
|
426
453
|
typeArguments,
|
|
427
|
-
namespace: namespace,
|
|
428
454
|
_idlNodeBrand: innerIdlSymbol,
|
|
429
455
|
_idlTypeBrand: innerIdlSymbol,
|
|
430
456
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
@@ -444,7 +470,12 @@ export function entityToType(entity) {
|
|
|
444
470
|
if (isType(entity)) {
|
|
445
471
|
return entity;
|
|
446
472
|
}
|
|
447
|
-
|
|
473
|
+
else if (isEntry(entity)) {
|
|
474
|
+
return createReferenceType(entity);
|
|
475
|
+
}
|
|
476
|
+
else {
|
|
477
|
+
throw new Error(`Expected to have IDLType or IDLEntry, got ${entity}`);
|
|
478
|
+
}
|
|
448
479
|
}
|
|
449
480
|
export function createContainerType(container, element) {
|
|
450
481
|
return {
|
|
@@ -467,17 +498,26 @@ export function createUnionType(types, name) {
|
|
|
467
498
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
468
499
|
};
|
|
469
500
|
}
|
|
470
|
-
export function
|
|
501
|
+
export function createFile(entries, fileName) {
|
|
502
|
+
return {
|
|
503
|
+
kind: IDLKind.File,
|
|
504
|
+
entries: entries,
|
|
505
|
+
fileName,
|
|
506
|
+
_idlNodeBrand: innerIdlSymbol,
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
export function createPackage(clause) {
|
|
471
510
|
return {
|
|
472
511
|
kind: IDLKind.Package,
|
|
473
|
-
name,
|
|
512
|
+
name: "",
|
|
513
|
+
clause,
|
|
474
514
|
_idlNodeBrand: innerIdlSymbol,
|
|
475
515
|
_idlEntryBrand: innerIdlSymbol,
|
|
476
516
|
_idlNamedNodeBrand: innerIdlSymbol,
|
|
477
517
|
};
|
|
478
518
|
}
|
|
479
|
-
export function createImport(
|
|
480
|
-
return Object.assign(Object.assign({ kind: IDLKind.Import, name,
|
|
519
|
+
export function createImport(clause, name, nodeInitializer) {
|
|
520
|
+
return Object.assign(Object.assign({ kind: IDLKind.Import, name: name || "", clause }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
481
521
|
}
|
|
482
522
|
export function createEnum(name, elements, nodeInitializer) {
|
|
483
523
|
return Object.assign(Object.assign({ kind: IDLKind.Enum, name: name, elements: elements }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
@@ -713,13 +753,15 @@ export function printMethod(idl) {
|
|
|
713
753
|
];
|
|
714
754
|
}
|
|
715
755
|
export function printPackage(idl) {
|
|
756
|
+
if (!idl.clause.length)
|
|
757
|
+
return [];
|
|
716
758
|
return [
|
|
717
|
-
`package
|
|
759
|
+
`package ${idl.clause.join(".")};`
|
|
718
760
|
];
|
|
719
761
|
}
|
|
720
762
|
export function printImport(idl) {
|
|
721
763
|
return [
|
|
722
|
-
`import "${idl.name}
|
|
764
|
+
`import ${idl.clause.join(".")}${idl.name ? " as " : ""}${idl.name};`
|
|
723
765
|
];
|
|
724
766
|
}
|
|
725
767
|
export function printNamespace(idl) {
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
|
-
import { GenerateOptions
|
|
3
|
-
export
|
|
2
|
+
import { GenerateOptions } from "./options";
|
|
3
|
+
export interface GenerateVisitor<T> {
|
|
4
|
+
visitPhase1(): T;
|
|
5
|
+
visitPhase2?(siblings: {
|
|
6
|
+
[key in string]: {
|
|
7
|
+
tsSourceFile: ts.SourceFile;
|
|
8
|
+
visitor: GenerateVisitor<T>;
|
|
9
|
+
result: T;
|
|
10
|
+
};
|
|
11
|
+
}): T;
|
|
12
|
+
}
|
|
13
|
+
export declare function generate<T>(inputDirs: string[], inputFiles: string[], outputDir: string, visitorFactory: (sourceFile: ts.SourceFile, program: ts.Program, compilerHost: ts.CompilerHost) => GenerateVisitor<T>, options: GenerateOptions<T>): void;
|
|
4
14
|
//# sourceMappingURL=idlize.d.ts.map
|
package/build/lib/src/idlize.js
CHANGED
|
@@ -62,7 +62,8 @@ export function generate(inputDirs, inputFiles, outputDir, visitorFactory, optio
|
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
input = Array.from(new Set(input.map(p => path.resolve(p)))).sort();
|
|
65
|
-
let
|
|
65
|
+
let compilerHost = ts.createCompilerHost(options.compilerOptions);
|
|
66
|
+
let program = ts.createProgram(input.concat([path.join(__dirname, "../stdlib.d.ts")]), options.compilerOptions, compilerHost);
|
|
66
67
|
if (options.enableLog) {
|
|
67
68
|
console.log("Initialized TypeScript program with input files:", input);
|
|
68
69
|
}
|
|
@@ -70,23 +71,37 @@ export function generate(inputDirs, inputFiles, outputDir, visitorFactory, optio
|
|
|
70
71
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
71
72
|
const typeChecker = program.getTypeChecker();
|
|
72
73
|
(_a = options.onBegin) === null || _a === void 0 ? void 0 : _a.call(options, outputDir, typeChecker);
|
|
74
|
+
const dtsFileName2Visitor = {};
|
|
73
75
|
for (const sourceFile of program.getSourceFiles()) {
|
|
74
|
-
const
|
|
75
|
-
const isInDir = resolvedInputDirs.some(dir =>
|
|
76
|
-
const isExplicitFile = input.some(f => path.resolve(f) ===
|
|
76
|
+
const resolvedSourceFileName = path.resolve(sourceFile.fileName);
|
|
77
|
+
const isInDir = resolvedInputDirs.some(dir => resolvedSourceFileName.startsWith(dir));
|
|
78
|
+
const isExplicitFile = input.some(f => path.resolve(f) === resolvedSourceFileName);
|
|
77
79
|
if (!isInDir && !isExplicitFile) {
|
|
78
80
|
if (options.enableLog) {
|
|
79
|
-
console.log(`Skipping file: ${
|
|
81
|
+
console.log(`Skipping file: ${resolvedSourceFileName}`);
|
|
80
82
|
}
|
|
81
83
|
continue;
|
|
82
84
|
}
|
|
83
85
|
if (options.enableLog) {
|
|
84
|
-
console.log(`Processing file: ${
|
|
86
|
+
console.log(`Processing file: ${resolvedSourceFileName}`);
|
|
85
87
|
}
|
|
86
88
|
// Walk the tree to search for classes
|
|
87
|
-
const visitor = visitorFactory(sourceFile,
|
|
88
|
-
const
|
|
89
|
-
|
|
89
|
+
const visitor = visitorFactory(sourceFile, program, compilerHost);
|
|
90
|
+
const result = visitor.visitPhase1();
|
|
91
|
+
dtsFileName2Visitor[sourceFile.fileName] = {
|
|
92
|
+
tsSourceFile: sourceFile,
|
|
93
|
+
visitor,
|
|
94
|
+
result
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
for (const resolvedSourceFileName in dtsFileName2Visitor) {
|
|
98
|
+
const visitorStaff = dtsFileName2Visitor[resolvedSourceFileName];
|
|
99
|
+
if (visitorStaff.visitor.visitPhase2)
|
|
100
|
+
visitorStaff.result = visitorStaff.visitor.visitPhase2(dtsFileName2Visitor);
|
|
101
|
+
}
|
|
102
|
+
for (const resolvedSourceFileName in dtsFileName2Visitor) {
|
|
103
|
+
const visitorStaff = dtsFileName2Visitor[resolvedSourceFileName];
|
|
104
|
+
(_b = options.onSingleFile) === null || _b === void 0 ? void 0 : _b.call(options, visitorStaff.result, outputDir, visitorStaff.tsSourceFile);
|
|
90
105
|
}
|
|
91
106
|
(_c = options.onEnd) === null || _c === void 0 ? void 0 : _c.call(options, outputDir);
|
|
92
107
|
if (options.enableLog) {
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
import * as idl from './idl';
|
|
2
2
|
export interface IDLLibrary {
|
|
3
|
-
readonly files: readonly IDLFile[];
|
|
3
|
+
readonly files: readonly idl.IDLFile[];
|
|
4
4
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
package?: idl.IDLPackage;
|
|
8
|
-
entities: idl.IDLNode[];
|
|
9
|
-
}
|
|
10
|
-
declare function createLibrary(files: IDLFile[]): IDLLibrary;
|
|
11
|
-
declare function toLibrary(ii: Iterable<IDLFile>): IDLLibrary;
|
|
5
|
+
declare function createLibrary(files: idl.IDLFile[]): IDLLibrary;
|
|
6
|
+
declare function toLibrary(ii: Iterable<idl.IDLFile>): IDLLibrary;
|
|
12
7
|
declare function serializeParam(params: unknown): string;
|
|
13
8
|
export interface LibraryQuery<A, R> {
|
|
14
9
|
fn: (x: A) => R;
|
|
@@ -44,8 +39,8 @@ export declare const lib: {
|
|
|
44
39
|
lens: typeof lens;
|
|
45
40
|
query: typeof query;
|
|
46
41
|
select: {
|
|
47
|
-
files(): LibraryReducer<readonly IDLFile[]>;
|
|
48
|
-
nodes(params: EntitiesParams): LibraryQuery<readonly IDLFile[], idl.IDLNode[]>;
|
|
42
|
+
files(): LibraryReducer<readonly idl.IDLFile[]>;
|
|
43
|
+
nodes(params: EntitiesParams): LibraryQuery<readonly idl.IDLFile[], idl.IDLNode[]>;
|
|
49
44
|
entries(): LibraryQuery<idl.IDLNode[], idl.IDLEntry[]>;
|
|
50
45
|
interfaces(): LibraryQuery<idl.IDLNode[], idl.IDLInterface[]>;
|
|
51
46
|
hasExt<T extends idl.IDLNode>(attr: idl.IDLExtendedAttributes): LibraryQuery<T[], T[]>;
|
package/build/lib/src/library.js
CHANGED
|
@@ -148,7 +148,7 @@ const select = {
|
|
|
148
148
|
return [node];
|
|
149
149
|
}
|
|
150
150
|
return req(key, xs => {
|
|
151
|
-
return xs.flatMap(x => x.
|
|
151
|
+
return xs.flatMap(x => x.entries).flatMap(go);
|
|
152
152
|
});
|
|
153
153
|
},
|
|
154
154
|
entries() {
|
|
@@ -166,7 +166,7 @@ const select = {
|
|
|
166
166
|
name(name) {
|
|
167
167
|
return reduce(`select.by.name.${name}`, lib => {
|
|
168
168
|
return lib.files.flatMap(it => {
|
|
169
|
-
return it.
|
|
169
|
+
return it.entries.flatMap(it => {
|
|
170
170
|
if (idl.isNamedNode(it) && it.name === name) {
|
|
171
171
|
return [it];
|
|
172
172
|
}
|
|
@@ -2,13 +2,14 @@ import * as idl from '../idl';
|
|
|
2
2
|
import { PeerClass } from "./PeerClass";
|
|
3
3
|
import { LibraryFileInterface } from '../LibraryInterface';
|
|
4
4
|
export declare class PeerFile implements LibraryFileInterface {
|
|
5
|
-
readonly
|
|
6
|
-
readonly entries: idl.IDLEntry[];
|
|
5
|
+
readonly file: idl.IDLFile;
|
|
7
6
|
readonly isPredefined: boolean;
|
|
8
7
|
readonly peers: Map<string, PeerClass>;
|
|
9
|
-
constructor(
|
|
8
|
+
constructor(file: idl.IDLFile, isPredefined?: boolean);
|
|
10
9
|
packageName(): string;
|
|
11
10
|
package(): idl.IDLPackage | undefined;
|
|
12
11
|
get peersToGenerate(): PeerClass[];
|
|
12
|
+
get entries(): idl.IDLEntry[];
|
|
13
|
+
get originalFilename(): string;
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=PeerFile.d.ts.map
|
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import * as idl from '../idl';
|
|
16
16
|
export class PeerFile {
|
|
17
|
-
constructor(
|
|
18
|
-
this.
|
|
19
|
-
this.entries = entries;
|
|
17
|
+
constructor(file, isPredefined = false) {
|
|
18
|
+
this.file = file;
|
|
20
19
|
this.isPredefined = isPredefined;
|
|
21
20
|
this.peers = new Map();
|
|
22
21
|
}
|
|
@@ -37,5 +36,13 @@ export class PeerFile {
|
|
|
37
36
|
const peers = Array.from(this.peers.values());
|
|
38
37
|
return peers;
|
|
39
38
|
}
|
|
39
|
+
// TODO just to not refactor too much in one PR
|
|
40
|
+
get entries() {
|
|
41
|
+
return this.file.entries;
|
|
42
|
+
}
|
|
43
|
+
// TODO just to not refactor too much in one PR
|
|
44
|
+
get originalFilename() {
|
|
45
|
+
return this.file.fileName;
|
|
46
|
+
}
|
|
40
47
|
}
|
|
41
48
|
//# sourceMappingURL=PeerFile.js.map
|
|
@@ -10254,10 +10254,8 @@ export declare class PeerLibrary implements LibraryInterface {
|
|
|
10254
10254
|
asIDLLibrary(): IDLLibrary;
|
|
10255
10255
|
get globalScopeInterfaces(): idl.IDLInterface[];
|
|
10256
10256
|
layout: LayoutManager;
|
|
10257
|
-
private
|
|
10258
|
-
|
|
10259
|
-
get syntheticEntries(): idl.IDLEntry[];
|
|
10260
|
-
initSyntheticEntries(entries: idl.IDLEntry[]): void;
|
|
10257
|
+
private _syntheticFile;
|
|
10258
|
+
initSyntheticEntries(file: idl.IDLFile): void;
|
|
10261
10259
|
readonly files: PeerFile[];
|
|
10262
10260
|
readonly builderClasses: Map<string, BuilderClass>;
|
|
10263
10261
|
get buildersToGenerate(): BuilderClass[];
|
|
@@ -10279,8 +10277,8 @@ export declare class PeerLibrary implements LibraryInterface {
|
|
|
10279
10277
|
setCurrentContext(context: string | undefined): void;
|
|
10280
10278
|
findFileByOriginalFilename(filename: string): PeerFile | undefined;
|
|
10281
10279
|
mapType(type: idl.IDLType): string;
|
|
10282
|
-
resolveTypeReference(type: idl.IDLReferenceType
|
|
10283
|
-
|
|
10280
|
+
resolveTypeReference(type: idl.IDLReferenceType): idl.IDLEntry | undefined;
|
|
10281
|
+
private resolveTypeReferenceScoped;
|
|
10284
10282
|
hasInLibrary(entry: idl.IDLEntry): boolean;
|
|
10285
10283
|
typeConvertor(param: string, type: idl.IDLType, isOptionalParam?: boolean): ArgConvertor;
|
|
10286
10284
|
declarationConvertor(param: string, type: idl.IDLReferenceType, declaration: idl.IDLEntry | undefined): ArgConvertor;
|
|
@@ -40,21 +40,13 @@ export class PeerLibrary {
|
|
|
40
40
|
return this._cachedIdlLibrary;
|
|
41
41
|
}
|
|
42
42
|
this._cachedIdlLibrary = {
|
|
43
|
-
files: this.files.map(file =>
|
|
44
|
-
fileName: file.originalFilename,
|
|
45
|
-
entities: file.entries,
|
|
46
|
-
package: file.package()
|
|
47
|
-
}))
|
|
43
|
+
files: this.files.map(file => file.file)
|
|
48
44
|
};
|
|
49
45
|
return this._cachedIdlLibrary;
|
|
50
46
|
}
|
|
51
47
|
get globalScopeInterfaces() { return query(this.asIDLLibrary(), lenses.globals); }
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return this._syntheticEntries;
|
|
55
|
-
}
|
|
56
|
-
initSyntheticEntries(entries) {
|
|
57
|
-
this._syntheticEntries = entries;
|
|
48
|
+
initSyntheticEntries(file) {
|
|
49
|
+
this._syntheticFile = file;
|
|
58
50
|
}
|
|
59
51
|
get buildersToGenerate() {
|
|
60
52
|
return Array.from(this.builderClasses.values()).filter(it => it.needBeGenerated);
|
|
@@ -66,7 +58,7 @@ export class PeerLibrary {
|
|
|
66
58
|
this.language = language;
|
|
67
59
|
this.libraryPackages = libraryPackages;
|
|
68
60
|
this.layout = LayoutManager.Empty();
|
|
69
|
-
this.
|
|
61
|
+
this._syntheticFile = idl.createFile([]);
|
|
70
62
|
this.files = [];
|
|
71
63
|
this.builderClasses = new Map();
|
|
72
64
|
this.materializedClasses = new Map();
|
|
@@ -110,7 +102,7 @@ export class PeerLibrary {
|
|
|
110
102
|
createContinuationCallbackReference(continuationType) {
|
|
111
103
|
const continuationParameters = this.createContinuationParameters(continuationType);
|
|
112
104
|
const syntheticName = generateSyntheticFunctionName(continuationParameters, idl.IDLVoidType);
|
|
113
|
-
return idl.createReferenceType(syntheticName
|
|
105
|
+
return idl.createReferenceType(syntheticName);
|
|
114
106
|
}
|
|
115
107
|
getCurrentContext() {
|
|
116
108
|
return this.context;
|
|
@@ -124,15 +116,15 @@ export class PeerLibrary {
|
|
|
124
116
|
mapType(type) {
|
|
125
117
|
return this.targetNameConvertorInstance.convert(type);
|
|
126
118
|
}
|
|
127
|
-
resolveTypeReference(type
|
|
128
|
-
|
|
119
|
+
resolveTypeReference(type) {
|
|
120
|
+
return this.resolveTypeReferenceScoped(type);
|
|
121
|
+
}
|
|
122
|
+
resolveTypeReferenceScoped(type, pointOfView, rootEntries) {
|
|
123
|
+
const entry = this._syntheticFile.entries.find(it => it.name === type.name);
|
|
129
124
|
if (entry)
|
|
130
125
|
return entry;
|
|
131
126
|
const qualifiedName = type.name.split(".");
|
|
132
|
-
|
|
133
|
-
let pointOfViewNamespace = !pointOfView || idl.isNamespace(pointOfView)
|
|
134
|
-
? pointOfView
|
|
135
|
-
: pointOfView.namespace;
|
|
127
|
+
let pointOfViewNamespace = idl.fetchNamespaceFrom(type.parent);
|
|
136
128
|
rootEntries !== null && rootEntries !== void 0 ? rootEntries : (rootEntries = this.files.flatMap(it => it.entries));
|
|
137
129
|
if (1 === qualifiedName.length) {
|
|
138
130
|
const predefined = rootEntries.filter(it => idl.hasExtAttribute(it, idl.IDLExtendedAttributes.Predefined));
|
|
@@ -152,9 +144,12 @@ export class PeerLibrary {
|
|
|
152
144
|
if (!candidates.length)
|
|
153
145
|
break;
|
|
154
146
|
if (qualifiedNamePart === qualifiedName.length - 1) {
|
|
155
|
-
|
|
147
|
+
const target = candidates.length == 1
|
|
156
148
|
? candidates[0]
|
|
157
149
|
: candidates.find(it => !idl.hasExtAttribute(it, idl.IDLExtendedAttributes.Import)); // probably the wrong logic here
|
|
150
|
+
if (target && idl.isImport(target)) // Temporary disable Import declarations
|
|
151
|
+
return undefined;
|
|
152
|
+
return target;
|
|
158
153
|
}
|
|
159
154
|
entries = [];
|
|
160
155
|
for (const candidate of candidates) {
|
|
@@ -166,7 +161,7 @@ export class PeerLibrary {
|
|
|
166
161
|
entries.push(...candidate.constants, ...candidate.properties, ...candidate.methods);
|
|
167
162
|
}
|
|
168
163
|
}
|
|
169
|
-
pointOfViewNamespace = pointOfViewNamespace === null || pointOfViewNamespace === void 0 ? void 0 : pointOfViewNamespace.
|
|
164
|
+
pointOfViewNamespace = idl.fetchNamespaceFrom(pointOfViewNamespace === null || pointOfViewNamespace === void 0 ? void 0 : pointOfViewNamespace.parent);
|
|
170
165
|
}
|
|
171
166
|
// TODO: remove the next block after namespaces out of quarantine
|
|
172
167
|
if (!pointOfView) {
|
|
@@ -174,7 +169,7 @@ export class PeerLibrary {
|
|
|
174
169
|
const traverseNamespaces = (entry) => {
|
|
175
170
|
if (entry && idl.isNamespace(entry) && entry.members.length) {
|
|
176
171
|
//console.log(`Try alien namespace '${idl.getNamespacesPathFor(entry.members[0]).map(obj => obj.name).join(".")}' to resolve name '${type.name}'`)
|
|
177
|
-
const resolved = this.
|
|
172
|
+
const resolved = this.resolveTypeReferenceScoped(type, entry, rootEntries);
|
|
178
173
|
if (resolved)
|
|
179
174
|
resolveds.push(resolved);
|
|
180
175
|
entry.members.forEach(traverseNamespaces);
|
|
@@ -186,22 +181,9 @@ export class PeerLibrary {
|
|
|
186
181
|
} // end of block to remove
|
|
187
182
|
return undefined; // empty result
|
|
188
183
|
}
|
|
189
|
-
resolvePackageName(entry) {
|
|
190
|
-
var _a;
|
|
191
|
-
if (this._syntheticEntries.includes(entry))
|
|
192
|
-
return ((_a = this.libraryPackages) === null || _a === void 0 ? void 0 : _a.length) ? this.libraryPackages[0] : this.files[0].packageName();
|
|
193
|
-
while (entry.namespace) {
|
|
194
|
-
entry = entry.namespace;
|
|
195
|
-
}
|
|
196
|
-
for (const file of this.files) {
|
|
197
|
-
if (file.entries.includes(entry))
|
|
198
|
-
return file.packageName();
|
|
199
|
-
}
|
|
200
|
-
throw new Error(`Package name for entry ${entry.name} was not found`);
|
|
201
|
-
}
|
|
202
184
|
hasInLibrary(entry) {
|
|
203
185
|
var _a, _b;
|
|
204
|
-
return !((_a = this.libraryPackages) === null || _a === void 0 ? void 0 : _a.length) || ((_b = this.libraryPackages) === null || _b === void 0 ? void 0 : _b.includes(
|
|
186
|
+
return !((_a = this.libraryPackages) === null || _a === void 0 ? void 0 : _a.length) || ((_b = this.libraryPackages) === null || _b === void 0 ? void 0 : _b.includes(idl.getPackageName(entry)));
|
|
205
187
|
}
|
|
206
188
|
typeConvertor(param, type, isOptionalParam = false) {
|
|
207
189
|
if (isOptionalParam) {
|
|
@@ -39,9 +39,9 @@ export function qualifiedName(decl, languageOrDelimiter) {
|
|
|
39
39
|
const delimiter = typeof languageOrDelimiter === "string"
|
|
40
40
|
? languageOrDelimiter
|
|
41
41
|
: (languageOrDelimiter === Language.CPP ? '_' : '.');
|
|
42
|
-
if (idl.isEntry(decl)
|
|
43
|
-
|
|
44
|
-
return idl.
|
|
42
|
+
if (!idl.isEntry(decl))
|
|
43
|
+
throw new Error(`Expected to have an IDLEntry, got ${idl.IDLKind[decl.kind]}`);
|
|
44
|
+
return idl.getFQName(decl).split(".").join(delimiter);
|
|
45
45
|
}
|
|
46
46
|
export function collapseTypes(types, name) {
|
|
47
47
|
const seenNames = new Set();
|
package/build/lib/src/util.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
|
+
import * as idl from "./idl";
|
|
2
3
|
import { Language } from './Language';
|
|
3
4
|
export interface NameWithType {
|
|
4
5
|
name?: ts.DeclarationName;
|
|
@@ -80,4 +81,5 @@ export declare class Lazy<T> {
|
|
|
80
81
|
get value(): T;
|
|
81
82
|
}
|
|
82
83
|
export declare function lazy<T>(factory: () => T): Lazy<T>;
|
|
84
|
+
export declare function isInNamespace(node: idl.IDLEntry): boolean;
|
|
83
85
|
//# sourceMappingURL=util.d.ts.map
|
package/build/lib/src/util.js
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import * as path from 'path';
|
|
16
16
|
import * as fs from "fs";
|
|
17
17
|
import * as ts from "typescript";
|
|
18
|
+
import * as idl from "./idl";
|
|
18
19
|
import { Language } from './Language';
|
|
19
20
|
/** True if this is visible outside this file, false otherwise */
|
|
20
21
|
export function isNodePublic(node) {
|
|
@@ -635,4 +636,7 @@ export class Lazy {
|
|
|
635
636
|
export function lazy(factory) {
|
|
636
637
|
return new Lazy(factory);
|
|
637
638
|
}
|
|
639
|
+
export function isInNamespace(node) {
|
|
640
|
+
return idl.getNamespacesPathFor(node).length > 0;
|
|
641
|
+
}
|
|
638
642
|
//# sourceMappingURL=util.js.map
|
package/build/lib/src/visitor.js
CHANGED
|
@@ -103,7 +103,7 @@ export class IDLDependencyCollector {
|
|
|
103
103
|
}
|
|
104
104
|
visitSupertype(type) {
|
|
105
105
|
if (idl.isInterface(type)) {
|
|
106
|
-
return this.walk(idl.createReferenceType(type
|
|
106
|
+
return this.walk(idl.createReferenceType(type));
|
|
107
107
|
}
|
|
108
108
|
return this.walk(type);
|
|
109
109
|
}
|
package/package.json
CHANGED
|
@@ -2073,32 +2073,35 @@ class Import extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
|
|
|
2073
2073
|
return;
|
|
2074
2074
|
}
|
|
2075
2075
|
const tokens = { import: importKeyword };
|
|
2076
|
-
tokens.
|
|
2076
|
+
tokens.clause =
|
|
2077
2077
|
tokeniser.consumeKind("string") ||
|
|
2078
|
+
tokeniser.consumeKind("identifier") ||
|
|
2078
2079
|
tokeniser.error("Incomplete import statement");
|
|
2080
|
+
tokens.as = tokeniser.consume("as");
|
|
2081
|
+
if (tokens.as)
|
|
2082
|
+
tokens.alias =
|
|
2083
|
+
tokeniser.consumeKind("identifier") ||
|
|
2084
|
+
tokeniser.error("Incomplete import statement");
|
|
2079
2085
|
tokens.termination =
|
|
2080
2086
|
tokeniser.consume(";") ||
|
|
2081
2087
|
tokeniser.error("No terminating ; for import statement");
|
|
2082
2088
|
const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.autoParenter)(new Import({ source: tokeniser.source, tokens }));
|
|
2083
|
-
ret.
|
|
2089
|
+
ret.clause = tokens.clause.value;
|
|
2090
|
+
ret.alias = tokens.alias?.value;
|
|
2084
2091
|
return ret.this;
|
|
2085
2092
|
}
|
|
2086
2093
|
|
|
2087
2094
|
get type() {
|
|
2088
2095
|
return "import";
|
|
2089
2096
|
}
|
|
2090
|
-
get target() {
|
|
2091
|
-
return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(this.tokens.target.value);
|
|
2092
|
-
}
|
|
2093
|
-
get import() {
|
|
2094
|
-
return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(this.tokens.importName.value);
|
|
2095
|
-
}
|
|
2096
2097
|
|
|
2097
2098
|
write(w) {
|
|
2098
2099
|
return w.ts.definition(
|
|
2099
2100
|
w.ts.wrap([
|
|
2100
2101
|
w.token(this.tokens.import),
|
|
2101
|
-
w.reference_token(this.tokens.
|
|
2102
|
+
w.reference_token(this.tokens.clause, this),
|
|
2103
|
+
w.token(this.tokens.as),
|
|
2104
|
+
w.token(this.tokens.alias),
|
|
2102
2105
|
w.token(this.tokens.termination),
|
|
2103
2106
|
]),
|
|
2104
2107
|
{ data: this },
|
|
@@ -2838,27 +2841,26 @@ class Package extends _base_js__WEBPACK_IMPORTED_MODULE_0__.Base {
|
|
|
2838
2841
|
return;
|
|
2839
2842
|
}
|
|
2840
2843
|
const tokens = { base: packageKeyword };
|
|
2841
|
-
tokens.
|
|
2842
|
-
tokeniser.consumeKind("string") ||
|
|
2844
|
+
tokens.clause =
|
|
2845
|
+
tokeniser.consumeKind("string") ||
|
|
2846
|
+
tokeniser.consumeKind("identifier") ||
|
|
2847
|
+
tokeniser.error("No clause for package");
|
|
2843
2848
|
tokens.termination =
|
|
2844
2849
|
tokeniser.consume(";") || tokeniser.error("No semicolon after package");
|
|
2845
2850
|
const ret = (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.autoParenter)(new Package({ source: tokeniser.source, tokens }));
|
|
2846
|
-
ret.
|
|
2851
|
+
ret.clause = tokens.clause.value;
|
|
2847
2852
|
return ret.this;
|
|
2848
2853
|
}
|
|
2849
2854
|
|
|
2850
2855
|
get type() {
|
|
2851
2856
|
return "package";
|
|
2852
2857
|
}
|
|
2853
|
-
get name() {
|
|
2854
|
-
return (0,_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(this.tokens.name.value);
|
|
2855
|
-
}
|
|
2856
2858
|
|
|
2857
2859
|
write(w) {
|
|
2858
2860
|
return w.ts.definition(
|
|
2859
2861
|
w.ts.wrap([
|
|
2860
2862
|
w.token(this.tokens.base),
|
|
2861
|
-
w.reference_token(this.tokens.
|
|
2863
|
+
w.reference_token(this.tokens.clause, this),
|
|
2862
2864
|
w.token(this.tokens.termination),
|
|
2863
2865
|
]),
|
|
2864
2866
|
{ data: this },
|
|
@@ -3640,6 +3642,7 @@ const argumentNameKeywords = [
|
|
|
3640
3642
|
"unrestricted",
|
|
3641
3643
|
"package",
|
|
3642
3644
|
"import",
|
|
3645
|
+
"as",
|
|
3643
3646
|
"version",
|
|
3644
3647
|
];
|
|
3645
3648
|
|
|
@@ -3733,9 +3736,7 @@ function tokenise(str) {
|
|
|
3733
3736
|
const token = tokens[lastIndex];
|
|
3734
3737
|
if (result !== -1) {
|
|
3735
3738
|
if (reserved.includes(token.value)) {
|
|
3736
|
-
const message = `${(0,_productions_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(
|
|
3737
|
-
token.value,
|
|
3738
|
-
)} is a reserved identifier and must not be used.`;
|
|
3739
|
+
const message = `${(0,_productions_helpers_js__WEBPACK_IMPORTED_MODULE_1__.unescape)(token.value)} is a reserved identifier and must not be used.`;
|
|
3739
3740
|
throw new WebIDLParseError(
|
|
3740
3741
|
(0,_error_js__WEBPACK_IMPORTED_MODULE_0__.syntaxError)(tokens, lastIndex, null, message),
|
|
3741
3742
|
);
|