@idlizer/core 2.1.10-arktscgen-3a → 2.1.10-arktscgen-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/src/LanguageWriters/ArgConvertors.d.ts +12 -0
- package/build/lib/src/LanguageWriters/ArgConvertors.js +55 -3
- package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +9 -1
- package/build/lib/src/LanguageWriters/LanguageWriter.js +10 -4
- package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +1 -1
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +2 -0
- package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +11 -15
- package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +0 -3
- package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.js +3 -0
- package/build/lib/src/config.d.ts +760 -0
- package/build/lib/src/config.js +7 -0
- package/build/lib/src/formatter.js +5 -2
- package/build/lib/src/from-idl/DtsPrinter.js +2 -2
- package/build/lib/src/from-idl/common.js +2 -2
- package/build/lib/src/from-idl/deserialize.d.ts +3 -7
- package/build/lib/src/from-idl/deserialize.js +64 -38
- package/build/lib/src/from-idl/parser.d.ts +1 -1
- package/build/lib/src/from-idl/parser.js +29 -20
- package/build/lib/src/idl.d.ts +7 -1
- package/build/lib/src/idl.js +54 -10
- package/build/lib/src/index.d.ts +2 -1
- package/build/lib/src/index.js +2 -1
- package/build/lib/src/languageSpecificKeywords.js +1 -1
- package/build/lib/src/peer-generation/PeerLibrary.js +10 -1
- package/build/lib/src/peer-generation/isMaterialized.js +1 -1
- package/build/lib/src/peer-generation/modules.d.ts +2 -0
- package/build/lib/src/peer-generation/modules.js +14 -1
- package/build/lib/src/transformers/GenericTransformer.js +70 -5
- package/build/lib/src/transformers/NullTransformer.d.ts +0 -1
- package/build/lib/src/transformers/NullTransformer.js +1 -2
- package/build/lib/src/transformers/OnSerializeTransformer.d.ts +3 -0
- package/build/lib/src/transformers/OnSerializeTransformer.js +19 -0
- package/build/lib/src/util.d.ts +5 -0
- package/build/lib/src/util.js +13 -2
- package/package.json +5 -5
package/build/lib/src/config.js
CHANGED
|
@@ -22,16 +22,22 @@ export const ModuleConfigurationSchema = D.object({
|
|
|
22
22
|
external: D.maybe(D.boolean()),
|
|
23
23
|
packages: T.stringArray(),
|
|
24
24
|
useFoldersLayout: D.maybe(D.boolean()),
|
|
25
|
+
tsLikePackage: D.maybe(D.string()),
|
|
25
26
|
});
|
|
26
27
|
export const HookMethodSchema = D.object({
|
|
27
28
|
hookName: D.string(),
|
|
28
29
|
replaceImplementation: D.boolean()
|
|
29
30
|
});
|
|
31
|
+
export const TransformOnSerializeSchema = D.object({
|
|
32
|
+
from: D.string(),
|
|
33
|
+
to: D.string(),
|
|
34
|
+
});
|
|
30
35
|
export const CoreConfigurationSchema = D.object({
|
|
31
36
|
ApiKind: D.number(),
|
|
32
37
|
TypePrefix: D.string(),
|
|
33
38
|
LibraryPrefix: D.string(),
|
|
34
39
|
OptionalPrefix: D.string(),
|
|
40
|
+
transformOnSerialize: D.array(TransformOnSerializeSchema),
|
|
35
41
|
rootComponents: T.stringArray(),
|
|
36
42
|
standaloneComponents: T.stringArray(),
|
|
37
43
|
parameterized: T.stringArray(),
|
|
@@ -53,6 +59,7 @@ export const defaultCoreConfiguration = {
|
|
|
53
59
|
TypePrefix: "",
|
|
54
60
|
LibraryPrefix: "",
|
|
55
61
|
OptionalPrefix: "",
|
|
62
|
+
transformOnSerialize: [],
|
|
56
63
|
rootComponents: [],
|
|
57
64
|
standaloneComponents: [],
|
|
58
65
|
parameterized: [],
|
|
@@ -78,9 +78,12 @@ export function outputDiagnosticMessageFormatted(message) {
|
|
|
78
78
|
let lines = location.lines;
|
|
79
79
|
console.log(`${indent}${lastPath != part.location.documentPath ? "-->" : ":::"} ${part.location.documentPath}:${range.start.line}:${range.start.character}`);
|
|
80
80
|
console.log(`${indent} |`);
|
|
81
|
-
|
|
81
|
+
const last = Math.min(range.end.line + 1, lines.length - 1);
|
|
82
|
+
for (let i = Math.max(range.start.line - 1, 1); i <= last; ++i) {
|
|
82
83
|
console.log(formatLine(digits, lines, i));
|
|
83
|
-
|
|
84
|
+
if (i >= range.start.line && i <= range.end.line) {
|
|
85
|
+
console.log(formatUnderline(indent, lines, i, range, "^", first ? "-" : "~", part.message));
|
|
86
|
+
}
|
|
84
87
|
}
|
|
85
88
|
}
|
|
86
89
|
else {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { indentedBy, isInNamespace } from "../util";
|
|
16
16
|
import { IDLEntity, IDLKind, getExtAttribute, getVerbatimDts, hasExtAttribute, isCallback, isConstructor, isContainerType, isEnum, isInterface, isMethod, isPrimitiveType, isProperty, isReferenceType, isSyntheticEntry, isTypeParameterType, isTypedef, isUnionType, isImport, isVersion, isNamespace, IDLExtendedAttributes, IDLAccessorAttribute, IDLVoidType, IDLStringType, IDLUndefinedType, isCallable, IDLAnyType, IDLContainerUtils, DebugUtils, mixMethodParametersAndTags, createReferenceType, transformMethodsAsync2ReturnPromise, linearizeNamespaceMembers, isNamedNode, IDLThisType, isOptionalType, IDLI8Type, IDLU8Type, IDLI16Type, IDLU16Type, IDLI32Type, IDLU32Type, IDLI64Type, IDLU64Type, IDLF16Type, IDLF32Type, IDLF64Type, IDLBufferType, isUnspecifiedGenericType, IDLUnknownType, IDLBooleanType, IDLNumberType, IDLPointerType, IDLInterfaceSubkind, escapeIDLKeyword, getNamespacesPathFor, IDLBigintType, IDLDate, IDLFunctionType, getQualifiedName, IDLObjectType } from "../idl";
|
|
17
|
-
import { resolveSyntheticType,
|
|
17
|
+
import { resolveSyntheticType, parseIDLFile } from "./deserialize";
|
|
18
18
|
import { Language } from "../Language";
|
|
19
19
|
import { warn } from "../util";
|
|
20
20
|
import { isInIdlize } from "../idlize";
|
|
@@ -359,7 +359,7 @@ export class CustomPrintVisitor {
|
|
|
359
359
|
}
|
|
360
360
|
export function idlToDtsString(name, content) {
|
|
361
361
|
let printer = new CustomPrintVisitor(resolveSyntheticType, Language.TS);
|
|
362
|
-
const
|
|
362
|
+
const idlFile = parseIDLFile(name, content);
|
|
363
363
|
printer.printPackage(idlFile);
|
|
364
364
|
linearizeNamespaceMembers(idlFile.entries).forEach(it => {
|
|
365
365
|
transformMethodsAsync2ReturnPromise(it);
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import * as fs from "fs";
|
|
16
16
|
import * as path from "path";
|
|
17
|
-
import {
|
|
17
|
+
import { parseIDLFile } from "./deserialize";
|
|
18
18
|
import { zip } from "../util";
|
|
19
19
|
function getFilesRecursive(dirPath, arrayOfFiles = []) {
|
|
20
20
|
let files = fs.readdirSync(dirPath);
|
|
@@ -65,7 +65,7 @@ export function scanIDL(inputDir, inputFile) {
|
|
|
65
65
|
? [path.join(inputDir, inputFile)]
|
|
66
66
|
: fs.readdirSync(inputDir)
|
|
67
67
|
.map((elem) => path.join(inputDir, elem));
|
|
68
|
-
return files.map(it =>
|
|
68
|
+
return files.map(it => parseIDLFile(it));
|
|
69
69
|
}
|
|
70
70
|
export const licence = `/*
|
|
71
71
|
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
|
@@ -4,12 +4,8 @@ export type WebIDLTokenCollection = Record<string, webidl2.Token | null | undefi
|
|
|
4
4
|
export type IDLTokenInfoMap = Map<unknown, WebIDLTokenCollection>;
|
|
5
5
|
export declare function addSyntheticType(name: string, type: idl.IDLEntry): void;
|
|
6
6
|
export declare function resolveSyntheticType(type: idl.IDLReferenceType): idl.IDLEntry | undefined;
|
|
7
|
-
type IDLInheritanceMode = 'single' | 'multiple';
|
|
8
|
-
interface ToIDLFileProps {
|
|
9
|
-
inheritanceMode?: IDLInheritanceMode;
|
|
10
|
-
content?: string;
|
|
11
|
-
}
|
|
12
7
|
export declare function toIdlType(fileName: string, content: string): idl.IDLType;
|
|
13
|
-
export declare function
|
|
14
|
-
export
|
|
8
|
+
export declare function compareParsingResults(oldFile: idl.IDLFile, newFile: idl.IDLFile): boolean;
|
|
9
|
+
export declare function parseIDLFile(fileName: string, content?: string, quiet?: boolean): idl.IDLFile;
|
|
10
|
+
export declare function parseIDLFileNew(fileName: string, content?: string, registerSynthetics?: boolean): idl.IDLFile;
|
|
15
11
|
//# sourceMappingURL=deserialize.d.ts.map
|
|
@@ -22,9 +22,14 @@ import { collapseTypes, generateSyntheticUnionName } from "../peer-generation/id
|
|
|
22
22
|
import { commonRange } from "../diagnostictypes";
|
|
23
23
|
import { DiagnosticMessageGroup, LoadingFatal, ParsingFatal, InternalFatal } from "../diagnosticmessages";
|
|
24
24
|
import { FatalParserException, Parser } from "./parser";
|
|
25
|
+
import { outputDiagnosticMessageFormatted } from "../formatter";
|
|
25
26
|
function getTokens(node) {
|
|
26
27
|
return node.tokens;
|
|
27
28
|
}
|
|
29
|
+
const extendedAttributesWithTypesValue = [
|
|
30
|
+
idl.IDLExtendedAttributes.TypeArguments,
|
|
31
|
+
idl.IDLExtendedAttributes.TypeParametersDefaults,
|
|
32
|
+
];
|
|
28
33
|
const syntheticTypes = new Map();
|
|
29
34
|
export function addSyntheticType(name, type) {
|
|
30
35
|
if (syntheticTypes.has(name)) {
|
|
@@ -39,9 +44,8 @@ class IDLDeserializer {
|
|
|
39
44
|
enterGenericScope(generics) {
|
|
40
45
|
this.genericsScopes.push(new Set(generics !== null && generics !== void 0 ? generics : []));
|
|
41
46
|
}
|
|
42
|
-
constructor(info
|
|
47
|
+
constructor(info) {
|
|
43
48
|
this.info = info;
|
|
44
|
-
this.inheritanceMode = inheritanceMode;
|
|
45
49
|
this.namespacePathNames = [];
|
|
46
50
|
this.currentPackage = [];
|
|
47
51
|
this.genericsScopes = [];
|
|
@@ -138,7 +142,7 @@ class IDLDeserializer {
|
|
|
138
142
|
node.inheritance.forEach(it => {
|
|
139
143
|
const attributes = it.extAttrs;
|
|
140
144
|
const parentTypeArgs = this.extractTypeArguments(file, attributes !== null && attributes !== void 0 ? attributes : [], idl.IDLExtendedAttributes.TypeArguments);
|
|
141
|
-
const attrs = this.toExtendedAttributes(attributes !== null && attributes !== void 0 ? attributes : []); // ?.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments)
|
|
145
|
+
const attrs = this.toExtendedAttributes(file, attributes !== null && attributes !== void 0 ? attributes : []); // ?.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments)
|
|
142
146
|
const ref = idl.createReferenceType(it.inheritance, parentTypeArgs, {
|
|
143
147
|
extendedAttributes: attrs
|
|
144
148
|
});
|
|
@@ -158,7 +162,7 @@ class IDLDeserializer {
|
|
|
158
162
|
.map(it => this.toIDLCallable(file, it)), generics, {
|
|
159
163
|
fileName: file,
|
|
160
164
|
documentation: this.makeDocs(node),
|
|
161
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
165
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
162
166
|
});
|
|
163
167
|
this.genericsScopes.pop();
|
|
164
168
|
this.info.set(result, getTokens(node));
|
|
@@ -174,6 +178,8 @@ class IDLDeserializer {
|
|
|
174
178
|
// is it IDLStringType?
|
|
175
179
|
const refType = idl.createReferenceType(type);
|
|
176
180
|
refType.fileName = file;
|
|
181
|
+
// Here is a bug: type.extAttrs are ignored, so typeArguments on ([TypeArguments="T"] Something) are always lost
|
|
182
|
+
// That must be fixed together with fixing non-generic placeholders on generic types in pipelines (like WrappedBuilder)
|
|
177
183
|
refType.typeArguments = this.extractTypeArguments(file, extAttrs, idl.IDLExtendedAttributes.TypeArguments);
|
|
178
184
|
return refType;
|
|
179
185
|
}
|
|
@@ -231,7 +237,7 @@ class IDLDeserializer {
|
|
|
231
237
|
idlRefType = ref;
|
|
232
238
|
}
|
|
233
239
|
idlRefType.fileName = file;
|
|
234
|
-
idlRefType.extendedAttributes = this.toExtendedAttributes(combinedExtAttrs);
|
|
240
|
+
idlRefType.extendedAttributes = this.toExtendedAttributes(file, combinedExtAttrs);
|
|
235
241
|
return this.withInfo(type, idlRefType);
|
|
236
242
|
}
|
|
237
243
|
if (isSequenceTypeDescription(type) || isPromiseTypeDescription(type) || isRecordTypeDescription(type)) {
|
|
@@ -259,7 +265,7 @@ class IDLDeserializer {
|
|
|
259
265
|
isAsync: node.async,
|
|
260
266
|
}, {
|
|
261
267
|
documentation: this.makeDocs(node),
|
|
262
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
268
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
263
269
|
}, generics));
|
|
264
270
|
this.genericsScopes.pop();
|
|
265
271
|
return result;
|
|
@@ -272,8 +278,6 @@ class IDLDeserializer {
|
|
|
272
278
|
const generics = this.extractGenerics(node.extAttrs);
|
|
273
279
|
this.enterGenericScope(generics);
|
|
274
280
|
const returnType = this.toIDLType(file, node.idlType, node.extAttrs);
|
|
275
|
-
if (idl.isReferenceType(returnType))
|
|
276
|
-
returnType.typeArguments = this.extractTypeArguments(file, node.extAttrs, idl.IDLExtendedAttributes.TypeArguments);
|
|
277
281
|
const result = this.withInfo(node, idl.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, {
|
|
278
282
|
isStatic: node.special === "static",
|
|
279
283
|
isAsync: node.async,
|
|
@@ -281,7 +285,7 @@ class IDLDeserializer {
|
|
|
281
285
|
isFree
|
|
282
286
|
}, {
|
|
283
287
|
documentation: this.makeDocs(node),
|
|
284
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
288
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
285
289
|
}, generics));
|
|
286
290
|
this.genericsScopes.pop();
|
|
287
291
|
return result;
|
|
@@ -289,7 +293,7 @@ class IDLDeserializer {
|
|
|
289
293
|
toIDLConstructor(file, node) {
|
|
290
294
|
return this.withInfo(node, idl.createConstructor(node.arguments.map(it => this.toIDLParameter(file, it)), undefined, {
|
|
291
295
|
documentation: this.makeDocs(node),
|
|
292
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
296
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
293
297
|
}));
|
|
294
298
|
}
|
|
295
299
|
toIDLParameter(file, node) {
|
|
@@ -302,7 +306,7 @@ class IDLDeserializer {
|
|
|
302
306
|
this.enterGenericScope(generics);
|
|
303
307
|
const result = idl.createCallback(node.name, node.arguments.map(it => this.toIDLParameter(file, it)), this.toIDLType(file, node.idlType, undefined), {
|
|
304
308
|
fileName: file,
|
|
305
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
309
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
306
310
|
documentation: this.makeDocs(node),
|
|
307
311
|
}, generics);
|
|
308
312
|
if (node.extAttrs.find(it => it.name === "Synthetic")) {
|
|
@@ -316,7 +320,7 @@ class IDLDeserializer {
|
|
|
316
320
|
const generics = this.extractGenerics(node.extAttrs);
|
|
317
321
|
this.enterGenericScope(generics);
|
|
318
322
|
const result = this.withInfo(node, idl.createTypedef(node.name, this.toIDLType(file, node.idlType, undefined, node.name), generics, {
|
|
319
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
323
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
320
324
|
documentation: this.makeDocs(node),
|
|
321
325
|
fileName: file,
|
|
322
326
|
}));
|
|
@@ -329,7 +333,7 @@ class IDLDeserializer {
|
|
|
329
333
|
toIDLDictionary(file, node) {
|
|
330
334
|
const result = idl.createEnum(node.name, [], {
|
|
331
335
|
documentation: this.makeDocs(node),
|
|
332
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
336
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
333
337
|
fileName: file,
|
|
334
338
|
});
|
|
335
339
|
result.elements = node.members.map(it => this.toIDLEnumMember(file, it, result));
|
|
@@ -337,7 +341,7 @@ class IDLDeserializer {
|
|
|
337
341
|
}
|
|
338
342
|
toIDLNamespace(file, node) {
|
|
339
343
|
const namespace = idl.createNamespace(node.name, [], {
|
|
340
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
344
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
341
345
|
fileName: file
|
|
342
346
|
});
|
|
343
347
|
this.namespacePathNames.push(node.name);
|
|
@@ -347,7 +351,7 @@ class IDLDeserializer {
|
|
|
347
351
|
}
|
|
348
352
|
toIDLVersion(file, node) {
|
|
349
353
|
return this.withInfo(node, idl.createVersion(node.value, {
|
|
350
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
354
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
351
355
|
fileName: file
|
|
352
356
|
}));
|
|
353
357
|
}
|
|
@@ -355,7 +359,7 @@ class IDLDeserializer {
|
|
|
355
359
|
return this.withInfo(node, idl.createProperty(node.name, this.toIDLType(file, node.idlType, undefined), node.readonly, node.special === "static", isOptional(node), {
|
|
356
360
|
documentation: this.makeDocs(node),
|
|
357
361
|
fileName: file,
|
|
358
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs)
|
|
362
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs)
|
|
359
363
|
}));
|
|
360
364
|
}
|
|
361
365
|
toIDLEnumMember(file, node, parent) {
|
|
@@ -374,12 +378,18 @@ class IDLDeserializer {
|
|
|
374
378
|
throw new Error(`Not representable enum initializer: ${JSON.stringify(node.default)}. Found in ${file}`);
|
|
375
379
|
}
|
|
376
380
|
return this.withInfo(node, idl.createEnumMember(node.name, parent, this.toIDLType(file, node.idlType, undefined), initializer, {
|
|
377
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
381
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
378
382
|
}));
|
|
379
383
|
}
|
|
380
|
-
toExtendedAttributes(extAttrs) {
|
|
384
|
+
toExtendedAttributes(file, extAttrs) {
|
|
381
385
|
return extAttrs.map(it => {
|
|
382
|
-
return this.withInfo(it, {
|
|
386
|
+
return this.withInfo(it, {
|
|
387
|
+
name: it.name,
|
|
388
|
+
value: this.toExtendedAttributeValue(it),
|
|
389
|
+
typesValue: extendedAttributesWithTypesValue.includes(it.name)
|
|
390
|
+
? this.extractTypeArguments(file, extAttrs, it.name)
|
|
391
|
+
: undefined
|
|
392
|
+
});
|
|
383
393
|
});
|
|
384
394
|
}
|
|
385
395
|
toExtendedAttributeValue(attr) {
|
|
@@ -395,7 +405,7 @@ class IDLDeserializer {
|
|
|
395
405
|
const result = idl.createEnum(node.name, [], {
|
|
396
406
|
fileName: file,
|
|
397
407
|
documentation: this.makeDocs(node),
|
|
398
|
-
extendedAttributes: this.toExtendedAttributes(node.extAttrs),
|
|
408
|
+
extendedAttributes: this.toExtendedAttributes(file, node.extAttrs),
|
|
399
409
|
});
|
|
400
410
|
result.elements = node.values.map((it) => idl.createEnumMember(it.value, result, idl.IDLNumberType, undefined));
|
|
401
411
|
return this.withInfo(node, result);
|
|
@@ -517,7 +527,7 @@ class IDLDeserializer {
|
|
|
517
527
|
}
|
|
518
528
|
export function toIdlType(fileName, content) {
|
|
519
529
|
const lexicalInfo = new Map();
|
|
520
|
-
const deserializer = new IDLDeserializer(lexicalInfo
|
|
530
|
+
const deserializer = new IDLDeserializer(lexicalInfo);
|
|
521
531
|
return deserializer.toIDLType(fileName, webidl2.parseType(content, fileName));
|
|
522
532
|
}
|
|
523
533
|
const DifferenceFound = new DiagnosticMessageGroup("error", "DifferenceFound", "Difference found");
|
|
@@ -597,14 +607,42 @@ function compareDeep(oldData, newData, paths) {
|
|
|
597
607
|
}
|
|
598
608
|
return [];
|
|
599
609
|
}
|
|
600
|
-
function compareParsingResults(oldFile, newFile) {
|
|
610
|
+
export function compareParsingResults(oldFile, newFile) {
|
|
601
611
|
const paths = new Set();
|
|
602
612
|
compareDeep(oldFile, newFile, paths);
|
|
603
613
|
if (paths.size > 0) {
|
|
604
614
|
DifferenceFound.reportDiagnosticMessage([newFile.nodeLocation], "Differences found in those paths:\n" + [...paths].join("\n"));
|
|
605
615
|
}
|
|
616
|
+
return paths.size == 0;
|
|
606
617
|
}
|
|
607
|
-
function
|
|
618
|
+
export function parseIDLFile(fileName, content, quiet) {
|
|
619
|
+
const previousDiagnosticsCount = DiagnosticMessageGroup.allGroupsEntries.length;
|
|
620
|
+
try {
|
|
621
|
+
let newFile;
|
|
622
|
+
// Temporarily is set to use old parser by default
|
|
623
|
+
// Old parser has a bug, it ignores extended attributes on return types, but some pipelines depend on that behavior
|
|
624
|
+
// So pipelines and old parser must be fixed before permanent switch to a new parser
|
|
625
|
+
const mode = process.env.IDLPARSE;
|
|
626
|
+
if (mode === "compare" || mode === "old") {
|
|
627
|
+
newFile = parseIDLFileOld(fileName, content);
|
|
628
|
+
if (mode === "old") {
|
|
629
|
+
return newFile;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
const file = parseIDLFileNew(fileName, content, mode !== "compare");
|
|
633
|
+
if (mode === "compare") {
|
|
634
|
+
compareParsingResults(file, newFile);
|
|
635
|
+
return newFile;
|
|
636
|
+
}
|
|
637
|
+
return file;
|
|
638
|
+
}
|
|
639
|
+
finally {
|
|
640
|
+
if (!quiet && DiagnosticMessageGroup.allGroupsEntries.length != previousDiagnosticsCount) {
|
|
641
|
+
DiagnosticMessageGroup.allGroupsEntries.slice(previousDiagnosticsCount).map(it => outputDiagnosticMessageFormatted(it));
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
export function parseIDLFileNew(fileName, content, registerSynthetics) {
|
|
608
646
|
let file = new Parser(fileName, content).parseIDL();
|
|
609
647
|
const ancestors = [];
|
|
610
648
|
const namespaces = [];
|
|
@@ -640,18 +678,10 @@ function parseIdlNew(fileName, content, registerSynthetics) {
|
|
|
640
678
|
});
|
|
641
679
|
return file;
|
|
642
680
|
}
|
|
643
|
-
|
|
681
|
+
function parseIDLFileOld(fileName, content) {
|
|
644
682
|
var _a, _b, _c;
|
|
645
|
-
let newFile;
|
|
646
|
-
const mode = process.env.IDLPARSE;
|
|
647
|
-
if (mode == "compare" || mode == "new") {
|
|
648
|
-
newFile = parseIdlNew(fileName, content, mode == "new");
|
|
649
|
-
if (mode == "new") {
|
|
650
|
-
return [newFile, new Map()];
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
683
|
const lexicalInfo = new Map();
|
|
654
|
-
const deserializer = new IDLDeserializer(lexicalInfo
|
|
684
|
+
const deserializer = new IDLDeserializer(lexicalInfo);
|
|
655
685
|
if (undefined === content) {
|
|
656
686
|
try {
|
|
657
687
|
content = fs.readFileSync(fileName).toString();
|
|
@@ -700,11 +730,7 @@ export function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } =
|
|
|
700
730
|
node.nameLocation = nameLocation;
|
|
701
731
|
}
|
|
702
732
|
});
|
|
703
|
-
|
|
704
|
-
compareParsingResults(file, newFile);
|
|
705
|
-
return [newFile, new Map()];
|
|
706
|
-
}
|
|
707
|
-
return [file, lexicalInfo];
|
|
733
|
+
return file;
|
|
708
734
|
}
|
|
709
735
|
function prepareOffsets(lines) {
|
|
710
736
|
let offsets = [];
|
|
@@ -33,7 +33,7 @@ export declare class Parser {
|
|
|
33
33
|
_curToken: Token;
|
|
34
34
|
_prevToken: Token;
|
|
35
35
|
_generics: string[][];
|
|
36
|
-
|
|
36
|
+
_inLiteralParsingLevel: number;
|
|
37
37
|
_match(re: RegExp, kind: TokenKind): Token | undefined;
|
|
38
38
|
_reDecimal: RegExp;
|
|
39
39
|
_reInteger: RegExp;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
import * as fs from "fs";
|
|
16
16
|
import * as idl from "../idl";
|
|
17
17
|
import { DiagnosticException } from "../diagnostictypes";
|
|
18
|
-
import { DiagnosticMessageGroup, LoadingFatal,
|
|
18
|
+
import { DiagnosticMessageGroup, LoadingFatal, InternalFatal } from "../diagnosticmessages";
|
|
19
19
|
const DuplicateModifier = new DiagnosticMessageGroup("error", "DuplicateModifier", "Duplicate modifier", "Duplicate of");
|
|
20
20
|
const NotApplicableModifier = new DiagnosticMessageGroup("error", "NotApplicableModifier", "Not applicable modifier");
|
|
21
21
|
const DuplicatePackageDeclaration = new DiagnosticMessageGroup("error", "DuplicatePackageDeclaration", "Duplicate package declaration", "Duplicate of");
|
|
@@ -25,12 +25,14 @@ const IncorrectLiteral = new DiagnosticMessageGroup("error", "IncorrectLiteral",
|
|
|
25
25
|
const IncorrectIdentifier = new DiagnosticMessageGroup("error", "IncorrectIdentifier", "Incorrect identifier");
|
|
26
26
|
const UnexpectedToken = new DiagnosticMessageGroup("error", "UnexpectedToken", "Unexpected token");
|
|
27
27
|
const UnexpectedEndOfFile = new DiagnosticMessageGroup("fatal", "UnexpectedEndOfFile", "Unexpected end of file");
|
|
28
|
+
const UnrecognizedSymbols = new DiagnosticMessageGroup("fatal", "UnrecognizedSymbols", "Unrecognized symbols");
|
|
28
29
|
const UnsupportedSyntax = new DiagnosticMessageGroup("error", "UnsupportedSyntax", "Unsupported syntax");
|
|
29
30
|
const WrongDeclarationPlacement = new DiagnosticMessageGroup("error", "WrongDeclarationPlacement", "Wrong declaration placement");
|
|
30
31
|
const ExpectedPrimitiveType = new DiagnosticMessageGroup("error", "ExpectedPrimitiveType", "Expected primitive type");
|
|
31
32
|
const ExpectedReferenceType = new DiagnosticMessageGroup("error", "ExpectedReferenceType", "Expected reference type");
|
|
32
33
|
const ExpectedGenericArguments = new DiagnosticMessageGroup("error", "ExpectedGenericArguments", "Expected generic arguments");
|
|
33
34
|
const UnexpectedGenericArguments = new DiagnosticMessageGroup("error", "UnexpectedGenericArguments", "Unexpected generic arguments");
|
|
35
|
+
const InlineParsingDepthExceeded = new DiagnosticMessageGroup("fatal", "InlineParsingDepthExceeded", "Inline parsing depth exceeded");
|
|
34
36
|
export class FatalParserException extends Error {
|
|
35
37
|
constructor(diagnosticMessages) {
|
|
36
38
|
super();
|
|
@@ -66,7 +68,7 @@ export class Parser {
|
|
|
66
68
|
// TypeParameters support
|
|
67
69
|
this._generics = [];
|
|
68
70
|
// TypeArguments parsing support
|
|
69
|
-
this.
|
|
71
|
+
this._inLiteralParsingLevel = 0;
|
|
70
72
|
// symTokens = ["(", ")", "[", "]", "{", "}", ",", "...", ":", ";", "<", "=", ">", "?"]
|
|
71
73
|
this._reDecimal = /-?(?=[0-9]*\.|[0-9]+[eE])(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][-+]?[0-9]+)?|[0-9]+[Ee][-+]?[0-9]+)/y;
|
|
72
74
|
this._reInteger = /-?(0([Xx][0-9A-Fa-f]+|[0-7]*)|[1-9][0-9]*)/y;
|
|
@@ -157,17 +159,17 @@ export class Parser {
|
|
|
157
159
|
this._curToken = { kind: TokenKind.End, value: "", location: { documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } } };
|
|
158
160
|
return;
|
|
159
161
|
}
|
|
160
|
-
if (this.
|
|
162
|
+
if (this._inLiteralParsingLevel && (this.content[this._curOffset] == "\"" || this.content[this._curOffset] == "'")) {
|
|
161
163
|
// TypeArguments parsing support
|
|
162
164
|
const pos = { line: this._curLine + 1, character: this._curOffset - this.offsets[this._curLine] + 1 };
|
|
163
|
-
this._curToken = { kind: TokenKind.Symbol, value:
|
|
165
|
+
this._curToken = { kind: TokenKind.Symbol, value: this.content[this._curOffset], location: { documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } } };
|
|
164
166
|
this._curOffset += 1;
|
|
165
167
|
return;
|
|
166
168
|
}
|
|
167
169
|
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));
|
|
168
170
|
if (!token) {
|
|
169
171
|
const pos = { line: this._curLine + 1, character: this._curOffset - this.offsets[this._curLine] + 1 };
|
|
170
|
-
|
|
172
|
+
UnrecognizedSymbols.throwDiagnosticMessage([{ documentPath: this.fileName, lines: this.lines, range: { start: pos, end: pos } }]);
|
|
171
173
|
}
|
|
172
174
|
// Uncomment in case of parser debugging
|
|
173
175
|
// if (token) {
|
|
@@ -473,28 +475,32 @@ export class Parser {
|
|
|
473
475
|
duplicates.add(name.value);
|
|
474
476
|
}
|
|
475
477
|
names.add(name.value);
|
|
476
|
-
if (name.value == idl.IDLExtendedAttributes.TypeArguments) {
|
|
478
|
+
if (name.value == idl.IDLExtendedAttributes.TypeArguments || name.value == idl.IDLExtendedAttributes.TypeParametersDefaults) {
|
|
477
479
|
// TypeArguments parsing support
|
|
478
480
|
try {
|
|
479
|
-
this.
|
|
481
|
+
this._inLiteralParsingLevel += 1;
|
|
482
|
+
if (this._inLiteralParsingLevel > 2) {
|
|
483
|
+
InlineParsingDepthExceeded.throwDiagnosticMessage([this.curLocation]);
|
|
484
|
+
}
|
|
480
485
|
this.skip("=");
|
|
481
486
|
const vloc = this.trackLocation();
|
|
482
487
|
const start = this._curOffset; // Already after first quote
|
|
483
|
-
this.skip("\"");
|
|
488
|
+
this.skip(this._inLiteralParsingLevel == 2 ? "'" : "\"");
|
|
484
489
|
const types = this.parseTypeList();
|
|
485
490
|
const end = this._curOffset - 1; // Already after second quote
|
|
486
|
-
this.
|
|
487
|
-
this.
|
|
491
|
+
this._inLiteralParsingLevel -= 1;
|
|
492
|
+
// Note that second this._inLiteralParsingLevel comparison happens after decrement
|
|
493
|
+
this.skip(this._inLiteralParsingLevel == 1 ? "'" : "\"");
|
|
488
494
|
const stringValue = this.content.slice(start, end);
|
|
489
495
|
ext.push({ name: name.value, value: stringValue, typesValue: types, nameLocation: name.location, valueLocation: vloc() });
|
|
490
496
|
}
|
|
491
497
|
catch (e) {
|
|
492
|
-
|
|
498
|
+
if (e instanceof DiagnosticException && e.diagnosticMessage.severity != "fatal") {
|
|
499
|
+
this.skipToAfter("\"");
|
|
500
|
+
}
|
|
501
|
+
this._inLiteralParsingLevel = 0;
|
|
493
502
|
throw e;
|
|
494
503
|
}
|
|
495
|
-
finally {
|
|
496
|
-
this._enableInLiteralParsing = false;
|
|
497
|
-
}
|
|
498
504
|
}
|
|
499
505
|
else {
|
|
500
506
|
let value;
|
|
@@ -676,9 +682,9 @@ export class Parser {
|
|
|
676
682
|
const name = this.parseSingleIdentifier();
|
|
677
683
|
this.skip("=");
|
|
678
684
|
const value = this.parseLiteral();
|
|
679
|
-
const extracted = extractLiteral(value);
|
|
680
685
|
this.skip(";");
|
|
681
|
-
|
|
686
|
+
// Note that raw value (with quoted strings) is used here, that provides compatibility with older code (while being different from `dictionary` processing)
|
|
687
|
+
return idl.createConstant(name.value, type, value.value, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location, valueLocation: value.location });
|
|
682
688
|
}
|
|
683
689
|
parseAttribute() {
|
|
684
690
|
trac("parseAttribute");
|
|
@@ -768,11 +774,14 @@ export class Parser {
|
|
|
768
774
|
const sloc = this.trackLocation();
|
|
769
775
|
const type = this.parsePrimitiveType();
|
|
770
776
|
const name = this.parseSingleIdentifier();
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
777
|
+
let value;
|
|
778
|
+
let extracted;
|
|
779
|
+
if (this.seeAndSkip("=")) {
|
|
780
|
+
value = this.parseLiteral();
|
|
781
|
+
extracted = extractLiteral(value);
|
|
782
|
+
}
|
|
774
783
|
this.skip(";");
|
|
775
|
-
return idl.createEnumMember(name.value, undefined, type, extracted.extractedValue, { extendedAttributes: ext, nodeLocation: sloc(), nameLocation: name.location, valueLocation: value.location });
|
|
784
|
+
return idl.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 });
|
|
776
785
|
}
|
|
777
786
|
parsePackage() {
|
|
778
787
|
trac("parsePackage");
|
package/build/lib/src/idl.d.ts
CHANGED
|
@@ -68,11 +68,13 @@ export declare enum IDLExtendedAttributes {
|
|
|
68
68
|
TypeAnnotations = "TypeAnnotations",
|
|
69
69
|
TypeArguments = "TypeArguments",
|
|
70
70
|
TypeParameters = "TypeParameters",
|
|
71
|
+
TypeParametersDefaults = "TypeParametersDefaults",
|
|
71
72
|
VerbatimDts = "VerbatimDts",
|
|
72
73
|
HandWrittenImplementation = "HandWrittenImplementation",
|
|
73
74
|
ExtraMethod = "ExtraMethod",
|
|
74
75
|
OverloadAlias = "OverloadAlias",
|
|
75
|
-
OverloadPriority = "OverloadPriority"
|
|
76
|
+
OverloadPriority = "OverloadPriority",
|
|
77
|
+
TransformOnSerialize = "TransformOnSerialize"
|
|
76
78
|
}
|
|
77
79
|
export declare enum IDLAccessorAttribute {
|
|
78
80
|
Getter = "Getter",
|
|
@@ -303,6 +305,7 @@ export declare const IDLSerializerBuffer: IDLPrimitiveType;
|
|
|
303
305
|
export declare const IDLFunctionType: IDLPrimitiveType;
|
|
304
306
|
export declare const IDLCustomObjectType: IDLPrimitiveType;
|
|
305
307
|
export declare const IDLInteropReturnBufferType: IDLPrimitiveType;
|
|
308
|
+
export declare const IDLNullTypeName = "idlize.stdlib.Null";
|
|
306
309
|
export type IDLNodeInitializer = {
|
|
307
310
|
extendedAttributes?: IDLExtendedAttribute[];
|
|
308
311
|
fileName?: string;
|
|
@@ -396,6 +399,8 @@ export declare function toIDLString(file: IDLFile, options: Partial<IDLPrintOpti
|
|
|
396
399
|
export declare function verifyIDLString(source: string): true;
|
|
397
400
|
export declare function hasExtAttribute(node: IDLNode, attribute: IDLExtendedAttributes): boolean;
|
|
398
401
|
export declare function getExtAttribute(node: IDLNode, name: IDLExtendedAttributes): stringOrNone;
|
|
402
|
+
export declare function removeExtAttribute(node: IDLNode, name: IDLExtendedAttributes): void;
|
|
403
|
+
export declare function updateExtAttribute(node: IDLNode, name: IDLExtendedAttributes, value: string | undefined): void;
|
|
399
404
|
export declare function getVerbatimDts(node: IDLEntry): stringOrNone;
|
|
400
405
|
export declare const IDLContainerUtils: {
|
|
401
406
|
isRecord: (x: IDLNode) => boolean;
|
|
@@ -406,6 +411,7 @@ export declare const IDLContainerUtils: {
|
|
|
406
411
|
* @returns tuple of qualifier name and real type name
|
|
407
412
|
*/
|
|
408
413
|
export declare function decomposeQualifiedName(type: IDLReferenceType): [string | undefined, string];
|
|
414
|
+
export declare function qualifiedNameStartsWith(node: IDLNode | string[], template: string[]): boolean;
|
|
409
415
|
export declare function maybeUnwrapOptionalType(type: IDLType): IDLType;
|
|
410
416
|
export declare function maybeOptional(type: IDLType, optional?: boolean): IDLType;
|
|
411
417
|
export declare const DebugUtils: {
|