@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.
Files changed (75) hide show
  1. package/README.md +2 -0
  2. package/dist/cjs/lib/AstCoreFactory.js +181 -149
  3. package/dist/cjs/lib/AstCoreFactory.js.map +1 -0
  4. package/dist/cjs/lib/generator-builder/builderTypes.js +2 -15
  5. package/dist/cjs/lib/generator-builder/builderTypes.js.map +1 -0
  6. package/dist/cjs/lib/generator-builder/dynamicGenerator.js +209 -200
  7. package/dist/cjs/lib/generator-builder/dynamicGenerator.js.map +1 -0
  8. package/dist/cjs/lib/generator-builder/generatorBuilder.js +103 -117
  9. package/dist/cjs/lib/generator-builder/generatorBuilder.js.map +1 -0
  10. package/dist/cjs/lib/generator-builder/generatorTypes.js +2 -15
  11. package/dist/cjs/lib/generator-builder/generatorTypes.js.map +1 -0
  12. package/dist/cjs/lib/index.js +39 -57
  13. package/dist/cjs/lib/index.js.map +1 -0
  14. package/dist/cjs/lib/indirection-builder/IndirBuilder.js +63 -85
  15. package/dist/cjs/lib/indirection-builder/IndirBuilder.js.map +1 -0
  16. package/dist/cjs/lib/indirection-builder/dynamicIndirected.js +28 -50
  17. package/dist/cjs/lib/indirection-builder/dynamicIndirected.js.map +1 -0
  18. package/dist/cjs/lib/indirection-builder/helpers.js +11 -31
  19. package/dist/cjs/lib/indirection-builder/helpers.js.map +1 -0
  20. package/dist/cjs/lib/lexer-builder/LexerBuilder.js +92 -114
  21. package/dist/cjs/lib/lexer-builder/LexerBuilder.js.map +1 -0
  22. package/dist/cjs/lib/parser-builder/builderTypes.js +2 -15
  23. package/dist/cjs/lib/parser-builder/builderTypes.js.map +1 -0
  24. package/dist/cjs/lib/parser-builder/dynamicParser.js +116 -136
  25. package/dist/cjs/lib/parser-builder/dynamicParser.js.map +1 -0
  26. package/dist/cjs/lib/parser-builder/parserBuilder.js +167 -169
  27. package/dist/cjs/lib/parser-builder/parserBuilder.js.map +1 -0
  28. package/dist/cjs/lib/parser-builder/ruleDefTypes.js +2 -15
  29. package/dist/cjs/lib/parser-builder/ruleDefTypes.js.map +1 -0
  30. package/dist/cjs/lib/transformers/TransformerObject.js +196 -198
  31. package/dist/cjs/lib/transformers/TransformerObject.js.map +1 -0
  32. package/dist/cjs/lib/transformers/TransformerSubTyped.js +110 -141
  33. package/dist/cjs/lib/transformers/TransformerSubTyped.js.map +1 -0
  34. package/dist/cjs/lib/transformers/TransformerTyped.js +87 -120
  35. package/dist/cjs/lib/transformers/TransformerTyped.js.map +1 -0
  36. package/dist/cjs/lib/types.js +2 -15
  37. package/dist/cjs/lib/types.js.map +1 -0
  38. package/dist/cjs/lib/utils.js +20 -34
  39. package/dist/cjs/lib/utils.js.map +1 -0
  40. package/dist/esm/lib/AstCoreFactory.d.ts +19 -7
  41. package/dist/esm/lib/AstCoreFactory.js +50 -5
  42. package/dist/esm/lib/AstCoreFactory.js.map +1 -1
  43. package/dist/esm/lib/generator-builder/dynamicGenerator.d.ts +5 -0
  44. package/dist/esm/lib/generator-builder/dynamicGenerator.js +20 -0
  45. package/dist/esm/lib/generator-builder/dynamicGenerator.js.map +1 -1
  46. package/dist/esm/lib/parser-builder/dynamicParser.js +1 -0
  47. package/dist/esm/lib/parser-builder/dynamicParser.js.map +1 -1
  48. package/dist/esm/lib/parser-builder/parserBuilder.js +2 -2
  49. package/dist/esm/lib/parser-builder/parserBuilder.js.map +1 -1
  50. package/dist/esm/lib/transformers/TransformerObject.d.ts +1 -1
  51. package/dist/esm/lib/transformers/TransformerObject.js.map +1 -1
  52. package/dist/esm/lib/transformers/TransformerSubTyped.d.ts +31 -22
  53. package/dist/esm/lib/transformers/TransformerSubTyped.js +30 -40
  54. package/dist/esm/lib/transformers/TransformerSubTyped.js.map +1 -1
  55. package/dist/esm/lib/transformers/TransformerTyped.d.ts +24 -20
  56. package/dist/esm/lib/transformers/TransformerTyped.js +23 -35
  57. package/dist/esm/lib/transformers/TransformerTyped.js.map +1 -1
  58. package/dist/esm/lib/types.d.ts +67 -5
  59. package/dist/esm/lib/types.js.map +1 -1
  60. package/dist/esm/lib/utils.d.ts +10 -0
  61. package/dist/esm/lib/utils.js +7 -0
  62. package/dist/esm/lib/utils.js.map +1 -1
  63. package/package.json +9 -9
  64. package/dist/cjs/test/generatorBuilder/generatorBuilder.types.test.js +0 -30
  65. package/dist/cjs/test/grammar-builder/parserBuilder.types.test.js +0 -27
  66. package/dist/cjs/test/transformer.test.js +0 -82
  67. package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.d.ts +0 -1
  68. package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.js +0 -38
  69. package/dist/esm/test/generatorBuilder/generatorBuilder.types.test.js.map +0 -1
  70. package/dist/esm/test/grammar-builder/parserBuilder.types.test.d.ts +0 -1
  71. package/dist/esm/test/grammar-builder/parserBuilder.types.test.js +0 -38
  72. package/dist/esm/test/grammar-builder/parserBuilder.types.test.js.map +0 -1
  73. package/dist/esm/test/transformer.test.d.ts +0 -1
  74. package/dist/esm/test/transformer.test.js +0 -82
  75. package/dist/esm/test/transformer.test.js.map +0 -1
