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.
@@ -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,8 +8,6 @@
8
8
  */
9
9
  'use strict';
10
10
 
11
- var getLast = function getLast(arr) {
12
- return arr[arr.length - 1];
13
- };
11
+ const getLast = arr => arr[arr.length - 1];
14
12
 
15
13
  module.exports = getLast;
@@ -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.
@@ -36,123 +36,107 @@ var _InsertStatement = require("./mutations/InsertStatement");
36
36
 
37
37
  var _RemoveComment = require("./mutations/RemoveComment");
38
38
 
39
+ var _RemoveNode = require("./mutations/RemoveNode");
40
+
39
41
  var _RemoveStatement = require("./mutations/RemoveStatement");
40
42
 
41
43
  var _ReplaceNode = require("./mutations/ReplaceNode");
42
44
 
43
45
  var _ReplaceStatementWithMany = require("./mutations/ReplaceStatementWithMany");
44
46
 
45
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
46
-
47
- 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); }
48
-
49
- 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; }
50
-
51
47
  function getTransformedAST(code, visitors) {
52
- var _parseForESLint = (0, _hermesEslint.parseForESLint)(code, {
48
+ const {
49
+ ast,
50
+ scopeManager
51
+ } = (0, _hermesEslint.parseForESLint)(code, {
53
52
  sourceType: 'module'
54
- }),
55
- ast = _parseForESLint.ast,
56
- scopeManager = _parseForESLint.scopeManager; // attach comments before mutation. this will ensure that as nodes are
53
+ }); // attach comments before mutation. this will ensure that as nodes are
57
54
  // cloned / moved around - comments remain in the correct place with respect to the node
58
55
 
59
-
60
56
  (0, _comments.attachComments)(ast.comments, ast, code); // traverse the AST and colllect the mutations
61
57
 
62
- var transformContext = (0, _TransformContext.getTransformContext)();
63
- (0, _traverse.traverseWithContext)(ast, scopeManager, function () {
64
- return transformContext;
65
- }, visitors); // apply the mutations to the AST
66
-
67
- var mutationContext = new _MutationContext.MutationContext(code);
68
- var removeCommentMutations = [];
69
-
70
- var _iterator = _createForOfIteratorHelper(transformContext.mutations),
71
- _step;
72
-
73
- try {
74
- var _loop = function _loop() {
75
- var mutation = _step.value;
76
-
77
- var mutationRoot = function () {
78
- switch (mutation.type) {
79
- case 'insertStatement':
80
- {
81
- return (0, _InsertStatement.performInsertStatementMutation)(mutationContext, mutation);
82
- }
83
-
84
- case 'replaceNode':
85
- {
86
- return (0, _ReplaceNode.performReplaceNodeMutation)(mutationContext, mutation);
87
- }
88
-
89
- case 'replaceStatementWithMany':
90
- {
91
- return (0, _ReplaceStatementWithMany.performReplaceStatementWithManyMutation)(mutationContext, mutation);
92
- }
93
-
94
- case 'removeStatement':
95
- {
96
- return (0, _RemoveStatement.performRemoveStatementMutation)(mutationContext, mutation);
97
- }
98
-
99
- case 'removeComment':
100
- {
101
- // these are handled later
102
- removeCommentMutations.push(mutation);
103
- return null;
104
- }
105
-
106
- case 'addLeadingComments':
107
- {
108
- return (0, _AddLeadingComments.performAddLeadingCommentsMutation)(mutationContext, mutation);
109
- }
110
-
111
- case 'addTrailingComments':
112
- {
113
- return (0, _AddTrailingComments.performAddTrailingCommentsMutation)(mutationContext, mutation);
114
- }
115
-
116
- case 'cloneCommentsTo':
117
- {
118
- return (0, _CloneCommentsTo.performCloneCommentsToMutation)(mutationContext, mutation);
119
- }
120
- }
121
- }(); // ensure the subtree's parent pointers are correct
122
- // this is required for two reasons:
123
- // 1) The userland transform is just JS - so there's nothing stopping them
124
- // from doing anything dodgy. The flow types have some enforcement, but
125
- // ofc that can just be ignored with a suppression.
126
- // 2) Shallow clones are a necessary evil in the transform because they
127
- // allow codemods to do simple changes to just one node without the
128
- // weight that comes with deeply cloning the entire AST.
129
- // However we can't update the parent pointers of the cloned node's
130
- // children until the mutation step or else we would be mutating
131
- // real AST nodes and potentially break the traverse step.
132
- //
133
- // Being strict here just helps us ensure we keep everything in sync
134
-
135
-
136
- if (mutationRoot) {
137
- (0, _detachedNode.updateAllParentPointers)(mutationRoot);
58
+ const transformContext = (0, _TransformContext.getTransformContext)(code);
59
+ (0, _traverse.traverseWithContext)(ast, scopeManager, () => transformContext, visitors); // apply the mutations to the AST
60
+
61
+ const mutationContext = new _MutationContext.MutationContext(code);
62
+ const removeCommentMutations = [];
63
+
64
+ for (const mutation of transformContext.mutations) {
65
+ const mutationRoot = (() => {
66
+ switch (mutation.type) {
67
+ case 'insertStatement':
68
+ {
69
+ return (0, _InsertStatement.performInsertStatementMutation)(mutationContext, mutation);
70
+ }
71
+
72
+ case 'replaceNode':
73
+ {
74
+ return (0, _ReplaceNode.performReplaceNodeMutation)(mutationContext, mutation);
75
+ }
76
+
77
+ case 'replaceStatementWithMany':
78
+ {
79
+ return (0, _ReplaceStatementWithMany.performReplaceStatementWithManyMutation)(mutationContext, mutation);
80
+ }
81
+
82
+ case 'removeNode':
83
+ {
84
+ return (0, _RemoveNode.performRemoveNodeMutation)(mutationContext, mutation);
85
+ }
86
+
87
+ case 'removeStatement':
88
+ {
89
+ return (0, _RemoveStatement.performRemoveStatementMutation)(mutationContext, mutation);
90
+ }
91
+
92
+ case 'removeComment':
93
+ {
94
+ // these are handled later
95
+ removeCommentMutations.push(mutation);
96
+ return null;
97
+ }
98
+
99
+ case 'addLeadingComments':
100
+ {
101
+ return (0, _AddLeadingComments.performAddLeadingCommentsMutation)(mutationContext, mutation);
102
+ }
103
+
104
+ case 'addTrailingComments':
105
+ {
106
+ return (0, _AddTrailingComments.performAddTrailingCommentsMutation)(mutationContext, mutation);
107
+ }
108
+
109
+ case 'cloneCommentsTo':
110
+ {
111
+ return (0, _CloneCommentsTo.performCloneCommentsToMutation)(mutationContext, mutation);
112
+ }
138
113
  }
139
- };
140
-
141
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
142
- _loop();
143
- } // remove the comments
144
- // this is done at the end because it requires a complete traversal of the AST
145
- // so that we can find relevant node's attachment array
114
+ })(); // ensure the subtree's parent pointers are correct
115
+ // this is required for two reasons:
116
+ // 1) The userland transform is just JS - so there's nothing stopping them
117
+ // from doing anything dodgy. The flow types have some enforcement, but
118
+ // ofc that can just be ignored with a suppression.
119
+ // 2) Shallow clones are a necessary evil in the transform because they
120
+ // allow codemods to do simple changes to just one node without the
121
+ // weight that comes with deeply cloning the entire AST.
122
+ // However we can't update the parent pointers of the cloned node's
123
+ // children until the mutation step or else we would be mutating
124
+ // real AST nodes and potentially break the traverse step.
125
+ //
126
+ // Being strict here just helps us ensure we keep everything in sync
127
+
128
+
129
+ if (mutationRoot) {
130
+ (0, _detachedNode.updateAllParentPointers)(mutationRoot);
131
+ }
132
+ } // remove the comments
133
+ // this is done at the end because it requires a complete traversal of the AST
134
+ // so that we can find relevant node's attachment array
146
135
 
147
- } catch (err) {
148
- _iterator.e(err);
149
- } finally {
150
- _iterator.f();
151
- }
152
136
 
153
137
  (0, _RemoveComment.performRemoveCommentMutations)(ast, removeCommentMutations);
154
138
  return {
155
- ast: ast,
139
+ ast,
156
140
  astWasMutated: transformContext.astWasMutated,
157
141
  mutatedCode: mutationContext.code
158
142
  };
@@ -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.
@@ -26,6 +26,7 @@ import {performAddTrailingCommentsMutation} from './mutations/AddTrailingComment
26
26
  import {performCloneCommentsToMutation} from './mutations/CloneCommentsTo';
27
27
  import {performInsertStatementMutation} from './mutations/InsertStatement';
28
28
  import {performRemoveCommentMutations} from './mutations/RemoveComment';
29
+ import {performRemoveNodeMutation} from './mutations/RemoveNode';
29
30
  import {performRemoveStatementMutation} from './mutations/RemoveStatement';
30
31
  import {performReplaceNodeMutation} from './mutations/ReplaceNode';
31
32
  import {performReplaceStatementWithManyMutation} from './mutations/ReplaceStatementWithMany';
@@ -47,7 +48,7 @@ export function getTransformedAST(
47
48
  attachComments(ast.comments, ast, code);
48
49
 
49
50
  // traverse the AST and colllect the mutations
50
- const transformContext = getTransformContext();
51
+ const transformContext = getTransformContext(code);
51
52
  traverseWithContext(ast, scopeManager, () => transformContext, visitors);
52
53
 
53
54
  // apply the mutations to the AST
@@ -73,6 +74,10 @@ export function getTransformedAST(
73
74
  );
74
75
  }
75
76
 
77
+ case 'removeNode': {
78
+ return performRemoveNodeMutation(mutationContext, mutation);
79
+ }
80
+
76
81
  case 'removeStatement': {
77
82
  return performRemoveStatementMutation(mutationContext, mutation);
78
83
  }
@@ -8,12 +8,15 @@ exports.performAddLeadingCommentsMutation = performAddLeadingCommentsMutation;
8
8
 
9
9
  var _comments = require("../comments/comments");
10
10
 
11
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
12
-
13
- 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); }
14
-
15
- 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; }
16
-
11
+ /**
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ *
18
+ * @format
19
+ */
17
20
  function createAddLeadingCommentsMutation(node, comments) {
18
21
  if (comments.length === 0) {
19
22
  return null;
@@ -21,26 +24,16 @@ function createAddLeadingCommentsMutation(node, comments) {
21
24
 
22
25
  return {
23
26
  type: 'addLeadingComments',
24
- comments: comments,
25
- node: node
27
+ comments,
28
+ node
26
29
  };
27
30
  }
28
31
 
29
32
  function performAddLeadingCommentsMutation(mutationContext, mutation) {
30
- var _iterator = _createForOfIteratorHelper(mutation.comments),
31
- _step;
32
-
33
- try {
34
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
35
- var originalComment = _step.value;
36
- var comment = (0, _comments.cloneComment)(originalComment);
37
- mutationContext.appendCommentToSource(comment);
38
- (0, _comments.addLeadingComment)(mutation.node, comment);
39
- }
40
- } catch (err) {
41
- _iterator.e(err);
42
- } finally {
43
- _iterator.f();
33
+ for (const originalComment of mutation.comments) {
34
+ const comment = (0, _comments.cloneComment)(originalComment);
35
+ mutationContext.appendCommentToSource(comment);
36
+ (0, _comments.addLeadingComment)(mutation.node, comment);
44
37
  }
45
38
 
46
39
  return null;
@@ -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,12 +8,15 @@ exports.performAddTrailingCommentsMutation = performAddTrailingCommentsMutation;
8
8
 
9
9
  var _comments = require("../comments/comments");
10
10
 
11
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
12
-
13
- 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); }
14
-
15
- 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; }
16
-
11
+ /**
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ *
18
+ * @format
19
+ */
17
20
  function createAddTrailingCommentsMutation(node, comments) {
18
21
  if (comments.length === 0) {
19
22
  return null;
@@ -21,26 +24,16 @@ function createAddTrailingCommentsMutation(node, comments) {
21
24
 
22
25
  return {
23
26
  type: 'addTrailingComments',
24
- comments: comments,
25
- node: node
27
+ comments,
28
+ node
26
29
  };
27
30
  }
28
31
 
29
32
  function performAddTrailingCommentsMutation(mutationContext, mutation) {
30
- var _iterator = _createForOfIteratorHelper(mutation.comments),
31
- _step;
32
-
33
- try {
34
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
35
- var originalComment = _step.value;
36
- var comment = (0, _comments.cloneComment)(originalComment);
37
- mutationContext.appendCommentToSource(comment);
38
- (0, _comments.addTrailingComment)(mutation.node, comment);
39
- }
40
- } catch (err) {
41
- _iterator.e(err);
42
- } finally {
43
- _iterator.f();
33
+ for (const originalComment of mutation.comments) {
34
+ const comment = (0, _comments.cloneComment)(originalComment);
35
+ mutationContext.appendCommentToSource(comment);
36
+ (0, _comments.addTrailingComment)(mutation.node, comment);
44
37
  }
45
38
 
46
39
  return null;
@@ -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,37 +8,30 @@ exports.performCloneCommentsToMutation = performCloneCommentsToMutation;
8
8
 
9
9
  var _comments = require("../comments/comments");
10
10
 
11
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
12
-
13
- 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); }
14
-
15
- 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; }
16
-
11
+ /**
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ *
18
+ * @format
19
+ */
17
20
  function createCloneCommentsToMutation(target, destination) {
18
21
  return {
19
22
  type: 'cloneCommentsTo',
20
- target: target,
21
- destination: destination
23
+ target,
24
+ destination
22
25
  };
23
26
  }
