@idlizer/core 2.1.9-arktscgen-9 → 2.1.10-arktscgen-3

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.
Files changed (41) hide show
  1. package/build/lib/src/LanguageWriters/ArgConvertors.js +5 -3
  2. package/build/lib/src/LanguageWriters/LanguageWriter.d.ts +7 -5
  3. package/build/lib/src/LanguageWriters/LanguageWriter.js +3 -1
  4. package/build/lib/src/LanguageWriters/convertors/CJConvertors.js +2 -1
  5. package/build/lib/src/LanguageWriters/convertors/InteropConvertors.js +2 -0
  6. package/build/lib/src/LanguageWriters/convertors/JavaConvertors.js +3 -0
  7. package/build/lib/src/LanguageWriters/convertors/KotlinConvertors.js +2 -0
  8. package/build/lib/src/LanguageWriters/convertors/TSConvertors.js +3 -1
  9. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.d.ts +2 -5
  10. package/build/lib/src/LanguageWriters/writers/CJLanguageWriter.js +8 -8
  11. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.d.ts +2 -1
  12. package/build/lib/src/LanguageWriters/writers/ETSLanguageWriter.js +6 -0
  13. package/build/lib/src/LanguageWriters/writers/KotlinLanguageWriter.d.ts +2 -5
  14. package/build/lib/src/LanguageWriters/writers/TsLanguageWriter.d.ts +2 -5
  15. package/build/lib/src/config.d.ts +66 -0
  16. package/build/lib/src/config.js +2 -0
  17. package/build/lib/src/configDescriber.js +1 -1
  18. package/build/lib/src/diagnosticmessages.d.ts +18 -12
  19. package/build/lib/src/diagnosticmessages.js +22 -14
  20. package/build/lib/src/diagnostictypes.d.ts +3 -9
  21. package/build/lib/src/formatter.d.ts +2 -1
  22. package/build/lib/src/formatter.js +3 -3
  23. package/build/lib/src/from-idl/deserialize.js +139 -6
  24. package/build/lib/src/from-idl/parser.d.ts +99 -0
  25. package/build/lib/src/from-idl/parser.js +943 -0
  26. package/build/lib/src/idl.d.ts +13 -1
  27. package/build/lib/src/idl.js +6 -0
  28. package/build/lib/src/index.d.ts +1 -0
  29. package/build/lib/src/index.js +1 -0
  30. package/build/lib/src/peer-generation/LayoutManager.d.ts +1 -1
  31. package/build/lib/src/peer-generation/Materialized.d.ts +5 -3
  32. package/build/lib/src/peer-generation/Materialized.js +10 -7
  33. package/build/lib/src/peer-generation/PeerClass.d.ts +8 -2
  34. package/build/lib/src/peer-generation/PeerClass.js +4 -2
  35. package/build/lib/src/peer-generation/PeerLibrary.d.ts +1 -0
  36. package/build/lib/src/peer-generation/PeerLibrary.js +6 -0
  37. package/build/lib/src/peer-generation/PeerMethod.d.ts +9 -2
  38. package/build/lib/src/peer-generation/PeerMethod.js +23 -4
  39. package/build/lib/src/peer-generation/getSuperType.d.ts +1 -0
  40. package/build/lib/src/peer-generation/getSuperType.js +9 -0
  41. package/package.json +12 -4