@@ -1,144 +1,113 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var TransformerSubTyped_exports = {};
20
- __export(TransformerSubTyped_exports, {
21
- TransformerSubTyped: () => TransformerSubTyped
22
- });
23
- module.exports = __toCommonJS(TransformerSubTyped_exports);
24
- var import_TransformerTyped = require("./TransformerTyped.js");
25
- class TransformerSubTyped extends import_TransformerTyped.TransformerTyped {
26
- constructor(defaultContext = {}, defaultNodePreVisitor = {}) {
27
- super(defaultContext, defaultNodePreVisitor);
28
- }
29
- clone(newDefaultContext = {}, newDefaultNodePreVisitor = {}) {
30
- return new TransformerSubTyped({ ...this.defaultContext, ...newDefaultContext }, { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor });
31
- }
32
- /**
33
- * Shares the functionality and first two arguments with {@link this.transformNode}.
34
- * The third argument allows you to also transform based on the subType of objects.
35
- * Note that when a callback for the subtype is provided, the callback for the general type is **NOT** executed.
36
- * @param startObject
37
- * @param nodeCallBacks
38
- * @param nodeSpecificCallBacks
39
- */
40
- transformNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
41
- const transformWrapper = (copy, orig) => {
42
- let ogTransform;
43
- const casted = copy;
44
- if (casted.type && casted.subType) {
45
- const specific = nodeSpecificCallBacks[casted.type];
46
- if (specific) {
47
- ogTransform = specific[casted.subType]?.transform;
48
- }
49
- if (!ogTransform) {
50
- ogTransform = nodeCallBacks[casted.type]?.transform;
51
- }
52
- }
53
- return ogTransform ? ogTransform(casted, orig) : copy;
54
- };
55
- const preVisitWrapper = (curObject) => {
56
- let ogPreVisit;
57
- const casted = curObject;
58
- if (casted.type && casted.subType) {
59
- const specific = nodeSpecificCallBacks[casted.type];
60
- if (specific) {
61
- ogPreVisit = specific[casted.subType]?.preVisitor;
62
- }
63
- if (!ogPreVisit) {
64
- ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
65
- }
66
- }
67
- return ogPreVisit ? ogPreVisit(casted) : {};
68
- };
69
- return this.transformObject(startObject, transformWrapper, preVisitWrapper);
70
- }
71
- /**
72
- * Similar to {@link this.visitNode} but also allows you to match based on the subtype of objects.
73
- * When both nodeCallBack and NodeSpecific callBack are matched, will only visit nodeSpecifCallback
74
- */
75
- visitNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
76
- const visitWrapper = (curObject) => {
77
- let ogTransform;
78
- const casted = curObject;
79
- if (casted.type && casted.subType) {
80
- const specific = nodeSpecificCallBacks[casted.type];
81
- if (specific) {
82
- ogTransform = specific[casted.subType]?.visitor;
83
- }
84
- if (!ogTransform) {
85
- ogTransform = nodeCallBacks[casted.type]?.visitor;
86
- }
87
- }
88
- if (ogTransform) {
89
- ogTransform(casted);
90
- }
91
- };
92
- const preVisitWrapper = (curObject) => {
93
- let ogPreVisit;
94
- const casted = curObject;
95
- if (casted.type && casted.subType) {
96
- const specific = nodeSpecificCallBacks[casted.type];
97
- if (specific) {
98
- ogPreVisit = specific[casted.subType]?.preVisitor;
99
- }
100
- if (!ogPreVisit) {
101
- ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
102
- }
103
- }
104
- return ogPreVisit ? ogPreVisit(casted) : {};
105
- };
106
- this.visitObject(startObject, visitWrapper, preVisitWrapper);
107
- }
108
- /**
109
- * Similar to {@link this.traverseNodes} but also allows you to match based on the subtype of objects.
110
- * @param currentNode
111
- * @param traverseNode
112
- * @param traverseSubNode
113
- */
114
- traverseSubNodes(currentNode, traverseNode, traverseSubNode) {
115
- let didShortCut = false;
116
- const recurse = (curNode) => {
117
- let traverser;
118
- const subObj = traverseSubNode[curNode.type];
119
- if (subObj) {
120
- traverser = subObj[curNode.subType];
121
- }
122
- if (!traverser) {
123
- traverser = traverseNode[curNode.type];
124
- }
125
- if (traverser) {
126
- const { next, shortcut } = traverser(curNode);
127
- didShortCut = shortcut ?? false;
128
- if (!didShortCut) {
129
- for (const node of next ?? []) {
130
- if (didShortCut) {
131
- return;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformerSubTyped = void 0;
4
+ const TransformerTyped_js_1 = require("./TransformerTyped.js");
5
+ class TransformerSubTyped extends TransformerTyped_js_1.TransformerTyped {
6
+ constructor(defaultContext = {}, defaultNodePreVisitor = {}) {
7
+ super(defaultContext, defaultNodePreVisitor);
8
+ }
9
+ ;
10
+ clone(newDefaultContext = {}, newDefaultNodePreVisitor = {}) {
11
+ return new TransformerSubTyped({ ...this.defaultContext, ...newDefaultContext }, { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor });
12
+ }
13
+ /**
14
+ * Transform a single node ({@link Typed}).
15
+ * Similar to {@link this.transformNode} but also allowing you to target the subTypes.
16
+ * @param startObject the object from which we will start the transformation,
17
+ * potentially visiting and transforming its descendants along the way.
18
+ * @param nodeCallBacks a dictionary mapping the various operation types to objects optionally
19
+ * containing preVisitor and transformer.
20
+ * The preVisitor allows you to provide {@link TransformContext} for the current object,
21
+ * altering how it will be transformed.
22
+ * The transformer allows you to manipulate the copy of the current object,
23
+ * and expects you to return the value that should take the current objects place.
24
+ * @param nodeSpecificCallBacks Same as nodeCallBacks but using an additional level of indirection to
25
+ * indicate the subType.
26
+ * @return the result of transforming the requested descendant operations (based on the preVisitor)
27
+ * using a transformer that works its way back up from the descendant to the startObject.
28
+ */
29
+ transformNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
30
+ const transformWrapper = (copy, orig) => {
31
+ let ogTransform;
32
+ const casted = copy;
33
+ if (casted.type && casted.subType) {
34
+ const specific = nodeSpecificCallBacks[casted.type];
35
+ if (specific) {
36
+ ogTransform = specific[casted.subType]?.transform;
37
+ }
38
+ if (!ogTransform) {
39
+ ogTransform = nodeCallBacks[casted.type]?.transform;
40
+ }
132
41
  }
133
- recurse(node);
134
- }
135
- }
136
- }
137
- };
138
- recurse(currentNode);
139
- }
42
+ return ogTransform ? ogTransform(casted, orig) : copy;
43
+ };
44
+ const preVisitWrapper = (curObject) => {
45
+ let ogPreVisit;
46
+ const casted = curObject;
47
+ if (casted.type && casted.subType) {
48
+ const specific = nodeSpecificCallBacks[casted.type];
49
+ if (specific) {
50
+ ogPreVisit = specific[casted.subType]?.preVisitor;
51
+ }
52
+ if (!ogPreVisit) {
53
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
54
+ }
55
+ }
56
+ return ogPreVisit ? ogPreVisit(casted) : {};
57
+ };
58
+ return this.transformObject(startObject, transformWrapper, preVisitWrapper);
59
+ }
60
+ /**
61
+ * Visit a selected subTree given a startObject, steering the visits based on {@link Typed} nodes.
62
+ * Similar to {@link this.visitNode}, but also allowing you to target subTypes.
63
+ * Will call the preVisitor on the outer distinct, then the visitor of the special distinct,
64
+ * followed by the visiting the outer distinct, printing '231'.
65
+ * The pre-visitor visits starting from the root, going deeper, while the actual visitor goes in reverse.
66
+ * @param startObject the object from which we will start visiting,
67
+ * potentially visiting its descendants along the way.
68
+ * @param nodeCallBacks a dictionary mapping the various operation types to objects optionally
69
+ * containing preVisitor and visitor.
70
+ * The preVisitor allows you to provide {@link VisitContext} for the current object,
71
+ * altering how it will be visited.
72
+ * The visitor allows you to visit the object from deepest to the outermost object.
73
+ * This is useful if you for example want to manipulate the objects you visit during your visits,
74
+ * similar to {@link mapOperation}.
75
+ * @param nodeSpecificCallBacks Same as nodeCallBacks but using an additional level of indirection to
76
+ * indicate the subType.
77
+ */
78
+ visitNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
79
+ const visitWrapper = (curObject) => {
80
+ let ogTransform;
81
+ const casted = curObject;
82
+ if (casted.type && casted.subType) {
83
+ const specific = nodeSpecificCallBacks[casted.type];
84
+ if (specific) {
85
+ ogTransform = specific[casted.subType]?.visitor;
86
+ }
87
+ if (!ogTransform) {
88
+ ogTransform = nodeCallBacks[casted.type]?.visitor;
89
+ }
90
+ }
91
+ if (ogTransform) {
92
+ ogTransform(casted);
93
+ }
94
+ };
95
+ const preVisitWrapper = (curObject) => {
96
+ let ogPreVisit;
97
+ const casted = curObject;
98
+ if (casted.type && casted.subType) {
99
+ const specific = nodeSpecificCallBacks[casted.type];
100
+ if (specific) {
101
+ ogPreVisit = specific[casted.subType]?.preVisitor;
102
+ }
103
+ if (!ogPreVisit) {
104
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
105
+ }
106
+ }
107
+ return ogPreVisit ? ogPreVisit(casted) : {};
108
+ };
109
+ this.visitObject(startObject, visitWrapper, preVisitWrapper);
110
+ }
140
111
  }
