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,13 +8,11 @@
8
8
  */
9
9
  'use strict';
10
10
 
11
- 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); }
11
+ const stringWidth = require('string-width');
12
12
 
13
- var stringWidth = require('string-width');
13
+ const getLast = require('../utils/get-last.js');
14
14
 
15
- var getLast = require('../utils/get-last.js');
16
-
17
- var notAsciiRegex = /[^\x20-\x7F]/;
15
+ const notAsciiRegex = /[^\x20-\x7F]/;
18
16
  /**
19
17
  * @typedef {{backwards?: boolean}} SkipOptions
20
18
  */
@@ -25,8 +23,8 @@ var notAsciiRegex = /[^\x20-\x7F]/;
25
23
  */
26
24
 
27
25
  function skip(chars) {
28
- return function (text, index, opts) {
29
- var backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
26
+ return (text, index, opts) => {
27
+ const backwards = opts && opts.backwards; // Allow `skip` functions to be threaded together without having
30
28
  // to check for failures (did someone say monads?).
31
29
 
32
30
  /* istanbul ignore next */
@@ -35,11 +33,13 @@ function skip(chars) {
35
33
  return false;
36
34
  }
37
35
 
38
- var length = text.length;
39
- var cursor = index;
36
+ const {
37
+ length
38
+ } = text;
39
+ let cursor = index;
40
40
 
41
41
  while (cursor >= 0 && cursor < length) {
42
- var c = text.charAt(cursor);
42
+ const c = text.charAt(cursor);
43
43
 
44
44
  if (chars instanceof RegExp) {
45
45
  if (!chars.test(c)) {
@@ -68,22 +68,22 @@ function skip(chars) {
68
68
  */
69
69
 
70
70
 
71
- var skipWhitespace = skip(/\s/);
71
+ const skipWhitespace = skip(/\s/);
72
72
  /**
73
73
  * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
74
74
  */
75
75
 
76
- var skipSpaces = skip(' \t');
76
+ const skipSpaces = skip(' \t');
77
77
  /**
78
78
  * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
79
79
  */
80
80
 
81
- var skipToLineEnd = skip(',; \t');
81
+ const skipToLineEnd = skip(',; \t');
82
82
  /**
83
83
  * @type {(text: string, index: number | false, opts?: SkipOptions) => number | false}
84
84
  */
85
85
 
86
- var skipEverythingButNewLine = skip(/[^\n\r]/);
86
+ const skipEverythingButNewLine = skip(/[^\n\r]/);
87
87
  /**
88
88
  * @param {string} text
89
89
  * @param {number | false} index
@@ -97,7 +97,7 @@ function skipInlineComment(text, index) {
97
97
  }
98
98
 
99
99
  if (text.charAt(index) === '/' && text.charAt(index + 1) === '*') {
100
- for (var i = index + 2; i < text.length; ++i) {
100
+ for (let i = index + 2; i < text.length; ++i) {
101
101
  if (text.charAt(i) === '*' && text.charAt(i + 1) === '/') {
102
102
  return i + 2;
103
103
  }
@@ -137,13 +137,13 @@ function skipTrailingComment(text, index) {
137
137
 
138
138
 
139
139
  function skipNewline(text, index, opts) {
140
- var backwards = opts && opts.backwards;
140
+ const backwards = opts && opts.backwards;
141
141
 
142
142
  if (index === false) {
143
143
  return false;
144
144
  }
145
145
 
146
- var atIndex = text.charAt(index);
146
+ const atIndex = text.charAt(index);
147
147
 
148
148
  if (backwards) {
149
149
  // We already replace `\r\n` with `\n` before parsing
@@ -153,7 +153,7 @@ function skipNewline(text, index, opts) {
153
153
  return index - 2;
154
154
  }
155
155
 
156
- if (atIndex === '\n' || atIndex === '\r' || atIndex === "\u2028" || atIndex === "\u2029") {
156
+ if (atIndex === '\n' || atIndex === '\r' || atIndex === '\u2028' || atIndex === '\u2029') {
157
157
  return index - 1;
158
158
  }
159
159
  } else {
@@ -164,7 +164,7 @@ function skipNewline(text, index, opts) {
164
164
  return index + 2;
165
165
  }
166
166
 
167
- if (atIndex === '\n' || atIndex === '\r' || atIndex === "\u2028" || atIndex === "\u2029") {
167
+ if (atIndex === '\n' || atIndex === '\r' || atIndex === '\u2028' || atIndex === '\u2029') {
168
168
  return index + 1;
169
169
  }
170
170
  }
@@ -179,10 +179,9 @@ function skipNewline(text, index, opts) {
179
179
  */
180
180
 
181
181
 
182
- function hasNewline(text, index) {
183
- var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
184
- var idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
185
- var idx2 = skipNewline(text, idx, opts);
182
+ function hasNewline(text, index, opts = {}) {
183
+ const idx = skipSpaces(text, opts.backwards ? index - 1 : index, opts);
184
+ const idx2 = skipNewline(text, idx, opts);
186
185
  return idx !== idx2;
187
186
  }
188
187
  /**
@@ -194,7 +193,7 @@ function hasNewline(text, index) {
194
193
 
195
194
 
196
195
  function hasNewlineInRange(text, start, end) {
197
- for (var i = start; i < end; ++i) {
196
+ for (let i = start; i < end; ++i) {
198
197
  if (text.charAt(i) === '\n') {
199
198
  return true;
200
199
  }
@@ -211,10 +210,10 @@ function hasNewlineInRange(text, start, end) {
211
210
 
212
211
  function isNextLineEmptyAfterIndex(text, index) {
213
212
  /** @type {number | false} */
214
- var oldIdx = null;
213
+ let oldIdx = null;
215
214
  /** @type {number | false} */
216
215
 
217
- var idx = index;
216
+ let idx = index;
218
217
 
219
218
  while (idx !== oldIdx) {
220
219
  // We need to skip all the potential trailing inline comments
@@ -237,10 +236,10 @@ function isNextLineEmptyAfterIndex(text, index) {
237
236
 
238
237
  function getNextNonSpaceNonCommentCharacterIndexWithStartIndex(text, idx) {
239
238
  /** @type {number | false} */
240
- var oldIdx = null;
239
+ let oldIdx = null;
241
240
  /** @type {number | false} */
242
241
 
243
- var nextIdx = idx;
242
+ let nextIdx = idx;
244
243
 
245
244
  while (nextIdx !== oldIdx) {
246
245
  oldIdx = nextIdx;
@@ -297,7 +296,7 @@ function getStringWidth(text) {
297
296
  }
298
297
 
299
298
  function addCommentHelper(node, comment) {
300
- var comments = node.comments || (node.comments = []);
299
+ const comments = node.comments || (node.comments = []);
301
300
  comments.push(comment);
302
301
  comment.printed = false;
303
302
  comment.nodeDescription = describeNodeForDebugging(node);
@@ -336,8 +335,8 @@ function isNonEmptyArray(object) {
336
335
  }
337
336
 
338
337
  function describeNodeForDebugging(node) {
339
- var nodeType = node.type || node.kind || '(unknown type)';
340
- var nodeName = String(node.name || node.id && (_typeof(node.id) === 'object' ? node.id.name : node.id) || node.key && (_typeof(node.key) === 'object' ? node.key.name : node.key) || node.value && (_typeof(node.value) === 'object' ? '' : String(node.value)) || node.operator || '');
338
+ const nodeType = node.type || node.kind || '(unknown type)';
339
+ let nodeName = String(node.name || node.id && (typeof node.id === 'object' ? node.id.name : node.id) || node.key && (typeof node.key === 'object' ? node.key.name : node.key) || node.value && (typeof node.value === 'object' ? '' : String(node.value)) || node.operator || '');
341
340
 
342
341
  if (nodeName.length > 20) {
343
342
  nodeName = nodeName.slice(0, 19) + '…';
@@ -347,19 +346,19 @@ function describeNodeForDebugging(node) {
347
346
  }
348
347
 
349
348
  module.exports = {
350
- getStringWidth: getStringWidth,
351
- getLast: getLast,
352
- getNextNonSpaceNonCommentCharacterIndexWithStartIndex: getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
353
- getNextNonSpaceNonCommentCharacterIndex: getNextNonSpaceNonCommentCharacterIndex,
354
- getNextNonSpaceNonCommentCharacter: getNextNonSpaceNonCommentCharacter,
355
- skipWhitespace: skipWhitespace,
356
- skipSpaces: skipSpaces,
357
- skipNewline: skipNewline,
358
- isNextLineEmptyAfterIndex: isNextLineEmptyAfterIndex,
359
- hasNewline: hasNewline,
360
- hasNewlineInRange: hasNewlineInRange,
361
- addLeadingComment: addLeadingComment,
362
- addDanglingComment: addDanglingComment,
363
- addTrailingComment: addTrailingComment,
364
- isNonEmptyArray: isNonEmptyArray
349
+ getStringWidth,
350
+ getLast,
351
+ getNextNonSpaceNonCommentCharacterIndexWithStartIndex,
352
+ getNextNonSpaceNonCommentCharacterIndex,
353
+ getNextNonSpaceNonCommentCharacter,
354
+ skipWhitespace,
355
+ skipSpaces,
356
+ skipNewline,
357
+ isNextLineEmptyAfterIndex,
358
+ hasNewline,
359
+ hasNewlineInRange,
360
+ addLeadingComment,
361
+ addDanglingComment,
362
+ addTrailingComment,
363
+ isNonEmptyArray
365
364
  };
@@ -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.