@traqula/core 0.0.23 → 0.0.24

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 (51) hide show
  1. package/dist/cjs/lib/AstCoreFactory.js +136 -149
  2. package/dist/cjs/lib/AstCoreFactory.js.map +1 -0
  3. package/dist/cjs/lib/generator-builder/builderTypes.js +2 -15
  4. package/dist/cjs/lib/generator-builder/builderTypes.js.map +1 -0
  5. package/dist/cjs/lib/generator-builder/dynamicGenerator.js +189 -200
  6. package/dist/cjs/lib/generator-builder/dynamicGenerator.js.map +1 -0
  7. package/dist/cjs/lib/generator-builder/generatorBuilder.js +103 -117
  8. package/dist/cjs/lib/generator-builder/generatorBuilder.js.map +1 -0
  9. package/dist/cjs/lib/generator-builder/generatorTypes.js +2 -15
  10. package/dist/cjs/lib/generator-builder/generatorTypes.js.map +1 -0
  11. package/dist/cjs/lib/index.js +39 -57
  12. package/dist/cjs/lib/index.js.map +1 -0
  13. package/dist/cjs/lib/indirection-builder/IndirBuilder.js +63 -85
  14. package/dist/cjs/lib/indirection-builder/IndirBuilder.js.map +1 -0
  15. package/dist/cjs/lib/indirection-builder/dynamicIndirected.js +28 -50
  16. package/dist/cjs/lib/indirection-builder/dynamicIndirected.js.map +1 -0
  17. package/dist/cjs/lib/indirection-builder/helpers.js +11 -31
  18. package/dist/cjs/lib/indirection-builder/helpers.js.map +1 -0
  19. package/dist/cjs/lib/lexer-builder/LexerBuilder.js +92 -114
  20. package/dist/cjs/lib/lexer-builder/LexerBuilder.js.map +1 -0
  21. package/dist/cjs/lib/parser-builder/builderTypes.js +2 -15
  22. package/dist/cjs/lib/parser-builder/builderTypes.js.map +1 -0
  23. package/dist/cjs/lib/parser-builder/dynamicParser.js +115 -136
  24. package/dist/cjs/lib/parser-builder/dynamicParser.js.map +1 -0
  25. package/dist/cjs/lib/parser-builder/parserBuilder.js +167 -169
  26. package/dist/cjs/lib/parser-builder/parserBuilder.js.map +1 -0
  27. package/dist/cjs/lib/parser-builder/ruleDefTypes.js +2 -15
  28. package/dist/cjs/lib/parser-builder/ruleDefTypes.js.map +1 -0
  29. package/dist/cjs/lib/transformers/TransformerObject.js +196 -198
  30. package/dist/cjs/lib/transformers/TransformerObject.js.map +1 -0
  31. package/dist/cjs/lib/transformers/TransformerSubTyped.js +120 -141
  32. package/dist/cjs/lib/transformers/TransformerSubTyped.js.map +1 -0
  33. package/dist/cjs/lib/transformers/TransformerTyped.js +99 -120
  34. package/dist/cjs/lib/transformers/TransformerTyped.js.map +1 -0
  35. package/dist/cjs/lib/types.js +2 -15
  36. package/dist/cjs/lib/types.js.map +1 -0
  37. package/dist/cjs/lib/utils.js +13 -34
  38. package/dist/cjs/lib/utils.js.map +1 -0
  39. package/package.json +9 -9
  40. package/dist/cjs/test/generatorBuilder/generatorBuilder.types.test.js +0 -30
  41. package/dist/cjs/test/grammar-builder/parserBuilder.types.test.js +0 -27
  42. package/dist/cjs/test/transformer.test.js +0 -82
  43. package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.d.ts +0 -1
  44. package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.js +0 -38
  45. package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.js.map +0 -1
  46. package/dist/esm/test/grammar-builder/parserBuilder.types.test.d.ts +0 -1
  47. package/dist/esm/test/grammar-builder/parserBuilder.types.test.js +0 -38
  48. package/dist/esm/test/grammar-builder/parserBuilder.types.test.js.map +0 -1
  49. package/dist/esm/test/transformer.test.d.ts +0 -1
  50. package/dist/esm/test/transformer.test.js +0 -82
  51. package/dist/esm/test/transformer.test.js.map +0 -1
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@traqula/core",
3
3
  "type": "module",
