Repository: babel/babel
File: packages/babel-generator/src/token-map.ts (TypeScript)

Code before:
    );

    let low = first;

    const children = childrenIterator(node);

    if (
      (node.type === "ExportNamedDeclaration" ||
        node.type === "ExportDefaultDeclaration") &&
      node.declaration &&
      node.declaration.type === "ClassDeclaration"
    ) {
      // Exported class declarations can be not properly nested inside
      // the export declaration that contains them. For example, in
      // `@dec export class Foo {}` the `export` is covered by the
      // ClassDeclaration range. Skip the class declaration from the list
      // of children to skip, so that when looking for `export` we also
      // traverse its tokens.
      children.next();
    }

    const indexes = [];

    for (const child of children) {
      if (!child) continue;

      const childTok = this._findTokensOfNode(child, low, last);

      const high = childTok.first;
      for (let k = low; k < high; k++) indexes.push(k);

      low = childTok.last + 1;
    }

    for (let k = low; k <= last; k++) indexes.push(k);

    return indexes;
  }

  _findTokensOfNode(node: t.Node, low: number, high: number) {
    const cached = this._tokensCache.get(node);
    if (cached) return cached;

    const first = this._findFirstTokenOfNode(node.start, low, high);
    const last = this._findLastTokenOfNode(node.end, first, high);

    this._tokensCache.set(node, { first, last });
    return { first, last };
  }

  _findFirstTokenOfNode(start: number, low: number, high: number): number {

Review comment (suggestion):
```suggestion
      if (child == null || child.start == null || child.end == null) continue;
```

Code after:
    );

    let low = first;

    const children = childrenIterator(node);

    if (
      (node.type === "ExportNamedDeclaration" ||
        node.type === "ExportDefaultDeclaration") &&
      node.declaration &&
      node.declaration.type === "ClassDeclaration"
    ) {
      // Exported class declarations can be not properly nested inside
      // the export declaration that contains them. For example, in
      // `@dec export class Foo {}` the `export` is covered by the
      // ClassDeclaration range. Skip the class declaration from the list
      // of children to skip, so that when looking for `export` we also
      // traverse its tokens.
      children.next();
    }

    const indexes = [];

    for (const child of children) {
      if (child == null) continue;
      if (child.start == null || child.end == null) continue;

      const childTok = this._findTokensOfNode(child, low, last);

      const high = childTok.first;
      for (let k = low; k < high; k++) indexes.push(k);

      low = childTok.last + 1;
    }

    for (let k = low; k <= last; k++) indexes.push(k);

    return indexes;
  }

  _findTokensOfNode(node: t.Node, low: number, high: number) {
    const cached = this._tokensCache.get(node);
    if (cached) return cached;

    const first = this._findFirstTokenOfNode(node.start, low, high);
    const last = this._findLastTokenOfNode(node.end, first, high);

    this._tokensCache.set(node, { first, last });
    return { first, last };
  }