@swagger-api/apidom-ast 0.82.2 → 0.84.0

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,20 @@
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
+ # [0.84.0](https://github.com/swagger-api/apidom/compare/v0.83.0...v0.84.0) (2023-11-24)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **ast:** remove redundant cycle detection ([#3411](https://github.com/swagger-api/apidom/issues/3411)) ([a8106de](https://github.com/swagger-api/apidom/commit/a8106deef0d70e23daa878437a47e58eebd89e3f))
11
+
12
+ ### Features
13
+
14
+ - **ast:** see edits by the following merged visitors ([#3412](https://github.com/swagger-api/apidom/issues/3412)) ([6499557](https://github.com/swagger-api/apidom/commit/64995573f5df1f7f291c20833cf274173f6a7bac))
15
+
16
+ # [0.83.0](https://github.com/swagger-api/apidom/compare/v0.82.2...v0.83.0) (2023-11-07)
17
+
18
+ **Note:** Version bump only for package @swagger-api/apidom-ast
19
+
6
20
  ## [0.82.2](https://github.com/swagger-api/apidom/compare/v0.82.1...v0.82.2) (2023-11-03)
7
21
 
8
22
  ### Bug Fixes
@@ -57,46 +57,61 @@ 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
61
  */
61
62
  exports.cloneNode = cloneNode;
62
63
  const mergeAll = (visitors, {
63
64
  visitFnGetter = getVisitFn,
64
- nodeTypeGetter = getNodeType
65
+ nodeTypeGetter = getNodeType,
66
+ breakSymbol = BREAK,
67
+ deleteNodeSymbol = null,
68
+ skipVisitingNodeSymbol = false,
69
+ exposeEdits = false
65
70
  } = {}) => {
66
- const skipping = new Array(visitors.length).fill(null);
71
+ const skipSymbol = Symbol('skip');
72
+ const skipping = new Array(visitors.length).fill(skipSymbol);
67
73
  return {
68
74
  enter(node, ...rest) {
75
+ let currentNode = node;
76
+ let hasChanged = false;
69
77
  for (let i = 0; i < visitors.length; i += 1) {
70
- if (skipping[i] === null) {
71
- const fn = visitFnGetter(visitors[i], nodeTypeGetter(node), /* isLeaving */false);
72
- if (typeof fn === 'function') {
73
- const result = fn.call(visitors[i], node, ...rest);
74
- if (result === false) {
78
+ if (skipping[i] === skipSymbol) {
79
+ const visitFn = visitFnGetter(visitors[i], nodeTypeGetter(currentNode), false);
80
+ if (typeof visitFn === 'function') {
81
+ const result = visitFn.call(visitors[i], currentNode, ...rest);
82
+ if (result === skipVisitingNodeSymbol) {
75
83
  skipping[i] = node;
76
- } else if (result === BREAK) {
77
- skipping[i] = BREAK;
78
- } else if (result !== undefined) {
84
+ } else if (result === breakSymbol) {
85
+ skipping[i] = breakSymbol;
86
+ } else if (result === deleteNodeSymbol) {
79
87
  return result;
88
+ } else if (result !== undefined) {
89
+ if (exposeEdits) {
90
+ currentNode = result;
91
+ hasChanged = true;
92
+ } else {
93
+ return result;
94
+ }
80
95
  }
81
96
  }
82
97
  }
83
98
  }
84
- return undefined;
99
+ return hasChanged ? currentNode : undefined;
85
100
  },
86
101
  leave(node, ...rest) {
87
102
  for (let i = 0; i < visitors.length; i += 1) {
88
- if (skipping[i] === null) {
89
- const fn = visitFnGetter(visitors[i], nodeTypeGetter(node), /* isLeaving */true);
90
- if (typeof fn === 'function') {
91
- const result = fn.call(visitors[i], node, ...rest);
92
- if (result === BREAK) {
93
- skipping[i] = BREAK;
94
- } else if (result !== undefined && result !== false) {
103
+ if (skipping[i] === skipSymbol) {
104
+ const visitFn = visitFnGetter(visitors[i], nodeTypeGetter(node), true);
105
+ if (typeof visitFn === 'function') {
106
+ const result = visitFn.call(visitors[i], node, ...rest);
107
+ if (result === breakSymbol) {
108
+ skipping[i] = breakSymbol;
109
+ } else if (result !== undefined && result !== skipVisitingNodeSymbol) {
95
110
  return result;
96
111
  }
97
112
  }
98
113
  } else if (skipping[i] === node) {
99
- skipping[i] = null;
114
+ skipping[i] = skipSymbol;
100
115
  }
101
116
  }
102
117
  return undefined;
@@ -104,7 +119,7 @@ const mergeAll = (visitors, {
104
119
  };
105
120
  };
106
121
 
107
- /* eslint-disable no-continue, no-nested-ternary, no-param-reassign */
122
+ /* eslint-disable no-continue, no-param-reassign */
108
123
  /**
109
124
  * visit() will walk through an AST using a preorder depth first traversal, calling
110
125
  * the visitor's enter function at each node in the traversal, and calling the
@@ -270,9 +285,6 @@ visitor, {
270
285
  }
271
286
  path.push(key);
272
287
  }
273
- if (ancestors.includes(node)) {
274
- continue;
275
- }
276
288
  let result;
277
289
  if (!Array.isArray(node)) {
278
290
  if (!nodePredicate(node)) {