Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add support for Flow to @addons/storysource #4971

Merged
merged 4 commits into from
Dec 14, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/storysource/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The parser that will be parsing your code to AST (based on [prettier](https://gi
Alowed values:
* `javascript` - default
* `typescript`
* `flow`

Usage:

Expand Down
5 changes: 5 additions & 0 deletions addons/storysource/src/loader/parsers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ function getParser(type) {
return require('./parser-ts').default;
}

if (type === 'flow') {
// eslint-disable-next-line global-require
return require('./parser-flow').default;
}

throw new Error(`Parser of type "${type}" is not supported`);
}

Expand Down
9 changes: 9 additions & 0 deletions addons/storysource/src/loader/parsers/parser-flow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import parseFlow from 'prettier/parser-flow';

function parse(source) {
return parseFlow.parsers.flow.parse(source);
}

export default {
parse,
};