Skip to content

Commit

Permalink
support flow syntax in es7 and jsx parsers (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrnail23 authored and rumpl committed Jul 9, 2019
1 parent 7cbd86b commit e080198
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/parser/es7.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export default function parseES7(content) {
'dynamicImport',
'exportDefaultFrom',
'exportNamespaceFrom',
'flow',
'flowComments',
'functionBind',
'functionSent',
'importMeta',
Expand Down
2 changes: 2 additions & 0 deletions src/parser/jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default function parseJSX(content) {
'dynamicImport',
'exportDefaultFrom',
'exportNamespaceFrom',
'flow',
'flowComments',
'functionBind',
'functionSent',
'importMeta',
Expand Down
23 changes: 23 additions & 0 deletions test/fake_modules/good_es7_flow/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @flow
/* eslint-disable no-unused-vars */

// This file includes some experimental ES7 syntax enabled in Babel by default. Reference: https://babeljs.io/docs/usage/experimental/

import 'ecmascript-rest-spread';

type TestType = {
x: Number,
y: Number,
x: Number,
};

const test: TestType = {
x: 1,
y: 2,
z: 3,
};

const objectRestSpread = {
...test,
spec: 'https://github.com/sebmarkbage/ecmascript-rest-spread',
};
5 changes: 5 additions & 0 deletions test/fake_modules/good_es7_flow/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"ecmascript-rest-spread": "0.0.1"
}
}
9 changes: 9 additions & 0 deletions test/fake_modules/jsx_flow/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// @flow
var React = require('react');

type Props = {
text: string
};

export default ({ text }: Props) =>
(<div>{text}</div>);
5 changes: 5 additions & 0 deletions test/fake_modules/jsx_flow/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"react": "0.0.1"
}
}
29 changes: 29 additions & 0 deletions test/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,21 @@ export default [
},
},
},
{
name: 'support flow syntax in ES7 modules',
module: 'good_es7_flow',
options: {
withoutDev: true,
},
expected: {
dependencies: [],
devDependencies: [],
missing: {},
using: {
'ecmascript-rest-spread': ['index.js'],
},
},
},
{
name: 'support Typescript syntax',
module: 'typescript',
Expand Down Expand Up @@ -608,6 +623,20 @@ export default [
},
},
},
{
name: 'support flow syntax in jsx modules',
module: 'jsx_flow',
options: {
},
expected: {
dependencies: [],
devDependencies: [],
missing: {},
using: {
react: ['index.jsx'],
},
},
},
{
name: 'parser jsx syntax in JavaScript file by default',
module: 'jsx_js',
Expand Down

0 comments on commit e080198

Please sign in to comment.