error on invalid flow type annotation with default assignment (#122)

This commit is contained in:
Dan Harper
2016-09-15 18:35:03 +01:00
committed by Daniel Tschinder
parent dc3036627b
commit 64145b07e3
7 changed files with 232 additions and 42 deletions

View File

@@ -1049,6 +1049,18 @@ export default function (instance) {
};
});
instance.extend("parseMaybeDefault", function (inner) {
return function (...args) {
const node = inner.apply(this, args);
if (node.type === "AssignmentPattern" && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
this.raise(node.typeAnnotation.start, "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`");
}
return node;
};
});
// parse typeof and type imports
instance.extend("parseImportSpecifiers", function (inner) {