@idlizer/arktscgen 2.1.10-arktscgen-3 → 2.1.10-arktscgen-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/libarkts-copy/native/src/generated/bridges.cc +39 -37
- package/build/libarkts-copy/package.json +10 -10
- package/build/libarkts-copy/src/arkts-api/factory/nodeFactory.ts +8 -2
- package/build/libarkts-copy/src/arkts-api/node-cache.ts +11 -7
- package/build/libarkts-copy/src/arkts-api/node-utilities/CallExpression.ts +33 -1
- package/build/libarkts-copy/src/arkts-api/node-utilities/ScriptFunction.ts +46 -0
- package/build/libarkts-copy/src/arkts-api/utilities/public.ts +22 -2
- package/build/libarkts-copy/src/generated/Es2pandaEnums.ts +103 -109
- package/build/libarkts-copy/src/generated/Es2pandaNativeModule.ts +10 -10
- package/build/libarkts-copy/src/generated/factory.ts +5 -6
- package/build/libarkts-copy/src/generated/peers/ArkTsConfig.ts +3 -0
- package/build/libarkts-copy/src/generated/peers/ETSIntrinsicNode.ts +9 -15
- package/build/libarkts-copy/src/utils.ts +0 -3
- package/lib/index.js +338 -99
- package/package.json +4 -5
- package/templates/factory.ts +1 -1
- package/templates/peer.ts +1 -1
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";
|
|
@@ -3845,11 +3847,13 @@ var IDLExtendedAttributes;
|
|
|
3845
3847
|
IDLExtendedAttributes["TypeAnnotations"] = "TypeAnnotations";
|
|
3846
3848
|
IDLExtendedAttributes["TypeArguments"] = "TypeArguments";
|
|
3847
3849
|
IDLExtendedAttributes["TypeParameters"] = "TypeParameters";
|
|
3850
|
+
IDLExtendedAttributes["TypeParametersDefaults"] = "TypeParametersDefaults";
|
|
3848
3851
|
IDLExtendedAttributes["VerbatimDts"] = "VerbatimDts";
|
|
3849
3852
|
IDLExtendedAttributes["HandWrittenImplementation"] = "HandWrittenImplementation";
|
|
3850
3853
|
IDLExtendedAttributes["ExtraMethod"] = "ExtraMethod";
|
|
3851
3854
|
IDLExtendedAttributes["OverloadAlias"] = "OverloadAlias";
|
|
3852
3855
|
IDLExtendedAttributes["OverloadPriority"] = "OverloadPriority";
|
|
3856
|
+
IDLExtendedAttributes["TransformOnSerialize"] = "TransformOnSerialize";
|
|
3853
3857
|
})(IDLExtendedAttributes || (IDLExtendedAttributes = {}));
|
|
3854
3858
|
var IDLAccessorAttribute;
|
|
3855
3859
|
(function (IDLAccessorAttribute) {
|
|
@@ -4188,6 +4192,7 @@ const IDLSerializerBuffer = createPrimitiveType('SerializerBuffer');
|
|
|
4188
4192
|
const IDLFunctionType = createPrimitiveType('Function');
|
|
4189
4193
|
const IDLCustomObjectType = createPrimitiveType('CustomObject');
|
|
4190
4194
|
createPrimitiveType('InteropReturnBuffer');
|
|
4195
|
+
const IDLNullTypeName = "idlize.stdlib.Null";
|
|
4191
4196
|
function createNamespace(name, members, nodeInitializer) {
|
|
4192
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 });
|
|
4193
4198
|
}
|
|
@@ -4559,23 +4564,29 @@ function escapeIDLKeyword(name) {
|
|
|
4559
4564
|
const printedIndentInc = "[[indent-inc]]";
|
|
4560
4565
|
const printedIndentDec = "[[indent-dec]]";
|
|
4561
4566
|
function printType(type, options) {
|
|
4567
|
+
var _a;
|
|
4562
4568
|
if (!type)
|
|
4563
4569
|
throw new Error("Missing type");
|
|
4564
4570
|
if (isInterface$1(type))
|
|
4565
4571
|
return type.name;
|
|
4566
|
-
if (isOptionalType(type))
|
|
4567
|
-
|
|
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
|
+
}
|
|
4568
4580
|
if (isPrimitiveType(type))
|
|
4569
4581
|
return type.name;
|
|
4570
4582
|
if (isContainerType(type))
|
|
4571
4583
|
return `${type.containerKind}<${type.elementType.map(it => printType(it)).join(", ")}>`;
|
|
4572
4584
|
if (isReferenceType(type)) {
|
|
4573
|
-
const extAttrs = type.extendedAttributes ? Array.from(type.extendedAttributes) : [];
|
|
4574
4585
|
if (type.typeArguments)
|
|
4575
|
-
|
|
4576
|
-
if (!
|
|
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))
|
|
4577
4588
|
return type.name;
|
|
4578
|
-
let res = `[${quoteAttributeValues(
|
|
4589
|
+
let res = `[${quoteAttributeValues(type.extendedAttributes)}] ${type.name}`;
|
|
4579
4590
|
if (options === null || options === void 0 ? void 0 : options.bracketsAroundReferenceTypeWithExtAttrs)
|
|
4580
4591
|
return `(${res})`;
|
|
4581
4592
|
return res;
|
|
@@ -4645,18 +4656,31 @@ function printExtendedAttributes(idl, indentLevel) {
|
|
|
4645
4656
|
break;
|
|
4646
4657
|
}
|
|
4647
4658
|
const attributes = Array.from(idl.extendedAttributes || []);
|
|
4648
|
-
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))
|
|
4649
4660
|
attributes.push({ name: IDLExtendedAttributes.TypeParameters, value: typeParameters.join(",") });
|
|
4650
|
-
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))
|
|
4651
4662
|
attributes.push({ name: IDLExtendedAttributes.TypeArguments, value: typeArguments.map(it => printType(it)).join(",") });
|
|
4652
4663
|
if (idl.documentation) {
|
|
4653
4664
|
let docs = {
|
|
4654
4665
|
name: IDLExtendedAttributes.Documentation,
|
|
4655
4666
|
value: idl.documentation
|
|
4656
4667
|
};
|
|
4657
|
-
attributes.
|
|
4668
|
+
attributes.unshift(docs);
|
|
4669
|
+
}
|
|
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 [];
|
|
4658
4682
|
}
|
|
4659
|
-
const attrSpec = quoteAttributeValues(
|
|
4683
|
+
const attrSpec = quoteAttributeValues(actualAttributes);
|
|
4660
4684
|
return attrSpec ? [`[${attrSpec}]`] : [];
|
|
4661
4685
|
}
|
|
4662
4686
|
const attributesToQuote = new Set([
|
|
@@ -4668,6 +4692,7 @@ const attributesToQuote = new Set([
|
|
|
4668
4692
|
IDLExtendedAttributes.TraceKey,
|
|
4669
4693
|
IDLExtendedAttributes.TypeArguments,
|
|
4670
4694
|
IDLExtendedAttributes.TypeParameters,
|
|
4695
|
+
IDLExtendedAttributes.TypeParametersDefaults,
|
|
4671
4696
|
]);
|
|
4672
4697
|
function quoteAttributeValues(attributes) {
|
|
4673
4698
|
return attributes === null || attributes === void 0 ? void 0 : attributes.map(it => {
|
|
@@ -4856,6 +4881,17 @@ function getExtAttribute(node, name) {
|
|
|
4856
4881
|
var _a, _b;
|
|
4857
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;
|
|
4858
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
|
+
}
|
|
4859
4895
|
const IDLContainerUtils = {
|
|
4860
4896
|
isRecord: (x) => isContainerType(x) && x.containerKind === 'record',
|
|
4861
4897
|
isSequence: (x) => isContainerType(x) && x.containerKind === 'sequence',
|
|
@@ -4904,11 +4940,30 @@ function linearizeNamespaceMembers(entries) {
|
|
|
4904
4940
|
return linearized;
|
|
4905
4941
|
}
|
|
4906
4942
|
|
|
4943
|
+
const stdlibModule = {
|
|
4944
|
+
name: "__stdlib",
|
|
4945
|
+
packages: [""],
|
|
4946
|
+
useFoldersLayout: false,
|
|
4947
|
+
external: true,
|
|
4948
|
+
tsLikePackage: "__stdlib"
|
|
4949
|
+
};
|
|
4907
4950
|
const modulesCache = new Map();
|
|
4951
|
+
/**
|
|
4952
|
+
* Is source submodule of target.
|
|
4953
|
+
* Every source is submodule if target is empty string
|
|
4954
|
+
* @example `isSubmodule("a.b.c", "a") === true`
|
|
4955
|
+
* @example `isSubmodule("a", "a.b.c") === false`
|
|
4956
|
+
* @example `isSubmodule("a.b.cd", "a.b.c") === false`
|
|
4957
|
+
*/
|
|
4958
|
+
function isSubmodule(source, target) {
|
|
4959
|
+
return source === target
|
|
4960
|
+
|| target === ""
|
|
4961
|
+
|| source.startsWith(target + '.');
|
|
4962
|
+
}
|
|
4908
4963
|
function isInModule(nodeOrPackage, module) {
|
|
4909
4964
|
if (typeof nodeOrPackage === 'object')
|
|
4910
4965
|
return isInModule(getPackageName(nodeOrPackage), module);
|
|
4911
|
-
return module.packages.some(modulePackage => nodeOrPackage
|
|
4966
|
+
return module.packages.some(modulePackage => isSubmodule(nodeOrPackage, modulePackage));
|
|
4912
4967
|
}
|
|
4913
4968
|
function isInExternalModule(node) {
|
|
4914
4969
|
var _a;
|
|
@@ -4931,7 +4986,7 @@ function getApplicableModuleFor(packageName) {
|
|
|
4931
4986
|
if (applicableModules.length === 0) {
|
|
4932
4987
|
if (packageName === '') {
|
|
4933
4988
|
console.error("WARNING: use current module for empty package");
|
|
4934
|
-
return
|
|
4989
|
+
return stdlibModule;
|
|
4935
4990
|
}
|
|
4936
4991
|
if (packageName.startsWith(`idlize.`)) {
|
|
4937
4992
|
return currentModule();
|
|
@@ -5256,8 +5311,11 @@ class LambdaExpression {
|
|
|
5256
5311
|
if (this.body) {
|
|
5257
5312
|
writer.writeStatement(new BlockStatement(this.body, isScoped, false));
|
|
5258
5313
|
}
|
|
5259
|
-
writer.features.forEach((
|
|
5260
|
-
|
|
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);
|
|
5261
5319
|
});
|
|
5262
5320
|
return writer.getOutput()
|
|
5263
5321
|
.map(line => (line.endsWith('{') || line.endsWith('}') || line.endsWith(';')) ? line : `${line};`)
|
|
@@ -5392,8 +5450,11 @@ class LanguageWriter {
|
|
|
5392
5450
|
return this.printer.indentDepth();
|
|
5393
5451
|
}
|
|
5394
5452
|
maybeSemicolon() { return ";"; }
|
|
5395
|
-
addFeature(
|
|
5396
|
-
|
|
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 });
|
|
5397
5458
|
}
|
|
5398
5459
|
// version of makeCast which uses TypeCheck.typeCast<T>(value) call for ETS language writer
|
|
5399
5460
|
// Use it only if TypeChecker class is added as import to the generated file
|
|
@@ -5459,7 +5520,7 @@ class LanguageWriter {
|
|
|
5459
5520
|
makeThis() {
|
|
5460
5521
|
return new StringExpression("this");
|
|
5461
5522
|
}
|
|
5462
|
-
makeNull(
|
|
5523
|
+
makeNull(type) {
|
|
5463
5524
|
return new StringExpression("null");
|
|
5464
5525
|
}
|
|
5465
5526
|
makeVoid() {
|
|
@@ -6144,12 +6205,14 @@ const IncorrectLiteral = new DiagnosticMessageGroup("error", "IncorrectLiteral",
|
|
|
6144
6205
|
const IncorrectIdentifier = new DiagnosticMessageGroup("error", "IncorrectIdentifier", "Incorrect identifier");
|
|
6145
6206
|
const UnexpectedToken = new DiagnosticMessageGroup("error", "UnexpectedToken", "Unexpected token");
|
|
6146
6207
|
const UnexpectedEndOfFile = new DiagnosticMessageGroup("fatal", "UnexpectedEndOfFile", "Unexpected end of file");
|
|
6208
|
+
const UnrecognizedSymbols = new DiagnosticMessageGroup("fatal", "UnrecognizedSymbols", "Unrecognized symbols");
|
|
6147
6209
|
const UnsupportedSyntax = new DiagnosticMessageGroup("error", "UnsupportedSyntax", "Unsupported syntax");
|
|
6148
6210
|
const WrongDeclarationPlacement = new DiagnosticMessageGroup("error", "WrongDeclarationPlacement", "Wrong declaration placement");
|
|
6149
6211
|
const ExpectedPrimitiveType = new DiagnosticMessageGroup("error", "ExpectedPrimitiveType", "Expected primitive type");
|
|
6150
6212
|
const ExpectedReferenceType = new DiagnosticMessageGroup("error", "ExpectedReferenceType", "Expected reference type");
|
|
6151
6213
|
const ExpectedGenericArguments = new DiagnosticMessageGroup("error", "ExpectedGenericArguments", "Expected generic arguments");
|
|
6152
6214
|
const UnexpectedGenericArguments = new DiagnosticMessageGroup("error", "UnexpectedGenericArguments", "Unexpected generic arguments");
|
|
6215
|
+
const InlineParsingDepthExceeded = new DiagnosticMessageGroup("fatal", "InlineParsingDepthExceeded", "Inline parsing depth exceeded");
|
|
6153
6216
|
class FatalParserException extends Error {
|
|
6154
6217
|
constructor(diagnosticMessages) {
|
|
6155
6218
|
super();
|
|
@@ -6181,7 +6244,7 @@ class Parser {
|
|
|
6181
6244
|
// TypeParameters support
|
|
6182
6245
|
this._generics = [];
|
|
6183
6246
|
// TypeArguments parsing support
|
|
6184
|
-
this.
|
|
6247
|
+
this._inLiteralParsingLevel = 0;
|
|
6185
6248
|
// symTokens = ["(", ")", "[", "]", "{", "}", ",", "...", ":", ";", "<", "=", ">", "?"]
|
|
6186
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;
|
|
6187
6250
|
this._reInteger = /-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/y;
|
|
@@ -6269,17 +6332,17 @@ class Parser {
|
|
|
6269
6332
|
this._curToken = { kind: TokenKind.End, value: "", location: { documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } } };
|
|
6270
6333
|
return;
|
|
6271
6334
|
}
|
|
6272
|
-
if (this.
|
|
6335
|
+
if (this._inLiteralParsingLevel && (this.content[this._curOffset] == "\"" || this.content[this._curOffset] == "'")) {
|
|
6273
6336
|
// TypeArguments parsing support
|
|
6274
6337
|
const pos = { line: this._curLine + 1, character: this._curOffset - this.offsets[this._curLine] + 1 };
|
|
6275
|
-
this._curToken = { kind: TokenKind.Symbol, value:
|
|
6338
|
+
this._curToken = { kind: TokenKind.Symbol, value: this.content[this._curOffset], location: { documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } } };
|
|
6276
6339
|
this._curOffset += 1;
|
|
6277
6340
|
return;
|
|
6278
6341
|
}
|
|
6279
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));
|
|
6280
6343
|
if (!token) {
|
|
6281
6344
|
const pos = { line: this._curLine + 1, character: this._curOffset - this.offsets[this._curLine] + 1 };
|
|
6282
|
-
|
|
6345
|
+
UnrecognizedSymbols.throwDiagnosticMessage([{ documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } }]);
|
|
6283
6346
|
}
|
|
6284
6347
|
// Uncomment in case of parser debugging
|
|
6285
6348
|
// if (token) {
|
|
@@ -6573,28 +6636,32 @@ class Parser {
|
|
|
6573
6636
|
duplicates.add(name.value);
|
|
6574
6637
|
}
|
|
6575
6638
|
names.add(name.value);
|
|
6576
|
-
if (name.value == IDLExtendedAttributes.TypeArguments) {
|
|
6639
|
+
if (name.value == IDLExtendedAttributes.TypeArguments || name.value == IDLExtendedAttributes.TypeParametersDefaults) {
|
|
6577
6640
|
// TypeArguments parsing support
|
|
6578
6641
|
try {
|
|
6579
|
-
this.
|
|
6642
|
+
this._inLiteralParsingLevel += 1;
|
|
6643
|
+
if (this._inLiteralParsingLevel > 2) {
|
|
6644
|
+
InlineParsingDepthExceeded.throwDiagnosticMessage([this.curLocation]);
|
|
6645
|
+
}
|
|
6580
6646
|
this.skip("=");
|
|
6581
6647
|
const vloc = this.trackLocation();
|
|
6582
6648
|
const start = this._curOffset; // Already after first quote
|
|
6583
|
-
this.skip("\"");
|
|
6649
|
+
this.skip(this._inLiteralParsingLevel == 2 ? "'" : "\"");
|
|
6584
6650
|
const types = this.parseTypeList();
|
|
6585
6651
|
const end = this._curOffset - 1; // Already after second quote
|
|
6586
|
-
this.
|
|
6587
|
-
this.
|
|
6652
|
+
this._inLiteralParsingLevel -= 1;
|
|
6653
|
+
// Note that second this._inLiteralParsingLevel comparison happens after decrement
|
|
6654
|
+
this.skip(this._inLiteralParsingLevel == 1 ? "'" : "\"");
|
|
6588
6655
|
const stringValue = this.content.slice(start, end);
|
|
6589
6656
|
ext.push({ name: name.value, value: stringValue, typesValue: types, nameLocation: name.location, valueLocation: vloc() });
|
|
6590
6657
|
}
|
|
6591
6658
|
catch (e) {
|
|
6592
|
-
|
|
6659
|
+
if (e instanceof DiagnosticException && e.diagnosticMessage.severity != "fatal") {
|
|
6660
|
+
this.skipToAfter("\"");
|
|
6661
|
+
}
|
|
6662
|
+
this._inLiteralParsingLevel = 0;
|
|
6593
6663
|
throw e;
|
|
6594
6664
|
}
|
|
6595
|
-
finally {
|
|
6596
|
-
this._enableInLiteralParsing = false;
|
|
6597
|
-
}
|
|
6598
6665
|
}
|
|
6599
6666
|
else {
|
|
6600
6667
|
let value;
|
|
@@ -6766,9 +6833,9 @@ class Parser {
|
|
|
6766
6833
|
const name = this.parseSingleIdentifier();
|
|
6767
6834
|
this.skip("=");
|
|
6768
6835
|
const value = this.parseLiteral();
|
|
6769
|
-
const extracted = extractLiteral(value);
|
|
6770
6836
|
this.skip(";");
|
|
6771
|
-
|
|
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 });
|
|
6772
6839
|
}
|
|
6773
6840
|
parseAttribute() {
|
|
6774
6841
|
const sloc = this.trackLocation();
|
|
@@ -6852,11 +6919,14 @@ class Parser {
|
|
|
6852
6919
|
const sloc = this.trackLocation();
|
|
6853
6920
|
const type = this.parsePrimitiveType();
|
|
6854
6921
|
const name = this.parseSingleIdentifier();
|
|
6855
|
-
|
|
6856
|
-
|
|
6857
|
-
|
|
6922
|
+
let value;
|
|
6923
|
+
let extracted;
|
|
6924
|
+
if (this.seeAndSkip("=")) {
|
|
6925
|
+
value = this.parseLiteral();
|
|
6926
|
+
extracted = extractLiteral(value);
|
|
6927
|
+
}
|
|
6858
6928
|
this.skip(";");
|
|
6859
|
-
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 });
|
|
6860
6930
|
}
|
|
6861
6931
|
parsePackage() {
|
|
6862
6932
|
const sloc = this.trackLocation();
|
|
@@ -7022,6 +7092,93 @@ const builtinTypesList = [IDLPointerType, IDLVoidType, IDLBooleanType,
|
|
|
7022
7092
|
const builtinTypes = new Map(builtinTypesList.map(x => [x.name, x]));
|
|
7023
7093
|
const builtinGenericTypeNames = new Set(["sequence", "record", "Promise"]);
|
|
7024
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
|
+
|
|
7025
7182
|
/*
|
|
7026
7183
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
7027
7184
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -7039,6 +7196,10 @@ const builtinGenericTypeNames = new Set(["sequence", "record", "Promise"]);
|
|
|
7039
7196
|
function getTokens(node) {
|
|
7040
7197
|
return node.tokens;
|
|
7041
7198
|
}
|
|
7199
|
+
const extendedAttributesWithTypesValue = [
|
|
7200
|
+
IDLExtendedAttributes.TypeArguments,
|
|
7201
|
+
IDLExtendedAttributes.TypeParametersDefaults,
|
|
7202
|
+
];
|
|
7042
7203
|
const syntheticTypes = new Map();
|
|
7043
7204
|
function addSyntheticType(name, type) {
|
|
7044
7205
|
if (syntheticTypes.has(name)) {
|
|
@@ -7050,9 +7211,8 @@ class IDLDeserializer {
|
|
|
7050
7211
|
enterGenericScope(generics) {
|
|
7051
7212
|
this.genericsScopes.push(new Set(generics !== null && generics !== void 0 ? generics : []));
|
|
7052
7213
|
}
|
|
7053
|
-
constructor(info
|
|
7214
|
+
constructor(info) {
|
|
7054
7215
|
this.info = info;
|
|
7055
|
-
this.inheritanceMode = inheritanceMode;
|
|
7056
7216
|
this.namespacePathNames = [];
|
|
7057
7217
|
this.currentPackage = [];
|
|
7058
7218
|
this.genericsScopes = [];
|
|
@@ -7149,7 +7309,7 @@ class IDLDeserializer {
|
|
|
7149
7309
|
node.inheritance.forEach(it => {
|
|
7150
7310
|
const attributes = it.extAttrs;
|
|
7151
7311
|
const parentTypeArgs = this.extractTypeArguments(file, attributes !== null && attributes !== void 0 ? attributes : [], IDLExtendedAttributes.TypeArguments);
|
|
7152
|
-
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)
|
|
7153
7313
|
const ref = createReferenceType(it.inheritance, parentTypeArgs, {
|
|
7154
7314
|
extendedAttributes: attrs
|
|
7155
7315
|
});
|
|
@@ -7169,7 +7329,7 @@ class IDLDeserializer {
|
|
|
7169
7329
|
.map(it => this.toIDLCallable(file, it)), generics, {
|
|
7170
7330
|
fileName: file,
|
|
7171
7331
|
documentation: this.makeDocs(node),
|
|
7172
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7332
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
7173
7333
|
});
|
|
7174
7334
|
this.genericsScopes.pop();
|
|
7175
7335
|
this.info.set(result, getTokens(node));
|
|
@@ -7185,6 +7345,8 @@ class IDLDeserializer {
|
|
|
7185
7345
|
// is it IDLStringType?
|
|
7186
7346
|
const refType = createReferenceType(type);
|
|
7187
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)
|
|
7188
7350
|
refType.typeArguments = this.extractTypeArguments(file, extAttrs, IDLExtendedAttributes.TypeArguments);
|
|
7189
7351
|
return refType;
|
|
7190
7352
|
}
|
|
@@ -7242,7 +7404,7 @@ class IDLDeserializer {
|
|
|
7242
7404
|
idlRefType = ref;
|
|
7243
7405
|
}
|
|
7244
7406
|
idlRefType.fileName = file;
|
|
7245
|
-
idlRefType.extendedAttributes = this.toExtendedAttributes(combinedExtAttrs);
|
|
7407
|
+
idlRefType.extendedAttributes = this.toExtendedAttributes(file, combinedExtAttrs);
|
|
7246
7408
|
return this.withInfo(type, idlRefType);
|
|
7247
7409
|
}
|
|
7248
7410
|
if (isSequenceTypeDescription(type) || isPromiseTypeDescription(type) || isRecordTypeDescription(type)) {
|
|
@@ -7270,7 +7432,7 @@ class IDLDeserializer {
|
|
|
7270
7432
|
isAsync: node.async,
|
|
7271
7433
|
}, {
|
|
7272
7434
|
documentation: this.makeDocs(node),
|
|
7273
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7435
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
7274
7436
|
}, generics));
|
|
7275
7437
|
this.genericsScopes.pop();
|
|
7276
7438
|
return result;
|
|
@@ -7283,8 +7445,6 @@ class IDLDeserializer {
|
|
|
7283
7445
|
const generics = this.extractGenerics(node.extAttrs);
|
|
7284
7446
|
this.enterGenericScope(generics);
|
|
7285
7447
|
const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
|
|
7286
|
-
if (isReferenceType(returnType))
|
|
7287
|
-
returnType.typeArguments = this.extractTypeArguments(file, node.extAttrs, IDLExtendedAttributes.TypeArguments);
|
|
7288
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, {
|
|
7289
7449
|
isStatic: node.special === "static",
|
|
7290
7450
|
isAsync: node.async,
|
|
@@ -7292,7 +7452,7 @@ class IDLDeserializer {
|
|
|
7292
7452
|
isFree
|
|
7293
7453
|
}, {
|
|
7294
7454
|
documentation: this.makeDocs(node),
|
|
7295
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7455
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
7296
7456
|
}, generics));
|
|
7297
7457
|
this.genericsScopes.pop();
|
|
7298
7458
|
return result;
|
|
@@ -7300,7 +7460,7 @@ class IDLDeserializer {
|
|
|
7300
7460
|
toIDLConstructor(file, node) {
|
|
7301
7461
|
return this.withInfo(node, createConstructor(node.arguments.map(it => this.toIDLParameter(file, it)), undefined, {
|
|
7302
7462
|
documentation: this.makeDocs(node),
|
|
7303
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7463
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
7304
7464
|
}));
|
|
7305
7465
|
}
|
|
7306
7466
|
toIDLParameter(file, node) {
|
|
@@ -7313,7 +7473,7 @@ class IDLDeserializer {
|
|
|
7313
7473
|
this.enterGenericScope(generics);
|
|
7314
7474
|
const result = createCallback(node.name, node.arguments.map(it => this.toIDLParameter(file, it)), this.toIDLType(file, node.idlType, undefined), {
|
|
7315
7475
|
fileName: file,
|
|
7316
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7476
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
7317
7477
|
documentation: this.makeDocs(node),
|
|
7318
7478
|
}, generics);
|
|
7319
7479
|
if (node.extAttrs.find(it => it.name === "Synthetic")) {
|
|
@@ -7327,7 +7487,7 @@ class IDLDeserializer {
|
|
|
7327
7487
|
const generics = this.extractGenerics(node.extAttrs);
|
|
7328
7488
|
this.enterGenericScope(generics);
|
|
7329
7489
|
const result = this.withInfo(node, createTypedef(node.name, this.toIDLType(file, node.idlType, undefined, node.name), generics, {
|
|
7330
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7490
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
7331
7491
|
documentation: this.makeDocs(node),
|
|
7332
7492
|
fileName: file,
|
|
7333
7493
|
}));
|
|
@@ -7340,7 +7500,7 @@ class IDLDeserializer {
|
|
|
7340
7500
|
toIDLDictionary(file, node) {
|
|
7341
7501
|
const result = createEnum(node.name, [], {
|
|
7342
7502
|
documentation: this.makeDocs(node),
|
|
7343
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7503
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
7344
7504
|
fileName: file,
|
|
7345
7505
|
});
|
|
7346
7506
|
result.elements = node.members.map(it => this.toIDLEnumMember(file, it, result));
|
|
@@ -7348,7 +7508,7 @@ class IDLDeserializer {
|
|
|
7348
7508
|
}
|
|
7349
7509
|
toIDLNamespace(file, node) {
|
|
7350
7510
|
const namespace = createNamespace(node.name, [], {
|
|
7351
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7511
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
7352
7512
|
fileName: file
|
|
7353
7513
|
});
|
|
7354
7514
|
this.namespacePathNames.push(node.name);
|
|
@@ -7358,7 +7518,7 @@ class IDLDeserializer {
|
|
|
7358
7518
|
}
|
|
7359
7519
|
toIDLVersion(file, node) {
|
|
7360
7520
|
return this.withInfo(node, createVersion(node.value, {
|
|
7361
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7521
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
7362
7522
|
fileName: file
|
|
7363
7523
|
}));
|
|
7364
7524
|
}
|
|
@@ -7366,7 +7526,7 @@ class IDLDeserializer {
|
|
|
7366
7526
|
return this.withInfo(node, createProperty(node.name, this.toIDLType(file, node.idlType, undefined), node.readonly, node.special === "static", isOptional(node), {
|
|
7367
7527
|
documentation: this.makeDocs(node),
|
|
7368
7528
|
fileName: file,
|
|
7369
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs)
|
|
7529
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs)
|
|
7370
7530
|
}));
|
|
7371
7531
|
}
|
|
7372
7532
|
toIDLEnumMember(file, node, parent) {
|
|
@@ -7385,12 +7545,18 @@ class IDLDeserializer {
|
|
|
7385
7545
|
throw new Error(`Not representable enum initializer: ${JSON.stringify(node.default)}. Found in ${file}`);
|
|
7386
7546
|
}
|
|
7387
7547
|
return this.withInfo(node, createEnumMember(node.name, parent, this.toIDLType(file, node.idlType, undefined), initializer, {
|
|
7388
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7548
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
7389
7549
|
}));
|
|
7390
7550
|
}
|
|
7391
|
-
toExtendedAttributes(extAttrs) {
|
|
7551
|
+
toExtendedAttributes(file, extAttrs) {
|
|
7392
7552
|
return extAttrs.map(it => {
|
|
7393
|
-
return this.withInfo(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
|
+
});
|
|
7394
7560
|
});
|
|
7395
7561
|
}
|
|
7396
7562
|
toExtendedAttributeValue(attr) {
|
|
@@ -7406,7 +7572,7 @@ class IDLDeserializer {
|
|
|
7406
7572
|
const result = createEnum(node.name, [], {
|
|
7407
7573
|
fileName: file,
|
|
7408
7574
|
documentation: this.makeDocs(node),
|
|
7409
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
7575
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
7410
7576
|
});
|
|
7411
7577
|
result.elements = node.values.map((it) => createEnumMember(it.value, result, IDLNumberType, undefined));
|
|
7412
7578
|
return this.withInfo(node, result);
|
|
@@ -7609,8 +7775,36 @@ function compareParsingResults(oldFile, newFile) {
|
|
|
7609
7775
|
if (paths.size > 0) {
|
|
7610
7776
|
DifferenceFound.reportDiagnosticMessage([newFile.nodeLocation], "Differences found in those paths:\n" + [...paths].join("\n"));
|
|
7611
7777
|
}
|
|
7778
|
+
return paths.size == 0;
|
|
7612
7779
|
}
|
|
7613
|
-
function
|
|
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
|
+
}
|
|
7806
|
+
}
|
|
7807
|
+
function parseIDLFileNew(fileName, content, registerSynthetics) {
|
|
7614
7808
|
let file = new Parser(fileName, content).parseIDL();
|
|
7615
7809
|
const ancestors = [];
|
|
7616
7810
|
const namespaces = [];
|
|
@@ -7646,18 +7840,10 @@ function parseIdlNew(fileName, content, registerSynthetics) {
|
|
|
7646
7840
|
});
|
|
7647
7841
|
return file;
|
|
7648
7842
|
}
|
|
7649
|
-
function
|
|
7843
|
+
function parseIDLFileOld(fileName, content) {
|
|
7650
7844
|
var _a, _b, _c;
|
|
7651
|
-
let newFile;
|
|
7652
|
-
const mode = process.env.IDLPARSE;
|
|
7653
|
-
if (mode == "compare" || mode == "new") {
|
|
7654
|
-
newFile = parseIdlNew(fileName, content, mode == "new");
|
|
7655
|
-
if (mode == "new") {
|
|
7656
|
-
return [newFile, new Map()];
|
|
7657
|
-
}
|
|
7658
|
-
}
|
|
7659
7845
|
const lexicalInfo = new Map();
|
|
7660
|
-
const deserializer = new IDLDeserializer(lexicalInfo
|
|
7846
|
+
const deserializer = new IDLDeserializer(lexicalInfo);
|
|
7661
7847
|
if (undefined === content) {
|
|
7662
7848
|
try {
|
|
7663
7849
|
content = fs__namespace.readFileSync(fileName).toString();
|
|
@@ -7706,11 +7892,7 @@ function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
|
|
|
7706
7892
|
node.nameLocation = nameLocation;
|
|
7707
7893
|
}
|
|
7708
7894
|
});
|
|
7709
|
-
|
|
7710
|
-
compareParsingResults(file, newFile);
|
|
7711
|
-
return [newFile, new Map()];
|
|
7712
|
-
}
|
|
7713
|
-
return [file, lexicalInfo];
|
|
7895
|
+
return file;
|
|
7714
7896
|
}
|
|
7715
7897
|
function prepareOffsets(lines) {
|
|
7716
7898
|
let offsets = [];
|
|
@@ -8227,7 +8409,7 @@ class CppLanguageWriter extends CLikeLanguageWriter {
|
|
|
8227
8409
|
writePrintLog(message) {
|
|
8228
8410
|
this.print(`printf("${message}\\n");`);
|
|
8229
8411
|
}
|
|
8230
|
-
makeDefinedCheck(value, isTag) {
|
|
8412
|
+
makeDefinedCheck(value, type, isTag) {
|
|
8231
8413
|
return this.makeString(isTag ? `${value} != ${PrimitiveTypeList.UndefinedTag}`
|
|
8232
8414
|
: `runtimeType(${value}) != ${PrimitiveTypeList.UndefinedRuntime}`);
|
|
8233
8415
|
}
|
|
@@ -8487,6 +8669,9 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
8487
8669
|
pushNamespace(namespace, options) {
|
|
8488
8670
|
this.namespaceStack.push(namespace);
|
|
8489
8671
|
const declaredPrefix = options.isDeclared ? "declare " : "";
|
|
8672
|
+
if (options.isDefault) {
|
|
8673
|
+
this.print(`export default ${namespace}`);
|
|
8674
|
+
}
|
|
8490
8675
|
this.print(`export ${declaredPrefix}namespace ${namespace} {`);
|
|
8491
8676
|
if (options.ident)
|
|
8492
8677
|
this.pushIndent();
|
|
@@ -8655,7 +8840,9 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
8655
8840
|
const normalizedArgs = signature.args.map((it, i) => isOptionalType(it) && signature.isArgOptional(i) ? maybeUnwrapOptionalType(it) : it);
|
|
8656
8841
|
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
8842
|
}
|
|
8658
|
-
makeNull() {
|
|
8843
|
+
makeNull(type) {
|
|
8844
|
+
if (type && hasExtAttribute(type, IDLExtendedAttributes.UnionOnlyNull))
|
|
8845
|
+
return new StringExpression("null");
|
|
8659
8846
|
return new StringExpression("undefined");
|
|
8660
8847
|
}
|
|
8661
8848
|
makeAssign(variableName, type, expr, isDeclared = true, isConst = true, options) {
|
|
@@ -8712,7 +8899,15 @@ class TSLanguageWriter extends LanguageWriter {
|
|
|
8712
8899
|
makeRuntimeType(rt) {
|
|
8713
8900
|
return this.makeString(`RuntimeType.${RuntimeType[rt]}`);
|
|
8714
8901
|
}
|
|
8715
|
-
makeDefinedCheck(value) {
|
|
8902
|
+
makeDefinedCheck(value, type) {
|
|
8903
|
+
if (type) {
|
|
8904
|
+
if (hasExtAttribute(type, IDLExtendedAttributes.UnionWithNull)) {
|
|
8905
|
+
return this.makeString(`${value} !== undefined && ${value} !== null`);
|
|
8906
|
+
}
|
|
8907
|
+
else if (hasExtAttribute(type, IDLExtendedAttributes.UnionOnlyNull)) {
|
|
8908
|
+
return this.makeString(`${value} !== null`);
|
|
8909
|
+
}
|
|
8910
|
+
}
|
|
8716
8911
|
return this.makeString(`${value} !== undefined`);
|
|
8717
8912
|
}
|
|
8718
8913
|
makeTupleAlloc(option) {
|
|
@@ -9043,9 +9238,6 @@ class ETSLanguageWriter extends TSLanguageWriter {
|
|
|
9043
9238
|
this.arrayConvertor = arrayConvertor;
|
|
9044
9239
|
}
|
|
9045
9240
|
pushNamespace(namespace, options) {
|
|
9046
|
-
if (options.isDefault) {
|
|
9047
|
-
this.print(`export default ${namespace}`);
|
|
9048
|
-
}
|
|
9049
9241
|
super.pushNamespace(namespace, options);
|
|
9050
9242
|
}
|
|
9051
9243
|
fork(options) {
|
|
@@ -9382,7 +9574,7 @@ class InterfaceConvertor extends BaseArgConvertor {
|
|
|
9382
9574
|
convertorSerialize(param, value, writer) {
|
|
9383
9575
|
const accessor = getSerializerName(this.declaration);
|
|
9384
9576
|
writer.addFeature(accessor, this.library.layout.resolve({ node: this.declaration, role: LayoutNodeRole.SERIALIZER }));
|
|
9385
|
-
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))]));
|
|
9386
9578
|
}
|
|
9387
9579
|
convertorDeserialize(bufferName, deserializerName, assigneer, writer) {
|
|
9388
9580
|
const accessor = getSerializerName(this.declaration);
|
|
@@ -9477,7 +9669,6 @@ class MaterializedClassConvertor extends BaseArgConvertor {
|
|
|
9477
9669
|
case Language.CPP:
|
|
9478
9670
|
return `static_cast<${generatorTypePrefix()}${qualifiedName(this.declaration, "_", "namespace.name")}>(${param})`;
|
|
9479
9671
|
case Language.JAVA:
|
|
9480
|
-
case Language.KOTLIN:
|
|
9481
9672
|
case Language.CJ:
|
|
9482
9673
|
return `MaterializedBase.toPeerPtr(${writer.escapeKeyword(param)})`;
|
|
9483
9674
|
default:
|
|
@@ -10043,16 +10234,22 @@ const ModuleConfigurationSchema = D.object({
|
|
|
10043
10234
|
external: D.maybe(D.boolean()),
|
|
10044
10235
|
packages: T.stringArray(),
|
|
10045
10236
|
useFoldersLayout: D.maybe(D.boolean()),
|
|
10237
|
+
tsLikePackage: D.maybe(D.string()),
|
|
10046
10238
|
});
|
|
10047
10239
|
const HookMethodSchema = D.object({
|
|
10048
10240
|
hookName: D.string(),
|
|
10049
10241
|
replaceImplementation: D.boolean()
|
|
10050
10242
|
});
|
|
10243
|
+
const TransformOnSerializeSchema = D.object({
|
|
10244
|
+
from: D.string(),
|
|
10245
|
+
to: D.string(),
|
|
10246
|
+
});
|
|
10051
10247
|
D.object({
|
|
10052
10248
|
ApiKind: D.number(),
|
|
10053
10249
|
TypePrefix: D.string(),
|
|
10054
10250
|
LibraryPrefix: D.string(),
|
|
10055
10251
|
OptionalPrefix: D.string(),
|
|
10252
|
+
transformOnSerialize: D.array(TransformOnSerializeSchema),
|
|
10056
10253
|
rootComponents: T.stringArray(),
|
|
10057
10254
|
standaloneComponents: T.stringArray(),
|
|
10058
10255
|
parameterized: T.stringArray(),
|
|
@@ -10074,6 +10271,7 @@ const defaultCoreConfiguration = {
|
|
|
10074
10271
|
TypePrefix: "",
|
|
10075
10272
|
LibraryPrefix: "",
|
|
10076
10273
|
OptionalPrefix: "",
|
|
10274
|
+
transformOnSerialize: [],
|
|
10077
10275
|
rootComponents: [],
|
|
10078
10276
|
standaloneComponents: [],
|
|
10079
10277
|
parameterized: [],
|
|
@@ -12434,6 +12632,32 @@ class Typechecker {
|
|
|
12434
12632
|
}
|
|
12435
12633
|
return ancestor === Config.defaultAncestor;
|
|
12436
12634
|
}
|
|
12635
|
+
hasDescendants(ref) {
|
|
12636
|
+
const iface = isReferenceType(ref) ? this.resolveReference(ref) : ref;
|
|
12637
|
+
if (!iface || !isInterface$1(iface)) {
|
|
12638
|
+
return false;
|
|
12639
|
+
}
|
|
12640
|
+
const lookupScopes = [];
|
|
12641
|
+
const parent = iface.parent;
|
|
12642
|
+
if (parent && isNamespace(parent)) {
|
|
12643
|
+
lookupScopes.push(...this.namespaces.filter(ns => ns.name === parent.name));
|
|
12644
|
+
}
|
|
12645
|
+
else {
|
|
12646
|
+
lookupScopes.push(this.file);
|
|
12647
|
+
}
|
|
12648
|
+
const visitInterfaces = (node, cb) => {
|
|
12649
|
+
switch (node.kind) {
|
|
12650
|
+
case IDLKind.File:
|
|
12651
|
+
return node.entries.some((value) => visitInterfaces(value, cb));
|
|
12652
|
+
case IDLKind.Namespace:
|
|
12653
|
+
return node.members.some((value) => visitInterfaces(value, cb));
|
|
12654
|
+
case IDLKind.Interface:
|
|
12655
|
+
return cb(node);
|
|
12656
|
+
}
|
|
12657
|
+
return false;
|
|
12658
|
+
};
|
|
12659
|
+
return lookupScopes.some(scope => visitInterfaces(scope, (node) => node.name !== iface.name && this.isHeir(node, iface.name)));
|
|
12660
|
+
}
|
|
12437
12661
|
isPeer(node) {
|
|
12438
12662
|
if (node.name === Config.astNodeCommonAncestor)
|
|
12439
12663
|
return false; // TODO: is handwritten
|
|
@@ -13313,7 +13537,7 @@ class Importer {
|
|
|
13313
13537
|
return it;
|
|
13314
13538
|
}
|
|
13315
13539
|
this.seen.add(it);
|
|
13316
|
-
this.import(it, "../../reexport-for-generated");
|
|
13540
|
+
this.import(it, "../../src/reexport-for-generated");
|
|
13317
13541
|
return it;
|
|
13318
13542
|
}
|
|
13319
13543
|
import(name, from) {
|
|
@@ -13477,21 +13701,35 @@ class BindingParameterTypeConvertor extends TopLevelTypeConvertor {
|
|
|
13477
13701
|
* limitations under the License.
|
|
13478
13702
|
*/
|
|
13479
13703
|
class BindingReturnValueTypeConvertor extends TopLevelTypeConvertor {
|
|
13480
|
-
constructor(typechecker) {
|
|
13704
|
+
constructor(typechecker, importer) {
|
|
13481
13705
|
const plain = (type) => (writer, call) => call;
|
|
13482
|
-
const wrap = (wrapWith) => (writer, call) => writer.makeFunctionCall(wrapWith, [call]);
|
|
13706
|
+
const wrap = (wrapWith, ...args) => (writer, call) => writer.makeFunctionCall(wrapWith, [call, ...args.map(a => writer.makeString(a))]);
|
|
13707
|
+
const isAstNode = (ref) => (isReferenceType(ref) || isInterface$1(ref)) && this.typechecker.isHeir(ref, Config.astNodeCommonAncestor);
|
|
13708
|
+
const makeArgs = (type) => {
|
|
13709
|
+
const iface = isReferenceType(type)
|
|
13710
|
+
? this.typechecker.resolveReference(type)
|
|
13711
|
+
: undefined;
|
|
13712
|
+
if (iface && isAstNode(iface) && !this.typechecker.hasDescendants(iface)) {
|
|
13713
|
+
const astNodeTypeName = this.typechecker.nodeTypeName(iface);
|
|
13714
|
+
if (astNodeTypeName) {
|
|
13715
|
+
importer.withEnumImport(Config.nodeTypeAttribute);
|
|
13716
|
+
return [astNodeTypeName];
|
|
13717
|
+
}
|
|
13718
|
+
}
|
|
13719
|
+
return [];
|
|
13720
|
+
};
|
|
13483
13721
|
super(typechecker, {
|
|
13484
|
-
sequence: (type) => wrap(PeersConstructions.arrayOfPointersToArrayOfPeers),
|
|
13722
|
+
sequence: (type) => wrap(PeersConstructions.arrayOfPointersToArrayOfPeers, ...makeArgs(type.elementType[0])),
|
|
13485
13723
|
string: (type) => wrap(PeersConstructions.receiveString),
|
|
13486
|
-
reference: (type) =>
|
|
13487
|
-
? wrap(PeersConstructions.unpackNonNullable)
|
|
13724
|
+
reference: (type) => isAstNode(type)
|
|
13725
|
+
? wrap(PeersConstructions.unpackNonNullable, ...makeArgs(type))
|
|
13488
13726
|
: wrap(baseNameString(type.name)),
|
|
13489
13727
|
optional: (type) => {
|
|
13490
|
-
|
|
13491
|
-
|
|
13492
|
-
|
|
13493
|
-
|
|
13494
|
-
|
|
13728
|
+
const innerType = type.type;
|
|
13729
|
+
if (isReferenceType(innerType)) {
|
|
13730
|
+
return isAstNode(innerType)
|
|
13731
|
+
? wrap(PeersConstructions.unpackNullable, ...makeArgs(innerType))
|
|
13732
|
+
: wrap(PeersConstructions.newOf(baseNameString(innerType.name)));
|
|
13495
13733
|
}
|
|
13496
13734
|
throwException(`unexpected optional of non-reference type`);
|
|
13497
13735
|
},
|
|
@@ -13502,6 +13740,7 @@ class BindingReturnValueTypeConvertor extends TopLevelTypeConvertor {
|
|
|
13502
13740
|
boolean: plain,
|
|
13503
13741
|
undefined: plain
|
|
13504
13742
|
});
|
|
13743
|
+
this.importer = importer;
|
|
13505
13744
|
}
|
|
13506
13745
|
}
|
|
13507
13746
|
|
|
@@ -13542,7 +13781,7 @@ class PeerPrinter extends SingleFilePrinter {
|
|
|
13542
13781
|
this.typechecker = new Typechecker(this.idl);
|
|
13543
13782
|
this.importer = new Importer(this.typechecker, `.`, this.node.name);
|
|
13544
13783
|
this.bindingParameterTypeConvertor = new BindingParameterTypeConvertor(this.typechecker);
|
|
13545
|
-
this.bindingReturnValueTypeConvertor = new BindingReturnValueTypeConvertor(this.typechecker);
|
|
13784
|
+
this.bindingReturnValueTypeConvertor = new BindingReturnValueTypeConvertor(this.typechecker, this.importer);
|
|
13546
13785
|
this.parent = (_a = parent(this.node)) !== null && _a !== void 0 ? _a : Config.defaultAncestor;
|
|
13547
13786
|
this.writer = new TSLanguageWriter(new IndentedPrinter(), createEmptyReferenceResolver(), { convert: (node) => convertAndImport(this.importer, new class extends LibraryTypeConvertor {
|
|
13548
13787
|
convertTypeReference(type) {
|
|
@@ -14307,12 +14546,12 @@ class DynamicEmitter {
|
|
|
14307
14546
|
this.generatorVersion = `Unknown`;
|
|
14308
14547
|
this.logDir = `./out/log-idl`;
|
|
14309
14548
|
this.logCount = 0;
|
|
14310
|
-
this.bridgesPrinter = new SingleFileEmitter((idl) => new BridgesPrinter(this.config, idl).print(), `libarkts/native/
|
|
14311
|
-
this.bindingsPrinter = new SingleFileEmitter((idl) => new BindingsPrinter(idl).print(), `libarkts/
|
|
14312
|
-
this.enumsPrinter = new SingleFileEmitter((idl) => new EnumsPrinter(idl).print(), `libarkts/
|
|
14313
|
-
this.indexPrinter = new SingleFileEmitter((idl) => new IndexPrinter(idl).print(), `libarkts/
|
|
14314
|
-
this.peersPrinter = new MultiFileEmitter((idl) => new AllPeersPrinter(this.config, idl).print(), `libarkts/
|
|
14315
|
-
this.factoryPrinter = new SingleFileEmitter((idl) => new FactoryPrinter(this.config, idl).print(), `libarkts/
|
|
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);
|
|
14316
14555
|
const myJson = path__namespace$1.resolve(__dirname, '..', 'package.json');
|
|
14317
14556
|
if (fs__namespace$1.existsSync(myJson)) {
|
|
14318
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`;
|
|
@@ -14706,7 +14945,7 @@ function main() {
|
|
|
14706
14945
|
if (options.initialize) {
|
|
14707
14946
|
new StaticEmitter(options.outputDir, options.pandaSdkPath).emit();
|
|
14708
14947
|
}
|
|
14709
|
-
new DynamicEmitter(options.outputDir, options.pandaSdkPath,
|
|
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();
|
|
14710
14949
|
}
|
|
14711
14950
|
main();
|
|
14712
14951
|
//# sourceMappingURL=index.js.map
|