@sdkgen/parser 1.6.1 → 2.0.1

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 (37) hide show
  1. package/README.md +1 -3
  2. package/dist/spec/lexer.spec.js +1 -3
  3. package/dist/spec/parser.spec.js +305 -30
  4. package/dist/src/ast.d.ts +17 -15
  5. package/dist/src/ast.js +23 -21
  6. package/dist/src/compatibility/index.js +17 -7
  7. package/dist/src/index.js +5 -1
  8. package/dist/src/json.d.ts +10 -18
  9. package/dist/src/json.js +100 -62
  10. package/dist/src/lexer.js +1 -7
  11. package/dist/src/parser.js +92 -40
  12. package/dist/src/semantic/{06_give_struct_and_enum_names.d.ts → 02_give_struct_and_enum_names.d.ts} +0 -0
  13. package/dist/src/semantic/{06_give_struct_and_enum_names.js → 02_give_struct_and_enum_names.js} +6 -1
  14. package/dist/src/semantic/{02_match_type_definitions.d.ts → 03_match_type_definitions.d.ts} +0 -0
  15. package/dist/src/semantic/{02_match_type_definitions.js → 03_match_type_definitions.js} +0 -0
  16. package/dist/src/semantic/04_check_dont_return_secret.d.ts +1 -0
  17. package/dist/src/semantic/04_check_dont_return_secret.js +7 -1
  18. package/dist/src/semantic/05_expand_spreads.d.ts +9 -0
  19. package/dist/src/semantic/05_expand_spreads.js +60 -0
  20. package/dist/src/semantic/{07_check_empty_struct_or_enum.d.ts → 06_check_empty_struct_or_enum.d.ts} +0 -0
  21. package/dist/src/semantic/{07_check_empty_struct_or_enum.js → 06_check_empty_struct_or_enum.js} +1 -1
  22. package/dist/src/semantic/07_validate_recursive_types.d.ts +8 -0
  23. package/dist/src/semantic/07_validate_recursive_types.js +49 -0
  24. package/dist/src/semantic/{10_validate_annotations.d.ts → 09_validate_annotations.d.ts} +0 -0
  25. package/dist/src/semantic/{10_validate_annotations.js → 09_validate_annotations.js} +5 -1
  26. package/dist/src/semantic/analyser.js +12 -14
  27. package/dist/src/semantic/visitor.js +19 -3
  28. package/dist/src/token.d.ts +1 -4
  29. package/dist/src/token.js +4 -10
  30. package/dist/tsconfig.tsbuildinfo +1 -2191
  31. package/package.json +6 -6
  32. package/dist/src/semantic/03_check_no_recursive_types.d.ts +0 -7
  33. package/dist/src/semantic/03_check_no_recursive_types.js +0 -36
  34. package/dist/src/semantic/05_check_naming_for_getters_returning_bool.d.ts +0 -5
  35. package/dist/src/semantic/05_check_naming_for_getters_returning_bool.js +0 -21
  36. package/dist/src/semantic/09_apply_struct_spreads.d.ts +0 -7
  37. package/dist/src/semantic/09_apply_struct_spreads.js +0 -42
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdkgen/parser",
3
- "version": "1.6.1",
3
+ "version": "2.0.1",
4
4
  "description": "",
5
5
  "main": "dist/src/index.js",
6
6
  "scripts": {
@@ -23,11 +23,11 @@
23
23
  },
24
24
  "homepage": "https://github.com/sdkgen/sdkgen#readme",
25
25
  "devDependencies": {
26
- "@cubos/eslint-config": "1.0.480297",
27
- "@types/jest": "^26.0.22",
28
- "jest": "^26.6.3",
29
- "ts-jest": "^26.5.4",
30
- "typescript": "4.2.3"
26
+ "@cubos/eslint-config": "^1.0.536820",
27
+ "@types/jest": "^27.0.1",
28
+ "jest": "^27.0.6",
29
+ "ts-jest": "^27.0.5",
30
+ "typescript": "^4.3.5"
31
31
  },
