hermes-parser 0.36.1 → 0.37.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 (79) hide show
  1. package/dist/HermesAST.js.flow +2 -2
  2. package/dist/HermesASTAdapter.js +1 -1
  3. package/dist/HermesParser.js +1 -1
  4. package/dist/HermesParserDecodeUTF8String.js +1 -1
  5. package/dist/HermesParserDeserializer.js +1 -1
  6. package/dist/HermesParserDeserializer.js.flow +8 -8
  7. package/dist/HermesParserNodeDeserializers.js +1 -1
  8. package/dist/HermesParserNodeDeserializers.js.flow +1 -1
  9. package/dist/HermesParserWASM.js +1 -1
  10. package/dist/HermesParserWASM.js.flow +6 -6
  11. package/dist/HermesToESTreeAdapter.js +3 -2
  12. package/dist/HermesToESTreeAdapter.js.flow +4 -3
  13. package/dist/ParserOptions.js +5 -3
  14. package/dist/ParserOptions.js.flow +5 -5
  15. package/dist/babel/TransformESTreeToBabel.js +4 -3
  16. package/dist/babel/TransformESTreeToBabel.js.flow +101 -100
  17. package/dist/estree/StripFlowTypes.js +1 -1
  18. package/dist/estree/StripFlowTypesForBabel.js +1 -1
  19. package/dist/estree/TransformComponentSyntax.js +1 -1
  20. package/dist/estree/TransformComponentSyntax.js.flow +3 -3
  21. package/dist/estree/TransformEnumSyntax.js +1 -1
  22. package/dist/estree/TransformEnumSyntax.js.flow +1 -1
  23. package/dist/estree/TransformMatchSyntax.js +11 -2
  24. package/dist/estree/TransformMatchSyntax.js.flow +10 -9
  25. package/dist/estree/TransformRecordSyntax.js +1 -1
  26. package/dist/generated/ESTreeVisitorKeys.js +1 -1
  27. package/dist/generated/ESTreeVisitorKeys.js.flow +1 -1
  28. package/dist/generated/ParserVisitorKeys.js +1 -1
  29. package/dist/generated/ParserVisitorKeys.js.flow +2 -2
  30. package/dist/getModuleDocblock.js +1 -1
  31. package/dist/index.js +4 -3
  32. package/dist/index.js.flow +5 -5
  33. package/dist/src/HermesASTAdapter.js +1 -1
  34. package/dist/src/HermesParser.js +1 -1
  35. package/dist/src/HermesParserDecodeUTF8String.js +1 -1
  36. package/dist/src/HermesParserDeserializer.js +1 -1
  37. package/dist/src/HermesParserNodeDeserializers.js +1 -1
  38. package/dist/src/HermesToESTreeAdapter.js +3 -2
  39. package/dist/src/ParserOptions.js +5 -3
  40. package/dist/src/babel/TransformESTreeToBabel.js +4 -3
  41. package/dist/src/estree/StripFlowTypes.js +1 -1
  42. package/dist/src/estree/StripFlowTypesForBabel.js +1 -1
  43. package/dist/src/estree/TransformComponentSyntax.js +1 -1
  44. package/dist/src/estree/TransformEnumSyntax.js +1 -1
  45. package/dist/src/estree/TransformMatchSyntax.js +11 -2
  46. package/dist/src/estree/TransformRecordSyntax.js +1 -1
  47. package/dist/src/generated/ESTreeVisitorKeys.js +1 -1
  48. package/dist/src/generated/ParserVisitorKeys.js +1 -1
  49. package/dist/src/getModuleDocblock.js +1 -1
  50. package/dist/src/index.js +4 -3
  51. package/dist/src/transform/SimpleTransform.js +10 -1
  52. package/dist/src/transform/astArrayMutationHelpers.js +1 -1
  53. package/dist/src/transform/astNodeMutationHelpers.js +4 -3
  54. package/dist/src/traverse/SimpleTraverser.js +4 -2
  55. package/dist/src/traverse/getVisitorKeys.js +5 -3
  56. package/dist/src/utils/Builders.js +2 -3
  57. package/dist/src/utils/GenID.js +1 -1
  58. package/dist/src/utils/createSyntaxError.js +1 -1
  59. package/dist/src/utils/isReservedWord.js +1 -1
  60. package/dist/src/utils/mutateESTreeASTForPrettier.js +1 -1
  61. package/dist/transform/SimpleTransform.js +10 -1
  62. package/dist/transform/SimpleTransform.js.flow +6 -7
  63. package/dist/transform/astArrayMutationHelpers.js +1 -1
  64. package/dist/transform/astArrayMutationHelpers.js.flow +8 -8
  65. package/dist/transform/astNodeMutationHelpers.js +4 -3
  66. package/dist/transform/astNodeMutationHelpers.js.flow +12 -6
  67. package/dist/traverse/SimpleTraverser.js +4 -2
  68. package/dist/traverse/SimpleTraverser.js.flow +4 -4
  69. package/dist/traverse/getVisitorKeys.js +5 -3
  70. package/dist/traverse/getVisitorKeys.js.flow +5 -3
  71. package/dist/utils/Builders.js +2 -3
  72. package/dist/utils/Builders.js.flow +6 -6
  73. package/dist/utils/GenID.js +1 -1
  74. package/dist/utils/GenID.js.flow +2 -2
  75. package/dist/utils/createSyntaxError.js +1 -1
  76. package/dist/utils/isReservedWord.js +1 -1
  77. package/dist/utils/mutateESTreeASTForPrettier.js +1 -1
  78. package/dist/utils/mutateESTreeASTForPrettier.js.flow +1 -1
  79. package/package.json +4 -3
