@idlizer/core 2.1.10-arktscgen-3a → 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.
Files changed (35) hide show
  1. package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +12 -0
  2. package/build/lib/src/LanguageWriters/ArgConvertors.js +55 -3
  3. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +9 -1
  4. package/build/lib/src/LanguageWriters/LanguageWriter.js +10 -4
  5. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +1 -1
  6. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +2 -0
  7. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +11 -15
  8. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +0 -3
  9. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +3 -0
  10. package/build/lib/src/config.d.ts +760 -0
  11. package/build/lib/src/config.js +7 -0
  12. package/build/lib/src/formatter.js +5 -2
  13. package/build/lib/src/from-idl/DtsPrinter.js +2 -2
  14. package/build/lib/src/from-idl/common.js +2 -2
  15. package/build/lib/src/from-idl/deserialize.d.ts +3 -7
  16. package/build/lib/src/from-idl/deserialize.js +64 -38
  17. package/build/lib/src/from-idl/parser.d.ts +1 -1
  18. package/build/lib/src/from-idl/parser.js +29 -20
  19. package/build/lib/src/idl.d.ts +7 -1
  20. package/build/lib/src/idl.js +54 -10
  21. package/build/lib/src/index.d.ts +2 -1
  22. package/build/lib/src/index.js +2 -1
  23. package/build/lib/src/languageSpecificKeywords.js +1 -1
  24. package/build/lib/src/peer-generation/PeerLibrary.js +10 -1
  25. package/build/lib/src/peer-generation/isMaterialized.js +1 -1
  26. package/build/lib/src/peer-generation/modules.d.ts +2 -0
  27. package/build/lib/src/peer-generation/modules.js +14 -1
  28. package/build/lib/src/transformers/GenericTransformer.js +70 -5
  29. package/build/lib/src/transformers/NullTransformer.d.ts +0 -1
  30. package/build/lib/src/transformers/NullTransformer.js +1 -2
  31. package/build/lib/src/transformers/OnSerializeTransformer.d.ts +3 -0
  32. package/build/lib/src/transformers/OnSerializeTransformer.js +19 -0
  33. package/build/lib/src/util.d.ts +5 -0
  34. package/build/lib/src/util.js +13 -2
  35. package/package.json +5 -5
@@ -87,11 +87,13 @@ export var IDLExtendedAttributes;
87
87
  IDLExtendedAttributes["TypeAnnotations"] = "TypeAnnotations";
88
88
  IDLExtendedAttributes["TypeArguments"] = "TypeArguments";
89
89
  IDLExtendedAttributes["TypeParameters"] = "TypeParameters";
90
+ IDLExtendedAttributes["TypeParametersDefaults"] = "TypeParametersDefaults";
90
91
  IDLExtendedAttributes["VerbatimDts"] = "VerbatimDts";
91
92
  IDLExtendedAttributes["HandWrittenImplementation"] = "HandWrittenImplementation";
92
93
  IDLExtendedAttributes["ExtraMethod"] = "ExtraMethod";
93
94
  IDLExtendedAttributes["OverloadAlias"] = "OverloadAlias";
94
95
  IDLExtendedAttributes["OverloadPriority"] = "OverloadPriority";
96
+ IDLExtendedAttributes["TransformOnSerialize"] = "TransformOnSerialize";
95
97
  })(IDLExtendedAttributes || (IDLExtendedAttributes = {}));
96
98
  export var IDLAccessorAttribute;
97
99
  (function (IDLAccessorAttribute) {
@@ -443,6 +445,7 @@ export const IDLSerializerBuffer = createPrimitiveType('SerializerBuffer');
443
445
  export const IDLFunctionType = createPrimitiveType('Function');
444
446
  export const IDLCustomObjectType = createPrimitiveType('CustomObject');
445
447
  export const IDLInteropReturnBufferType = createPrimitiveType('InteropReturnBuffer');
448
+ export const IDLNullTypeName = "idlize.stdlib.Null";
446
449
  export function createNamespace(name, members, nodeInitializer) {
447
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 });
448
451
  }
