@idlizer/core 2.0.21 → 2.0.23

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.
@@ -21,15 +21,15 @@ export class CppInteropConvertor extends InteropConvertor {
21
21
  unwrap(type, result) {
22
22
  const conf = generatorConfiguration();
23
23
  if (idl.isType(type) && idl.isOptionalType(type)) {
24
- return `${conf.param("OptionalPrefix")}${result.text}`;
24
+ return `${conf.OptionalPrefix}${result.text}`;
25
25
  }
26
26
  if (result.noPrefix) {
27
27
  return result.text;
28
28
  }
29
- const typePrefix = conf.param("TypePrefix");
29
+ const typePrefix = conf.TypePrefix;
30
30
  // TODO remove this ugly hack for CustomObject's
31
31
  const convertedToCustomObject = result.text === idl.IDLCustomObjectType.name;
32
- const libPrefix = idl.isPrimitiveType(type) || convertedToCustomObject ? "" : conf.param("LibraryPrefix");
32
+ const libPrefix = idl.isPrimitiveType(type) || convertedToCustomObject ? "" : conf.LibraryPrefix;
33
33
  return `${typePrefix}${libPrefix}${result.text}`;
34
34
  }
35
35
  convert(node) {
@@ -35,6 +35,8 @@ export declare class InteropNameConvertor implements IdlNameConvertor {
35
35
  convert(node: idl.IDLNode): string;
36
36
  }
37
37
  export declare class InteropReturnTypeConvertor implements TypeConvertor<string> {
38
+ protected readonly resolver?: ReferenceResolver | undefined;
39
+ constructor(resolver?: ReferenceResolver | undefined);
38
40
  isVoid(method: PeerMethod): boolean;
39
41
  convert(type: idl.IDLType): string;
40
42
  convertContainer(type: idl.IDLContainerType): string;
@@ -57,7 +57,7 @@ export class InteropConvertor {
57
57
  return this.make(node.name);
58
58
  }
59
59
  convertCallback(node) {
60
- return this.make(generatorConfiguration().param("LibraryPrefix") + node.name, true);
60
+ return this.make(generatorConfiguration().LibraryPrefix + node.name, true);
61
61
  }
62
62
  convertMethod(node) {
63
63
  return this.make(node.name);
@@ -98,7 +98,7 @@ export class InteropConvertor {
98
98
  case "Object":
99
99
  return this.make('CustomObject');
100
100
  }
101
- if (generatorConfiguration().paramArray("knownParameterized").includes(refName)) {
101
+ if (generatorConfiguration().param("parameterized").includes(refName)) {
102
102
  return this.make('CustomObject');
103
103
  }
104
104
  let decl = this.resolver.toDeclaration(type);
@@ -173,6 +173,9 @@ export class InteropNameConvertor {
173
173
  }
174
174
  }
175
175
  export class InteropReturnTypeConvertor {
176
+ constructor(resolver) {
177
+ this.resolver = resolver;
178
+ }
176
179
  isVoid(method) {
177
180
  return this.convert(method.returnType) === idl.IDLVoidType.name;
178
181
  }
@@ -225,6 +228,10 @@ export class InteropReturnTypeConvertor {
225
228
  convertTypeReference(type) {
226
229
  if (type.name.endsWith("Attribute"))
227
230
  return idl.IDLVoidType.name;
231
+ // Callbacks and array types return by value
232
+ if (this.resolver && idl.isCallback(this.resolver.toDeclaration(type))) {
233
+ return type.name;
234
+ }
228
235
  return PrimitiveTypesInstance.NativePointer.getText();
229
236
  }
230
237
  convertUnion(type) {
@@ -1,12 +1,17 @@
1
1
  export interface GeneratorConfiguration {
2
2
  param<T>(name: string): T;
3
- paramArray<T>(name: string): T[];
3
+ readonly params: Record<string, any>;
4
+ TypePrefix: string;
5
+ LibraryPrefix: string;
6
+ OptionalPrefix: string;
4
7
  }
5
8
  export declare class BaseGeneratorConfiguration implements GeneratorConfiguration {
6
- protected params: Record<string, any>;
9
+ readonly params: Record<string, any>;
7
10
  constructor(params?: Record<string, any>);
8
11
  param<T>(name: string): T;
9
- paramArray<T>(name: string): T[];
12
+ get TypePrefix(): string;
13
+ get LibraryPrefix(): string;
14
+ get OptionalPrefix(): string;
10
15
  }
11
16
  export declare function setDefaultConfiguration(config: GeneratorConfiguration): void;
12
17
  export declare function generatorConfiguration(): GeneratorConfiguration;
@@ -15,7 +15,7 @@
15
15
  export class BaseGeneratorConfiguration {
16
16
  constructor(params = {}) {
17
17
  this.params = {};
18
- Object.assign(this.params, params);
18
+ Object.assign(this.params, Object.assign({ TypePrefix: "", LibraryPrefix: "", OptionalPrefix: "" }, params));
19
19
  }
20
20
  param(name) {
21
21
  if (name in this.params) {
@@ -23,12 +23,9 @@ export class BaseGeneratorConfiguration {
23
23
  }
24
24
  throw new Error(`${name} is unknown`);
25
25
  }
26
- paramArray(name) {
27
- if (name in this.params) {
28
- return this.params[name];
29
- }
30
- throw new Error(`${name} is unknown`);
31
- }
26
+ get TypePrefix() { return this.param("TypePrefix"); }
27
+ get LibraryPrefix() { return this.param("LibraryPrefix"); }
28
+ get OptionalPrefix() { return this.param("OptionalPrefix"); }
32
29
  }
33
30
  let currentConfig = new BaseGeneratorConfiguration();
34
31
  export function setDefaultConfiguration(config) {
@@ -168,7 +168,7 @@ export class CustomPrintVisitor {
168
168
  let isProtected = hasExtAttribute(node, IDLExtendedAttributes.Protected);
169
169
  if (isCommonMethod) {
170
170
  // TODO: not very clean, but we don't need to print these so far.
171
- // if (PeerGeneratorConfig.ignorePeerMethod.includes(node.name)) return
171
+ // if (peerGeneratorConfiguration().ignorePeerMethod.includes(node.name)) return
172
172
  const typeParams = (_a = this.currentInterface) === null || _a === void 0 ? void 0 : _a.typeParameters;
173
173
  const returnType = typeParams && typeParams.length > 0 ? typeParams[0] : this.currentInterface.name;
174
174
  this.print(`${getName(node)}(value: ${this.printTypeForTS(node.type, undefined, undefined, isCommonMethod)}): ${returnType};`);
@@ -1,5 +1,4 @@
1
1
  export * from "./config";
2
- export * from "./configMerge";
3
2
  export * from "./idl";
4
3
  export * from "./visitor";
5
4
  export * from "./library";
@@ -13,7 +13,6 @@
13
13
  * limitations under the License.
14
14
  */
15
15
  export * from "./config";
16
- export * from "./configMerge";
17
16
  export * from "./idl";
18
17
  export * from "./visitor";
19
18
  export * from "./library";
@@ -39,9 +39,9 @@ export function isCommonMethodOrSubclass(typeChecker, decl) {
39
39
  return isSubclass;
40
40
  }
41
41
  export function determineInheritanceRole(name) {
42
- if (generatorConfiguration().paramArray("rootComponents").includes(name))
42
+ if (generatorConfiguration().param("rootComponents").includes(name))
43
43
  return InheritanceRole.Root;
44
- if (generatorConfiguration().paramArray("standaloneComponents").includes(name))
44
+ if (generatorConfiguration().param("standaloneComponents").includes(name))
45
45
  return InheritanceRole.Standalone;
46
46
  return InheritanceRole.Heir;
47
47
  }
@@ -32,7 +32,7 @@ export class BuilderClass {
32
32
  */
33
33
  export function isBuilderClass(declaration) {
34
34
  const className = declaration.name;
35
- if (generatorConfiguration().paramArray("builderClasses").includes(className)) {
35
+ if (generatorConfiguration().param("builderClasses").includes(className)) {
36
36
  return true;
37
37
  }
38
38
  if (isCustomBuilderClass(className)) {
@@ -43,7 +43,7 @@ export function isBuilderClass(declaration) {
43
43
  // are used for now.
44
44
  return false;
45
45
  /*
46
- if (PeerGeneratorConfig.isStandardNameIgnored(className)) {
46
+ if (peerGeneratorConfiguration().isStandardNameIgnored(className)) {
47
47
  return false
48
48
  }
49
49
 
@@ -26,7 +26,7 @@ export function isMaterialized(declaration, resolver) {
26
26
  declaration.subkind === idl.IDLInterfaceSubkind.Tuple) {
27
27
  return false;
28
28
  }
29
- for (const ignore of generatorConfiguration().paramArray("ignoreMaterialized")) {
29
+ for (const ignore of generatorConfiguration().param("ignoreMaterialized")) {
30
30
  if (declaration.name.endsWith(ignore))
31
31
  return false;
32
32
  }
@@ -87,6 +87,9 @@ export class MaterializedMethod extends PeerMethod {
87
87
  }
88
88
  return `(void*) 300`;
89
89
  }
90
+ if (idl.isReferenceType(this.method.signature.returnType)) {
91
+ return "{}";
92
+ }
90
93
  return undefined;
91
94
  }
92
95
  get receiverType() {
@@ -19,7 +19,7 @@ export class PrimitiveType {
19
19
  this.isPointer = isPointer;
20
20
  }
21
21
  getText() {
22
- return generatorConfiguration().param("TypePrefix") + this.name;
22
+ return generatorConfiguration().TypePrefix + this.name;
23
23
  }
24
24
  toString() {
25
25
  return this.getText();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idlizer/core",
3
- "version": "2.0.21",
3
+ "version": "2.0.23",
4
4
  "description": "",
5
5
  "types": "build/lib/src/index.d.ts",
6
6
  "exports": {
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "keywords": [],
36
36
  "dependencies": {
37
- "@koalaui/interop": "1.4.8",
37
+ "@koalaui/interop": "1.5.0",
38
38
  "typescript": "4.9.5",
39
39
  "@types/node": "^18.0.0"
40
40
  },