24
27
 
25
28
  function performCloneCommentsToMutation(mutationContext, mutation) {
26
- var newComments = [];
27
-
28
- var _iterator = _createForOfIteratorHelper((0, _comments.getCommentsForNode)(mutation.target)),
29
- _step;
29
+ const newComments = [];
30
30
 
31
- try {
32
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
33
- var originalComment = _step.value;
34
- var comment = (0, _comments.cloneCommentWithMarkers)(originalComment);
35
- mutationContext.appendCommentToSource(comment);
36
- newComments.push(comment);
37
- }
38
- } catch (err) {
39
- _iterator.e(err);
40
- } finally {
41
- _iterator.f();
31
+ for (const originalComment of (0, _comments.getCommentsForNode)(mutation.target)) {
32
+ const comment = (0, _comments.cloneCommentWithMarkers)(originalComment);
33
+ mutationContext.appendCommentToSource(comment);
34
+ newComments.push(comment);
42
35
  }
43
36
 
44
37
  (0, _comments.addCommentsToNode)(mutation.destination, newComments);
@@ -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,7 +1,5 @@
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
  });
@@ -18,22 +16,19 @@ var _Errors = require("../Errors");
18
16
 
19
17
  var t = _interopRequireWildcard(require("../../generated/node-types"));
20
18
 
