@babel/traverse 7.0.0-beta.5 → 7.0.0-beta.53

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.

Potentially problematic release.


This version of @babel/traverse might be problematic. Click here for more details.

package/README.md CHANGED
@@ -1,33 +1,19 @@
1
1
  # @babel/traverse
2
2
 
3
- > @babel/traverse maintains the overall tree state, and is responsible for replacing, removing, and adding nodes.
3
+ > The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes
4
+
5
+ See our website [@babel/traverse](https://babeljs.io/docs/en/next/babel-traverse.html) for more information or the [issues](https://github.com/babel/babel/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3A%22pkg%3A%20traverse%22+is%3Aopen) associated with this package.
4
6
 
5
7
  ## Install
6
8
 
9
+ Using npm:
10
+
7
11
  ```sh
8
- $ npm install --save @babel/traverse
12
+ npm install --save-dev @babel/traverse
9
13
  ```
10
14
 
11
- ## Usage
12
-
13
- We can use it alongside Babylon to traverse and update nodes:
14
-
15
- ```js
16
- import * as babylon from "babylon";
17
- import traverse from "@babel/traverse";
15
+ or using yarn:
18
16
 
19
- const code = `function square(n) {
20
- return n * n;
21
- }`;
22
-
23
- const ast = babylon.parse(code);
24
-
25
- traverse(ast, {
26
- enter(path) {
27
- if (path.isIdentifier({ name: "n" })) {
28
- path.node.name = "x";
29
- }
30
- }
31
- });
17
+ ```sh
18
+ yarn add @babel/traverse --dev
32
19
  ```
33
- [:book: **Read the full docs here**](https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md#babel-traverse)
package/lib/cache.js CHANGED
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
 
3
- exports.__esModule = true;
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
4
6
  exports.clear = clear;
5
7
  exports.clearPath = clearPath;
6
8
  exports.clearScope = clearScope;
7
9
  exports.scope = exports.path = void 0;
8
- var path = new WeakMap();
10
+ let path = new WeakMap();
9
11
  exports.path = path;
10
- var scope = new WeakMap();
12
+ let scope = new WeakMap();
11
13
  exports.scope = scope;
12
14
 
13
15
  function clear() {
package/lib/context.js CHANGED
@@ -1,71 +1,62 @@
1
1
  "use strict";
2
2
 
3
- exports.__esModule = true;
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
4
6
  exports.default = void 0;
5
7
 
6
- var _path4 = _interopRequireDefault(require("./path"));
8
+ var _path = _interopRequireDefault(require("./path"));
7
9
 
8
- var t = _interopRequireWildcard(require("@babel/types"));
10
+ function t() {
11
+ const data = _interopRequireWildcard(require("@babel/types"));
9
12
 
10
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
13
+ t = function () {
14
+ return data;
15
+ };
16
+
17
+ return data;
18
+ }
19
+
20
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
11
21
 
12
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
23
 
14
- var testing = process.env.NODE_ENV === "test";
24
+ const testing = process.env.NODE_ENV === "test";
15
25
 
16
- var TraversalContext = function () {
17
- function TraversalContext(scope, opts, state, parentPath) {
18
- Object.defineProperty(this, "queue", {
19
- configurable: true,
20
- enumerable: true,
21
- writable: true,
22
- value: null
23
- });
26
+ class TraversalContext {
27
+ constructor(scope, opts, state, parentPath) {
28
+ this.queue = null;
24
29
  this.parentPath = parentPath;
25
30
  this.scope = scope;
26
31
  this.state = state;
27
32
  this.opts = opts;
28
33
  }
29
34
 
30
- var _proto = TraversalContext.prototype;
31
-
32
- _proto.shouldVisit = function shouldVisit(node) {
33
- var opts = this.opts;
35
+ shouldVisit(node) {
36
+ const opts = this.opts;
34
37
  if (opts.enter || opts.exit) return true;
35
38
  if (opts[node.type]) return true;
36
- var keys = t.VISITOR_KEYS[node.type];
39
+ const keys = t().VISITOR_KEYS[node.type];
37
40
  if (!keys || !keys.length) return false;
38
41
 
39
- for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
40
- var _ref;
41
-
42
- if (_isArray) {
43
- if (_i >= _iterator.length) break;
44
- _ref = _iterator[_i++];
45
- } else {
46
- _i = _iterator.next();
47
- if (_i.done) break;
48
- _ref = _i.value;
49
- }
50
-
51
- var _key = _ref;
52
- if (node[_key]) return true;
42
+ for (const key of keys) {
43
+ if (node[key]) return true;
53
44
  }
54
45
 
55
46
  return false;
56
- };
47
+ }
57
48
 
58
- _proto.create = function create(node, obj, key, listKey) {
59
- return _path4.default.get({
49
+ create(node, obj, key, listKey) {
50
+ return _path.default.get({
60
51
  parentPath: this.parentPath,
61
52
  parent: node,
62
53
  container: obj,
63
54
  key: key,
64
- listKey: listKey
55
+ listKey
65
56
  });
66
- };
57
+ }
67
58
 
68
- _proto.maybeQueue = function maybeQueue(path, notPriority) {
59
+ maybeQueue(path, notPriority) {
69
60
  if (this.trap) {
70
61
  throw new Error("Infinite cycle detected");
71
62
  }
@@ -77,14 +68,14 @@ var TraversalContext = function () {
77
68
  this.priorityQueue.push(path);
78
69
  }
79
70
  }
80
- };
71
+ }
81
72
 
82
- _proto.visitMultiple = function visitMultiple(container, parent, listKey) {
73
+ visitMultiple(container, parent, listKey) {
83
74
  if (container.length === 0) return false;
84
- var queue = [];
75
+ const queue = [];
85
76
 
86
- for (var key = 0; key < container.length; key++) {
87
- var node = container[key];
77
+ for (let key = 0; key < container.length; key++) {
78
+ const node = container[key];
88
79
 
89
80
  if (node && this.shouldVisit(node)) {
90
81
  queue.push(this.create(parent, container, key, listKey));
@@ -92,52 +83,39 @@ var TraversalContext = function () {
92
83
  }
93
84
 
94
85
  return this.visitQueue(queue);
95
- };
86
+ }
96
87
 
97
- _proto.visitSingle = function visitSingle(node, key) {
88
+ visitSingle(node, key) {
98
89
  if (this.shouldVisit(node[key])) {
99
90
  return this.visitQueue([this.create(node, node, key)]);
100
91
  } else {
101
92
  return false;
102
93
  }
103
- };
94
+ }
104
95
 
105
- _proto.visitQueue = function visitQueue(queue) {
96
+ visitQueue(queue) {
106
97
  this.queue = queue;
107
98
  this.priorityQueue = [];
108
- var visited = [];
109
- var stop = false;
99
+ const visited = [];
100
+ let stop = false;
110
101
 
111
- for (var _iterator2 = queue, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
112
- var _ref2;
102
+ for (const path of queue) {
103
+ path.resync();
113
104
 
114
- if (_isArray2) {
115
- if (_i2 >= _iterator2.length) break;
116
- _ref2 = _iterator2[_i2++];
117
- } else {
118
- _i2 = _iterator2.next();
119
- if (_i2.done) break;
120
- _ref2 = _i2.value;
105
+ if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
106
+ path.pushContext(this);
121
107
  }
122
108
 
123
- var _path2 = _ref2;
124
-
125
- _path2.resync();
126
-
127
- if (_path2.contexts.length === 0 || _path2.contexts[_path2.contexts.length - 1] !== this) {
128
- _path2.pushContext(this);
129
- }
130
-
131
- if (_path2.key === null) continue;
109
+ if (path.key === null) continue;
132
110
 
133
111
  if (testing && queue.length >= 10000) {
134
112
  this.trap = true;
135
113
  }
136
114
 
137
- if (visited.indexOf(_path2.node) >= 0) continue;
138
- visited.push(_path2.node);
115
+ if (visited.indexOf(path.node) >= 0) continue;
116
+ visited.push(path.node);
139
117
 
140
- if (_path2.visit()) {
118
+ if (path.visit()) {
141
119
  stop = true;
142
120
  break;
143
121
  }
@@ -150,29 +128,16 @@ var TraversalContext = function () {
150
128
  }
151
129
  }
152
130
 
153
- for (var _iterator3 = queue, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
154
- var _ref3;
155
-
156
- if (_isArray3) {
157
- if (_i3 >= _iterator3.length) break;
158
- _ref3 = _iterator3[_i3++];
159
- } else {
160
- _i3 = _iterator3.next();
161
- if (_i3.done) break;
162
- _ref3 = _i3.value;
163
- }
164
-
165
- var _path3 = _ref3;
166
-
167
- _path3.popContext();
131
+ for (const path of queue) {
132
+ path.popContext();
168
133
  }
169
134
 
170
135
  this.queue = null;
171
136
  return stop;
172
- };
137
+ }
173
138
 
174
- _proto.visit = function visit(node, key) {
175
- var nodes = node[key];
139
+ visit(node, key) {
140
+ const nodes = node[key];
176
141
  if (!nodes) return false;
177
142
 
178
143
  if (Array.isArray(nodes)) {
@@ -180,9 +145,8 @@ var TraversalContext = function () {
180
145
  } else {
181
146
  return this.visitSingle(node, key);
182
147
  }
183
- };
148
+ }
184
149
 
185
- return TraversalContext;
186
- }();
150
+ }
187
151
 
188
152
  exports.default = TraversalContext;
package/lib/hub.js CHANGED
@@ -1,10 +1,15 @@
1
1
  "use strict";
2
2
 
3
- exports.__esModule = true;
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
4
6
  exports.default = void 0;
5
7
 
6
- var Hub = function Hub(file) {
7
- this.file = file;
8
- };
8
+ class Hub {
9
+ constructor(file) {
10
+ this.file = file;
11
+ }
12
+
13
+ }
9
14
 
10
15
  exports.default = Hub;
package/lib/index.js CHANGED
@@ -1,22 +1,24 @@
1
1
  "use strict";
2
2
 
3
- exports.__esModule = true;
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
4
6
  exports.default = traverse;
5
7
  Object.defineProperty(exports, "NodePath", {
6
8
  enumerable: true,
7
- get: function get() {
9
+ get: function () {
8
10
  return _path.default;
9
11
  }
10
12
  });
11
13
  Object.defineProperty(exports, "Scope", {
12
14
  enumerable: true,
13
- get: function get() {
15
+ get: function () {
14
16
  return _scope.default;
15
17
  }
16
18
  });
17
19
  Object.defineProperty(exports, "Hub", {
18
20
  enumerable: true,
19
- get: function get() {
21
+ get: function () {
20
22
  return _hub.default;
21
23
  }
22
24
  });
@@ -28,9 +30,25 @@ var visitors = _interopRequireWildcard(require("./visitors"));
28
30
 
29
31
  exports.visitors = visitors;
30
32
 
31
- var _includes = _interopRequireDefault(require("lodash/includes"));
33
+ function _includes() {
34
+ const data = _interopRequireDefault(require("lodash/includes"));
35
+
36
+ _includes = function () {
37
+ return data;
38
+ };
39
+
40
+ return data;
41
+ }
42
+
43
+ function t() {
44
+ const data = _interopRequireWildcard(require("@babel/types"));
32
45
 
33
- var t = _interopRequireWildcard(require("@babel/types"));
46
+ t = function () {
47
+ return data;
48
+ };
49
+
50
+ return data;
51
+ }
34
52
 
35
53
  var cache = _interopRequireWildcard(require("./cache"));
36
54
 
@@ -40,7 +58,7 @@ var _scope = _interopRequireDefault(require("./scope"));
40
58
 
41
59
  var _hub = _interopRequireDefault(require("./hub"));
42
60
 
43
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
61
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
44
62
 
45
63
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
46
64
 
@@ -50,7 +68,7 @@ function traverse(parent, opts, scope, state, parentPath) {
50
68
 
51
69
  if (!opts.noScope && !scope) {
52
70
  if (parent.type !== "Program" && parent.type !== "File") {
53
- throw new Error("You must pass a scope and parentPath unless traversing a Program/File. " + ("Instead of that you tried to traverse a " + parent.type + " node without ") + "passing scope and parentPath.");
71
+ throw new Error("You must pass a scope and parentPath unless traversing a Program/File. " + `Instead of that you tried to traverse a ${parent.type} node without ` + "passing scope and parentPath.");
54
72
  }
55
73
  }
56
74
 
@@ -61,44 +79,29 @@ function traverse(parent, opts, scope, state, parentPath) {
61
79
  traverse.visitors = visitors;
62
80
  traverse.verify = visitors.verify;
63
81
  traverse.explode = visitors.explode;
64
- traverse.NodePath = require("./path");
65
- traverse.Scope = require("./scope");
66
- traverse.Hub = require("./hub");
67
82
 
68
83
  traverse.cheap = function (node, enter) {
69
- return t.traverseFast(node, enter);
84
+ return t().traverseFast(node, enter);
70
85
  };
71
86
 
72
87
  traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
73
- var keys = t.VISITOR_KEYS[node.type];
88
+ const keys = t().VISITOR_KEYS[node.type];
74
89
  if (!keys) return;
75
- var context = new _context.default(scope, opts, state, parentPath);
76
-
77
- for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
78
- var _ref;
79
-
80
- if (_isArray) {
81
- if (_i >= _iterator.length) break;
82
- _ref = _iterator[_i++];
83
- } else {
84
- _i = _iterator.next();
85
- if (_i.done) break;
86
- _ref = _i.value;
87
- }
90
+ const context = new _context.default(scope, opts, state, parentPath);
88
91
 
89
- var _key = _ref;
90
- if (skipKeys && skipKeys[_key]) continue;
91
- if (context.visit(node, _key)) return;
92
+ for (const key of keys) {
93
+ if (skipKeys && skipKeys[key]) continue;
94
+ if (context.visit(node, key)) return;
92
95
  }
93
96
  };
94
97
 
95
98
  traverse.clearNode = function (node, opts) {
96
- t.removeProperties(node, opts);
99
+ t().removeProperties(node, opts);
97
100
  cache.path.delete(node);
98
101
  };
99
102
 
100
103
  traverse.removeProperties = function (tree, opts) {
101
- t.traverseFast(tree, traverse.clearNode, opts);
104
+ t().traverseFast(tree, traverse.clearNode, opts);
102
105
  return tree;
103
106
  };
104
107
 
@@ -110,9 +113,9 @@ function hasBlacklistedType(path, state) {
110
113
  }
111
114
 
112
115
  traverse.hasType = function (tree, type, blacklistTypes) {
113
- if ((0, _includes.default)(blacklistTypes, tree.type)) return false;
116
+ if ((0, _includes().default)(blacklistTypes, tree.type)) return false;
114
117
  if (tree.type === type) return true;
115
- var state = {
118
+ const state = {
116
119
  has: false,
117
120
  type: type
118
121
  };
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
 
3
- exports.__esModule = true;
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
4
6
  exports.findParent = findParent;
5
7
  exports.find = find;
6
8
  exports.getFunctionParent = getFunctionParent;
@@ -12,16 +14,24 @@ exports.isAncestor = isAncestor;
12
14
  exports.isDescendant = isDescendant;
13
15
  exports.inType = inType;
14
16
 
15
- var t = _interopRequireWildcard(require("@babel/types"));
17
+ function t() {
18
+ const data = _interopRequireWildcard(require("@babel/types"));
19
+
20
+ t = function () {
21
+ return data;
22
+ };
23
+
24
+ return data;
25
+ }
16
26
 
17
27
  var _index = _interopRequireDefault(require("./index"));
18
28
 
19
29
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
30
 
21
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
31
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
22
32
 
23
33
  function findParent(callback) {
24
- var path = this;
34
+ let path = this;
25
35
 
26
36
  while (path = path.parentPath) {
27
37
  if (callback(path)) return path;
@@ -31,7 +41,7 @@ function findParent(callback) {
31
41
  }
32
42
 
33
43
  function find(callback) {
34
- var path = this;
44
+ let path = this;
35
45
 
36
46
  do {
37
47
  if (callback(path)) return path;
@@ -41,13 +51,11 @@ function find(callback) {
41
51
  }
42
52
 
43
53
  function getFunctionParent() {
44
- return this.findParent(function (p) {
45
- return p.isFunction();
46
- });
54
+ return this.findParent(p => p.isFunction());
47
55
  }
48
56
 
49
57
  function getStatementParent() {
50
- var path = this;
58
+ let path = this;
51
59
 
52
60
  do {
53
61
  if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
@@ -66,13 +74,11 @@ function getStatementParent() {
66
74
 
67
75
  function getEarliestCommonAncestorFrom(paths) {
68
76
  return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {
69
- var earliest;
70
- var keys = t.VISITOR_KEYS[deepest.type];
71
- var _arr = ancestries;
77
+ let earliest;
78
+ const keys = t().VISITOR_KEYS[deepest.type];
72
79
 
73
- for (var _i = 0; _i < _arr.length; _i++) {
74
- var ancestry = _arr[_i];
75
- var path = ancestry[i + 1];
80
+ for (const ancestry of ancestries) {
81
+ const path = ancestry[i + 1];
76
82
 
77
83
  if (!earliest) {
78
84
  earliest = path;
@@ -86,8 +92,8 @@ function getEarliestCommonAncestorFrom(paths) {
86
92
  }
87
93
  }
88
94
 
89
- var earliestKeyIndex = keys.indexOf(earliest.parentKey);
90
- var currentKeyIndex = keys.indexOf(path.parentKey);
95
+ const earliestKeyIndex = keys.indexOf(earliest.parentKey);
96
+ const currentKeyIndex = keys.indexOf(path.parentKey);
91
97
 
92
98
  if (earliestKeyIndex > currentKeyIndex) {
93
99
  earliest = path;
@@ -99,8 +105,6 @@ function getEarliestCommonAncestorFrom(paths) {
99
105
  }
100
106
 
101
107
  function getDeepestCommonAncestorFrom(paths, filter) {
102
- var _this = this;
103
-
104
108
  if (!paths.length) {
105
109
  return this;
106
110
  }
@@ -109,14 +113,14 @@ function getDeepestCommonAncestorFrom(paths, filter) {
109
113
  return paths[0];
110
114
  }
111
115
 
112
- var minDepth = Infinity;
113
- var lastCommonIndex, lastCommon;
114
- var ancestries = paths.map(function (path) {
115
- var ancestry = [];
116
+ let minDepth = Infinity;
117
+ let lastCommonIndex, lastCommon;
118
+ const ancestries = paths.map(path => {
119
+ const ancestry = [];
116
120
 
117
121
  do {
118
122
  ancestry.unshift(path);
119
- } while ((path = path.parentPath) && path !== _this);
123
+ } while ((path = path.parentPath) && path !== this);
120
124
 
121
125
  if (ancestry.length < minDepth) {
122
126
  minDepth = ancestry.length;
@@ -124,15 +128,12 @@ function getDeepestCommonAncestorFrom(paths, filter) {
124
128
 
125
129
  return ancestry;
126
130
  });
127
- var first = ancestries[0];
128
-
129
- depthLoop: for (var i = 0; i < minDepth; i++) {
130
- var shouldMatch = first[i];
131
- var _arr2 = ancestries;
131
+ const first = ancestries[0];
132
132
 
133
- for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
134
- var ancestry = _arr2[_i2];
133
+ depthLoop: for (let i = 0; i < minDepth; i++) {
134
+ const shouldMatch = first[i];
135
135
 
136
+ for (const ancestry of ancestries) {
136
137
  if (ancestry[i] !== shouldMatch) {
137
138
  break depthLoop;
138
139
  }
@@ -154,8 +155,8 @@ function getDeepestCommonAncestorFrom(paths, filter) {
154
155
  }
155
156
 
156
157
  function getAncestry() {
157
- var path = this;
158
- var paths = [];
158
+ let path = this;
159
+ const paths = [];
159
160
 
160
161
  do {
161
162
  paths.push(path);
@@ -169,19 +170,14 @@ function isAncestor(maybeDescendant) {
169
170
  }
170
171
 
171
172
  function isDescendant(maybeAncestor) {
172
- return !!this.findParent(function (parent) {
173
- return parent === maybeAncestor;
174
- });
173
+ return !!this.findParent(parent => parent === maybeAncestor);
175
174
  }
176
175
 
177
176
  function inType() {
178
- var path = this;
177
+ let path = this;
179
178
 
180
179
  while (path) {
181
- var _arr3 = arguments;
182
-
183
- for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
184
- var type = _arr3[_i3];
180
+ for (const type of arguments) {
185
181
  if (path.node.type === type) return true;
186
182
  }
187
183
 
@@ -1,25 +1,35 @@
1
1
  "use strict";
2
2
 
3
- exports.__esModule = true;
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
4
6
  exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
5
7
  exports.addComment = addComment;
6
8
  exports.addComments = addComments;
7
9
 
8
- var t = _interopRequireWildcard(require("@babel/types"));
10
+ function t() {
11
+ const data = _interopRequireWildcard(require("@babel/types"));
9
12
 
10
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
13
+ t = function () {
14
+ return data;
15
+ };
16
+
17
+ return data;
18
+ }
19
+
20
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
11
21
 
12
22
  function shareCommentsWithSiblings() {
13
23
  if (typeof this.key === "string") return;
14
- var node = this.node;
24
+ const node = this.node;
15
25
  if (!node) return;
16
- var trailing = node.trailingComments;
17
- var leading = node.leadingComments;
26
+ const trailing = node.trailingComments;
27
+ const leading = node.leadingComments;
18
28
  if (!trailing && !leading) return;
19
- var prev = this.getSibling(this.key - 1);
20
- var next = this.getSibling(this.key + 1);
21
- var hasPrev = Boolean(prev.node);
22
- var hasNext = Boolean(next.node);
29
+ const prev = this.getSibling(this.key - 1);
30
+ const next = this.getSibling(this.key + 1);
31
+ const hasPrev = Boolean(prev.node);
32
+ const hasNext = Boolean(next.node);
23
33
 
24
34
  if (hasPrev && hasNext) {} else if (hasPrev) {
25
35
  prev.addComments("trailing", trailing);
@@ -29,9 +39,9 @@ function shareCommentsWithSiblings() {
29
39
  }
30
40
 
31
41
  function addComment(type, content, line) {
32
- t.addComment(this.node, type, content, line);
42
+ t().addComment(this.node, type, content, line);
33
43
  }
34
44
 
35
45
  function addComments(type, comments) {
36
- t.addComments(this.node, type, comments);
46
+ t().addComments(this.node, type, comments);
37
47
  }