Merge branch 'master' into allow-booleans-in-spreads

This commit is contained in:
Nathan Shively-Sanders
2017-09-14 10:30:58 -07:00
28 changed files with 384 additions and 91 deletions

View File

@@ -14793,7 +14793,7 @@ namespace ts {
return;
}
if (findAncestor(node, node => node.kind === SyntaxKind.PropertyDeclaration ? true : isExpression(node) ? false : "quit") &&
if (isInPropertyInitializer(node) &&
!isBlockScopedNameDeclaredBeforeUse(valueDeclaration, right)
&& !isPropertyDeclaredInAncestorClass(prop)) {
error(right, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, unescapeLeadingUnderscores(right.escapedText));
@@ -14806,6 +14806,20 @@ namespace ts {
}
}
function isInPropertyInitializer(node: Node): boolean {
return !!findAncestor(node, node => {
switch (node.kind) {
case SyntaxKind.PropertyDeclaration:
return true;
case SyntaxKind.PropertyAssignment:
// We might be in `a = { b: this.b }`, so keep looking. See `tests/cases/compiler/useBeforeDeclaration_propertyAssignment.ts`.
return false;
default:
return isPartOfExpression(node) ? false : "quit";
}
});
}
/**
* It's possible that "prop.valueDeclaration" is a local declaration, but the property was also declared in a superclass.
* In that case we won't consider it used before its declaration, because it gets its value from the superclass' declaration.