{"record":{"id":"66448b9d11101f5a","repo":"facebook/flow","slug":"updatependingstatements-variable-for-dependency","errorCode":null,"errorMessage":"updatePendingStatements: Variable for dependency \"${dep}\" not found","messagePattern":"updatePendingStatements: Variable for dependency \"(.+?)\" not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/flow-api-translator/src/flowToFlowDef.js","lineNumber":191,"sourceCode":"  function storeTranslatedStatement(\n    stmt: DetachedNode<ProgramStatement>,\n    orgStmt: ProgramStatement,\n  ): void {\n    translatedStatements.set(orgStmt, stmt);\n  }\n\n  const seenDeps = new Set<Dep>();\n  const processedStatements = new Set<ProgramStatement>();\n  const pendingStatements = new Set<ProgramStatement>();\n  function updatePendingStatements(deps: TranslatedDeps): void {\n    for (const dep of deps) {\n      if (seenDeps.has(dep)) {\n        continue;\n      }\n      seenDeps.add(dep);\n      const variable = context.variableMap.get(dep);\n      if (variable == null) {\n        throw new Error(\n          `updatePendingStatements: Variable for dependency \"${dep}\" not found`,\n        );\n      }\n      for (const def of variable.defs) {\n        const stmt = def.node;\n        if (stmt == null) {\n          throw new Error(\n            `updatePendingStatements: Variable parent of \"${dep}\" not found`,\n          );\n        }\n        const topLevelStmt = getTopLevelStatement(stmt, context);\n        if (processedStatements.has(topLevelStmt)) {\n          continue;\n        }\n        pendingStatements.add(topLevelStmt);\n      }\n    }\n  }","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/facebook/flow/blob/d1341dac899a79c027762f6b423d896045287620/packages/flow-api-translator/src/flowToFlowDef.js#L173-L209","documentation":"Internal invariant in flowToFlowDef (flow-api-translator). While ordering top-level output statements it walks each translated statement's dependencies and looks each name up in context.variableMap. If a dependency identifier has no Variable record, translation state is inconsistent and it throws, naming the dependency.","triggerScenarios":"Translating a Flow AST program where a statement references an identifier never registered in the translation context's variableMap — an undeclared/global identifier, a name imported or declared outside the supplied statements, a partial Program AST, or an AST missing scope/parent information.","commonSituations":"Feeding hand-built, cloned, or subtree ASTs into the translator instead of a full Program; identifiers that are Flow builtins or globals not declared in the input file; translator/parser version mismatch dropping scope info.","solutions":["Pass a complete Program AST (all statements of the file) — fragments leave referenced identifiers undeclared","Declare or import the identifier named in the message inside the input source so it resolves within the same program","Update flow-api-translator in case the lookup logic changed for your AST shape","Minimize the input and file an issue — this is a violated translator invariant"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Before translating, ensure every referenced identifier is declared\n// within the same Program you pass in.\nfunction collectDeclared(program: {body: any[]}): Set<string> {\n  const declared = new Set<string>();\n  for (const stmt of program.body) {\n    switch (stmt.type) {\n      case 'VariableDeclaration':\n        for (const d of stmt.declarations) declared.add(d.id.name);\n        break;\n      case 'FunctionDeclaration':\n      case 'ClassDeclaration':\n      case 'TypeAlias':\n      case 'InterfaceDeclaration':\n        if (stmt.id) declared.add(stmt.id.name);\n        break;\n      case 'ImportDeclaration':\n        for (const s of stmt.specifiers) declared.add(s.local.name);\n        break;\n    }\n  }\n  return declared;\n}\n// then: referencedNames ⊆ declared ∪ FLOW_GLOBALS before calling translate","typeGuard":null,"tryCatchPattern":"try {\n  const defs = translateFlowASTToFlowDef(program, context);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('Variable for dependency')) {\n    // undeclared/global identifier: log program.body statement types and move on\n  } else throw err;\n}","preventionTips":["Translate whole files, never fragments or hand-pruned ASTs","Ensure the input source passes `flow check` first","Use the parser output directly without cloning or transform passes"],"tags":["flow","ast","transformation","internal-invariant","scope"],"backgroundTag":"unresolved-identifier","analyzedSha":"d1341dac899a79c027762f6b423d896045287620","analyzedAt":"2026-08-17T00:07:02.212Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}