@@ -21,9 +21,9 @@ export interface DiagnosticMessage {
21
21
  */
22
22
  severity: MessageSeverity;
23
23
  /**
24
- * Unsigned integer code of the diagnostic.
24
+ * String representing code of the diagnostic.
25
25
  */
26
- code: number;
26
+ code: string;
27
27
  /**
28
28
  * Description of the diagnostic.
29
29
  */
@@ -115,16 +115,10 @@ export interface DiagnosticDiffComponent {
115
115
  */
116
116
  replacement?: string;
117
117
  }
118
- /**
119
- * Receiver of diagnostic messages.
120
- */
121
- export interface DiagnosticReceiver {
122
- push(message: DiagnosticMessage): void;
123
- }
124
118
  /**
125
119
  * Collection of diagnostic messages with calculated statistics.
126
120
  */
127
- export declare class DiagnosticResults implements DiagnosticReceiver {
121
+ export declare class DiagnosticResults {
128
122
  entries: DiagnosticMessage[];
129
123
  totals: Record<MessageSeverity, number>;
130
124
  push(message: DiagnosticMessage): void;
@@ -1,3 +1,4 @@
1
- import { DiagnosticResults } from "./diagnostictypes";
1
+ import { DiagnosticResults, DiagnosticMessage } from "./diagnostictypes";
2
2
  export declare function outputDiagnosticResultsFormatted(result: DiagnosticResults): void;
3
+ export declare function outputDiagnosticMessageFormatted(message: DiagnosticMessage): void;
3
4
  //# sourceMappingURL=formatter.d.ts.map
@@ -15,7 +15,7 @@
15
15
  import { MessageSeverityList } from "./diagnostictypes";
16
16
  export function outputDiagnosticResultsFormatted(result) {
17
17
  for (let message of result.entries) {
18
- outputReadableMessage(message);
18
+ outputDiagnosticMessageFormatted(message);
19
19
  }
20
20
  outputReadableTotals(result);
21
21
  }
@@ -62,11 +62,11 @@ function formatUnderline(indent, lines, lineNo, range, edgeChar, midChar, messag
62
62
  }
63
63
  return `${indent} | ${midChar.repeat(lines[lineNo - 1].length)}`;
64
64
  }
65
- function outputReadableMessage(message) {
65
+ export function outputDiagnosticMessageFormatted(message) {
66
66
  if (message.parts.length == 0) {
67
67
  return;
68
68
  }
69
- console.log(`${message.severity}[E${message.code}]: ${message.codeDescription}`);
69
+ console.log(`${message.severity}[${message.code}]: ${message.codeDescription}`);
70
70
  let digits = lineDigitCount(message);
71
71
  let indent = " ".repeat(digits);
72
72
  let first = true;
@@ -20,7 +20,8 @@ import * as idl from "../idl";
20
20
  import { isDefined, warn } from "../util";
21
21
  import { collapseTypes, generateSyntheticUnionName } from "../peer-generation/idl/common";
22
22
  import { commonRange } from "../diagnostictypes";
23
- import { LoadingErrorMessage, ParsingErrorMessage, UnknownErrorMessage } from "../diagnosticmessages";
23
+ import { DiagnosticMessageGroup, LoadingFatal, ParsingFatal, InternalFatal } from "../diagnosticmessages";
24
+ import { FatalParserException, Parser } from "./parser";
24
25
  function getTokens(node) {
25
26
  return node.tokens;
26
27
  }
@@ -135,10 +136,9 @@ class IDLDeserializer {
135
136
  }
136
137
  const implementations = [];
137
138
  node.inheritance.forEach(it => {
138
- var _a;
139
139
  const attributes = it.extAttrs;
140
140
  const parentTypeArgs = this.extractTypeArguments(file, attributes !== null && attributes !== void 0 ? attributes : [], idl.IDLExtendedAttributes.TypeArguments);
141
- const attrs = (_a = this.toExtendedAttributes(attributes !== null && attributes !== void 0 ? attributes : [])) === null || _a === void 0 ? void 0 : _a.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments);
141
+ const attrs = this.toExtendedAttributes(attributes !== null && attributes !== void 0 ? attributes : []); // ?.filter(it => it.name !== idl.IDLExtendedAttributes.TypeArguments)
142
142
  const ref = idl.createReferenceType(it.inheritance, parentTypeArgs, {
143
143
  extendedAttributes: attrs
144
144
  });
@@ -289,6 +289,7 @@ class IDLDeserializer {
289
289
  toIDLConstructor(file, node) {
290
290
  return this.withInfo(node, idl.createConstructor(node.arguments.map(it => this.toIDLParameter(file, it)), undefined, {
291
291
  documentation: this.makeDocs(node),
292
+ extendedAttributes: this.toExtendedAttributes(node.extAttrs),
292
293
  }));
293
294
  }
294
295
  toIDLParameter(file, node) {
@@ -519,8 +520,136 @@ export function toIdlType(fileName, content) {
519
520
  const deserializer = new IDLDeserializer(lexicalInfo, 'multiple');
520
521
  return deserializer.toIDLType(fileName, webidl2.parseType(content, fileName));
521
522
  }
523
+ const DifferenceFound = new DiagnosticMessageGroup("error", "DifferenceFound", "Difference found");
524
+ const noCompare = new Set(["parent", "fileName", "nodeLocation", "nameLocation", "valueLocation", "typesValue"]);
525
+ const canContainMoreCompare = new Set(["extendedAttributes", "typeParameters", "typeArguments"]);
526
+ function safeString(value) {
527
+ if (typeof value == "symbol") {
528
+ return String(value);
529
+ }
530
+ return JSON.stringify(value, (k, v) => { return noCompare.has(k) ? undefined : v; });
531
+ }
532
+ function joinPath(left, right) {
533
+ if (!right) {
534
+ return left;
535
+ }
536
+ return `${left}.${right}`;
537
+ }
538
+ function compareDeep(oldData, newData, paths) {
539
+ var _a;
540
+ const location = (newData === null || newData === void 0 ? void 0 : newData.kind) && ((_a = newData === null || newData === void 0 ? void 0 : newData.nameLocation) !== null && _a !== void 0 ? _a : newData === null || newData === void 0 ? void 0 : newData.nodeLocation);
541
+ const diffs = [];
542
+ if (typeof oldData != typeof newData) {
543
+ diffs.push({ path: "", oldValue: safeString(oldData), newValue: safeString(newData) });
544
+ }
545
+ else if (Array.isArray(oldData) && Array.isArray(newData)) {
546
+ const len = Math.max(oldData.length, newData.length);
547
+ if (oldData.length != newData.length) {
548
+ diffs.push({ path: "", oldValue: `(length=${oldData.length})`, newValue: `(length=${newData.length})` });
549
+ }
550
+ for (let i = 0; i < len; ++i) {
551
+ const deeperDiffs = compareDeep(oldData[i], newData[i], paths);
552
+ if (deeperDiffs.length > 0) {
553
+ diffs.push(...deeperDiffs.map(x => { x.path = joinPath("" + i, x.path); return x; }));
554
+ }
555
+ }
556
+ }
557
+ else if (typeof newData == "object") {
558
+ const keys = [...new Set([...Object.getOwnPropertyNames(oldData), ...Object.getOwnPropertyNames(newData)])].filter(x => !noCompare.has(x));
559
+ for (const k of keys) {
560
+ let oldValue = oldData[k];
561
+ let newValue = newData[k];
562
+ if (canContainMoreCompare.has(k)) {
563
+ if (newValue == null && Array.isArray(oldValue) && oldValue.length == 0) {
564
+ continue;
565
+ }
566
+ if (oldValue == null && Array.isArray(newValue)) {
567
+ continue;
568
+ }
569
+ if (Array.isArray(oldValue) && Array.isArray(newValue)) {
570
+ if (newValue.length > oldValue.length) {
571
+ // Cases when old parser takes attributes from outer declaration and ignores the right ones
572
+ newValue = newValue.slice(newValue.length - oldValue.length);
573
+ }
574
+ else if (oldValue.length > newValue.length) {
575
+ // Cases when types in parentheses have own attributes, but old parser adds attributes from outer declaration
576
+ oldValue = oldValue.slice(0, newValue.length);
577
+ }
578
+ }
579
+ }
580
+ const deeperDiffs = compareDeep(oldValue, newValue, paths);
581
+ if (deeperDiffs.length > 0) {
582
+ diffs.push(...deeperDiffs.map(x => { x.path = joinPath(k, x.path); return x; }));
583
+ }
584
+ }
585
+ }
586
+ else {
587
+ if (oldData != newData) {
588
+ diffs.push({ path: "", oldValue: safeString(oldData), newValue: safeString(newData) });
589
+ }
590
+ }
591
+ if (!location) {
592
+ return diffs;
593
+ }
594
+ for (const diff of diffs) {
595
+ paths.add(diff.path);
596
+ DifferenceFound.reportDiagnosticMessage([location], `path: ${diff.path} oldValue: ${diff.oldValue} newValue: ${diff.newValue}`);
597
+ }
598
+ return [];
599
+ }
600
+ function compareParsingResults(oldFile, newFile) {
601
+ const paths = new Set();
602
+ compareDeep(oldFile, newFile, paths);
603
+ if (paths.size > 0) {
604
+ DifferenceFound.reportDiagnosticMessage([newFile.nodeLocation], "Differences found in those paths:\n" + [...paths].join("\n"));
605
+ }
606
+ }
607
+ function parseIdlNew(fileName, content, registerSynthetics) {
608
+ let file = new Parser(fileName, content).parseIDL();
609
+ const ancestors = [];
610
+ const namespaces = [];
611
+ // Mimic old parser and deserialize.ts behavior:
612
+ // 1. Add `fileName`.
613
+ // 2. Add `parent`.
614
+ // 3. Possibly register node with `addSyntheticType` if "Synthetic" is in attributes
615
+ idl.forEachChild(file, (node) => {
616
+ var _a;
617
+ if (idl.isPrimitiveType(node)) {
618
+ return;
619
+ }
620
+ node.fileName = fileName;
621
+ if (registerSynthetics && idl.isEntry(node) && ((_a = node.extendedAttributes) === null || _a === void 0 ? void 0 : _a.some(it => it.name === "Synthetic"))) {
622
+ const fqName = file.packageClause.concat(namespaces).concat([node.name]).join('.');
623
+ addSyntheticType(fqName, node);
624
+ }
625
+ if (ancestors.length) {
626
+ node.parent = ancestors[ancestors.length - 1];
627
+ }
628
+ if (idl.isNamespace(node)) {
629
+ namespaces.push(node.name);
630
+ }
631
+ ancestors.push(node);
632
+ }, (node) => {
633
+ if (idl.isPrimitiveType(node)) {
634
+ return;
635
+ }
636
+ if (idl.isNamespace(node)) {
637
+ namespaces.pop();
638
+ }
639
+ ancestors.pop();
640
+ });
641
+ return file;
642
+ }
522
643
  export function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } = {}) {
523
644
  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
+ }
524
653
  const lexicalInfo = new Map();
525
654
  const deserializer = new IDLDeserializer(lexicalInfo, inheritanceMode);
526
655
  if (undefined === content) {
@@ -529,7 +658,7 @@ export function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } =
529
658
  }
530
659
  catch (e) {
531
660
  content = "";
532
- LoadingErrorMessage.throwDiagnosticMessage([{ documentPath: fileName }], (_a = e.message) !== null && _a !== void 0 ? _a : "");
661
+ throw new FatalParserException([LoadingFatal.reportDiagnosticMessage([{ documentPath: fileName }], (_a = e.message) !== null && _a !== void 0 ? _a : "")]);
533
662
  }
534
663
  }
535
664
  let lines = (_b = content.match(/[^\r\n]*(\n|\r\n)?/g)) !== null && _b !== void 0 ? _b : [];
@@ -545,9 +674,9 @@ export function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } =
545
674
  if (e.name == "WebIDLParseError") {
546
675
  let tokens = e.tokens;
547
676
  let range = tokens.length > 0 ? rangeForToken(offsets, tokens[0]) : undefined;
548
- ParsingErrorMessage.throwDiagnosticMessage([{ documentPath: fileName, range, lines }], e.bareMessage);
677
+ throw new FatalParserException([ParsingFatal.reportDiagnosticMessage([{ documentPath: fileName, range, lines }], e.bareMessage)]);
549
678
  }
550
- UnknownErrorMessage.throwDiagnosticMessage([{ documentPath: fileName }], (_c = e.message) !== null && _c !== void 0 ? _c : "");
679
+ throw new FatalParserException([InternalFatal.reportDiagnosticMessage([{ documentPath: fileName, lines }], (_c = e.message) !== null && _c !== void 0 ? _c : "")]);
551
680
  }
552
681
  const entries = rawParsingResults
553
682
  .filter(it => {
@@ -571,6 +700,10 @@ export function toIDLFile(fileName, { content, inheritanceMode = 'multiple' } =
571
700
  node.nameLocation = nameLocation;
572
701
  }
573
702
  });
703
+ if (mode == "compare") {
704
+ compareParsingResults(file, newFile);
705
+ return [newFile, new Map()];
706
+ }
574
707
  return [file, lexicalInfo];
575
708
  }