4
- "version": "0.0.23",
4
+ "version": "0.0.24",
5
5
  "description": "Core components of Traqula",
6
6
  "lsd:module": true,
7
7
  "license": "MIT",
@@ -27,21 +27,21 @@
27
27
  "access": "public"
28
28
  },
29
29
  "files": [
30
- "dist/**/*.d.ts",
31
- "dist/**/*.js",
32
- "dist/**/*.js.map",
33
- "dist/**/package.json"
30
+ "dist/*/lib/**/*.d.ts",
31
+ "dist/*/lib/**/*.js",
32
+ "dist/*/lib/**/*.js.map",
33
+ "dist/cjs/package.json"
34
34
  ],
35
35
  "engines": {
36
36
  "node": "^20.19.0 || >=22.12.0"
37
37
  },
38
38
  "scripts": {
39
- "build": "yarn build:ts && yarn build:transpile",
39
+ "build": "yarn build:ts && yarn build:cjs",
40
40
  "build:ts": "node \"../../node_modules/typescript/bin/tsc\" -b",
41
- "build:transpile": "esbuild \"dist/esm/**/*.js\" --outdir=dist/cjs --platform=node --format=cjs"
41
+ "build:cjs": "node \"../../node_modules/typescript/bin/tsc\" -b tsconfig.cjs.json"
42
42
  },
43
43
  "dependencies": {
44
- "@traqula/chevrotain": "^0.0.23"
44
+ "@traqula/chevrotain": "^0.0.24"
45
45
  },
46
- "gitHead": "36ec1aae80524a84f044182811a55ebeef6d9cda"
46
+ "gitHead": "9865fe1fe302819d46e19c6f3250ceef778f434f"
47
47
  }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- var import_vitest = require("vitest");
