message: test(ivy): enhance the in-memory-typescript helper
  The `getDeclaration()` function now searches down into the AST for
  matching nodes, which is needed for UMD testing.
  PR Close
diff: @@ -117,37 +117,41 @@ export function getDeclaration<T extends ts.Declaration>(
  if (!sf) {
  throw new Error(`No such file: ${fileName}`);
  }
  + const chosenDecl = walkForDeclaration(sf);
  - let chosenDecl: ts.Declaration|null = null;
  + if (chosenDecl === null) {
  + throw new Error(`No such symbol: ${name} in ${fileName}`);
  + }
  + if (!assert(chosenDecl)) {
  + throw new Error(`Symbol ${name} from ${fileName} is a ${ts.SyntaxKind[chosenDecl.kind]}`);
  + }
  + return chosenDecl;
  - sf.statements.forEach(stmt => {
  + // We walk the AST tree looking for a declaration that matches
  + function walkForDeclaration(rootNode: ts.Node): ts.Declaration|null {
  + let chosenDecl: ts.Declaration|null = null;
  + rootNode.forEachChild(node => {
  if (chosenDecl !== null) {
  return;
  - } else if (ts.isVariableStatement(stmt)) {
  - stmt.declarationList.declarations.forEach(decl => {
  + }
  + if (ts.isVariableStatement(node)) {
  + node.declarationList.declarations.forEach(decl => {
  if (bindingNameEquals(decl.name, name)) {
  chosenDecl = decl;
  }
  });
  - } else if (ts.isClassDeclaration(stmt) || ts.isFunctionDeclaration(stmt)) {
  - if (stmt.name !== undefined && stmt.name.text === name) {
  - chosenDecl = stmt;
  + } else if (ts.isClassDeclaration(node) || ts.isFunctionDeclaration(node)) {
  + if (node.name !== undefined && node.name.text === name) {
  + chosenDecl = node;
  }
  } else if (
  - ts.isImportDeclaration(stmt) && stmt.importClause !== undefined &&
  - stmt.importClause.name !== undefined && stmt.importClause.name.text === name) {
  - chosenDecl = stmt.importClause;
  + ts.isImportDeclaration(node) && node.importClause !== undefined &&
  + node.importClause.name !== undefined && node.importClause.name.text === name) {
  + chosenDecl = node.importClause;
  + } else {
  + chosenDecl = walkForDeclaration(node);
  }
  });
  -
  - chosenDecl = chosenDecl as ts.Declaration | null;
  -
  - if (chosenDecl === null) {
  - throw new Error(`No such symbol: ${name} in ${fileName}`);
  - }
  - if (!assert(chosenDecl)) {
  - throw new Error(`Symbol ${name} from ${fileName} is a ${ts.SyntaxKind[chosenDecl.kind]}`);
  - }
  -
  return chosenDecl;
  }
  +}
  