hermes-transform 0.5.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 +21 -0
  2. package/README.md +8 -0
  3. package/dist/detachedNode.js +128 -0
  4. package/dist/detachedNode.js.flow +113 -0
  5. package/dist/generated/TransformCloneSignatures.js.flow +19 -0
  6. package/dist/generated/TransformReplaceSignatures.js.flow +943 -0
  7. package/dist/generated/node-types.js +2071 -0
  8. package/dist/generated/node-types.js.flow +3149 -0
  9. package/dist/generated/special-case-node-types.js +178 -0
  10. package/dist/generated/special-case-node-types.js.flow +248 -0
  11. package/dist/getVisitorKeys.js +35 -0
  12. package/dist/getVisitorKeys.js.flow +31 -0
  13. package/dist/index.js +41 -0
  14. package/dist/index.js.flow +15 -0
  15. package/dist/transform/Errors.js +151 -0
  16. package/dist/transform/Errors.js.flow +17 -0
  17. package/dist/transform/MutationContext.js +94 -0
  18. package/dist/transform/MutationContext.js.flow +80 -0
  19. package/dist/transform/TransformContext.js +136 -0
  20. package/dist/transform/TransformContext.js.flow +378 -0
  21. package/dist/transform/comments/comments.js +140 -0
  22. package/dist/transform/comments/comments.js.flow +145 -0
  23. package/dist/transform/comments/prettier/README.md +6 -0
  24. package/dist/transform/comments/prettier/common/util.js +365 -0
  25. package/dist/transform/comments/prettier/common/util.js.flow +349 -0
  26. package/dist/transform/comments/prettier/language-js/comments.js +777 -0
  27. package/dist/transform/comments/prettier/language-js/comments.js.flow +950 -0
  28. package/dist/transform/comments/prettier/language-js/loc.js +41 -0
  29. package/dist/transform/comments/prettier/language-js/loc.js.flow +41 -0
  30. package/dist/transform/comments/prettier/language-js/printer-estree.js +31 -0
  31. package/dist/transform/comments/prettier/language-js/printer-estree.js.flow +37 -0
  32. package/dist/transform/comments/prettier/language-js/utils.js +131 -0
  33. package/dist/transform/comments/prettier/language-js/utils.js.flow +135 -0
  34. package/dist/transform/comments/prettier/main/comments.js +513 -0
  35. package/dist/transform/comments/prettier/main/comments.js.flow +436 -0
  36. package/dist/transform/comments/prettier/utils/get-last.js +15 -0
  37. package/dist/transform/comments/prettier/utils/get-last.js.flow +14 -0
  38. package/dist/transform/getTransformedAST.js +159 -0
  39. package/dist/transform/getTransformedAST.js.flow +128 -0
  40. package/dist/transform/mutations/AddLeadingComments.js +47 -0
  41. package/dist/transform/mutations/AddLeadingComments.js.flow +49 -0
  42. package/dist/transform/mutations/AddTrailingComments.js +47 -0
  43. package/dist/transform/mutations/AddTrailingComments.js.flow +49 -0
  44. package/dist/transform/mutations/CloneCommentsTo.js +46 -0
  45. package/dist/transform/mutations/CloneCommentsTo.js.flow +51 -0
  46. package/dist/transform/mutations/InsertStatement.js +92 -0
  47. package/dist/transform/mutations/InsertStatement.js.flow +113 -0
  48. package/dist/transform/mutations/RemoveComment.js +96 -0
  49. package/dist/transform/mutations/RemoveComment.js.flow +80 -0
  50. package/dist/transform/mutations/RemoveStatement.js +61 -0
  51. package/dist/transform/mutations/RemoveStatement.js.flow +68 -0
  52. package/dist/transform/mutations/ReplaceNode.js +96 -0
  53. package/dist/transform/mutations/ReplaceNode.js.flow +113 -0
  54. package/dist/transform/mutations/ReplaceStatementWithMany.js +81 -0
  55. package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +102 -0
  56. package/dist/transform/mutations/utils/arrayUtils.js +41 -0
  57. package/dist/transform/mutations/utils/arrayUtils.js.flow +35 -0
  58. package/dist/transform/mutations/utils/getStatementParent.js +147 -0
  59. package/dist/transform/mutations/utils/getStatementParent.js.flow +143 -0
  60. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js +53 -0
  61. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js.flow +50 -0
  62. package/dist/transform/transform.js +69 -0
  63. package/dist/transform/transform.js.flow +60 -0
  64. package/dist/traverse/NodeEventGenerator.js +427 -0
  65. package/dist/traverse/NodeEventGenerator.js.flow +406 -0
  66. package/dist/traverse/SafeEmitter.js +70 -0
  67. package/dist/traverse/SafeEmitter.js.flow +46 -0
  68. package/dist/traverse/SimpleTraverser.js +149 -0
  69. package/dist/traverse/SimpleTraverser.js.flow +109 -0
  70. package/dist/traverse/esquery.js +37 -0
  71. package/dist/traverse/esquery.js.flow +173 -0
  72. package/dist/traverse/traverse.js +139 -0
  73. package/dist/traverse/traverse.js.flow +149 -0
  74. package/package.json +22 -0
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ArrowFunctionExpression = ArrowFunctionExpression;
7
+ exports.BlockComment = BlockComment;
8
+ exports.BooleanLiteral = BooleanLiteral;
9
+ exports.Identifier = Identifier;
10
+ exports.LineComment = LineComment;
11
+ exports.NullLiteral = NullLiteral;
12
+ exports.NumericLiteral = NumericLiteral;
13
+ exports.RegExpLiteral = RegExpLiteral;
14
+ exports.StringLiteral = StringLiteral;
15
+ exports.TemplateElement = TemplateElement;
16
+
17
+ var _detachedNode = require("../detachedNode");
18
+
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({
39
+ type: 'ArrowFunctionExpression',
40
+ id: null,
41
+ // $FlowExpectedError[incompatible-use]
42
+ expression: props.body.type !== 'BlockStatement'
43
+ }, props));
44
+ (0, _detachedNode.setParentPointersInDirectChildren)(node);
45
+ return node;
46
+ } // pattern/flags are on a subobject in the estree spec, but are flat on the hermes types
47
+ // also the value is supposed to be a RegExp instance
48
+
49
+
50
+ function RegExpLiteral(_ref2) {
51
+ var pattern = _ref2.pattern,
52
+ flags = _ref2.flags,
53
+ parent = _ref2.parent;
54
+ var value = new RegExp(pattern, flags);
55
+ return (0, _detachedNode.detachedProps)(parent, {
56
+ type: 'Literal',
57
+ value: value,
58
+ raw: value.toString(),
59
+ regex: {
60
+ pattern: pattern,
61
+ flags: flags
62
+ }
63
+ });
64
+ } // raw/cooked are on a subobject in the estree spec, but are flat on the hermes types
65
+
66
+
67
+ function TemplateElement(_ref3) {
68
+ var tail = _ref3.tail,
69
+ parent = _ref3.parent,
70
+ value = _objectWithoutProperties(_ref3, _excluded2);
71
+
72
+ return (0, _detachedNode.detachedProps)(parent, {
73
+ type: 'TemplateElement',
74
+ tail: tail,
75
+ value: value
76
+ });
77
+ } // Identifier has a bunch of stuff that usually you don't want to provide - so we have
78
+ // this manual def to allow us to default some values
79
+
80
+
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({
90
+ type: 'Identifier',
91
+ optional: optional,
92
+ typeAnnotation: typeAnnotation
93
+ }, props));
94
+ (0, _detachedNode.setParentPointersInDirectChildren)(node);
95
+ return node;
96
+ } //
97
+ // Literals require a "raw" which is added by the estree transform, not hermes.
98
+ //
99
+
100
+
101
+ function BooleanLiteral(_ref5) {
102
+ var parent = _ref5.parent,
103
+ value = _ref5.value;
104
+ return (0, _detachedNode.detachedProps)(parent, {
105
+ type: 'Literal',
106
+ raw: value ? 'true' : 'false',
107
+ value: value
108
+ });
109
+ }
110
+
111
+ function NumericLiteral(_ref6) {
112
+ var _props$raw;
113
+
114
+ var parent = _ref6.parent,
115
+ props = _objectWithoutProperties(_ref6, _excluded4);
116
+
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
+ }));
122
+ }
123
+
124
+ function NullLiteral() {
125
+ var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
126
+ parent = _ref7.parent;
127
+
128
+ return (0, _detachedNode.detachedProps)(parent, {
129
+ type: 'Literal',
130
+ value: null,
131
+ raw: 'null'
132
+ });
133
+ }
134
+
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;
142
+
143
+ if (raw == null) {
144
+ if (hasSingleQuote && hasDoubleQuote) {
145
+ raw = "'".concat(value.replace(/'/g, "\\'"), "'");
146
+ } else if (hasSingleQuote) {
147
+ raw = "\"".concat(value, "\"");
148
+ } else {
149
+ raw = "'".concat(value, "'");
150
+ }
151
+ }
152
+
153
+ return (0, _detachedNode.detachedProps)(parent, {
154
+ type: 'Literal',
155
+ raw: raw,
156
+ value: value
157
+ });
158
+ }
159
+
160
+ function LineComment(_ref9) {
161
+ var value = _ref9.value;
162
+ // $FlowExpectedError[prop-missing]
163
+ // $FlowExpectedError[incompatible-return]
164
+ return (0, _detachedNode.detachedProps)(undefined, {
165
+ type: 'Line',
166
+ value: value
167
+ });
168
+ }
169
+
170
+ function BlockComment(_ref10) {
171
+ var value = _ref10.value;
172
+ // $FlowExpectedError[prop-missing]
173
+ // $FlowExpectedError[incompatible-return]
174
+ return (0, _detachedNode.detachedProps)(undefined, {
175
+ type: 'Block',
176
+ value: value
177
+ });
178
+ }
@@ -0,0 +1,248 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ /*
12
+ These are a number of special-case node creation functions that we can't auto-generate.
13
+ The list of exported functions here must be kept in sync with the `NODES_WITH_SPECIAL_HANDLING`
14
+ list in `scripts/genTransformNodeTypes` to ensure there's no duplicates
15
+ */
16
+
17
+ import type {
18
+ ESNode,
19
+ ArrowFunctionExpression as ArrowFunctionExpressionType,
20
+ RegExpLiteral as RegExpLiteralType,
21
+ TemplateElement as TemplateElementType,
22
+ Identifier as IdentifierType,
23
+ BooleanLiteral as BooleanLiteralType,
24
+ NumericLiteral as NumericLiteralType,
25
+ NullLiteral as NullLiteralType,
26
+ StringLiteral as StringLiteralType,
27
+ LineComment as LineCommentType,
28
+ BlockComment as BlockCommentType,
29
+ } from 'hermes-estree';
30
+ import type {DetachedNode} from '../detachedNode';
31
+
32
+ import {
33
+ detachedProps,
34
+ setParentPointersInDirectChildren,
35
+ } from '../detachedNode';
36
+
37
+ // hermes adds an `id` prop which is always null, and it adds an `expression`
38
+ // boolean which is true when the body isn't a BlockStatement.
39
+ // No need to make consumers set these
40
+ export type ArrowFunctionExpressionProps = {
41
+ +params: $ReadOnlyArray<
42
+ DetachedNode<ArrowFunctionExpressionType['params'][number]>,
43
+ >,
44
+ +body: DetachedNode<ArrowFunctionExpressionType['body']>,
45
+ +typeParameters?: ?DetachedNode<
46
+ ArrowFunctionExpressionType['typeParameters'],
47
+ >,
48
+ +returnType?: ?DetachedNode<ArrowFunctionExpressionType['returnType']>,
49
+ +predicate?: ?DetachedNode<ArrowFunctionExpressionType['predicate']>,
50
+ +async: ArrowFunctionExpressionType['async'],
51
+ };
52
+ export function ArrowFunctionExpression({
53
+ parent,
54
+ ...props
55
+ }: {
56
+ ...$ReadOnly<ArrowFunctionExpressionProps>,
57
+ +parent?: ESNode,
58
+ }): DetachedNode<ArrowFunctionExpressionType> {
59
+ const node = detachedProps<ArrowFunctionExpressionType>(parent, {
60
+ type: 'ArrowFunctionExpression',
61
+ id: null,
62
+ // $FlowExpectedError[incompatible-use]
63
+ expression: props.body.type !== 'BlockStatement',
64
+ ...props,
65
+ });
66
+ setParentPointersInDirectChildren(node);
67
+ return node;
68
+ }
69
+
70
+ // pattern/flags are on a subobject in the estree spec, but are flat on the hermes types
71
+ // also the value is supposed to be a RegExp instance
72
+ export type RegExpLiteralProps = {
73
+ +pattern: RegExpLiteralType['regex']['pattern'],
74
+ +flags: RegExpLiteralType['regex']['flags'],
75
+ };
76
+ export function RegExpLiteral({
77
+ pattern,
78
+ flags,
79
+ parent,
80
+ }: {
81
+ ...$ReadOnly<RegExpLiteralProps>,
82
+ +parent?: ESNode,
83
+ }): DetachedNode<RegExpLiteralType> {
84
+ const value = new RegExp(pattern, flags);
85
+ return detachedProps<RegExpLiteralType>(parent, {
86
+ type: 'Literal',
87
+ value,
88
+ raw: value.toString(),
89
+ regex: {
90
+ pattern,
91
+ flags,
92
+ },
93
+ });
94
+ }
95
+
96
+ // raw/cooked are on a subobject in the estree spec, but are flat on the hermes types
97
+ export type TemplateElementProps = {
98
+ +tail: TemplateElementType['tail'],
99
+ +cooked: TemplateElementType['value']['cooked'],
100
+ +raw: TemplateElementType['value']['raw'],
101
+ };
102
+ export function TemplateElement({
103
+ tail,
104
+ parent,
105
+ ...value
106
+ }: {
107
+ ...$ReadOnly<TemplateElementProps>,
108
+ +parent?: ESNode,
109
+ }): DetachedNode<TemplateElementType> {
110
+ return detachedProps<TemplateElementType>(parent, {
111
+ type: 'TemplateElement',
112
+ tail,
113
+ value,
114
+ });
115
+ }
116
+
117
+ // Identifier has a bunch of stuff that usually you don't want to provide - so we have
118
+ // this manual def to allow us to default some values
119
+ export type IdentifierProps = {
120
+ +name: IdentifierType['name'],
121
+ +typeAnnotation?: ?DetachedNode<IdentifierType['typeAnnotation']>,
122
+ +optional?: IdentifierType['optional'],
123
+ };
124
+ export function Identifier({
125
+ parent,
126
+ optional = false,
127
+ typeAnnotation = null,
128
+ ...props
129
+ }: {
130
+ ...$ReadOnly<IdentifierProps>,
131
+ +parent?: ESNode,
132
+ }): DetachedNode<IdentifierType> {
133
+ const node = detachedProps<IdentifierType>(parent, {
134
+ type: 'Identifier',
135
+ optional,
136
+ typeAnnotation,
137
+ ...props,
138
+ });
139
+ setParentPointersInDirectChildren(node);
140
+ return node;
141
+ }
142
+
143
+ //
144
+ // Literals require a "raw" which is added by the estree transform, not hermes.
145
+ //
146
+
147
+ export type BooleanLiteralProps = {
148
+ +value: BooleanLiteralType['value'],
149
+ };
150
+ export function BooleanLiteral({
151
+ parent,
152
+ value,
153
+ }: {
154
+ ...$ReadOnly<BooleanLiteralProps>,
155
+ +parent?: ESNode,
156
+ }): DetachedNode<BooleanLiteralType> {
157
+ return detachedProps<BooleanLiteralType>(parent, {
158
+ type: 'Literal',
159
+ raw: value ? 'true' : 'false',
160
+ value,
161
+ });
162
+ }
163
+
164
+ export type NumericLiteralProps = {
165
+ +value: NumericLiteralType['value'],
166
+ /**
167
+ * Only set this if you want to use a source-code representation like 1e100, 0x11, etc.
168
+ * By default "raw" will just be the exact number you've given.
169
+ */
170
+ +raw?: NumericLiteralType['raw'],
171
+ };
172
+ export function NumericLiteral({
173
+ parent,
174
+ ...props
175
+ }: {
176
+ ...$ReadOnly<NumericLiteralProps>,
177
+ +parent?: ESNode,
178
+ }): DetachedNode<NumericLiteralType> {
179
+ return detachedProps<NumericLiteralType>(parent, {
180
+ type: 'Literal',
181
+ ...props,
182
+ raw: props.raw ?? `${props.value}`,
183
+ });
184
+ }
185
+
186
+ export type NullLiteralProps = {};
187
+ export function NullLiteral({
188
+ parent,
189
+ }: {
190
+ +parent?: ESNode,
191
+ } = {}): DetachedNode<NullLiteralType> {
192
+ return detachedProps<NullLiteralType>(parent, {
193
+ type: 'Literal',
194
+ value: null,
195
+ raw: 'null',
196
+ });
197
+ }
198
+
199
+ export type StringLiteralProps = {
200
+ +value: StringLiteralType['value'],
201
+ +raw?: StringLiteralType['raw'],
202
+ };
203
+ export function StringLiteral({
204
+ parent,
205
+ raw: rawIn,
206
+ value,
207
+ }: {
208
+ ...$ReadOnly<StringLiteralProps>,
209
+ +parent?: ESNode,
210
+ }): DetachedNode<StringLiteralType> {
211
+ const hasSingleQuote = value.includes('"');
212
+ const hasDoubleQuote = value.includes("'");
213
+ let raw = rawIn;
214
+ if (raw == null) {
215
+ if (hasSingleQuote && hasDoubleQuote) {
216
+ raw = `'${value.replace(/'/g, "\\'")}'`;
217
+ } else if (hasSingleQuote) {
218
+ raw = `"${value}"`;
219
+ } else {
220
+ raw = `'${value}'`;
221
+ }
222
+ }
223
+ return detachedProps<StringLiteralType>(parent, {
224
+ type: 'Literal',
225
+ raw,
226
+ value,
227
+ });
228
+ }
229
+
230
+ export type LineCommentProps = {+value: string};
231
+ export function LineComment({value}: LineCommentProps): LineCommentType {
232
+ // $FlowExpectedError[prop-missing]
233
+ // $FlowExpectedError[incompatible-return]
234
+ return detachedProps<LineCommentType>(undefined, {
235
+ type: 'Line',
236
+ value,
237
+ });
238
+ }
239
+
240
+ export type BlockCommentProps = {+value: string};
241
+ export function BlockComment({value}: BlockCommentProps): BlockCommentType {
242
+ // $FlowExpectedError[prop-missing]
243
+ // $FlowExpectedError[incompatible-return]
244
+ return detachedProps<BlockCommentType>(undefined, {
245
+ type: 'Block',
246
+ value,
247
+ });
248
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ * @format
9
+ */
10
+ 'use strict';
11
+
12
+ Object.defineProperty(exports, "__esModule", {
13
+ value: true
14
+ });
15
+ exports.getVisitorKeys = getVisitorKeys;
16
+ exports.isNode = isNode;
17
+
18
+ var _hermesEslint = require("hermes-eslint");
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
+ function isNode(thing) {
23
+ return _typeof(thing) === 'object' && thing != null && typeof thing.type === 'string';
24
+ }
25
+
26
+ function getVisitorKeys(node) {
27
+ var keys = _hermesEslint.VisitorKeys[node.type];
28
+
29
+ if (keys == null) {
30
+ throw new Error("No visitor keys found for node type \"".concat(node.type, "\"."));
31
+ } // $FlowExpectedError[prop-missing]
32
+
33
+
34
+ return keys;
35
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ import type {ESNode} from 'hermes-estree';
14
+
15
+ import {VisitorKeys} from 'hermes-eslint';
16
+
17
+ export function isNode(thing: mixed): boolean %checks {
18
+ return (
19
+ typeof thing === 'object' && thing != null && typeof thing.type === 'string'
20
+ );
21
+ }
22
+
23
+ export function getVisitorKeys<T: ESNode>(node: T): $ReadOnlyArray<$Keys<T>> {
24
+ const keys = VisitorKeys[node.type];
25
+ if (keys == null) {
26
+ throw new Error(`No visitor keys found for node type "${node.type}".`);
27
+ }
28
+
29
+ // $FlowExpectedError[prop-missing]
30
+ return keys;
31
+ }
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ * @format
9
+ */
10
+ 'use strict';
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
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
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
+ });
30
+
31
+ var _traverse = require("./traverse/traverse");
32
+
33
+ var _transform = require("./transform/transform");
34
+
35
+ var _t = _interopRequireWildcard(require("./generated/node-types"));
36
+
37
+ exports.t = _t;
38
+
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); }
40
+
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; }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ export {traverse} from './traverse/traverse';
14
+ export {transform} from './transform/transform';
15
+ export * as t from './generated/node-types';