32
32
  "jest": {
33
33
  "transform": {
@@ -1,7 +0,0 @@
1
- import type { AstNode, Type } from "../ast";
2
- import { Visitor } from "./visitor";
3
- export declare class CheckNoRecursiveTypesVisitor extends Visitor {
4
- path: string[];
5
- rootType: Type | undefined;
6
- visit(node: AstNode): void;
7
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CheckNoRecursiveTypesVisitor = void 0;
4
- const ast_1 = require("../ast");
5
- const visitor_1 = require("./visitor");
6
- class CheckNoRecursiveTypesVisitor extends visitor_1.Visitor {
7
- constructor() {
8
- super(...arguments);
9
- this.path = [];
10
- }
11
- visit(node) {
12
- if (node instanceof ast_1.TypeDefinition) {
13
- this.path = [node.name];
14
- this.rootType = node.type;
15
- super.visit(node);
16
- this.path = [];
17
- this.rootType = undefined;
18
- }
19
- else if (node instanceof ast_1.Field) {
20
- this.path.push(node.name);
21
- super.visit(node);
22
- this.path.pop();
23
- }
24
- else if (node instanceof ast_1.TypeReference) {
25
- if (this.rootType === node.type) {
26
- throw new visitor_1.SemanticError(`Detected type recursion: ${this.path.join(".")} at ${node.location}`);
27
- }
28
- this.visit(node.type);
29
- super.visit(node);
30
- }
31
- else {
32
- super.visit(node);
33
- }
34
- }
35
- }
36
- exports.CheckNoRecursiveTypesVisitor = CheckNoRecursiveTypesVisitor;
@@ -1,5 +0,0 @@
1
- import type { AstNode } from "../ast";
2
- import { Visitor } from "./visitor";
3
- export declare class CheckNamingForGettersReturningBoolVisitor extends Visitor {
4
- visit(node: AstNode): void;
5
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CheckNamingForGettersReturningBoolVisitor = void 0;
4
- const ast_1 = require("../ast");
5
- const visitor_1 = require("./visitor");
6
- class CheckNamingForGettersReturningBoolVisitor extends visitor_1.Visitor {
7
- visit(node) {
8
- super.visit(node);
9
- if (node instanceof ast_1.GetOperation) {
10
- const returnsBool = node.returnType instanceof ast_1.BoolPrimitiveType;
11
- const hasBoolNaming = /^(?:is|has|can|may|should)/u.test(node.name);
12
- if (returnsBool && !hasBoolNaming) {
13
- throw new visitor_1.SemanticError(`Get operation '${node.name}' at ${node.location} returns bool but isn't named accordingly`);
14
- }
15
- else if (!returnsBool && hasBoolNaming) {
16
- throw new visitor_1.SemanticError(`Get operation '${node.name}' at ${node.location} doesn't return bool but its name suggest it does`);
17
- }
18
- }
19
- }
20
- }
21
- exports.CheckNamingForGettersReturningBoolVisitor = CheckNamingForGettersReturningBoolVisitor;
@@ -1,7 +0,0 @@
1
- import type { AstNode } from "../ast";
2
- import { StructType } from "../ast";
3
- import { Visitor } from "./visitor";
4
- export declare class ApplyStructSpreadsVisitor extends Visitor {
5
- processed: Set<StructType>;
6
- visit(node: AstNode): void;
7
- }
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApplyStructSpreadsVisitor = void 0;
4
- const ast_1 = require("../ast");
5
- const visitor_1 = require("./visitor");
6
- class ApplyStructSpreadsVisitor extends visitor_1.Visitor {
7
- constructor() {
8
- super(...arguments);
9
- /*
10
- * Here we may visit the same struct multiple times
11
- * We must make sure we only process each one once
12
- */
13
- this.processed = new Set();
14
- }
15
- visit(node) {
16
- if (node instanceof ast_1.StructType) {
17
- if (this.processed.has(node)) {
18
- return;
19
- }
20
- this.processed.add(node);
21
- }
22
- super.visit(node);
23
- if (node instanceof ast_1.StructType) {
24
- for (const other of node.spreads.map(t => t.type)) {
25
- if (!(other instanceof ast_1.StructType)) {
26
- throw new visitor_1.SemanticError(`A spread operator in a struct can't refer to something that is not a struct, in '${node.name}' at ${node.location}.`);
27
- }
28
- this.visit(other); // Recursion!
29
- for (const otherField of other.fields) {
30
- const existingIdx = node.fields.findIndex(f => f.name === otherField.name);
31
- if (existingIdx >= 0) {
32
- node.fields[existingIdx] = otherField;
33
- }
34
- else {
35
- node.fields.push(otherField);
36
- }
37
- }
38
- }
39
- }
40
- }
41
- }
42
- exports.ApplyStructSpreadsVisitor = ApplyStructSpreadsVisitor;