* Given a piece of text to extract ('targetRange'), computes a list of possible extractions. * Each returned ExtractResultForScope corresponds to a possible target scope and is either a set of changes * or an error explaining why we can't extract into that scope.
(targetRange, context)
| 160587 | * or an error explaining why we can't extract into that scope. |
| 160588 | */ |
| 160589 | function getPossibleExtractions(targetRange, context) { |
| 160590 | var _a = getPossibleExtractionsWorker(targetRange, context), scopes = _a.scopes, _b = _a.readsAndWrites, functionErrorsPerScope = _b.functionErrorsPerScope, constantErrorsPerScope = _b.constantErrorsPerScope; |
| 160591 | // Need the inner type annotation to avoid https://github.com/Microsoft/TypeScript/issues/7547 |
| 160592 | var extractions = scopes.map(function (scope, i) { |
| 160593 | var functionDescriptionPart = getDescriptionForFunctionInScope(scope); |
| 160594 | var constantDescriptionPart = getDescriptionForConstantInScope(scope); |
| 160595 | var scopeDescription = ts.isFunctionLikeDeclaration(scope) |
| 160596 | ? getDescriptionForFunctionLikeDeclaration(scope) |
| 160597 | : ts.isClassLike(scope) |
| 160598 | ? getDescriptionForClassLikeDeclaration(scope) |
| 160599 | : getDescriptionForModuleLikeDeclaration(scope); |
| 160600 | var functionDescription; |
| 160601 | var constantDescription; |
| 160602 | if (scopeDescription === 1 /* SpecialScope.Global */) { |
| 160603 | functionDescription = ts.formatStringFromArgs(ts.getLocaleSpecificMessage(ts.Diagnostics.Extract_to_0_in_1_scope), [functionDescriptionPart, "global"]); |
| 160604 | constantDescription = ts.formatStringFromArgs(ts.getLocaleSpecificMessage(ts.Diagnostics.Extract_to_0_in_1_scope), [constantDescriptionPart, "global"]); |
| 160605 | } |
| 160606 | else if (scopeDescription === 0 /* SpecialScope.Module */) { |
| 160607 | functionDescription = ts.formatStringFromArgs(ts.getLocaleSpecificMessage(ts.Diagnostics.Extract_to_0_in_1_scope), [functionDescriptionPart, "module"]); |
| 160608 | constantDescription = ts.formatStringFromArgs(ts.getLocaleSpecificMessage(ts.Diagnostics.Extract_to_0_in_1_scope), [constantDescriptionPart, "module"]); |
| 160609 | } |
| 160610 | else { |
| 160611 | functionDescription = ts.formatStringFromArgs(ts.getLocaleSpecificMessage(ts.Diagnostics.Extract_to_0_in_1), [functionDescriptionPart, scopeDescription]); |
| 160612 | constantDescription = ts.formatStringFromArgs(ts.getLocaleSpecificMessage(ts.Diagnostics.Extract_to_0_in_1), [constantDescriptionPart, scopeDescription]); |
| 160613 | } |
| 160614 | // Customize the phrasing for the innermost scope to increase clarity. |
| 160615 | if (i === 0 && !ts.isClassLike(scope)) { |
| 160616 | constantDescription = ts.formatStringFromArgs(ts.getLocaleSpecificMessage(ts.Diagnostics.Extract_to_0_in_enclosing_scope), [constantDescriptionPart]); |
| 160617 | } |
| 160618 | return { |
| 160619 | functionExtraction: { |
| 160620 | description: functionDescription, |
| 160621 | errors: functionErrorsPerScope[i], |
| 160622 | }, |
| 160623 | constantExtraction: { |
| 160624 | description: constantDescription, |
| 160625 | errors: constantErrorsPerScope[i], |
| 160626 | }, |
| 160627 | }; |
| 160628 | }); |
| 160629 | return extractions; |
| 160630 | } |
| 160631 | function getPossibleExtractionsWorker(targetRange, context) { |
| 160632 | var sourceFile = context.file; |
| 160633 | var scopes = collectEnclosingScopes(targetRange); |
no test coverage detected