3
- var import_lib = require("../../lib/index.js");
4
- const RuleA = {
5
- name: "apple",
6
- gImpl: () => () => {
7
- }
8
- };
9
- const RuleB = {
10
- name: "banana",
11
- gImpl: () => () => {
12
- }
13
- };
14
- const RuleC = {
15
- name: "coconut",
16
- gImpl: () => () => {
17
- }
18
- };
19
- (0, import_vitest.describe)("parserBuilder", () => {
20
- (0, import_vitest.describe)("types", () => {
21
- (0, import_vitest.it)("builder constructor", () => {
22
- (0, import_vitest.expectTypeOf)(import_lib.GeneratorBuilder.create([RuleA])).branded.toEqualTypeOf();
23
- (0, import_vitest.expectTypeOf)(import_lib.GeneratorBuilder.create([RuleB])).branded.toEqualTypeOf();
24
- (0, import_vitest.expectTypeOf)(import_lib.GeneratorBuilder.create([RuleA, RuleB])).branded.toEqualTypeOf();
25
- (0, import_vitest.expectTypeOf)(import_lib.GeneratorBuilder.create([RuleA, RuleB]).addRule(RuleC)).branded.toEqualTypeOf();
26
- (0, import_vitest.expectTypeOf)(import_lib.GeneratorBuilder.create([RuleA]).merge(import_lib.GeneratorBuilder.create([RuleB]), [])).branded.toEqualTypeOf();
27
- (0, import_vitest.expectTypeOf)(import_lib.GeneratorBuilder.create([RuleA, RuleB]).merge(import_lib.GeneratorBuilder.create([RuleB, RuleC]), [])).branded.toEqualTypeOf();
28
- });
29
- });
30
- });
@@ -1,27 +0,0 @@
1
- "use strict";
2
- var import_vitest = require("vitest");
3
- var import_lib = require("../../lib/index.js");
4
- const RuleA = {
5
- name: "apple",
6
- impl: () => () => "apple"
7
- };
8
- const RuleB = {
9
- name: "banana",
10
- impl: () => () => "banana"
11
- };
12
- const RuleC = {
13
- name: "coconut",
14
- impl: () => () => "coconut"
15
- };
16
- (0, import_vitest.describe)("parserBuilder", () => {
17
- (0, import_vitest.describe)("types", () => {
18
- (0, import_vitest.it)("builder constructor", () => {
19
- (0, import_vitest.expectTypeOf)(import_lib.ParserBuilder.create([RuleA])).branded.toEqualTypeOf();
20
- (0, import_vitest.expectTypeOf)(import_lib.ParserBuilder.create([RuleB])).branded.toEqualTypeOf();
21
- (0, import_vitest.expectTypeOf)(import_lib.ParserBuilder.create([RuleA, RuleB])).branded.toEqualTypeOf();
22
- (0, import_vitest.expectTypeOf)(import_lib.ParserBuilder.create([RuleA, RuleB]).addRule(RuleC)).branded.toEqualTypeOf();
23
- (0, import_vitest.expectTypeOf)(import_lib.ParserBuilder.create([RuleA]).merge(import_lib.ParserBuilder.create([RuleB]), [])).branded.toEqualTypeOf();
24
- (0, import_vitest.expectTypeOf)(import_lib.ParserBuilder.create([RuleA, RuleB]).merge(import_lib.ParserBuilder.create([RuleB, RuleC]), [])).branded.toEqualTypeOf();
25
- });
26
- });
27
- });
@@ -1,82 +0,0 @@
1
- "use strict";
2
- var import_vitest = require("vitest");
3
- var import_lib = require("../lib/index.js");
4
- (0, import_vitest.describe)("transformer", () => {
5
- const transformer = new import_lib.TransformerTyped();
6
- (0, import_vitest.it)("makes copies when needed", ({ expect }) => {
7
- const fruit = {
8
- type: "fruit",
9
- clone1: { type: "vegetable", random: { type: "fruit", val: "blep" } }
10
- };
11
- const fullCopy = transformer.transformNode(fruit, {});
12
- expect(fullCopy).not.toBe(fruit);
13
- expect(fullCopy.clone1).not.toBe(fruit.clone1);
14
- expect(fullCopy.clone1.random).not.toBe(fruit.clone1.random);
15
- const sameVegetable = transformer.transformNode(fruit, {
16
- vegetable: { preVisitor: () => ({ copy: false }) },
17
- fruit: { transform: (fruit2) => {
18
- fruit2.test = "yes";
19
- return fruit2;
20
- } }
21
- });
22
- expect(sameVegetable).not.toBe(fruit);
23
- expect(sameVegetable.clone1).toBe(fruit.clone1);
24
- expect(sameVegetable.clone1.random).toMatchObject({ test: "yes" });
25
- });
26
- (0, import_vitest.it)("knows shortcut and continue", ({ expect }) => {
27
- const in2 = { type: "fruit", val: "depth3" };
28
- const in1 = { type: "vegetable", in: in2, val: "depth2" };
29
- const side1 = { type: "fruit", val: "side1" };
30
- const side2 = { type: "vegetable" };
31
- const fruit = { type: "fruit", in: in1, val: "depth1", side: side1, side2 };
32
- const onlyCopyDepth1 = transformer.transformNode(fruit, {
33
- fruit: { preVisitor: () => ({ continue: false }) }
34
- });
35
- expect(onlyCopyDepth1).not.toBe(fruit);
36
- expect(onlyCopyDepth1.in).toBe(in1);
37
- expect(onlyCopyDepth1.in.in).toBe(in2);
38
- expect(onlyCopyDepth1.side).toBe(side1);
39
- const doNotCopy = transformer.transformNode(fruit, {
40
- fruit: { preVisitor: () => ({ continue: false, copy: false }) }
41
- });
42
- expect(doNotCopy).toBe(fruit);
43
- expect(doNotCopy.in).toBe(in1);
44
- expect(doNotCopy.in.in).toBe(in2);
45
- expect(doNotCopy.side).toBe(side1);
46
- const doNotCopyByShortcut = transformer.transformNode(fruit, {
47
- fruit: { preVisitor: () => ({ shortcut: true }) }
48
- });
49
- expect(doNotCopyByShortcut).not.toBe(fruit);
50
- expect(doNotCopyByShortcut.in).toBe(in1);
51
- expect(doNotCopyByShortcut.in.in).toBe(in2);
52
- expect(doNotCopyByShortcut.side).toBe(side1);
53
- const doNotCopySideWhenShortcut = transformer.transformNode(fruit, {
54
- vegetable: { preVisitor: () => ({ shortcut: true }) }
55
- });
56
- expect(doNotCopySideWhenShortcut).not.toBe(fruit);
57
- expect(doNotCopySideWhenShortcut.in).toBe(in1);
58
- expect(doNotCopySideWhenShortcut.in.in).toBe(in2);
59
- expect(doNotCopySideWhenShortcut.side).toBe(side1);
60
- expect(doNotCopySideWhenShortcut.side2).not.toBe(side2);
61
- });
62
- (0, import_vitest.it)("knows shallowKeys and ignoreKeys", ({ expect }) => {
63
- const in2 = { type: "fruit", val: "depth3" };
64
- const in1 = { type: "vegetable", in: in2, val: "depth2" };
65
- const side1 = { type: "fruit", val: "side1" };
66
- const fruit = { type: "fruit", in: in1, val: "depth1", side: side1 };
67
- const noDeepOnShallowKeys = transformer.transformNode(fruit, {
68
- fruit: { preVisitor: () => ({ shallowKeys: /* @__PURE__ */ new Set(["in"]) }) }
69
- });
70
- expect(noDeepOnShallowKeys).not.toBe(fruit);
71
- expect(noDeepOnShallowKeys.in).not.toBe(in1);
72
- expect(noDeepOnShallowKeys.in.in).toBe(in2);
73
- expect(noDeepOnShallowKeys.side).not.toBe(side1);
74
- const ignoreKeysAreIgnored = transformer.transformNode(fruit, {
75
- fruit: { preVisitor: () => ({ ignoreKeys: /* @__PURE__ */ new Set(["in"]) }) }
76
- });
77
- expect(ignoreKeysAreIgnored).not.toBe(fruit);
78
- expect(ignoreKeysAreIgnored.in).toBe(in1);
79
- expect(ignoreKeysAreIgnored.in.in).toBe(in2);
80
- expect(ignoreKeysAreIgnored.side).not.toBe(side1);
81
- });
82
- });
@@ -1,38 +0,0 @@
1
- import { describe, it, expectTypeOf } from 'vitest';
2
- import { GeneratorBuilder } from '../../lib/index.js';
3
- const RuleA = {
4
- name: 'apple',
5
- gImpl: () => () => { },
6
- };
7
- const RuleB = {
8
- name: 'banana',
9
- gImpl: () => () => { },
10
- };
11
- const RuleC = {
12
- name: 'coconut',
13
- gImpl: () => () => { },
14
- };
15
- describe('parserBuilder', () => {
16
- describe('types', () => {
17
- it('builder constructor', () => {
18
- expectTypeOf(GeneratorBuilder.create([RuleA]))
19
- .branded.toEqualTypeOf();
20
- expectTypeOf(GeneratorBuilder.create([RuleB]))
21
- .branded.toEqualTypeOf();
22
- expectTypeOf(GeneratorBuilder.create([RuleA, RuleB]))
23
- .branded
24
- .toEqualTypeOf();
25
- // AddRule
26
- expectTypeOf(GeneratorBuilder.create([RuleA, RuleB]).addRule(RuleC))
27
- .branded.toEqualTypeOf();
28
- // Merge
29
- expectTypeOf(GeneratorBuilder.create([RuleA])
30
- .merge(GeneratorBuilder.create([RuleB]), [])).branded
31
- .toEqualTypeOf();
32
- expectTypeOf(GeneratorBuilder.create([RuleA, RuleB])
33
- .merge(GeneratorBuilder.create([RuleB, RuleC]), [])).branded
34
- .toEqualTypeOf();
35
- });
36
- });
37
- });
38
- //# sourceMappingURL=generatorBuilder.types.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generatorBuilder.types.test.js","sourceRoot":"","sources":["../../../../test/generatorBuilder/generatorBuilder.types.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAMtD,MAAM,KAAK,GAA+D;IACxE,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC;CACtB,CAAC;AACF,MAAM,KAAK,GAAkE;IAC3E,IAAI,EAAE,QAAQ;IACd,KAAK,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,GAAE,CAAC;CACtB,CAAC;AACF,MAAM,KAAK,GAAqE;IAC9E,IAAI,EAAE,S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C","sourcesContent":["import { describe, it, expectTypeOf } from 'vitest';\nimport type { GeneratorRule, Node } from '../../lib/index.js';\nimport { GeneratorBuilder } from '../../lib/index.js';\n\ninterface Context {\n world: 'hello';\n}\n\nconst RuleA: GeneratorRule<Context, 'apple', { apple: 'apple' } & Node> = {\n name: 'apple',\n gImpl: () => () => {},\n};\nconst RuleB: GeneratorRule<Context, 'banana', { banana: 'banana' } & Node> = {\n name: 'banana',\n gImpl: () => () => {},\n};\nconst RuleC: GeneratorRule<Context, 'coconut', { coconut: 'coconut' } & Node> = {\n name: 'coconut',\n gImpl: () => () => {},\n};\n\ndescribe('parserBuilder', () => {\n describe('types', () => {\n it('builder constructor', () => {\n expectTypeOf(GeneratorBuilder.create(<const> [ RuleA ]))\n .branded.toEqualTypeOf<GeneratorBuilder<Context, 'apple', { apple: typeof RuleA }>>();\n expectTypeOf(GeneratorBuilder.create(<const> [ RuleB ]))\n .branded.toEqualTypeOf<GeneratorBuilder<Context, 'banana', { banana: typeof RuleB }>>();\n expectTypeOf(GeneratorBuilder.create(<const> [ RuleA, RuleB ]))\n .branded\n .toEqualTypeOf<GeneratorBuilder<Context, 'apple' | 'banana', { apple: typeof RuleA; banana: typeof RuleB }>>();\n\n // AddRule\n expectTypeOf(GeneratorBuilder.create(<const> [ RuleA, RuleB ]).addRule(RuleC))\n .branded.toEqualTypeOf<GeneratorBuilder<\n Context,\n 'apple' | 'banana' | 'coconut',\n { apple: typeof RuleA; banana: typeof RuleB; coconut: typeof RuleC }\n >>();\n\n // Merge\n expectTypeOf(\n GeneratorBuilder.create(<const> [ RuleA ])\n .merge(GeneratorBuilder.create(<const> [ RuleB ]), <const> []),\n ).branded\n .toEqualTypeOf<GeneratorBuilder<Context, 'apple' | 'banana', { apple: typeof RuleA; banana: typeof RuleB }>>();\n\n expectTypeOf(\n GeneratorBuilder.create(<const> [ RuleA, RuleB ])\n .merge(GeneratorBuilder.create(<const> [ RuleB, RuleC ]), <const> []),\n ).branded\n .toEqualTypeOf<GeneratorBuilder<\n Context,\n 'apple' | 'banana' | 'coconut',\n { apple: typeof RuleA; banana: typeof RuleB; coconut: typeof RuleC }\n >>();\n });\n });\n});\n"]}
@@ -1,38 +0,0 @@
1
- import { describe, it, expectTypeOf } from 'vitest';
2
- import { ParserBuilder } from '../../lib/index.js';
3
- const RuleA = {
4
- name: 'apple',
5
- impl: () => () => 'apple',
6
- };
7
- const RuleB = {
8
- name: 'banana',
9
- impl: () => () => 'banana',
10
- };
11
- const RuleC = {
12
- name: 'coconut',
13
- impl: () => () => 'coconut',
14
- };
15
- describe('parserBuilder', () => {
16
- describe('types', () => {
17
- it('builder constructor', () => {
18
- expectTypeOf(ParserBuilder.create([RuleA]))
19
- .branded.toEqualTypeOf();
20
- expectTypeOf(ParserBuilder.create([RuleB]))
21
- .branded.toEqualTypeOf();
22
- expectTypeOf(ParserBuilder.create([RuleA, RuleB]))
23
- .branded
24
- .toEqualTypeOf();
25
- // AddRule
26
- expectTypeOf(ParserBuilder.create([RuleA, RuleB]).addRule(RuleC))
27
- .branded.toEqualTypeOf();
28
- // Merge
29
- expectTypeOf(ParserBuilder.create([RuleA])
30
- .merge(ParserBuilder.create([RuleB]), [])).branded
31
- .toEqualTypeOf();
32
- expectTypeOf(ParserBuilder.create([RuleA, RuleB])
33
- .merge(ParserBuilder.create([RuleB, RuleC]), [])).branded
34
- .toEqualTypeOf();
35
- });
36
- });
37
- });
38
- //# sourceMappingURL=parserBuilder.types.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parserBuilder.types.test.js","sourceRoot":"","sources":["../../../../test/grammar-builder/parserBuilder.types.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMnD,MAAM,KAAK,GAA0C;IACnD,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,GAAG,EAAE,CAAC,G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,CAAC,MAAM,CAAS,CAAE,KAAK,EAAE,KAAK,CAAE,CAAC,EAAU,EAAE,CAAC,CACrE,CAAC,OAAO;iBACN,aAAa,EAIZ,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, it, expectTypeOf } from 'vitest';\nimport type { ParserRule } from '../../lib/index.js';\nimport { ParserBuilder } from '../../lib/index.js';\n\ninterface Context {\n world: 'hello';\n}\n\nconst RuleA: ParserRule<Context, 'apple', 'apple'> = {\n name: 'apple',\n impl: () => () => 'apple',\n};\nconst RuleB: ParserRule<Context, 'banana', 'banana'> = {\n name: 'banana',\n impl: () => () => 'banana',\n};\nconst RuleC: ParserRule<Context, 'coconut', 'coconut'> = {\n name: 'coconut',\n impl: () => () => 'coconut',\n};\n\ndescribe('parserBuilder', () => {\n describe('types', () => {\n it('builder constructor', () => {\n expectTypeOf(ParserBuilder.create(<const> [ RuleA ]))\n .branded.toEqualTypeOf<ParserBuilder<Context, 'apple', { apple: typeof RuleA }>>();\n expectTypeOf(ParserBuilder.create(<const> [ RuleB ]))\n .branded.toEqualTypeOf<ParserBuilder<Context, 'banana', { banana: typeof RuleB }>>();\n expectTypeOf(ParserBuilder.create(<const> [ RuleA, RuleB ]))\n .branded\n .toEqualTypeOf<ParserBuilder<Context, 'apple' | 'banana', { apple: typeof RuleA; banana: typeof RuleB }>>();\n\n // AddRule\n expectTypeOf(ParserBuilder.create(<const> [ RuleA, RuleB ]).addRule(RuleC))\n .branded.toEqualTypeOf<ParserBuilder<\n Context,\n'apple' | 'banana' | 'coconut',\n{ apple: typeof RuleA; banana: typeof RuleB; coconut: typeof RuleC }\n >>();\n\n // Merge\n expectTypeOf(\n ParserBuilder.create(<const> [ RuleA ])\n .merge(ParserBuilder.create(<const> [ RuleB ]), <const> []),\n ).branded\n .toEqualTypeOf<ParserBuilder<Context, 'apple' | 'banana', { apple: typeof RuleA; banana: typeof RuleB }>>();\n\n expectTypeOf(\n ParserBuilder.create(<const> [ RuleA, RuleB ])\n .merge(ParserBuilder.create(<const> [ RuleB, RuleC ]), <const> []),\n ).branded\n .toEqualTypeOf<ParserBuilder<\n Context,\n'apple' | 'banana' | 'coconut',\n{ apple: typeof RuleA; banana: typeof RuleB; coconut: typeof RuleC }\n >>();\n });\n });\n});\n"]}
@@ -1 +0,0 @@
1
- export {};
@@ -1,82 +0,0 @@
1
- import { describe, it } from 'vitest';
2
- import { TransformerTyped } from '../lib/index.js';
3
- describe('transformer', () => {
4
- const transformer = new TransformerTyped();
5
- it('makes copies when needed', ({ expect }) => {
6
- const fruit = {
7
- type: 'fruit',
8
- clone1: { type: 'vegetable', random: { type: 'fruit', val: 'blep' } },
9
- };
10
- const fullCopy = transformer.transformNode(fruit, {});
11
- expect(fullCopy).not.toBe(fruit);
12
- expect(fullCopy.clone1).not.toBe(fruit.clone1);
13
- expect(fullCopy.clone1.random).not.toBe(fruit.clone1.random);
14
- const sameVegetable = transformer.transformNode(fruit, {
15
- vegetable: { preVisitor: () => ({ copy: false }) },
16
- fruit: { transform: (fruit) => {
17
- fruit.test = 'yes';
18
- return fruit;
19
- } },
20
- });
21
- expect(sameVegetable).not.toBe(fruit);
22
- expect(sameVegetable.clone1).toBe(fruit.clone1);
23
- expect(sameVegetable.clone1.random).toMatchObject({ test: 'yes' });
24
- });
25
- it('knows shortcut and continue', ({ expect }) => {
26
- const in2 = { type: 'fruit', val: 'depth3' };
27
- const in1 = { type: 'vegetable', in: in2, val: 'depth2' };
28
- const side1 = { type: 'fruit', val: 'side1' };
29
- const side2 = { type: 'vegetable' };
30
- const fruit = { type: 'fruit', in: in1, val: 'depth1', side: side1, side2 };
31
- const onlyCopyDepth1 = transformer.transformNode(fruit, {
32
- fruit: { preVisitor: () => ({ continue: false }) },
33
- });
34
- expect(onlyCopyDepth1).not.toBe(fruit);
35
- expect(onlyCopyDepth1.in).toBe(in1);
36
- expect(onlyCopyDepth1.in.in).toBe(in2);
37
- expect(onlyCopyDepth1.side).toBe(side1);
38
- const doNotCopy = transformer.transformNode(fruit, {
39
- fruit: { preVisitor: () => ({ continue: false, copy: false }) },
40
- });
41
- expect(doNotCopy).toBe(fruit);
42
- expect(doNotCopy.in).toBe(in1);
43
- expect(doNotCopy.in.in).toBe(in2);
44
- expect(doNotCopy.side).toBe(side1);
45
- const doNotCopyByShortcut = transformer.transformNode(fruit, {
46
- fruit: { preVisitor: () => ({ shortcut: true }) },
47
- });
48
- expect(doNotCopyByShortcut).not.toBe(fruit);
49
- expect(doNotCopyByShortcut.in).toBe(in1);
50
- expect(doNotCopyByShortcut.in.in).toBe(in2);
51
- expect(doNotCopyByShortcut.side).toBe(side1);
52
- const doNotCopySideWhenShortcut = transformer.transformNode(fruit, {
53
- vegetable: { preVisitor: () => ({ shortcut: true }) },
54
- });
55
- expect(doNotCopySideWhenShortcut).not.toBe(fruit);
56
- expect(doNotCopySideWhenShortcut.in).toBe(in1);
57
- expect(doNotCopySideWhenShortcut.in.in).toBe(in2);
58
- expect(doNotCopySideWhenShortcut.side).toBe(side1);
59
- expect(doNotCopySideWhenShortcut.side2).not.toBe(side2);
60
- });
61
- it('knows shallowKeys and ignoreKeys', ({ expect }) => {
62
- const in2 = { type: 'fruit', val: 'depth3' };
63
- const in1 = { type: 'vegetable', in: in2, val: 'depth2' };
64
- const side1 = { type: 'fruit', val: 'side1' };
65
- const fruit = { type: 'fruit', in: in1, val: 'depth1', side: side1 };
66
- const noDeepOnShallowKeys = transformer.transformNode(fruit, {
67
- fruit: { preVisitor: () => ({ shallowKeys: new Set(['in']) }) },
68
- });
69
- expect(noDeepOnShallowKeys).not.toBe(fruit);
70
- expect(noDeepOnShallowKeys.in).not.toBe(in1);
71
- expect(noDeepOnShallowKeys.in.in).toBe(in2);
72
- expect(noDeepOnShallowKeys.side).not.toBe(side1);
73
- const ignoreKeysAreIgnored = transformer.transformNode(fruit, {
74
- fruit: { preVisitor: () => ({ ignoreKeys: new Set(['in']) }) },
75
- });
76
- expect(ignoreKeysAreIgnored).not.toBe(fruit);
77
- expect(ignoreKeysAreIgnored.in).toBe(in1);
78
- expect(ignoreKeysAreIgnored.in.in).toBe(in2);
79
- expect(ignoreKeysAreIgnored.side).not.toBe(side1);
80
- });
81
- });
82
- //# sourceMappingURL=transformer.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transformer.test.js","sourceRoot":"","sources":["../../../test/transformer.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAYnD,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAC3B,MAAM,WAAW,GAAG,IAAI,gBAAgB,EAAqB,CAAC;IAC9D,EAAE,CAAC,0BAA0B,EAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAU;YACnB,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,EAAC;SACrE,CAAC;QACF,MAAM,QAAQ,GAAS,WAAW,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC5D,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/C,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAE7D,MAAM,aAAa,GAAS,WAAW,CAAC,aAAa,CAAC,KAAK,EAAE;YAC3D,SAAS,EAAE,EAAE,UAAU,EAAE,G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AAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { describe, it } from 'vitest';\nimport { TransformerTyped } from '../lib/index.js';\n\ninterface Fruit {\n type: 'fruit';\n [key: string]: any;\n}\n\ninterface Vegetable {\n type: 'vegetable';\n [key: string]: any;\n}\n\ndescribe('transformer', () => {\n const transformer = new TransformerTyped<Fruit | Vegetable>();\n it('makes copies when needed', ({ expect }) => {\n const fruit: Fruit = {\n type: 'fruit',\n clone1: { type: 'vegetable', random: { type: 'fruit', val: 'blep' }},\n };\n const fullCopy = <any> transformer.transformNode(fruit, {});\n expect(fullCopy).not.toBe(fruit);\n expect(fullCopy.clone1).not.toBe(fruit.clone1);\n expect(fullCopy.clone1.random).not.toBe(fruit.clone1.random);\n\n const sameVegetable = <any> transformer.transformNode(fruit, {\n vegetable: { preVisitor: () => ({ copy: false }) },\n fruit: { transform: (fruit: any) => {\n fruit.test = 'yes';\n return fruit;\n } },\n });\n expect(sameVegetable).not.toBe(fruit);\n expect(sameVegetable.clone1).toBe(fruit.clone1);\n expect(sameVegetable.clone1.random).toMatchObject({ test: 'yes' });\n });\n\n it('knows shortcut and continue', ({ expect }) => {\n const in2 = { type: 'fruit', val: 'depth3' };\n const in1 = { type: 'vegetable', in: in2, val: 'depth2' };\n const side1 = { type: 'fruit', val: 'side1' };\n const side2 = { type: 'vegetable' };\n const fruit: Fruit = { type: 'fruit', in: in1, val: 'depth1', side: side1, side2 };\n\n const onlyCopyDepth1 = <any> transformer.transformNode(fruit, {\n fruit: { preVisitor: () => ({ continue: false }) },\n });\n expect(onlyCopyDepth1).not.toBe(fruit);\n expect(onlyCopyDepth1.in).toBe(in1);\n expect(onlyCopyDepth1.in.in).toBe(in2);\n expect(onlyCopyDepth1.side).toBe(side1);\n\n const doNotCopy = <any> transformer.transformNode(fruit, {\n fruit: { preVisitor: () => ({ continue: false, copy: false }) },\n });\n expect(doNotCopy).toBe(fruit);\n expect(doNotCopy.in).toBe(in1);\n expect(doNotCopy.in.in).toBe(in2);\n expect(doNotCopy.side).toBe(side1);\n\n const doNotCopyByShortcut = <any> transformer.transformNode(fruit, {\n fruit: { preVisitor: () => ({ shortcut: true }) },\n });\n expect(doNotCopyByShortcut).not.toBe(fruit);\n expect(doNotCopyByShortcut.in).toBe(in1);\n expect(doNotCopyByShortcut.in.in).toBe(in2);\n expect(doNotCopyByShortcut.side).toBe(side1);\n\n const doNotCopySideWhenShortcut = <any> transformer.transformNode(fruit, {\n vegetable: { preVisitor: () => ({ shortcut: true }) },\n });\n expect(doNotCopySideWhenShortcut).not.toBe(fruit);\n expect(doNotCopySideWhenShortcut.in).toBe(in1);\n expect(doNotCopySideWhenShortcut.in.in).toBe(in2);\n expect(doNotCopySideWhenShortcut.side).toBe(side1);\n expect(doNotCopySideWhenShortcut.side2).not.toBe(side2);\n });\n\n it('knows shallowKeys and ignoreKeys', ({ expect }) => {\n const in2 = { type: 'fruit', val: 'depth3' };\n const in1 = { type: 'vegetable', in: in2, val: 'depth2' };\n const side1 = { type: 'fruit', val: 'side1' };\n const fruit: Fruit = { type: 'fruit', in: in1, val: 'depth1', side: side1 };\n\n const noDeepOnShallowKeys = <any> transformer.transformNode(fruit, {\n fruit: { preVisitor: () => ({ shallowKeys: new Set([ 'in' ]) }) },\n });\n expect(noDeepOnShallowKeys).not.toBe(fruit);\n expect(noDeepOnShallowKeys.in).not.toBe(in1);\n expect(noDeepOnShallowKeys.in.in).toBe(in2);\n expect(noDeepOnShallowKeys.side).not.toBe(side1);\n\n const ignoreKeysAreIgnored = <any> transformer.transformNode(fruit, {\n fruit: { preVisitor: () => ({ ignoreKeys: new Set([ 'in' ]) }) },\n });\n expect(ignoreKeysAreIgnored).not.toBe(fruit);\n expect(ignoreKeysAreIgnored.in).toBe(in1);\n expect(ignoreKeysAreIgnored.in.in).toBe(in2);\n expect(ignoreKeysAreIgnored.side).not.toBe(side1);\n });\n});\n"]}