Skip to content

Commit

Permalink
feat(alita): 添加flow支持
Browse files Browse the repository at this point in the history
fix #29
  • Loading branch information
ykforerlang committed Oct 24, 2019
1 parent 7d0a9ab commit c94aaea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@babel/plugin-syntax-jsx": "^7.0.0",
"@babel/plugin-transform-react-jsx": "^7.1.6",
"@babel/plugin-transform-runtime": "^7.5.0",
"@babel/preset-flow": "^7.0.0",
"@babel/traverse": "^7.1.6",
"@babel/types": "^7.1.6",
"babel-eslint": "^8.2.6",
Expand Down
1 change: 1 addition & 0 deletions src/util/uast.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export function geneReactCode(ast) {
code = babel.transformSync(code, {
babelrc: false,
configFile: false,
presets: ["@babel/preset-flow"],
plugins: [
babelDecorators,
babelRestSpread,
Expand Down
26 changes: 26 additions & 0 deletions test/util/uast.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) Areslabs.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

import {parseCode, geneReactCode} from '../../src/util/uast'

describe('uast', () => {


it("parseCode geneReactCode: flow语法支持", () => {
const code = `
function foo(one: any, two: number, three?): string {}
`

const ast = parseCode(code)
const newcode = geneReactCode(ast)

const expectCode = `function foo(one, two, three) {}`
expect(newcode).toBe(expectCode)
})

})

0 comments on commit c94aaea

Please sign in to comment.