@traqula/core 0.0.16 → 0.0.17

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.
@@ -3,35 +3,68 @@ type Safeness = 'safe' | 'unsafe';
3
3
  type SafeWrap<Safe extends Safeness, obj extends object> = Safe extends 'safe' ? {
4
4
  [key in keyof obj]: unknown;
5
5
  } : obj;
6
+ export interface VisitContext {
7
+ shortcut?: boolean;
8
+ continue?: boolean;
9
+ }
10
+ export interface SelectiveTraversalContext<Nodes> {
11
+ next?: Nodes[];
12
+ shortcut?: boolean;
13
+ }
6
14
  export declare class TransformerType<Nodes extends Pick<Node, 'type'>> {
15
+ protected clone<T>(obj: T): T;
7
16
  protected safeObjectVisit(value: unknown, mapper: (some: object) => any): unknown;
8
- transformNode<Safe extends 'safe' | 'unsafe' = 'safe'>(curObject: object, nodeCallBacks: {
17
+ /**
18
+ * Recursively transforms all objects that are not arrays. Mapper is called on deeper objects first.
19
+ * @param startObject object to start iterating from
20
+ * @param mapper mapper to transform the various objects - argument is a copy of the original
21
+ * @param preVisitor callback that is evaluated before iterating deeper.
22
+ * If continues is false, we do not iterate deeper, current object is still mapped. - default: true
23
+ * If shortcut is true, we do not iterate deeper, nor do we branch out, this mapper will be the last one called.
24
+ * - Default false
25
+ */
26
+ transformObject(startObject: object, mapper: (some: object) => any, preVisitor?: (some: object) => VisitContext): unknown;
27
+ /**
28
+ * Visitor that visits all objects. Visits deeper objects first.
29
+ */
30
+ visitObject(startObject: object, visitor: (some: object) => void, preVisitor?: (some: object) => VisitContext): void;
31
+ transformNode<Safe extends 'safe' | 'unsafe' = 'safe'>(startObject: object, nodeCallBacks: {
9
32
  [T in Nodes['type']]?: {
10
33
  transform?: (op: SafeWrap<Safe, Extract<Nodes, {
11
34
  type: T;
12
35
  }>>) => any;
13
- continue?: (op: Extract<Nodes, {
36
+ preVisitor?: (op: Extract<Nodes, {
14
37
  type: T;
15
- }>) => boolean;
38
+ }>) => VisitContext;
16
39
  };
17
40
  }): any;
18
- visitNode(curObject: object, nodeCallBacks: {
41
+ visitNode(startObject: object, nodeCallBacks: {
42
+ [T in Nodes['type']]?: {
43
+ visitor?: (op: Extract<Nodes, {
44
+ type: T;
45
+ }>) => void;
46
+ preVisitor?: (op: Extract<Nodes, {
47
+ type: T;
48
+ }>) => VisitContext;
49
+ };
50
+ }): void;
51
+ traverseNodes(currentNode: Nodes, traverse: {
19
52
  [T in Nodes['type']]?: (op: Extract<Nodes, {
20
53
  type: T;
21
- }>) => boolean;
54
+ }>) => SelectiveTraversalContext<Nodes>;
22
55
  }): void;
23
56
  }
24
57
  export declare class TransformerSubType<Nodes extends Pick<Node, 'type' | 'subType'>> extends TransformerType<Nodes> {
25
- transformNodeSpecific<Safe extends 'safe' | 'unsafe' = 'safe'>(curObject: object, nodeCallBacks: {
58
+ transformNodeSpecific<Safe extends 'safe' | 'unsafe' = 'safe'>(startObject: object, nodeCallBacks: {
26
59
  [T in Nodes['type']]?: {
27
60
  transform?: (op: SafeWrap<Safe, Extract<Nodes, {
28
61
  type: T;
29
62
  }>>) => any;
30
- continue?: (op: Extract<Nodes, {
63
+ preVisitor?: (op: Extract<Nodes, {
31
64
  type: T;
32
- }>) => boolean;
65
+ }>) => VisitContext;
33
66
  };
34
- }, nodeSpecificCallBacks?: {
67
+ }, nodeSpecificCallBacks: {
35
68
  [Type in Nodes['type']]?: {
36
69
  [SubType in Extract<Nodes, {
37
70
  type: Type;
@@ -41,21 +74,47 @@ export declare class TransformerSubType<Nodes extends Pick<Node, 'type' | 'subTy
41
74
  type: Type;
42
75
  subType: SubType;
43
76
  }>>) => any;
44
- continue?: (op: Extract<Nodes, {
77
+ preVisitor?: (op: Extract<Nodes, {
45
78
  type: Type;
46
79
  subType: SubType;
47
- }>) => boolean;
80
+ }>) => VisitContext;
48
81
  };
49
82
  };
50
83
  }): any;
51
84
  /**
52
85
  * When both nodeCallBack and NodeSpecific callBack are matched, will only look at nodeSpecifCallback
53
86
  */
54
- visitNodeSpecific(curObject: object, nodeCallBacks: {
55
- [T in Nodes['type']]?: (op: Extract<Nodes, {
56
- type: T;
57
- }>) => boolean | void;
58
- }, nodeSpecificCallBacks?: {
87
+ visitNodeSpecific(startObject: object, nodeCallBacks: {
88
+ [T in Nodes['type']]?: {
89
+ visitor?: (op: Extract<Nodes, {
90
+ type: T;
91
+ }>) => void;
92
+ preVisitor?: (op: Extract<Nodes, {
93
+ type: T;
94
+ }>) => VisitContext;
95
+ };
96
+ }, nodeSpecificCallBacks: {
97
+ [Type in Nodes['type']]?: {
98
+ [Subtype in Extract<Nodes, {
99
+ type: Type;
100
+ subType: string;
101
+ }>['subType']]?: {
102
+ visitor?: (op: Extract<Nodes, {
103
+ type: Type;
104
+ subType: Subtype;
105
+ }>) => void;
106
+ preVisitor?: (op: Extract<Nodes, {
107
+ type: Type;
108
+ subType: Subtype;
109
+ }>) => VisitContext;
110
+ };
111
+ };
112
+ }): void;
113
+ traverseSubNodes(currentNode: Nodes, traverseNode: {
114
+ [Type in Nodes['type']]?: (op: Extract<Nodes, {
115
+ type: Type;
116
+ }>) => SelectiveTraversalContext<Nodes>;
117
+ }, traverseSubNode: {
59
118
  [Type in Nodes['type']]?: {
60
119
  [Subtype in Extract<Nodes, {
61
120
  type: Type;
@@ -63,7 +122,7 @@ export declare class TransformerSubType<Nodes extends Pick<Node, 'type' | 'subTy
63
122
  }>['subType']]?: (op: Extract<Nodes, {
64
123
  type: Type;
65
124
  subType: Subtype;
66
- }>) => boolean | void;
125
+ }>) => SelectiveTraversalContext<Nodes>;
67
126
  };
68
127
  }): void;
69
128
  }
@@ -1,7 +1,11 @@
1
1
  export class TransformerType {
2
+ clone(obj) {
3
+ const newObj = Object.create(Object.getPrototypeOf(obj));
4
+ Object.defineProperties(newObj, Object.getOwnPropertyDescriptors(obj));
5
+ return newObj;
6
+ }
2
7
  safeObjectVisit(value, mapper) {
3
8
  if (value && typeof value === 'object') {
4
- // If you wonder why this is all so hard, this is the reason. We cannot lose the methods of our Array objects
5
9
  if (Array.isArray(value)) {
6
10
  return value.map(x => this.safeObjectVisit(x, mapper));
7
11
  }
@@ -9,106 +13,214 @@ export class TransformerType {
9
13
  }
10
14
  return value;
11
15
  }
12
- transformNode(curObject, nodeCallBacks) {
13
- let continueCheck;
14
- let transformation;
15
- const casted = curObject;
16
- if (casted.type) {
17
- continueCheck = nodeCallBacks[casted.type]?.continue;
18
- transformation = nodeCallBacks[casted.type]?.transform;
19
- }
20
- let shouldContinue = true;
21
- if (continueCheck) {
22
- shouldContinue = continueCheck(curObject);
23
- }
24
- if (!shouldContinue) {
16
+ /**
17
+ * Recursively transforms all objects that are not arrays. Mapper is called on deeper objects first.
18
+ * @param startObject object to start iterating from
19
+ * @param mapper mapper to transform the various objects - argument is a copy of the original
20
+ * @param preVisitor callback that is evaluated before iterating deeper.
21
+ * If continues is false, we do not iterate deeper, current object is still mapped. - default: true
22
+ * If shortcut is true, we do not iterate deeper, nor do we branch out, this mapper will be the last one called.
23
+ * - Default false
24
+ */
25
+ transformObject(startObject, mapper, preVisitor = () => ({})) {
26
+ let didShortCut = false;
27
+ const recurse = (curObject) => {
28
+ const copy = this.clone(curObject);
29
+ const context = preVisitor(copy);
30
+ didShortCut = context.shortcut ?? false;
31
+ const continues = context.continue ?? true;
32
+ if (continues && !didShortCut) {
33
+ for (const [key, value] of Object.entries(copy)) {
34
+ if (didShortCut) {
35
+ return copy;
36
+ }
37
+ copy[key] =
38
+ this.safeObjectVisit(value, obj => recurse(obj));
39
+ }
40
+ }
41
+ return mapper(copy);
42
+ };
43
+ return recurse(startObject);
44
+ }
45
+ /**
46
+ * Visitor that visits all objects. Visits deeper objects first.
47
+ */
48
+ visitObject(startObject, visitor, preVisitor = () => ({})) {
49
+ let didShortCut = false;
50
+ const recurse = (curObject) => {
51
+ const context = preVisitor(curObject);
52
+ didShortCut = context.shortcut ?? false;
53
+ const continues = context.continue ?? true;
54
+ if (continues && !didShortCut) {
55
+ for (const value of Object.values(curObject)) {
56
+ if (didShortCut) {
57
+ return;
58
+ }
59
+ this.safeObjectVisit(value, obj => recurse(obj));
60
+ }
61
+ }
62
+ visitor(curObject);
63
+ };
64
+ recurse(startObject);
65
+ }
66
+ transformNode(startObject, nodeCallBacks) {
67
+ const transformWrapper = (curObject) => {
68
+ const casted = curObject;
69
+ if (casted.type) {
70
+ const ogFunc = nodeCallBacks[casted.type]?.transform;
71
+ if (ogFunc) {
72
+ return ogFunc(casted);
73
+ }
74
+ }
25
75
  return curObject;
26
- }
27
- const copy = { ...curObject };
28
- for (const [key, value] of Object.entries(copy)) {
29
- copy[key] =
30
- this.safeObjectVisit(value, obj => this.transformNode(obj, nodeCallBacks));
31
- }
32
- if (transformation) {
33
- return transformation(copy);
34
- }
35
- return copy;
76
+ };
77
+ const preTransformWrapper = (curObject) => {
78
+ const casted = curObject;
79
+ if (casted.type) {
80
+ const ogFunc = nodeCallBacks[casted.type]?.preVisitor;
81
+ if (ogFunc) {
82
+ return ogFunc(casted);
83
+ }
84
+ }
85
+ return {};
86
+ };
87
+ return this.transformObject(startObject, transformWrapper, preTransformWrapper);
36
88
  }
37
- visitNode(curObject, nodeCallBacks) {
38
- let callback;
39
- const casted = curObject;
40
- if (casted.type) {
41
- callback = nodeCallBacks[casted.type];
42
- }
43
- let shouldIterate = true;
44
- if (callback) {
45
- shouldIterate = callback(curObject);
46
- }
47
- if (shouldIterate) {
48
- for (const value of Object.values(curObject)) {
49
- this.safeObjectVisit(value, obj => this.visitNode(obj, nodeCallBacks));
89
+ visitNode(startObject, nodeCallBacks) {
90
+ const visitWrapper = (curObject) => {
91
+ const casted = curObject;
92
+ if (casted.type) {
93
+ const ogFunc = nodeCallBacks[casted.type]?.visitor;
94
+ if (ogFunc) {
95
+ ogFunc(casted);
96
+ }
50
97
  }
51
- }
98
+ };
99
+ const preVisitWrapper = (curObject) => {
100
+ const casted = curObject;
101
+ if (casted.type) {
102
+ const ogFunc = nodeCallBacks[casted.type]?.preVisitor;
103
+ if (ogFunc) {
104
+ return ogFunc(casted);
105
+ }
106
+ }
107
+ return {};
108
+ };
109
+ this.visitObject(startObject, visitWrapper, preVisitWrapper);
110
+ }
111
+ traverseNodes(currentNode, traverse) {
112
+ let didShortCut = false;
113
+ const recurse = (curNode) => {
114
+ const traverser = traverse[curNode.type];
115
+ if (traverser) {
116
+ const { next, shortcut } = traverser(curNode);
117
+ didShortCut = shortcut ?? false;
118
+ if (!didShortCut) {
119
+ for (const node of next ?? []) {
120
+ if (didShortCut) {
121
+ return;
122
+ }
123
+ recurse(node);
124
+ }
125
+ }
126
+ }
127
+ };
128
+ recurse(currentNode);
52
129
  }
53
130
  }
54
131
  export class TransformerSubType extends TransformerType {
55
- // Public visitObjects(curObject: object, visitor: (current: object) => void): void {
56
- // for (const value of Object.values(curObject)) {
57
- // this.safeObjectVisit(value, obj => this.visitObjects(obj, visitor));
58
- // }
59
- // }
60
- transformNodeSpecific(curObject, nodeCallBacks, nodeSpecificCallBacks = {}) {
61
- let continueCheck;
62
- let transformation;
63
- const casted = curObject;
64
- if (casted.type && casted.subType) {
65
- const specific = nodeSpecificCallBacks[casted.type];
66
- if (specific) {
67
- continueCheck = specific[casted.subType]?.continue;
68
- transformation = specific[casted.subType]?.transform;
132
+ transformNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
133
+ const transformWrapper = (curObject) => {
134
+ let ogTransform;
135
+ const casted = curObject;
136
+ if (casted.type && casted.subType) {
137
+ const specific = nodeSpecificCallBacks[casted.type];
138
+ if (specific) {
139
+ ogTransform = specific[casted.subType]?.transform;
140
+ }
141
+ if (!ogTransform) {
142
+ ogTransform = nodeCallBacks[casted.type]?.transform;
143
+ }
69
144
  }
70
- }
71
- let shouldContinue = true;
72
- if (continueCheck) {
73
- shouldContinue = continueCheck(curObject);
74
- }
75
- if (!shouldContinue) {
76
- return curObject;
77
- }
78
- const copy = { ...curObject };
79
- for (const [key, value] of Object.entries(copy)) {
80
- copy[key] =
81
- this.safeObjectVisit(value, obj => this.transformNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));
82
- }
83
- if (transformation) {
84
- return transformation(copy);
85
- }
86
- return copy;
145
+ return ogTransform ? ogTransform(casted) : curObject;
146
+ };
147
+ const preVisitWrapper = (curObject) => {
148
+ let ogPreVisit;
149
+ const casted = curObject;
150
+ if (casted.type && casted.subType) {
151
+ const specific = nodeSpecificCallBacks[casted.type];
152
+ if (specific) {
153
+ ogPreVisit = specific[casted.subType]?.preVisitor;
154
+ }
155
+ if (!ogPreVisit) {
156
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
157
+ }
158
+ }
159
+ return ogPreVisit ? ogPreVisit(casted) : curObject;
160
+ };
161
+ return this.transformObject(startObject, transformWrapper, preVisitWrapper);
87
162
  }
88
163
  /**
89
164
  * When both nodeCallBack and NodeSpecific callBack are matched, will only look at nodeSpecifCallback
90
165
  */
91
- visitNodeSpecific(curObject, nodeCallBacks, nodeSpecificCallBacks = {}) {
92
- let callback;
93
- const casted = curObject;
94
- if (casted.type && casted.subType) {
95
- const specific = nodeSpecificCallBacks[casted.type];
96
- if (specific) {
97
- callback = specific[casted.subType];
166
+ visitNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
167
+ const visitWrapper = (curObject) => {
168
+ let ogTransform;
169
+ const casted = curObject;
170
+ if (casted.type && casted.subType) {
171
+ const specific = nodeSpecificCallBacks[casted.type];
172
+ if (specific) {
173
+ ogTransform = specific[casted.subType]?.visitor;
174
+ }
175
+ if (!ogTransform) {
176
+ ogTransform = nodeCallBacks[casted.type]?.visitor;
177
+ }
98
178
  }
99
- }
100
- if (!callback && casted.type) {
101
- callback = nodeCallBacks[curObject.type];
102
- }
103
- let shouldIterate = true;
104
- if (callback) {
105
- shouldIterate = callback(curObject) ?? true;
106
- }
107
- if (shouldIterate) {
108
- for (const value of Object.values(curObject)) {
109
- this.safeObjectVisit(value, obj => this.visitNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));
179
+ if (ogTransform) {
180
+ ogTransform(casted);
110
181
  }
111
- }
182
+ };
183
+ const preVisitWrapper = (curObject) => {
184
+ let ogPreVisit;
185
+ const casted = curObject;
186
+ if (casted.type && casted.subType) {
187
+ const specific = nodeSpecificCallBacks[casted.type];
188
+ if (specific) {
189
+ ogPreVisit = specific[casted.subType]?.preVisitor;
190
+ }
191
+ if (!ogPreVisit) {
192
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
193
+ }
194
+ }
195
+ return ogPreVisit ? ogPreVisit(casted) : curObject;
196
+ };
197
+ this.visitObject(startObject, visitWrapper, preVisitWrapper);
198
+ }
199
+ traverseSubNodes(currentNode, traverseNode, traverseSubNode) {
200
+ let didShortCut = false;
201
+ const recurse = (curNode) => {
202
+ let traverser;
203
+ const subObj = traverseSubNode[curNode.type];
204
+ if (subObj) {
205
+ traverser = subObj[curNode.subType];
206
+ }
207
+ if (!traverser) {
208
+ traverser = traverseNode[curNode.type];
209
+ }
210
+ if (traverser) {
211
+ const { next, shortcut } = traverser(curNode);
212
+ didShortCut = shortcut ?? false;
213
+ if (!didShortCut) {
214
+ for (const node of next ?? []) {
215
+ if (didShortCut) {
216
+ return;
217
+ }
218
+ recurse(node);
219
+ }
220
+ }
221
+ }
222
+ };
223
+ recurse(currentNode);
112
224
  }
113
225
  }
114
226
  //# sourceMappingURL=Transformers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Transformers.js","sourceRoot":"","sources":["Transformers.ts"],"names":[],"mappings":"AAKA,MAAM,OAAO,eAAe;IAChB,eAAe,CAAC,KAAc,EAAE,MAA6B;QACrE,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvC,6GAA6G;YAC7G,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;YACz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S,CAAC,EAAE,CAAC;gBAC7C,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,EAAE,aAAa,EAAE,qBAAqB,CAAC,CAAC,CAAC;YACxG,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { Node } from './nodeTypings.js';\n\ntype Safeness = 'safe' | 'unsafe';\ntype SafeWrap<Safe extends Safeness, obj extends object> = Safe extends 'safe' ? {[key in keyof obj]: unknown } : obj;\n\nexport class TransformerType<Nodes extends Pick<Node, 'type'>> {\n protected safeObjectVisit(value: unknown, mapper: (some: object) => any): unknown {\n if (value && typeof value === 'object') {\n // If you wonder why this is all so hard, this is the reason. We cannot lose the methods of our Array objects\n if (Array.isArray(value)) {\n return value.map(x => this.safeObjectVisit(x, mapper));\n }\n return mapper(value);\n }\n return value;\n }\n\n public transformNode<Safe extends 'safe' | 'unsafe' = 'safe'>(\n curObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n transform?: (op: SafeWrap<Safe, Extract<Nodes, { type: T }>>) => any;\n continue?: (op: Extract<Nodes, { type: T }>) => boolean;\n }},\n ): any {\n let continueCheck: ((node: any) => boolean) | undefined;\n let transformation: ((node: any) => unknown) | undefined;\n const casted = <{ type?: Nodes['type'] }>curObject;\n if (casted.type) {\n continueCheck = nodeCallBacks[casted.type]?.continue;\n transformation = nodeCallBacks[casted.type]?.transform;\n }\n let shouldContinue = true;\n if (continueCheck) {\n shouldContinue = continueCheck(curObject);\n }\n if (!shouldContinue) {\n return curObject;\n }\n const copy: { type?: unknown } = { ...curObject };\n for (const [ key, value ] of Object.entries(copy)) {\n (<Record<string, unknown>> copy)[key] =\n this.safeObjectVisit(value, obj => this.transformNode(obj, nodeCallBacks));\n }\n if (transformation) {\n return transformation(copy);\n }\n return copy;\n }\n\n public visitNode(\n curObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: (op: Extract<Nodes, { type: T }>) => boolean },\n ): void {\n let callback: ((node: any) => boolean) | undefined;\n const casted = <{ type?: Nodes['type'] }>curObject;\n if (casted.type) {\n callback = nodeCallBacks[casted.type];\n }\n let shouldIterate = true;\n if (callback) {\n shouldIterate = callback(curObject);\n }\n if (shouldIterate) {\n for (const value of Object.values(curObject)) {\n this.safeObjectVisit(value, obj => this.visitNode(obj, nodeCallBacks));\n }\n }\n }\n}\n\nexport class TransformerSubType<Nodes extends Pick<Node, 'type' | 'subType'>> extends TransformerType<Nodes> {\n // Public visitObjects(curObject: object, visitor: (current: object) => void): void {\n // for (const value of Object.values(curObject)) {\n // this.safeObjectVisit(value, obj => this.visitObjects(obj, visitor));\n // }\n // }\n\n public transformNodeSpecific<Safe extends 'safe' | 'unsafe' = 'safe'>(\n curObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n transform?: (op: SafeWrap<Safe, Extract<Nodes, { type: T }>>) => any;\n continue?: (op: Extract<Nodes, { type: T }>) => boolean;\n }},\n nodeSpecificCallBacks: {[Type in Nodes['type']]?: {\n [SubType in Extract<Nodes, { type: Type; subType: string }>['subType']]?: {\n transform?: (op: SafeWrap<Safe, Extract<Nodes, { type: Type; subType: SubType }>>) => any;\n continue?: (op: Extract<Nodes, { type: Type; subType: SubType }>) => boolean;\n }}} = {},\n ): any {\n let continueCheck: ((node: any) => boolean) | undefined;\n let transformation: ((node: any) => unknown) | undefined;\n const casted = <{ type?: Nodes['type']; subType?: string }>curObject;\n if (casted.type && casted.subType) {\n const specific = nodeSpecificCallBacks[casted.type];\n if (specific) {\n continueCheck = specific[<keyof typeof specific> casted.subType]?.continue;\n transformation = specific[<keyof typeof specific> casted.subType]?.transform;\n }\n }\n let shouldContinue = true;\n if (continueCheck) {\n shouldContinue = continueCheck(curObject);\n }\n if (!shouldContinue) {\n return curObject;\n }\n const copy: { type?: unknown } = { ...curObject };\n for (const [ key, value ] of Object.entries(copy)) {\n (<Record<string, unknown>> copy)[key] =\n this.safeObjectVisit(value, obj => this.transformNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));\n }\n if (transformation) {\n return transformation(copy);\n }\n return copy;\n }\n\n /**\n * When both nodeCallBack and NodeSpecific callBack are matched, will only look at nodeSpecifCallback\n */\n public visitNodeSpecific(\n curObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: (op: Extract<Nodes, { type: T }>) => boolean | void },\n nodeSpecificCallBacks: {[Type in Nodes['type']]?:\n {[Subtype in Extract<Nodes, { type: Type; subType: string }>['subType']]?:\n (op: Extract<Nodes, { type: Type; subType: Subtype }>) => boolean | void }} = {},\n ): void {\n let callback: ((node: any) => boolean | void) | undefined;\n const casted = <{ type?: Nodes['type']; subType?: string }> curObject;\n if (casted.type && casted.subType) {\n const specific = nodeSpecificCallBacks[casted.type];\n if (specific) {\n callback = specific[<keyof typeof specific>casted.subType];\n }\n }\n if (!callback && casted.type) {\n callback = nodeCallBacks[(<{ type: Nodes['type'] }> curObject).type];\n }\n let shouldIterate = true;\n if (callback) {\n shouldIterate = callback(curObject) ?? true;\n }\n if (shouldIterate) {\n for (const value of Object.values(curObject)) {\n this.safeObjectVisit(value, obj => this.visitNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"Transformers.js","sourceRoot":"","sources":["Transformers.ts"],"names":[],"mappings":"AAeA,MAAM,OAAO,eAAe;IAChB,KAAK,CAAI,GAAM;QACvB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC;QACzD,MAAM,CAAC,gBAAgB,CACrB,MAAM,EACN,MAAM,CAAC,yBAAyB,CAAC,GAAG,CAAC,CACtC,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;IAES,eAAe,CAAC,KAAc,EAAE,MAA6B;QACrE,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvC,IAAI,KAAK,CAAC,OAAO,CAAC,K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AgB,OAAO,CAAC,IAAI,CAAC,CAAC;YACxD,CAAC;YACD,IAAI,SAAS,EAAE,CAAC;gBACd,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAM,OAAO,CAAC,CAAC;gBACnD,WAAW,GAAG,QAAQ,IAAI,KAAK,CAAC;gBAChC,IAAI,CAAC,WAAW,EAAE,CAAC;oBACjB,KAAK,MAAM,IAAI,IAAI,IAAI,IAAI,EAAE,EAAE,CAAC;wBAC9B,IAAI,WAAW,EAAE,CAAC;4BAChB,OAAO;wBACT,CAAC;wBACD,OAAO,CAAC,IAAI,CAAC,CAAC;oBAChB,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC;QAEF,OAAO,CAAC,WAAW,CAAC,CAAC;IACvB,CAAC;CACF","sourcesContent":["import type { Node } from './nodeTypings.js';\n\ntype Safeness = 'safe' | 'unsafe';\ntype SafeWrap<Safe extends Safeness, obj extends object> = Safe extends 'safe' ? {[key in keyof obj]: unknown } : obj;\n\nexport interface VisitContext {\n shortcut?: boolean;\n continue?: boolean;\n}\n\nexport interface SelectiveTraversalContext<Nodes> {\n next?: Nodes[];\n shortcut?: boolean;\n}\n\nexport class TransformerType<Nodes extends Pick<Node, 'type'>> {\n protected clone<T>(obj: T): T {\n const newObj = Object.create(Object.getPrototypeOf(obj));\n Object.defineProperties(\n newObj,\n Object.getOwnPropertyDescriptors(obj),\n );\n return newObj;\n }\n\n protected safeObjectVisit(value: unknown, mapper: (some: object) => any): unknown {\n if (value && typeof value === 'object') {\n if (Array.isArray(value)) {\n return value.map(x => this.safeObjectVisit(x, mapper));\n }\n return mapper(value);\n }\n return value;\n }\n\n /**\n * Recursively transforms all objects that are not arrays. Mapper is called on deeper objects first.\n * @param startObject object to start iterating from\n * @param mapper mapper to transform the various objects - argument is a copy of the original\n * @param preVisitor callback that is evaluated before iterating deeper.\n * If continues is false, we do not iterate deeper, current object is still mapped. - default: true\n * If shortcut is true, we do not iterate deeper, nor do we branch out, this mapper will be the last one called.\n * - Default false\n */\n public transformObject(\n startObject: object,\n mapper: (some: object) => any,\n preVisitor: (some: object) => VisitContext = () => ({}),\n ): unknown {\n let didShortCut = false;\n const recurse = (curObject: object): unknown => {\n const copy = this.clone(curObject);\n const context = preVisitor(copy);\n didShortCut = context.shortcut ?? false;\n const continues = context.continue ?? true;\n if (continues && !didShortCut) {\n for (const [ key, value ] of Object.entries(copy)) {\n if (didShortCut) {\n return copy;\n }\n (<Record<string, unknown>> copy)[key] =\n this.safeObjectVisit(value, obj => recurse(obj));\n }\n }\n return mapper(copy);\n };\n\n return recurse(startObject);\n }\n\n /**\n * Visitor that visits all objects. Visits deeper objects first.\n */\n public visitObject(\n startObject: object,\n visitor: (some: object) => void,\n preVisitor: (some: object) => VisitContext = () => ({}),\n ): void {\n let didShortCut = false;\n\n const recurse = (curObject: object): void => {\n const context = preVisitor(curObject);\n didShortCut = context.shortcut ?? false;\n const continues = context.continue ?? true;\n if (continues && !didShortCut) {\n for (const value of Object.values(curObject)) {\n if (didShortCut) {\n return;\n }\n this.safeObjectVisit(value, obj => recurse(obj));\n }\n }\n visitor(curObject);\n };\n recurse(startObject);\n }\n\n public transformNode<Safe extends 'safe' | 'unsafe' = 'safe'>(\n startObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n transform?: (op: SafeWrap<Safe, Extract<Nodes, { type: T }>>) => any;\n preVisitor?: (op: Extract<Nodes, { type: T }>) => VisitContext;\n }},\n ): any {\n const transformWrapper = (curObject: object): unknown => {\n const casted = <{ type?: Nodes['type'] }>curObject;\n if (casted.type) {\n const ogFunc: ((node: any) => unknown) | undefined = nodeCallBacks[casted.type]?.transform;\n if (ogFunc) {\n return ogFunc(casted);\n }\n }\n return curObject;\n };\n const preTransformWrapper = (curObject: object): VisitContext => {\n const casted = <{ type?: Nodes['type'] }>curObject;\n if (casted.type) {\n const ogFunc: ((node: any) => VisitContext) | undefined = nodeCallBacks[casted.type]?.preVisitor;\n if (ogFunc) {\n return ogFunc(casted);\n }\n }\n return {};\n };\n return this.transformObject(startObject, transformWrapper, preTransformWrapper);\n }\n\n public visitNode(\n startObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n visitor?: (op: Extract<Nodes, { type: T }>) => void;\n preVisitor?: (op: Extract<Nodes, { type: T }>) => VisitContext;\n }},\n ): void {\n const visitWrapper = (curObject: object): void => {\n const casted = <{ type?: Nodes['type'] }>curObject;\n if (casted.type) {\n const ogFunc: ((node: any) => unknown) | undefined = nodeCallBacks[casted.type]?.visitor;\n if (ogFunc) {\n ogFunc(casted);\n }\n }\n };\n const preVisitWrapper = (curObject: object): VisitContext => {\n const casted = <{ type?: Nodes['type'] }>curObject;\n if (casted.type) {\n const ogFunc: ((node: any) => VisitContext) | undefined = nodeCallBacks[casted.type]?.preVisitor;\n if (ogFunc) {\n return ogFunc(casted);\n }\n }\n return {};\n };\n this.visitObject(startObject, visitWrapper, preVisitWrapper);\n }\n\n public traverseNodes(\n currentNode: Nodes,\n traverse: {[T in Nodes['type']]?: (op: Extract<Nodes, { type: T }>) => SelectiveTraversalContext<Nodes> },\n ): void {\n let didShortCut = false;\n\n const recurse = (curNode: Nodes): void => {\n const traverser = traverse[<Nodes['type']>curNode.type];\n if (traverser) {\n const { next, shortcut } = traverser(<any>curNode);\n didShortCut = shortcut ?? false;\n if (!didShortCut) {\n for (const node of next ?? []) {\n if (didShortCut) {\n return;\n }\n recurse(node);\n }\n }\n }\n };\n\n recurse(currentNode);\n }\n}\n\nexport class TransformerSubType<Nodes extends Pick<Node, 'type' | 'subType'>> extends TransformerType<Nodes> {\n public transformNodeSpecific<Safe extends 'safe' | 'unsafe' = 'safe'>(\n startObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n transform?: (op: SafeWrap<Safe, Extract<Nodes, { type: T }>>) => any;\n preVisitor?: (op: Extract<Nodes, { type: T }>) => VisitContext;\n }},\n nodeSpecificCallBacks: {[Type in Nodes['type']]?: {\n [SubType in Extract<Nodes, { type: Type; subType: string }>['subType']]?: {\n transform?: (op: SafeWrap<Safe, Extract<Nodes, { type: Type; subType: SubType }>>) => any;\n preVisitor?: (op: Extract<Nodes, { type: Type; subType: SubType }>) => VisitContext;\n }}},\n ): any {\n const transformWrapper = (curObject: object): unknown => {\n let ogTransform: ((node: any) => unknown) | undefined;\n const casted = <{ type?: Nodes['type']; subType?: string }>curObject;\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) : curObject;\n };\n const preVisitWrapper = (curObject: object): VisitContext => {\n let ogPreVisit: ((node: any) => VisitContext) | undefined;\n const casted = <{ type?: Nodes['type']; subType?: string }>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) : curObject;\n };\n return this.transformObject(startObject, transformWrapper, preVisitWrapper);\n }\n\n /**\n * When both nodeCallBack and NodeSpecific callBack are matched, will only look at nodeSpecifCallback\n */\n public visitNodeSpecific(\n startObject: object,\n nodeCallBacks: {[T in Nodes['type']]?: {\n visitor?: (op: Extract<Nodes, { type: T }>) => void;\n preVisitor?: (op: Extract<Nodes, { type: T }>) => VisitContext;\n }},\n nodeSpecificCallBacks: {[Type in Nodes['type']]?:\n {[Subtype in Extract<Nodes, { type: Type; subType: string }>['subType']]?: {\n visitor?: (op: Extract<Nodes, { type: Type; subType: Subtype }>) => void;\n preVisitor?: (op: Extract<Nodes, { type: Type; subType: Subtype }>) => VisitContext;\n }}},\n ): void {\n const visitWrapper = (curObject: object): void => {\n let ogTransform: ((node: any) => void) | undefined;\n const casted = <{ type?: Nodes['type']; subType?: string }>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 = <{ type?: Nodes['type']; subType?: string }>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) : curObject;\n };\n this.visitObject(startObject, visitWrapper, preVisitWrapper);\n }\n\n public traverseSubNodes(\n currentNode: Nodes,\n traverseNode: {[Type in Nodes['type']]?:\n (op: Extract<Nodes, { type: Type }>) => SelectiveTraversalContext<Nodes> },\n traverseSubNode: {[Type in Nodes['type']]?:\n {[Subtype in Extract<Nodes, { type: Type; subType: string }>['subType']]?:\n (op: Extract<Nodes, { type: Type; subType: Subtype }>) => SelectiveTraversalContext<Nodes> }},\n ): void {\n let didShortCut = false;\n\n const recurse = (curNode: Nodes): void => {\n let traverser: ((call: any) => SelectiveTraversalContext<Nodes>) | undefined;\n const subObj = traverseSubNode[<Nodes['type']>curNode.type];\n if (subObj) {\n traverser = subObj[<keyof typeof subObj>curNode.subType];\n }\n if (!traverser) {\n traverser = traverseNode[<Nodes['type']>curNode.type];\n }\n if (traverser) {\n const { next, shortcut } = traverser(<any>curNode);\n didShortCut = shortcut ?? false;\n if (!didShortCut) {\n for (const node of next ?? []) {\n if (didShortCut) {\n return;\n }\n recurse(node);\n }\n }\n }\n };\n\n recurse(currentNode);\n }\n}\n"]}
package/lib/index.cjs CHANGED
@@ -10098,6 +10098,11 @@ ${firstError.message}`);
10098
10098
 
10099
10099
  // lib/Transformers.js
10100
10100
  var TransformerType = class {
10101
+ clone(obj) {
10102
+ const newObj = Object.create(Object.getPrototypeOf(obj));
10103
+ Object.defineProperties(newObj, Object.getOwnPropertyDescriptors(obj));
10104
+ return newObj;
10105
+ }
10101
10106
  safeObjectVisit(value, mapper) {
10102
10107
  if (value && typeof value === "object") {
10103
10108
  if (Array.isArray(value)) {
@@ -10107,104 +10112,213 @@ var TransformerType = class {
10107
10112
  }
10108
10113
  return value;
10109
10114
  }
10110
- transformNode(curObject, nodeCallBacks) {
10111
- let continueCheck;
10112
- let transformation;
10113
- const casted = curObject;
10114
- if (casted.type) {
10115
- continueCheck = nodeCallBacks[casted.type]?.continue;
10116
- transformation = nodeCallBacks[casted.type]?.transform;
10117
- }
10118
- let shouldContinue = true;
10119
- if (continueCheck) {
10120
- shouldContinue = continueCheck(curObject);
10121
- }
10122
- if (!shouldContinue) {
10123
- return curObject;
10124
- }
10125
- const copy = { ...curObject };
10126
- for (const [key, value] of Object.entries(copy)) {
10127
- copy[key] = this.safeObjectVisit(value, (obj) => this.transformNode(obj, nodeCallBacks));
10128
- }
10129
- if (transformation) {
10130
- return transformation(copy);
10131
- }
10132
- return copy;
10115
+ /**
10116
+ * Recursively transforms all objects that are not arrays. Mapper is called on deeper objects first.
10117
+ * @param startObject object to start iterating from
10118
+ * @param mapper mapper to transform the various objects - argument is a copy of the original
10119
+ * @param preVisitor callback that is evaluated before iterating deeper.
10120
+ * If continues is false, we do not iterate deeper, current object is still mapped. - default: true
10121
+ * If shortcut is true, we do not iterate deeper, nor do we branch out, this mapper will be the last one called.
10122
+ * - Default false
10123
+ */
10124
+ transformObject(startObject, mapper, preVisitor = () => ({})) {
10125
+ let didShortCut = false;
10126
+ const recurse = (curObject) => {
10127
+ const copy = this.clone(curObject);
10128
+ const context = preVisitor(copy);
10129
+ didShortCut = context.shortcut ?? false;
10130
+ const continues = context.continue ?? true;
10131
+ if (continues && !didShortCut) {
10132
+ for (const [key, value] of Object.entries(copy)) {
10133
+ if (didShortCut) {
10134
+ return copy;
10135
+ }
10136
+ copy[key] = this.safeObjectVisit(value, (obj) => recurse(obj));
10137
+ }
10138
+ }
10139
+ return mapper(copy);
10140
+ };
10141
+ return recurse(startObject);
10133
10142
  }
10134
- visitNode(curObject, nodeCallBacks) {
10135
- let callback;
10136
- const casted = curObject;
10137
- if (casted.type) {
10138
- callback = nodeCallBacks[casted.type];
10139
- }
10140
- let shouldIterate = true;
10141
- if (callback) {
10142
- shouldIterate = callback(curObject);
10143
- }
10144
- if (shouldIterate) {
10145
- for (const value of Object.values(curObject)) {
10146
- this.safeObjectVisit(value, (obj) => this.visitNode(obj, nodeCallBacks));
10143
+ /**
10144
+ * Visitor that visits all objects. Visits deeper objects first.
10145
+ */
10146
+ visitObject(startObject, visitor, preVisitor = () => ({})) {
10147
+ let didShortCut = false;
10148
+ const recurse = (curObject) => {
10149
+ const context = preVisitor(curObject);
10150
+ didShortCut = context.shortcut ?? false;
10151
+ const continues = context.continue ?? true;
10152
+ if (continues && !didShortCut) {
10153
+ for (const value of Object.values(curObject)) {
10154
+ if (didShortCut) {
10155
+ return;
10156
+ }
10157
+ this.safeObjectVisit(value, (obj) => recurse(obj));
10158
+ }
10147
10159
  }
10148
- }
10160
+ visitor(curObject);
10161
+ };
10162
+ recurse(startObject);
10163
+ }
10164
+ transformNode(startObject, nodeCallBacks) {
10165
+ const transformWrapper = (curObject) => {
10166
+ const casted = curObject;
10167
+ if (casted.type) {
10168
+ const ogFunc = nodeCallBacks[casted.type]?.transform;
10169
+ if (ogFunc) {
10170
+ return ogFunc(casted);
10171
+ }
10172
+ }
10173
+ return curObject;
10174
+ };
10175
+ const preTransformWrapper = (curObject) => {
10176
+ const casted = curObject;
10177
+ if (casted.type) {
10178
+ const ogFunc = nodeCallBacks[casted.type]?.preVisitor;
10179
+ if (ogFunc) {
10180
+ return ogFunc(casted);
10181
+ }
10182
+ }
10183
+ return {};
10184
+ };
10185
+ return this.transformObject(startObject, transformWrapper, preTransformWrapper);
10186
+ }
10187
+ visitNode(startObject, nodeCallBacks) {
10188
+ const visitWrapper = (curObject) => {
10189
+ const casted = curObject;
10190
+ if (casted.type) {
10191
+ const ogFunc = nodeCallBacks[casted.type]?.visitor;
10192
+ if (ogFunc) {
10193
+ ogFunc(casted);
10194
+ }
10195
+ }
10196
+ };
10197
+ const preVisitWrapper = (curObject) => {
10198
+ const casted = curObject;
10199
+ if (casted.type) {
10200
+ const ogFunc = nodeCallBacks[casted.type]?.preVisitor;
10201
+ if (ogFunc) {
10202
+ return ogFunc(casted);
10203
+ }
10204
+ }
10205
+ return {};
10206
+ };
10207
+ this.visitObject(startObject, visitWrapper, preVisitWrapper);
10208
+ }
10209
+ traverseNodes(currentNode, traverse) {
10210
+ let didShortCut = false;
10211
+ const recurse = (curNode) => {
10212
+ const traverser = traverse[curNode.type];
10213
+ if (traverser) {
10214
+ const { next, shortcut } = traverser(curNode);
10215
+ didShortCut = shortcut ?? false;
10216
+ if (!didShortCut) {
10217
+ for (const node of next ?? []) {
10218
+ if (didShortCut) {
10219
+ return;
10220
+ }
10221
+ recurse(node);
10222
+ }
10223
+ }
10224
+ }
10225
+ };
10226
+ recurse(currentNode);
10149
10227
  }
10150
10228
  };
10151
10229
  var TransformerSubType = class extends TransformerType {
10152
- // Public visitObjects(curObject: object, visitor: (current: object) => void): void {
10153
- // for (const value of Object.values(curObject)) {
10154
- // this.safeObjectVisit(value, obj => this.visitObjects(obj, visitor));
10155
- // }
10156
- // }
10157
- transformNodeSpecific(curObject, nodeCallBacks, nodeSpecificCallBacks = {}) {
10158
- let continueCheck;
10159
- let transformation;
10160
- const casted = curObject;
10161
- if (casted.type && casted.subType) {
10162
- const specific = nodeSpecificCallBacks[casted.type];
10163
- if (specific) {
10164
- continueCheck = specific[casted.subType]?.continue;
10165
- transformation = specific[casted.subType]?.transform;
10166
- }
10167
- }
10168
- let shouldContinue = true;
10169
- if (continueCheck) {
10170
- shouldContinue = continueCheck(curObject);
10171
- }
10172
- if (!shouldContinue) {
10173
- return curObject;
10174
- }
10175
- const copy = { ...curObject };
10176
- for (const [key, value] of Object.entries(copy)) {
10177
- copy[key] = this.safeObjectVisit(value, (obj) => this.transformNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));
10178
- }
10179
- if (transformation) {
10180
- return transformation(copy);
10181
- }
10182
- return copy;
10230
+ transformNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
10231
+ const transformWrapper = (curObject) => {
10232
+ let ogTransform;
10233
+ const casted = curObject;
10234
+ if (casted.type && casted.subType) {
10235
+ const specific = nodeSpecificCallBacks[casted.type];
10236
+ if (specific) {
10237
+ ogTransform = specific[casted.subType]?.transform;
10238
+ }
10239
+ if (!ogTransform) {
10240
+ ogTransform = nodeCallBacks[casted.type]?.transform;
10241
+ }
10242
+ }
10243
+ return ogTransform ? ogTransform(casted) : curObject;
10244
+ };
10245
+ const preVisitWrapper = (curObject) => {
10246
+ let ogPreVisit;
10247
+ const casted = curObject;
10248
+ if (casted.type && casted.subType) {
10249
+ const specific = nodeSpecificCallBacks[casted.type];
10250
+ if (specific) {
10251
+ ogPreVisit = specific[casted.subType]?.preVisitor;
10252
+ }
10253
+ if (!ogPreVisit) {
10254
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
10255
+ }
10256
+ }
10257
+ return ogPreVisit ? ogPreVisit(casted) : curObject;
10258
+ };
10259
+ return this.transformObject(startObject, transformWrapper, preVisitWrapper);
10183
10260
  }
10184
10261
  /**
10185
10262
  * When both nodeCallBack and NodeSpecific callBack are matched, will only look at nodeSpecifCallback
10186
10263
  */
10187
- visitNodeSpecific(curObject, nodeCallBacks, nodeSpecificCallBacks = {}) {
10188
- let callback;
10189
- const casted = curObject;
10190
- if (casted.type && casted.subType) {
10191
- const specific = nodeSpecificCallBacks[casted.type];
10192
- if (specific) {
10193
- callback = specific[casted.subType];
10264
+ visitNodeSpecific(startObject, nodeCallBacks, nodeSpecificCallBacks) {
10265
+ const visitWrapper = (curObject) => {
10266
+ let ogTransform;
10267
+ const casted = curObject;
10268
+ if (casted.type && casted.subType) {
10269
+ const specific = nodeSpecificCallBacks[casted.type];
10270
+ if (specific) {
10271
+ ogTransform = specific[casted.subType]?.visitor;
10272
+ }
10273
+ if (!ogTransform) {
10274
+ ogTransform = nodeCallBacks[casted.type]?.visitor;
10275
+ }
10194
10276
  }
10195
- }
10196
- if (!callback && casted.type) {
10197
- callback = nodeCallBacks[curObject.type];
10198
- }
10199
- let shouldIterate = true;
10200
- if (callback) {
10201
- shouldIterate = callback(curObject) ?? true;
10202
- }
10203
- if (shouldIterate) {
10204
- for (const value of Object.values(curObject)) {
10205
- this.safeObjectVisit(value, (obj) => this.visitNodeSpecific(obj, nodeCallBacks, nodeSpecificCallBacks));
10277
+ if (ogTransform) {
10278
+ ogTransform(casted);
10206
10279
  }
10207
- }
10280
+ };
10281
+ const preVisitWrapper = (curObject) => {
10282
+ let ogPreVisit;
10283
+ const casted = curObject;
10284
+ if (casted.type && casted.subType) {
10285
+ const specific = nodeSpecificCallBacks[casted.type];
10286
+ if (specific) {
10287
+ ogPreVisit = specific[casted.subType]?.preVisitor;
10288
+ }
10289
+ if (!ogPreVisit) {
10290
+ ogPreVisit = nodeCallBacks[casted.type]?.preVisitor;
10291
+ }
10292
+ }
10293
+ return ogPreVisit ? ogPreVisit(casted) : curObject;
10294
+ };
10295
+ this.visitObject(startObject, visitWrapper, preVisitWrapper);
10296
+ }
10297
+ traverseSubNodes(currentNode, traverseNode, traverseSubNode) {
10298
+ let didShortCut = false;
10299
+ const recurse = (curNode) => {
10300
+ let traverser;
10301
+ const subObj = traverseSubNode[curNode.type];
10302
+ if (subObj) {
10303
+ traverser = subObj[curNode.subType];
10304
+ }
10305
+ if (!traverser) {
10306
+ traverser = traverseNode[curNode.type];
10307
+ }
10308
+ if (traverser) {
10309
+ const { next, shortcut } = traverser(curNode);
10310
+ didShortCut = shortcut ?? false;
10311
+ if (!didShortCut) {
10312
+ for (const node of next ?? []) {
10313
+ if (didShortCut) {
10314
+ return;
10315
+ }
10316
+ recurse(node);
10317
+ }
10318
+ }
10319
+ }
10320
+ };
10321
+ recurse(currentNode);
10208
10322
  }
10209
10323
  };
10210
10324
  /*! Bundled license information:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@traqula/core",
3
3
  "type": "module",
4
- "version": "0.0.16",
4
+ "version": "0.0.17",
5
5
  "description": "Core components of Traqula",
6
6
  "lsd:module": true,
7
7
  "license": "MIT",
@@ -47,5 +47,5 @@
47
47
  "devDependencies": {
48
48
  "@chevrotain/types": "^11.0.3"
49
49
  },
50
- "gitHead": "2de4ee608a2337bed63ecc5cf336b1a57c39e45f"
50
+ "gitHead": "e4c1ef096da34d42ff86ac01d9affd428754c0b1"
51
51
  }