Repository: babel/babel
File: packages/babel-parser/src/parser/statement.ts (TypeScript)

Code before:
      this.chStartsBindingIdentifier(nextCh, next)
    );
  }

  /**
   * Assuming we have seen a contextual `using` and declaration is allowed, check if it
   * starts a variable declaration in the same line so that it should be interpreted as
   * a keyword.
   */
  hasInLineFollowingBindingIdentifierOrBrace(): boolean {
    const next = this.nextTokenInLineStart();
    const nextCh = this.codePointAtPos(next);
    return (
      nextCh === charCodes.leftCurlyBrace ||
      this.chStartsBindingIdentifier(nextCh, next)
    );
  }

  allowsForUsing(): boolean {
    const { type, containsEsc, end } = this.lookahead();
    if (type === tt._of && !containsEsc) {
      // `for( using of` must start either a for-lhs-of statement
      // or a for lexical declaration
      const nextCharAfterOf = this.input.charCodeAt(
        this.nextTokenStartSince(end),
      );
      if (
        nextCharAfterOf !== charCodes.equalsTo &&
        nextCharAfterOf !== charCodes.colon &&
        // recover from `for(using of;...);`
        nextCharAfterOf !== charCodes.semicolon
      ) {
        return false;
      }
    }
    if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
      this.expectPlugin("explicitResourceManagement");
      return true;
    }
    return false;
  }

  startsAwaitUsing(): boolean {
    let next = this.nextTokenInLineStart();
    if (this.isUnparsedContextual(next, "using")) {
      next = this.nextTokenInLineStartSince(next + 5);
      const nextCh = this.codePointAtPos(next);
      if (this.chStartsBindingIdentifier(nextCh, next)) {
        this.expectPlugin("explicitResourceManagement");
        return true;
      }

Review comment (suggestion):
We can modify `lookaheadCharCode` as follows and use it.
```
  lookaheadCharCode(pos = this.state.pos): number {
    return this.input.charCodeAt(this.nextTokenStartSince(pos));
  }
```

Code after:
      this.chStartsBindingIdentifier(nextCh, next)
    );
  }

  /**
   * Assuming we have seen a contextual `using` and declaration is allowed, check if it
   * starts a variable declaration in the same line so that it should be interpreted as
   * a keyword.
   */
  hasInLineFollowingBindingIdentifierOrBrace(): boolean {
    const next = this.nextTokenInLineStart();
    const nextCh = this.codePointAtPos(next);
    return (
      nextCh === charCodes.leftCurlyBrace ||
      this.chStartsBindingIdentifier(nextCh, next)
    );
  }

  allowsForUsing(): boolean {
    const { type, containsEsc, end } = this.lookahead();
    if (type === tt._of && !containsEsc) {
      // `for( using of` must start either a for-lhs-of statement
      // or a for lexical declaration
      const nextCharAfterOf = this.lookaheadCharCodeSince(end);
      if (
        nextCharAfterOf !== charCodes.equalsTo &&
        nextCharAfterOf !== charCodes.colon &&
        // recover from `for(using of;...);`
        nextCharAfterOf !== charCodes.semicolon
      ) {
        return false;
      }
    }
    if (tokenIsIdentifier(type) && !this.hasFollowingLineBreak()) {
      this.expectPlugin("explicitResourceManagement");
      return true;
    }
    return false;
  }

  startsAwaitUsing(): boolean {
    let next = this.nextTokenInLineStart();
    if (this.isUnparsedContextual(next, "using")) {
      next = this.nextTokenInLineStartSince(next + 5);
      const nextCh = this.codePointAtPos(next);
      if (this.chStartsBindingIdentifier(nextCh, next)) {
        this.expectPlugin("explicitResourceManagement");
        return true;
      }
    }
    return false;