hermes-estree 0.32.1 → 0.33.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/generated/HermesESTreeSelectorTypes.js.flow +262 -27
- package/dist/generated/predicates.js +120 -0
- package/dist/generated/predicates.js.flow +72 -0
- package/dist/predicates.js +2 -4
- package/dist/predicates.js.flow +5 -4
- package/dist/src/generated/predicates.js +120 -0
- package/dist/src/predicates.js +2 -4
- package/dist/types.js.flow +103 -11
- package/package.json +1 -1
- package/dist/HermesAST.js.flow +0 -57
- package/dist/HermesASTAdapter.js +0 -192
- package/dist/HermesASTAdapter.js.flow +0 -189
- package/dist/HermesParser.js +0 -108
- package/dist/HermesParser.js.flow +0 -161
- package/dist/HermesParserDecodeUTF8String.js +0 -68
- package/dist/HermesParserDecodeUTF8String.js.flow +0 -65
- package/dist/HermesParserDeserializer.js +0 -242
- package/dist/HermesParserDeserializer.js.flow +0 -260
- package/dist/HermesParserNodeDeserializers.js +0 -2477
- package/dist/HermesParserNodeDeserializers.js.flow +0 -16
- package/dist/HermesParserWASM.js +0 -6
- package/dist/HermesParserWASM.js.flow +0 -87
- package/dist/HermesToESTreeAdapter.js +0 -439
- package/dist/HermesToESTreeAdapter.js.flow +0 -421
- package/dist/ParserOptions.js +0 -18
- package/dist/ParserOptions.js.flow +0 -41
- package/dist/babel/TransformESTreeToBabel.js +0 -1123
- package/dist/babel/TransformESTreeToBabel.js.flow +0 -1277
- package/dist/estree/StripFlowTypes.js +0 -175
- package/dist/estree/StripFlowTypes.js.flow +0 -158
- package/dist/estree/StripFlowTypesForBabel.js +0 -215
- package/dist/estree/StripFlowTypesForBabel.js.flow +0 -216
- package/dist/estree/TransformComponentSyntax.js +0 -788
- package/dist/estree/TransformComponentSyntax.js.flow +0 -864
- package/dist/estree/TransformEnumSyntax.js +0 -106
- package/dist/estree/TransformEnumSyntax.js.flow +0 -125
- package/dist/estree/TransformMatchSyntax.js +0 -1006
- package/dist/estree/TransformMatchSyntax.js.flow +0 -912
- package/dist/generated/ESTreeVisitorKeys.js +0 -220
- package/dist/generated/ESTreeVisitorKeys.js.flow +0 -15
- package/dist/generated/ParserVisitorKeys.js +0 -794
- package/dist/generated/ParserVisitorKeys.js.flow +0 -17
- package/dist/getModuleDocblock.js +0 -112
- package/dist/getModuleDocblock.js.flow +0 -118
- package/dist/src/HermesASTAdapter.js +0 -192
- package/dist/src/HermesParser.js +0 -108
- package/dist/src/HermesParserDecodeUTF8String.js +0 -68
- package/dist/src/HermesParserDeserializer.js +0 -242
- package/dist/src/HermesParserNodeDeserializers.js +0 -2477
- package/dist/src/HermesToESTreeAdapter.js +0 -439
- package/dist/src/ParserOptions.js +0 -18
- package/dist/src/babel/TransformESTreeToBabel.js +0 -1123
- package/dist/src/estree/StripFlowTypes.js +0 -175
- package/dist/src/estree/StripFlowTypesForBabel.js +0 -215
- package/dist/src/estree/TransformComponentSyntax.js +0 -788
- package/dist/src/estree/TransformEnumSyntax.js +0 -106
- package/dist/src/estree/TransformMatchSyntax.js +0 -1006
- package/dist/src/generated/ESTreeVisitorKeys.js +0 -220
- package/dist/src/generated/ParserVisitorKeys.js +0 -794
- package/dist/src/getModuleDocblock.js +0 -112
- package/dist/src/transform/SimpleTransform.js +0 -136
- package/dist/src/transform/astArrayMutationHelpers.js +0 -62
- package/dist/src/transform/astNodeMutationHelpers.js +0 -200
- package/dist/src/traverse/SimpleTraverser.js +0 -137
- package/dist/src/traverse/getVisitorKeys.js +0 -37
- package/dist/src/utils/Builders.js +0 -191
- package/dist/src/utils/GenID.js +0 -41
- package/dist/src/utils/createSyntaxError.js +0 -25
- package/dist/src/utils/mutateESTreeASTForPrettier.js +0 -127
- package/dist/transform/SimpleTransform.js +0 -136
- package/dist/transform/SimpleTransform.js.flow +0 -169
- package/dist/transform/astArrayMutationHelpers.js +0 -62
- package/dist/transform/astArrayMutationHelpers.js.flow +0 -71
- package/dist/transform/astNodeMutationHelpers.js +0 -200
- package/dist/transform/astNodeMutationHelpers.js.flow +0 -246
- package/dist/traverse/SimpleTraverser.js +0 -137
- package/dist/traverse/SimpleTraverser.js.flow +0 -133
- package/dist/traverse/getVisitorKeys.js +0 -37
- package/dist/traverse/getVisitorKeys.js.flow +0 -36
- package/dist/utils/Builders.js +0 -191
- package/dist/utils/Builders.js.flow +0 -218
- package/dist/utils/GenID.js +0 -41
- package/dist/utils/GenID.js.flow +0 -38
- package/dist/utils/createSyntaxError.js +0 -25
- package/dist/utils/createSyntaxError.js.flow +0 -24
- package/dist/utils/mutateESTreeASTForPrettier.js +0 -127
- package/dist/utils/mutateESTreeASTForPrettier.js.flow +0 -130
|
@@ -1,24 +0,0 @@
|
|
|
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
|
-
import type {ESNode} from 'hermes-estree';
|
|
14
|
-
|
|
15
|
-
export function createSyntaxError(node: ESNode, err: string): SyntaxError {
|
|
16
|
-
const syntaxError = new SyntaxError(err);
|
|
17
|
-
// $FlowExpectedError[prop-missing]
|
|
18
|
-
syntaxError.loc = {
|
|
19
|
-
line: node.loc.start.line,
|
|
20
|
-
column: node.loc.start.column,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
return syntaxError;
|
|
24
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
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
|
-
*/
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
Object.defineProperty(exports, "__esModule", {
|
|
13
|
-
value: true
|
|
14
|
-
});
|
|
15
|
-
exports.default = mutate;
|
|
16
|
-
|
|
17
|
-
var _SimpleTransform = require("../transform/SimpleTransform");
|
|
18
|
-
|
|
19
|
-
// https://github.com/prettier/prettier/blob/d962466a828f8ef51435e3e8840178d90b7ec6cd/src/language-js/parse/postprocess/index.js#L161-L182
|
|
20
|
-
function transformChainExpression(node, comments) {
|
|
21
|
-
if (comments != null) {
|
|
22
|
-
var _node$comments;
|
|
23
|
-
|
|
24
|
-
// $FlowExpectedError[prop-missing]
|
|
25
|
-
const joinedComments = comments.concat((_node$comments = node.comments) != null ? _node$comments : []); // $FlowExpectedError[prop-missing]
|
|
26
|
-
// $FlowFixMe[cannot-write]
|
|
27
|
-
|
|
28
|
-
node.comments = joinedComments;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
switch (node.type) {
|
|
32
|
-
case 'CallExpression':
|
|
33
|
-
// $FlowExpectedError[cannot-spread-interface]
|
|
34
|
-
return { ...node,
|
|
35
|
-
type: 'OptionalCallExpression',
|
|
36
|
-
callee: transformChainExpression(node.callee)
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
case 'MemberExpression':
|
|
40
|
-
// $FlowExpectedError[cannot-spread-interface]
|
|
41
|
-
return { ...node,
|
|
42
|
-
type: 'OptionalMemberExpression',
|
|
43
|
-
object: transformChainExpression(node.object)
|
|
44
|
-
};
|
|
45
|
-
// No default
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return node;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function mutate(rootNode, visitorKeys) {
|
|
52
|
-
// Since we don't return the result of `transform` we need to be careful not to replace the Program root node.
|
|
53
|
-
_SimpleTransform.SimpleTransform.transform(rootNode, {
|
|
54
|
-
transform(node) {
|
|
55
|
-
// prettier fully expects the parent pointers are NOT set and
|
|
56
|
-
// certain cases can crash due to prettier infinite-looping
|
|
57
|
-
// whilst naively traversing the parent property
|
|
58
|
-
// https://github.com/prettier/prettier/issues/11793
|
|
59
|
-
// Note: Only needed for prettier V2, this is supported in V3
|
|
60
|
-
if (node.parent) {
|
|
61
|
-
// $FlowExpectedError[cannot-write]
|
|
62
|
-
delete node.parent;
|
|
63
|
-
} // prettier currently relies on the AST being in the old-school, deprecated AST format for optional chaining
|
|
64
|
-
// so we have to apply their transform to our AST so it can actually format it.
|
|
65
|
-
// Note: Only needed for prettier V2, this is supported in V3
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (node.type === 'ChainExpression') {
|
|
69
|
-
// $FlowFixMe[prop-missing]
|
|
70
|
-
return transformChainExpression(node.expression, node == null ? void 0 : node.comments);
|
|
71
|
-
} // Prettier currently relies on comparing the `node` vs `node.value` start positions to know if an
|
|
72
|
-
// `ObjectTypeProperty` is a method or not (instead of using the `node.method` boolean). To correctly print
|
|
73
|
-
// the node when its not a method we need the start position to be different from the `node.value`s start
|
|
74
|
-
// position.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (node.type === 'ObjectTypeProperty') {
|
|
78
|
-
if (node.method === false && node.kind === 'init' && node.range[0] === 1 && node.value.range[0] === 1) {
|
|
79
|
-
// $FlowExpectedError[cannot-write]
|
|
80
|
-
// $FlowExpectedError[cannot-spread-interface]
|
|
81
|
-
node.value = { ...node.value,
|
|
82
|
-
range: [2, node.value.range[1]]
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return node;
|
|
87
|
-
} // Prettier currently relies on comparing the the start positions to know if the import/export specifier should have a
|
|
88
|
-
// rename (eg `Name` vs `Name as Name`) when the name is exactly the same
|
|
89
|
-
// So we need to ensure that the range is always the same to avoid the useless code printing
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (node.type === 'ImportSpecifier') {
|
|
93
|
-
if (node.local.name === node.imported.name) {
|
|
94
|
-
if (node.local.range == null) {
|
|
95
|
-
// for our TS-ast printing which has no locs
|
|
96
|
-
// $FlowExpectedError[cannot-write]
|
|
97
|
-
node.local.range = [0, 0];
|
|
98
|
-
} // $FlowExpectedError[cannot-write]
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
node.imported.range = [...node.local.range];
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return node;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (node.type === 'ExportSpecifier') {
|
|
108
|
-
if (node.local.name === node.exported.name) {
|
|
109
|
-
if (node.local.range == null) {
|
|
110
|
-
// for our TS-ast printing which has no locs
|
|
111
|
-
// $FlowExpectedError[cannot-write]
|
|
112
|
-
node.local.range = [0, 0];
|
|
113
|
-
} // $FlowExpectedError[cannot-write]
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
node.exported.range = [...node.local.range];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return node;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return node;
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
visitorKeys
|
|
126
|
-
});
|
|
127
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
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
|
-
import type {ESNode, Program, Comment} from 'hermes-estree';
|
|
14
|
-
import type {VisitorKeysType} from '../traverse/getVisitorKeys';
|
|
15
|
-
import {SimpleTransform} from '../transform/SimpleTransform';
|
|
16
|
-
|
|
17
|
-
// https://github.com/prettier/prettier/blob/d962466a828f8ef51435e3e8840178d90b7ec6cd/src/language-js/parse/postprocess/index.js#L161-L182
|
|
18
|
-
function transformChainExpression(
|
|
19
|
-
node: ESNode,
|
|
20
|
-
comments: ?$ReadOnlyArray<Comment>,
|
|
21
|
-
): ESNode {
|
|
22
|
-
if (comments != null) {
|
|
23
|
-
// $FlowExpectedError[prop-missing]
|
|
24
|
-
const joinedComments = comments.concat(node.comments ?? []);
|
|
25
|
-
// $FlowExpectedError[prop-missing]
|
|
26
|
-
// $FlowFixMe[cannot-write]
|
|
27
|
-
node.comments = joinedComments;
|
|
28
|
-
}
|
|
29
|
-
switch (node.type) {
|
|
30
|
-
case 'CallExpression':
|
|
31
|
-
// $FlowExpectedError[cannot-spread-interface]
|
|
32
|
-
return {
|
|
33
|
-
...node,
|
|
34
|
-
type: 'OptionalCallExpression',
|
|
35
|
-
callee: transformChainExpression(node.callee),
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
case 'MemberExpression':
|
|
39
|
-
// $FlowExpectedError[cannot-spread-interface]
|
|
40
|
-
return {
|
|
41
|
-
...node,
|
|
42
|
-
type: 'OptionalMemberExpression',
|
|
43
|
-
object: transformChainExpression(node.object),
|
|
44
|
-
};
|
|
45
|
-
// No default
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return node;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export default function mutate(
|
|
52
|
-
rootNode: Program,
|
|
53
|
-
visitorKeys: ?VisitorKeysType,
|
|
54
|
-
): void {
|
|
55
|
-
// Since we don't return the result of `transform` we need to be careful not to replace the Program root node.
|
|
56
|
-
SimpleTransform.transform(rootNode, {
|
|
57
|
-
transform(node): ESNode | null {
|
|
58
|
-
// prettier fully expects the parent pointers are NOT set and
|
|
59
|
-
// certain cases can crash due to prettier infinite-looping
|
|
60
|
-
// whilst naively traversing the parent property
|
|
61
|
-
// https://github.com/prettier/prettier/issues/11793
|
|
62
|
-
// Note: Only needed for prettier V2, this is supported in V3
|
|
63
|
-
if (node.parent) {
|
|
64
|
-
// $FlowExpectedError[cannot-write]
|
|
65
|
-
delete node.parent;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// prettier currently relies on the AST being in the old-school, deprecated AST format for optional chaining
|
|
69
|
-
// so we have to apply their transform to our AST so it can actually format it.
|
|
70
|
-
// Note: Only needed for prettier V2, this is supported in V3
|
|
71
|
-
if (node.type === 'ChainExpression') {
|
|
72
|
-
// $FlowFixMe[prop-missing]
|
|
73
|
-
return transformChainExpression(node.expression, node?.comments);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Prettier currently relies on comparing the `node` vs `node.value` start positions to know if an
|
|
77
|
-
// `ObjectTypeProperty` is a method or not (instead of using the `node.method` boolean). To correctly print
|
|
78
|
-
// the node when its not a method we need the start position to be different from the `node.value`s start
|
|
79
|
-
// position.
|
|
80
|
-
if (node.type === 'ObjectTypeProperty') {
|
|
81
|
-
if (
|
|
82
|
-
node.method === false &&
|
|
83
|
-
node.kind === 'init' &&
|
|
84
|
-
node.range[0] === 1 &&
|
|
85
|
-
node.value.range[0] === 1
|
|
86
|
-
) {
|
|
87
|
-
// $FlowExpectedError[cannot-write]
|
|
88
|
-
// $FlowExpectedError[cannot-spread-interface]
|
|
89
|
-
node.value = {
|
|
90
|
-
...node.value,
|
|
91
|
-
range: [2, node.value.range[1]],
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
return node;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Prettier currently relies on comparing the the start positions to know if the import/export specifier should have a
|
|
98
|
-
// rename (eg `Name` vs `Name as Name`) when the name is exactly the same
|
|
99
|
-
// So we need to ensure that the range is always the same to avoid the useless code printing
|
|
100
|
-
if (node.type === 'ImportSpecifier') {
|
|
101
|
-
if (node.local.name === node.imported.name) {
|
|
102
|
-
if (node.local.range == null) {
|
|
103
|
-
// for our TS-ast printing which has no locs
|
|
104
|
-
// $FlowExpectedError[cannot-write]
|
|
105
|
-
node.local.range = [0, 0];
|
|
106
|
-
}
|
|
107
|
-
// $FlowExpectedError[cannot-write]
|
|
108
|
-
node.imported.range = [...node.local.range];
|
|
109
|
-
}
|
|
110
|
-
return node;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (node.type === 'ExportSpecifier') {
|
|
114
|
-
if (node.local.name === node.exported.name) {
|
|
115
|
-
if (node.local.range == null) {
|
|
116
|
-
// for our TS-ast printing which has no locs
|
|
117
|
-
// $FlowExpectedError[cannot-write]
|
|
118
|
-
node.local.range = [0, 0];
|
|
119
|
-
}
|
|
120
|
-
// $FlowExpectedError[cannot-write]
|
|
121
|
-
node.exported.range = [...node.local.range];
|
|
122
|
-
}
|
|
123
|
-
return node;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return node;
|
|
127
|
-
},
|
|
128
|
-
visitorKeys,
|
|
129
|
-
});
|
|
130
|
-
}
|