@idlizer/arktscgen 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.
package/lib/index.js CHANGED
@@ -3847,11 +3847,13 @@ var IDLExtendedAttributes;
3847
3847
  IDLExtendedAttributes["TypeAnnotations"] = "TypeAnnotations";
3848
3848
  IDLExtendedAttributes["TypeArguments"] = "TypeArguments";
3849
3849
  IDLExtendedAttributes["TypeParameters"] = "TypeParameters";
3850
+ IDLExtendedAttributes["TypeParametersDefaults"] = "TypeParametersDefaults";
3850
3851
  IDLExtendedAttributes["VerbatimDts"] = "VerbatimDts";
3851
3852
  IDLExtendedAttributes["HandWrittenImplementation"] = "HandWrittenImplementation";
3852
3853
  IDLExtendedAttributes["ExtraMethod"] = "ExtraMethod";
3853
3854
  IDLExtendedAttributes["OverloadAlias"] = "OverloadAlias";
3854
3855
  IDLExtendedAttributes["OverloadPriority"] = "OverloadPriority";
3856
+ IDLExtendedAttributes["TransformOnSerialize"] = "TransformOnSerialize";
3855
3857
  })(IDLExtendedAttributes || (IDLExtendedAttributes = {}));
3856
3858
  var IDLAccessorAttribute;
