@idlizer/arktscgen 2.1.10-arktscgen-3 → 2.1.10-arktscgen-3a

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.
@@ -17,7 +17,7 @@
17
17
 
18
18
  /*
19
19
  * THIS FILE IS AUTOGENERATED BY arktscgen v2.1.10+devel. DO NOT EDIT MANUALLY!
20
- * es2panda bb0d61379a95a80fffec85824dc465e3cf3b321e(2025-08-20) sdk v1.5.0-dev.42382
20
+ * es2panda b90198c15c97a5627fa1a69ab5f061ef4e54921e(2025-08-25) sdk v1.5.0-dev.42899
21
21
  */
22
22
 
23
23
  KNativePointer impl_GetAllErrorMessages(KNativePointer context)
@@ -16362,6 +16362,15 @@ KNativePointer impl_ArkTsConfigOutDirConst(KNativePointer context, KNativePointe
16362
16362
  }
16363
16363
  KOALA_INTEROP_2(ArkTsConfigOutDirConst, KNativePointer, KNativePointer, KNativePointer);
16364
16364
 
16365
+ KNativePointer impl_ArkTsConfigCacheDirConst(KNativePointer context, KNativePointer receiver)
16366
+ {
16367
+ const auto _context = reinterpret_cast<es2panda_Context*>(context);
16368
+ const auto _receiver = reinterpret_cast<es2panda_ArkTsConfig*>(receiver);
16369
+ auto result = GetImpl()->ArkTsConfigCacheDirConst(_context, _receiver);
16370
+ return StageArena::strdup(result);
16371
+ }
16372
+ KOALA_INTEROP_2(ArkTsConfigCacheDirConst, KNativePointer, KNativePointer, KNativePointer);
16373
+
16365
16374
  KBoolean impl_ArkTsConfigUseUrlConst(KNativePointer context, KNativePointer receiver)
