save union type in _getTypeAnnotationBindingConstantViolations to prevent infinite recursion
This commit is contained in:
parent
2d0355b3b9
commit
a6b374a681
@ -89,6 +89,9 @@ export function getTypeAnnotation(force) {
|
|||||||
export function _getTypeAnnotationBindingConstantViolations(name, types = []) {
|
export function _getTypeAnnotationBindingConstantViolations(name, types = []) {
|
||||||
var binding = this.scope.getBinding(name);
|
var binding = this.scope.getBinding(name);
|
||||||
|
|
||||||
|
var types = [];
|
||||||
|
this.typeAnnotation = t.unionTypeAnnotation(types);
|
||||||
|
|
||||||
for (var constantViolation of (binding.constantViolations: Array)) {
|
for (var constantViolation of (binding.constantViolations: Array)) {
|
||||||
types.push(constantViolation.getTypeAnnotation());
|
types.push(constantViolation.getTypeAnnotation());
|
||||||
}
|
}
|
||||||
@ -132,9 +135,15 @@ export function _getTypeAnnotation(force?: boolean): ?Object {
|
|||||||
var id = this.get("id");
|
var id = this.get("id");
|
||||||
|
|
||||||
if (id.isIdentifier()) {
|
if (id.isIdentifier()) {
|
||||||
return this._getTypeAnnotationBindingConstantViolations(id.node.name, [
|
var init = this.get("init").getTypeAnnotation();
|
||||||
this.get("init").getTypeAnnotation()
|
|
||||||
]);
|
// just because we're inferring a VariableDeclarator doesn't mean that it's the same
|
||||||
|
// binding path as it may have been shadowed
|
||||||
|
if (this.scope.getBinding(id.node.name).path === this) {
|
||||||
|
return this._getTypeAnnotationBindingConstantViolations(id.node.name, [init]);
|
||||||
|
} else {
|
||||||
|
return init;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user