oxc-project / oxc-project/backlog

New APIs for interacting with `ScopeTree` and `SymbolTable`

Open
#152 1 comment 0 reactions 1 assignee View on GitHub

@overlookmotel is already working on this.

Since Oct 10, 2024.

A-semantic
Dominant language
No language data
Stars
7
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Currently to get flags for a scope:

ctx.scopes().get_flags(scope_id)

We could instead support:

scope_id.flags(ctx)

Implemented as:

impl ScopeId {
    pub fn flags<C: ScopesAccessor>(self, ctx: &C) {
        ctx.scopes().get_flags(self)
    }
}

trait ScopesAccessor {
    fn scopes(&self) -> &ScopeTree;
}

ScopesAccessor trait would be implemented on Semantic, TraverseCtx, LinterCtx and any other structs which hold a copy of ScopeTree. Then we can centralize logic for acting on scopes in this trait.

Similarly, would also have these traits:

  • SymbolsAccessor
  • NodesAccessor
  • AstBuilderAccessor
  • SymbolsAndScopesAccessor: SymbolsAccessor + ScopesAccessor
  • SymbolsAndScopesAndAstBuilderAccessor: SymbolsAndScopesAccessor + AstBuilderAccessor
  • SymbolsAndScopesAndNodesAccessor: SymbolsAndScopesAccessor + NodesAccessor

All logic for manipulating scopes/symbols/references/nodes would be implemented on these traits (or perhaps they delegate to a set of common functions, to keep the generic method impls on the traits slim).

Related to oxc-project/oxc#9607.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.