oxc-project / backlog

backlog for collborators only
1 stars 0 forks source link

Store `Reference`s for TS identifers separately in `Semantic` #36

Closed overlookmotel closed 4 weeks ago

overlookmotel commented 4 months ago

Boshen's idea from today's meeting:

Store references used in TS IdentiferReferences separately from normal references:

pub struct SymbolTable {
    pub resolved_references: IndexVec<SymbolId, Vec<ReferenceId>>,
    pub resolved_ts_references: IndexVec<SymbolId, Vec<ReferenceId>>,
    /* ... more ... */
}

Advantage is that when transforming TS to JS, you can just clear resolved_ts_references (or ignore it) when calculating if a symbol is referenced or not.

Symbols would be stored together regardless of whether they're types or not to allow for when a symbol is used in both contexts e.g.:

import Foo from 'foo';
let foo = new Foo(); // JS usage
function bar(foo: Foo) {} // TS usage

Maybe use a different AST type TSIdentiferReference for identifiers in TS contexts, to simplify visitors.

See also the point "Get rid of Reference" in #32.

overlookmotel commented 3 months ago

https://github.com/oxc-project/oxc/issues/3799 is relevant. Possible we don't want to resolve TS identifier references at all.

Boshen commented 4 weeks ago

We conformed to tsc's "container" concept instead.