hermes-transform 0.5.0 → 0.8.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 (76) 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 +1728 -9
  5. package/dist/generated/TransformReplaceSignatures.js.flow +921 -780
  6. package/dist/generated/node-types.js +1099 -1156
  7. package/dist/generated/node-types.js.flow +77 -125
  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 +8 -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 +4 -3
  18. package/dist/transform/TransformContext.js +100 -58
  19. package/dist/transform/TransformContext.js.flow +277 -141
  20. package/dist/transform/comments/comments.js +127 -40
  21. package/dist/transform/comments/comments.js.flow +106 -29
  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 +81 -104
  37. package/dist/transform/getTransformedAST.js.flow +18 -13
  38. package/dist/transform/mutations/AddComments.js +43 -0
  39. package/dist/transform/mutations/AddComments.js.flow +50 -0
  40. package/dist/transform/mutations/CloneCommentsTo.js +16 -24
  41. package/dist/transform/mutations/CloneCommentsTo.js.flow +2 -3
  42. package/dist/transform/mutations/InsertStatement.js +28 -30
  43. package/dist/transform/mutations/InsertStatement.js.flow +7 -2
  44. package/dist/transform/mutations/RemoveComment.js +25 -43
  45. package/dist/transform/mutations/RemoveComment.js.flow +1 -1
  46. package/dist/transform/mutations/RemoveNode.js +192 -0
  47. package/dist/transform/mutations/RemoveNode.js.flow +290 -0
  48. package/dist/transform/mutations/RemoveStatement.js +7 -9
  49. package/dist/transform/mutations/RemoveStatement.js.flow +1 -1
  50. package/dist/transform/mutations/ReplaceNode.js +36 -44
  51. package/dist/transform/mutations/ReplaceNode.js.flow +1 -1
  52. package/dist/transform/mutations/ReplaceStatementWithMany.js +11 -13
  53. package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +1 -1
  54. package/dist/transform/mutations/utils/arrayUtils.js +16 -14
  55. package/dist/transform/mutations/utils/arrayUtils.js.flow +16 -1
  56. package/dist/transform/mutations/utils/getStatementParent.js +23 -28
  57. package/dist/transform/mutations/utils/getStatementParent.js.flow +2 -2
  58. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js +7 -24
  59. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js.flow +1 -1
  60. package/dist/transform/transform.js +58 -30
  61. package/dist/transform/transform.js.flow +51 -13
  62. package/dist/traverse/NodeEventGenerator.js +91 -165
  63. package/dist/traverse/NodeEventGenerator.js.flow +1 -1
  64. package/dist/traverse/SafeEmitter.js +20 -38
  65. package/dist/traverse/SafeEmitter.js.flow +1 -1
  66. package/dist/traverse/SimpleTraverser.js +67 -98
  67. package/dist/traverse/SimpleTraverser.js.flow +4 -1
  68. package/dist/traverse/esquery.js +6 -6
  69. package/dist/traverse/esquery.js.flow +1 -1
  70. package/dist/traverse/traverse.js +64 -52
  71. package/dist/traverse/traverse.js.flow +63 -10
  72. package/package.json +5 -3
  73. package/dist/transform/mutations/AddLeadingComments.js +0 -47
  74. package/dist/transform/mutations/AddLeadingComments.js.flow +0 -49
  75. package/dist/transform/mutations/AddTrailingComments.js +0 -47
  76. package/dist/transform/mutations/AddTrailingComments.js.flow +0 -49
@@ -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.
@@ -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,20 +8,21 @@
8
8
  */
9
9
  'use strict';
10
10
 
11
- var _require = require('../common/util.js'),
12
- isNonEmptyArray = _require.isNonEmptyArray;
11
+ const {
12
+ isNonEmptyArray
13
+ } = require('../common/util.js');
13
14
  /**
14
15
  * @typedef {import("./types/estree").Node} Node
15
16
  */
16
17
 
17
18
 
