Skip to content

Commit c94aaea

Browse files
committed
feat(alita): 添加flow支持
fix #29
1 parent 7d0a9ab commit c94aaea

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"@babel/plugin-syntax-jsx": "^7.0.0",
5151
"@babel/plugin-transform-react-jsx": "^7.1.6",
5252
"@babel/plugin-transform-runtime": "^7.5.0",
53+
"@babel/preset-flow": "^7.0.0",
5354
"@babel/traverse": "^7.1.6",
5455
"@babel/types": "^7.1.6",
5556
"babel-eslint": "^8.2.6",

src/util/uast.js

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export function geneReactCode(ast) {
6464
code = babel.transformSync(code, {
6565
babelrc: false,
6666
configFile: false,
67+
presets: ["@babel/preset-flow"],
6768
plugins: [
6869
babelDecorators,
6970
babelRestSpread,

test/util/uast.test.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) Areslabs.
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+
9+
import {parseCode, geneReactCode} from '../../src/util/uast'
10+
11+
describe('uast', () => {
12+
13+
14+
it("parseCode geneReactCode: flow语法支持", () => {
15+
const code = `
16+
function foo(one: any, two: number, three?): string {}
17+
`
18+
19+
const ast = parseCode(code)
20+
const newcode = geneReactCode(ast)
21+
22+
const expectCode = `function foo(one, two, three) {}`
23+
expect(newcode).toBe(expectCode)
24+
})
25+
26+
})

0 commit comments

Comments
 (0)