Update param scope values when expanding parameters.

This commit is contained in:
Logan Smyth
2017-05-02 21:24:35 -07:00
committed by Brian Ng
parent 95882d4e5a
commit 8e19a5b057
4 changed files with 30 additions and 9 deletions

View File

@@ -5,11 +5,23 @@ export { default as Identifier } from "./inferer-reference";
export function VariableDeclarator() {
const id = this.get("id");
if (id.isIdentifier()) {
return this.get("init").getTypeAnnotation();
} else {
return;
if (!id.isIdentifier()) return;
const init = this.get("init");
let type = init.getTypeAnnotation();
if (type && type.type === "AnyTypeAnnotation") {
// Detect "var foo = Array()" calls so we can optimize for arrays vs iterables.
if (
init.isCallExpression() &&
init.get("callee").isIdentifier({ name: "Array" }) &&
!init.scope.hasBinding("Array", true /* noGlobals */)
) {
type = ArrayExpression();
}
}
return type;
}
export function TypeCastExpression(node) {