@swagger-api/apidom-ast 1.0.0-alpha.1 → 1.0.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,42 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.0.0-alpha.10](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.9...v1.0.0-alpha.10) (2024-10-21)
7
+
8
+ **Note:** Version bump only for package @swagger-api/apidom-ast
9
+
10
+ # [1.0.0-alpha.9](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.8...v1.0.0-alpha.9) (2024-08-14)
11
+
12
+ **Note:** Version bump only for package @swagger-api/apidom-ast
13
+
14
+ # [1.0.0-alpha.8](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2024-08-08)
15
+
16
+ **Note:** Version bump only for package @swagger-api/apidom-ast
17
+
18
+ # [1.0.0-alpha.7](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.6...v1.0.0-alpha.7) (2024-08-05)
19
+
20
+ **Note:** Version bump only for package @swagger-api/apidom-ast
21
+
22
+ # [1.0.0-alpha.6](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2024-07-09)
23
+
24
+ **Note:** Version bump only for package @swagger-api/apidom-ast
25
+
26
+ # [1.0.0-alpha.5](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.4...v1.0.0-alpha.5) (2024-05-29)
27
+
28
+ **Note:** Version bump only for package @swagger-api/apidom-ast
29
+
30
+ # [1.0.0-alpha.3](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.2...v1.0.0-alpha.3) (2024-05-21)
31
+
32
+ ### Bug Fixes
33
+
34
+ - **ast:** fix visitor merging when performing node replacements ([#4124](https://github.com/swagger-api/apidom/issues/4124)) ([c89cbad](https://github.com/swagger-api/apidom/commit/c89cbadb00a0dadb08daf39f5be949bff67457f8)), closes [#4120](https://github.com/swagger-api/apidom/issues/4120)
35
+
36
+ # [1.0.0-alpha.2](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2024-05-20)
37
+
38
+ ### Features
39
+
40
+ - **ast:** add support for mutable node replacements ([#4121](https://github.com/swagger-api/apidom/issues/4121)) ([b37ecd2](https://github.com/swagger-api/apidom/commit/b37ecd2dba83aaa3813bb539ae64e98b290f0292)), closes [#4120](https://github.com/swagger-api/apidom/issues/4120)
41
+
6
42
  # [1.0.0-alpha.1](https://github.com/swagger-api/apidom/compare/v1.0.0-alpha.0...v1.0.0-alpha.1) (2024-05-15)
7
43
 
8
44
  **Note:** Version bump only for package @swagger-api/apidom-ast
@@ -57,7 +57,7 @@ const cloneNode = node => Object.create(Object.getPrototypeOf(node), Object.getO
57
57
  * parallel. Each visitor will be visited for each node before moving on.
58
58
  *
59
59
  * If a prior visitor edits a node, no following visitors will see that node.
60
- * `exposeEdits=true` can be used to exoise the edited node from the previous visitors.
60
+ * `exposeEdits=true` can be used to expose the edited node from the previous visitors.
61
61
  */
62
62
  exports.cloneNode = cloneNode;
63
63
  const mergeAll = (visitors, {
@@ -71,14 +71,21 @@ const mergeAll = (visitors, {
71
71
  const skipSymbol = Symbol('skip');
72
72
  const skipping = new Array(visitors.length).fill(skipSymbol);
73
73
  return {
74
- enter(node, ...rest) {
74
+ enter(node, key, parent, path, ancestors, link) {
75
75
  let currentNode = node;
76
76
  let hasChanged = false;
77
+ const linkProxy = {
78
+ ...link,
79
+ replaceWith(newNode, replacer) {
80
+ link.replaceWith(newNode, replacer);
81
+ currentNode = newNode;
82
+ }
83
+ };
77
84
  for (let i = 0; i < visitors.length; i += 1) {
78
85
  if (skipping[i] === skipSymbol) {
79
86
  const visitFn = visitFnGetter(visitors[i], nodeTypeGetter(currentNode), false);
80
87
  if (typeof visitFn === 'function') {
81
- const result = visitFn.call(visitors[i], currentNode, ...rest);
88
+ const result = visitFn.call(visitors[i], currentNode, key, parent, path, ancestors, linkProxy);
82
89
 
83
90
  // check if the visitor is async
84
91
  if (typeof (result == null ? void 0 : result.then) === 'function') {
@@ -88,7 +95,7 @@ const mergeAll = (visitors, {
88
95
  });
89
96
  }
90
97
  if (result === skipVisitingNodeSymbol) {
91
- skipping[i] = node;
98
+ skipping[i] = currentNode;
92
99
  } else if (result === breakSymbol) {
93
100
  skipping[i] = breakSymbol;
94
101
  } else if (result === deleteNodeSymbol) {
@@ -106,12 +113,20 @@ const mergeAll = (visitors, {
106
113
  }
107
114
  return hasChanged ? currentNode : undefined;
108
115
  },
109
- leave(node, ...rest) {
116
+ leave(node, key, parent, path, ancestors, link) {
117
+ let currentNode = node;
118
+ const linkProxy = {
119
+ ...link,
120
+ replaceWith(newNode, replacer) {
121
+ link.replaceWith(newNode, replacer);
122
+ currentNode = newNode;
123
+ }
124
+ };
110
125
  for (let i = 0; i < visitors.length; i += 1) {
111
126
  if (skipping[i] === skipSymbol) {
112
- const visitFn = visitFnGetter(visitors[i], nodeTypeGetter(node), true);
127
+ const visitFn = visitFnGetter(visitors[i], nodeTypeGetter(currentNode), true);
113
128
  if (typeof visitFn === 'function') {
114
- const result = visitFn.call(visitors[i], node, ...rest);
129
+ const result = visitFn.call(visitors[i], currentNode, key, parent, path, ancestors, linkProxy);
115
130
 
116
131
  // check if the visitor is async
117
132
  if (typeof (result == null ? void 0 : result.then) === 'function') {
@@ -126,7 +141,7 @@ const mergeAll = (visitors, {
126
141
  return result;
127
142
  }
128
143
  }
129
- } else if (skipping[i] === node) {
144
+ } else if (skipping[i] === currentNode) {
130
145
  skipping[i] = skipSymbol;
131
146
  }
132
147
  }
@@ -146,17 +161,24 @@ const mergeAllAsync = (visitors, {
146
161
  const skipSymbol = Symbol('skip');
147
162
  const skipping = new Array(visitors.length).fill(skipSymbol);
148
163
  return {
149
- async enter(node, ...rest) {
164
+ async enter(node, key, parent, path, ancestors, link) {
150
165
  let currentNode = node;
151
166
  let hasChanged = false;
167
+ const linkProxy = {
168
+ ...link,
169
+ replaceWith(newNode, replacer) {
170
+ link.replaceWith(newNode, replacer);
171
+ currentNode = newNode;
172
+ }
173
+ };
152
174
  for (let i = 0; i < visitors.length; i += 1) {
153
175
  if (skipping[i] === skipSymbol) {
154
176
  const visitFn = visitFnGetter(visitors[i], nodeTypeGetter(currentNode), false);
155
177
  if (typeof visitFn === 'function') {
156
178
  // eslint-disable-next-line no-await-in-loop
157
- const result = await visitFn.call(visitors[i], currentNode, ...rest);
179
+ const result = await visitFn.call(visitors[i], currentNode, key, parent, path, ancestors, linkProxy);
158
180
  if (result === skipVisitingNodeSymbol) {
159
- skipping[i] = node;
181
+ skipping[i] = currentNode;
160
182
  } else if (result === breakSymbol) {
161
183
  skipping[i] = breakSymbol;
162
184
  } else if (result === deleteNodeSymbol) {
@@ -174,20 +196,28 @@ const mergeAllAsync = (visitors, {
174
196
  }
175
197
  return hasChanged ? currentNode : undefined;
176
198
  },
177
- async leave(node, ...rest) {
199
+ async leave(node, key, parent, path, ancestors, link) {
200
+ let currentNode = node;
201
+ const linkProxy = {
202
+ ...link,
203
+ replaceWith(newNode, replacer) {
204
+ link.replaceWith(newNode, replacer);
205
+ currentNode = newNode;
206
+ }
207
+ };
178
208
  for (let i = 0; i < visitors.length; i += 1) {
179
209
  if (skipping[i] === skipSymbol) {
180
- const visitFn = visitFnGetter(visitors[i], nodeTypeGetter(node), true);
210
+ const visitFn = visitFnGetter(visitors[i], nodeTypeGetter(currentNode), true);
181
211
  if (typeof visitFn === 'function') {
182
212
  // eslint-disable-next-line no-await-in-loop
183
- const result = await visitFn.call(visitors[i], node, ...rest);
213
+ const result = await visitFn.call(visitors[i], currentNode, key, parent, path, ancestors, linkProxy);
184
214
  if (result === breakSymbol) {
185
215
  skipping[i] = breakSymbol;
186
216
  } else if (result !== undefined && result !== skipVisitingNodeSymbol) {
187
217
  return result;
188
218
  }
189
219
  }
190
- } else if (skipping[i] === node) {
220
+ } else if (skipping[i] === currentNode) {
191
221
  skipping[i] = skipSymbol;
192
222
  }
193
223
  }
@@ -383,8 +413,22 @@ visitor, {
383
413
  for (const [stateKey, stateValue] of Object.entries(state)) {
384
414
  visitor[stateKey] = stateValue;
385
415
  }
416
+ const link = {
417
+ // eslint-disable-next-line @typescript-eslint/no-loop-func
418
+ replaceWith(newNode, replacer) {
419
+ if (typeof replacer === 'function') {
420
+ replacer(newNode, node, key, parent, path, ancestors);
421
+ } else if (parent) {
422
+ parent[key] = newNode;
423
+ }
424
+ if (!isLeaving) {
425
+ node = newNode;
426
+ }
427
+ }
428
+ };
429
+
386
430
  // retrieve result
387
- result = visitFn.call(visitor, node, key, parent, path, ancestors);
431
+ result = visitFn.call(visitor, node, key, parent, path, ancestors, link);
388
432
  }
389
433
 
390
434
  // check if the visitor is async
@@ -542,9 +586,22 @@ visitor, {
542
586
  for (const [stateKey, stateValue] of Object.entries(state)) {
543
587
  visitor[stateKey] = stateValue;
544
588
  }
589
+ const link = {
590
+ // eslint-disable-next-line @typescript-eslint/no-loop-func
591
+ replaceWith(newNode, replacer) {
592
+ if (typeof replacer === 'function') {
593
+ replacer(newNode, node, key, parent, path, ancestors);
594
+ } else if (parent) {
595
+ parent[key] = newNode;
596
+ }
597
+ if (!isLeaving) {
598
+ node = newNode;
599
+ }
600
+ }
601
+ };
545
602
 
546
603
  // retrieve result
547
- result = await visitFn.call(visitor, node, key, parent, path, ancestors); // eslint-disable-line no-await-in-loop
604
+ result = await visitFn.call(visitor, node, key, parent, path, ancestors, link); // eslint-disable-line no-await-in-loop
548
605
  }
549
606
  if (result === breakSymbol) {
550
607
  break;