Remove several `Atom` allocations from this function.
1. Take a `Cow<'a, str>` instead of `&str`, and use `AstBuilder::atom_from_cow` to avoid reallocating the string when possible.
2. Create a static `Atom` for `"_"` (no allocation required, as `"_"` is a `&'static str`).
3. `name` is an `ArenaString`, so already in arena. Convert `name` to `Atom` directly with `Atom::from`, instead of `AstBuilder::atom` (which makes a 2nd copy of the string in arena).
Various methods e.g. `PropertyKey::static_name` return a `Cow<'a, str>`.
When we need to create an `Atom` from such a `Cow`, we can avoid reallocating the string into arena again if the `Cow` already borrows an arena string. The `Atom` can reference that same string, rather than making another copy of it in arena.
Add `AstBuilder::atom_from_cow` method for this purpose.
Replace stack of `PrivateProps` with a stack of `ClassDetails`.
Primary purpose is to prepare for further changes to come, but this also allows removing the messy hack of storing `ClassBindings` in 2 places, and having to decide which is the source of truth at any given moment. Now there is only 1 copy of `ClassBindings`.
Pure refactor. Use `bench_function` instead of `bench_with_input` and
just borrow data from outside closure. This shortens the code and (I
think) makes it easier to read.
close: #7900
After #4283 changed, we don't need to inherit `ScopeFlags` from the `constructor`, `set`, `get` anymore, I think this is a logic of forgetting to remove
`just submodules` run `just update-transformer-fixtures`. Otherwise
after updating submodules, transformer tests will break. Most people
won't know that they need to run `just update-transformer-fixtures` too.
Also make `just update-transformer-fixtures` work on Windows.
``` ts
export type { a };
export { type b };
```
In the above cases, `a` and `b` are both type-only references. Before, we handled them in `visit_export_named_declaration` and `visit_export_specifier`, but it doesn't look intuitive due to we need to determine
if `ExportNamedSpecifier` is a type-only in `visit_export_specifier ` by checking if `current_reference_flags` is a type, and also needs to set it back before exit node.
This PR moves determining reference flags from `visit_export_specifier` to `visit_export_named_declaration` so that we don't need to check `current_reference_flags` and set it back because here we can always know the
if `ExportSpecifierNamed` is type-only by `ExportNamedDeclaration::export_kind::is_type`.
For this case, we set `current_reference_flags` to `ReferenceFlags::Type` for `TSInterfaceHeritage`, but never unset it, which causes resolving `fowardRef` identifier reuse `current_reference_flags` of `TSInterfaceHeritage`.
```ts
import { forwardRef } from "react";
export interface MenuTriggerProps extends Object {}
export const MenuTrigger = forwardRef();
```
In this PR, reset the `current_reference_flags` when resolved, so that we don't need to reset it in individual visit functions. This is a reasonable change because the `current_reference_flags` only applies to the next encountered identifier.
Do not create temp var for computed key which is `TemplateLiteral` with no expressions. Evaluating such a template literal cannot have side effects.
```js
class C {
[`foo`] = 1;
}
```
But this *can* have side effects:
```js
class C {
[`foo${bar}`] = 1;
}
```
Previously where a class method had a computed key which does not require a temp var (e.g. `const methodName = 'x'; class C { [methodName]() {} }`), the `PropertyKey` was consumed and replaced with a newly-generated one which was identical to the original. Skip this pointless work.
Split out methods from `class.rs` into separate files.
Note: `static_block.rs` is currently very small, but it will get bigger - a new visitor is required here to rename references to class name and `this`.
Adds `top_level` option which is similar to [terser's `toplevel`
option](https://terser.org/docs/cli-usage/#cli-mangle-options).
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>