hermes-transform 0.5.0 → 0.6.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.
Files changed (74) hide show
  1. package/LICENSE +1 -1
  2. package/dist/detachedNode.js +25 -49
  3. package/dist/detachedNode.js.flow +3 -3
  4. package/dist/generated/TransformCloneSignatures.js.flow +1761 -9
  5. package/dist/generated/TransformReplaceSignatures.js.flow +936 -774
  6. package/dist/generated/node-types.js +1117 -1132
  7. package/dist/generated/node-types.js.flow +26 -1
  8. package/dist/generated/special-case-node-types.js +106 -85
  9. package/dist/generated/special-case-node-types.js.flow +28 -2
  10. package/dist/getVisitorKeys.js +4 -6
  11. package/dist/getVisitorKeys.js.flow +1 -1
  12. package/dist/index.js +13 -18
  13. package/dist/index.js.flow +7 -2
  14. package/dist/transform/Errors.js +8 -116
  15. package/dist/transform/Errors.js.flow +1 -1
  16. package/dist/transform/MutationContext.js +54 -67
  17. package/dist/transform/MutationContext.js.flow +1 -1
  18. package/dist/transform/TransformContext.js +106 -54
  19. package/dist/transform/TransformContext.js.flow +255 -121
  20. package/dist/transform/comments/comments.js +25 -25
  21. package/dist/transform/comments/comments.js.flow +1 -1
  22. package/dist/transform/comments/prettier/common/util.js +46 -47
  23. package/dist/transform/comments/prettier/common/util.js.flow +1 -1
  24. package/dist/transform/comments/prettier/language-js/comments.js +199 -216
  25. package/dist/transform/comments/prettier/language-js/comments.js.flow +1 -1
  26. package/dist/transform/comments/prettier/language-js/loc.js +10 -9
  27. package/dist/transform/comments/prettier/language-js/loc.js.flow +1 -1
  28. package/dist/transform/comments/prettier/language-js/printer-estree.js +7 -6
  29. package/dist/transform/comments/prettier/language-js/printer-estree.js.flow +1 -1
  30. package/dist/transform/comments/prettier/language-js/utils.js +18 -30
  31. package/dist/transform/comments/prettier/language-js/utils.js.flow +1 -1
  32. package/dist/transform/comments/prettier/main/comments.js +225 -298
  33. package/dist/transform/comments/prettier/main/comments.js.flow +1 -1
  34. package/dist/transform/comments/prettier/utils/get-last.js +2 -4
  35. package/dist/transform/comments/prettier/utils/get-last.js.flow +1 -1
  36. package/dist/transform/getTransformedAST.js +85 -101
  37. package/dist/transform/getTransformedAST.js.flow +7 -2
  38. package/dist/transform/mutations/AddLeadingComments.js +15 -22
  39. package/dist/transform/mutations/AddLeadingComments.js.flow +1 -1
  40. package/dist/transform/mutations/AddTrailingComments.js +15 -22
  41. package/dist/transform/mutations/AddTrailingComments.js.flow +1 -1
  42. package/dist/transform/mutations/CloneCommentsTo.js +16 -23
  43. package/dist/transform/mutations/CloneCommentsTo.js.flow +1 -1
  44. package/dist/transform/mutations/InsertStatement.js +27 -30
  45. package/dist/transform/mutations/InsertStatement.js.flow +1 -1
  46. package/dist/transform/mutations/RemoveComment.js +25 -43
  47. package/dist/transform/mutations/RemoveComment.js.flow +1 -1
  48. package/dist/transform/mutations/RemoveNode.js +185 -0
  49. package/dist/transform/mutations/RemoveNode.js.flow +279 -0
  50. package/dist/transform/mutations/RemoveStatement.js +7 -9
  51. package/dist/transform/mutations/RemoveStatement.js.flow +1 -1
  52. package/dist/transform/mutations/ReplaceNode.js +36 -44
  53. package/dist/transform/mutations/ReplaceNode.js.flow +1 -1
  54. package/dist/transform/mutations/ReplaceStatementWithMany.js +11 -13
  55. package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +1 -1
  56. package/dist/transform/mutations/utils/arrayUtils.js +2 -14
  57. package/dist/transform/mutations/utils/arrayUtils.js.flow +1 -1
  58. package/dist/transform/mutations/utils/getStatementParent.js +23 -28
  59. package/dist/transform/mutations/utils/getStatementParent.js.flow +2 -2
  60. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js +7 -24
  61. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js.flow +1 -1
  62. package/dist/transform/transform.js +20 -24
  63. package/dist/transform/transform.js.flow +12 -8
  64. package/dist/traverse/NodeEventGenerator.js +91 -165
  65. package/dist/traverse/NodeEventGenerator.js.flow +1 -1
  66. package/dist/traverse/SafeEmitter.js +20 -38
  67. package/dist/traverse/SafeEmitter.js.flow +1 -1
  68. package/dist/traverse/SimpleTraverser.js +67 -98
  69. package/dist/traverse/SimpleTraverser.js.flow +4 -1
  70. package/dist/traverse/esquery.js +6 -6
  71. package/dist/traverse/esquery.js.flow +1 -1
  72. package/dist/traverse/traverse.js +39 -51
  73. package/dist/traverse/traverse.js.flow +1 -1
  74. package/package.json +4 -3
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -8,6 +8,10 @@
8
8
  * @format