21
- 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); }
22
-
23
- 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; }
24
-
25
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
26
-
27
- 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."); }
28
-
29
- 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); }
30
-
31
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
32
-
33
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
19
+ 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); }
34
20
 
35
- 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; }
21
+ 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
22
 
23
+ /**
24
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
25
+ *
26
+ * This source code is licensed under the MIT license found in the
27
+ * LICENSE file in the root directory of this source tree.
28
+ *
29
+ *
30
+ * @format
31
+ */
37
32
  function createInsertStatementMutation(side, target, nodesToInsert) {
38
33
  if (nodesToInsert.length === 0) {
39
34
  return null;
@@ -41,34 +36,34 @@ function createInsertStatementMutation(side, target, nodesToInsert) {
41
36
 
42
37
  return {
43
38
  type: 'insertStatement',
44
- side: side,
45
- target: target,
46
- nodesToInsert: nodesToInsert
39
+ side,
40
+ target,
41
+ nodesToInsert
47
42
  };
48
43
  }
49
44
 
50
45
  function performInsertStatementMutation(mutationContext, mutation) {
51
- var insertionParent = (0, _getStatementParent.getStatementParent)(mutation.target); // enforce that if we are inserting module declarations - they are being inserted in a valid location
46
+ const insertionParent = (0, _getStatementParent.getStatementParent)(mutation.target); // enforce that if we are inserting module declarations - they are being inserted in a valid location
52
47
 
53
48
  if (!(0, _isValidModuleDeclarationParent.isValidModuleDeclarationParent)(insertionParent.parent, mutation.nodesToInsert)) {
54
- throw new _Errors.InvalidInsertionError("import/export cannot be inserted into a ".concat(insertionParent.parent.type, "."));
49
+ throw new _Errors.InvalidInsertionError(`import/export cannot be inserted into a ${insertionParent.parent.type}.`);
55
50
  }
56
51
 
57
52
  mutationContext.markMutation(insertionParent.parent, insertionParent.key);
58
53
 
59
54
  if (insertionParent.type === 'array') {
60
- var _parent = insertionParent.parent;
55
+ const parent = insertionParent.parent;
61
56
 
62
57
  switch (mutation.side) {
63
58
  case 'before':
64
59
  {
65
- _parent[insertionParent.key] = (0, _arrayUtils.insertInArray)(_parent[insertionParent.key], insertionParent.targetIndex - 1, mutation.nodesToInsert);
60
+ parent[insertionParent.key] = (0, _arrayUtils.insertInArray)(parent[insertionParent.key], insertionParent.targetIndex - 1, mutation.nodesToInsert);
66
61
  break;
67
62
  }
68
63
 
69
64
  case 'after':
70
65
  {
71
- _parent[insertionParent.key] = (0, _arrayUtils.insertInArray)(_parent[insertionParent.key], insertionParent.targetIndex + 1, mutation.nodesToInsert);
66
+ parent[insertionParent.key] = (0, _arrayUtils.insertInArray)(parent[insertionParent.key], insertionParent.targetIndex + 1, mutation.nodesToInsert);
72
67
  break;
73
68
  }
74
69
  }
@@ -76,15 +71,17 @@ function performInsertStatementMutation(mutationContext, mutation) {
76
71
  return insertionParent.parent;
77
72
  }
78
73
 
79
- var statementsToInsert = // $FlowExpectedError[incompatible-cast] -- this is enforced by isValidModuleDeclarationParent above
74
+ const statementsToInsert = // $FlowExpectedError[incompatible-cast] -- this is enforced by isValidModuleDeclarationParent above
80
75
  mutation.nodesToInsert;
81
- var parent = insertionParent.parent,
82
- key = insertionParent.key; // $FlowExpectedError[prop-missing]
76
+ const {
77
+ parent,
78
+ key
79
+ } = insertionParent; // $FlowExpectedError[prop-missing]
83
80
 
84
- var statementToWrap = parent[key]; // we need to wrap this key in a BlockStatement so we can insert the new statement
81
+ const statementToWrap = parent[key]; // we need to wrap this key in a BlockStatement so we can insert the new statement
85
82
 
86
- var blockStatement = t.BlockStatement({
87
- body: mutation.side === 'before' ? [].concat(_toConsumableArray(statementsToInsert), [statementToWrap]) : [statementToWrap].concat(_toConsumableArray(statementsToInsert)),
83
+ const blockStatement = t.BlockStatement({
84
+ body: mutation.side === 'before' ? [...statementsToInsert, statementToWrap] : [statementToWrap, ...statementsToInsert],
88
85
  parent: insertionParent.parent
89
86
  });
90
87
  insertionParent.parent[insertionParent.key] = blockStatement;
@@ -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.