Separate out attributes which communicate info to codegen related to scopes into `#[scope]` attr.
Before:
```rs
#[visited_node(scope(ScopeFlags::empty()))]
pub struct BlockStatement<'a> { /* ... */ }
```
After:
```rs
#[visited_node]
#[scope]
pub struct BlockStatement<'a> { /* ... */ }
```
I think this is clearer.
Fix scope and spans in TS `enum` transform.
Incomplete - not yet fixed either scopes or spans for the interior of the function which TS `enum` is transformed into, only what's outside the function.
Rule Detail:
[link](https://github.com/import-js/eslint-plugin-import/blob/v2.29.1/docs/rules/max-dependencies.md)
---
This lacks the handling of `require()` which seems to be the case for
most existing `import` rules.
Another "issue" could be if you have:
```
import { foo } from "./foo";
import { bar } from "./foo";
```
But then again there should be another rule to filter these duplicate
imports out and combine them into one.
Co-authored-by: Don Isaac <donald.isaac@gmail.com>
This improves `GraphicalReportHandler` logic by using a string-buffer
with a capacity hint. That avoids growing the buffer from zero each
time, saving a bunch of reallocations.
Since this is a temporary solution in the time that we are waiting for the `#[span]` hint, And there are already other workarounds used in our `ast_codegen` I propose removing it right away - sorry in my opinion adding it in the first place was a mistake - in favor of adding an edge case in the codegen. It is better to do the refactoring in the codegen instead of the production code which people may depend on.
As discussed in #3483, `AstBuilder::copy` is unsound. It's going to be a
hard slog removing all uses of it. This PR adds a comment to please not
introduce any further usages of it in meantime.
Improve annotation of AST types for codegen.
Currently:
```rs
#[visited_node(
scope(ScopeFlags::empty()),
enter_scope_before(cases),
)]
pub struct SwitchStatement<'a> {
pub span: Span,
pub discriminant: Expression<'a>,
pub cases: Vec<'a, SwitchCase<'a>>,
pub scope_id: Cell<Option<ScopeId>>,
}
```
After this PR:
```rs
#[visited_node(scope(ScopeFlags::empty()))]
pub struct SwitchStatement<'a> {
pub span: Span,
pub discriminant: Expression<'a>,
#[scope(enter_before)]
pub cases: Vec<'a, SwitchCase<'a>>,
pub scope_id: Cell<Option<ScopeId>>,
}
```
I think this is easier to read.
In order to enable use of `#[scope]` attr, this introduces a dummy `VisitedNode` derive macro. Like the `visited_node` macro, `VisitedNode` derive macro is designed to do very minimal work and have no heavy dependencies, so it should be almost 0 cost in terms of compile time.
Fix#3848.
#3830 added a `directives` field to `TSModuleBlock`. ESTree AST treats directives in module blocks as `StringLiteral`s. Add a custom `Serialize` impl to combine any directives back into `body` in JS AST.
NB: `#[serde(skip)]` attr on `directives` field is for benefit of `Tsify` derive macro, so TS defs match the actual JSON AST.
#3855 added a `span` field to `BindingPattern` but it's duplicate information from `BindingPatternKind`. `BindingPatternKind`'s `span` is already included in JS AST, so serde can skip the duplicate in `BindingPattern`.