@@ -872,23 +875,29 @@ export function unescapeKeyword(name) {
872
875
  const printedIndentInc = "[[indent-inc]]";
873
876
  const printedIndentDec = "[[indent-dec]]";
874
877
  export function printType(type, options) {
878
+ var _a;
875
879
  if (!type)
876
880
  throw new Error("Missing type");
877
881
  if (isInterface(type))
878
882
  return type.name;
879
- if (isOptionalType(type))
880
- return `(${printType(type.type)} or ${IDLUndefinedType.name})`;
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
+ }
881
891
  if (isPrimitiveType(type))
882
892
  return type.name;
883
893
  if (isContainerType(type))
884
894
  return `${type.containerKind}<${type.elementType.map(it => printType(it)).join(", ")}>`;
885
895
  if (isReferenceType(type)) {
886
- const extAttrs = type.extendedAttributes ? Array.from(type.extendedAttributes) : [];
887
896
  if (type.typeArguments)
888
- extAttrs.push({ name: IDLExtendedAttributes.TypeArguments, value: type.typeArguments.map(it => printType(it)).join(",") });
889
- if (!extAttrs.length)
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))
890
899
  return type.name;
891
- let res = `[${quoteAttributeValues(extAttrs)}] ${type.name}`;
900
+ let res = `[${quoteAttributeValues(type.extendedAttributes)}] ${type.name}`;
892
901
  if (options === null || options === void 0 ? void 0 : options.bracketsAroundReferenceTypeWithExtAttrs)
893
902
  return `(${res})`;
894
903
  return res;
@@ -958,18 +967,31 @@ export function printExtendedAttributes(idl, indentLevel) {
958
967
  break;
959
968
  }
960
969
  const attributes = Array.from(idl.extendedAttributes || []);
961
- 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))
962
971
  attributes.push({ name: IDLExtendedAttributes.TypeParameters, value: typeParameters.join(",") });
963
- 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))
964
973
  attributes.push({ name: IDLExtendedAttributes.TypeArguments, value: typeArguments.map(it => printType(it)).join(",") });
965
974
  if (idl.documentation) {
966
975
  let docs = {
967
976
  name: IDLExtendedAttributes.Documentation,
968
977
  value: idl.documentation
969
978
  };
970
- attributes.push(docs);
979
+ attributes.unshift(docs);
971
980
  }
972
- const attrSpec = quoteAttributeValues(attributes);
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);
973
995
  return attrSpec ? [`[${attrSpec}]`] : [];
974
996
  }
