hermes-transform 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 (49) hide show
  1. package/dist/generated/special-case-node-types/Comment.js +2 -2
  2. package/dist/generated/special-case-node-types/Comment.js.flow +2 -2
  3. package/dist/generated/special-case-node-types/DeclareExportDeclaration.js +3 -3
  4. package/dist/generated/special-case-node-types/DeclareExportDeclaration.js.flow +3 -3
  5. package/dist/generated/special-case-node-types/ExportNamedDeclaration.js +2 -2
  6. package/dist/generated/special-case-node-types/ExportNamedDeclaration.js.flow +2 -2
  7. package/dist/generated/special-case-node-types/ObjectTypeProperty.js +1 -1
  8. package/dist/generated/special-case-node-types/ObjectTypeProperty.js.flow +1 -1
  9. package/dist/generated/special-case-node-types/misc.js +10 -10
  10. package/dist/generated/special-case-node-types/misc.js.flow +10 -10
  11. package/dist/src/generated/special-case-node-types/Comment.js +2 -2
  12. package/dist/src/generated/special-case-node-types/DeclareExportDeclaration.js +3 -3
  13. package/dist/src/generated/special-case-node-types/ExportNamedDeclaration.js +2 -2
  14. package/dist/src/generated/special-case-node-types/ObjectTypeProperty.js +1 -1
  15. package/dist/src/generated/special-case-node-types/misc.js +10 -10
  16. package/dist/src/transform/TransformContext.js +1 -1
  17. package/dist/src/transform/comments/comments.js +9 -6
  18. package/dist/src/transform/mutations/InsertStatement.js +1 -1
  19. package/dist/src/transform/mutations/ModifyNodeInPlace.js +1 -0
  20. package/dist/src/transform/mutations/RemoveNode.js +3 -1
  21. package/dist/src/transform/mutations/ReplaceNode.js +1 -0
  22. package/dist/src/transform/mutations/ReplaceStatementWithMany.js +1 -1
  23. package/dist/src/transform/mutations/utils/getStatementParent.js +3 -1
  24. package/dist/src/transform/mutations/utils/isValidModuleDeclarationParent.js +1 -1
  25. package/dist/src/transform/print.js +21 -6
  26. package/dist/src/traverse/NodeEventGenerator.js +1 -1
  27. package/dist/transform/TransformContext.js +1 -1
  28. package/dist/transform/TransformContext.js.flow +1 -1
  29. package/dist/transform/comments/comments.js +9 -6
  30. package/dist/transform/comments/comments.js.flow +9 -6
  31. package/dist/transform/mutations/InsertStatement.js +1 -1
  32. package/dist/transform/mutations/InsertStatement.js.flow +1 -1
  33. package/dist/transform/mutations/ModifyNodeInPlace.js +1 -0
  34. package/dist/transform/mutations/ModifyNodeInPlace.js.flow +1 -0
  35. package/dist/transform/mutations/RemoveNode.js +3 -1
  36. package/dist/transform/mutations/RemoveNode.js.flow +3 -0
  37. package/dist/transform/mutations/ReplaceNode.js +1 -0
  38. package/dist/transform/mutations/ReplaceNode.js.flow +1 -0
  39. package/dist/transform/mutations/ReplaceStatementWithMany.js +1 -1
  40. package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +1 -1
  41. package/dist/transform/mutations/utils/getStatementParent.js +3 -1
  42. package/dist/transform/mutations/utils/getStatementParent.js.flow +2 -0
  43. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js +1 -1
  44. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js.flow +1 -1
  45. package/dist/transform/print.js +21 -6
  46. package/dist/transform/print.js.flow +19 -5
  47. package/dist/traverse/NodeEventGenerator.js +1 -1
  48. package/dist/traverse/NodeEventGenerator.js.flow +1 -1
  49. package/package.json +11 -5
@@ -19,7 +19,7 @@ var _detachedNode = require("../../detachedNode");
19
19
  */
