@uwdata/mosaic-sql 0.16.1 → 0.16.2
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/dist/types/visit/rewrite.d.ts +1 -1
- package/package.json +2 -2
- package/src/visit/rewrite.js +22 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Rewrite a SQL expression, based on a map of nodes to replace.
|
|
3
|
-
* This method
|
|
3
|
+
* This method copies nodes as needed; it does not modify the input node.
|
|
4
4
|
* @param {ExprNode} node The root AST node of the expression.
|
|
5
5
|
* @param {Map<ExprNode, ExprNode>} map The rewrite map.
|
|
6
6
|
* When encountered, key nodes are replaced by value nodes.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uwdata/mosaic-sql",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"description": "SQL query construction and analysis.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sql",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
"tsc": "tsc -p jsconfig.json",
|
|
28
28
|
"prepublishOnly": "npm run test && npm run lint && npm run build"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "26d2719f4bcab471d2831145e1f03f39f3509869"
|
|
31
31
|
}
|
package/src/visit/rewrite.js
CHANGED
|
@@ -4,7 +4,7 @@ import { recurse } from './recurse.js';
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Rewrite a SQL expression, based on a map of nodes to replace.
|
|
7
|
-
* This method
|
|
7
|
+
* This method copies nodes as needed; it does not modify the input node.
|
|
8
8
|
* @param {ExprNode} node The root AST node of the expression.
|
|
9
9
|
* @param {Map<ExprNode, ExprNode>} map The rewrite map.
|
|
10
10
|
* When encountered, key nodes are replaced by value nodes.
|
|
@@ -16,18 +16,30 @@ export function rewrite(node, map) {
|
|
|
16
16
|
} else if (isNode(node)) {
|
|
17
17
|
const props = recurse[node.type];
|
|
18
18
|
const n = props?.length ?? 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
if (n > 0) {
|
|
20
|
+
node = cloneNode(node);
|
|
21
|
+
for (let i = 0; i < n; ++i) {
|
|
22
|
+
const prop = props[i];
|
|
23
|
+
const child = node[prop];
|
|
24
|
+
if (Array.isArray(child)) {
|
|
25
|
+
const m = child.length;
|
|
26
|
+
for (let j = 0; j < m; ++j) {
|
|
27
|
+
child[j] = rewrite(child[j], map);
|
|
28
|
+
}
|
|
29
|
+
} else if (child) {
|
|
30
|
+
node[prop] = rewrite(child, map);
|
|
26
31
|
}
|
|
27
|
-
} else if (child) {
|
|
28
|
-
node[prop] = rewrite(child, map);
|
|
29
32
|
}
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
return node;
|
|
33
36
|
}
|
|
37
|
+
|
|
38
|
+
// TODO: consider typed node.clone() methods
|
|
39
|
+
function cloneNode(node) {
|
|
40
|
+
const clone = new node.constructor();
|
|
41
|
+
for (const key in node) {
|
|
42
|
+
clone[key] = node[key];
|
|
43
|
+
}
|
|
44
|
+
return clone;
|
|
45
|
+
}
|