9
9
  */
10
10
 
11
+ // lint directives to let us do some basic validation of generated files
12
+ /* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
13
+ /* global $NonMaybeType, $Partial, $ReadOnly, $ReadOnlyArray */
14
+
11
15
  'use strict';
12
16
 
13
17
  import type {
@@ -19,6 +23,7 @@ import type {
19
23
  AssignmentExpression as AssignmentExpressionType,
20
24
  AssignmentPattern as AssignmentPatternType,
21
25
  AwaitExpression as AwaitExpressionType,
26
+ BigIntLiteralTypeAnnotation as BigIntLiteralTypeAnnotationType,
22
27
  BinaryExpression as BinaryExpressionType,
23
28
  BlockStatement as BlockStatementType,
24
29
  BooleanLiteralTypeAnnotation as BooleanLiteralTypeAnnotationType,
@@ -202,6 +207,10 @@ export type AwaitExpressionProps = {
202
207
  +argument: DetachedNode<AwaitExpressionType['argument']>,
203
208
  };
204
209
 
210
+ export type BigIntLiteralTypeAnnotationProps = {
211
+ +raw: BigIntLiteralTypeAnnotationType['raw'],
212
+ };
213
+
205
214
  export type BinaryExpressionProps = {
206
215
  +left: DetachedNode<BinaryExpressionType['left']>,
207
216
  +right: DetachedNode<BinaryExpressionType['right']>,
@@ -865,6 +874,7 @@ export type SpreadElementProps = {
865
874
 
866
875
  export type StringLiteralTypeAnnotationProps = {
867
876
  +value: StringLiteralTypeAnnotationType['value'],
877
+ +raw: StringLiteralTypeAnnotationType['raw'],
868
878
  };
869
879
 
870
880
  export type StringTypeAnnotationProps = {};
@@ -1106,6 +1116,21 @@ export function AwaitExpression({
1106
1116
  return node;
1107
1117
  }
1108
1118
 
1119
+ export function BigIntLiteralTypeAnnotation({
1120
+ parent,
1121
+ ...props
1122
+ }: {
1123
+ ...$ReadOnly<BigIntLiteralTypeAnnotationProps>,
1124
+ +parent?: ESNode,
1125
+ }): DetachedNode<BigIntLiteralTypeAnnotationType> {
1126
+ const node = detachedProps<BigIntLiteralTypeAnnotationType>(parent, {
1127
+ type: 'BigIntLiteralTypeAnnotation',
1128
+ ...props,
1129
+ });
1130
+ setParentPointersInDirectChildren(node);
1131
+ return node;
1132
+ }
1133
+
1109
1134
  export function BinaryExpression({
1110
1135
  parent,
1111
1136
  ...props
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ArrowFunctionExpression = ArrowFunctionExpression;
7
+ exports.BigIntLiteral = BigIntLiteral;
7
8
  exports.BlockComment = BlockComment;
8
9
  exports.BooleanLiteral = BooleanLiteral;
9
10
  exports.Identifier = Identifier;
@@ -16,81 +17,82 @@ exports.TemplateElement = TemplateElement;
16
17
 
17
18
  var _detachedNode = require("../detachedNode");
18
19
 
19
- var _excluded = ["parent"],
20
- _excluded2 = ["tail", "parent"],
21
- _excluded3 = ["parent", "optional", "typeAnnotation"],
22
- _excluded4 = ["parent"];
23
-
24
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
25
-
26
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
27
-
28
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
-
30
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
31
-
32
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
33
-
34
- function ArrowFunctionExpression(_ref) {
35
- var parent = _ref.parent,
36
- props = _objectWithoutProperties(_ref, _excluded);
37
-
38
- var node = (0, _detachedNode.detachedProps)(parent, _objectSpread({
20
+ /**
21
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
22
+ *
23
+ * This source code is licensed under the MIT license found in the
24
+ * LICENSE file in the root directory of this source tree.
25
+ *
26
+ *
27
+ * @format
28
+ */
29
+
30
+ /*
31
+ These are a number of special-case node creation functions that we can't auto-generate.
32
+ The list of exported functions here must be kept in sync with the `NODES_WITH_SPECIAL_HANDLING`
33
+ list in `scripts/genTransformNodeTypes` to ensure there's no duplicates
34
+ */
35
+ function ArrowFunctionExpression({
36
+ parent,
37
+ ...props
38
+ }) {
39
+ const node = (0, _detachedNode.detachedProps)(parent, {
39
40
  type: 'ArrowFunctionExpression',
40
41
  id: null,
41
42
  // $FlowExpectedError[incompatible-use]
42
- expression: props.body.type !== 'BlockStatement'
43
- }, props));
43
+ expression: props.body.type !== 'BlockStatement',
44
+ ...props
45
+ });
44
46
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
45
47
  return node;
46
48
  } // pattern/flags are on a subobject in the estree spec, but are flat on the hermes types
47
49
  // also the value is supposed to be a RegExp instance
48
50
 
49
51
 
50
- function RegExpLiteral(_ref2) {
51
- var pattern = _ref2.pattern,
52
- flags = _ref2.flags,
53
- parent = _ref2.parent;
54
- var value = new RegExp(pattern, flags);
52
+ function RegExpLiteral({
53
+ pattern,
54
+ flags,
55
+ parent
56
+ }) {
57
+ const value = new RegExp(pattern, flags);
55
58
  return (0, _detachedNode.detachedProps)(parent, {
56
59
  type: 'Literal',
57
- value: value,
60
+ value,
58
61
  raw: value.toString(),
59
62
  regex: {
60
- pattern: pattern,
61
- flags: flags
63
+ pattern,
64
+ flags
62
65
  }
63
66
  });
64
67
  } // raw/cooked are on a subobject in the estree spec, but are flat on the hermes types
65
68
 
66
69
 
67
- function TemplateElement(_ref3) {
68
- var tail = _ref3.tail,
69
- parent = _ref3.parent,
70
- value = _objectWithoutProperties(_ref3, _excluded2);
71
-
70
+ function TemplateElement({
71
+ tail,
72
+ parent,
73
+ ...value
74
+ }) {
72
75
  return (0, _detachedNode.detachedProps)(parent, {
73
76
  type: 'TemplateElement',
74
- tail: tail,
75
- value: value
77
+ tail,
78
+ value
76
79
  });
77
80
  } // Identifier has a bunch of stuff that usually you don't want to provide - so we have
78
81
  // this manual def to allow us to default some values
79
82
 
80
83
 
81
- function Identifier(_ref4) {
82
- var parent = _ref4.parent,
83
- _ref4$optional = _ref4.optional,
84
- optional = _ref4$optional === void 0 ? false : _ref4$optional,
85
- _ref4$typeAnnotation = _ref4.typeAnnotation,
86
- typeAnnotation = _ref4$typeAnnotation === void 0 ? null : _ref4$typeAnnotation,
87
- props = _objectWithoutProperties(_ref4, _excluded3);
88
-
89
- var node = (0, _detachedNode.detachedProps)(parent, _objectSpread({
84
+ function Identifier({
85
+ parent,
86
+ optional = false,
87
+ typeAnnotation = null,
88
+ ...props
89
+ }) {
90
+ const node = (0, _detachedNode.detachedProps)(parent, {
90
91
  type: 'Identifier',
91
- optional: optional,
92
- typeAnnotation: typeAnnotation
93
- }, props));
92
+ optional,
93
+ typeAnnotation,
94
+ ...props
95
+ });
94
96
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
95
97
  return node;
96
98
  } //
@@ -98,33 +100,49 @@ function Identifier(_ref4) {
98
100
  //
99
101
 
100
102
 
101
- function BooleanLiteral(_ref5) {
102
- var parent = _ref5.parent,
103
- value = _ref5.value;
103
+ function BigIntLiteral({
104
+ parent,
105
+ ...props
106
+ }) {
107
+ var _props$raw;
108
+
109
+ const node = (0, _detachedNode.detachedProps)(parent, {
110
+ type: 'Literal',
111
+ ...props,
112
+ raw: (_props$raw = props.raw) != null ? _props$raw : `${props.value}n`,
113
+ bigint: `${props.value}`
114
+ });
115
+ (0, _detachedNode.setParentPointersInDirectChildren)(node);
116
+ return node;
117
+ }
118
+
119
+ function BooleanLiteral({
120
+ parent,
121
+ value
122
+ }) {
104
123
  return (0, _detachedNode.detachedProps)(parent, {
105
124
  type: 'Literal',
106
125
  raw: value ? 'true' : 'false',
107
- value: value
126
+ value
108
127
  });
109
128
  }
110
129
 
111
- function NumericLiteral(_ref6) {
112
- var _props$raw;
113
-
114
- var parent = _ref6.parent,
115
- props = _objectWithoutProperties(_ref6, _excluded4);
130
+ function NumericLiteral({
131
+ parent,
132
+ ...props
133
+ }) {
134
+ var _props$raw2;
116
135
 
117
- return (0, _detachedNode.detachedProps)(parent, _objectSpread(_objectSpread({
118
- type: 'Literal'
119
- }, props), {}, {
120
- raw: (_props$raw = props.raw) !== null && _props$raw !== void 0 ? _props$raw : "".concat(props.value)
121
- }));
136
+ return (0, _detachedNode.detachedProps)(parent, {
137
+ type: 'Literal',
138
+ ...props,
139
+ raw: (_props$raw2 = props.raw) != null ? _props$raw2 : `${props.value}`
140
+ });
122
141
  }
123
142
 
124
- function NullLiteral() {
125
- var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
126
- parent = _ref7.parent;
127
-
143
+ function NullLiteral({
144
+ parent
145
+ } = {}) {
128
146
  return (0, _detachedNode.detachedProps)(parent, {
129
147
  type: 'Literal',
130
148
  value: null,
@@ -132,47 +150,50 @@ function NullLiteral() {
132
150
  });
133
151
  }
134
152
 
135
- function StringLiteral(_ref8) {
136
- var parent = _ref8.parent,
137
- rawIn = _ref8.raw,
138
- value = _ref8.value;
139
- var hasSingleQuote = value.includes('"');
140
- var hasDoubleQuote = value.includes("'");
141
- var raw = rawIn;
153
+ function StringLiteral({
154
+ parent,
155
+ raw: rawIn,
156
+ value
157
+ }) {
158
+ const hasSingleQuote = value.includes('"');
159
+ const hasDoubleQuote = value.includes("'");
160
+ let raw = rawIn;
142
161
 
143
162
  if (raw == null) {
144
163
  if (hasSingleQuote && hasDoubleQuote) {
145
- raw = "'".concat(value.replace(/'/g, "\\'"), "'");
164
+ raw = `'${value.replace(/'/g, "\\'")}'`;
146
165
  } else if (hasSingleQuote) {
147
- raw = "\"".concat(value, "\"");
166
+ raw = `"${value}"`;
148
167
  } else {
149
- raw = "'".concat(value, "'");
168
+ raw = `'${value}'`;
150
169
  }
151
170
  }
152
171
 
153
172
  return (0, _detachedNode.detachedProps)(parent, {
154
173
  type: 'Literal',
155
- raw: raw,
156
- value: value
174
+ raw,
175
+ value
157
176
  });
158
177
  }
159
178
 
160
- function LineComment(_ref9) {
161
- var value = _ref9.value;
179
+ function LineComment({
180
+ value
181
+ }) {
162
182
  // $FlowExpectedError[prop-missing]
163
183
  // $FlowExpectedError[incompatible-return]
164
184
  return (0, _detachedNode.detachedProps)(undefined, {
165
185
  type: 'Line',
166
- value: value
186
+ value
167
187
  });
168
188
  }
169
189
 
170
- function BlockComment(_ref10) {
171
- var value = _ref10.value;
190
+ function BlockComment({
191
+ value
192
+ }) {
172
193
  // $FlowExpectedError[prop-missing]
173
194
  // $FlowExpectedError[incompatible-return]
174
195
  return (0, _detachedNode.detachedProps)(undefined, {
175
196
  type: 'Block',
176
- value: value
197
+ value
177
198
  });
178
199
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -20,6 +20,7 @@ import type {
20
20
  RegExpLiteral as RegExpLiteralType,
21
21
  TemplateElement as TemplateElementType,
22
22
  Identifier as IdentifierType,
23
+ BigIntLiteral as BigIntLiteralType,
23
24
  BooleanLiteral as BooleanLiteralType,
24
25
  NumericLiteral as NumericLiteralType,
25
26
  NullLiteral as NullLiteralType,
@@ -144,6 +145,31 @@ export function Identifier({
144
145
  // Literals require a "raw" which is added by the estree transform, not hermes.
145
146
  //
146
147
 
148
+ export type BigIntLiteralProps = {
149
+ +value: $FlowFixMe /* bigint | null */,
150
+ /**
151
+ * Only set this if you want to use a source-code representation like 1_1n, etc.
152
+ * By default "raw" will just be the exact number you've given.
153
+ */
154
+ +raw?: NumericLiteralType['raw'],
155
+ };
156
+ export function BigIntLiteral({
157
+ parent,
158
+ ...props
159
+ }: {
160
+ ...$ReadOnly<BigIntLiteralProps>,
161
+ +parent?: ESNode,
162
+ }): DetachedNode<BigIntLiteralType> {
163
+ const node = detachedProps<BigIntLiteralType>(parent, {
164
+ type: 'Literal',
165
+ ...props,
166
+ raw: props.raw ?? `${props.value}n`,
167
+ bigint: `${props.value}`,
168
+ });
169
+ setParentPointersInDirectChildren(node);
170
+ return node;
171
+ }
172
+
147
173
  export type BooleanLiteralProps = {
148
174
  +value: BooleanLiteralType['value'],
149
175
  };
@@ -164,7 +190,7 @@ export function BooleanLiteral({
164
190
  export type NumericLiteralProps = {
165
191
  +value: NumericLiteralType['value'],
166
192
  /**
167
- * Only set this if you want to use a source-code representation like 1e100, 0x11, etc.
193
+ * Only set this if you want to use a source-code representation like 1e100, 0x11, 1_1, etc.
168
194
  * By default "raw" will just be the exact number you've given.
169
195
  */
170
196
  +raw?: NumericLiteralType['raw'],
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -17,17 +17,15 @@ exports.isNode = isNode;
17
17
 
18
18
  var _hermesEslint = require("hermes-eslint");
19
19
 
20
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
21
-
22
20
  function isNode(thing) {
23
- return _typeof(thing) === 'object' && thing != null && typeof thing.type === 'string';
21
+ return typeof thing === 'object' && thing != null && typeof thing.type === 'string';
24
22
  }
25
23
 
26
24
  function getVisitorKeys(node) {
27
- var keys = _hermesEslint.VisitorKeys[node.type];
25
+ const keys = _hermesEslint.VisitorKeys[node.type];
28
26
 
29
27
  if (keys == null) {
30
- throw new Error("No visitor keys found for node type \"".concat(node.type, "\"."));
28
+ throw new Error(`No visitor keys found for node type "${node.type}".`);
31
29
  } // $FlowExpectedError[prop-missing]
32
30
 
33
31
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -9,33 +9,28 @@
9
9
  */
10
10
  'use strict';
11
11
 
12
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
13
-
14
12
  Object.defineProperty(exports, "__esModule", {
15
13
  value: true
16
14
  });
17
- exports.t = void 0;
18
- Object.defineProperty(exports, "transform", {
19
- enumerable: true,
20
- get: function get() {
21
- return _transform.transform;
22
- }
23
- });
24
- Object.defineProperty(exports, "traverse", {
25
- enumerable: true,
26
- get: function get() {
27
- return _traverse.traverse;
28
- }
29
- });
15
+ exports.traverseWithContext = exports.traverse = exports.transform = exports.t = exports.SimpleTraverser = void 0;
16
+
17
+ var _SimpleTraverser = require("./traverse/SimpleTraverser");
18
+
19
+ exports.SimpleTraverser = _SimpleTraverser.SimpleTraverser;
30
20
 
31
21
  var _traverse = require("./traverse/traverse");
32
22
 
23
+ exports.traverse = _traverse.traverse;
24
+ exports.traverseWithContext = _traverse.traverseWithContext;
25
+
33
26
  var _transform = require("./transform/transform");
34
27
 
28
+ exports.transform = _transform.transform;
29
+
35
30
  var _t = _interopRequireWildcard(require("./generated/node-types"));
36
31
 
37
32
  exports.t = _t;
38
33
 
39
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
34
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
40
35
 
41
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
36
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -10,6 +10,11 @@
10
10
 
11
11
  'use strict';
12
12
 
13
- export {traverse} from './traverse/traverse';
13
+ export type {TraversalContext, Visitor} from './traverse/traverse';
14
+ export type {TransformVisitor} from './transform/transform';
15
+ export type {DetachedNode} from './detachedNode';
16
+
17
+ export {SimpleTraverser} from './traverse/SimpleTraverser';
18
+ export {traverse, traverseWithContext} from './traverse/traverse';
14
19
  export {transform} from './transform/transform';
15
20
  export * as t from './generated/node-types';
@@ -1,36 +1,12 @@
1
1
  "use strict";
2
2
 
3
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
-
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.UnexpectedTransformationState = exports.NodeIsMutatedError = exports.NodeIsDeletedError = exports.InvalidStatementError = exports.InvalidReplacementError = exports.InvalidRemovalError = exports.InvalidInsertionError = void 0;
9
7
 
10
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
-
12
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
13
-
14
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
15
-
16
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
17
-
18
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
19
-
20
- function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
21
-
22
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
23
-
24
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
25
-
26
- function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
27
-
28
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
29
-
30
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
31
-
32
8
  /**
33
- * Copyright (c) Facebook, Inc. and its affiliates.
9
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
34
10
  *
35
11
  * This source code is licensed under the MIT license found in the
36
12
  * LICENSE file in the root directory of this source tree.
@@ -38,114 +14,30 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
38
14
  *
39
15
  * @format
40
16
  */
41
- var NodeIsDeletedError = /*#__PURE__*/function (_Error) {
42
- _inherits(NodeIsDeletedError, _Error);
43
-
44
- var _super = _createSuper(NodeIsDeletedError);
45
-
46
- function NodeIsDeletedError() {
47
- _classCallCheck(this, NodeIsDeletedError);
48
-
49
- return _super.apply(this, arguments);
50
- }
51
-
52
- return NodeIsDeletedError;
53
- }( /*#__PURE__*/_wrapNativeSuper(Error));
17
+ class NodeIsDeletedError extends Error {}
54
18
 
55
19
  exports.NodeIsDeletedError = NodeIsDeletedError;
56
20
 
57
- var NodeIsMutatedError = /*#__PURE__*/function (_Error2) {
58
- _inherits(NodeIsMutatedError, _Error2);
59
-
60
- var _super2 = _createSuper(NodeIsMutatedError);
61
-
62
- function NodeIsMutatedError() {
63
- _classCallCheck(this, NodeIsMutatedError);
64
-
65
- return _super2.apply(this, arguments);
66
- }
67
-
68
- return NodeIsMutatedError;
69
- }( /*#__PURE__*/_wrapNativeSuper(Error));
21
+ class NodeIsMutatedError extends Error {}
70
22
 
71
23
  exports.NodeIsMutatedError = NodeIsMutatedError;
72
24
 
73
- var InvalidInsertionError = /*#__PURE__*/function (_Error3) {
74
- _inherits(InvalidInsertionError, _Error3);
75
-
76
- var _super3 = _createSuper(InvalidInsertionError);
77
-
78
- function InvalidInsertionError() {
79
- _classCallCheck(this, InvalidInsertionError);
80
-
81
- return _super3.apply(this, arguments);
82
- }
83
-
84
- return InvalidInsertionError;
85
- }( /*#__PURE__*/_wrapNativeSuper(Error));
25
+ class InvalidInsertionError extends Error {}
86
26
 
87
27
  exports.InvalidInsertionError = InvalidInsertionError;
88
28
 
89
- var UnexpectedTransformationState = /*#__PURE__*/function (_Error4) {
90
- _inherits(UnexpectedTransformationState, _Error4);
91
-
92
- var _super4 = _createSuper(UnexpectedTransformationState);
93
-
94
- function UnexpectedTransformationState() {
95
- _classCallCheck(this, UnexpectedTransformationState);
96
-
97
- return _super4.apply(this, arguments);
98
- }
99
-
100
- return UnexpectedTransformationState;
101
- }( /*#__PURE__*/_wrapNativeSuper(Error));
29
+ class UnexpectedTransformationState extends Error {}
102
30
 
103
31
  exports.UnexpectedTransformationState = UnexpectedTransformationState;
104
32
 
105
- var InvalidStatementError = /*#__PURE__*/function (_Error5) {
106
- _inherits(InvalidStatementError, _Error5);
107
-
108
- var _super5 = _createSuper(InvalidStatementError);
109
-
110
- function InvalidStatementError() {
111
- _classCallCheck(this, InvalidStatementError);
112
-
113
- return _super5.apply(this, arguments);
114
- }
115
-
116
- return InvalidStatementError;
117
- }( /*#__PURE__*/_wrapNativeSuper(Error));
33
+ class InvalidStatementError extends Error {}
118
34
 
119
35
  exports.InvalidStatementError = InvalidStatementError;
120
36
 
121
- var InvalidRemovalError = /*#__PURE__*/function (_Error6) {
122
- _inherits(InvalidRemovalError, _Error6);
123
-
124
- var _super6 = _createSuper(InvalidRemovalError);
125
-
126
- function InvalidRemovalError() {
127
- _classCallCheck(this, InvalidRemovalError);
128
-
129
- return _super6.apply(this, arguments);
130
- }
131
-
132
- return InvalidRemovalError;
133
- }( /*#__PURE__*/_wrapNativeSuper(Error));
37
+ class InvalidRemovalError extends Error {}
134
38
 
135
39
  exports.InvalidRemovalError = InvalidRemovalError;
136
40
 
137
- var InvalidReplacementError = /*#__PURE__*/function (_Error7) {
138
- _inherits(InvalidReplacementError, _Error7);
139
-
140
- var _super7 = _createSuper(InvalidReplacementError);
141
-
142
- function InvalidReplacementError() {
143
- _classCallCheck(this, InvalidReplacementError);
144
-
145
- return _super7.apply(this, arguments);
146
- }
147
-
148
- return InvalidReplacementError;
149
- }( /*#__PURE__*/_wrapNativeSuper(Error));
41
+ class InvalidReplacementError extends Error {}
150
42
 
151
43
  exports.InvalidReplacementError = InvalidReplacementError;