source: node_modules/estree-walker/src/walker.js

Last change on this file was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago

Initial commit

  • Property mode set to 100644
File size: 1.1 KB
Line 
1// @ts-check
2/** @typedef { import('estree').BaseNode} BaseNode */
3
4/** @typedef {{
5 skip: () => void;
6 remove: () => void;
7 replace: (node: BaseNode) => void;
8}} WalkerContext */
9
10export class WalkerBase {
11 constructor() {
12 /** @type {boolean} */
13 this.should_skip = false;
14
15 /** @type {boolean} */
16 this.should_remove = false;
17
18 /** @type {BaseNode | null} */
19 this.replacement = null;
20
21 /** @type {WalkerContext} */
22 this.context = {
23 skip: () => (this.should_skip = true),
24 remove: () => (this.should_remove = true),
25 replace: (node) => (this.replacement = node)
26 };
27 }
28
29 /**
30 *
31 * @param {any} parent
32 * @param {string} prop
33 * @param {number} index
34 * @param {BaseNode} node
35 */
36 replace(parent, prop, index, node) {
37 if (parent) {
38 if (index !== null) {
39 parent[prop][index] = node;
40 } else {
41 parent[prop] = node;
42 }
43 }
44 }
45
46 /**
47 *
48 * @param {any} parent
49 * @param {string} prop
50 * @param {number} index
51 */
52 remove(parent, prop, index) {
53 if (parent) {
54 if (index !== null) {
55 parent[prop].splice(index, 1);
56 } else {
57 delete parent[prop];
58 }
59 }
60 }
61}
Note: See TracBrowser for help on using the repository browser.