Fix Flow return types on arrow functions (#124)

* fix: arrow return type on next line is valid

https://github.com/babel/babel-eslint/issues/348

* fix: arrow on line after return type annotation is invalid

* lint
This commit is contained in:
Dan Harper
2016-09-15 18:27:11 +01:00
committed by Daniel Tschinder
parent abf6ca8e5e
commit dc3036627b
6 changed files with 218 additions and 1 deletions

View File

@@ -1178,6 +1178,7 @@ export default function (instance) {
let state = this.state.clone();
try {
let returnType = this.flowParseTypeAnnotation();
if (this.canInsertSemicolon()) this.unexpected();
if (!this.match(tt.arrow)) this.unexpected();
// assign after it is clear it is an arrow
node.returnType = returnType;
@@ -1194,6 +1195,12 @@ export default function (instance) {
};
});
instance.extend("shouldParseArrow", function (inner) {
return function () {
return this.match(tt.colon) || inner.call(this);
};
});
instance.extend("isClassMutatorStarter", function (inner) {
return function () {
if (this.isRelational("<")) {