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.
- package/dist/HermesAST.js.flow +2 -2
- package/dist/HermesASTAdapter.js +1 -1
- package/dist/HermesParser.js +1 -1
- package/dist/HermesParserDecodeUTF8String.js +1 -1
- package/dist/HermesParserDeserializer.js +1 -1
- package/dist/HermesParserDeserializer.js.flow +8 -8
- package/dist/HermesParserNodeDeserializers.js +1 -1
- package/dist/HermesParserNodeDeserializers.js.flow +1 -1
- package/dist/HermesParserWASM.js +1 -1
- package/dist/HermesParserWASM.js.flow +6 -6
- package/dist/HermesToESTreeAdapter.js +3 -2
- package/dist/HermesToESTreeAdapter.js.flow +4 -3
- package/dist/ParserOptions.js +5 -3
- package/dist/ParserOptions.js.flow +5 -5
- package/dist/babel/TransformESTreeToBabel.js +4 -3
- package/dist/babel/TransformESTreeToBabel.js.flow +101 -100
- package/dist/estree/StripFlowTypes.js +1 -1
- package/dist/estree/StripFlowTypesForBabel.js +1 -1
- package/dist/estree/TransformComponentSyntax.js +1 -1
- package/dist/estree/TransformComponentSyntax.js.flow +3 -3
- package/dist/estree/TransformEnumSyntax.js +1 -1
- package/dist/estree/TransformEnumSyntax.js.flow +1 -1
- package/dist/estree/TransformMatchSyntax.js +11 -2
- package/dist/estree/TransformMatchSyntax.js.flow +10 -9
- package/dist/estree/TransformRecordSyntax.js +1 -1
- package/dist/generated/ESTreeVisitorKeys.js +1 -1
- package/dist/generated/ESTreeVisitorKeys.js.flow +1 -1
- package/dist/generated/ParserVisitorKeys.js +1 -1
- package/dist/generated/ParserVisitorKeys.js.flow +2 -2
- package/dist/getModuleDocblock.js +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.flow +5 -5
- package/dist/src/HermesASTAdapter.js +1 -1
- package/dist/src/HermesParser.js +1 -1
- package/dist/src/HermesParserDecodeUTF8String.js +1 -1
- package/dist/src/HermesParserDeserializer.js +1 -1
- package/dist/src/HermesParserNodeDeserializers.js +1 -1
- package/dist/src/HermesToESTreeAdapter.js +3 -2
- package/dist/src/ParserOptions.js +5 -3
- package/dist/src/babel/TransformESTreeToBabel.js +4 -3
- package/dist/src/estree/StripFlowTypes.js +1 -1
- package/dist/src/estree/StripFlowTypesForBabel.js +1 -1
- package/dist/src/estree/TransformComponentSyntax.js +1 -1
- package/dist/src/estree/TransformEnumSyntax.js +1 -1
- package/dist/src/estree/TransformMatchSyntax.js +11 -2
- package/dist/src/estree/TransformRecordSyntax.js +1 -1
- package/dist/src/generated/ESTreeVisitorKeys.js +1 -1
- package/dist/src/generated/ParserVisitorKeys.js +1 -1
- package/dist/src/getModuleDocblock.js +1 -1
- package/dist/src/index.js +4 -3
- package/dist/src/transform/SimpleTransform.js +10 -1
- package/dist/src/transform/astArrayMutationHelpers.js +1 -1
- package/dist/src/transform/astNodeMutationHelpers.js +4 -3
- package/dist/src/traverse/SimpleTraverser.js +4 -2
- package/dist/src/traverse/getVisitorKeys.js +5 -3
- package/dist/src/utils/Builders.js +2 -3
- package/dist/src/utils/GenID.js +1 -1
- package/dist/src/utils/createSyntaxError.js +1 -1
- package/dist/src/utils/isReservedWord.js +1 -1
- package/dist/src/utils/mutateESTreeASTForPrettier.js +1 -1
- package/dist/transform/SimpleTransform.js +10 -1
- package/dist/transform/SimpleTransform.js.flow +6 -7
- package/dist/transform/astArrayMutationHelpers.js +1 -1
- package/dist/transform/astArrayMutationHelpers.js.flow +8 -8
- package/dist/transform/astNodeMutationHelpers.js +4 -3
- package/dist/transform/astNodeMutationHelpers.js.flow +12 -6
- package/dist/traverse/SimpleTraverser.js +4 -2
- package/dist/traverse/SimpleTraverser.js.flow +4 -4
- package/dist/traverse/getVisitorKeys.js +5 -3
- package/dist/traverse/getVisitorKeys.js.flow +5 -3
- package/dist/utils/Builders.js +2 -3
- package/dist/utils/Builders.js.flow +6 -6
- package/dist/utils/GenID.js +1 -1
- package/dist/utils/GenID.js.flow +2 -2
- package/dist/utils/createSyntaxError.js +1 -1
- package/dist/utils/isReservedWord.js +1 -1
- package/dist/utils/mutateESTreeASTForPrettier.js +1 -1
- package/dist/utils/mutateESTreeASTForPrettier.js.flow +1 -1
- package/package.json +4 -3
|
@@ -25,7 +25,7 @@ function getParentKey(
|
|
|
25
25
|
target: ESNode,
|
|
26
26
|
parent: ESNode,
|
|
27
27
|
visitorKeys?: ?VisitorKeysType,
|
|
28
|
-
):
|
|
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 (
|
|
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 |
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
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
|
|
87
|
-
|
|
88
|
-
|
|
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 {
|
|
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(
|
|
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
|
|
27
|
+
export function getVisitorKeys<T extends ESNode>(
|
|
26
28
|
node: T,
|
|
27
29
|
visitorKeys?: ?VisitorKeysType,
|
|
28
|
-
)
|
|
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}".`);
|
package/dist/utils/Builders.js
CHANGED
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
179
|
-
params:
|
|
180
|
-
args:
|
|
178
|
+
statements: ReadonlyArray<Statement>,
|
|
179
|
+
params: ReadonlyArray<BindingName> = [],
|
|
180
|
+
args: ReadonlyArray<Expression> = [],
|
|
181
181
|
): CallExpression {
|
|
182
182
|
const callee: ArrowFunctionExpression = {
|
|
183
183
|
type: 'ArrowFunctionExpression',
|
package/dist/utils/GenID.js
CHANGED
package/dist/utils/GenID.js.flow
CHANGED
|
@@ -14,8 +14,8 @@ const genPrefix = '$$gen$';
|
|
|
14
14
|
|
|
15
15
|
export default class GenID {
|
|
16
16
|
genN: number = 0;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
readonly used: Set<string> = new Set();
|
|
18
|
+
readonly prefix: string;
|
|
19
19
|
|
|
20
20
|
constructor(uniqueTransformPrefix: string) {
|
|
21
21
|
this.prefix = `${genPrefix}${uniqueTransformPrefix}`;
|
|
@@ -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:
|
|
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.
|
|
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
|
|
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.
|
|
13
|
+
"hermes-estree": "0.37.0"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {
|
|
15
16
|
"@babel/parser": "7.7.4",
|