20
20
  function LineComment(props) {
21
21
  // $FlowExpectedError[prop-missing]
22
- // $FlowExpectedError[incompatible-return]
22
+ // $FlowExpectedError[incompatible-type]
23
23
  return (0, _detachedNode.detachedProps)(undefined, {
24
24
  type: 'Line',
25
25
  value: props.value
@@ -28,7 +28,7 @@ function LineComment(props) {
28
28
 
29
29
  function BlockComment(props) {
30
30
  // $FlowExpectedError[prop-missing]
31
- // $FlowExpectedError[incompatible-return]
31
+ // $FlowExpectedError[incompatible-type]
32
32
  return (0, _detachedNode.detachedProps)(undefined, {
33
33
  type: 'Block',
34
34
  value: props.value
@@ -18,7 +18,7 @@ import {detachedProps} from '../../detachedNode';
18
18
  export type LineCommentProps = {+value: string};
19
19
  export function LineComment(props: LineCommentProps): LineCommentType {
20
20
  // $FlowExpectedError[prop-missing]
21
- // $FlowExpectedError[incompatible-return]
21
+ // $FlowExpectedError[incompatible-type]
22
22
  return detachedProps<LineCommentType>(undefined, {
23
23
  type: 'Line',
24
24
  value: props.value,
@@ -28,7 +28,7 @@ export function LineComment(props: LineCommentProps): LineCommentType {
28
28
  export type BlockCommentProps = {+value: string};
29
29
  export function BlockComment(props: BlockCommentProps): BlockCommentType {
30
30
  // $FlowExpectedError[prop-missing]
31
- // $FlowExpectedError[incompatible-return]
31
+ // $FlowExpectedError[incompatible-type]
32
32
  return detachedProps<BlockCommentType>(undefined, {
33
33
  type: 'Block',
34
34
  value: props.value,
@@ -21,7 +21,7 @@ var _detachedNode = require("../../detachedNode");
21
21
  function DeclareExportDefaultDeclaration(props) {
22
22
  const node = (0, _detachedNode.detachedProps)(props.parent, {
23
23
  type: 'DeclareExportDeclaration',
24
- // $FlowFixMe[incompatible-call]
24
+ // $FlowFixMe[incompatible-type]
25
25
  declaration: (0, _detachedNode.asDetachedNode)(props.declaration),
26
26
  specifiers: [],
27
27
  source: null,
@@ -34,7 +34,7 @@ function DeclareExportDefaultDeclaration(props) {
34
34
  function DeclareExportDeclarationNamedWithDeclaration(props) {
35
35
  const node = (0, _detachedNode.detachedProps)(props.parent, {
36
36
  type: 'DeclareExportDeclaration',
37
- // $FlowFixMe[incompatible-call]
37
+ // $FlowFixMe[incompatible-type]
38
38
  declaration: (0, _detachedNode.asDetachedNode)(props.declaration),
39
39
  specifiers: [],
40
40
  source: null,
@@ -49,7 +49,7 @@ function DeclareExportDeclarationNamedWithSpecifiers(props) {
49
49
  type: 'DeclareExportDeclaration',
50
50
  declaration: null,
51
51
  specifiers: props.specifiers.map(n => (0, _detachedNode.asDetachedNode)(n)),
52
- // $FlowFixMe[incompatible-call]
52
+ // $FlowFixMe[incompatible-type]
53
53
  source: (0, _detachedNode.asDetachedNode)(props.source),
54
54
  default: false
55
55
  });
@@ -35,7 +35,7 @@ export function DeclareExportDefaultDeclaration(props: {
35
35
  props.parent,
36
36
  {
37
37
  type: 'DeclareExportDeclaration',
38
- // $FlowFixMe[incompatible-call]
38
+ // $FlowFixMe[incompatible-type]
39
39
  declaration: asDetachedNode(props.declaration),
40
40
  specifiers: [],
41
41
  source: null,
@@ -59,7 +59,7 @@ export function DeclareExportDeclarationNamedWithDeclaration(props: {
59
59
  props.parent,
60
60
  {
61
61
  type: 'DeclareExportDeclaration',
62
- // $FlowFixMe[incompatible-call]
62
+ // $FlowFixMe[incompatible-type]
63
63
  declaration: asDetachedNode(props.declaration),
64
64
  specifiers: [],
65
65
  source: null,
@@ -90,7 +90,7 @@ export function DeclareExportDeclarationNamedWithSpecifiers(props: {
90
90
  type: 'DeclareExportDeclaration',
91
91
  declaration: null,
92
92
  specifiers: props.specifiers.map(n => asDetachedNode(n)),
93
- // $FlowFixMe[incompatible-call]
93
+ // $FlowFixMe[incompatible-type]
94
94
  source: asDetachedNode(props.source),
95
95
  default: false,
96
96
  },
@@ -20,7 +20,7 @@ var _detachedNode = require("../../detachedNode");
20
20
  function ExportNamedDeclarationWithDeclaration(props) {
21
21
  const node = (0, _detachedNode.detachedProps)(props.parent, {
22
22
  type: 'ExportNamedDeclaration',
23
- // $FlowFixMe[incompatible-call]
23
+ // $FlowFixMe[incompatible-type]
24
24
  declaration: (0, _detachedNode.asDetachedNode)(props.declaration),
25
25
  specifiers: [],
26
26
  source: null,
@@ -35,7 +35,7 @@ function ExportNamedDeclarationWithSpecifiers(props) {
35
35
  type: 'ExportNamedDeclaration',
36
36
  declaration: null,
37
37
  specifiers: props.specifiers.map(n => (0, _detachedNode.asDetachedNode)(n)),
38
- // $FlowFixMe[incompatible-call]
38
+ // $FlowFixMe[incompatible-type]
39
39
  source: (0, _detachedNode.asDetachedNode)(props.source),
40
40
  exportKind: props.exportKind
41
41
  });
@@ -35,7 +35,7 @@ export function ExportNamedDeclarationWithDeclaration(props: {
35
35
  props.parent,
36
36
  {
37
37
  type: 'ExportNamedDeclaration',
38
- // $FlowFixMe[incompatible-call]
38
+ // $FlowFixMe[incompatible-type]
39
39
  declaration: asDetachedNode(props.declaration),
40
40
  specifiers: [],
41
41
  source: null,
@@ -67,7 +67,7 @@ export function ExportNamedDeclarationWithSpecifiers(props: {
67
67
  type: 'ExportNamedDeclaration',
68
68
  declaration: null,
69
69
  specifiers: props.specifiers.map(n => asDetachedNode(n)),
70
- // $FlowFixMe[incompatible-call]
70
+ // $FlowFixMe[incompatible-type]
71
71
  source: asDetachedNode(props.source),
72
72
  exportKind: props.exportKind,
73
73
  },
@@ -48,7 +48,7 @@ function ObjectTypePropertySignature(props) {
48
48
  proto: (_props$proto2 = props.proto) != null ? _props$proto2 : false,
49
49
  static: (_props$static2 = props.static) != null ? _props$static2 : false,
50
50
  value: (0, _detachedNode.asDetachedNode)(props.value),
51
- // $FlowFixMe[incompatible-call]
51
+ // $FlowFixMe[incompatible-type]
52
52
  variance: (0, _detachedNode.asDetachedNode)(props.variance)
53
53
  });
54
54
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
@@ -72,7 +72,7 @@ export function ObjectTypePropertySignature(props: {
72
72
  proto: props.proto ?? false,
73
73
  static: props.static ?? false,
74
74
  value: asDetachedNode(props.value),
75
- // $FlowFixMe[incompatible-call]
75
+ // $FlowFixMe[incompatible-type]
76
76
  variance: asDetachedNode(props.variance),
77
77
  });
78
78
  setParentPointersInDirectChildren(node);
@@ -31,11 +31,11 @@ function ArrowFunctionExpression(props) {
31
31
  expression: props.body.type !== 'BlockStatement',
32
32
  params: props.params.map(n => (0, _detachedNode.asDetachedNode)(n)),
33
33
  body: (0, _detachedNode.asDetachedNode)(props.body),
34
- // $FlowFixMe[incompatible-call]
34
+ // $FlowFixMe[incompatible-type]
35
35
  typeParameters: (0, _detachedNode.asDetachedNode)(props.typeParameters),
36
- // $FlowFixMe[incompatible-call]
36
+ // $FlowFixMe[incompatible-type]
37
37
  returnType: (0, _detachedNode.asDetachedNode)(props.returnType),
38
- // $FlowFixMe[incompatible-call]
38
+ // $FlowFixMe[incompatible-type]
39
39
  predicate: (0, _detachedNode.asDetachedNode)(props.predicate),
40
40
  async: props.async
41
41
  });
@@ -48,13 +48,13 @@ function ClassDeclaration(props) {
48
48
 
49
49
  const node = (0, _detachedNode.detachedProps)(props.parent, {
50
50
  type: 'ClassDeclaration',
51
- // $FlowFixMe[incompatible-call]
51
+ // $FlowFixMe[incompatible-type]
52
52
  id: (0, _detachedNode.asDetachedNode)(props.id),
53
- // $FlowFixMe[incompatible-call]
53
+ // $FlowFixMe[incompatible-type]
54
54
  typeParameters: (0, _detachedNode.asDetachedNode)(props.typeParameters),
55
- // $FlowFixMe[incompatible-call]
55
+ // $FlowFixMe[incompatible-type]
56
56
  superClass: (0, _detachedNode.asDetachedNode)(props.superClass),
57
- // $FlowFixMe[incompatible-call]
57
+ // $FlowFixMe[incompatible-type]
58
58
  superTypeParameters: (0, _detachedNode.asDetachedNode)(props.superTypeParameters),
59
59
  decorators: ((_props$decorators = props.decorators) != null ? _props$decorators : []).map(n => (0, _detachedNode.asDetachedNode)(n)),
60
60
  implements: ((_props$implements = props.implements) != null ? _props$implements : []).map(n => (0, _detachedNode.asDetachedNode)(n)),
@@ -85,7 +85,7 @@ function Identifier(props) {
85
85
  type: 'Identifier',
86
86
  name: props.name,
87
87
  optional: (_props$optional = props.optional) != null ? _props$optional : false,
88
- // $FlowFixMe[incompatible-call]
88
+ // $FlowFixMe[incompatible-type]
89
89
  typeAnnotation: (0, _detachedNode.asDetachedNode)(props.typeAnnotation)
90
90
  });
91
91
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
@@ -103,7 +103,7 @@ function Program(props) {
103
103
  body: props.body.map(n => (0, _detachedNode.asDetachedNode)(n)),
104
104
  tokens: (_props$tokens = props.tokens) != null ? _props$tokens : [],
105
105
  comments: (_props$comments = props.comments) != null ? _props$comments : [],
106
- interpreter: props.interpreter != null ? // $FlowFixMe[incompatible-call]
106
+ interpreter: props.interpreter != null ? // $FlowFixMe[incompatible-type]
107
107
  (0, _detachedNode.asDetachedNode)({
108
108
  type: 'InterpreterDirective',
109
109
  value: props.interpreter
@@ -126,7 +126,7 @@ function DeclareFunction(props) {
126
126
  typeAnnotation: (0, _detachedNode.asDetachedNode)(props.functionType)
127
127
  })
128
128
  }),
129
- // $FlowFixMe[incompatible-call]
129
+ // $FlowFixMe[incompatible-type]
130
130
  predicate: (0, _detachedNode.asDetachedNode)(props.predicate)
131
131
  });
132
132
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
@@ -65,11 +65,11 @@ export function ArrowFunctionExpression(props: {
65
65
  expression: props.body.type !== 'BlockStatement',
66
66
  params: props.params.map(n => asDetachedNode(n)),
67
67
  body: asDetachedNode(props.body),
68
- // $FlowFixMe[incompatible-call]
68
+ // $FlowFixMe[incompatible-type]
69
69
  typeParameters: asDetachedNode(props.typeParameters),
70
- // $FlowFixMe[incompatible-call]
70
+ // $FlowFixMe[incompatible-type]
71
71
  returnType: asDetachedNode(props.returnType),
72
- // $FlowFixMe[incompatible-call]
72
+ // $FlowFixMe[incompatible-type]
73
73
  predicate: asDetachedNode(props.predicate),
74
74
  async: props.async,
75
75
  });
@@ -100,13 +100,13 @@ export function ClassDeclaration(props: {
100
100
  }): DetachedNode<ClassDeclarationType> {
101
101
  const node = detachedProps<ClassDeclarationType>(props.parent, {
102
102
  type: 'ClassDeclaration',
103
- // $FlowFixMe[incompatible-call]
103
+ // $FlowFixMe[incompatible-type]
104
104
  id: asDetachedNode(props.id),
105
- // $FlowFixMe[incompatible-call]
105
+ // $FlowFixMe[incompatible-type]
106
106
  typeParameters: asDetachedNode(props.typeParameters),
107
- // $FlowFixMe[incompatible-call]
107
+ // $FlowFixMe[incompatible-type]
108
108
  superClass: asDetachedNode(props.superClass),
109
- // $FlowFixMe[incompatible-call]
109
+ // $FlowFixMe[incompatible-type]
110
110
  superTypeParameters: asDetachedNode(props.superTypeParameters),
111
111
  decorators: (props.decorators ?? []).map(n => asDetachedNode(n)),
112
112
  implements: (props.implements ?? []).map(n => asDetachedNode(n)),
@@ -151,7 +151,7 @@ export function Identifier(props: {
151
151
  type: 'Identifier',
152
152
  name: props.name,
153
153
  optional: props.optional ?? false,
154
- // $FlowFixMe[incompatible-call]
154
+ // $FlowFixMe[incompatible-type]
155
155
  typeAnnotation: asDetachedNode(props.typeAnnotation),
156
156
  });
157
157
  setParentPointersInDirectChildren(node);
@@ -179,7 +179,7 @@ export function Program(props: {
179
179
  comments: props.comments ?? [],
180
180
  interpreter:
181
181
  props.interpreter != null
182
- ? // $FlowFixMe[incompatible-call]
182
+ ? // $FlowFixMe[incompatible-type]
183
183
  asDetachedNode<InterpreterDirectiveType>({
184
184
  type: 'InterpreterDirective',
185
185
  value: props.interpreter,
@@ -211,7 +211,7 @@ export function DeclareFunction(props: {
211
211
  typeAnnotation: asDetachedNode(props.functionType),
212
212
  }),
213
213
  }),
214
- // $FlowFixMe[incompatible-call]
214
+ // $FlowFixMe[incompatible-type]
215
215
  predicate: asDetachedNode(props.predicate),
216
216
  });
217
217
  setParentPointersInDirectChildren(node);
@@ -19,7 +19,7 @@ var _detachedNode = require("../../detachedNode");
19
19
  */
20
20
  function LineComment(props) {
21
21
  // $FlowExpectedError[prop-missing]
22
- // $FlowExpectedError[incompatible-return]
22
+ // $FlowExpectedError[incompatible-type]
23
23
  return (0, _detachedNode.detachedProps)(undefined, {
24
24
  type: 'Line',
25
25
  value: props.value
@@ -28,7 +28,7 @@ function LineComment(props) {
28
28
 
29
29
  function BlockComment(props) {
30
30
  // $FlowExpectedError[prop-missing]
31
- // $FlowExpectedError[incompatible-return]
31
+ // $FlowExpectedError[incompatible-type]
32
32
  return (0, _detachedNode.detachedProps)(undefined, {
33
33
  type: 'Block',
34
34
  value: props.value
@@ -21,7 +21,7 @@ var _detachedNode = require("../../detachedNode");
21
21
  function DeclareExportDefaultDeclaration(props) {
22
22
  const node = (0, _detachedNode.detachedProps)(props.parent, {
23
23
  type: 'DeclareExportDeclaration',
24
- // $FlowFixMe[incompatible-call]
24
+ // $FlowFixMe[incompatible-type]
25
25
  declaration: (0, _detachedNode.asDetachedNode)(props.declaration),
26
26
  specifiers: [],
27
27
  source: null,
@@ -34,7 +34,7 @@ function DeclareExportDefaultDeclaration(props) {
34
34
  function DeclareExportDeclarationNamedWithDeclaration(props) {
35
35
  const node = (0, _detachedNode.detachedProps)(props.parent, {
36
36
  type: 'DeclareExportDeclaration',
37
- // $FlowFixMe[incompatible-call]
37
+ // $FlowFixMe[incompatible-type]
38
38
  declaration: (0, _detachedNode.asDetachedNode)(props.declaration),
39
39
  specifiers: [],
40
40
  source: null,
@@ -49,7 +49,7 @@ function DeclareExportDeclarationNamedWithSpecifiers(props) {
49
49
  type: 'DeclareExportDeclaration',
50
50
  declaration: null,
51
51
  specifiers: props.specifiers.map(n => (0, _detachedNode.asDetachedNode)(n)),
52
- // $FlowFixMe[incompatible-call]
52
+ // $FlowFixMe[incompatible-type]
53
53
  source: (0, _detachedNode.asDetachedNode)(props.source),
54
54
  default: false
55
55
  });
@@ -20,7 +20,7 @@ var _detachedNode = require("../../detachedNode");
20
20
  function ExportNamedDeclarationWithDeclaration(props) {
21
21
  const node = (0, _detachedNode.detachedProps)(props.parent, {
22
22
  type: 'ExportNamedDeclaration',
23
- // $FlowFixMe[incompatible-call]
23
+ // $FlowFixMe[incompatible-type]
24
24
  declaration: (0, _detachedNode.asDetachedNode)(props.declaration),
25
25
  specifiers: [],
26
26
  source: null,
@@ -35,7 +35,7 @@ function ExportNamedDeclarationWithSpecifiers(props) {
35
35
  type: 'ExportNamedDeclaration',
36
36
  declaration: null,
37
37
  specifiers: props.specifiers.map(n => (0, _detachedNode.asDetachedNode)(n)),
38
- // $FlowFixMe[incompatible-call]
38
+ // $FlowFixMe[incompatible-type]
39
39
  source: (0, _detachedNode.asDetachedNode)(props.source),
40
40
  exportKind: props.exportKind
41
41
  });
@@ -48,7 +48,7 @@ function ObjectTypePropertySignature(props) {
48
48
  proto: (_props$proto2 = props.proto) != null ? _props$proto2 : false,
49
49
  static: (_props$static2 = props.static) != null ? _props$static2 : false,
50
50
  value: (0, _detachedNode.asDetachedNode)(props.value),
51
- // $FlowFixMe[incompatible-call]
51
+ // $FlowFixMe[incompatible-type]
52
52
  variance: (0, _detachedNode.asDetachedNode)(props.variance)
53
53
  });
54
54
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
@@ -31,11 +31,11 @@ function ArrowFunctionExpression(props) {
31
31
  expression: props.body.type !== 'BlockStatement',
32
32
  params: props.params.map(n => (0, _detachedNode.asDetachedNode)(n)),
33
33
  body: (0, _detachedNode.asDetachedNode)(props.body),
34
- // $FlowFixMe[incompatible-call]
34
+ // $FlowFixMe[incompatible-type]
35
35
  typeParameters: (0, _detachedNode.asDetachedNode)(props.typeParameters),
36
- // $FlowFixMe[incompatible-call]
36
+ // $FlowFixMe[incompatible-type]
37
37
  returnType: (0, _detachedNode.asDetachedNode)(props.returnType),
38
- // $FlowFixMe[incompatible-call]
38
+ // $FlowFixMe[incompatible-type]
39
39
  predicate: (0, _detachedNode.asDetachedNode)(props.predicate),
40
40
  async: props.async
41
41
  });
@@ -48,13 +48,13 @@ function ClassDeclaration(props) {
48
48
 
49
49
  const node = (0, _detachedNode.detachedProps)(props.parent, {
50
50
  type: 'ClassDeclaration',
51
- // $FlowFixMe[incompatible-call]
51
+ // $FlowFixMe[incompatible-type]
52
52
  id: (0, _detachedNode.asDetachedNode)(props.id),
53
- // $FlowFixMe[incompatible-call]
53
+ // $FlowFixMe[incompatible-type]
54
54
  typeParameters: (0, _detachedNode.asDetachedNode)(props.typeParameters),
55
- // $FlowFixMe[incompatible-call]
55
+ // $FlowFixMe[incompatible-type]
56
56
  superClass: (0, _detachedNode.asDetachedNode)(props.superClass),
57
- // $FlowFixMe[incompatible-call]
57
+ // $FlowFixMe[incompatible-type]
58
58
  superTypeParameters: (0, _detachedNode.asDetachedNode)(props.superTypeParameters),
59
59
  decorators: ((_props$decorators = props.decorators) != null ? _props$decorators : []).map(n => (0, _detachedNode.asDetachedNode)(n)),
60
60
  implements: ((_props$implements = props.implements) != null ? _props$implements : []).map(n => (0, _detachedNode.asDetachedNode)(n)),
@@ -85,7 +85,7 @@ function Identifier(props) {
85
85
  type: 'Identifier',
86
86
  name: props.name,
87
87
  optional: (_props$optional = props.optional) != null ? _props$optional : false,
88
- // $FlowFixMe[incompatible-call]
88
+ // $FlowFixMe[incompatible-type]
89
89
  typeAnnotation: (0, _detachedNode.asDetachedNode)(props.typeAnnotation)
90
90
  });
91
91
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
@@ -103,7 +103,7 @@ function Program(props) {
103
103
  body: props.body.map(n => (0, _detachedNode.asDetachedNode)(n)),
104
104
  tokens: (_props$tokens = props.tokens) != null ? _props$tokens : [],
105
105
  comments: (_props$comments = props.comments) != null ? _props$comments : [],
106
- interpreter: props.interpreter != null ? // $FlowFixMe[incompatible-call]
106
+ interpreter: props.interpreter != null ? // $FlowFixMe[incompatible-type]
107
107
  (0, _detachedNode.asDetachedNode)({
108
108
  type: 'InterpreterDirective',
109
109
  value: props.interpreter
@@ -126,7 +126,7 @@ function DeclareFunction(props) {
126
126
  typeAnnotation: (0, _detachedNode.asDetachedNode)(props.functionType)
127
127
  })
128
128
  }),
129
- // $FlowFixMe[incompatible-call]
129
+ // $FlowFixMe[incompatible-type]
130
130
  predicate: (0, _detachedNode.asDetachedNode)(props.predicate)
131
131
  });
132
132
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
@@ -76,7 +76,7 @@ function getTransformContext() {
76
76
  const node = node_;
77
77
 
78
78
  if (node == null) {
79
- // $FlowExpectedError[incompatible-return]
79
+ // $FlowExpectedError[incompatible-type]
80
80
  return node;
81
81
  }
82
82
 
@@ -128,14 +128,17 @@ function cloneJSDocCommentsToNewNode(oldNode, newNode) {
128
128
  }
129
129
 
130
130
  function setCommentsOnNode(node, comments) {
131
- // $FlowExpectedError - this property is secretly added by prettier.
131
+ // $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
132
+ // $FlowExpectedError[incompatible-use] - this property is secretly added by prettier.
133
+ // $FlowExpectedError[cannot-write] - this property is secretly added by prettier.
132
134
  node.comments = comments;
133
135
  }
134
136
 
135
137
  function getCommentsForNode(node) {
136
138
  var _node$comments;
137
139
 
138
- // $FlowExpectedError - this property is secretly added by prettier.
140
+ // $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
141
+ // $FlowExpectedError[incompatible-use] - this property is secretly added by prettier.
139
142
  return (_node$comments = node.comments) != null ? _node$comments : [];
140
143
  }
141
144
 
@@ -146,12 +149,12 @@ function isAttachedComment(comment) {
146
149
  }
147
150
 
148
151
  function isLeadingComment(comment) {
149
- // $FlowExpectedError - this property is secretly added by prettier.
152
+ // $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
150
153
  return comment.leading === true;
151
154
  }
152
155
 
153
156
  function isTrailingComment(comment) {
154
- // $FlowExpectedError - this property is secretly added by prettier.
157
+ // $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
155
158
  return comment.trailing === true;
156
159
  }
157
160
 
@@ -182,7 +185,7 @@ function addComment(node, comment, placement) {
182
185
  }
183
186
 
184
187
  function cloneComment(comment) {
185
- // $FlowExpectedError[incompatible-return]
188
+ // $FlowExpectedError[incompatible-type]
186
189
  return {
187
190
  type: comment.type,
188
191
  value: comment.value,
@@ -192,7 +195,7 @@ function cloneComment(comment) {
192
195
  }
193
196
 
194
197
  function cloneCommentWithMarkers(comment) {
195
- // $FlowExpectedError[incompatible-return]
198
+ // $FlowExpectedError[incompatible-type]
196
199
  return {
197
200
  type: comment.type,
198
201
  value: comment.value,
@@ -72,7 +72,7 @@ function performInsertStatementMutation(mutationContext, mutation) {
72
72
  return insertionParent.parent;
73
73
  }
74
74
 
75
- const statementsToInsert = // $FlowExpectedError[incompatible-cast] -- this is enforced by isValidModuleDeclarationParent above
75
+ const statementsToInsert = // $FlowExpectedError[incompatible-type] -- this is enforced by isValidModuleDeclarationParent above
76
76
  mutation.nodesToInsert;
77
77
  const {
78
78
  parent,
@@ -33,6 +33,7 @@ function performModifyNodeInPlaceMutation(mutationContext, mutation) {
33
33
 
34
34
  for (const [key, newPropValue] of Object.entries(newProps)) {
35
35
  const prevPropValue = target[key]; // If the value did not change, skip.
36
+ // $FlowFixMe[invalid-compare]
36
37
 
37
38
  if (prevPropValue === newPropValue) {
38
39
  continue;
@@ -140,6 +140,7 @@ function getRemovalParent(node) {
140
140
  case 'ObjectPattern':
141
141
  return 'properties';
142
142
  // $FlowFixMe[incompatible-type]
143
+ // $FlowFixMe[invalid-compare]
143
144
 
144
145
  case 'OptionalCallExpression':
145
146
  case 'CallExpression':
@@ -160,6 +161,7 @@ function getRemovalParent(node) {
160
161
  case 'ObjectExpression':
161
162
  return 'properties';
162
163
  // $FlowFixMe[incompatible-type]
164
+ // $FlowFixMe[invalid-compare]
163
165
 
164
166
  case 'OptionalCallExpression':
165
167
  case 'CallExpression':
@@ -178,7 +180,7 @@ function getRemovalParent(node) {
178
180
  const targetIndex = (() => {
179
181
  // $FlowExpectedError[prop-missing]
180
182
  const arr = node.parent[key];
181
- const idx = arr.indexOf(node);
183
+ const idx = arr.indexOf(node); // $FlowFixMe[invalid-compare]
182
184
 
183
185
  if (idx === -1) {
184
186
  throw new _Errors.InvalidRemovalError(`Could not find target in array of \`${node.parent.type}.${key}\`.`);
@@ -63,6 +63,7 @@ function getParentKey(target) {
63
63
  const child = parent[key];
64
64
 
65
65
  if ((0, _hermesParser.isNode)(child)) {
66
+ // $FlowFixMe[invalid-compare]
66
67
  if (child === target) {
67
68
  return {
68
69
  type: 'single',
@@ -67,7 +67,7 @@ function performReplaceStatementWithManyMutation(mutationContext, mutation) {
67
67
  return replacementParent.parent;
68
68
  }
69
69
 
70
- const statementsToReplaceWith = // $FlowExpectedError[incompatible-cast] -- this is enforced by isValidModuleDeclarationParent above
70
+ const statementsToReplaceWith = // $FlowExpectedError[incompatible-type] -- this is enforced by isValidModuleDeclarationParent above
71
71
  mutation.nodesToReplaceWith; // we need to wrap the nodes in a BlockStatement as before there was only 1 node
72
72
 
73
73
  const blockStatement = t.BlockStatement({
@@ -22,7 +22,8 @@ function getStatementParent(target) {
22
22
  // $FlowExpectedError[prop-missing]
23
23
  const value = parentWithType[key];
24
24
 
25
- if (value === target || Array.isArray(value) && value.includes(target)) {
25
+ if ( // $FlowFixMe[invalid-compare]
26
+ value === target || Array.isArray(value) && value.includes(target)) {
26
27
  throw new _Errors.InvalidStatementError(`Attempted to insert a statement into \`${parentWithType.type}.${key}\`.`);
27
28
  }
28
29
  }
@@ -135,6 +136,7 @@ function getStatementParent(target) {
135
136
 
136
137
  if ( // array insertions are already validated by the getAssertedIndex function
137
138
  result.targetIndex == null && // $FlowExpectedError[prop-missing]
139
+ // $FlowFixMe[invalid-compare]
138
140
  result.parent[result.key] !== target) {
139
141
  throw new _Errors.InvalidStatementError(`Expected to find the target "${target.type}" on the "${result.parent.type}.${result.key}", but found a different node. ` + 'This likely means that you attempted to mutate around the target after it was deleted/replaced.');
140
142
  }
@@ -31,7 +31,7 @@ function isValidModuleDeclarationParent(target, nodesToInsertOrReplace) {
31
31
  }
32
32
 
33
33
  for (const node of nodesToInsertOrReplace) {
34
- if (!isModuleDeclaration( // $FlowExpectedError[incompatible-cast]
34
+ if (!isModuleDeclaration( // $FlowExpectedError[incompatible-type]
35
35
  node)) {
36
36
  continue;
37
37
  }
@@ -44,24 +44,39 @@ async function print(ast, originalCode, prettierOptions = {}, visitorKeys) {
44
44
 
45
45
  const codeForPrinting = (0, _comments.mutateESTreeASTCommentsForPrettier)(program, originalCode); // Fix up the AST to match what prettier expects.
46
46
 
47
- (0, _hermesParser.mutateESTreeASTForPrettier)(program, visitorKeys); // Lazy require this module as it only exists in prettier v3.
48
-
49
- const prettierFlowPlugin = require('prettier/plugins/flow');
47
+ (0, _hermesParser.mutateESTreeASTForPrettier)(program, visitorKeys);
48
+ let pluginParserName = 'flow';
49
+ let pluginParser;
50
+ let pluginPrinter;
51
+
52
+ try {
53
+ // Use prettier-plugin-hermes-parser if we can. It has latest Flow syntax support.
54
+ // $FlowExpectedError[untyped-import]
55
+ const prettierHermesPlugin = await Promise.resolve().then(() => _interopRequireWildcard(require('prettier-plugin-hermes-parser')));
56
+ pluginParser = prettierHermesPlugin.parsers.hermes;
57
+ pluginPrinter = prettierHermesPlugin.printers;
58
+ pluginParserName = 'hermes';
59
+ } catch {
60
+ const prettierFlowPlugin = require('prettier/plugins/flow');
61
+
62
+ pluginParser = prettierFlowPlugin.parsers.flow;
63
+ }
50
64
 
51
65
  return prettier.format(codeForPrinting, // $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
52
66
  { ...prettierOptions,
53
- parser: 'flow',
67
+ parser: pluginParserName,
54
68
  requirePragma: false,
55
69
  plugins: [{
56
70
  parsers: {
57
- flow: { ...prettierFlowPlugin.parsers.flow,
71
+ [pluginParserName]: { ...pluginParser,
58
72
 
59
73
  parse() {
60
74
  return program;
61
75
  }
62
76
 
63
77
  }
64
- }
78
+ },
79
+ printers: pluginPrinter
65
80
  }]
66
81
  });
67
82
  }
@@ -69,7 +69,7 @@ function getPossibleTypes(parsedSelector) {
69
69
  case 'identifier':
70
70
  if (!(parsedSelector.value in _hermesParser.FlowVisitorKeys)) {
71
71
  throw new Error(`Unexpected selector ${parsedSelector.value}`);
72
- } // $FlowExpectedError[incompatible-return]
72
+ } // $FlowExpectedError[incompatible-type]
73
73
 
74
74
 
75
75
  return [parsedSelector.value];
@@ -76,7 +76,7 @@ function getTransformContext() {
76
76
  const node = node_;
77
77
 
78
78
  if (node == null) {
79
- // $FlowExpectedError[incompatible-return]
79
+ // $FlowExpectedError[incompatible-type]
80
80
  return node;
81
81
  }
82
82
 
@@ -366,7 +366,7 @@ export function getTransformContext(): TransformContextAdditions {
366
366
  return nodes.map((node_: ?T): DetachedNode<?ESNode> => {
367
367
  const node: ?ESNode = node_;
368
368
  if (node == null) {
369
- // $FlowExpectedError[incompatible-return]
369
+ // $FlowExpectedError[incompatible-type]
370
370
  return node;
371
371
  }
372
372
  return shallowCloneNode<ESNode>(node, {});
@@ -128,14 +128,17 @@ function cloneJSDocCommentsToNewNode(oldNode, newNode) {
128
128
  }
129
129
 
130
130
  function setCommentsOnNode(node, comments) {
131
- // $FlowExpectedError - this property is secretly added by prettier.
131
+ // $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
132
+ // $FlowExpectedError[incompatible-use] - this property is secretly added by prettier.
133
+ // $FlowExpectedError[cannot-write] - this property is secretly added by prettier.
132
134
  node.comments = comments;
133
135
  }
134
136
 
135
137
  function getCommentsForNode(node) {
136
138
  var _node$comments;
137
139
 
138
- // $FlowExpectedError - this property is secretly added by prettier.
140
+ // $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
141
+ // $FlowExpectedError[incompatible-use] - this property is secretly added by prettier.
139
142
  return (_node$comments = node.comments) != null ? _node$comments : [];
140
143
  }
141
144
 
@@ -146,12 +149,12 @@ function isAttachedComment(comment) {
146
149
  }
147
150
 
148
151
  function isLeadingComment(comment) {
149
- // $FlowExpectedError - this property is secretly added by prettier.
152
+ // $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
150
153
  return comment.leading === true;
151
154
  }
152
155
 
153
156
  function isTrailingComment(comment) {
154
- // $FlowExpectedError - this property is secretly added by prettier.
157
+ // $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
155
158
  return comment.trailing === true;
156
159
  }
157
160
 
@@ -182,7 +185,7 @@ function addComment(node, comment, placement) {
182
185
  }
183
186
 
184
187
  function cloneComment(comment) {
185
- // $FlowExpectedError[incompatible-return]
188
+ // $FlowExpectedError[incompatible-type]
186
189
  return {
187
190
  type: comment.type,
188
191
  value: comment.value,
@@ -192,7 +195,7 @@ function cloneComment(comment) {
192
195
  }
193
196
 
194
197
  function cloneCommentWithMarkers(comment) {
195
- // $FlowExpectedError[incompatible-return]
198
+ // $FlowExpectedError[incompatible-type]
196
199
  return {
197
200
  type: comment.type,
198
201
  value: comment.value,
@@ -147,14 +147,17 @@ export function setCommentsOnNode(
147
147
  node: ESNode | DetachedNode<ESNode>,
148
148
  comments: $ReadOnlyArray<Comment>,
149
149
  ): void {
150
- // $FlowExpectedError - this property is secretly added by prettier.
150
+ // $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
151
+ // $FlowExpectedError[incompatible-use] - this property is secretly added by prettier.
152
+ // $FlowExpectedError[cannot-write] - this property is secretly added by prettier.
151
153
  node.comments = comments;
152
154
  }
153
155
 
154
156
  export function getCommentsForNode(
155
157
  node: ESNode | DetachedNode<ESNode>,
156
158
  ): $ReadOnlyArray<Comment> {
157
- // $FlowExpectedError - this property is secretly added by prettier.
159
+ // $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
160
+ // $FlowExpectedError[incompatible-use] - this property is secretly added by prettier.
158
161
  return node.comments ?? [];
159
162
  }
160
163
 
@@ -165,11 +168,11 @@ export function isAttachedComment(comment: Comment): boolean {
165
168
  }
166
169
 
167
170
  export function isLeadingComment(comment: Comment): boolean {
168
- // $FlowExpectedError - this property is secretly added by prettier.
171
+ // $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
169
172
  return comment.leading === true;
170
173
  }
171
174
  export function isTrailingComment(comment: Comment): boolean {
172
- // $FlowExpectedError - this property is secretly added by prettier.
175
+ // $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
173
176
  return comment.trailing === true;
174
177
  }
175
178
 
@@ -205,7 +208,7 @@ export function addComment(
205
208
  }
206
209
 
207
210
  export function cloneComment<T: Comment>(comment: T): T {
208
- // $FlowExpectedError[incompatible-return]
211
+ // $FlowExpectedError[incompatible-type]
209
212
  return {
210
213
  type: comment.type,
211
214
  value: comment.value,
@@ -215,7 +218,7 @@ export function cloneComment<T: Comment>(comment: T): T {
215
218
  }
216
219
 
217
220
  export function cloneCommentWithMarkers<T: Comment>(comment: T): T {
218
- // $FlowExpectedError[incompatible-return]
221
+ // $FlowExpectedError[incompatible-type]
219
222
  return {
220
223
  type: comment.type,
221
224
  value: comment.value,
@@ -72,7 +72,7 @@ function performInsertStatementMutation(mutationContext, mutation) {
72
72
  return insertionParent.parent;
73
73
  }
74
74
 
75
- const statementsToInsert = // $FlowExpectedError[incompatible-cast] -- this is enforced by isValidModuleDeclarationParent above
75
+ const statementsToInsert = // $FlowExpectedError[incompatible-type] -- this is enforced by isValidModuleDeclarationParent above
76
76
  mutation.nodesToInsert;
77
77
  const {
78
78
  parent,
@@ -95,7 +95,7 @@ export function performInsertStatementMutation(
95
95
  }
96
96
 
97
97
  const statementsToInsert =
98
- // $FlowExpectedError[incompatible-cast] -- this is enforced by isValidModuleDeclarationParent above
98
+ // $FlowExpectedError[incompatible-type] -- this is enforced by isValidModuleDeclarationParent above
99
99
  (mutation.nodesToInsert: $ReadOnlyArray<DetachedNode<Statement>>);
100
100
 
101
101
  const {parent, key} = insertionParent;
@@ -33,6 +33,7 @@ function performModifyNodeInPlaceMutation(mutationContext, mutation) {
33
33
 
34
34
  for (const [key, newPropValue] of Object.entries(newProps)) {
35
35
  const prevPropValue = target[key]; // If the value did not change, skip.
36
+ // $FlowFixMe[invalid-compare]
36
37
 
37
38
  if (prevPropValue === newPropValue) {
38
39
  continue;
@@ -40,6 +40,7 @@ export function performModifyNodeInPlaceMutation(
40
40
  const prevPropValue = target[key];
41
41
 
42
42
  // If the value did not change, skip.
43
+ // $FlowFixMe[invalid-compare]
43
44
  if (prevPropValue === newPropValue) {
44
45
  continue;
45
46
  }
@@ -140,6 +140,7 @@ function getRemovalParent(node) {
140
140
  case 'ObjectPattern':
141
141
  return 'properties';
142
142
  // $FlowFixMe[incompatible-type]
143
+ // $FlowFixMe[invalid-compare]
143
144
 
144
145
  case 'OptionalCallExpression':
145
146
  case 'CallExpression':
@@ -160,6 +161,7 @@ function getRemovalParent(node) {
160
161
  case 'ObjectExpression':
161
162
  return 'properties';
162
163
  // $FlowFixMe[incompatible-type]
164
+ // $FlowFixMe[invalid-compare]
163
165
 
164
166
  case 'OptionalCallExpression':
165
167
  case 'CallExpression':
@@ -178,7 +180,7 @@ function getRemovalParent(node) {
178
180
  const targetIndex = (() => {
179
181
  // $FlowExpectedError[prop-missing]
180
182
  const arr = node.parent[key];
181
- const idx = arr.indexOf(node);
183
+ const idx = arr.indexOf(node); // $FlowFixMe[invalid-compare]
182
184
 
183
185
  if (idx === -1) {
184
186
  throw new _Errors.InvalidRemovalError(`Could not find target in array of \`${node.parent.type}.${key}\`.`);
@@ -216,6 +216,7 @@ function getRemovalParent(node: RemoveNodeMutation['node']): $ReadOnly<{
216
216
  return 'properties';
217
217
 
218
218
  // $FlowFixMe[incompatible-type]
219
+ // $FlowFixMe[invalid-compare]
219
220
  case 'OptionalCallExpression':
220
221
  case 'CallExpression':
221
222
  case 'NewExpression':
@@ -247,6 +248,7 @@ function getRemovalParent(node: RemoveNodeMutation['node']): $ReadOnly<{
247
248
  return 'properties';
248
249
 
249
250
  // $FlowFixMe[incompatible-type]
251
+ // $FlowFixMe[invalid-compare]
250
252
  case 'OptionalCallExpression':
251
253
  case 'CallExpression':
252
254
  case 'NewExpression':
@@ -275,6 +277,7 @@ function getRemovalParent(node: RemoveNodeMutation['node']): $ReadOnly<{
275
277
  // $FlowExpectedError[prop-missing]
276
278
  const arr = node.parent[key];
277
279
  const idx = arr.indexOf(node);
280
+ // $FlowFixMe[invalid-compare]
278
281
  if (idx === -1) {
279
282
  throw new InvalidRemovalError(
280
283
  `Could not find target in array of \`${node.parent.type}.${key}\`.`,
@@ -63,6 +63,7 @@ function getParentKey(target) {
63
63
  const child = parent[key];
64
64
 
65
65
  if ((0, _hermesParser.isNode)(child)) {
66
+ // $FlowFixMe[invalid-compare]
66
67
  if (child === target) {
67
68
  return {
68
69
  type: 'single',
@@ -90,6 +90,7 @@ function getParentKey(target: ESNode): $ReadOnly<
90
90
  for (const key of getVisitorKeys(parent)) {
91
91
  const child = (parent: $FlowFixMe)[key];
92
92
  if (isNode(child)) {
93
+ // $FlowFixMe[invalid-compare]
93
94
  if (child === target) {
94
95
  return {type: 'single', parent, key};
95
96
  }
@@ -67,7 +67,7 @@ function performReplaceStatementWithManyMutation(mutationContext, mutation) {
67
67
  return replacementParent.parent;
68
68
  }
69
69
 
70
- const statementsToReplaceWith = // $FlowExpectedError[incompatible-cast] -- this is enforced by isValidModuleDeclarationParent above
70
+ const statementsToReplaceWith = // $FlowExpectedError[incompatible-type] -- this is enforced by isValidModuleDeclarationParent above
71
71
  mutation.nodesToReplaceWith; // we need to wrap the nodes in a BlockStatement as before there was only 1 node
72
72
 
73
73
  const blockStatement = t.BlockStatement({
@@ -88,7 +88,7 @@ export function performReplaceStatementWithManyMutation(
88
88
  }
89
89
 
90
90
  const statementsToReplaceWith =
91
- // $FlowExpectedError[incompatible-cast] -- this is enforced by isValidModuleDeclarationParent above
91
+ // $FlowExpectedError[incompatible-type] -- this is enforced by isValidModuleDeclarationParent above
92
92
  (mutation.nodesToReplaceWith: $ReadOnlyArray<DetachedNode<Statement>>);
93
93
 
94
94
  // we need to wrap the nodes in a BlockStatement as before there was only 1 node
@@ -22,7 +22,8 @@ function getStatementParent(target) {
22
22
  // $FlowExpectedError[prop-missing]
23
23
  const value = parentWithType[key];
24
24
 
25
- if (value === target || Array.isArray(value) && value.includes(target)) {
25
+ if ( // $FlowFixMe[invalid-compare]
26
+ value === target || Array.isArray(value) && value.includes(target)) {
26
27
  throw new _Errors.InvalidStatementError(`Attempted to insert a statement into \`${parentWithType.type}.${key}\`.`);
27
28
  }
28
29
  }
@@ -135,6 +136,7 @@ function getStatementParent(target) {
135
136
 
136
137
  if ( // array insertions are already validated by the getAssertedIndex function
137
138
  result.targetIndex == null && // $FlowExpectedError[prop-missing]
139
+ // $FlowFixMe[invalid-compare]
138
140
  result.parent[result.key] !== target) {
139
141
  throw new _Errors.InvalidStatementError(`Expected to find the target "${target.type}" on the "${result.parent.type}.${result.key}", but found a different node. ` + 'This likely means that you attempted to mutate around the target after it was deleted/replaced.');
140
142
  }
@@ -45,6 +45,7 @@ export function getStatementParent(
45
45
  const value = parentWithType[key];
46
46
 
47
47
  if (
48
+ // $FlowFixMe[invalid-compare]
48
49
  value === target ||
49
50
  (Array.isArray(value) && value.includes(target))
50
51
  ) {
@@ -136,6 +137,7 @@ export function getStatementParent(
136
137
  // array insertions are already validated by the getAssertedIndex function
137
138
  result.targetIndex == null &&
138
139
  // $FlowExpectedError[prop-missing]
140
+ // $FlowFixMe[invalid-compare]
139
141
  result.parent[result.key] !== target
140
142
  ) {
141
143
  throw new InvalidStatementError(
@@ -31,7 +31,7 @@ function isValidModuleDeclarationParent(target, nodesToInsertOrReplace) {
31
31
  }
32
32
 
33
33
  for (const node of nodesToInsertOrReplace) {
34
- if (!isModuleDeclaration( // $FlowExpectedError[incompatible-cast]
34
+ if (!isModuleDeclaration( // $FlowExpectedError[incompatible-type]
35
35
  node)) {
36
36
  continue;
37
37
  }
@@ -57,7 +57,7 @@ export function isValidModuleDeclarationParent(
57
57
  for (const node of nodesToInsertOrReplace) {
58
58
  if (
59
59
  !isModuleDeclaration(
60
- // $FlowExpectedError[incompatible-cast]
60
+ // $FlowExpectedError[incompatible-type]
61
61
  (node: ESNode),
62
62
  )
63
63
  ) {
@@ -44,24 +44,39 @@ async function print(ast, originalCode, prettierOptions = {}, visitorKeys) {
44
44
 
45
45
  const codeForPrinting = (0, _comments.mutateESTreeASTCommentsForPrettier)(program, originalCode); // Fix up the AST to match what prettier expects.
46
46
 
47
- (0, _hermesParser.mutateESTreeASTForPrettier)(program, visitorKeys); // Lazy require this module as it only exists in prettier v3.
48
-
49
- const prettierFlowPlugin = require('prettier/plugins/flow');
47
+ (0, _hermesParser.mutateESTreeASTForPrettier)(program, visitorKeys);
48
+ let pluginParserName = 'flow';
49
+ let pluginParser;
50
+ let pluginPrinter;
51
+
52
+ try {
53
+ // Use prettier-plugin-hermes-parser if we can. It has latest Flow syntax support.
54
+ // $FlowExpectedError[untyped-import]
55
+ const prettierHermesPlugin = await Promise.resolve().then(() => _interopRequireWildcard(require('prettier-plugin-hermes-parser')));
56
+ pluginParser = prettierHermesPlugin.parsers.hermes;
57
+ pluginPrinter = prettierHermesPlugin.printers;
58
+ pluginParserName = 'hermes';
59
+ } catch {
60
+ const prettierFlowPlugin = require('prettier/plugins/flow');
61
+
62
+ pluginParser = prettierFlowPlugin.parsers.flow;
63
+ }
50
64
 
51
65
  return prettier.format(codeForPrinting, // $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
52
66
  { ...prettierOptions,
53
- parser: 'flow',
67
+ parser: pluginParserName,
54
68
  requirePragma: false,
55
69
  plugins: [{
56
70
  parsers: {
57
- flow: { ...prettierFlowPlugin.parsers.flow,
71
+ [pluginParserName]: { ...pluginParser,
58
72
 
59
73
  parse() {
60
74
  return program;
61
75
  }
62
76
 
63
77
  }
64
- }
78
+ },
79
+ printers: pluginPrinter
65
80
  }]
66
81
  });
67
82
  }
@@ -47,25 +47,39 @@ export async function print(
47
47
  // Fix up the AST to match what prettier expects.
48
48
  mutateESTreeASTForPrettier(program, visitorKeys);
49
49
 
50
- // Lazy require this module as it only exists in prettier v3.
51
- const prettierFlowPlugin = require('prettier/plugins/flow');
50
+ let pluginParserName = 'flow';
51
+ let pluginParser;
52
+ let pluginPrinter;
53
+ try {
54
+ // Use prettier-plugin-hermes-parser if we can. It has latest Flow syntax support.
55
+ // $FlowExpectedError[untyped-import]
56
+ const prettierHermesPlugin = await import('prettier-plugin-hermes-parser');
57
+ pluginParser = prettierHermesPlugin.parsers.hermes;
58
+ pluginPrinter = prettierHermesPlugin.printers;
59
+ pluginParserName = 'hermes';
60
+ } catch {
61
+ const prettierFlowPlugin = require('prettier/plugins/flow');
62
+ pluginParser = prettierFlowPlugin.parsers.flow;
63
+ }
64
+
52
65
  return prettier.format(
53
66
  codeForPrinting,
54
67
  // $FlowExpectedError[incompatible-exact] - we don't want to create a dependency on the prettier types
55
68
  {
56
69
  ...prettierOptions,
57
- parser: 'flow',
70
+ parser: pluginParserName,
58
71
  requirePragma: false,
59
72
  plugins: [
60
73
  {
61
74
  parsers: {
62
- flow: {
63
- ...prettierFlowPlugin.parsers.flow,
75
+ [pluginParserName]: {
76
+ ...pluginParser,
64
77
  parse() {
65
78
  return program;
66
79
  },
67
80
  },
68
81
  },
82
+ printers: pluginPrinter,
69
83
  },
70
84
  ],
71
85
  },
@@ -69,7 +69,7 @@ function getPossibleTypes(parsedSelector) {
69
69
  case 'identifier':
70
70
  if (!(parsedSelector.value in _hermesParser.FlowVisitorKeys)) {
71
71
  throw new Error(`Unexpected selector ${parsedSelector.value}`);
72
- } // $FlowExpectedError[incompatible-return]
72
+ } // $FlowExpectedError[incompatible-type]
73
73
 
74
74
 
75
75
  return [parsedSelector.value];
@@ -77,7 +77,7 @@ function getPossibleTypes(parsedSelector: Selector): ?Array<ESNode['type']> {
77
77
  if (!(parsedSelector.value in FlowVisitorKeys)) {
78
78
  throw new Error(`Unexpected selector ${parsedSelector.value}`);
79
79
  }
80
- // $FlowExpectedError[incompatible-return]
80
+ // $FlowExpectedError[incompatible-type]
81
81
  return [parsedSelector.value];
82
82
 
83
83
  case 'matches': {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-transform",
3
- "version": "0.31.2",
3
+ "version": "0.32.1",
4
4
  "description": "Tools built on top of Hermes-ESTree to enable codebase transformation",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
@@ -12,13 +12,19 @@
12
12
  "@babel/code-frame": "^7.16.0",
13
13
  "esquery": "^1.4.0",
14
14
  "flow-enums-runtime": "^0.0.6",
15
- "hermes-eslint": "0.31.2",
16
- "hermes-estree": "0.31.2",
17
- "hermes-parser": "0.31.2",
15
+ "hermes-eslint": "0.32.1",
16
+ "hermes-estree": "0.32.1",
17
+ "hermes-parser": "0.32.1",
18
18
  "string-width": "4.2.3"
19
19
  },
20
20
  "peerDependencies": {
21
- "prettier": "^3.0.0"
21
+ "prettier": "^3.0.0",
22
+ "prettier-plugin-hermes-parser": "*"
23
+ },
24
+ "peerDependenciesMeta": {
25
+ "prettier-plugin-hermes-parser": {
26
+ "optional": true
27
+ }
22
28
  },
23
29
  "files": [
24
30
  "dist",