975
997
  export const attributesToQuote = new Set([
@@ -981,6 +1003,7 @@ export const attributesToQuote = new Set([
981
1003
  IDLExtendedAttributes.TraceKey,
982
1004
  IDLExtendedAttributes.TypeArguments,
983
1005
  IDLExtendedAttributes.TypeParameters,
1006
+ IDLExtendedAttributes.TypeParametersDefaults,
984
1007
  ]);
985
1008
  function quoteAttributeValues(attributes) {
986
1009
  return attributes === null || attributes === void 0 ? void 0 : attributes.map(it => {
@@ -1181,6 +1204,17 @@ export function getExtAttribute(node, name) {
1181
1204
  var _a, _b;
1182
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;
1183
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
+ }
1184
1218
  export function getVerbatimDts(node) {
1185
1219
  let value = getExtAttribute(node, IDLExtendedAttributes.VerbatimDts);
1186
1220
  return value ? value.substring(1, value.length - 1) : undefined;
@@ -1203,6 +1237,16 @@ export function decomposeQualifiedName(type) {
1203
1237
  }
1204
1238
  return [undefined, typeName];
1205
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
+ }
1206
1250
  export function maybeUnwrapOptionalType(type) {
1207
1251
  if (isOptionalType(type)) {
1208
1252
  return type.type;
@@ -52,13 +52,14 @@ export * from "./peer-generation/getSuperType";
52
52
  export * from "./transformers/FqnTransformer";
53
53
  export * from "./transformers/GenericTransformer";
54
54
  export * from "./transformers/NullTransformer";
55
+ export * from "./transformers/OnSerializeTransformer";
55
56
  export * from "./LanguageWriters";
56
57
  export * from "./peer-generation/ReferenceResolver";
57
58
  export * from "./peer-generation/idl/common";
58
59
  export * from "./from-idl/IDLLinter";
59
60
  export { fromIDL, scanIDL } from "./from-idl/common";
60
61
  export { idlToDtsString, CustomPrintVisitor } from "./from-idl/DtsPrinter";
61
- export { toIDLFile, addSyntheticType, resolveSyntheticType, IDLTokenInfoMap } from "./from-idl/deserialize";
62
+ export { parseIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
62
63
  export { Parser, FatalParserException } from "./from-idl/parser";
63
64
  export { D, ConfigTypeInfer, ConfigSchema, inspectSchema } from './configDescriber';
64
65
  //# sourceMappingURL=index.d.ts.map
@@ -66,13 +66,14 @@ export * from "./peer-generation/getSuperType";
66
66
  export * from "./transformers/FqnTransformer";
67
67
  export * from "./transformers/GenericTransformer";
68
68
  export * from "./transformers/NullTransformer";
69
+ export * from "./transformers/OnSerializeTransformer";
69
70
  export * from "./LanguageWriters";
70
71
  export * from "./peer-generation/ReferenceResolver";
71
72
  export * from "./peer-generation/idl/common";
72
73
  export * from "./from-idl/IDLLinter";
73
74
  export { fromIDL, scanIDL } from "./from-idl/common";
74
75
  export { idlToDtsString, CustomPrintVisitor } from "./from-idl/DtsPrinter";
75
- export { toIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
76
+ export { parseIDLFile, addSyntheticType, resolveSyntheticType } from "./from-idl/deserialize";
76
77
  export { Parser, FatalParserException } from "./from-idl/parser";
77
78
  export { D, inspectSchema } from './configDescriber';
78
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
- /*'false', */ 'static', 'public', 'private',
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())
@@ -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
  }
@@ -463,6 +468,10 @@ export class PeerLibrary {
463
468
  warn(`Cyclic typedef: ${idl.DebugUtils.debugPrintType(type)}`);
464
469
  return ArkCustomObject;
465
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
+ }
466
475
  return !decl ? ArkCustomObject // assume some builtin type
467
476
  : idl.isTypedef(decl) ? this.toDeclaration(decl.type)
468
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.includes(declaration.name)) {
28
+ if (generatorConfiguration().forceMaterialized.some(r => r === idl.getFQName(declaration))) {
29
29
  return true;
30
30
  }
31
31
  // TODO: rework this
@@ -16,4 +16,6 @@ export declare function getModuleFor(packageName: string): ModuleConfiguration;
16
16
  export declare function currentModule(): ModuleConfiguration;
17
17
  export declare function isInCurrentModule(node: idl.IDLNode): boolean;
18
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;
19
21
  //# sourceMappingURL=modules.d.ts.map
@@ -1,5 +1,12 @@
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();
4
11
  /**
5
12
  * Is source submodule of target.
@@ -39,7 +46,7 @@ function getApplicableModuleFor(packageName) {
39
46
  if (applicableModules.length === 0) {
40
47
  if (packageName === '') {
41
48
  console.error("WARNING: use current module for empty package");
42
- return currentModule();
49
+ return stdlibModule;
43
50
  }
44
51
  if (packageName.startsWith(`idlize.`)) {
45
52
  return currentModule();
@@ -66,4 +73,10 @@ export function isInCurrentModule(nodeOrPackage) {
66
73
  : getModuleFor(nodeOrPackage);
67
74
  return generatorConfiguration().moduleName == module.name;
68
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
+ }
69
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
@@ -1,4 +1,3 @@
1
1
  import * as idl from "../idl";
2
- export declare const NULL_REFERENCE = "idlize.stdlib.Null";
3
2
  export declare function inplaceNullsAsUndefined(node: idl.IDLNode): void;
4
3
  //# sourceMappingURL=NullTransformer.d.ts.map
@@ -1,6 +1,5 @@
1
1
  import * as idl from "../idl";
2
2
  import { generateSyntheticUnionName } from "../peer-generation/idl/common";
3
- export const NULL_REFERENCE = "idlize.stdlib.Null";
4
3
  export function inplaceNullsAsUndefined(node) {
5
4
  idl.updateEachChild(node, (child) => {
6
5
  var _a;
@@ -29,6 +28,6 @@ export function inplaceNullsAsUndefined(node) {
29
28
  });
30
29
  }
31
30
  function isNullReference(node) {
32
- return idl.isReferenceType(node) && node.name === NULL_REFERENCE;
31
+ return idl.isReferenceType(node) && node.name === idl.IDLNullTypeName;
33
32
  }
34
33
  //# sourceMappingURL=NullTransformer.js.map
@@ -0,0 +1,3 @@
1
+ import * as idl from "../idl";
2
+ export declare function inplaceTransformOnSerializeFromConfig(node: idl.IDLNode): void;
3
+ //# sourceMappingURL=OnSerializeTransformer.d.ts.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
@@ -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
@@ -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-3a",
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
- "@koalaui/interop": "1.7.10",
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",