576
709
  function prepareOffsets(lines) {
@@ -0,0 +1,99 @@
1
+ import * as idl from "../idl";
2
+ import { DiagnosticMessage, Location } from "../diagnostictypes";
3
+ export declare class FatalParserException extends Error {
4
+ diagnosticMessages?: DiagnosticMessage[];
5
+ constructor(diagnosticMessages?: DiagnosticMessage[]);
6
+ }
7
+ declare enum TokenKind {
8
+ Words = 0,
9
+ Literal = 1,
10
+ Symbol = 2,
11
+ Comment = 3,
12
+ Whitespace = 4,
13
+ End = 5
14
+ }
15
+ interface Token {
16
+ kind: TokenKind;
17
+ value: string;
18
+ location: Location;
19
+ }
20
+ type ModifierToken = "static" | "readonly" | "async";
21
+ type ModifiersContainer = {
22
+ [Key in ModifierToken]?: Token;
23
+ };
24
+ export declare class Parser {
25
+ fileName: string;
26
+ content: string;
27
+ lines: string[];
28
+ offsets: number[];
29
+ constructor(fileName: string, content?: string);
30
+ parseIDL(): idl.IDLFile;
31
+ _curOffset: number;
32
+ _curLine: number;
33
+ _curToken: Token;
34
+ _prevToken: Token;
35
+ _generics: string[][];
36
+ _enableInLiteralParsing: boolean;
37
+ _match(re: RegExp, kind: TokenKind): Token | undefined;
38
+ _reDecimal: RegExp;
39
+ _reInteger: RegExp;
40
+ _reString: RegExp;
41
+ _reWords: RegExp;
42
+ _reSymbol: RegExp;
43
+ _reWhitespace: RegExp;
44
+ _reComment: RegExp;
45
+ _reIsDocComment: RegExp;
46
+ _matchComment(): Token | undefined;
47
+ _lexerNext(): void;
48
+ get curToken(): Token;
49
+ get curKind(): TokenKind;
50
+ get curValue(): string;
51
+ get curLocation(): Location;
52
+ see(tok: string): boolean;
53
+ seeAndSkip(tok: string): boolean;
54
+ seeEof(): boolean;
55
+ skip(tok: string): void;
56
+ skipToAfter(tok: string): void;
57
+ trackLocation(): () => Location;
58
+ _internalCurrentExtended: idl.IDLExtendedAttribute[] | undefined;
59
+ consumeCurrentExtended(): idl.IDLExtendedAttribute[] | undefined;
60
+ currentModifiers: ModifiersContainer;
61
+ assertPossibleModifiers(...mods: ModifierToken[]): void;
62
+ precedingComment: Token | undefined;
63
+ currentPackage: string | undefined;
64
+ parseSingleIdentifier(): Token;
65
+ parseFullIdentifier(): Token;
66
+ parseFullIdentifierOrLiteral(): Token;
67
+ parseLiteral(): Token;
68
+ parseAndPushGenerics(ext?: idl.IDLExtendedAttribute[]): string[] | undefined;
69
+ hasGeneric(name: string): boolean;
70
+ parseFile(): idl.IDLFile;
71
+ parseDeclaration(scopeKind: idl.IDLKind): idl.IDLEntry | undefined;
72
+ parseDeclarationUnsafe(scopeKind: idl.IDLKind): idl.IDLEntry | undefined;
73
+ parseNamespace(): idl.IDLNamespace;
74
+ parseInterface(): idl.IDLInterface;
75
+ parseExtendedAttributes(): idl.IDLExtendedAttribute[] | undefined;
76
+ parseTypeList(): idl.IDLType[];
77
+ parseType(outerExt?: idl.IDLExtendedAttribute[]): idl.IDLType;
78
+ parseReferenceType(): idl.IDLReferenceType;
79
+ parsePrimitiveType(): idl.IDLPrimitiveType;
80
+ parseArgTuple(): idl.IDLParameter[];
81
+ parseArg(): idl.IDLParameter;
82
+ parseOperation(): idl.IDLCallable | idl.IDLMethod;
83
+ parseConstructor(): idl.IDLConstructor;
84
+ parseConst(): idl.IDLConstant;
85
+ parseAttribute(): idl.IDLProperty;
86
+ parseTypedef(): idl.IDLTypedef;
87
+ parseCallback(): idl.IDLCallback;
88
+ parseEnum(): idl.IDLEnum;
89
+ parseDictionary(): idl.IDLEnum;
90
+ parseDictionaryEntry(): idl.IDLEnumMember;
91
+ parsePackage(): {
92
+ location: Location;
93
+ name: string;
94
+ };
95
+ parseImport(): idl.IDLImport;
96
+ parseVersion(): idl.IDLVersion;
97
+ }
98
+ export {};
99
+ //# sourceMappingURL=parser.d.ts.map