@@ -25,7 +25,7 @@ function getParentKey(
25
25
  target: ESNode,
26
26
  parent: ESNode,
27
27
  visitorKeys?: ?VisitorKeysType,
28
- ): $ReadOnly<
28
+ ): Readonly<
29
29
  | {
30
30
  type: 'single',
31
31
  node: ESNode,
@@ -52,10 +52,16 @@ function getParentKey(
52
52
  if (parent[key] === target) {
53
53
  return {type: 'single', node: parent, key};
54
54
  }
55
- } else if (Array.isArray(parent[key])) {
55
+ } else if (
56
+ Array.isArray(
57
+ // $FlowExpectedError[prop-missing]
58
+ parent[key],
59
+ )
60
+ ) {
56
61
  for (let i = 0; i < parent[key].length; i += 1) {
57
62
  // $FlowExpectedError[invalid-tuple-index]
58
63
  const current = parent[key][i];
64
+ // $FlowFixMe[invalid-compare]
59
65
  if (current === target) {
60
66
  return {type: 'array', node: parent, key, targetIndex: i};
61
67
  }
@@ -75,7 +81,7 @@ function getParentKey(
75
81
  export function replaceNodeOnParent(
76
82
  originalNode: ESNode,
77
83
  originalNodeParent: ESNode,
78
- nodeToReplaceWith: ESNode | $ReadOnlyArray<ESNode>,
84
+ nodeToReplaceWith: ESNode | ReadonlyArray<ESNode>,
79
85
  visitorKeys?: ?VisitorKeysType,
80
86
  ): void {
81
87
  const replacementParent = getParentKey(
@@ -173,7 +179,7 @@ export function updateAllParentPointers(
173
179
  *
174
180
  * This will only create a new object if the overrides actually result in a change.
175
181
  */
176
- export function nodeWith<T: ESNode>(
182
+ export function nodeWith<T extends ESNode>(
177
183
  node: T,
178
184
  overrideProps: Partial<T>,
179
185
  visitorKeys?: ?VisitorKeysType,
@@ -210,7 +216,7 @@ export function nodeWith<T: ESNode>(
210
216
  /**
211
217
  * Shallow clones node, providing a new reference for an existing node.
212
218
  */
213
- export function shallowCloneNode<T: ESNode>(
219
+ export function shallowCloneNode<T extends ESNode>(
214
220
  node: T,
215
221
  visitorKeys?: ?VisitorKeysType,
216
222
  ): T {
@@ -226,7 +232,7 @@ export function shallowCloneNode<T: ESNode>(
226
232
  /**
227
233
  * Deeply clones node and its entire tree.
228
234
  */
229
- export function deepCloneNode<T: ESNode>(
235
+ export function deepCloneNode<T extends ESNode>(
230
236
  node: T,
231
237
  visitorKeys?: ?VisitorKeysType,
232
238
  ): T {
@@ -4,7 +4,7 @@
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.
6
6
  *
7
- *
7
+ * strict
8
8
  * @format
9
9
  */
10
10
  'use strict';
@@ -80,7 +80,9 @@ class SimpleTraverser {
80
80
  const keys = (0, _getVisitorKeys.getVisitorKeys)(node, options.visitorKeys);
81
81
 
82
82
  for (const key of keys) {
83
- const child = node[key];
83
+ const lookupKey = key;
84
+ const childAny = node[lookupKey];
85
+ const child = childAny;
84
86
 
85
87
  if (Array.isArray(child)) {
86
88
  for (let j = 0; j < child.length; ++j) {
@@ -16,7 +16,7 @@ import type {ESNode} from 'hermes-estree';
16
16
  import {getVisitorKeys, isNode} from './getVisitorKeys';
17
17
 
18
18
  export type TraverserCallback = (node: ESNode, parent: ?ESNode) => void;
19
- export type TraverserOptions = $ReadOnly<{
19
+ export type TraverserOptions = Readonly<{
20
20
  /** The callback function which is called on entering each node. */
21
21
  enter: TraverserCallback,
22
22
  /** The callback function which is called on leaving each node. */
@@ -83,9 +83,9 @@ export class SimpleTraverser {
83
83
 
84
84
  const keys = getVisitorKeys(node, options.visitorKeys);
85
85
  for (const key of keys) {
86
- const child: ESNode | $ReadOnlyArray<ESNode> = (node[
87
- (key: $FlowFixMe)
88
- ]: $FlowFixMe);
86
+ const lookupKey: $FlowFixMe = key;
87
+ const childAny: $FlowFixMe = node[lookupKey];
88
+ const child: ESNode | ReadonlyArray<ESNode> = childAny;
89
89
 
90
90
  if (Array.isArray(child)) {
91
91
  for (let j = 0; j < child.length; ++j) {
@@ -4,7 +4,7 @@
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.
6
6
  *
7
- *
7
+ * strict
8
8
  * @noformat
9
9
  */
10
10
  'use strict';
@@ -20,12 +20,14 @@ var _ESTreeVisitorKeys = _interopRequireDefault(require("../generated/ESTreeVisi
20
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
21
 
22
22
  function isNode(thing)
23
- /*: implies thing is {+[string]: mixed} */
23
+ /*: implies thing is {readonly [string]: unknown} */
24
24
  {
25
25
  return typeof thing === 'object' && thing != null && typeof thing.type === 'string';
26
26
  }
27
27
 
28
- function getVisitorKeys(node, visitorKeys) {
28
+ function getVisitorKeys(node, visitorKeys)
29
+ /*: ReadonlyArray<keyof T> */
30
+ {
29
31
  const keys = (visitorKeys != null ? visitorKeys : _ESTreeVisitorKeys.default)[node.type];
30
32
 
31
33
  if (keys == null) {
@@ -15,17 +15,19 @@ import type {VisitorKeys as VisitorKeysType} from '../generated/ESTreeVisitorKey
15
15
 
16
16
  import FlowVisitorKeys from '../generated/ESTreeVisitorKeys';
17
17
 
18
- export function isNode(thing: mixed) /*: implies thing is {+[string]: mixed} */ {
18
+ export function isNode(
19
+ thing: unknown,
20
+ ) /*: implies thing is {readonly [string]: unknown} */ {
19
21
  return (
20
22
  typeof thing === 'object' && thing != null && typeof thing.type === 'string'
21
23
  );
22
24
  }
23
25
 
24
26
  export type {VisitorKeysType};
25
- export function getVisitorKeys<T: ESNode>(
27
+ export function getVisitorKeys<T extends ESNode>(
26
28
  node: T,
27
29
  visitorKeys?: ?VisitorKeysType,
28
- ): $ReadOnlyArray<$Keys<T>> {
30
+ ) /*: ReadonlyArray<keyof T> */ {
29
31
  const keys = (visitorKeys ?? FlowVisitorKeys)[node.type];
30
32
  if (keys == null) {
31
33
  throw new Error(`No visitor keys found for node type "${node.type}".`);
@@ -4,10 +4,10 @@
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.
6
6
  *
7
- *
7
+ * strict
8
8
  * @format
9
9
  */
10
- 'use strict';
10
+ 'use strict'; // Rely on the mapper to fix up parent relationships.
11
11
 
12
12
  Object.defineProperty(exports, "__esModule", {
13
13
  value: true
@@ -26,7 +26,6 @@ exports.stringLiteral = stringLiteral;
26
26
  exports.throwStatement = throwStatement;
27
27
  exports.typeofExpression = typeofExpression;
28
28
  exports.variableDeclaration = variableDeclaration;
29
- // Rely on the mapper to fix up parent relationships.
30
29
  const EMPTY_PARENT = null;
31
30
  exports.EMPTY_PARENT = EMPTY_PARENT;
32
31
 
@@ -103,7 +103,7 @@ export function nullLiteral(info?: Etc): NullLiteral {
103
103
  };
104
104
  }
105
105
 
106
- export function conjunction(tests: $ReadOnlyArray<Expression>): Expression {
106
+ export function conjunction(tests: ReadonlyArray<Expression>): Expression {
107
107
  if (tests.length === 0) {
108
108
  throw new Error('Must have at least one test.');
109
109
  }
@@ -116,7 +116,7 @@ export function conjunction(tests: $ReadOnlyArray<Expression>): Expression {
116
116
  }));
117
117
  }
118
118
 
119
- export function disjunction(tests: $ReadOnlyArray<Expression>): Expression {
119
+ export function disjunction(tests: ReadonlyArray<Expression>): Expression {
120
120
  if (tests.length === 0) {
121
121
  throw new Error('Must have at least one test.');
122
122
  }
@@ -153,7 +153,7 @@ export function variableDeclaration(
153
153
 
154
154
  export function callExpression(
155
155
  callee: Expression | Super,
156
- args: $ReadOnlyArray<Expression | SpreadElement>,
156
+ args: ReadonlyArray<Expression | SpreadElement>,
157
157
  info?: Etc,
158
158
  ): CallExpression {
159
159
  return {
@@ -175,9 +175,9 @@ export function throwStatement(arg: Expression, info?: Etc): ThrowStatement {
175
175
  }
176
176
 
177
177
  export function iife(
178
- statements: $ReadOnlyArray<Statement>,
179
- params: $ReadOnlyArray<BindingName> = [],
180
- args: $ReadOnlyArray<Expression> = [],
178
+ statements: ReadonlyArray<Statement>,
179
+ params: ReadonlyArray<BindingName> = [],
180
+ args: ReadonlyArray<Expression> = [],
181
181
  ): CallExpression {
182
182
  const callee: ArrowFunctionExpression = {
183
183
  type: 'ArrowFunctionExpression',
@@ -4,7 +4,7 @@
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.
6
6
  *
7
- *
7
+ * strict
8
8
  * @format
9
9
  */
10
10
  'use strict';
@@ -14,8 +14,8 @@ const genPrefix = '$$gen$';
14
14
 
15
15
  export default class GenID {
16
16
  genN: number = 0;
17
- +used: Set<string> = new Set();
18
- +prefix: string;
17
+ readonly used: Set<string> = new Set();
18
+ readonly prefix: string;
19
19
 
20
20
  constructor(uniqueTransformPrefix: string) {
21
21
  this.prefix = `${genPrefix}${uniqueTransformPrefix}`;
@@ -4,7 +4,7 @@
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.
6
6
  *
7
- *
7
+ * strict
8
8
  * @format
9
9
  */
10
10
  'use strict';
@@ -4,7 +4,7 @@
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.
6
6
  *
7
- *
7
+ * strict
8
8
  * @format
9
9
  */
10
10
  'use strict';
@@ -4,7 +4,7 @@
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.
6
6
  *
7
- *
7
+ * strict
8
8
  * @format
9
9
  */
10
10
  'use strict';
@@ -17,7 +17,7 @@ import {SimpleTransform} from '../transform/SimpleTransform';
17
17
  // https://github.com/prettier/prettier/blob/d962466a828f8ef51435e3e8840178d90b7ec6cd/src/language-js/parse/postprocess/index.js#L161-L182
18
18
  function transformChainExpression(
19
19
  node: ESNode,
20
- comments: ?$ReadOnlyArray<Comment>,
20
+ comments: ?ReadonlyArray<Comment>,
21
21
  ): ESNode {
22
22
  if (comments != null) {
23
23
  // $FlowExpectedError[prop-missing]
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "hermes-parser",
3
- "version": "0.36.1",
3
+ "version": "0.37.0",
4
4
  "description": "A JavaScript parser built from the Hermes engine",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git@github.com:facebook/hermes.git"
9
+ "url": "git+https://github.com/facebook/hermes.git",
10
+ "directory": "tools/hermes-parser/js/hermes-parser"
10
11
  },
11
12
  "dependencies": {
12
- "hermes-estree": "0.36.1"
13
+ "hermes-estree": "0.37.0"
13
14
  },
14
15
  "devDependencies": {
15
16
  "@babel/parser": "7.7.4",