MCPcopy Create free account
hub / github.com/nodejs/node / findAwaitableInitializers

Function findAwaitableInitializers

test/fixtures/snapshot/typescript.js:150482–150528  ·  view source on GitHub ↗
(expression, sourceFile, cancellationToken, program, checker)

Source from the content-addressed store, hash-verified

150480 });
150481 }
150482 function findAwaitableInitializers(expression, sourceFile, cancellationToken, program, checker) {
150483 var identifiers = getIdentifiersFromErrorSpanExpression(expression, checker);
150484 if (!identifiers) {
150485 return;
150486 }
150487 var isCompleteFix = identifiers.isCompleteFix;
150488 var initializers;
150489 var _loop_13 = function (identifier) {
150490 var symbol = checker.getSymbolAtLocation(identifier);
150491 if (!symbol) {
150492 return "continue";
150493 }
150494 var declaration = ts.tryCast(symbol.valueDeclaration, ts.isVariableDeclaration);
150495 var variableName = declaration && ts.tryCast(declaration.name, ts.isIdentifier);
150496 var variableStatement = ts.getAncestor(declaration, 237 /* SyntaxKind.VariableStatement */);
150497 if (!declaration || !variableStatement ||
150498 declaration.type ||
150499 !declaration.initializer ||
150500 variableStatement.getSourceFile() !== sourceFile ||
150501 ts.hasSyntacticModifier(variableStatement, 1 /* ModifierFlags.Export */) ||
150502 !variableName ||
150503 !isInsideAwaitableBody(declaration.initializer)) {
150504 isCompleteFix = false;
150505 return "continue";
150506 }
150507 var diagnostics = program.getSemanticDiagnostics(sourceFile, cancellationToken);
150508 var isUsedElsewhere = ts.FindAllReferences.Core.eachSymbolReferenceInFile(variableName, checker, sourceFile, function (reference) {
150509 return identifier !== reference && !symbolReferenceIsAlsoMissingAwait(reference, diagnostics, sourceFile, checker);
150510 });
150511 if (isUsedElsewhere) {
150512 isCompleteFix = false;
150513 return "continue";
150514 }
150515 (initializers || (initializers = [])).push({
150516 expression: declaration.initializer,
150517 declarationSymbol: symbol,
150518 });
150519 };
150520 for (var _i = 0, _a = identifiers.identifiers; _i < _a.length; _i++) {
150521 var identifier = _a[_i];
150522 _loop_13(identifier);
150523 }
150524 return initializers && {
150525 initializers: initializers,
150526 needsSecondPassForFixAll: !isCompleteFix,
150527 };
150528 }
150529 function getIdentifiersFromErrorSpanExpression(expression, checker) {
150530 if (ts.isPropertyAccessExpression(expression.parent) && ts.isIdentifier(expression.parent.expression)) {
150531 return { identifiers: [expression.parent.expression], isCompleteFix: true };

Callers 1

getDeclarationSiteFixFunction · 0.85

Calls 2

_loop_13Function · 0.85

Tested by

no test coverage detected