3857
3859
  (function (IDLAccessorAttribute) {
@@ -4190,6 +4192,7 @@ const IDLSerializerBuffer = createPrimitiveType('SerializerBuffer');
4190
4192
  const IDLFunctionType = createPrimitiveType('Function');
4191
4193
  const IDLCustomObjectType = createPrimitiveType('CustomObject');
4192
4194
  createPrimitiveType('InteropReturnBuffer');
4195
+ const IDLNullTypeName = "idlize.stdlib.Null";
4193
4196
  function createNamespace(name, members, nodeInitializer) {
4194
4197
  return Object.assign(Object.assign({ kind: IDLKind.Namespace, members: members !== null && members !== void 0 ? members : [], name: name }, nodeInitializer), { _idlNodeBrand: innerIdlSymbol, _idlEntryBrand: innerIdlSymbol, _idlNamedNodeBrand: innerIdlSymbol });
4195
4198
  }
@@ -4561,23 +4564,29 @@ function escapeIDLKeyword(name) {
4561
4564
  const printedIndentInc = "[[indent-inc]]";
4562
4565
  const printedIndentDec = "[[indent-dec]]";
4563
4566
  function printType(type, options) {
4567
+ var _a;
4564
4568
  if (!type)
4565
4569
  throw new Error("Missing type");
4566
4570
  if (isInterface$1(type))
4567
4571
  return type.name;
4568
- if (isOptionalType(type))
4569
- return `(${printType(type.type)} or ${IDLUndefinedType.name})`;
4572
+ if (isOptionalType(type)) {
4573
+ if (hasExtAttribute(type, IDLExtendedAttributes.UnionOnlyNull))
4574
+ return `(${printType(type.type)} or ${IDLNullTypeName})`;
4575
+ else if (hasExtAttribute(type, IDLExtendedAttributes.UnionWithNull))
4576
+ return `(${printType(type.type)} or ${IDLUndefinedType.name} or${IDLNullTypeName})`;
4577
+ else
4578
+ return `(${printType(type.type)} or ${IDLUndefinedType.name})`;
4579
+ }
4570
4580
  if (isPrimitiveType(type))
4571
4581
  return type.name;
4572
4582
  if (isContainerType(type))
4573
4583
  return `${type.containerKind}<${type.elementType.map(it => printType(it)).join(", ")}>`;
4574
4584
  if (isReferenceType(type)) {
4575
- const extAttrs = type.extendedAttributes ? Array.from(type.extendedAttributes) : [];
4576
4585
  if (type.typeArguments)
4577
- extAttrs.push({ name: IDLExtendedAttributes.TypeArguments, value: type.typeArguments.map(it => printType(it)).join(",") });
4578
- if (!extAttrs.length)
4586
+ updateExtAttribute(type, IDLExtendedAttributes.TypeArguments, type.typeArguments.map(it => printType(it)).join(","));
4587
+ if (!((_a = type.extendedAttributes) === null || _a === void 0 ? void 0 : _a.length))
4579
4588
  return type.name;
4580
- let res = `[${quoteAttributeValues(extAttrs)}] ${type.name}`;
4589
+ let res = `[${quoteAttributeValues(type.extendedAttributes)}] ${type.name}`;
4581
4590
  if (options === null || options === void 0 ? void 0 : options.bracketsAroundReferenceTypeWithExtAttrs)
4582
4591
  return `(${res})`;
4583
4592
  return res;
@@ -4647,18 +4656,31 @@ function printExtendedAttributes(idl, indentLevel) {
4647
4656
  break;
4648
4657
  }
4649
4658
  const attributes = Array.from(idl.extendedAttributes || []);
4650
- if (typeParameters === null || typeParameters === void 0 ? void 0 : typeParameters.length)
4659
+ if ((typeParameters === null || typeParameters === void 0 ? void 0 : typeParameters.length) && !attributes.find(x => x.name === IDLExtendedAttributes.TypeParameters))
4651
4660
  attributes.push({ name: IDLExtendedAttributes.TypeParameters, value: typeParameters.join(",") });
4652
- if (typeArguments === null || typeArguments === void 0 ? void 0 : typeArguments.length)
4661
+ if ((typeArguments === null || typeArguments === void 0 ? void 0 : typeArguments.length) && !attributes.find(x => x.name === IDLExtendedAttributes.TypeArguments))
4653
4662
  attributes.push({ name: IDLExtendedAttributes.TypeArguments, value: typeArguments.map(it => printType(it)).join(",") });
4654
4663
  if (idl.documentation) {
4655
4664
  let docs = {
4656
4665
  name: IDLExtendedAttributes.Documentation,
4657
4666
  value: idl.documentation
4658
4667
  };
4659
- attributes.push(docs);
4668
+ attributes.unshift(docs);
4660
4669
  }
4661
- const attrSpec = quoteAttributeValues(attributes);
4670
+ // Deduplicate
4671
+ const names = new Set();
4672
+ const actualAttributes = [];
4673
+ for (const attr of attributes) {
4674
+ if (names.has(attr.name)) {
4675
+ continue;
4676
+ }
4677
+ names.add(attr.name);
4678
+ actualAttributes.push(attr);
4679
+ }
4680
+ if (actualAttributes.length == 0) {
4681
+ return [];
4682
+ }
4683
+ const attrSpec = quoteAttributeValues(actualAttributes);
4662
4684
  return attrSpec ? [`[${attrSpec}]`] : [];
4663
4685
  }
4664
4686
  const attributesToQuote = new Set([
@@ -4670,6 +4692,7 @@ const attributesToQuote = new Set([
4670
4692
  IDLExtendedAttributes.TraceKey,
4671
4693
  IDLExtendedAttributes.TypeArguments,
4672
4694
  IDLExtendedAttributes.TypeParameters,
4695
+ IDLExtendedAttributes.TypeParametersDefaults,
4673
4696
  ]);
4674
4697
  function quoteAttributeValues(attributes) {
4675
4698
  return attributes === null || attributes === void 0 ? void 0 : attributes.map(it => {
@@ -4858,6 +4881,17 @@ function getExtAttribute(node, name) {
4858
4881
  var _a, _b;
4859
4882
  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;
4860
4883
  }
4884
+ function removeExtAttribute(node, name) {
4885
+ if (node.extendedAttributes) {
4886
+ node.extendedAttributes = node.extendedAttributes.filter(it => it.name !== name);
4887
+ }
4888
+ }
4889
+ function updateExtAttribute(node, name, value) {
4890
+ var _a;
4891
+ removeExtAttribute(node, name);
4892
+ (_a = node.extendedAttributes) !== null && _a !== void 0 ? _a : (node.extendedAttributes = []);
4893
+ node.extendedAttributes.push({ name, value });
4894
+ }
4861
4895
  const IDLContainerUtils = {
4862
4896
  isRecord: (x) => isContainerType(x) && x.containerKind === 'record',
4863
4897
  isSequence: (x) => isContainerType(x) && x.containerKind === 'sequence',
@@ -4906,6 +4940,13 @@ function linearizeNamespaceMembers(entries) {
4906
4940
  return linearized;
4907
4941
  }
4908
4942
 
4943
+ const stdlibModule = {
4944
+ name: "__stdlib",
4945
+ packages: [""],
4946
+ useFoldersLayout: false,
4947
+ external: true,
4948
+ tsLikePackage: "__stdlib"
4949
+ };
4909
4950
  const modulesCache = new Map();
4910
4951
  /**
4911
4952
  * Is source submodule of target.
@@ -4945,7 +4986,7 @@ function getApplicableModuleFor(packageName) {
4945
4986
  if (applicableModules.length === 0) {
4946
4987
  if (packageName === '') {
4947
4988
  console.error("WARNING: use current module for empty package");
4948
- return currentModule();
4989
+ return stdlibModule;
4949
4990
  }
4950
4991
  if (packageName.startsWith(`idlize.`)) {
4951
4992
  return currentModule();
@@ -5270,8 +5311,11 @@ class LambdaExpression {
5270
5311
  if (this.body) {
5271
5312
  writer.writeStatement(new BlockStatement(this.body, isScoped, false));
5272
5313
  }
5273
- writer.features.forEach(([feature, module]) => {
5274
- this.originalWriter.addFeature(feature, module);
5314
+ writer.features.forEach((feature) => {
5315
+ if (feature.type === "raw")
5316
+ this.originalWriter.addFeature(feature.feature, feature.module);
5317
+ else
5318
+ this.originalWriter.addFeature(feature.node);
5275
5319
  });
5276
5320
  return writer.getOutput()
5277
5321
  .map(line => (line.endsWith('{') || line.endsWith('}') || line.endsWith(';')) ? line : `${line};`)
@@ -5406,8 +5450,11 @@ class LanguageWriter {
5406
5450
  return this.printer.indentDepth();
5407
5451
  }
5408
5452
  maybeSemicolon() { return ";"; }
5409
- addFeature(feature, module) {
5410
- this.features.push([feature, module]);
5453
+ addFeature(featureOrNode, module) {
5454
+ if (typeof featureOrNode === "string")
5455
+ this.features.push({ type: "raw", feature: featureOrNode, module: module });
5456
+ else
5457
+ this.features.push({ type: "idl", node: featureOrNode });
5411
5458
  }
5412
5459
  // version of makeCast which uses TypeCheck.typeCast<T>(value) call for ETS language writer
5413
5460
  // Use it only if TypeChecker class is added as import to the generated file
@@ -6158,12 +6205,14 @@ const IncorrectLiteral = new DiagnosticMessageGroup("error", "IncorrectLiteral",
6158
6205
  const IncorrectIdentifier = new DiagnosticMessageGroup("error", "IncorrectIdentifier", "Incorrect identifier");
6159
6206
  const UnexpectedToken = new DiagnosticMessageGroup("error", "UnexpectedToken", "Unexpected token");
6160
6207
  const UnexpectedEndOfFile = new DiagnosticMessageGroup("fatal", "UnexpectedEndOfFile", "Unexpected end of file");
6208
+ const UnrecognizedSymbols = new DiagnosticMessageGroup("fatal", "UnrecognizedSymbols", "Unrecognized symbols");
6161
6209
  const UnsupportedSyntax = new DiagnosticMessageGroup("error", "UnsupportedSyntax", "Unsupported syntax");
6162
6210
  const WrongDeclarationPlacement = new DiagnosticMessageGroup("error", "WrongDeclarationPlacement", "Wrong declaration placement");
6163
6211
  const ExpectedPrimitiveType = new DiagnosticMessageGroup("error", "ExpectedPrimitiveType", "Expected primitive type");
6164
6212
  const ExpectedReferenceType = new DiagnosticMessageGroup("error", "ExpectedReferenceType", "Expected reference type");
6165
6213
  const ExpectedGenericArguments = new DiagnosticMessageGroup("error", "ExpectedGenericArguments", "Expected generic arguments");
6166
6214
  const UnexpectedGenericArguments = new DiagnosticMessageGroup("error", "UnexpectedGenericArguments", "Unexpected generic arguments");
6215
+ const InlineParsingDepthExceeded = new DiagnosticMessageGroup("fatal", "InlineParsingDepthExceeded", "Inline parsing depth exceeded");
6167
6216
  class FatalParserException extends Error {
6168
6217
  constructor(diagnosticMessages) {
6169
6218
  super();
@@ -6195,7 +6244,7 @@ class Parser {
6195
6244
  // TypeParameters support
6196
6245
  this._generics = [];
6197
6246
  // TypeArguments parsing support
6198
- this._enableInLiteralParsing = false;
6247
+ this._inLiteralParsingLevel = 0;
6199
6248
  // symTokens = ["(", ")", "[", "]", "{", "}", ",", "...", ":", ";", "<", "=", ">", "?"]
6200
6249
  this._reDecimal = /-?(?=[0-9]*\.|[0-9]+[eE])(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][-+]?[0-9]+)?|[0-9]+[Ee][-+]?[0-9]+)/y;
6201
6250
  this._reInteger = /-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/y;
@@ -6283,17 +6332,17 @@ class Parser {
6283
6332
  this._curToken = { kind: TokenKind.End, value: "", location: { documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } } };
6284
6333
  return;
6285
6334
  }
6286
- if (this._enableInLiteralParsing && this.content[this._curOffset] == "\"") {
6335
+ if (this._inLiteralParsingLevel && (this.content[this._curOffset] == "\"" || this.content[this._curOffset] == "'")) {
6287
6336
  // TypeArguments parsing support
6288
6337
  const pos = { line: this._curLine + 1, character: this._curOffset - this.offsets[this._curLine] + 1 };
6289
- this._curToken = { kind: TokenKind.Symbol, value: "\"", location: { documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } } };
6338
+ this._curToken = { kind: TokenKind.Symbol, value: this.content[this._curOffset], location: { documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } } };
6290
6339
  this._curOffset += 1;
6291
6340
  return;
6292
6341
  }
6293
6342
  const token = ((_d = (_c = (_b = (_a = this._match(this._reDecimal, TokenKind.Literal)) !== null && _a !== void 0 ? _a : this._match(this._reInteger, TokenKind.Literal)) !== null && _b !== void 0 ? _b : this._match(this._reString, TokenKind.Literal)) !== null && _c !== void 0 ? _c : this._match(this._reWords, TokenKind.Words)) !== null && _d !== void 0 ? _d : this._match(this._reSymbol, TokenKind.Symbol));
6294
6343
  if (!token) {
6295
6344
  const pos = { line: this._curLine + 1, character: this._curOffset - this.offsets[this._curLine] + 1 };
6296
- ParsingFatal.throwDiagnosticMessage([{ documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } }], "Unrecognized symbols");
6345
+ UnrecognizedSymbols.throwDiagnosticMessage([{ documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } }]);
6297
6346
  }
6298
6347
  // Uncomment in case of parser debugging
6299
6348
  // if (token) {
@@ -6587,28 +6636,32 @@ class Parser {
6587
6636
  duplicates.add(name.value);
6588
6637
  }
6589
6638
  names.add(name.value);
6590
- if (name.value == IDLExtendedAttributes.TypeArguments) {
6639
+ if (name.value == IDLExtendedAttributes.TypeArguments || name.value == IDLExtendedAttributes.TypeParametersDefaults) {
6591
6640
  // TypeArguments parsing support
6592
6641
  try {
6593
- this._enableInLiteralParsing = true;
6642
+ this._inLiteralParsingLevel += 1;
6643
+ if (this._inLiteralParsingLevel > 2) {
6644
+ InlineParsingDepthExceeded.throwDiagnosticMessage([this.curLocation]);
6645
+ }
6594
6646
  this.skip("=");
6595
6647
  const vloc = this.trackLocation();
6596
6648
  const start = this._curOffset; // Already after first quote
6597
- this.skip("\"");
6649
+ this.skip(this._inLiteralParsingLevel == 2 ? "'" : "\"");
6598
6650
  const types = this.parseTypeList();
6599
6651
  const end = this._curOffset - 1; // Already after second quote
6600
- this._enableInLiteralParsing = false;
6601
- this.skip("\"");
6652
+ this._inLiteralParsingLevel -= 1;
6653
+ // Note that second this._inLiteralParsingLevel comparison happens after decrement
6654
+ this.skip(this._inLiteralParsingLevel == 1 ? "'" : "\"");
6602
6655
  const stringValue = this.content.slice(start, end);
6603
6656
  ext.push({ name: name.value, value: stringValue, typesValue: types, nameLocation: name.location, valueLocation: vloc() });
6604
6657
  }
6605
6658
  catch (e) {
6606
- this.skipToAfter("\"");
6659
+ if (e instanceof DiagnosticException && e.diagnosticMessage.severity != "fatal") {
6660
+ this.skipToAfter("\"");
6661
+ }
6662
+ this._inLiteralParsingLevel = 0;
6607
6663
  throw e;
6608
6664
  }
6609
- finally {
6610
- this._enableInLiteralParsing = false;
6611
- }
6612
6665
  }
6613
6666
  else {
6614
6667
  let value;
@@ -6780,9 +6833,9 @@ class Parser {
6780
6833
  const name = this.parseSingleIdentifier();
6781
6834
  this.skip("=");
6782
6835
  const value = this.parseLiteral();
6783
- const extracted = extractLiteral(value);
6784
6836
  this.skip(";");
6785
- return createConstant(name.value, type, extracted.extractedString, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location, valueLocation: value.location });
6837
+ // Note that raw value (with quoted strings) is used here, that provides compatibility with older code (while being different from `dictionary` processing)
6838
+ return createConstant(name.value, type, value.value, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location, valueLocation: value.location });
6786
6839
  }
6787
6840
  parseAttribute() {
6788
6841
  const sloc = this.trackLocation();
@@ -6866,11 +6919,14 @@ class Parser {
6866
6919
  const sloc = this.trackLocation();
6867
6920
  const type = this.parsePrimitiveType();
6868
6921
  const name = this.parseSingleIdentifier();
6869
- this.skip("=");
6870
- const value = this.parseLiteral();
6871
- const extracted = extractLiteral(value);
6922
+ let value;
6923
+ let extracted;
6924
+ if (this.seeAndSkip("=")) {
6925
+ value = this.parseLiteral();
6926
+ extracted = extractLiteral(value);
6927
+ }
6872
6928
  this.skip(";");
6873
- return createEnumMember(name.value, undefined, type, extracted.extractedValue, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location, valueLocation: value.location });
6929
+ return createEnumMember(name.value, undefined, type, extracted === null || extracted === void 0 ? void 0 : extracted.extractedValue, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location, valueLocation: value === null || value === void 0 ? void 0 : value.location });
6874
6930
  }
6875
6931
  parsePackage() {
6876
6932
  const sloc = this.trackLocation();
@@ -7036,6 +7092,93 @@ const builtinTypesList = [IDLPointerType, IDLVoidType, IDLBooleanType,
7036
7092
  const builtinTypes = new Map(builtinTypesList.map(x => [x.name, x]));
7037
7093
  const builtinGenericTypeNames = new Set(["sequence", "record", "Promise"]);
7038
7094
 
7095
+ /*
7096
+ * Copyright (c) 2025 Huawei Device Co., Ltd.
7097
+ * Licensed under the Apache License, Version 2.0 (the "License");
7098
+ * you may not use this file except in compliance with the License.
7099
+ * You may obtain a copy of the License at
7100
+ *
7101
+ * http://www.apache.org/licenses/LICENSE-2.0
7102
+ *
7103
+ * Unless required by applicable law or agreed to in writing, software
7104
+ * distributed under the License is distributed on an "AS IS" BASIS,
7105
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7106
+ * See the License for the specific language governing permissions and
7107
+ * limitations under the License.
7108
+ */
7109
+ function lineDigitCount(message) {
7110
+ let count = 0;
7111
+ for (let part of message.parts) {
7112
+ let range = part.location.range;
7113
+ if (range == null) {
7114
+ continue;
7115
+ }
7116
+ count = Math.max(count, range.start.line.toString().length, range.end.line.toString().length);
7117
+ }
7118
+ return count;
7119
+ }
7120
+ function paddedLineNo(digits, line) {
7121
+ let s = line.toString();
7122
+ if (s.length < digits) {
7123
+ return " ".repeat(digits - s.length) + s;
7124
+ }
7125
+ return s;
7126
+ }
7127
+ function formatLine(digits, lines, lineNo) {
7128
+ return `${paddedLineNo(digits, lineNo)} | ${lines[lineNo - 1]}`;
7129
+ }
7130
+ function formatUnderline(indent, lines, lineNo, range, edgeChar, midChar, message) {
7131
+ if (lineNo == range.start.line && lineNo == range.end.line) {
7132
+ let len = range.end.character - range.start.character + 1;
7133
+ return `${indent} | ${" ".repeat(range.start.character - 1)}${edgeChar}${len > 2 ? midChar.repeat(len - 2) : ""}${len > 1 ? edgeChar : ""} ${message}`;
7134
+ }
7135
+ if (lineNo == range.start.line) {
7136
+ let len = lines[lineNo - 1].length - range.start.character;
7137
+ return `${indent} | ${" ".repeat(range.start.character - 1)}${edgeChar}${len > 1 ? midChar.repeat(len - 1) : ""}`;
7138
+ }
7139
+ if (lineNo == range.end.line) {
7140
+ let len = range.end.character;
7141
+ return `${indent} | ${len > 1 ? midChar.repeat(len - 1) : ""}${edgeChar} ${message}`;
7142
+ }
7143
+ return `${indent} | ${midChar.repeat(lines[lineNo - 1].length)}`;
7144
+ }
7145
+ function outputDiagnosticMessageFormatted(message) {
7146
+ if (message.parts.length == 0) {
7147
+ return;
7148
+ }
7149
+ console.log(`${message.severity}[${message.code}]: ${message.codeDescription}`);
7150
+ let digits = lineDigitCount(message);
7151
+ let indent = " ".repeat(digits);
7152
+ let first = true;
7153
+ let lastPath = "";
7154
+ for (let part of message.parts) {
7155
+ const location = part.location;
7156
+ if (location.range != null && location.lines != null) {
7157
+ let range = location.range;
7158
+ let lines = location.lines;
7159
+ console.log(`${indent}${lastPath != part.location.documentPath ? "-->" : ":::"} ${part.location.documentPath}:${range.start.line}:${range.start.character}`);
7160
+ console.log(`${indent} |`);
7161
+ const last = Math.min(range.end.line + 1, lines.length - 1);
7162
+ for (let i = Math.max(range.start.line - 1, 1); i <= last; ++i) {
7163
+ console.log(formatLine(digits, lines, i));
7164
+ if (i >= range.start.line && i <= range.end.line) {
7165
+ console.log(formatUnderline(indent, lines, i, range, "^", first ? "-" : "~", part.message));
7166
+ }
7167
+ }
7168
+ }
7169
+ else {
7170
+ console.log(`${indent}--> ${part.location.documentPath}`);
7171
+ if (message.parts.length > 1) {
7172
+ console.log(`${indent} # ${part.message}`);
7173
+ }
7174
+ }
7175
+ first = false;
7176
+ lastPath = part.location.documentPath;
7177
+ }
7178
+ console.log(`${indent} = ${message.parts[0].message}`);
7179
+ console.log();
7180
+ }
7181
+
7039
7182
  /*
7040
7183
  * Copyright (c) 2024 Huawei Device Co., Ltd.
7041
7184
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -7053,6 +7196,10 @@ const builtinGenericTypeNames = new Set(["sequence", "record", "Promise"]);
7053
7196
  function getTokens(node) {
7054
7197
  return node.tokens;
7055
7198
  }
7199
+ const extendedAttributesWithTypesValue = [
7200
+ IDLExtendedAttributes.TypeArguments,
7201
+ IDLExtendedAttributes.TypeParametersDefaults,
7202
+ ];
7056
7203
  const syntheticTypes = new Map();
7057
7204
  function addSyntheticType(name, type) {
7058
7205
  if (syntheticTypes.has(name)) {
@@ -7064,9 +7211,8 @@ class IDLDeserializer {
7064
7211
  enterGenericScope(generics) {
7065
7212
  this.genericsScopes.push(new Set(generics !== null && generics !== void 0 ? generics : []));
7066
7213
  }
7067
- constructor(info, inheritanceMode = 'multiple') {
7214
+ constructor(info) {
7068
7215
  this.info = info;
7069
- this.inheritanceMode = inheritanceMode;
7070
7216
  this.namespacePathNames = [];
7071
7217
  this.currentPackage = [];
7072
7218
  this.genericsScopes = [];
@@ -7163,7 +7309,7 @@ class IDLDeserializer {
7163
7309
  node.inheritance.forEach(it => {
7164
7310
  const attributes = it.extAttrs;
7165
7311
  const parentTypeArgs = this.extractTypeArguments(file, attributes !== null && attributes !== void 0 ? attributes : [], IDLExtendedAttributes.TypeArguments);
7166
- const attrs = this.toExtendedAttributes(attributes !== null && attributes !== void 0 ? attributes : []); // ?.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments)
7312
+ const attrs = this.toExtendedAttributes(file, attributes !== null && attributes !== void 0 ? attributes : []); // ?.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments)
7167
7313
  const ref = createReferenceType(it.inheritance, parentTypeArgs, {
7168
7314
  extendedAttributes: attrs
7169
7315
  });
@@ -7183,7 +7329,7 @@ class IDLDeserializer {
7183
7329
  .map(it => this.toIDLCallable(file, it)), generics, {
7184
7330
  fileName: file,
7185
7331
  documentation: this.makeDocs(node),
7186
- extendedAttributes: this.toExtendedAttributes(node.extAttrs),
7332
+ extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
7187
7333
  });
7188
7334
  this.genericsScopes.pop();
7189
7335
  this.info.set(result, getTokens(node));
@@ -7199,6 +7345,8 @@ class IDLDeserializer {
7199
7345
  // is it IDLStringType?
7200
7346
  const refType = createReferenceType(type);
7201
7347
  refType.fileName = file;
7348
+ // Here is a bug: type.extAttrs are ignored, so typeArguments on ([TypeArguments="T"] Something) are always lost
7349
+ // That must be fixed together with fixing non-generic placeholders on generic types in pipelines (like WrappedBuilder)
7202
7350
  refType.typeArguments = this.extractTypeArguments(file, extAttrs, IDLExtendedAttributes.TypeArguments);
7203
7351
  return refType;
7204
7352
  }
@@ -7256,7 +7404,7 @@ class IDLDeserializer {
7256
7404
  idlRefType = ref;
7257
7405
  }
7258
7406
  idlRefType.fileName = file;
7259
- idlRefType.extendedAttributes = this.toExtendedAttributes(combinedExtAttrs);
7407
+ idlRefType.extendedAttributes = this.toExtendedAttributes(file, combinedExtAttrs);
7260
7408
  return this.withInfo(type, idlRefType);
7261
7409
  }
7262
7410
  if (isSequenceTypeDescription(type) || isPromiseTypeDescription(type) || isRecordTypeDescription(type)) {
@@ -7284,7 +7432,7 @@ class IDLDeserializer {
7284
7432
  isAsync: node.async,
7285
7433
  }, {
7286
7434
  documentation: this.makeDocs(node),
7287
- extendedAttributes: this.toExtendedAttributes(node.extAttrs),
7435
+ extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
7288
7436
  }, generics));
7289
7437
  this.genericsScopes.pop();
7290
7438
  return result;
@@ -7297,8 +7445,6 @@ class IDLDeserializer {
7297
7445
  const generics = this.extractGenerics(node.extAttrs);
7298
7446
  this.enterGenericScope(generics);
7299
7447
  const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
7300
- if (isReferenceType(returnType))
7301
- returnType.typeArguments = this.extractTypeArguments(file, node.extAttrs, IDLExtendedAttributes.TypeArguments);
7302
7448
  const result = this.withInfo(node, createMethod((_a = node.name) !== null && _a !== void 0 ? _a : "", node.arguments.map(it => this.toIDLParameter(file, it !== null && it !== void 0 ? it : new Map())), returnType, {
7303
7449
  isStatic: node.special === "static",
7304
7450
  isAsync: node.async,
@@ -7306,7 +7452,7 @@ class IDLDeserializer {
7306
7452
  isFree
7307
7453
  }, {
7308
7454
  documentation: this.makeDocs(node),
7309
- extendedAttributes: this.toExtendedAttributes(node.extAttrs),
7455
+ extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
7310
7456
  }, generics));
7311
7457
  this.genericsScopes.pop();
7312
7458
  return result;
@@ -7314,7 +7460,7 @@ class IDLDeserializer {
7314
7460
  toIDLConstructor(file, node) {
7315
7461
  return this.withInfo(node, createConstructor(node.arguments.map(it => this.toIDLParameter(file, it)), undefined, {
7316
7462
  documentation: this.makeDocs(node),
7317
- extendedAttributes: this.toExtendedAttributes(node.extAttrs),
7463
+ extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
7318
7464
  }));
7319
7465
  }
7320
7466
  toIDLParameter(file, node) {
@@ -7327,7 +7473,7 @@ class IDLDeserializer {
7327
7473
  this.enterGenericScope(generics);
7328
7474
  const result = createCallback(node.name, node.arguments.map(it => this.toIDLParameter(file, it)), this.toIDLType(file, node.idlType, undefined), {
7329
7475
  fileName: file,
7330
- extendedAttributes: this.toExtendedAttributes(node.extAttrs),
7476
+ extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
7331
7477
  documentation: this.makeDocs(node),
7332
7478
  }, generics);
7333
7479
  if (node.extAttrs.find(it => it.name === "Synthetic")) {
@@ -7341,7 +7487,7 @@ class IDLDeserializer {
7341
7487
  const generics = this.extractGenerics(node.extAttrs);
7342
7488
  this.enterGenericScope(generics);
7343
7489
  const result = this.withInfo(node, createTypedef(node.name, this.toIDLType(file, node.idlType, undefined, node.name), generics, {
7344
- extendedAttributes: this.toExtendedAttributes(node.extAttrs),
7490
+ extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
7345
7491
  documentation: this.makeDocs(node),
7346
7492
  fileName: file,
7347
7493
  }));
@@ -7354,7 +7500,7 @@ class IDLDeserializer {
7354
7500
  toIDLDictionary(file, node) {
7355
7501
  const result = createEnum(node.name, [], {
7356
7502
  documentation: this.makeDocs(node),
7357
- extendedAttributes: this.toExtendedAttributes(node.extAttrs),
7503
+ extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
7358
7504
  fileName: file,
7359
7505
  });
7360
7506
  result.elements = node.members.map(it => this.toIDLEnumMember(file, it, result));
@@ -7362,7 +7508,7 @@ class IDLDeserializer {
7362
7508
  }
7363
7509
  toIDLNamespace(file, node) {
7364
7510
  const namespace = createNamespace(node.name, [], {
7365
- extendedAttributes: this.toExtendedAttributes(node.extAttrs),
7511
+ extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
7366
7512
  fileName: file
7367
7513
  });
7368
7514
  this.namespacePathNames.push(node.name);
@@ -7372,7 +7518,7 @@ class IDLDeserializer {
7372
7518
  }
7373
7519
  toIDLVersion(file, node) {
7374
7520
  return this.withInfo(node, createVersion(node.value, {
7375
- extendedAttributes: this.toExtendedAttributes(node.extAttrs),
7521
+ extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
7376
7522
  fileName: file
7377
7523
  }));
7378
7524
  }
@@ -7380,7 +7526,7 @@ class IDLDeserializer {
7380
7526
  return this.withInfo(node, createProperty(node.name, this.toIDLType(file, node.idlType, undefined), node.readonly, node.special === "static", isOptional(node), {
7381
7527
  documentation: this.makeDocs(node),
7382
7528
  fileName: file,
7383
- extendedAttributes: this.toExtendedAttributes(node.extAttrs)
7529
+ extendedAttributes: this.toExtendedAttributes(file, node.extAttrs)
7384
7530
  }));
7385
7531
  }
7386
7532
  toIDLEnumMember(file, node, parent) {
@@ -7399,12 +7545,18 @@ class IDLDeserializer {
7399
7545
  throw new Error(`Not representable enum initializer: ${JSON.stringify(node.default)}. Found in ${file}`);
7400
7546
  }
7401
7547
  return this.withInfo(node, createEnumMember(node.name, parent, this.toIDLType(file, node.idlType, undefined), initializer, {
7402
- extendedAttributes: this.toExtendedAttributes(node.extAttrs),
7548
+ extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
7403
7549
  }));
7404
7550
  }
7405
- toExtendedAttributes(extAttrs) {
7551
+ toExtendedAttributes(file, extAttrs) {
7406
7552
  return extAttrs.map(it => {
7407
- return this.withInfo(it, { name: it.name, value: this.toExtendedAttributeValue(it) });
7553
+ return this.withInfo(it, {
7554
+ name: it.name,
7555
+ value: this.toExtendedAttributeValue(it),
7556
+ typesValue: extendedAttributesWithTypesValue.includes(it.name)
7557
+ ? this.extractTypeArguments(file, extAttrs, it.name)
7558
+ : undefined
7559
+ });
7408
7560
  });
7409
7561
  }
7410
7562
  toExtendedAttributeValue(attr) {
@@ -7420,7 +7572,7 @@ class IDLDeserializer {
7420
7572
  const result = createEnum(node.name, [], {
7421
7573
  fileName: file,
7422
7574
  documentation: this.makeDocs(node),
7423
- extendedAttributes: this.toExtendedAttributes(node.extAttrs),
7575
+ extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
7424
7576
  });
7425
7577
  result.elements = node.values.map((it) => createEnumMember(it.value, result, IDLNumberType, undefined));
7426
7578
  return this.withInfo(node, result);
@@ -7623,8 +7775,36 @@ function compareParsingResults(oldFile, newFile) {
7623
7775
  if (paths.size > 0) {
7624
7776
  DifferenceFound.reportDiagnosticMessage([newFile.nodeLocation], "Differences found in those paths:\n" + [...paths].join("\n"));
7625
7777
  }
7778
+ return paths.size == 0;
7779
+ }
7780
+ function parseIDLFile(fileName, content, quiet) {
7781
+ const previousDiagnosticsCount = DiagnosticMessageGroup.allGroupsEntries.length;
7782
+ try {
7783
+ let newFile;
7784
+ // Temporarily is set to use old parser by default
7785
+ // Old parser has a bug, it ignores extended attributes on return types, but some pipelines depend on that behavior
7786
+ // So pipelines and old parser must be fixed before permanent switch to a new parser
7787
+ const mode = process.env.IDLPARSE;
7788
+ if (mode === "compare" || mode === "old") {
7789
+ newFile = parseIDLFileOld(fileName, content);
7790
+ if (mode === "old") {
7791
+ return newFile;
7792
+ }
7793
+ }
7794
+ const file = parseIDLFileNew(fileName, content, mode !== "compare");
7795
+ if (mode === "compare") {
7796
+ compareParsingResults(file, newFile);
7797
+ return newFile;
7798
+ }
7799
+ return file;
7800
+ }
7801
+ finally {
7802
+ if (DiagnosticMessageGroup.allGroupsEntries.length != previousDiagnosticsCount) {
7803
+ DiagnosticMessageGroup.allGroupsEntries.slice(previousDiagnosticsCount).map(it => outputDiagnosticMessageFormatted(it));
7804
+ }
7805
+ }
7626
7806
  }
7627
- function parseIdlNew(fileName, content, registerSynthetics) {
7807
+ function parseIDLFileNew(fileName, content, registerSynthetics) {
7628
7808
  let file = new Parser(fileName, content).parseIDL();
7629
7809
  const ancestors = [];
7630
7810
  const namespaces = [];
@@ -7660,18 +7840,10 @@ function parseIdlNew(fileName, content, registerSynthetics) {
7660
7840
  });
7661
7841
  return file;
7662
7842
  }
7663
- function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
7843
+ function parseIDLFileOld(fileName, content) {
7664
7844
  var _a, _b, _c;
7665
- let newFile;
7666
- const mode = process.env.IDLPARSE;
7667
- if (mode == "compare" || mode == "new") {
7668
- newFile = parseIdlNew(fileName, content, mode == "new");
7669
- if (mode == "new") {
7670
- return [newFile, new Map()];
7671
- }
7672
- }
7673
7845
  const lexicalInfo = new Map();
7674
- const deserializer = new IDLDeserializer(lexicalInfo, inheritanceMode);
7846
+ const deserializer = new IDLDeserializer(lexicalInfo);
7675
7847
  if (undefined === content) {
7676
7848
  try {
7677
7849
  content = fs__namespace.readFileSync(fileName).toString();
@@ -7720,11 +7892,7 @@ function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
7720
7892
  node.nameLocation = nameLocation;
7721
7893
  }
7722
7894
  });
7723
- if (mode == "compare") {
7724
- compareParsingResults(file, newFile);
7725
- return [newFile, new Map()];
7726
- }
7727
- return [file, lexicalInfo];
7895
+ return file;
7728
7896
  }
7729
7897
  function prepareOffsets(lines) {
7730
7898
  let offsets = [];
@@ -8501,6 +8669,9 @@ class TSLanguageWriter extends LanguageWriter {
8501
8669
  pushNamespace(namespace, options) {
8502
8670
  this.namespaceStack.push(namespace);
8503
8671
  const declaredPrefix = options.isDeclared ? "declare " : "";
8672
+ if (options.isDefault) {
8673
+ this.print(`export default ${namespace}`);
8674
+ }
8504
8675
  this.print(`export ${declaredPrefix}namespace ${namespace} {`);
8505
8676
  if (options.ident)
8506
8677
  this.pushIndent();
@@ -9067,9 +9238,6 @@ class ETSLanguageWriter extends TSLanguageWriter {
9067
9238
  this.arrayConvertor = arrayConvertor;
9068
9239
  }
9069
9240
  pushNamespace(namespace, options) {
9070
- if (options.isDefault) {
9071
- this.print(`export default ${namespace}`);
9072
- }
9073
9241
  super.pushNamespace(namespace, options);
9074
9242
  }
9075
9243
  fork(options) {
@@ -9406,7 +9574,7 @@ class InterfaceConvertor extends BaseArgConvertor {
9406
9574
  convertorSerialize(param, value, writer) {
9407
9575
  const accessor = getSerializerName(this.declaration);
9408
9576
  writer.addFeature(accessor, this.library.layout.resolve({ node: this.declaration, role: LayoutNodeRole.SERIALIZER }));
9409
- return writer.makeStatement(writer.makeStaticMethodCall(accessor, 'write', [writer.makeString(`${param}Serializer`), writer.makeString(value)]));
9577
+ return writer.makeStatement(writer.makeStaticMethodCall(accessor, 'write', [writer.makeString(`${param}Serializer`), writer.makeString(writer.escapeKeyword(value))]));
9410
9578
  }
9411
9579
  convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
9412
9580
  const accessor = getSerializerName(this.declaration);
@@ -9501,7 +9669,6 @@ class MaterializedClassConvertor extends BaseArgConvertor {
9501
9669
  case Language.CPP:
9502
9670
  return `static_cast<${generatorTypePrefix()}${qualifiedName(this.declaration, "_", "namespace.name")}>(${param})`;
9503
9671
  case Language.JAVA:
9504
- case Language.KOTLIN:
9505
9672
  case Language.CJ:
9506
9673
  return `MaterializedBase.toPeerPtr(${writer.escapeKeyword(param)})`;
9507
9674
  default:
@@ -10067,16 +10234,22 @@ const ModuleConfigurationSchema = D.object({
10067
10234
  external: D.maybe(D.boolean()),
10068
10235
  packages: T.stringArray(),
10069
10236
  useFoldersLayout: D.maybe(D.boolean()),
10237
+ tsLikePackage: D.maybe(D.string()),
10070
10238
  });
10071
10239
  const HookMethodSchema = D.object({
10072
10240
  hookName: D.string(),
10073
10241
  replaceImplementation: D.boolean()
10074
10242
  });
10243
+ const TransformOnSerializeSchema = D.object({
10244
+ from: D.string(),
10245
+ to: D.string(),
10246
+ });
10075
10247
  D.object({
10076
10248
  ApiKind: D.number(),
10077
10249
  TypePrefix: D.string(),
10078
10250
  LibraryPrefix: D.string(),
10079
10251
  OptionalPrefix: D.string(),
10252
+ transformOnSerialize: D.array(TransformOnSerializeSchema),
10080
10253
  rootComponents: T.stringArray(),
10081
10254
  standaloneComponents: T.stringArray(),
10082
10255
  parameterized: T.stringArray(),
@@ -10098,6 +10271,7 @@ const defaultCoreConfiguration = {
10098
10271
  TypePrefix: "",
10099
10272
  LibraryPrefix: "",
10100
10273
  OptionalPrefix: "",
10274
+ transformOnSerialize: [],
10101
10275
  rootComponents: [],
10102
10276
  standaloneComponents: [],
10103
10277
  parameterized: [],
@@ -13363,7 +13537,7 @@ class Importer {
13363
13537
  return it;
13364
13538
  }
13365
13539
  this.seen.add(it);
13366
- this.import(it, "../../reexport-for-generated");
13540
+ this.import(it, "../../src/reexport-for-generated");
13367
13541
  return it;
13368
13542
  }
13369
13543
  import(name, from) {
@@ -14372,12 +14546,12 @@ class DynamicEmitter {
14372
14546
  this.generatorVersion = `Unknown`;
14373
14547
  this.logDir = `./out/log-idl`;
14374
14548
  this.logCount = 0;
14375
- this.bridgesPrinter = new SingleFileEmitter((idl) => new BridgesPrinter(this.config, idl).print(), `libarkts/native/src/generated/bridges.cc`, `bridges.cc`, true);
14376
- this.bindingsPrinter = new SingleFileEmitter((idl) => new BindingsPrinter(idl).print(), `libarkts/src/generated/Es2pandaNativeModule.ts`, `Es2pandaNativeModule.ts`, true);
14377
- this.enumsPrinter = new SingleFileEmitter((idl) => new EnumsPrinter(idl).print(), `libarkts/src/generated/Es2pandaEnums.ts`, `Es2pandaEnums.ts`, true);
14378
- this.indexPrinter = new SingleFileEmitter((idl) => new IndexPrinter(idl).print(), `libarkts/src/generated/index.ts`, `index.ts`, true);
14379
- this.peersPrinter = new MultiFileEmitter((idl) => new AllPeersPrinter(this.config, idl).print(), `libarkts/src/generated/peers`, `peer.ts`, true);
14380
- this.factoryPrinter = new SingleFileEmitter((idl) => new FactoryPrinter(this.config, idl).print(), `libarkts/src/generated/factory.ts`, `factory.ts`, true);
14549
+ this.bridgesPrinter = new SingleFileEmitter((idl) => new BridgesPrinter(this.config, idl).print(), `libarkts/generated/native/bridges.cc`, `bridges.cc`, true);
14550
+ this.bindingsPrinter = new SingleFileEmitter((idl) => new BindingsPrinter(idl).print(), `libarkts/generated/Es2pandaNativeModule.ts`, `Es2pandaNativeModule.ts`, true);
14551
+ this.enumsPrinter = new SingleFileEmitter((idl) => new EnumsPrinter(idl).print(), `libarkts/generated/Es2pandaEnums.ts`, `Es2pandaEnums.ts`, true);
14552
+ this.indexPrinter = new SingleFileEmitter((idl) => new IndexPrinter(idl).print(), `libarkts/generated/index.ts`, `index.ts`, true);
14553
+ this.peersPrinter = new MultiFileEmitter((idl) => new AllPeersPrinter(this.config, idl).print(), `libarkts/generated/peers`, `peer.ts`, true);
14554
+ this.factoryPrinter = new SingleFileEmitter((idl) => new FactoryPrinter(this.config, idl).print(), `libarkts/generated/factory.ts`, `factory.ts`, true);
14381
14555
  const myJson = path__namespace$1.resolve(__dirname, '..', 'package.json');
14382
14556
  if (fs__namespace$1.existsSync(myJson)) {
14383
14557
  this.generatorVersion = (_b = (_a = lib.parse(fs__namespace$1.readFileSync(myJson).toString())) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : `Unknown`;
@@ -14771,7 +14945,7 @@ function main() {
14771
14945
  if (options.initialize) {
14772
14946
  new StaticEmitter(options.outputDir, options.pandaSdkPath).emit();
14773
14947
  }
14774
- new DynamicEmitter(options.outputDir, options.pandaSdkPath, toIDLFile(path__namespace$1.join(options.pandaSdkPath, pandaSdkIdlFilePath), { inheritanceMode: 'single' })[0], new Config(new IgnoreOptions(options.optionsFile), new NonNullableOptions(options.optionsFile), new IrHackOptions(options.optionsFile), new CodeFragmentOptions(options.optionsFile), new ExtraParameters(options.optionsFile)), options.debug).emit();
14948
+ new DynamicEmitter(options.outputDir, options.pandaSdkPath, parseIDLFile(path__namespace$1.join(options.pandaSdkPath, pandaSdkIdlFilePath)), new Config(new IgnoreOptions(options.optionsFile), new NonNullableOptions(options.optionsFile), new IrHackOptions(options.optionsFile), new CodeFragmentOptions(options.optionsFile), new ExtraParameters(options.optionsFile)), options.debug).emit();
14775
14949
  }
14776
14950
  main();
14777
14951
  //# sourceMappingURL=index.js.map