hermes-estree 0.31.2 → 0.32.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.
Files changed (82) hide show
  1. package/dist/HermesAST.js.flow +57 -0
  2. package/dist/HermesASTAdapter.js +192 -0
  3. package/dist/HermesASTAdapter.js.flow +189 -0
  4. package/dist/HermesParser.js +108 -0
  5. package/dist/HermesParser.js.flow +161 -0
  6. package/dist/HermesParserDecodeUTF8String.js +68 -0
  7. package/dist/HermesParserDecodeUTF8String.js.flow +65 -0
  8. package/dist/HermesParserDeserializer.js +242 -0
  9. package/dist/HermesParserDeserializer.js.flow +260 -0
  10. package/dist/HermesParserNodeDeserializers.js +2477 -0
  11. package/dist/HermesParserNodeDeserializers.js.flow +16 -0
  12. package/dist/HermesParserWASM.js +6 -0
  13. package/dist/HermesParserWASM.js.flow +87 -0
  14. package/dist/HermesToESTreeAdapter.js +439 -0
  15. package/dist/HermesToESTreeAdapter.js.flow +421 -0
  16. package/dist/ParserOptions.js +18 -0
  17. package/dist/ParserOptions.js.flow +41 -0
  18. package/dist/babel/TransformESTreeToBabel.js +1123 -0
  19. package/dist/babel/TransformESTreeToBabel.js.flow +1277 -0
  20. package/dist/estree/StripFlowTypes.js +175 -0
  21. package/dist/estree/StripFlowTypes.js.flow +158 -0
  22. package/dist/estree/StripFlowTypesForBabel.js +215 -0
  23. package/dist/estree/StripFlowTypesForBabel.js.flow +216 -0
  24. package/dist/estree/TransformComponentSyntax.js +788 -0
  25. package/dist/estree/TransformComponentSyntax.js.flow +864 -0
  26. package/dist/estree/TransformEnumSyntax.js +106 -0
  27. package/dist/estree/TransformEnumSyntax.js.flow +125 -0
  28. package/dist/estree/TransformMatchSyntax.js +1006 -0
  29. package/dist/estree/TransformMatchSyntax.js.flow +912 -0
  30. package/dist/generated/ESTreeVisitorKeys.js +220 -0
  31. package/dist/generated/ESTreeVisitorKeys.js.flow +15 -0
  32. package/dist/generated/ParserVisitorKeys.js +794 -0
  33. package/dist/generated/ParserVisitorKeys.js.flow +17 -0
  34. package/dist/getModuleDocblock.js +112 -0
  35. package/dist/getModuleDocblock.js.flow +118 -0
  36. package/dist/predicates.js +1 -0
  37. package/dist/predicates.js.flow +1 -0
  38. package/dist/src/HermesASTAdapter.js +192 -0
  39. package/dist/src/HermesParser.js +108 -0
  40. package/dist/src/HermesParserDecodeUTF8String.js +68 -0
  41. package/dist/src/HermesParserDeserializer.js +242 -0
  42. package/dist/src/HermesParserNodeDeserializers.js +2477 -0
  43. package/dist/src/HermesToESTreeAdapter.js +439 -0
  44. package/dist/src/ParserOptions.js +18 -0
  45. package/dist/src/babel/TransformESTreeToBabel.js +1123 -0
  46. package/dist/src/estree/StripFlowTypes.js +175 -0
  47. package/dist/src/estree/StripFlowTypesForBabel.js +215 -0
  48. package/dist/src/estree/TransformComponentSyntax.js +788 -0
  49. package/dist/src/estree/TransformEnumSyntax.js +106 -0
  50. package/dist/src/estree/TransformMatchSyntax.js +1006 -0
  51. package/dist/src/generated/ESTreeVisitorKeys.js +220 -0
  52. package/dist/src/generated/ParserVisitorKeys.js +794 -0
  53. package/dist/src/getModuleDocblock.js +112 -0
  54. package/dist/src/predicates.js +1 -0
  55. package/dist/src/transform/SimpleTransform.js +136 -0
  56. package/dist/src/transform/astArrayMutationHelpers.js +62 -0
  57. package/dist/src/transform/astNodeMutationHelpers.js +200 -0
  58. package/dist/src/traverse/SimpleTraverser.js +137 -0
  59. package/dist/src/traverse/getVisitorKeys.js +37 -0
  60. package/dist/src/utils/Builders.js +191 -0
  61. package/dist/src/utils/GenID.js +41 -0
  62. package/dist/src/utils/createSyntaxError.js +25 -0
  63. package/dist/src/utils/mutateESTreeASTForPrettier.js +127 -0
  64. package/dist/transform/SimpleTransform.js +136 -0
  65. package/dist/transform/SimpleTransform.js.flow +169 -0
  66. package/dist/transform/astArrayMutationHelpers.js +62 -0
  67. package/dist/transform/astArrayMutationHelpers.js.flow +71 -0
  68. package/dist/transform/astNodeMutationHelpers.js +200 -0
  69. package/dist/transform/astNodeMutationHelpers.js.flow +246 -0
  70. package/dist/traverse/SimpleTraverser.js +137 -0
  71. package/dist/traverse/SimpleTraverser.js.flow +133 -0
  72. package/dist/traverse/getVisitorKeys.js +37 -0
  73. package/dist/traverse/getVisitorKeys.js.flow +36 -0
  74. package/dist/utils/Builders.js +191 -0
  75. package/dist/utils/Builders.js.flow +218 -0
  76. package/dist/utils/GenID.js +41 -0
  77. package/dist/utils/GenID.js.flow +38 -0
  78. package/dist/utils/createSyntaxError.js +25 -0
  79. package/dist/utils/createSyntaxError.js.flow +24 -0
  80. package/dist/utils/mutateESTreeASTForPrettier.js +127 -0
  81. package/dist/utils/mutateESTreeASTForPrettier.js.flow +130 -0
  82. package/package.json +1 -1
@@ -0,0 +1,24 @@
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
+ }
@@ -0,0 +1,127 @@
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
+ }
@@ -0,0 +1,130 @@
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-estree",
3
- "version": "0.31.2",
3
+ "version": "0.32.1",
4
4
  "description": "Flow types for the Flow-ESTree spec produced by the hermes parser",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",