141
- // Annotate the CommonJS export names for ESM import in node:
142
- 0 && (module.exports = {
143
- TransformerSubTyped
144
- });
112
+ exports.TransformerSubTyped = TransformerSubTyped;
113
+ //# sourceMappingURL=TransformerSubTyped.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransformerSubTyped.js","sourceRoot":"","sources":["../../../../lib/transformers/TransformerSubTyped.ts"],"names":[],"mappings":";;;AAMA,+DAAyD;AAEzD,MAAa,mBAAyC,SAAQ,sCAAuB;IACnF,YACE,iBAAmC,EAAE,EACrC,wBAAsD,EAAE;QAExD,KAAK,CAAC,cAAc,EAAE,qBAAqB,CAAC,CAAC;IAC/C,CAAC;IAAA,CAAC;IAEc,KAAK,CACnB,oBAAsC,EAAE,EACxC,2BAAyD,EAAE;QAE3D,OAAO,IAAI,mBAAmB,CAC5B,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,GAAG,iBAAiB,EAAE,EAChD,EAAE,GAAG,IAAI,CAAC,qBAAqB,EAAE,GAAG,wBAAwB,EAAE,CAC/D,CAAC;IACJ,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACI,qBAAqB,CAC1B,WAAmB,EACnB,aAGE,EACF,qBAIK;QAEL,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAE,IAAY,EAAW,EAAE;YAC/D,IAAI,WAA4D,CAAC;YACjE,MAAM,MAAM,GAA4B,IAAI,CAAC;YAC7C,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBAClC,MAAM,QAAQ,GAAG,qBAAqB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACpD,IAAI,QAAQ,EAAE,CAAC;oBACb,WAAW,GAAG,QAAQ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port type {\n TransformContext,\n VisitContext,\n} from './TransformerObject.js';\nimport type { DefaultNodePreVisitor, Safeness, SafeWrap } from './TransformerTyped.js';\nimport { TransformerTyped } from './TransformerTyped.js';\n\nexport class TransformerSubTyped<Nodes extends Typed> extends TransformerTyped<Nodes> {\n public constructor(\n defaultContext: TransformContext = {},\n defaultNodePreVisitor: DefaultNodePreVisitor<Nodes> = {},\n ) {\n super(defaultContext, defaultNodePreVisitor);\n };\n\n public override clone(\n newDefaultContext: TransformContext = {},\n newDefaultNodePreVisitor: DefaultNodePreVisitor<Nodes> = {},\n ): TransformerSubTyped<Nodes> {\n return new TransformerSubTyped(\n { ...this.defaultContext, ...newDefaultContext },\n { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor },\n );\n }\n\n /**\n * Transform a single node ({@link Typed}).\n * Similar to {@link this.transformNode} but also allowing you to target the subTypes.\n * @param startObject the object from which we will start the transformation,\n * potentially visiting and transforming its descendants along the way.\n * @param nodeCallBacks a dictionary mapping the various operation types to objects optionally\n * containing preVisitor and transformer.\n * The preVisitor allows you to provide {@link TransformContext} for the current object,\n * altering how it will be transformed.\n * The transformer allows you to manipulate the copy of the current object,\n * and expects you to return the value that should take the current objects place.\n * @param nodeSpecificCallBacks Same as nodeCallBacks but using an additional level of indirection to\n * indicate the subType.\n * @return the result of transforming the requested descendant operations (based on the preVisitor)\n * using a transformer that works its way back up from the descendant to the startObject.\n */\n public transformNodeSpecific<Safe extends Safeness = 'safe', OutType = unknown>(\n startObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n transform?: (copy: SafeWrap<Safe, Extract<Nodes, Typed<T>>>, orig: Extract<Nodes, Typed<T>>) => unknown;\n preVisitor?: (orig: Extract<Nodes, Typed<T>>) => TransformContext;\n }},\n nodeSpecificCallBacks: {[Type in Nodes['type']]?: {\n [SubType in Extract<Nodes, SubTyped<Type>>['subType']]?: {\n transform?: (op: SafeWrap<Safe, Extract<Nodes, SubTyped<Type, SubType>>>) => unknown;\n preVisitor?: (op: Extract<Nodes, SubTyped<Type, SubType>>) => TransformContext;\n }}},\n ): Safe extends 'unsafe' ? OutType : unknown {\n const transformWrapper = (copy: object, orig: object): unknown => {\n let ogTransform: ((copy: any, orig: any) => unknown) | undefined;\n const casted = <SubTyped<Nodes['type']>>copy;\n if (casted.type && casted.subType) {\n const specific = nodeSpecificCallBacks[casted.type];\n if (specific) {\n ogTransform = specific[<keyof typeof specific> casted.subType]?.transform;\n }\n if (!ogTransform) {\n ogTransform = nodeCallBacks[casted.type]?.transform;\n }\n }\n return ogTransform ? ogTransform(casted, orig) : copy;\n };\n const preVisitWrapper = (curObject: object): VisitContext => {\n let ogPreVisit: ((node: any) => VisitContext) | undefined;\n const casted = <SubTyped<Nodes['type']>>curObject;\n if (casted.type && casted.subType) {\n const specific = nodeSpecificCallBacks[casted.type];\n if (specific) {\n ogPreVisit = specific[<keyof typeof specific> casted.subType]?.preVisitor;\n }\n if (!ogPreVisit) {\n ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;\n }\n }\n return ogPreVisit ? ogPreVisit(casted) : {};\n };\n return <any> this.transformObject(startObject, transformWrapper, preVisitWrapper);\n }\n\n /**\n * Visit a selected subTree given a startObject, steering the visits based on {@link Typed} nodes.\n * Similar to {@link this.visitNode}, but also allowing you to target subTypes.\n * Will call the preVisitor on the outer distinct, then the visitor of the special distinct,\n * followed by the visiting the outer distinct, printing '231'.\n * The pre-visitor visits starting from the root, going deeper, while the actual visitor goes in reverse.\n * @param startObject the object from which we will start visiting,\n * potentially visiting its descendants along the way.\n * @param nodeCallBacks a dictionary mapping the various operation types to objects optionally\n * containing preVisitor and visitor.\n * The preVisitor allows you to provide {@link VisitContext} for the current object,\n * altering how it will be visited.\n * The visitor allows you to visit the object from deepest to the outermost object.\n * This is useful if you for example want to manipulate the objects you visit during your visits,\n * similar to {@link mapOperation}.\n * @param nodeSpecificCallBacks Same as nodeCallBacks but using an additional level of indirection to\n * indicate the subType.\n */\n public visitNodeSpecific(\n startObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n visitor?: (op: Extract<Nodes, Typed<T>>) => void;\n preVisitor?: (op: Extract<Nodes, Typed<T>>) => VisitContext;\n }},\n nodeSpecificCallBacks: {[Type in Nodes['type']]?:\n {[Subtype in Extract<Nodes, SubTyped<Type>>['subType']]?: {\n visitor?: (op: Extract<Nodes, SubTyped<Type, Subtype>>) => void;\n preVisitor?: (op: Extract<Nodes, SubTyped<Type, Subtype>>) => VisitContext;\n }}},\n ): void {\n const visitWrapper = (curObject: object): void => {\n let ogTransform: ((node: any) => void) | undefined;\n const casted = <SubTyped<Nodes['type']>>curObject;\n if (casted.type && casted.subType) {\n const specific = nodeSpecificCallBacks[casted.type];\n if (specific) {\n ogTransform = specific[<keyof typeof specific> casted.subType]?.visitor;\n }\n if (!ogTransform) {\n ogTransform = nodeCallBacks[casted.type]?.visitor;\n }\n }\n if (ogTransform) {\n ogTransform(casted);\n }\n };\n const preVisitWrapper = (curObject: object): VisitContext => {\n let ogPreVisit: ((node: any) => VisitContext) | undefined;\n const casted = <SubTyped<Nodes['type']>>curObject;\n if (casted.type && casted.subType) {\n const specific = nodeSpecificCallBacks[casted.type];\n if (specific) {\n ogPreVisit = specific[<keyof typeof specific> casted.subType]?.preVisitor;\n }\n if (!ogPreVisit) {\n ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;\n }\n }\n return ogPreVisit ? ogPreVisit(casted) : {};\n };\n this.visitObject(startObject, visitWrapper, preVisitWrapper);\n }\n}\n"]}
@@ -1,123 +1,90 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var TransformerTyped_exports = {};
20
- __export(TransformerTyped_exports, {
21
- TransformerTyped: () => TransformerTyped
22
- });
23
- module.exports = __toCommonJS(TransformerTyped_exports);
24
- var import_TransformerObject = require("./TransformerObject.js");
25
- class TransformerTyped extends import_TransformerObject.TransformerObject {
26
- defaultNodePreVisitor;
27
- constructor(defaultContext = {}, defaultNodePreVisitor = {}) {
28
- super(defaultContext);
29
- this.defaultNodePreVisitor = defaultNodePreVisitor;
30
- }
31
- clone(newDefaultContext = {}, newDefaultNodePreVisitor = {}) {
32
- return new TransformerTyped({ ...this.defaultContext, ...newDefaultContext }, { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor });
33
- }
34
- /**
35
- * Transform a single node.
36
- * The transformation calls the preVisitor from starting from the startObject.
37
- * The preVisitor can dictate whether transformation should be stopped.
38
- * Note that stopping the transformation also prevets further copying.
39
- * The transformer itself transforms object starting with the deepest one that can be visited.
40
- * The transformer callback is performed on a copy of the original.
41
- * @param startObject
42
- * @param nodeCallBacks
43
- */
44
- transformNode(startObject, nodeCallBacks) {
45
- const transformWrapper = (copy, orig) => {
46
- let ogTransform;
47
- const casted = copy;
48
- if (casted.type) {
49
- ogTransform = nodeCallBacks[casted.type]?.transform;
50
- }
51
- return ogTransform ? ogTransform(casted, orig) : copy;
52
- };
53
- const nodeDefaults = this.defaultNodePreVisitor;
54
- const preVisitWrapper = (curObject) => {
55
- let ogPreVisit;
56
- let nodeContext = {};
57
- const casted = curObject;
58
- if (casted.type) {
59
- ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
60
- nodeContext = nodeDefaults[casted.type] ?? nodeContext;
61
- }
62
- return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;
63
- };
64
- return this.transformObject(startObject, transformWrapper, preVisitWrapper);
65
- }
66
- /**
67
- * Similar to {@link this.transformNode}, but without copying the startObject.
68
- * The pre-visitor visits starting from the root, going deeper, while the actual visitor goes in reverse.
69
- * @param startObject
70
- * @param nodeCallBacks
71
- */
72
- visitNode(startObject, nodeCallBacks) {
73
- const visitorWrapper = (curObject) => {
74
- const casted = curObject;
75
- if (casted.type) {
76
- const ogTransform = nodeCallBacks[casted.type]?.visitor;
77
- if (ogTransform) {
78
- ogTransform(casted);
79
- }
80
- }
81
- };
82
- const nodeDefaults = this.defaultNodePreVisitor;
83
- const preVisitWrapper = (curObject) => {
84
- let ogPreVisit;
85
- let nodeContext = {};
86
- const casted = curObject;
87
- if (casted.type) {
88
- ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
89
- nodeContext = nodeDefaults[casted.type] ?? nodeContext;
90
- }
91
- return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;
92
- };
93
- return this.visitObject(startObject, visitorWrapper, preVisitWrapper);
94
- }
95
- /**
96
- * Traverses only selected nodes as returned by the function.
97
- * @param currentNode
98
- * @param traverse
99
- */
100
- traverseNodes(currentNode, traverse) {
101
- let didShortCut = false;
102
- const recurse = (curNode) => {
103
- const traverser = traverse[curNode.type];
104
- if (traverser) {
105
- const { next, shortcut } = traverser(curNode);
106
- didShortCut = shortcut ?? false;
107
- if (!didShortCut) {
108
- for (const node of next ?? []) {
109
- if (didShortCut) {
110
- return;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransformerTyped = void 0;
4
+ const TransformerObject_js_1 = require("./TransformerObject.js");
5
+ class TransformerTyped extends TransformerObject_js_1.TransformerObject {
6
+ defaultNodePreVisitor;
7
+ constructor(defaultContext = {}, defaultNodePreVisitor = {}) {
8
+ super(defaultContext);
9
+ this.defaultNodePreVisitor = defaultNodePreVisitor;
10
+ }
11
+ ;
12
+ clone(newDefaultContext = {}, newDefaultNodePreVisitor = {}) {
13
+ return new TransformerTyped({ ...this.defaultContext, ...newDefaultContext }, { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor });
14
+ }
15
+ /**
16
+ * Transform a single node ({@link Typed}).
17
+ * @param startObject the object from which we will start the transformation,
18
+ * potentially visiting and transforming its descendants along the way.
19
+ * @param nodeCallBacks a dictionary mapping the various node types to objects optionally
20
+ * containing preVisitor and transformer.
21
+ * The preVisitor allows you to provide {@link TransformContext} for the current object,
22
+ * altering how it will be transformed.
23
+ * The transformer allows you to manipulate the copy of the current object,
24
+ * and expects you to return the value that should take the current objects place.
25
+ * @return the result of transforming the requested descendant operations (based on the preVisitor)
26
+ * using a transformer that works its way back up from the descendant to the startObject.
27
+ */
28
+ transformNode(startObject, nodeCallBacks) {
29
+ const transformWrapper = (copy, orig) => {
30
+ let ogTransform;
31
+ const casted = copy;
32
+ if (casted.type) {
33
+ ogTransform = nodeCallBacks[casted.type]?.transform;
111
34
  }
112
- recurse(node);
113
- }
114
- }
115
- }
116
- };
117
- recurse(currentNode);
118
- }
35
+ return ogTransform ? ogTransform(casted, orig) : copy;
36
+ };
37
+ const nodeDefaults = this.defaultNodePreVisitor;
38
+ const preVisitWrapper = (curObject) => {
39
+ let ogPreVisit;
40
+ let nodeContext = {};
41
+ const casted = curObject;
42
+ if (casted.type) {
43
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
44
+ nodeContext = nodeDefaults[casted.type] ?? nodeContext;
45
+ }
46
+ return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;
47
+ };
48
+ return this.transformObject(startObject, transformWrapper, preVisitWrapper);
49
+ }
50
+ /**
51
+ * Visit a selected subTree given a startObject, steering the visits based on {@link Typed} nodes.
52
+ * Will first call the preVisitor on the project and notice it should not iterate on its descendants.
53
+ * It then visits the project, and the outermost distinct, printing '21'.
54
+ * The pre-visitor visits starting from the root, going deeper, while the actual visitor goes in reverse.
55
+ * @param startObject the object from which we will start visiting,
56
+ * potentially visiting its descendants along the way.
57
+ * @param nodeCallBacks a dictionary mapping the various operation types to objects optionally
58
+ * containing preVisitor and visitor.
59
+ * The preVisitor allows you to provide {@link VisitContext} for the current object,
60
+ * altering how it will be visited.
61
+ * The visitor allows you to visit the object from deepest to the outermost object.
62
+ * This is useful if you for example want to manipulate the objects you visit during your visits,
63
+ * similar to {@link this.transformNode}.
64
+ */
65
+ visitNode(startObject, nodeCallBacks) {
66
+ const visitorWrapper = (curObject) => {
67
+ const casted = curObject;
68
+ if (casted.type) {
69
+ const ogTransform = nodeCallBacks[casted.type]?.visitor;
70
+ if (ogTransform) {
71
+ ogTransform(casted);
72
+ }
73
+ }
74
+ };
75
+ const nodeDefaults = this.defaultNodePreVisitor;
76
+ const preVisitWrapper = (curObject) => {
77
+ let ogPreVisit;
78
+ let nodeContext = {};
79
+ const casted = curObject;
80
+ if (casted.type) {
81
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
82
+ nodeContext = nodeDefaults[casted.type] ?? nodeContext;
83
+ }
84
+ return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;
85
+ };
86
+ return this.visitObject(startObject, visitorWrapper, preVisitWrapper);
87
+ }
119
88
  }
120
- // Annotate the CommonJS export names for ESM import in node:
121
- 0 && (module.exports = {
122
- TransformerTyped
123
- });
89
+ exports.TransformerTyped = TransformerTyped;
90
+ //# sourceMappingURL=TransformerTyped.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransformerTyped.js","sourceRoot":"","sources":["../../../../lib/transformers/TransformerTyped.ts"],"names":[],"mappings":";;;AAEA,iEAA2D;AAQ3D,MAAa,gBAAsC,SAAQ,wCAAiB;IAG9D;IAFZ,YACE,iBAAmC,EAAE,EAC3B,wBAAsD,EAAE;QAElE,KAAK,CAAC,cAAc,CAAC,CAAC;QAFZ,0BAAqB,GAArB,qBAAqB,CAAmC;IAGpE,CAAC;IAAA,CAAC;IAEc,KAAK,CACnB,oBAAsC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EAAE,gBAAgB,EAAE,eAAe,CAAC,CAAC;IACpF,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACI,SAAS,CACd,WAAmB,EACnB,aAGE;QAEF,MAAM,cAAc,GAAG,CAAC,SAAiB,EAAQ,EAAE;YACjD,MAAM,MAAM,GAAyB,SAAS,CAAC;YAC/C,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBAChB,MAAM,WAAW,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;gBACxD,IAAI,WAAW,EAAE,CAAC;oBAChB,WAAW,CAAO,MAAM,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC;QACH,CAAC,CAAC;QACF,MAAM,YAAY,GAAG,IAAI,CAAC,qBAAqB,CAAC;QAChD,MAAM,eAAe,GAAG,CAAC,SAAiB,EAAgB,EAAE;YAC1D,IAAI,UAAqD,CAAC;YAC1D,IAAI,WAAW,GAAiB,EAAE,CAAC;YACnC,MAAM,MAAM,GAAyB,SAAS,CAAC;YAC/C,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;gBAChB,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC;gBACpD,WAAW,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC;YACzD,CAAC;YACD,OAAO,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,WAAW,EAAE,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;QAC9E,CAAC,CAAC;QACF,OAAO,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC;IACxE,CAAC;CACF;AAxGD,4CAwGC","sourcesContent":["import type { Typed } from '../types.js';\nimport type { TransformContext, VisitContext } from './TransformerObject.js';\nimport { TransformerObject } from './TransformerObject.js';\n\nexport type Safeness = 'safe' | 'unsafe';\nexport type SafeWrap<Safe extends Safeness, obj extends object> =\n Safe extends 'safe' ? {[key in keyof obj]: unknown } : obj;\n\nexport type DefaultNodePreVisitor<Nodes extends Typed> = {[T in Nodes['type']]?: TransformContext };\n\nexport class TransformerTyped<Nodes extends Typed> extends TransformerObject {\n public constructor(\n defaultContext: TransformContext = {},\n protected defaultNodePreVisitor: DefaultNodePreVisitor<Nodes> = {},\n ) {\n super(defaultContext);\n };\n\n public override clone(\n newDefaultContext: TransformContext = {},\n newDefaultNodePreVisitor: DefaultNodePreVisitor<Nodes> = {},\n ): TransformerTyped<Nodes> {\n return new TransformerTyped(\n { ...this.defaultContext, ...newDefaultContext },\n { ...this.defaultNodePreVisitor, ...newDefaultNodePreVisitor },\n );\n }\n\n /**\n * Transform a single node ({@link Typed}).\n * @param startObject the object from which we will start the transformation,\n * potentially visiting and transforming its descendants along the way.\n * @param nodeCallBacks a dictionary mapping the various node types to objects optionally\n * containing preVisitor and transformer.\n * The preVisitor allows you to provide {@link TransformContext} for the current object,\n * altering how it will be transformed.\n * The transformer allows you to manipulate the copy of the current object,\n * and expects you to return the value that should take the current objects place.\n * @return the result of transforming the requested descendant operations (based on the preVisitor)\n * using a transformer that works its way back up from the descendant to the startObject.\n */\n public transformNode<Safe extends Safeness = 'safe', OutType = unknown>(\n startObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n transform?: (copy: SafeWrap<Safe, Extract<Nodes, Typed<T>>>, orig: Extract<Nodes, Typed<T>>) => unknown;\n preVisitor?: (orig: Extract<Nodes, Typed<T>>) => TransformContext;\n }},\n ): Safe extends 'unsafe' ? OutType : unknown {\n const transformWrapper = (copy: object, orig: object): unknown => {\n let ogTransform: ((copy: any, orig: any) => unknown) | undefined;\n const casted = <Typed<Nodes['type']>>copy;\n if (casted.type) {\n ogTransform = nodeCallBacks[casted.type]?.transform;\n }\n return ogTransform ? ogTransform(casted, orig) : copy;\n };\n const nodeDefaults = this.defaultNodePreVisitor;\n const preVisitWrapper = (curObject: object): VisitContext => {\n let ogPreVisit: ((node: any) => VisitContext) | undefined;\n let nodeContext: VisitContext = {};\n const casted = <Typed<Nodes['type']>>curObject;\n if (casted.type) {\n ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;\n nodeContext = nodeDefaults[casted.type] ?? nodeContext;\n }\n return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;\n };\n return <any> this.transformObject(startObject, transformWrapper, preVisitWrapper);\n }\n\n /**\n * Visit a selected subTree given a startObject, steering the visits based on {@link Typed} nodes.\n * Will first call the preVisitor on the project and notice it should not iterate on its descendants.\n * It then visits the project, and the outermost distinct, printing '21'.\n * The pre-visitor visits starting from the root, going deeper, while the actual visitor goes in reverse.\n * @param startObject the object from which we will start visiting,\n * potentially visiting its descendants along the way.\n * @param nodeCallBacks a dictionary mapping the various operation types to objects optionally\n * containing preVisitor and visitor.\n * The preVisitor allows you to provide {@link VisitContext} for the current object,\n * altering how it will be visited.\n * The visitor allows you to visit the object from deepest to the outermost object.\n * This is useful if you for example want to manipulate the objects you visit during your visits,\n * similar to {@link this.transformNode}.\n */\n public visitNode(\n startObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n visitor?: (op: Extract<Nodes, Typed<T>>) => void;\n preVisitor?: (op: Extract<Nodes, Typed<T>>) => VisitContext;\n }},\n ): void {\n const visitorWrapper = (curObject: object): void => {\n const casted = <Typed<Nodes['type']>>curObject;\n if (casted.type) {\n const ogTransform = nodeCallBacks[casted.type]?.visitor;\n if (ogTransform) {\n ogTransform(<any> casted);\n }\n }\n };\n const nodeDefaults = this.defaultNodePreVisitor;\n const preVisitWrapper = (curObject: object): VisitContext => {\n let ogPreVisit: ((node: any) => VisitContext) | undefined;\n let nodeContext: VisitContext = {};\n const casted = <Typed<Nodes['type']>>curObject;\n if (casted.type) {\n ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;\n nodeContext = nodeDefaults[casted.type] ?? nodeContext;\n }\n return ogPreVisit ? { ...nodeContext, ...ogPreVisit(casted) } : nodeContext;\n };\n return this.visitObject(startObject, visitorWrapper, preVisitWrapper);\n }\n}\n"]}
@@ -1,16 +1,3 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
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"]}
@@ -1,39 +1,25 @@
1
1
  "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var utils_exports = {};
20
- __export(utils_exports, {
21
- createToken: () => createToken,
22
- traqulaIndentation: () => traqulaIndentation,
23
- unCapitalize: () => unCapitalize
24
- });
25
- module.exports = __toCommonJS(utils_exports);
26
- var import_chevrotain = require("@traqula/chevrotain");
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.traqulaIndentation = void 0;
4
+ exports.unCapitalize = unCapitalize;
5
+ exports.createToken = createToken;
6
+ const chevrotain_1 = require("@traqula/chevrotain");
7
+ /**
8
+ * Lowercase the first letter of a given string.
9
+ * @param str
10
+ */
27
11
  function unCapitalize(str) {
28
- return str.charAt(0).toLowerCase() + str.slice(1);
12
+ return (str.charAt(0).toLowerCase() + str.slice(1));
29
13
  }
14
+ /**
15
+ * Create a token in a typesafe way necessary by the traqula core builders.
16
+ */
30
17
  function createToken(config) {
31
- return (0, import_chevrotain.createToken)(config);
18
+ return (0, chevrotain_1.createToken)(config);
32
19
  }
33
- const traqulaIndentation = "When you use this string, you expect traqula to handle indentation after every newline";
34
- // Annotate the CommonJS export names for ESM import in node:
35
- 0 && (module.exports = {
36
- createToken,
37
- traqulaIndentation,
38
- unCapitalize
39
- });
20
+ /**
21
+ * Key that allows you to set the space based indentation of your query when generating newlines using the NEW_LINE.
22
+ * A value of -1 disables the generation of newlines from the NEW_LINE function
23
+ */
24
+ exports.traqulaIndentation = 'When you use this string, you expect traqula to handle indentation after every newline';
25
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/utils.ts"],"names":[],"mappings":";;;AAYA,oCAEC;AAOD,kCAEC;AAtBD,oDAA4D;AAO5D;;;GAGG;AACH,SAAgB,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,SAAgB,WAAW,CAAsB,MAAqC;IACpF,OAAoC,IAAA,wBAAM,EAAC,MAAM,CAAC,CAAC;AACrD,CAAC;AAQD;;;GAGG;AACU,QAAA,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"]}