18
19
  function locStart(node, opts) {
19
- var _ref = opts || {},
20
- ignoreDecorators = _ref.ignoreDecorators; // Handle nodes with decorators. They should start at the first decorator
21
-
20
+ const {
21
+ ignoreDecorators
22
+ } = opts || {}; // Handle nodes with decorators. They should start at the first decorator
22
23
 
23
24
  if (!ignoreDecorators) {
24
- var decorators = node.declaration && node.declaration.decorators || node.decorators;
25
+ const decorators = node.declaration && node.declaration.decorators || node.decorators;
25
26
 
26
27
  if (isNonEmptyArray(decorators)) {
27
28
  return locStart(decorators[0]);
@@ -36,6 +37,6 @@ function locEnd(node) {
36
37
  }
37
38
 
38
39
  module.exports = {
39
- locStart: locStart,
40
- locEnd: locEnd
40
+ locStart,
41
+ locEnd
41
42
  };
@@ -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.
@@ -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,11 +8,12 @@
8
8
  */
9
9
  'use strict';
10
10
 
11
- var handleComments = require('./comments.js');
11
+ const handleComments = require('./comments.js');
12
12
 
13
- var _require = require('./utils.js'),
14
- isBlockComment = _require.isBlockComment,
15
- isLineComment = _require.isLineComment;
13
+ const {
14
+ isBlockComment,
15
+ isLineComment
16
+ } = require('./utils.js');
16
17
 
17
18
  function canAttachComment(node) {
18
19
  return node.type && !isBlockComment(node) && !isLineComment(node) && node.type !== 'EmptyStatement' && node.type !== 'TemplateElement' && node.type !== 'Import' && // `babel-ts` don't have similar node for `class Foo { bar() /* bat */; }`
@@ -20,7 +21,7 @@ function canAttachComment(node) {
20
21
  }
21
22
 
22
23
  module.exports = {
23
- canAttachComment: canAttachComment,
24
+ canAttachComment,
24
25
  handleComments: {
25
26
  avoidAstMutation: true,
26
27
  ownLine: handleComments.handleOwnLineComment,
@@ -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.
@@ -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.
@@ -12,18 +12,6 @@
12
12
  * @returns {boolean}
13
13
  */
14
14
 
15
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
16
-
17
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
18
-
19
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
20
-
21
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
22
-
23
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
24
-
25
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
26
-
27
15
  function isBlockComment(comment) {
28
16
  return comment.type === 'Block' || comment.type === 'CommentBlock' || // `meriyah`
29
17
  comment.type === 'MultiLine';
@@ -57,24 +45,24 @@ function isMemberExpression(node) {
57
45
  return node && (node.type === 'MemberExpression' || node.type === 'OptionalMemberExpression');
58
46
  }
59
47
 
60
- var functionParametersCache = new WeakMap();
48
+ const functionParametersCache = new WeakMap();
61
49
 
62
50
  function getFunctionParameters(node) {
63
51
  if (functionParametersCache.has(node)) {
64
52
  return functionParametersCache.get(node);
65
53
  }
66
54
 
67
- var parameters = [];
55
+ const parameters = [];
68
56
 
69
- if (node["this"]) {
70
- parameters.push(node["this"]);
57
+ if (node.this) {
58
+ parameters.push(node.this);
71
59
  } // `params` vs `parameters` - see https://github.com/babel/babel/issues/9231
72
60
 
73
61
 
74
62
  if (Array.isArray(node.parameters)) {
75
- parameters.push.apply(parameters, _toConsumableArray(node.parameters));
63
+ parameters.push(...node.parameters);
76
64
  } else if (Array.isArray(node.params)) {
77
- parameters.push.apply(parameters, _toConsumableArray(node.params));
65
+ parameters.push(...node.params);
78
66
  }
79
67
 
80
68
  if (node.rest) {
@@ -85,14 +73,14 @@ function getFunctionParameters(node) {
85
73
  return parameters;
86
74
  }
87
75
 
88
- var callArgumentsCache = new WeakMap();
76
+ const callArgumentsCache = new WeakMap();
89
77
 
90
78
  function getCallArguments(node) {
91
79
  if (callArgumentsCache.has(node)) {
92
80
  return callArgumentsCache.get(node);
93
81
  }
94
82
 
95
- var args = node.arguments;
83
+ let args = node.arguments;
96
84
 
97
85
  if (node.type === 'ImportExpression') {
98
86
  args = [node.source];
@@ -119,13 +107,13 @@ function isObjectProperty(node) {
119
107
  }
120
108
 
121
109
  module.exports = {
122
- getFunctionParameters: getFunctionParameters,
123
- getCallArguments: getCallArguments,
124
- isBlockComment: isBlockComment,
125
- isCallLikeExpression: isCallLikeExpression,
126
- isLineComment: isLineComment,
127
- isPrettierIgnoreComment: isPrettierIgnoreComment,
128
- isCallExpression: isCallExpression,
129
- isMemberExpression: isMemberExpression,
130
- isObjectProperty: isObjectProperty
110
+ getFunctionParameters,
111
+ getCallArguments,
112
+ isBlockComment,
113
+ isCallLikeExpression,
114
+ isLineComment,
115
+ isPrettierIgnoreComment,
116
+ isCallExpression,
117
+ isMemberExpression,
118
+ isObjectProperty
131
119
  };
@@ -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.