Problem
Esprima can't parse codes which already have flow type annotations.
When we have foo.js like this:
// @flow
/**
* @param {string} str
*/
function foo(str): string {
return str;
}
... then flow-jsdoc dies, because esprima.parse() can't parse flow type annotation and throws a parse error.
$ flow-jsdoc -f foo.js
/Users/fand/.nodenv/versions/6.9.5/lib/node_modules/flow-jsdoc/node_modules/esprima/dist/esprima.js:552
throw this.unexpectedTokenError(token, message);
^
Error: Line 6: Unexpected token :
at ErrorHandler.constructError (/Users/fand/.nodenv/versions/6.9.5/lib/node_modules/flow-jsdoc/node_modules/esprima/dist/esprima.js:3396:22)
at ErrorHandler.createError (/Users/fand/.nodenv/versions/6.9.5/lib/node_modules/flow-jsdoc/node_modules/esprima/dist/esprima.js:3414:27)
at JSXParser.Parser.unexpectedTokenError (/Users/fand/.nodenv/versions/6.9.5/lib/node_modules/flow-jsdoc/node_modules/esprima/dist/esprima.js:542:39)
at JSXParser.Parser.throwUnexpectedToken (/Users/fand/.nodenv/versions/6.9.5/lib/node_modules/flow-jsdoc/node_modules/esprima/dist/esprima.js:552:21)
at JSXParser.Parser.expect (/Users/fand/.nodenv/versions/6.9.5/lib/node_modules/flow-jsdoc/node_modules/esprima/dist/esprima.js:716:19)
at JSXParser.Parser.parseFunctionSourceElements (/Users/fand/.nodenv/versions/6.9.5/lib/node_modules/flow-jsdoc/node_modules/esprima/dist/esprima.js:2572:15)
at JSXParser.Parser.parseFunctionDeclaration (/Users/fand/.nodenv/versions/6.9.5/lib/node_modules/flow-jsdoc/node_modules/esprima/dist/esprima.js:2713:26)
at JSXParser.Parser.parseStatementListItem (/Users/fand/.nodenv/versions/6.9.5/lib/node_modules/flow-jsdoc/node_modules/esprima/dist/esprima.js:1809:39)
at JSXParser.Parser.parseProgram (/Users/fand/.nodenv/versions/6.9.5/lib/node_modules/flow-jsdoc/node_modules/esprima/dist/esprima.js:3061:29)
at parse (/Users/fand/.nodenv/versions/6.9.5/lib/node_modules/flow-jsdoc/node_modules/esprima/dist/esprima.js:117:24)
It would be great if flow-jsdoc could parse such codes.
Replacing Esprima with Babylon will solve the problem.
Also, It would be nice if flow-jsdoc could handle the confliction between JSDoc types and existing flow type annotations 😺
Problem
Esprima can't parse codes which already have flow type annotations.
When we have
foo.jslike this:... then
flow-jsdocdies, becauseesprima.parse()can't parse flow type annotation and throws a parse error.It would be great if
flow-jsdoccould parse such codes.Replacing Esprima with Babylon will solve the problem.
Also, It would be nice if
flow-jsdoccould handle the confliction between JSDoc types and existing flow type annotations 😺