16366
16375
  {
16367
16376
  const auto _context = reinterpret_cast<es2panda_Context*>(context);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koalaui/libarkts",
3
- "version": "1.7.9+devel",
3
+ "version": "1.7.10+devel",
4
4
  "bin": "./lib/es2panda",
5
5
  "typesVersions": {
6
6
  "*": {
@@ -28,13 +28,13 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@koalaui/ets-tsc": "4.9.5-r6",
31
- "@koalaui/build-common": "1.7.9+devel",
32
- "@koalaui/compat": "1.7.9+devel",
33
- "@koalaui/common": "1.7.9+devel",
34
- "@koalaui/harness": "1.7.9+devel",
35
- "@koalaui/interop": "1.7.9+devel",
36
- "@koalaui/fast-arktsc": "1.7.9+devel",
37
- "@idlizer/arktscgen": "2.1.10-arktscgen-2",
31
+ "@koalaui/build-common": "1.7.10+devel",
32
+ "@koalaui/compat": "1.7.10+devel",
33
+ "@koalaui/common": "1.7.10+devel",
34
+ "@koalaui/harness": "1.7.10+devel",
35
+ "@koalaui/interop": "1.7.10+devel",
36
+ "@koalaui/fast-arktsc": "1.7.10+devel",
37
+ "@idlizer/arktscgen": "2.1.10-arktscgen-3",
38
38
  "@types/mocha": "^9.1.0",
39
39
  "mocha": "^9.2.2",
40
40
  "node-addon-api": "8.0.0",
@@ -15,25 +15,29 @@
15
15
 
16
16
  import { KNativePointer } from "@koalaui/interop"
17
17
  import { AstNode } from "./peers/AstNode"
18
- import { Es2pandaAstNodeType } from "src/generated/Es2pandaEnums"
19
18
 
20
19
  export class NodeCache {
21
20
  private static cache = new Map<KNativePointer, AstNode>()
22
21
 
22
+ static cached<T extends AstNode>(pointer: KNativePointer, factory: (pointer: KNativePointer) => AstNode): T {
23
+ const cached = NodeCache.cache.get(pointer)
24
+ if (cached !== undefined) {
25
+ return cached as T
26
+ }
27
+ const node = factory(pointer)
28
+ NodeCache.addToCache(pointer, node)
29
+ return node as T
30
+ }
31
+
23
32
  static get<T extends AstNode>(pointer: KNativePointer): T | undefined {
24
33
  return NodeCache.cache.get(pointer) as T | undefined
25
34
  }
26
35
 
27
36
  public static addToCache(pointer: KNativePointer, node: AstNode) {
28
- if (node.astNodeType == Es2pandaAstNodeType.AST_NODE_TYPE_SCRIPT_FUNCTION
29
- || node.astNodeType == Es2pandaAstNodeType.AST_NODE_TYPE_ETS_FUNCTION_TYPE
30
- || node.astNodeType == Es2pandaAstNodeType.AST_NODE_TYPE_CALL_EXPRESSION) {
31
- NodeCache.cache.set(pointer, node)
32
- }
37
+ NodeCache.cache.set(pointer, node)
33
38
  }
34
39
 
35
40
  public static clear(): void {
36
- console.log("SIZE WAS", NodeCache.cache.size, "ON CLEAR")
37
41
  NodeCache.cache.clear()
38
42
  }
39
43
  }
@@ -16,10 +16,10 @@
16
16
  import { global } from "../static/global"
17
17
  import { isNumber, throwError, withWarning } from "../../utils"
18
18
  import { KNativePointer, nullptr, KInt, KUInt} from "@koalaui/interop"
19
- import { passNode, unpackNodeArray, unpackNonNullableNode, passString, unpackString, passStringArray } from "./private"
19
+ import { passNode, unpackNodeArray, unpackNonNullableNode, passString, unpackString, passStringArray, unpackNode } from "./private"
20
20
  import { Es2pandaContextState, Es2pandaModifierFlags, Es2pandaMethodDefinitionKind, Es2pandaAstNodeType, Es2pandaPluginDiagnosticType } from "../../generated/Es2pandaEnums"
21
21
  import type { AstNode } from "../peers/AstNode"
22
- import { DiagnosticInfo, SourcePosition, SourceRange, SuggestionInfo } from "../../generated"
22
+ import { DiagnosticInfo, Identifier, isConditionalExpression, SourcePosition, SourceRange, SuggestionInfo, VariableDeclarator } from "../../generated"
23
23
  import {
24
24
  type AnnotationUsage,
25
25
  ClassDefinition,
@@ -230,6 +230,26 @@ export function getPeerDecl(peer: KNativePointer): AstNode | undefined {
230
230
  return unpackNonNullableNode(decl)
231
231
  }
232
232
 
233
+ export function declarationFromIdentifier(node: Identifier): AstNode | undefined {
234
+ return unpackNode(global.generatedEs2panda._DeclarationFromIdentifier(global.context, node.peer))
235
+ }
236
+
237
+ export function resolveGensymVariableDeclaratorForDefaultParam(node: VariableDeclarator): Identifier | undefined {
238
+ const init = node.init
239
+ if (isConditionalExpression(init) && isIdentifier(init.consequent) && init.consequent.name.startsWith("gensym%%_")) {
240
+ return init.consequent
241
+ }
242
+ return undefined
243
+ }
244
+
245
+ export function resolveGensymVariableDeclaratorForOptionalCall(node: VariableDeclarator): Identifier | undefined {
246
+ const init = node.init
247
+ if (isIdentifier(node.id) && node.id.name.startsWith("gensym%%_") && isIdentifier(init)) {
248
+ return init
249
+ }
250
+ return undefined
251
+ }
252
+
233
253
  export function getPeerObjectDecl(peer: KNativePointer): AstNode | undefined {
234
254
  const decl = global.es2panda._ClassVariableDeclaration(global.context, peer);
235
255
  if (decl === nullptr) {
@@ -5186,6 +5186,9 @@ export class Es2pandaNativeModule {
5186
5186
  _ArkTsConfigOutDirConst(context: KNativePointer, receiver: KNativePointer): KStringPtr {
5187
5187
  throw new Error("This methods was not overloaded by native module initialization")
5188
5188
  }
5189
+ _ArkTsConfigCacheDirConst(context: KNativePointer, receiver: KNativePointer): KStringPtr {
5190
+ throw new Error("This methods was not overloaded by native module initialization")
5191
+ }
5189
5192
  _ArkTsConfigUseUrlConst(context: KNativePointer, receiver: KNativePointer): KBoolean {
5190
5193
  throw new Error("This methods was not overloaded by native module initialization")
5191
5194
  }
@@ -60,6 +60,9 @@ export class ArkTsConfig extends ArktsObject {
60
60
  get outDir(): string {
61
61
  return unpackString(global.generatedEs2panda._ArkTsConfigOutDirConst(global.context, this.peer))
62
62
  }
63
+ get cacheDir(): string {
64
+ return unpackString(global.generatedEs2panda._ArkTsConfigCacheDirConst(global.context, this.peer))
65
+ }
63
66
  get useUrl(): boolean {
64
67
  return global.generatedEs2panda._ArkTsConfigUseUrlConst(global.context, this.peer)
65
68
  }
@@ -13,9 +13,6 @@
13
13
  * limitations under the License.
14
14
  */
15
15
 
16
- export class Es2pandaError extends Error { }
17
- export class EarlyExitError extends Error { }
18
-
19
16
  export function throwError(error: string): never {
20
17
  throw new Error(error)
21
18
  }
package/lib/index.js CHANGED
@@ -3834,6 +3834,8 @@ var IDLExtendedAttributes;
3834
3834
  IDLExtendedAttributes["Interfaces"] = "Interfaces";
3835
3835
  IDLExtendedAttributes["NativeModule"] = "NativeModule";
3836
3836
  IDLExtendedAttributes["Optional"] = "Optional";
3837
+ IDLExtendedAttributes["UnionOnlyNull"] = "OptionalOnlyNull";
3838
+ IDLExtendedAttributes["UnionWithNull"] = "OptionalWithNull";
3837
3839
  IDLExtendedAttributes["OriginalEnumMemberName"] = "OriginalEnumMemberName";
3838
3840
  IDLExtendedAttributes["OriginalGenericName"] = "OriginalGenericName";
3839
3841
  IDLExtendedAttributes["Predefined"] = "Predefined";
@@ -4905,10 +4907,22 @@ function linearizeNamespaceMembers(entries) {
4905
4907
  }
4906
4908
 
4907
4909
  const modulesCache = new Map();
4910
+ /**
4911
+ * Is source submodule of target.
4912
+ * Every source is submodule if target is empty string
4913
+ * @example `isSubmodule("a.b.c", "a") === true`
4914
+ * @example `isSubmodule("a", "a.b.c") === false`
4915
+ * @example `isSubmodule("a.b.cd", "a.b.c") === false`
4916
+ */
4917
+ function isSubmodule(source, target) {
4918
+ return source === target
4919
+ || target === ""
4920
+ || source.startsWith(target + '.');
4921
+ }
4908
4922
  function isInModule(nodeOrPackage, module) {
4909
4923
  if (typeof nodeOrPackage === 'object')
4910
4924
  return isInModule(getPackageName(nodeOrPackage), module);
4911
- return module.packages.some(modulePackage => nodeOrPackage.startsWith(modulePackage));
4925
+ return module.packages.some(modulePackage => isSubmodule(nodeOrPackage, modulePackage));
4912
4926
  }
4913
4927
  function isInExternalModule(node) {
4914
4928
  var _a;
@@ -5459,7 +5473,7 @@ class LanguageWriter {
5459
5473
  makeThis() {
5460
5474
  return new StringExpression("this");
5461
5475
  }
5462
- makeNull(value) {
5476
+ makeNull(type) {
5463
5477
  return new StringExpression("null");
5464
5478
  }
5465
5479
  makeVoid() {
@@ -8227,7 +8241,7 @@ class CppLanguageWriter extends CLikeLanguageWriter {
8227
8241
  writePrintLog(message) {
8228
8242
  this.print(`printf("${message}\\n");`);
8229
8243
  }
8230
- makeDefinedCheck(value, isTag) {
8244
+ makeDefinedCheck(value, type, isTag) {
8231
8245
  return this.makeString(isTag ? `${value} != ${PrimitiveTypeList.UndefinedTag}`
8232
8246
  : `runtimeType(${value}) != ${PrimitiveTypeList.UndefinedRuntime}`);
8233
8247
  }
@@ -8655,7 +8669,9 @@ class TSLanguageWriter extends LanguageWriter {
8655
8669
  const normalizedArgs = signature.args.map((it, i) => isOptionalType(it) && signature.isArgOptional(i) ? maybeUnwrapOptionalType(it) : it);
8656
8670
  this.printer.print(`${prefix}${name}${typeParams}(${normalizedArgs.map((it, index) => `${this.escapeKeyword(signature.argName(index))}${signature.isArgOptional(index) ? "?" : ``}: ${this.getNodeName(it)}${signature.argDefault(index) ? ' = ' + signature.argDefault(index) : ""}`).join(", ")})${needReturn ? ": " + this.getNodeName(signature.returnType) : ""}${needBracket ? " {" : ""}`);
8657
8671
  }
8658
- makeNull() {
8672
+ makeNull(type) {
8673
+ if (type && hasExtAttribute(type, IDLExtendedAttributes.UnionOnlyNull))
8674
+ return new StringExpression("null");
8659
8675
  return new StringExpression("undefined");
8660
8676
  }
8661
8677
  makeAssign(variableName, type, expr, isDeclared = true, isConst = true, options) {
@@ -8712,7 +8728,15 @@ class TSLanguageWriter extends LanguageWriter {
8712
8728
  makeRuntimeType(rt) {
8713
8729
  return this.makeString(`RuntimeType.${RuntimeType[rt]}`);
8714
8730
  }
8715
- makeDefinedCheck(value) {
8731
+ makeDefinedCheck(value, type) {
8732
+ if (type) {
8733
+ if (hasExtAttribute(type, IDLExtendedAttributes.UnionWithNull)) {
8734
+ return this.makeString(`${value} !== undefined && ${value} !== null`);
8735
+ }
8736
+ else if (hasExtAttribute(type, IDLExtendedAttributes.UnionOnlyNull)) {
8737
+ return this.makeString(`${value} !== null`);
8738
+ }
8739
+ }
8716
8740
  return this.makeString(`${value} !== undefined`);
8717
8741
  }
8718
8742
  makeTupleAlloc(option) {
@@ -12434,6 +12458,32 @@ class Typechecker {
12434
12458
  }
12435
12459
  return ancestor === Config.defaultAncestor;
12436
12460
  }
12461
+ hasDescendants(ref) {
12462
+ const iface = isReferenceType(ref) ? this.resolveReference(ref) : ref;
12463
+ if (!iface || !isInterface$1(iface)) {
12464
+ return false;
12465
+ }
12466
+ const lookupScopes = [];
12467
+ const parent = iface.parent;
12468
+ if (parent && isNamespace(parent)) {
12469
+ lookupScopes.push(...this.namespaces.filter(ns => ns.name === parent.name));
12470
+ }
12471
+ else {
12472
+ lookupScopes.push(this.file);
12473
+ }
12474
+ const visitInterfaces = (node, cb) => {
12475
+ switch (node.kind) {
12476
+ case IDLKind.File:
12477
+ return node.entries.some((value) => visitInterfaces(value, cb));
12478
+ case IDLKind.Namespace:
12479
+ return node.members.some((value) => visitInterfaces(value, cb));
12480
+ case IDLKind.Interface:
12481
+ return cb(node);
12482
+ }
12483
+ return false;
12484
+ };
12485
+ return lookupScopes.some(scope => visitInterfaces(scope, (node) => node.name !== iface.name && this.isHeir(node, iface.name)));
12486
+ }
12437
12487
  isPeer(node) {
12438
12488
  if (node.name === Config.astNodeCommonAncestor)
12439
12489
  return false; // TODO: is handwritten
@@ -13477,21 +13527,35 @@ class BindingParameterTypeConvertor extends TopLevelTypeConvertor {
13477
13527
  * limitations under the License.
13478
13528
  */
13479
13529
  class BindingReturnValueTypeConvertor extends TopLevelTypeConvertor {
13480
- constructor(typechecker) {
13530
+ constructor(typechecker, importer) {
13481
13531
  const plain = (type) => (writer, call) => call;
13482
- const wrap = (wrapWith) => (writer, call) => writer.makeFunctionCall(wrapWith, [call]);
13532
+ const wrap = (wrapWith, ...args) => (writer, call) => writer.makeFunctionCall(wrapWith, [call, ...args.map(a => writer.makeString(a))]);
13533
+ const isAstNode = (ref) => (isReferenceType(ref) || isInterface$1(ref)) && this.typechecker.isHeir(ref, Config.astNodeCommonAncestor);
13534
+ const makeArgs = (type) => {
13535
+ const iface = isReferenceType(type)
13536
+ ? this.typechecker.resolveReference(type)
13537
+ : undefined;
13538
+ if (iface && isAstNode(iface) && !this.typechecker.hasDescendants(iface)) {
13539
+ const astNodeTypeName = this.typechecker.nodeTypeName(iface);
13540
+ if (astNodeTypeName) {
13541
+ importer.withEnumImport(Config.nodeTypeAttribute);
13542
+ return [astNodeTypeName];
13543
+ }
13544
+ }
13545
+ return [];
13546
+ };
13483
13547
  super(typechecker, {
13484
- sequence: (type) => wrap(PeersConstructions.arrayOfPointersToArrayOfPeers),
13548
+ sequence: (type) => wrap(PeersConstructions.arrayOfPointersToArrayOfPeers, ...makeArgs(type.elementType[0])),
13485
13549
  string: (type) => wrap(PeersConstructions.receiveString),
13486
- reference: (type) => this.typechecker.isHeir(type, Config.astNodeCommonAncestor)
13487
- ? wrap(PeersConstructions.unpackNonNullable)
13550
+ reference: (type) => isAstNode(type)
13551
+ ? wrap(PeersConstructions.unpackNonNullable, ...makeArgs(type))
13488
13552
  : wrap(baseNameString(type.name)),
13489
13553
  optional: (type) => {
13490
- if (isReferenceType(type.type)) {
13491
- if (this.typechecker.isHeir(type.type, Config.astNodeCommonAncestor)) {
13492
- return wrap(PeersConstructions.unpackNullable);
13493
- }
13494
- return wrap(PeersConstructions.newOf(baseNameString(type.type.name)));
13554
+ const innerType = type.type;
13555
+ if (isReferenceType(innerType)) {
13556
+ return isAstNode(innerType)
13557
+ ? wrap(PeersConstructions.unpackNullable, ...makeArgs(innerType))
13558
+ : wrap(PeersConstructions.newOf(baseNameString(innerType.name)));
13495
13559
  }
13496
13560
  throwException(`unexpected optional of non-reference type`);
13497
13561
  },
@@ -13502,6 +13566,7 @@ class BindingReturnValueTypeConvertor extends TopLevelTypeConvertor {
13502
13566
  boolean: plain,
13503
13567
  undefined: plain
13504
13568
  });
13569
+ this.importer = importer;
13505
13570
  }
13506
13571
  }
13507
13572
 
@@ -13542,7 +13607,7 @@ class PeerPrinter extends SingleFilePrinter {
13542
13607
  this.typechecker = new Typechecker(this.idl);
13543
13608
  this.importer = new Importer(this.typechecker, `.`, this.node.name);
13544
13609
  this.bindingParameterTypeConvertor = new BindingParameterTypeConvertor(this.typechecker);
13545
- this.bindingReturnValueTypeConvertor = new BindingReturnValueTypeConvertor(this.typechecker);
13610
+ this.bindingReturnValueTypeConvertor = new BindingReturnValueTypeConvertor(this.typechecker, this.importer);
13546
13611
  this.parent = (_a = parent(this.node)) !== null && _a !== void 0 ? _a : Config.defaultAncestor;
13547
13612
  this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => convertAndImport(this.importer, new class extends LibraryTypeConvertor {
13548
13613
  convertTypeReference(type) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idlizer/arktscgen",
3
- "version": "2.1.10-arktscgen-3",
3
+ "version": "2.1.10-arktscgen-3a",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "bin": "lib/index.js",
@@ -19,7 +19,7 @@
19
19
  "license": "Apache-2.0",
20
20
  "keywords": [],
21
21
  "dependencies": {
22
- "@idlizer/core": "2.1.10-arktscgen-3",
22
+ "@idlizer/core": "2.1.10-arktscgen-3a",
23
23
  "@types/node": "^18.0.0",
24
24
  "commander": "^10.0.0",
25
25
  "typescript": "^4.9.5"