Loosen restriction on usages in innermost scope

Now that we're smarter about where we declare the extracted local, we
can ignore usage problems in the innermost script - it'll always have
access to the same symbols as the extracted expression.
This commit is contained in:
Andrew Casey
2017-09-29 18:00:27 -07:00
parent c08308a0f1
commit bcc93f2c08
4 changed files with 41 additions and 17 deletions

View File

@@ -1349,7 +1349,10 @@ namespace ts.refactor.extractSymbol {
for (let i = 0; i < scopes.length; i++) {
if (!isReadonlyArray(targetRange.range)) {
const scopeUsages = usagesPerScope[i];
if (scopeUsages.usages.size > 0 || scopeUsages.typeParameterUsages.size > 0) {
// Special case: in the innermost scope, all usages are available.
// (The computed value reflects the value at the top-level of the scope, but the
// local will actually be declared at the same level as the extracted expression).
if (i > 0 && (scopeUsages.usages.size > 0 || scopeUsages.typeParameterUsages.size > 0)) {
constantErrorsPerScope[i].push(createDiagnosticForNode(targetRange.range, Messages.CannotAccessVariablesFromNestedScopes));
}
}