flow-parser 0.328.0 → 0.329.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.
@@ -62,6 +62,11 @@ export type FlowParserWASM = Readonly<{
62
62
  'number',
63
63
  'number',
64
64
  'number',
65
+ 'number',
66
+ 'number',
67
+ 'number',
68
+ 'number',
69
+ 'number',
65
70
  ],
66
71
  ): (
67
72
  number,
@@ -80,6 +85,11 @@ export type FlowParserWASM = Readonly<{
80
85
  number,
81
86
  CBoolean,
82
87
  CBoolean,
88
+ CBoolean,
89
+ CBoolean,
90
+ CBoolean,
91
+ number,
92
+ CBoolean,
83
93
  ) => number,
84
94
  ('hermesParseResult_free', 'void', ['number']): number => void,
85
95
  ('hermesParseResult_getError', 'string', ['number']): number => string,
@@ -0,0 +1,29 @@
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
+ import type {BaseNode, BaseToken, Program} from 'flow-estree';
12
+
13
+ export interface BabelFile extends BaseNode {
14
+ readonly type: 'File';
15
+ readonly program: Program;
16
+ readonly comments: ReadonlyArray<BabelComment>;
17
+ }
18
+
19
+ interface BabelCommentBlock extends BaseToken {
20
+ readonly type: 'CommentBlock';
21
+ readonly value: string;
22
+ }
23
+
24
+ interface BabelCommentLine extends BaseToken {
25
+ readonly type: 'CommentLine';
26
+ readonly value: string;
27
+ }
28
+
29
+ type BabelComment = BabelCommentBlock | BabelCommentLine;
package/dist/index.js CHANGED
@@ -21,7 +21,6 @@ var TransformEnumSyntax = _interopRequireWildcard(require("./estree/TransformEnu
21
21
  var TransformMatchSyntax = _interopRequireWildcard(require("./estree/TransformMatchSyntax"));
22
22
  var TransformRecordSyntax = _interopRequireWildcard(require("./estree/TransformRecordSyntax"));
23
23
  var StripFlowTypesForBabel = _interopRequireWildcard(require("./estree/StripFlowTypesForBabel"));
24
- var TransformESTreeToBabel = _interopRequireWildcard(require("./babel/TransformESTreeToBabel"));
25
24
  var StripFlowTypes = _interopRequireWildcard(require("./estree/StripFlowTypes"));
26
25
  var _ParserOptions = require("./ParserOptions");
27
26
  Object.keys(_ParserOptions).forEach(function (key) {
@@ -119,22 +118,13 @@ function getOptions(opts) {
119
118
  return options;
120
119
  }
121
120
  function parse(code, opts) {
122
- var _options$transformOpt, _options$transformOpt2;
123
121
  const options = getOptions(opts);
124
122
  if (options.flow === 'all') {
125
123
  options.enableTypes = true;
126
124
  } else {
127
125
  options.enableTypesPragmaDetection = true;
128
126
  }
129
- const estreeAST = FlowParser.parse(code, options);
130
- if (options.babel !== true) {
131
- return estreeAST;
132
- }
133
- const loweredESTreeAST = [(_options$transformOpt = options.transformOptions) != null && (_options$transformOpt2 = _options$transformOpt.TransformEnumSyntax) != null && _options$transformOpt2.enable ? TransformEnumSyntax.transformProgram : null, TransformMatchSyntax.transformProgram, TransformComponentSyntax.transformProgram, TransformRecordSyntax.transformProgram, StripFlowTypesForBabel.transformProgram].reduce((ast, transform) => {
134
- var _transform;
135
- return (_transform = transform == null ? void 0 : transform(ast, options)) != null ? _transform : ast;
136
- }, estreeAST);
137
- return TransformESTreeToBabel.transformProgram(loweredESTreeAST, options);
127
+ return FlowParser.parse(code, options);
138
128
  }
139
129
  const Transforms = exports.Transforms = {
140
130
  transformEnumSyntax: TransformEnumSyntax.transformProgram,
@@ -12,7 +12,7 @@
12
12
 
13
13
  import type {Program as ESTreeProgram} from 'flow-estree';
14
14
  import type {ParserOptions} from './ParserOptions';
15
- import type {BabelFile} from './babel/TransformESTreeToBabel';
15
+ import type {BabelFile} from './babel/BabelAST';
16
16
 
17
17
  import * as FlowParser from './FlowParser';
18
18
  import FlowVisitorKeys from './generated/ESTreeVisitorKeys';
@@ -21,7 +21,6 @@ import * as TransformEnumSyntax from './estree/TransformEnumSyntax';
21
21
  import * as TransformMatchSyntax from './estree/TransformMatchSyntax';
22
22
  import * as TransformRecordSyntax from './estree/TransformRecordSyntax';
23
23
  import * as StripFlowTypesForBabel from './estree/StripFlowTypesForBabel';
24
- import * as TransformESTreeToBabel from './babel/TransformESTreeToBabel';
25
24
  import * as StripFlowTypes from './estree/StripFlowTypes';
26
25
 
27
26
  const DEFAULTS: {flow: 'detect'} = {
@@ -140,26 +139,7 @@ export function parse(
140
139
  // ESTree loc/range. Optional-chain ESTree wrapping is emitted by the WASM
141
140
  // serializer, mirroring upstream `HermesToESTreeAdapter.mapChainExpression`.
142
141
  // See FlowParser.js.
143
- const estreeAST = FlowParser.parse(code, options);
144
-
145
- if (options.babel !== true) {
146
- return estreeAST;
147
- }
148
-
149
- // `babel: true` overload — reduce the ESTree AST through the same syntax
150
- // lowering pipeline upstream uses (Enum/Match/Component/Record syntax,
151
- // strip Flow types), then convert ESTree → Babel AST shape.
152
- const loweredESTreeAST = [
153
- options.transformOptions?.TransformEnumSyntax?.enable
154
- ? TransformEnumSyntax.transformProgram
155
- : null,
156
- TransformMatchSyntax.transformProgram,
157
- TransformComponentSyntax.transformProgram,
158
- TransformRecordSyntax.transformProgram,
159
- StripFlowTypesForBabel.transformProgram,
160
- ].reduce((ast, transform) => transform?.(ast, options) ?? ast, estreeAST);
161
-
162
- return TransformESTreeToBabel.transformProgram(loweredESTreeAST, options);
142
+ return FlowParser.parse(code, options);
163
143
  }
164
144
 
165
145
  export type {ParserOptions} from './ParserOptions';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flow-parser",
3
- "version": "0.328.0",
3
+ "version": "0.329.0",
4
4
  "description": "JavaScript parser written in OCaml. Produces ESTree AST",
5
5
  "homepage": "https://flow.org",
6
6
  "license": "MIT",
@@ -23,7 +23,7 @@
23
23
  "test": "node test/run_tests.js"
24
24
  },
25
25
  "dependencies": {
26
- "flow-estree": "0.328.0"
26
+ "flow-estree": "0.329.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@babel/generator": "7.7.4",