hermes-parser 0.10.0 → 0.10.1

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.
@@ -18,15 +18,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
18
18
  *
19
19
  * @format
20
20
  */
21
-
22
- /*
23
- This class does some very "javascripty" things in the name of
24
- performance which are ultimately impossible to soundly type.
25
-
26
- So instead of adding strict types and a large number of suppression
27
- comments, instead it is left untyped and subclasses are strictly
28
- typed via a separate flow declaration file.
29
- */
30
21
  class HermesToBabelAdapter extends _HermesASTAdapter.default {
31
22
  fixSourceLocation(node) {
32
23
  var _this$sourceFilename;
@@ -4,19 +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
- * @flow
7
+ * @flow strict
8
8
  * @format
9
9
  */
10
10
 
11
- /*
12
- This class does some very "javascripty" things in the name of
13
- performance which are ultimately impossible to soundly type.
14
-
15
- So instead of adding strict types and a large number of suppression
16
- comments, instead it is left untyped and subclasses are strictly
17
- typed via a separate flow declaration file.
18
- */
19
-
20
11
  import type {HermesNode} from './HermesAST';
21
12
 
22
13
  import HermesASTAdapter from './HermesASTAdapter';
@@ -20,15 +20,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
20
20
  *
21
21
  * @format
22
22
  */
23
-
24
- /*
25
- This class does some very "javascripty" things in the name of
26
- performance which are ultimately impossible to soundly type.
27
-
28
- So instead of adding strict types and a large number of suppression
29
- comments, instead it is left untyped and subclasses are strictly
30
- typed via a separate flow declaration file.
31
- */
32
23
  class HermesToESTreeAdapter extends _HermesASTAdapter.default {
33
24
  constructor(options, code) {
34
25
  super(options);
@@ -131,10 +122,10 @@ class HermesToESTreeAdapter extends _HermesASTAdapter.default {
131
122
  }
132
123
 
133
124
  mapProgram(node) {
134
- node = this.mapNodeDefault(node);
125
+ const nodeDefault = this.mapNodeDefault(node);
135
126
  node.sourceType = this.getSourceType();
136
- node.docblock = (0, _getModuleDocblock.getModuleDocblock)(node);
137
- return node;
127
+ node.docblock = (0, _getModuleDocblock.getModuleDocblock)(nodeDefault);
128
+ return nodeDefault;
138
129
  }
139
130
 
140
131
  mapSimpleLiteral(node) {
@@ -4,19 +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
- * @flow
7
+ * @flow strict
8
8
  * @format
9
9
  */
10
10
 
11
- /*
12
- This class does some very "javascripty" things in the name of
13
- performance which are ultimately impossible to soundly type.
14
-
15
- So instead of adding strict types and a large number of suppression
16
- comments, instead it is left untyped and subclasses are strictly
17
- typed via a separate flow declaration file.
18
- */
19
-
20
11
  import type {HermesNode} from './HermesAST';
21
12
  import type {ParserOptions} from './ParserOptions';
22
13
 
@@ -107,12 +98,12 @@ export default class HermesToESTreeAdapter extends HermesASTAdapter {
107
98
  }
108
99
 
109
100
  mapProgram(node: HermesNode): HermesNode {
110
- node = this.mapNodeDefault(node);
101
+ const nodeDefault = this.mapNodeDefault(node);
111
102
  node.sourceType = this.getSourceType();
112
103
 
113
- node.docblock = getModuleDocblock(node);
104
+ node.docblock = getModuleDocblock(nodeDefault);
114
105
 
115
- return node;
106
+ return nodeDefault;
116
107
  }
117
108
 
118
109
  mapSimpleLiteral(node: HermesNode): HermesNode {
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+ * @generated
10
+ */
11
+
12
+ /*
13
+ * !!! GENERATED FILE !!!
14
+ *
15
+ * Any manual changes to this file will be overwritten. To regenerate run `yarn build`.
16
+ */
17
+ // lint directives to let us do some basic validation of generated files
18
+
19
+ /* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
20
+
21
+ /* global $NonMaybeType, Partial, $ReadOnly, $ReadOnlyArray */
22
+ 'use strict';
23
+
24
+ module.exports = {
25
+ AnyTypeAnnotation: [],
26
+ ArrayExpression: ['elements'],
27
+ ArrayPattern: ['elements', 'typeAnnotation'],
28
+ ArrayTypeAnnotation: ['elementType'],
29
+ ArrowFunctionExpression: ['id', 'params', 'body', 'typeParameters', 'returnType', 'predicate'],
30
+ AssignmentExpression: ['left', 'right'],
31
+ AssignmentPattern: ['left', 'right'],
32
+ AwaitExpression: ['argument'],
33
+ BigIntLiteralTypeAnnotation: [],
34
+ BigIntTypeAnnotation: [],
35
+ BinaryExpression: ['left', 'right'],
36
+ BlockStatement: ['body'],
37
+ BooleanLiteralTypeAnnotation: [],
38
+ BooleanTypeAnnotation: [],
39
+ BreakStatement: ['label'],
40
+ CallExpression: ['callee', 'typeArguments', 'arguments'],
41
+ CatchClause: ['param', 'body'],
42
+ ChainExpression: ['expression'],
43
+ ClassBody: ['body'],
44
+ ClassDeclaration: ['id', 'typeParameters', 'superClass', 'superTypeParameters', 'implements', 'decorators', 'body'],
45
+ ClassExpression: ['id', 'typeParameters', 'superClass', 'superTypeParameters', 'implements', 'decorators', 'body'],
46
+ ClassImplements: ['id', 'typeParameters'],
47
+ ConditionalExpression: ['test', 'consequent', 'alternate'],
48
+ ContinueStatement: ['label'],
49
+ DebuggerStatement: [],
50
+ DeclareClass: ['id', 'typeParameters', 'extends', 'implements', 'mixins', 'body'],
51
+ DeclaredPredicate: ['value'],
52
+ DeclareExportAllDeclaration: ['source'],
53
+ DeclareExportDeclaration: ['declaration', 'specifiers', 'source'],
54
+ DeclareFunction: ['id', 'predicate'],
55
+ DeclareInterface: ['id', 'typeParameters', 'extends', 'body'],
56
+ DeclareModule: ['id', 'body'],
57
+ DeclareModuleExports: ['typeAnnotation'],
58
+ DeclareOpaqueType: ['id', 'typeParameters', 'impltype', 'supertype'],
59
+ DeclareTypeAlias: ['id', 'typeParameters', 'right'],
60
+ DeclareVariable: ['id'],
61
+ DoWhileStatement: ['body', 'test'],
62
+ EmptyStatement: [],
63
+ EmptyTypeAnnotation: [],
64
+ EnumBooleanBody: ['members'],
65
+ EnumBooleanMember: ['id', 'init'],
66
+ EnumDeclaration: ['id', 'body'],
67
+ EnumDefaultedMember: ['id'],
68
+ EnumNumberBody: ['members'],
69
+ EnumNumberMember: ['id', 'init'],
70
+ EnumStringBody: ['members'],
71
+ EnumStringMember: ['id', 'init'],
72
+ EnumSymbolBody: ['members'],
73
+ ExistsTypeAnnotation: [],
74
+ ExportAllDeclaration: ['exported', 'source'],
75
+ ExportDefaultDeclaration: ['declaration'],
76
+ ExportNamedDeclaration: ['declaration', 'specifiers', 'source'],
77
+ ExportSpecifier: ['exported', 'local'],
78
+ ExpressionStatement: ['expression'],
79
+ ForInStatement: ['left', 'right', 'body'],
80
+ ForOfStatement: ['left', 'right', 'body'],
81
+ ForStatement: ['init', 'test', 'update', 'body'],
82
+ FunctionDeclaration: ['id', 'params', 'body', 'typeParameters', 'returnType', 'predicate'],
83
+ FunctionExpression: ['id', 'params', 'body', 'typeParameters', 'returnType', 'predicate'],
84
+ FunctionTypeAnnotation: ['params', 'this', 'returnType', 'rest', 'typeParameters'],
85
+ FunctionTypeParam: ['name', 'typeAnnotation'],
86
+ GenericTypeAnnotation: ['id', 'typeParameters'],
87
+ Identifier: ['typeAnnotation'],
88
+ IfStatement: ['test', 'consequent', 'alternate'],
89
+ ImportAttribute: ['key', 'value'],
90
+ ImportDeclaration: ['specifiers', 'source', 'assertions'],
91
+ ImportDefaultSpecifier: ['local'],
92
+ ImportExpression: ['source', 'attributes'],
93
+ ImportNamespaceSpecifier: ['local'],
94
+ ImportSpecifier: ['imported', 'local'],
95
+ IndexedAccessType: ['objectType', 'indexType'],
96
+ InferredPredicate: [],
97
+ InterfaceDeclaration: ['id', 'typeParameters', 'extends', 'body'],
98
+ InterfaceExtends: ['id', 'typeParameters'],
99
+ InterfaceTypeAnnotation: ['extends', 'body'],
100
+ IntersectionTypeAnnotation: ['types'],
101
+ JSXAttribute: ['name', 'value'],
102
+ JSXClosingElement: ['name'],
103
+ JSXClosingFragment: [],
104
+ JSXElement: ['openingElement', 'children', 'closingElement'],
105
+ JSXEmptyExpression: [],
106
+ JSXExpressionContainer: ['expression'],
107
+ JSXFragment: ['openingFragment', 'children', 'closingFragment'],
108
+ JSXIdentifier: [],
109
+ JSXMemberExpression: ['object', 'property'],
110
+ JSXNamespacedName: ['namespace', 'name'],
111
+ JSXOpeningElement: ['name', 'attributes'],
112
+ JSXOpeningFragment: [],
113
+ JSXSpreadAttribute: ['argument'],
114
+ JSXSpreadChild: ['expression'],
115
+ JSXText: [],
116
+ LabeledStatement: ['label', 'body'],
117
+ LogicalExpression: ['left', 'right'],
118
+ MemberExpression: ['object', 'property'],
119
+ MetaProperty: ['meta', 'property'],
120
+ MethodDefinition: ['key', 'value'],
121
+ MixedTypeAnnotation: [],
122
+ NewExpression: ['callee', 'typeArguments', 'arguments'],
123
+ NullableTypeAnnotation: ['typeAnnotation'],
124
+ NullLiteralTypeAnnotation: [],
125
+ NumberLiteralTypeAnnotation: [],
126
+ NumberTypeAnnotation: [],
127
+ ObjectExpression: ['properties'],
128
+ ObjectPattern: ['properties', 'typeAnnotation'],
129
+ ObjectTypeAnnotation: ['properties', 'indexers', 'callProperties', 'internalSlots'],
130
+ ObjectTypeCallProperty: ['value'],
131
+ ObjectTypeIndexer: ['id', 'key', 'value', 'variance'],
132
+ ObjectTypeInternalSlot: ['id', 'value'],
133
+ ObjectTypeProperty: ['key', 'value', 'variance'],
134
+ ObjectTypeSpreadProperty: ['argument'],
135
+ OpaqueType: ['id', 'typeParameters', 'impltype', 'supertype'],
136
+ OptionalIndexedAccessType: ['objectType', 'indexType'],
137
+ PrivateIdentifier: [],
138
+ Program: ['body'],
139
+ Property: ['key', 'value'],
140
+ PropertyDefinition: ['key', 'value', 'variance', 'typeAnnotation', 'tsModifiers'],
141
+ QualifiedTypeIdentifier: ['qualification', 'id'],
142
+ RestElement: ['argument'],
143
+ ReturnStatement: ['argument'],
144
+ SequenceExpression: ['expressions'],
145
+ SpreadElement: ['argument'],
146
+ StringLiteralTypeAnnotation: [],
147
+ StringTypeAnnotation: [],
148
+ Super: [],
149
+ SwitchCase: ['test', 'consequent'],
150
+ SwitchStatement: ['discriminant', 'cases'],
151
+ SymbolTypeAnnotation: [],
152
+ TaggedTemplateExpression: ['tag', 'quasi'],
153
+ TemplateElement: [],
154
+ TemplateLiteral: ['quasis', 'expressions'],
155
+ ThisExpression: [],
156
+ ThisTypeAnnotation: [],
157
+ ThrowStatement: ['argument'],
158
+ TryStatement: ['block', 'handler', 'finalizer'],
159
+ TupleTypeAnnotation: ['types'],
160
+ TypeAlias: ['id', 'typeParameters', 'right'],
161
+ TypeAnnotation: ['typeAnnotation'],
162
+ TypeCastExpression: ['expression', 'typeAnnotation'],
163
+ TypeofTypeAnnotation: ['argument'],
164
+ TypeParameter: ['bound', 'variance', 'default'],
165
+ TypeParameterDeclaration: ['params'],
166
+ TypeParameterInstantiation: ['params'],
167
+ UnaryExpression: ['argument'],
168
+ UnionTypeAnnotation: ['types'],
169
+ UpdateExpression: ['argument'],
170
+ VariableDeclaration: ['declarations'],
171
+ VariableDeclarator: ['id', 'init'],
172
+ Variance: [],
173
+ VoidTypeAnnotation: [],
174
+ WhileStatement: ['test', 'body'],
175
+ WithStatement: ['object', 'body'],
176
+ YieldExpression: ['argument'],
177
+ OptionalMemberExpression: ['object', 'property'],
178
+ OptionalCallExpression: ['callee', 'typeArguments', 'arguments'],
179
+ Literal: []
180
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and 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
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ export type VisitorKeys = $ReadOnly<{[string]: $ReadOnlyArray<string>}>;
14
+
15
+ declare module.exports: VisitorKeys;
@@ -18,7 +18,7 @@
18
18
 
19
19
  /* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
20
20
 
21
- /* global $NonMaybeType, $Partial, $ReadOnly, $ReadOnlyArray */
21
+ /* global $NonMaybeType, Partial, $ReadOnly, $ReadOnlyArray */
22
22
  'use strict';
23
23
 
24
24
  Object.defineProperty(exports, "__esModule", {
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", {
14
14
  });
15
15
  var _exportNames = {
16
16
  parse: true,
17
+ FlowVisitorKeys: true,
17
18
  astArrayMutationHelpers: true,
18
19
  astNodeMutationHelpers: true
19
20
  };
@@ -26,6 +27,10 @@ var _HermesToBabelAdapter = _interopRequireDefault(require("./HermesToBabelAdapt
26
27
 
27
28
  var _HermesToESTreeAdapter = _interopRequireDefault(require("./HermesToESTreeAdapter"));
28
29
 
30
+ var _ESTreeVisitorKeys = _interopRequireDefault(require("./generated/ESTreeVisitorKeys"));
31
+
32
+ exports.FlowVisitorKeys = _ESTreeVisitorKeys.default;
33
+
29
34
  var _SimpleTraverser = require("./traverse/SimpleTraverser");
30
35
 
31
36
  Object.keys(_SimpleTraverser).forEach(function (key) {
@@ -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
- * @flow strict-local
7
+ * @flow strict
8
8
  * @format
9
9
  */
10
10
 
@@ -16,6 +16,7 @@ import type {ParserOptions} from './ParserOptions';
16
16
  import * as HermesParser from './HermesParser';
17
17
  import HermesToBabelAdapter from './HermesToBabelAdapter';
18
18
  import HermesToESTreeAdapter from './HermesToESTreeAdapter';
19
+ import FlowVisitorKeys from './generated/ESTreeVisitorKeys';
19
20
 
20
21
  const DEFAULTS = {
21
22
  flow: 'detect',
@@ -86,5 +87,6 @@ export type {ParserOptions} from './ParserOptions';
86
87
  export * from './traverse/SimpleTraverser';
87
88
  export * from './transform/SimpleTransform';
88
89
  export * from './traverse/getVisitorKeys';
90
+ export {FlowVisitorKeys};
89
91
  export * as astArrayMutationHelpers from './transform/astArrayMutationHelpers';
90
92
  export * as astNodeMutationHelpers from './transform/astNodeMutationHelpers';
@@ -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
- * @flow strict-local
7
+ * @flow strict
8
8
  * @format
9
9
  */
10
10
 
@@ -35,7 +35,7 @@ export type TransformOptions = $ReadOnly<{
35
35
  /** The callback function which is called on entering each node. */
36
36
  transform: TransformCallback,
37
37
 
38
- /** The set of visitor keys to use for traversal. Defaults to the `hermes-eslint` visitor keys */
38
+ /** The set of visitor keys to use for traversal. Defaults to the Flow ESTree visitor keys */
39
39
  visitorKeys?: ?VisitorKeysType,
40
40
  }>;
41
41
 
@@ -98,7 +98,7 @@ export class SimpleTransform {
98
98
  * @return Either the orginal node if the properties matched the existing node or a new node with
99
99
  * the new properties.
100
100
  */
101
- static nodeWith<T: ESNode>(node: T, overrideProps: $Partial<T>): T {
101
+ static nodeWith<T: ESNode>(node: T, overrideProps: Partial<T>): T {
102
102
  return nodeWith<T>(node, overrideProps);
103
103
  }
104
104
  }
@@ -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
- * @flow strict-local
7
+ * @flow strict
8
8
  * @format
9
9
  */
10
10
 
@@ -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
- * @flow strict-local
7
+ * @flow strict
8
8
  * @format
9
9
  */
10
10
 
@@ -149,7 +149,7 @@ export function updateAllParentPointers(node: ESNode) {
149
149
  *
150
150
  * This will only create a new object if the overrides actually result in a change.
151
151
  */
152
- export function nodeWith<T: ESNode>(node: T, overrideProps: $Partial<T>): T {
152
+ export function nodeWith<T: ESNode>(node: T, overrideProps: Partial<T>): T {
153
153
  // Check if this will actually result in a change, maintaining referential equality is important.
154
154
  const willBeUnchanged = Object.entries(overrideProps).every(([key, value]) =>
155
155
  // $FlowExpectedError[prop-missing]
@@ -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
- * @flow strict-local
7
+ * @flow strict
8
8
  * @format
9
9
  */
10
10
 
@@ -21,7 +21,7 @@ export type TraverserOptions = $ReadOnly<{
21
21
  enter: TraverserCallback,
22
22
  /** The callback function which is called on leaving each node. */
23
23
  leave: TraverserCallback,
24
- /** The set of visitor keys to use for traversal. Defaults to the `hermes-eslint` visitor keys */
24
+ /** The set of visitor keys to use for traversal. Defaults to the Flow ESTree visitor keys */
25
25
  visitorKeys?: ?VisitorKeysType,
26
26
  }>;
27
27
 
@@ -15,14 +15,16 @@ Object.defineProperty(exports, "__esModule", {
15
15
  exports.getVisitorKeys = getVisitorKeys;
16
16
  exports.isNode = isNode;
17
17
 
18
- var _hermesEslint = require("hermes-eslint");
18
+ var _ESTreeVisitorKeys = _interopRequireDefault(require("../generated/ESTreeVisitorKeys"));
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
21
 
20
22
  function isNode(thing) {
21
23
  return typeof thing === 'object' && thing != null && typeof thing.type === 'string';
22
24
  }
23
25
 
24
26
  function getVisitorKeys(node, visitorKeys) {
25
- const keys = (visitorKeys != null ? visitorKeys : _hermesEslint.VisitorKeys)[node.type];
27
+ const keys = (visitorKeys != null ? visitorKeys : _ESTreeVisitorKeys.default)[node.type];
26
28
 
27
29
  if (keys == null) {
28
30
  throw new Error(`No visitor keys found for node type "${node.type}".`);
@@ -4,15 +4,16 @@
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
- * @flow strict-local
7
+ * @flow strict
8
8
  * @format
9
9
  */
10
10
 
11
11
  'use strict';
12
12
 
13
13
  import type {ESNode} from 'hermes-estree';
14
+ import type {VisitorKeys as VisitorKeysType} from '../generated/ESTreeVisitorKeys';
14
15
 
15
- import {VisitorKeys as FlowVisitorKeys} from 'hermes-eslint';
16
+ import FlowVisitorKeys from '../generated/ESTreeVisitorKeys';
16
17
 
17
18
  export function isNode(thing: mixed): boolean %checks {
18
19
  return (
@@ -20,7 +21,7 @@ export function isNode(thing: mixed): boolean %checks {
20
21
  );
21
22
  }
22
23
 
23
- export type VisitorKeysType = $ReadOnly<{[string]: $ReadOnlyArray<string>}>;
24
+ export type {VisitorKeysType};
24
25
  export function getVisitorKeys<T: ESNode>(
25
26
  node: T,
26
27
  visitorKeys?: ?VisitorKeysType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-parser",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "A JavaScript parser built from the Hermes engine",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
@@ -9,7 +9,7 @@
9
9
  "url": "git@github.com:facebook/hermes.git"
10
10
  },
11
11
  "dependencies": {
12
- "hermes-estree": "0.10.0"
12
+ "hermes-estree": "0.10.1"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@babel/parser": "7.7.4",
@@ -1 +0,0 @@
1
- "use strict";
File without changes