@idlizer/core 2.1.10-arktscgen-3 → 2.1.10-arktscgen-4
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 +14 -2
- package/build/lib/src/LanguageWriters/ArgConvertors.js +60 -8
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +11 -3
- package/build/lib/src/LanguageWriters/LanguageWriter.js +11 -5
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +1 -1
- package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +9 -1
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +3 -1
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +12 -16
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.d.ts +1 -1
- package/build/lib/src/LanguageWriters/writers/CppLanguageWriter.js +1 -1
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +0 -3
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +2 -2
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +15 -2
- package/build/lib/src/config.d.ts +760 -0
- package/build/lib/src/config.js +7 -0
- package/build/lib/src/formatter.js +5 -2
- package/build/lib/src/from-idl/DtsPrinter.js +2 -2
- package/build/lib/src/from-idl/common.js +2 -2
- package/build/lib/src/from-idl/deserialize.d.ts +3 -7
- package/build/lib/src/from-idl/deserialize.js +64 -38
- package/build/lib/src/from-idl/parser.d.ts +1 -1
- package/build/lib/src/from-idl/parser.js +29 -20
- package/build/lib/src/idl.d.ts +9 -1
- package/build/lib/src/idl.js +56 -10
- package/build/lib/src/index.d.ts +3 -1
- package/build/lib/src/index.js +3 -1
- package/build/lib/src/languageSpecificKeywords.js +1 -1
- package/build/lib/src/peer-generation/PeerLibrary.js +14 -4
- package/build/lib/src/peer-generation/isMaterialized.js +1 -1
- package/build/lib/src/peer-generation/modules.d.ts +10 -0
- package/build/lib/src/peer-generation/modules.js +27 -2
- package/build/lib/src/transformers/GenericTransformer.js +70 -5
- package/build/lib/src/transformers/NullTransformer.d.ts +3 -0
- package/build/lib/src/transformers/NullTransformer.js +33 -0
- package/build/lib/src/transformers/OnSerializeTransformer.d.ts +3 -0
- package/build/lib/src/transformers/OnSerializeTransformer.js +19 -0
- package/build/lib/src/util.d.ts +5 -0
- package/build/lib/src/util.js +13 -2
- package/package.json +5 -5
package/build/lib/src/idl.js
CHANGED
|
@@ -74,6 +74,8 @@ export var IDLExtendedAttributes;
|
|
|
74
74
|
IDLExtendedAttributes["Interfaces"] = "Interfaces";
|
|
75
75
|
IDLExtendedAttributes["NativeModule"] = "NativeModule";
|
|
76
76
|
IDLExtendedAttributes["Optional"] = "Optional";
|
|
77
|
+
IDLExtendedAttributes["UnionOnlyNull"] = "OptionalOnlyNull";
|
|
78
|
+
IDLExtendedAttributes["UnionWithNull"] = "OptionalWithNull";
|
|
77
79
|
IDLExtendedAttributes["OriginalEnumMemberName"] = "OriginalEnumMemberName";
|
|
78
80
|
IDLExtendedAttributes["OriginalGenericName"] = "OriginalGenericName";
|
|
79
81
|
IDLExtendedAttributes["Predefined"] = "Predefined";
|
|
@@ -85,11 +87,13 @@ export var IDLExtendedAttributes;
|
|
|
85
87
|
IDLExtendedAttributes["TypeAnnotations"] = "TypeAnnotations";
|
|
86
88
|
IDLExtendedAttributes["TypeArguments"] = "TypeArguments";
|
|
87
89
|
IDLExtendedAttributes["TypeParameters"] = "TypeParameters";
|
|
90
|
+
IDLExtendedAttributes["TypeParametersDefaults"] = "TypeParametersDefaults";
|
|
88
91
|
IDLExtendedAttributes["VerbatimDts"] = "VerbatimDts";
|
|
89
92
|
IDLExtendedAttributes["HandWrittenImplementation"] = "HandWrittenImplementation";
|
|
90
93
|
IDLExtendedAttributes["ExtraMethod"] = "ExtraMethod";
|
|
91
94
|
IDLExtendedAttributes["OverloadAlias"] = "OverloadAlias";
|
|
92
95
|
IDLExtendedAttributes["OverloadPriority"] = "OverloadPriority";
|
|
96
|
+
IDLExtendedAttributes["TransformOnSerialize"] = "TransformOnSerialize";
|
|
93
97
|
})(IDLExtendedAttributes || (IDLExtendedAttributes = {}));
|
|
94
98
|
export var IDLAccessorAttribute;
|
|
95
99
|
(function (IDLAccessorAttribute) {
|
|
@@ -441,6 +445,7 @@ export const IDLSerializerBuffer = createPrimitiveType('SerializerBuffer');
|
|
|
441
445
|
export const IDLFunctionType = createPrimitiveType('Function');
|
|
442
446
|
export const IDLCustomObjectType = createPrimitiveType('CustomObject');
|
|
443
447
|
export const IDLInteropReturnBufferType = createPrimitiveType('InteropReturnBuffer');
|
|
448
|
+
export const IDLNullTypeName = "idlize.stdlib.Null";
|
|
444
449
|
export function createNamespace(name, members, nodeInitializer) {
|
|
445
450
|
return Object.assign(Object.assign({ kind: IDLKind.Namespace, members: members !== null && members !== void 0 ? members : [], name: name }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
|
|
446
451
|
}
|
|
@@ -870,23 +875,29 @@ export function unescapeKeyword(name) {
|
|
|
870
875
|
const printedIndentInc = "[[indent-inc]]";
|
|
871
876
|
const printedIndentDec = "[[indent-dec]]";
|
|
872
877
|
export function printType(type, options) {
|
|
878
|
+
var _a;
|
|
873
879
|
if (!type)
|
|
874
880
|
throw new Error("Missing type");
|
|
875
881
|
if (isInterface(type))
|
|
876
882
|
return type.name;
|
|
877
|
-
if (isOptionalType(type))
|
|
878
|
-
|
|
883
|
+
if (isOptionalType(type)) {
|
|
884
|
+
if (hasExtAttribute(type, IDLExtendedAttributes.UnionOnlyNull))
|
|
885
|
+
return `(${printType(type.type)} or ${IDLNullTypeName})`;
|
|
886
|
+
else if (hasExtAttribute(type, IDLExtendedAttributes.UnionWithNull))
|
|
887
|
+
return `(${printType(type.type)} or ${IDLUndefinedType.name} or${IDLNullTypeName})`;
|
|
888
|
+
else
|
|
889
|
+
return `(${printType(type.type)} or ${IDLUndefinedType.name})`;
|
|
890
|
+
}
|
|
879
891
|
if (isPrimitiveType(type))
|
|
880
892
|
return type.name;
|
|
881
893
|
if (isContainerType(type))
|
|
882
894
|
return `${type.containerKind}<${type.elementType.map(it => printType(it)).join(", ")}>`;
|
|
883
895
|
if (isReferenceType(type)) {
|
|
884
|
-
const extAttrs = type.extendedAttributes ? Array.from(type.extendedAttributes) : [];
|
|
885
896
|
if (type.typeArguments)
|
|
886
|
-
|
|
887
|
-
if (!
|
|
897
|
+
updateExtAttribute(type, IDLExtendedAttributes.TypeArguments, type.typeArguments.map(it => printType(it)).join(","));
|
|
898
|
+
if (!((_a = type.extendedAttributes) === null || _a === void 0 ? void 0 : _a.length))
|
|
888
899
|
return type.name;
|
|
889
|
-
let res = `[${quoteAttributeValues(
|
|
900
|
+
let res = `[${quoteAttributeValues(type.extendedAttributes)}] ${type.name}`;
|
|
890
901
|
if (options === null || options === void 0 ? void 0 : options.bracketsAroundReferenceTypeWithExtAttrs)
|
|
891
902
|
return `(${res})`;
|
|
892
903
|
return res;
|
|
@@ -956,18 +967,31 @@ export function printExtendedAttributes(idl, indentLevel) {
|
|
|
956
967
|
break;
|
|
957
968
|
}
|
|
958
969
|
const attributes = Array.from(idl.extendedAttributes || []);
|
|
959
|
-
if (typeParameters === null || typeParameters === void 0 ? void 0 : typeParameters.length)
|
|
970
|
+
if ((typeParameters === null || typeParameters === void 0 ? void 0 : typeParameters.length) && !attributes.find(x => x.name === IDLExtendedAttributes.TypeParameters))
|
|
960
971
|
attributes.push({ name: IDLExtendedAttributes.TypeParameters, value: typeParameters.join(",") });
|
|
961
|
-
if (typeArguments === null || typeArguments === void 0 ? void 0 : typeArguments.length)
|
|
972
|
+
if ((typeArguments === null || typeArguments === void 0 ? void 0 : typeArguments.length) && !attributes.find(x => x.name === IDLExtendedAttributes.TypeArguments))
|
|
962
973
|
attributes.push({ name: IDLExtendedAttributes.TypeArguments, value: typeArguments.map(it => printType(it)).join(",") });
|
|
963
974
|
if (idl.documentation) {
|
|
964
975
|
let docs = {
|
|
965
976
|
name: IDLExtendedAttributes.Documentation,
|
|
966
977
|
value: idl.documentation
|
|
967
978
|
};
|
|
968
|
-
attributes.
|
|
979
|
+
attributes.unshift(docs);
|
|
969
980
|
}
|
|
970
|
-
|
|
981
|
+
// Deduplicate
|
|
982
|
+
const names = new Set();
|
|
983
|
+
const actualAttributes = [];
|
|
984
|
+
for (const attr of attributes) {
|
|
985
|
+
if (names.has(attr.name)) {
|
|
986
|
+
continue;
|
|
987
|
+
}
|
|
988
|
+
names.add(attr.name);
|
|
989
|
+
actualAttributes.push(attr);
|
|
990
|
+
}
|
|
991
|
+
if (actualAttributes.length == 0) {
|
|
992
|
+
return [];
|
|
993
|
+
}
|
|
994
|
+
const attrSpec = quoteAttributeValues(actualAttributes);
|
|
971
995
|
return attrSpec ? [`[${attrSpec}]`] : [];
|
|
972
996
|
}
|
|
973
997
|
export const attributesToQuote = new Set([
|
|
@@ -979,6 +1003,7 @@ export const attributesToQuote = new Set([
|
|
|
979
1003
|
IDLExtendedAttributes.TraceKey,
|
|
980
1004
|
IDLExtendedAttributes.TypeArguments,
|
|
981
1005
|
IDLExtendedAttributes.TypeParameters,
|
|
1006
|
+
IDLExtendedAttributes.TypeParametersDefaults,
|
|
982
1007
|
]);
|
|
983
1008
|
function quoteAttributeValues(attributes) {
|
|
984
1009
|
return attributes === null || attributes === void 0 ? void 0 : attributes.map(it => {
|
|
@@ -1179,6 +1204,17 @@ export function getExtAttribute(node, name) {
|
|
|
1179
1204
|
var _a, _b;
|
|
1180
1205
|
return (_b = (_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.find(it => it.name === name)) === null || _b === void 0 ? void 0 : _b.value;
|
|
1181
1206
|
}
|
|
1207
|
+
export function removeExtAttribute(node, name) {
|
|
1208
|
+
if (node.extendedAttributes) {
|
|
1209
|
+
node.extendedAttributes = node.extendedAttributes.filter(it => it.name !== name);
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
export function updateExtAttribute(node, name, value) {
|
|
1213
|
+
var _a;
|
|
1214
|
+
removeExtAttribute(node, name);
|
|
1215
|
+
(_a = node.extendedAttributes) !== null && _a !== void 0 ? _a : (node.extendedAttributes = []);
|
|
1216
|
+
node.extendedAttributes.push({ name, value });
|
|
1217
|
+
}
|
|
1182
1218
|
export function getVerbatimDts(node) {
|
|
1183
1219
|
let value = getExtAttribute(node, IDLExtendedAttributes.VerbatimDts);
|
|
1184
1220
|
return value ? value.substring(1, value.length - 1) : undefined;
|
|
@@ -1201,6 +1237,16 @@ export function decomposeQualifiedName(type) {
|
|
|
1201
1237
|
}
|
|
1202
1238
|
return [undefined, typeName];
|
|
1203
1239
|
}
|
|
1240
|
+
export function qualifiedNameStartsWith(node, template) {
|
|
1241
|
+
const name = Array.isArray(node) ? node : getFQName(node).split(".");
|
|
1242
|
+
if (name.length < template.length)
|
|
1243
|
+
return false;
|
|
1244
|
+
for (let i = 0; i < template.length; i++) {
|
|
1245
|
+
if (name[i] != template[i])
|
|
1246
|
+
return false;
|
|
1247
|
+
}
|
|
1248
|
+
return true;
|
|
1249
|
+
}
|
|
1204
1250
|
export function maybeUnwrapOptionalType(type) {
|
|
1205
1251
|
if (isOptionalType(type)) {
|
|
1206
1252
|
return type.type;
|
package/build/lib/src/index.d.ts
CHANGED
|
@@ -51,13 +51,15 @@ export * from "./peer-generation/unions";
|
|
|
51
51
|
export * from "./peer-generation/getSuperType";
|
|
52
52
|
export * from "./transformers/FqnTransformer";
|
|
53
53
|
export * from "./transformers/GenericTransformer";
|
|
54
|
+
export * from "./transformers/NullTransformer";
|
|
55
|
+
export * from "./transformers/OnSerializeTransformer";
|
|
54
56
|
export * from "./LanguageWriters";
|
|
55
57
|
export * from "./peer-generation/ReferenceResolver";
|
|
56
58
|
export * from "./peer-generation/idl/common";
|
|
57
59
|
export * from "./from-idl/IDLLinter";
|
|
58
60
|
export { fromIDL, scanIDL } from "./from-idl/common";
|
|
59
61
|
export { idlToDtsString, CustomPrintVisitor } from "./from-idl/DtsPrinter";
|
|
60
|
-
export {
|
|
62
|
+
export { parseIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
|
|
61
63
|
export { Parser, FatalParserException } from "./from-idl/parser";
|
|
62
64
|
export { D, ConfigTypeInfer, ConfigSchema, inspectSchema } from './configDescriber';
|
|
63
65
|
//# sourceMappingURL=index.d.ts.map
|
package/build/lib/src/index.js
CHANGED
|
@@ -65,13 +65,15 @@ export * from "./peer-generation/unions";
|
|
|
65
65
|
export * from "./peer-generation/getSuperType";
|
|
66
66
|
export * from "./transformers/FqnTransformer";
|
|
67
67
|
export * from "./transformers/GenericTransformer";
|
|
68
|
+
export * from "./transformers/NullTransformer";
|
|
69
|
+
export * from "./transformers/OnSerializeTransformer";
|
|
68
70
|
export * from "./LanguageWriters";
|
|
69
71
|
export * from "./peer-generation/ReferenceResolver";
|
|
70
72
|
export * from "./peer-generation/idl/common";
|
|
71
73
|
export * from "./from-idl/IDLLinter";
|
|
72
74
|
export { fromIDL, scanIDL } from "./from-idl/common";
|
|
73
75
|
export { idlToDtsString, CustomPrintVisitor } from "./from-idl/DtsPrinter";
|
|
74
|
-
export {
|
|
76
|
+
export { parseIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
|
|
75
77
|
export { Parser, FatalParserException } from "./from-idl/parser";
|
|
76
78
|
export { D, inspectSchema } from './configDescriber';
|
|
77
79
|
//# sourceMappingURL=index.js.map
|
|
@@ -35,7 +35,7 @@ export const CJKeywords = new Set([
|
|
|
35
35
|
'break', 'is', 'as', 'in', 'match',
|
|
36
36
|
'from', 'where', 'extend', 'spawn',
|
|
37
37
|
'synchronized', 'macro', 'quote', 'true',
|
|
38
|
-
|
|
38
|
+
'false', 'static', 'public', 'private',
|
|
39
39
|
'protected', 'override', 'redef', 'abstract',
|
|
40
40
|
'open', 'operator', 'foreign', 'inout',
|
|
41
41
|
'prop', 'mut', 'unsafe', 'get', 'set', 'type'
|
|
@@ -17,7 +17,7 @@ import * as idl from '../idl';
|
|
|
17
17
|
import { resolveNamedNode } from '../resolveNamedNode';
|
|
18
18
|
import { Language } from '../Language';
|
|
19
19
|
import { createLanguageWriter } from '../LanguageWriters';
|
|
20
|
-
import { BufferConvertor, CallbackConvertor, DateConvertor, MapConvertor, PointerConvertor, TupleConvertor, TypeAliasConvertor, AggregateConvertor, StringConvertor, ClassConvertor, ArrayConvertor, FunctionConvertor, OptionConvertor, NumberConvertor, NumericConvertor, CustomTypeConvertor, UnionConvertor, MaterializedClassConvertor, BooleanConvertor, EnumConvertor, UndefinedConvertor, VoidConvertor, ImportTypeConvertor, InterfaceConvertor, BigIntToU64Convertor, ObjectConvertor, } from "../LanguageWriters/ArgConvertors";
|
|
20
|
+
import { BufferConvertor, CallbackConvertor, DateConvertor, MapConvertor, PointerConvertor, TupleConvertor, TypeAliasConvertor, AggregateConvertor, StringConvertor, ClassConvertor, ArrayConvertor, FunctionConvertor, OptionConvertor, NumberConvertor, NumericConvertor, CustomTypeConvertor, UnionConvertor, MaterializedClassConvertor, BooleanConvertor, EnumConvertor, UndefinedConvertor, VoidConvertor, ImportTypeConvertor, InterfaceConvertor, BigIntToU64Convertor, ObjectConvertor, TransformOnSerializeConvertor, } from "../LanguageWriters/ArgConvertors";
|
|
21
21
|
import { CppNameConvertor } from '../LanguageWriters/convertors/CppConvertors';
|
|
22
22
|
import { CJTypeNameConvertor } from '../LanguageWriters/convertors/CJConvertors';
|
|
23
23
|
import { CppConvertor } from '../LanguageWriters/convertors/CppConvertors';
|
|
@@ -33,6 +33,7 @@ import { isInIdlizeInternal } from '../idlize';
|
|
|
33
33
|
import { isInCurrentModule } from './modules';
|
|
34
34
|
import { generatorConfiguration } from '../config';
|
|
35
35
|
import { KotlinTypeNameConvertor } from '../LanguageWriters/convertors/KotlinConvertors';
|
|
36
|
+
import { toIdlType } from '../from-idl/deserialize';
|
|
36
37
|
export const lenses = {
|
|
37
38
|
globals: lib.lens(lib.select.files())
|
|
38
39
|
.pipe(lib.select.nodes())
|
|
@@ -280,10 +281,10 @@ export class PeerLibrary {
|
|
|
280
281
|
}
|
|
281
282
|
typeConvertor(param, type, isOptionalParam = false) {
|
|
282
283
|
if (isOptionalParam) {
|
|
283
|
-
return new OptionConvertor(this, param, idl.
|
|
284
|
+
return new OptionConvertor(this, param, idl.isOptionalType(type) ? type : idl.createOptionalType(type));
|
|
284
285
|
}
|
|
285
286
|
if (idl.isOptionalType(type)) {
|
|
286
|
-
return new OptionConvertor(this, param, type
|
|
287
|
+
return new OptionConvertor(this, param, type);
|
|
287
288
|
}
|
|
288
289
|
if (idl.isPrimitiveType(type)) {
|
|
289
290
|
switch (type) {
|
|
@@ -374,6 +375,10 @@ export class PeerLibrary {
|
|
|
374
375
|
return new CustomTypeConvertor(param, declaration.name, false, declaration.name);
|
|
375
376
|
}
|
|
376
377
|
}
|
|
378
|
+
if (idl.hasExtAttribute(declaration, idl.IDLExtendedAttributes.TransformOnSerialize)) {
|
|
379
|
+
const targetRef = idl.createReferenceType(idl.getExtAttribute(declaration, idl.IDLExtendedAttributes.TransformOnSerialize));
|
|
380
|
+
return new TransformOnSerializeConvertor(param, this, declaration, targetRef);
|
|
381
|
+
}
|
|
377
382
|
if (idl.isEnum(declaration)) {
|
|
378
383
|
return new EnumConvertor(param, declaration);
|
|
379
384
|
}
|
|
@@ -420,7 +425,8 @@ export class PeerLibrary {
|
|
|
420
425
|
case `Record`:
|
|
421
426
|
return new CustomTypeConvertor(param, "Record", false, "Record<string, string>");
|
|
422
427
|
case `Optional`:
|
|
423
|
-
|
|
428
|
+
throw new Error("Not expected to have reference type named Optional");
|
|
429
|
+
// return new OptionConvertor(this, param, type.typeArguments![0])
|
|
424
430
|
}
|
|
425
431
|
return undefined;
|
|
426
432
|
}
|
|
@@ -462,6 +468,10 @@ export class PeerLibrary {
|
|
|
462
468
|
warn(`Cyclic typedef: ${idl.DebugUtils.debugPrintType(type)}`);
|
|
463
469
|
return ArkCustomObject;
|
|
464
470
|
}
|
|
471
|
+
if (decl && idl.hasExtAttribute(decl, idl.IDLExtendedAttributes.TransformOnSerialize)) {
|
|
472
|
+
const type = toIdlType("", idl.getExtAttribute(decl, idl.IDLExtendedAttributes.TransformOnSerialize));
|
|
473
|
+
return this.toDeclaration(type);
|
|
474
|
+
}
|
|
465
475
|
return !decl ? ArkCustomObject // assume some builtin type
|
|
466
476
|
: idl.isTypedef(decl) ? this.toDeclaration(decl.type)
|
|
467
477
|
: decl;
|
|
@@ -25,7 +25,7 @@ export function isMaterialized(declaration, resolver) {
|
|
|
25
25
|
if (generatorConfiguration().forceResource.includes(declaration.name)) {
|
|
26
26
|
return false;
|
|
27
27
|
}
|
|
28
|
-
if (generatorConfiguration().forceMaterialized.
|
|
28
|
+
if (generatorConfiguration().forceMaterialized.some(r => r === idl.getFQName(declaration))) {
|
|
29
29
|
return true;
|
|
30
30
|
}
|
|
31
31
|
// TODO: rework this
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { ModuleConfiguration } from "../config";
|
|
2
2
|
import * as idl from "../idl";
|
|
3
|
+
/**
|
|
4
|
+
* Is source submodule of target.
|
|
5
|
+
* Every source is submodule if target is empty string
|
|
6
|
+
* @example `isSubmodule("a.b.c", "a") === true`
|
|
7
|
+
* @example `isSubmodule("a", "a.b.c") === false`
|
|
8
|
+
* @example `isSubmodule("a.b.cd", "a.b.c") === false`
|
|
9
|
+
*/
|
|
10
|
+
export declare function isSubmodule(source: string, target: string): boolean;
|
|
3
11
|
export declare function isInModule(node: idl.IDLNode, module: ModuleConfiguration): boolean;
|
|
4
12
|
export declare function isInModule(packageName: string, module: ModuleConfiguration): boolean;
|
|
5
13
|
export declare function isInExternalModule(node: idl.IDLNode): boolean;
|
|
@@ -8,4 +16,6 @@ export declare function getModuleFor(packageName: string): ModuleConfiguration;
|
|
|
8
16
|
export declare function currentModule(): ModuleConfiguration;
|
|
9
17
|
export declare function isInCurrentModule(node: idl.IDLNode): boolean;
|
|
10
18
|
export declare function isInCurrentModule(packageName: string): boolean;
|
|
19
|
+
export declare function isInStdlibModule(node: idl.IDLNode): boolean;
|
|
20
|
+
export declare function isInStdlibModule(packageName: string): boolean;
|
|
11
21
|
//# sourceMappingURL=modules.d.ts.map
|
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
import { generatorConfiguration } from "../config";
|
|
2
2
|
import * as idl from "../idl";
|
|
3
|
+
const stdlibModule = {
|
|
4
|
+
name: "__stdlib",
|
|
5
|
+
packages: [""],
|
|
6
|
+
useFoldersLayout: false,
|
|
7
|
+
external: true,
|
|
8
|
+
tsLikePackage: "__stdlib"
|
|
9
|
+
};
|
|
3
10
|
const modulesCache = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* Is source submodule of target.
|
|
13
|
+
* Every source is submodule if target is empty string
|
|
14
|
+
* @example `isSubmodule("a.b.c", "a") === true`
|
|
15
|
+
* @example `isSubmodule("a", "a.b.c") === false`
|
|
16
|
+
* @example `isSubmodule("a.b.cd", "a.b.c") === false`
|
|
17
|
+
*/
|
|
18
|
+
export function isSubmodule(source, target) {
|
|
19
|
+
return source === target
|
|
20
|
+
|| target === ""
|
|
21
|
+
|| source.startsWith(target + '.');
|
|
22
|
+
}
|
|
4
23
|
export function isInModule(nodeOrPackage, module) {
|
|
5
24
|
if (typeof nodeOrPackage === 'object')
|
|
6
25
|
return isInModule(idl.getPackageName(nodeOrPackage), module);
|
|
7
|
-
return module.packages.some(modulePackage => nodeOrPackage
|
|
26
|
+
return module.packages.some(modulePackage => isSubmodule(nodeOrPackage, modulePackage));
|
|
8
27
|
}
|
|
9
28
|
export function isInExternalModule(node) {
|
|
10
29
|
var _a;
|
|
@@ -27,7 +46,7 @@ function getApplicableModuleFor(packageName) {
|
|
|
27
46
|
if (applicableModules.length === 0) {
|
|
28
47
|
if (packageName === '') {
|
|
29
48
|
console.error("WARNING: use current module for empty package");
|
|
30
|
-
return
|
|
49
|
+
return stdlibModule;
|
|
31
50
|
}
|
|
32
51
|
if (packageName.startsWith(`idlize.`)) {
|
|
33
52
|
return currentModule();
|
|
@@ -54,4 +73,10 @@ export function isInCurrentModule(nodeOrPackage) {
|
|
|
54
73
|
: getModuleFor(nodeOrPackage);
|
|
55
74
|
return generatorConfiguration().moduleName == module.name;
|
|
56
75
|
}
|
|
76
|
+
export function isInStdlibModule(nodeOrPackage) {
|
|
77
|
+
const module = typeof nodeOrPackage === 'string'
|
|
78
|
+
? getModuleFor(nodeOrPackage)
|
|
79
|
+
: getModuleFor(nodeOrPackage);
|
|
80
|
+
return stdlibModule.name == module.name;
|
|
81
|
+
}
|
|
57
82
|
//# sourceMappingURL=modules.js.map
|
|
@@ -12,12 +12,9 @@ export function inplaceGenerics(node, resolver, options) {
|
|
|
12
12
|
if (idl.isReferenceType(child))
|
|
13
13
|
candidates.push(child);
|
|
14
14
|
});
|
|
15
|
-
if (idl.isReferenceType(node)) {
|
|
16
|
-
candidates.push(node);
|
|
17
|
-
}
|
|
18
15
|
options !== null && options !== void 0 ? options : (options = {});
|
|
19
16
|
(_a = options.ignore) !== null && _a !== void 0 ? _a : (options.ignore = []);
|
|
20
|
-
options.ignore.push(ignoreConfigRule, ignoreBuilderClassRule, createIgnoreMaterializedRule(resolver));
|
|
17
|
+
options.ignore.push(ignoreConfigRule, ignoreBuilderClassRule, createIgnoreMaterializedRule(resolver), createIgnoreResourceRule(resolver));
|
|
21
18
|
candidates.forEach(it => inplaceReferenceGenerics(it, resolver, options));
|
|
22
19
|
}
|
|
23
20
|
export function isInplacedGeneric(entry) {
|
|
@@ -52,7 +49,19 @@ function ignoreBuilderClassRule(node) {
|
|
|
52
49
|
return idl.isInterface(node) && isBuilderClass(node);
|
|
53
50
|
}
|
|
54
51
|
function createIgnoreMaterializedRule(resolver) {
|
|
55
|
-
return (node) => idl.isInterface(node) && isMaterialized(node, resolver);
|
|
52
|
+
return (node) => idl.isInterface(node) && isMaterialized(node, resolver) && !idl.hasExtAttribute(node, idl.IDLExtendedAttributes.TransformOnSerialize);
|
|
53
|
+
}
|
|
54
|
+
function createIgnoreResourceRule(resolver) {
|
|
55
|
+
return (node) => {
|
|
56
|
+
if (!idl.isReferenceType(node)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const declaration = resolver.resolveTypeReference(node);
|
|
60
|
+
if (!declaration) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return generatorConfiguration().forceResource.includes(declaration.name);
|
|
64
|
+
};
|
|
56
65
|
}
|
|
57
66
|
function monomorphisedEntryName(typedEntry, typeArguments) {
|
|
58
67
|
return typedEntry.name + "_" + typeArguments.map(generateSyntheticIdlNodeName).join("_");
|
|
@@ -86,6 +95,7 @@ function monomorphizeEntry(typedEntry, typeArguments) {
|
|
|
86
95
|
name: idl.IDLExtendedAttributes.TypeArguments,
|
|
87
96
|
value: typeArguments.map(type => idl.printType(type)).join("|"),
|
|
88
97
|
});
|
|
98
|
+
inplaceRemoveMeaninglessFields(monomorphizedEntry);
|
|
89
99
|
return monomorphizedEntry;
|
|
90
100
|
}
|
|
91
101
|
function hasTypeParameterTypeChild(node) {
|
|
@@ -98,6 +108,7 @@ function hasTypeParameterTypeChild(node) {
|
|
|
98
108
|
}
|
|
99
109
|
function inplaceReferenceGenerics(ref, resolver, options) {
|
|
100
110
|
var _a, _b;
|
|
111
|
+
inplaceDefaultReferenceGenerics(ref, resolver);
|
|
101
112
|
if (!((_a = ref.typeArguments) === null || _a === void 0 ? void 0 : _a.length) || hasTypeParameterTypeChild(ref)) {
|
|
102
113
|
return;
|
|
103
114
|
}
|
|
@@ -117,6 +128,7 @@ function inplaceReferenceGenerics(ref, resolver, options) {
|
|
|
117
128
|
const monomorphizedEntry = monomorphizeEntry(resolved, ref.typeArguments);
|
|
118
129
|
insertEntryNearTo(monomorphizedEntry, resolved);
|
|
119
130
|
inplaceGenerics(monomorphizedEntry, resolver);
|
|
131
|
+
correctTransformOnSerialize(resolver, monomorphizedEntry, ref.typeArguments, options);
|
|
120
132
|
}
|
|
121
133
|
ref.name = inplacedRef.name;
|
|
122
134
|
ref.typeArguments = undefined;
|
|
@@ -138,4 +150,57 @@ function insertEntryNearTo(entry, anchor) {
|
|
|
138
150
|
parentEntries.splice(parentEntries.indexOf(anchor), 0, entry);
|
|
139
151
|
idl.linkParentBack(anchor.parent);
|
|
140
152
|
}
|
|
153
|
+
// when generic declaration has TransformOnSerialize attribute, for monomorphized entry we must update that attribute that will look
|
|
154
|
+
// at monomorphized TransformOnSerialize
|
|
155
|
+
function correctTransformOnSerialize(resolver, monomorphizedEntry, typeArguments, options) {
|
|
156
|
+
const targetName = idl.getExtAttribute(monomorphizedEntry, idl.IDLExtendedAttributes.TransformOnSerialize);
|
|
157
|
+
if (targetName === undefined) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const targetType = toIdlType("", targetName);
|
|
161
|
+
if (idl.isReferenceType(targetType)) {
|
|
162
|
+
targetType.typeArguments = typeArguments;
|
|
163
|
+
inplaceReferenceGenerics(targetType, resolver, options);
|
|
164
|
+
idl.updateExtAttribute(monomorphizedEntry, idl.IDLExtendedAttributes.TransformOnSerialize, targetType.name);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function inplaceDefaultReferenceGenerics(node, resolver) {
|
|
168
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
169
|
+
const decl = resolver.resolveTypeReference(node);
|
|
170
|
+
if (!decl) {
|
|
171
|
+
console.error(`Can not resolve reference for inplacing default generics ${node.name} in file ${(_a = node.fileName) !== null && _a !== void 0 ? _a : '<unknown>'}`);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (!idl.isTypedef(decl) && !idl.isInterface(decl) && !idl.isCallback(decl)) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (((_c = (_b = decl.typeParameters) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > ((_e = (_d = node.typeArguments) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0)) {
|
|
178
|
+
const defaults = (_h = (_g = (_f = decl.extendedAttributes) === null || _f === void 0 ? void 0 : _f.find(it => it.name === idl.IDLExtendedAttributes.TypeParametersDefaults)) === null || _g === void 0 ? void 0 : _g.typesValue) !== null && _h !== void 0 ? _h : [];
|
|
179
|
+
while (defaults.length < decl.typeParameters.length) {
|
|
180
|
+
defaults.unshift(undefined);
|
|
181
|
+
}
|
|
182
|
+
(_j = node.typeArguments) !== null && _j !== void 0 ? _j : (node.typeArguments = []);
|
|
183
|
+
while (decl.typeParameters.length > node.typeArguments.length) {
|
|
184
|
+
if (defaults[node.typeArguments.length] === undefined) {
|
|
185
|
+
throw new Error(`Can not validate reference to ${idl.getFQName(decl)} declaration: reference has not enough generic arguments or declaration does not have enough default generic values`);
|
|
186
|
+
}
|
|
187
|
+
node.typeArguments.push(defaults[node.typeArguments.length]);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function isMeaninglessFieldType(type) {
|
|
192
|
+
return type === idl.IDLVoidType || type === idl.IDLUndefinedType;
|
|
193
|
+
}
|
|
194
|
+
function inplaceRemoveMeaninglessFields(node, options = { recursive: true }) {
|
|
195
|
+
if (options.recursive) {
|
|
196
|
+
idl.forEachChild(node, child => inplaceRemoveMeaninglessFields(child, { recursive: false }));
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (idl.isInterface(node)) {
|
|
200
|
+
node.properties = node.properties.filter(it => !isMeaninglessFieldType(it.type));
|
|
201
|
+
}
|
|
202
|
+
if (idl.isMethod(node)) {
|
|
203
|
+
node.parameters = node.parameters.filter(it => !isMeaninglessFieldType(it.type));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
141
206
|
//# sourceMappingURL=GenericTransformer.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as idl from "../idl";
|
|
2
|
+
import { generateSyntheticUnionName } from "../peer-generation/idl/common";
|
|
3
|
+
export function inplaceNullsAsUndefined(node) {
|
|
4
|
+
idl.updateEachChild(node, (child) => {
|
|
5
|
+
var _a;
|
|
6
|
+
if (idl.isOptionalType(child)) {
|
|
7
|
+
if (idl.isUnionType(child.type) && child.type.types.some(isNullReference)) {
|
|
8
|
+
child.type.types = child.type.types.filter(it => !isNullReference(it));
|
|
9
|
+
child.type.name = generateSyntheticUnionName(child.type.types);
|
|
10
|
+
if (child.type.types.length === 1) {
|
|
11
|
+
child.type = child.type.types[0];
|
|
12
|
+
}
|
|
13
|
+
(_a = child.extendedAttributes) !== null && _a !== void 0 ? _a : (child.extendedAttributes = []);
|
|
14
|
+
child.extendedAttributes.push({ name: idl.IDLExtendedAttributes.UnionWithNull });
|
|
15
|
+
return child;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else if (idl.isUnionType(child)) {
|
|
19
|
+
if (child.types.some(isNullReference)) {
|
|
20
|
+
child.types = child.types.filter(it => !isNullReference(it));
|
|
21
|
+
child.name = generateSyntheticUnionName(child.types);
|
|
22
|
+
return idl.createOptionalType(child.types.length > 1 ? child : child.types[0], { extendedAttributes: [{
|
|
23
|
+
name: idl.IDLExtendedAttributes.UnionOnlyNull
|
|
24
|
+
}] });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return child;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function isNullReference(node) {
|
|
31
|
+
return idl.isReferenceType(node) && node.name === idl.IDLNullTypeName;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=NullTransformer.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { generatorConfiguration } from "../config";
|
|
2
|
+
import * as idl from "../idl";
|
|
3
|
+
export function inplaceTransformOnSerializeFromConfig(node) {
|
|
4
|
+
inplaceTransformOnSerializeSelf(node);
|
|
5
|
+
idl.updateEachChild(node, child => {
|
|
6
|
+
inplaceTransformOnSerializeSelf(child);
|
|
7
|
+
return child;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
function inplaceTransformOnSerializeSelf(node) {
|
|
11
|
+
if (!idl.isEntry(node)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const transformation = generatorConfiguration().transformOnSerialize.find(it => it.from === idl.getFQName(node));
|
|
15
|
+
if (transformation !== undefined) {
|
|
16
|
+
idl.updateExtAttribute(node, idl.IDLExtendedAttributes.TransformOnSerialize, transformation.to);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=OnSerializeTransformer.js.map
|
package/build/lib/src/util.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as ts from "typescript";
|
|
2
2
|
import * as idl from "./idl";
|
|
3
3
|
import { Language } from './Language';
|
|
4
|
+
import { LibraryInterface } from './LibraryInterface';
|
|
4
5
|
export interface NameWithType {
|
|
5
6
|
name?: ts.DeclarationName;
|
|
6
7
|
type?: ts.TypeNode;
|
|
@@ -95,5 +96,9 @@ export declare function getExtractor(target: idl.IDLInterface, lang: Language, t
|
|
|
95
96
|
receiver?: string;
|
|
96
97
|
method: string;
|
|
97
98
|
};
|
|
99
|
+
export declare function getTransformer(library: LibraryInterface, from: idl.IDLNode, to: idl.IDLNode): {
|
|
100
|
+
receiver?: string;
|
|
101
|
+
method: string;
|
|
102
|
+
};
|
|
98
103
|
export {};
|
|
99
104
|
//# sourceMappingURL=util.d.ts.map
|
package/build/lib/src/util.js
CHANGED
|
@@ -17,7 +17,7 @@ import * as fs from "fs";
|
|
|
17
17
|
import * as ts from "typescript";
|
|
18
18
|
import * as idl from "./idl";
|
|
19
19
|
import { Language } from './Language';
|
|
20
|
-
import { isInExternalModule } from './peer-generation/modules';
|
|
20
|
+
import { getModuleFor, isInExternalModule } from './peer-generation/modules';
|
|
21
21
|
import { getInternalClassName, getInternalClassQualifiedName } from './peer-generation/Materialized';
|
|
22
22
|
/** True if this is visible outside this file, false otherwise */
|
|
23
23
|
export function isNodePublic(node) {
|
|
@@ -693,8 +693,12 @@ export function sorted(array, key) {
|
|
|
693
693
|
}
|
|
694
694
|
export function mapLibraryName(node, lang, mapping, prefix = "@") {
|
|
695
695
|
var _a, _b;
|
|
696
|
+
const module = getModuleFor(node);
|
|
697
|
+
if (module.tsLikePackage !== undefined) {
|
|
698
|
+
return `^` + module.tsLikePackage;
|
|
699
|
+
}
|
|
696
700
|
const packageName = idl.getPackageName(node);
|
|
697
|
-
return (_b = (_a = mapping === null || mapping === void 0 ? void 0 : mapping.get(packageName)) === null || _a === void 0 ? void 0 : _a.get(lang.name)) !== null && _b !== void 0 ? _b : `${prefix}${packageName}
|
|
701
|
+
return `^` + ((_b = (_a = mapping === null || mapping === void 0 ? void 0 : mapping.get(packageName)) === null || _a === void 0 ? void 0 : _a.get(lang.name)) !== null && _b !== void 0 ? _b : `${prefix}${packageName}`);
|
|
698
702
|
}
|
|
699
703
|
function getExtractorClass(target, toPtr = true) {
|
|
700
704
|
if (isInExternalModule(target)) {
|
|
@@ -716,4 +720,11 @@ export function getExtractor(target, lang, toPtr = true) {
|
|
|
716
720
|
const method = toPtr ? `to${extractorClass}Ptr` : `from${extractorClass}Ptr`;
|
|
717
721
|
return { receiver, method };
|
|
718
722
|
}
|
|
723
|
+
export function getTransformer(library, from, to) {
|
|
724
|
+
const convertor = library.createTypeNameConvertor(Language.CPP);
|
|
725
|
+
return {
|
|
726
|
+
receiver: "extractors",
|
|
727
|
+
method: `transform_${convertor.convert(from)}_to_${convertor.convert(to)}`
|
|
728
|
+
};
|
|
729
|
+
}
|
|
719
730
|
//# sourceMappingURL=util.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idlizer/core",
|
|
3
|
-
"version": "2.1.10-arktscgen-
|
|
3
|
+
"version": "2.1.10-arktscgen-4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"types": "build/lib/src/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
},
|
|
34
34
|
"keywords": [],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"
|
|
37
|
-
"typescript": "4.9.5",
|
|
38
|
-
"@types/node": "^18.0.0"
|
|
36
|
+
"typescript": "4.9.5"
|
|
39
37
|
},
|
|
40
38
|
"devDependencies": {
|
|
41
39
|
"@koalaui/harness": "1.7.6+devel",
|
|
42
40
|
"@koalaui/ets-tsc": "4.9.5-r5",
|
|
43
41
|
"@types/mocha": "^9.1.0",
|
|
44
42
|
"mocha": "^9.2.2",
|
|
45
|
-
"ts-node": "^10.9.2"
|
|
43
|
+
"ts-node": "^10.9.2",
|
|
44
|
+
"@koalaui/interop": "1.7.9",
|
|
45
|
+
"@types/node": "^18.0.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"test": "mocha",
|