@traqula/core 0.0.23 → 0.0.25
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/README.md +2 -0
- package/dist/cjs/lib/AstCoreFactory.js +181 -149
- package/dist/cjs/lib/AstCoreFactory.js.map +1 -0
- package/dist/cjs/lib/generator-builder/builderTypes.js +2 -15
- package/dist/cjs/lib/generator-builder/builderTypes.js.map +1 -0
- package/dist/cjs/lib/generator-builder/dynamicGenerator.js +209 -200
- package/dist/cjs/lib/generator-builder/dynamicGenerator.js.map +1 -0
- package/dist/cjs/lib/generator-builder/generatorBuilder.js +103 -117
- package/dist/cjs/lib/generator-builder/generatorBuilder.js.map +1 -0
- package/dist/cjs/lib/generator-builder/generatorTypes.js +2 -15
- package/dist/cjs/lib/generator-builder/generatorTypes.js.map +1 -0
- package/dist/cjs/lib/index.js +39 -57
- package/dist/cjs/lib/index.js.map +1 -0
- package/dist/cjs/lib/indirection-builder/IndirBuilder.js +63 -85
- package/dist/cjs/lib/indirection-builder/IndirBuilder.js.map +1 -0
- package/dist/cjs/lib/indirection-builder/dynamicIndirected.js +28 -50
- package/dist/cjs/lib/indirection-builder/dynamicIndirected.js.map +1 -0
- package/dist/cjs/lib/indirection-builder/helpers.js +11 -31
- package/dist/cjs/lib/indirection-builder/helpers.js.map +1 -0
- package/dist/cjs/lib/lexer-builder/LexerBuilder.js +92 -114
- package/dist/cjs/lib/lexer-builder/LexerBuilder.js.map +1 -0
- package/dist/cjs/lib/parser-builder/builderTypes.js +2 -15
- package/dist/cjs/lib/parser-builder/builderTypes.js.map +1 -0
- package/dist/cjs/lib/parser-builder/dynamicParser.js +116 -136
- package/dist/cjs/lib/parser-builder/dynamicParser.js.map +1 -0
- package/dist/cjs/lib/parser-builder/parserBuilder.js +167 -169
- package/dist/cjs/lib/parser-builder/parserBuilder.js.map +1 -0
- package/dist/cjs/lib/parser-builder/ruleDefTypes.js +2 -15
- package/dist/cjs/lib/parser-builder/ruleDefTypes.js.map +1 -0
- package/dist/cjs/lib/transformers/TransformerObject.js +196 -198
- package/dist/cjs/lib/transformers/TransformerObject.js.map +1 -0
- package/dist/cjs/lib/transformers/TransformerSubTyped.js +110 -141
- package/dist/cjs/lib/transformers/TransformerSubTyped.js.map +1 -0
- package/dist/cjs/lib/transformers/TransformerTyped.js +87 -120
- package/dist/cjs/lib/transformers/TransformerTyped.js.map +1 -0
- package/dist/cjs/lib/types.js +2 -15
- package/dist/cjs/lib/types.js.map +1 -0
- package/dist/cjs/lib/utils.js +20 -34
- package/dist/cjs/lib/utils.js.map +1 -0
- package/dist/esm/lib/AstCoreFactory.d.ts +19 -7
- package/dist/esm/lib/AstCoreFactory.js +50 -5
- package/dist/esm/lib/AstCoreFactory.js.map +1 -1
- package/dist/esm/lib/generator-builder/dynamicGenerator.d.ts +5 -0
- package/dist/esm/lib/generator-builder/dynamicGenerator.js +20 -0
- package/dist/esm/lib/generator-builder/dynamicGenerator.js.map +1 -1
- package/dist/esm/lib/parser-builder/dynamicParser.js +1 -0
- package/dist/esm/lib/parser-builder/dynamicParser.js.map +1 -1
- package/dist/esm/lib/parser-builder/parserBuilder.js +2 -2
- package/dist/esm/lib/parser-builder/parserBuilder.js.map +1 -1
- package/dist/esm/lib/transformers/TransformerObject.d.ts +1 -1
- package/dist/esm/lib/transformers/TransformerObject.js.map +1 -1
- package/dist/esm/lib/transformers/TransformerSubTyped.d.ts +31 -22
- package/dist/esm/lib/transformers/TransformerSubTyped.js +30 -40
- package/dist/esm/lib/transformers/TransformerSubTyped.js.map +1 -1
- package/dist/esm/lib/transformers/TransformerTyped.d.ts +24 -20
- package/dist/esm/lib/transformers/TransformerTyped.js +23 -35
- package/dist/esm/lib/transformers/TransformerTyped.js.map +1 -1
- package/dist/esm/lib/types.d.ts +67 -5
- package/dist/esm/lib/types.js.map +1 -1
- package/dist/esm/lib/utils.d.ts +10 -0
- package/dist/esm/lib/utils.js +7 -0
- package/dist/esm/lib/utils.js.map +1 -1
- package/package.json +9 -9
- package/dist/cjs/test/generatorBuilder/generatorBuilder.types.test.js +0 -30
- package/dist/cjs/test/grammar-builder/parserBuilder.types.test.js +0 -27
- package/dist/cjs/test/transformer.test.js +0 -82
- package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.d.ts +0 -1
- package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.js +0 -38
- package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.js.map +0 -1
- package/dist/esm/test/grammar-builder/parserBuilder.types.test.d.ts +0 -1
- package/dist/esm/test/grammar-builder/parserBuilder.types.test.js +0 -38
- package/dist/esm/test/grammar-builder/parserBuilder.types.test.js.map +0 -1
- package/dist/esm/test/transformer.test.d.ts +0 -1
- package/dist/esm/test/transformer.test.js +0 -82
- package/dist/esm/test/transformer.test.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../lib/types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../lib/types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Type that is used by the Traqula core package to type raw objects/ Data Transfer Objects (DTO).\n * Enforces the presence of a type string, and that in case the subType key is present, it also be a string.\n */\nexport interface Typed<Type extends string = string> {\n type: Type;\n subType?: string;\n}\n\n/**\n * A {@link Typed} object that is sure to have a subType\n */\nexport interface SubTyped<Type extends string = string, SubType extends string = string> extends Typed<Type> {\n subType: SubType;\n}\n\n/**\n * Type used by the parser and generator builders of the core Traqula package to annotate\n * the relation between AST objects and the source string.\n */\nexport interface Localized {\n loc: SourceLocation;\n}\n\n/**\n * Wrapper type for localization,\n * can be used to state localization information about any other type (including primitive types)\n */\nexport interface Wrap<T> extends Localized {\n val: T;\n}\n\n/**\n * A AST node. Nodes are indexable by their types.\n * When generating, the SUBRULES called should be located within the current location range.\n */\nexport interface Node extends Localized, Typed {}\n\nexport interface SourceLocationBase {\n sourceLocationType: string;\n}\n\n/**\n * SourceLocation type that annotates that the node represents the AST representation of\n * the given range in the source string.\n */\nexport interface SourceLocationSource extends SourceLocationBase {\n sourceLocationType: 'source';\n start: number;\n end: number;\n}\n\n/**\n * Similar to {@link SourceLocationSource} but also carrying the source it related too.\n * All sourceLocation nodes that are descends of this one, relate themselves to this source.\n */\nexport interface SourceLocationInlinedSource extends SourceLocationBase, Localized {\n sourceLocationType: 'inlinedSource';\n /**\n * The string that will be used as the source for this node and the descends of this node.\n * Note that the generator will print the characters from newSource[0] until start. Likewise for the suffix.\n */\n newSource: string;\n /**\n * Behavior of the current loc, after replacing the source string.\n */\n loc: SourceLocation;\n /**\n * The range that this node replaces in the context of the original source.\n */\n start: number;\n end: number;\n startOnNew: number;\n endOnNew: number;\n}\n\n/**\n * NoStringManifestation means the node does not have a string representation.\n * For example the literal '5' has an integer type (which is an AST node),\n * but the type does not have an associated string representation.\n * When set to true, the node will not be printed, start and end are meaningless in this case.\n */\nexport interface SourceLocationNoMaterialize extends SourceLocationBase {\n sourceLocationType: 'noMaterialize';\n}\n\n/**\n * SourceLocation type that annotates that the node has been replaced\n * in relation to the original string by a new string.\n * It means that this node should be generated, and that the source string from start to end has been changed.\n */\nexport interface SourceLocationStringReplace extends SourceLocationBase {\n sourceLocationType: 'stringReplace';\n /**\n * The string that will replace the given range in the original source.\n */\n newSource: string;\n /**\n * The start of the region in the original source string that this node replaces.\n */\n start: number;\n /**\n * The end of the region in the original source string that this node replaces.\n */\n end: number;\n}\n\n/**\n * SourceLocation type that annotates that the node has been replaced in relation to the original string.\n * It means that this node should be generated, and that the source string from start to end has been changed.\n */\nexport interface SourceLocationNodeReplace extends SourceLocationBase {\n sourceLocationType: 'nodeReplace';\n /**\n * The start of the region in the original source string that this node replaces.\n */\n start: number;\n /**\n * The end of the region in the original source string that this node replaces.\n */\n end: number;\n}\n/**\n * Must have an ancestor of type {@link SourceLocationNodeReplace}\n */\nexport interface SourceLocationNodeAutoGenerate extends SourceLocationBase {\n sourceLocationType: 'autoGenerate';\n}\n\nexport type SourceLocation =\n // Relate yourself to the source\n | SourceLocationSource\n // Add a new source\n | SourceLocationInlinedSource\n // No not generate anything for the current node and descendants\n | SourceLocationNoMaterialize\n // Replace some range by a string\n | SourceLocationStringReplace\n // Replace this node by some autogen\n | SourceLocationNodeReplace\n // Auto gen current node.\n | SourceLocationNodeAutoGenerate;\n"]}
|
package/dist/esm/lib/utils.d.ts
CHANGED
|
@@ -3,13 +3,23 @@ import type { ITokenConfig, TokenType } from '@traqula/chevrotain';
|
|
|
3
3
|
* Check whether the first two types overlap, if no, return the 3th argument, else the 4th.
|
|
4
4
|
*/
|
|
5
5
|
export type CheckOverlap<T, U, V, W = never> = T & U extends never ? V : W;
|
|
6
|
+
/**
|
|
7
|
+
* Lowercase the first letter of a given string.
|
|
8
|
+
* @param str
|
|
9
|
+
*/
|
|
6
10
|
export declare function unCapitalize<T extends string>(str: T): Uncapitalize<T>;
|
|
7
11
|
export type NamedToken<Name extends string = string> = TokenType & {
|
|
8
12
|
name: Name;
|
|
9
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Create a token in a typesafe way necessary by the traqula core builders.
|
|
16
|
+
*/
|
|
10
17
|
export declare function createToken<Name extends string>(config: ITokenConfig & {
|
|
11
18
|
name: Name;
|
|
12
19
|
}): NamedToken<Name>;
|
|
20
|
+
/**
|
|
21
|
+
* Patch a given type by changing the value-type of a specific key in the given object type.
|
|
22
|
+
*/
|
|
13
23
|
export type Patch<T extends object, Patch extends {
|
|
14
24
|
[Key in keyof T]?: unknown;
|
|
15
25
|
}> = {
|
package/dist/esm/lib/utils.js
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { createToken as chevcT } from '@traqula/chevrotain';
|
|
2
|
+
/**
|
|
3
|
+
* Lowercase the first letter of a given string.
|
|
4
|
+
* @param str
|
|
5
|
+
*/
|
|
2
6
|
export function unCapitalize(str) {
|
|
3
7
|
return (str.charAt(0).toLowerCase() + str.slice(1));
|
|
4
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a token in a typesafe way necessary by the traqula core builders.
|
|
11
|
+
*/
|
|
5
12
|
export function createToken(config) {
|
|
6
13
|
return chevcT(config);
|
|
7
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAO5D,MAAM,UAAU,YAAY,CAAmB,GAAM;IACnD,OAAyB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACxE,CAAC;AAID,MAAM,UAAU,WAAW,CAAsB,MAAqC;IACpF,OAAoC,MAAM,CAAC,MAAM,CAAC,CAAC;AACrD,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAO5D;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAmB,GAAM;IACnD,OAAyB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACxE,CAAC;AAID;;GAEG;AACH,MAAM,UAAU,WAAW,CAAsB,MAAqC;IACpF,OAAoC,MAAM,CAAC,MAAM,CAAC,CAAC;AACrD,CAAC;AAQD;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC7B,wFAAwF,CAAC","sourcesContent":["import type { ITokenConfig, TokenType } from '@traqula/chevrotain';\nimport { createToken as chevcT } from '@traqula/chevrotain';\n\n/**\n * Check whether the first two types overlap, if no, return the 3th argument, else the 4th.\n */\nexport type CheckOverlap<T, U, V, W = never> = T & U extends never ? V : W;\n\n/**\n * Lowercase the first letter of a given string.\n * @param str\n */\nexport function unCapitalize<T extends string>(str: T): Uncapitalize<T> {\n return <Uncapitalize<T>> (str.charAt(0).toLowerCase() + str.slice(1));\n}\n\nexport type NamedToken<Name extends string = string> = TokenType & { name: Name };\n\n/**\n * Create a token in a typesafe way necessary by the traqula core builders.\n */\nexport function createToken<Name extends string>(config: ITokenConfig & { name: Name }): NamedToken<Name> {\n return <TokenType & { name: Name }> chevcT(config);\n}\n\n/**\n * Patch a given type by changing the value-type of a specific key in the given object type.\n */\nexport type Patch<T extends object, Patch extends {[Key in keyof T ]?: unknown }> =\n {[Key in keyof T]: Key extends keyof Patch ? Patch[Key] : T[Key] };\n\n/**\n * Key that allows you to set the space based indentation of your query when generating newlines using the NEW_LINE.\n * A value of -1 disables the generation of newlines from the NEW_LINE function\n */\nexport const traqulaIndentation =\n 'When you use this string, you expect traqula to handle indentation after every newline';\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@traqula/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.25",
|
|
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
|
|
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:
|
|
39
|
+
"build": "yarn build:ts && yarn build:cjs",
|
|
40
40
|
"build:ts": "node \"../../node_modules/typescript/bin/tsc\" -b",
|
|
41
|
-
"build:
|
|
41
|
+
"build:cjs": "node \"../../node_modules/typescript/bin/tsc\" -b tsconfig.cjs.json"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@traqula/chevrotain": "^0.0.
|
|
44
|
+
"@traqula/chevrotain": "^0.0.25"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "52cfb2b513294dc154febc0209ac811ceeb6785b"
|
|
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 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -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,CA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aAAa,EAIV,CAAC;QACT,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","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 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -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,GAAG,EAAE,CAAC,OAAO;CAC1B,CAAC;AACF,MAAM,KAAK,GAA4C;IACrD,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ;CAC3B,CAAC;AACF,MAAM,KAAK,GAA8C;IACvD,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,SAAS;CAC5B,CAAC;AAEF,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;QACrB,EAAE,CAAC,qBAAqB,EAAE,GAAG,EAAE;YAC7B,YAAY,CAAC,aAAa,CAAC,MAAM,CAAS,CAAE,KAAK,CAAE,CAAC,CAAC;iBAClD,OAAO,CAAC,aAAa,EAA4D,CAAC;YACrF,YAAY,CAAC,aAAa,CAAC,MAAM,CAAS,CAAE,KAAK,CAAE,CAAC,CAAC;iBAClD,OAAO,CAAC,aAAa,EAA8D,CAAC;YACvF,YAAY,CAAC,aAAa,CAAC,MAAM,CAAS,CAAE,KAAK,EAAE,KAAK,CAAE,CAAC,CAAC;iBACzD,OAAO;iBACP,aAAa,EAA6F,CAAC;YAE9G,UAAU;YACV,YAAY,CAAC,aAAa,CAAC,MAAM,CAAS,CAAE,KAAK,EAAE,KAAK,CAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;iBACxE,OAAO,CAAC,aAAa,EAIpB,CAAC;YAEL,QAAQ;YACR,YAAY,CACV,aAAa,CAAC,MAAM,CAAS,CAAE,KAAK,CAAE,CAAC;iBACpC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAS,CAAE,KAAK,CAAE,CAAC,EAAU,EAAE,CAAC,CAC9D,CAAC,OAAO;iBACN,aAAa,EAA6F,CAAC;YAE9G,YAAY,CACV,aAAa,CAAC,MAAM,CAAS,CAAE,KAAK,EAAE,KAAK,CAAE,CAAC;iBAC3C,KAAK,CAAC,aAAa,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,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,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ourcesContent":["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"]}
|