Commit graph

7356 commits

Author SHA1 Message Date
overlookmotel
6551dfef5c refactor(semantic): pass &str instead of Cow (#7972)
As suggested by clippy...
2024-12-18 02:37:12 +00:00
overlookmotel
d4d7bc08d3 refactor(transformer/async-to-generator): avoid allocating unnecessary Atoms (#7975)
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).
2024-12-18 02:25:36 +00:00
overlookmotel
8b7c5ae09c feat(ast): add AstBuilder::atom_from_cow (#7974)
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.
2024-12-18 02:25:35 +00:00
overlookmotel
c30a982da3 feat(span): add impl From<ArenaString> for Atom (#7973)
Add conversion method from `oxc_allocator::String` to `Atom`. This is a zero-cost conversion, because the string is already in the arena.
2024-12-18 02:25:34 +00:00
overlookmotel
ff9d1b35d7 refactor(transformer/class-properties): comments about shorter output (#7976)
Add TODO comments about how output could be shorter.
2024-12-17 19:21:39 +00:00
Dunqing
4ea90d4acd refactor(transformer/react-refresh): calculate signature key once (#7970)
I can't remember why I wrote such code. This change reduced big allocation.
2024-12-17 17:11:44 +00:00
overlookmotel
d59bbaed08 refactor(transformer): remove unneeded lint #[allow] (#7971) 2024-12-17 16:54:39 +00:00
overlookmotel
6fc40f030e refactor(transformer/class-properties): pass BoundIdentifiers by reference (#7968)
Don't pass by value when passing by reference is sufficient.
2024-12-17 16:34:09 +00:00
overlookmotel
69eeeea138 refactor(transformer/class-properties): methods take &self where possible (#7967)
These 2 methods don't need to take `&mut self`.
2024-12-17 15:59:09 +00:00
overlookmotel
41a14564ec docs(transformer/class-properties): correct doc comments (#7966)
Correct doc comments which were inaccurate.
2024-12-17 15:22:08 +00:00
Boshen
c16a85176d feat(napi/transform): add jsx: 'preserve' option (#7965)
closes #7958
2024-12-17 13:49:51 +00:00
branchseer
111dc52f62
fix(parser): include export token in spans of TSNamespaceExportDeclaration (#7963)
Spans of `TSNamespaceExportDeclaration`(`export as namespace Foo`)
should start with `export`:


cc89efb2b7
2024-12-17 20:55:56 +08:00
Dmitry Zakharov
ec2128e614
fix(linter): fix line calculation for eslint/max-lines in diagnostics (#7962)
closes #7961
2024-12-17 20:53:56 +08:00
Boshen
1314c9763b refactor(minifier): expose dce as an API instead of an option (#7957) 2024-12-17 04:47:13 +00:00
Dunqing
18441afe1c docs(transformer/class-properties): remove oudated todo for assignment expression (#7955) 2024-12-17 04:41:09 +00:00
overlookmotel
98340bbaa1 refactor(transformer/class-properties): use stack of ClassDetails (#7947)
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`.
2024-12-17 04:30:41 +00:00
oxc-bot
fc5380442b
release(oxlint): v0.15.3 (#7954)
## [0.15.3] - 2024-12-17

### Features

- 25ddb35 linter: Add the import/no_named_default rule (#7902)
(Guillaume Piedigrossi)
- ee26b44 linter: Enhance `get_element_type` to resolve more element
types (#7885) (dalaoshu)

### Bug Fixes

- 6f41d92 linter: False positive in `unicorn/no-useless-spread` (#7940)
(dalaoshu)
- 0867b40 linter: Fix configuration parser for `no-restricted-imports`
(#7921) (Alexander S.)
- 9c9b73d linter: Fix incorrect fixer for `prefer-regexp-test` (#7898)
(Cameron)
- 32935e6 linter: False positive in
`jsx-a11y/label-has-associated-control` (#7881) (dalaoshu)
- 14c51ff semantic: Remove inherting `ScopeFlags::Modifier` from parent
scope (#7932) (Dunqing)

### Refactor

- 3858221 global: Sort imports (#7883) (overlookmotel)
- b99ee37 linter: Move rule "no-restricted-imports" to nursery (#7897)
(Alexander S.)
- ff2a68f linter/yoda: Simplify code (#7941) (overlookmotel)

### Styling

- 7fb9d47 rust: `cargo +nightly fmt` (#7877) (Boshen)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-17 12:24:09 +08:00
Guillaume Piedigrossi
25ddb35192
feat(linter): add the import/no_named_default rule (#7902)
Co-authored-by: Boshen <boshenc@gmail.com>
2024-12-17 12:04:40 +08:00
Boshen
99a431be74
fix(coverage): make coverage runtime timeout stable (#7953)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-12-17 12:02:56 +08:00
Yuji Sugiura
a4e8ce8fe5
feat(prettier): Complete print_literal (#7952)
Part of #5068 

- [x] RegExpLiteral
- [x] BigIntLiteral
- [x] NumericLiteral
- [x] StringLiteral
  - [x] replaceEndOfLine
  - [x] makeString keep usless escape
- [x] NullLiteral
- [x] BooleanLiteral
2024-12-17 12:02:22 +08:00
翠 / green
de8a86e356
fix(minifier): incorrect minification in try_fold_left_child_op (#7949)
fixes #7944
2024-12-17 10:40:22 +08:00
Dunqing
e0d440a618
fix(wasm): use ScopeTree's flags rather than enter_scope's flags parameter (#7950)
close:
https://github.com/oxc-project/oxc/issues/7900#issuecomment-2545374960
2024-12-17 10:32:37 +08:00
Alexander S.
b961d5477a
docs(tasks/website): add legend for fixable column (#7945) 2024-12-17 10:25:11 +08:00
overlookmotel
46e2e27735 feat(data_structures): implement Default for NonEmptyStack (#7946)
Implement `Default` for `NonEmptyStack<T>` where `T: Default`.
2024-12-16 21:02:52 +00:00
overlookmotel
ff2a68f22b refactor(linter/yoda): simplify code (#7941)
Follow-on after #7679.

Simplify `do_diagnostic_with_fix`, in particular the search for the operator. Also reduce `span()` calls, as they have a cost.
2024-12-16 16:41:16 +00:00
Boshen
c3c76cb232 chore(deps): update npm packages (#7931) 2024-12-16 15:19:14 +00:00
dalaoshu
6f41d92972
fix(linter): false positive in unicorn/no-useless-spread (#7940)
closes #7936
2024-12-16 22:20:58 +08:00
overlookmotel
6f8bb1cebf
ci(benchmarks): simplify benchmarks (#7939)
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.
2024-12-16 22:01:01 +08:00
overlookmotel
3c73e86f8c ci(codegen): simplify codegen benchmark (#7938)
Follow-on after #7934. Pure refactor. Make codegen benchmark simpler.
2024-12-16 13:51:40 +00:00
Boshen
4799471c1e fix(minfier): bigint bitwise operation only works with bigint (#7937) 2024-12-16 13:25:39 +00:00
camc314
9b3a2beaa3 refactor(benchmark): transform code before codegen (#7934)
@overlookmotel suggested this [here](https://github.com/oxc-project/oxc/pull/7926#discussion_r1886023496).
2024-12-16 13:08:11 +00:00
overlookmotel
84b75a0e5f refactor(semantic)!: remove ScopeFlags::Modifiers (#7935)
#7932 removed the only usage of `ScopeFlags::Modifiers`. So we don't need it any more. Remove it.
2024-12-16 12:15:12 +00:00
Dunqing
14c51ffa1d fix(semantic): remove inherting ScopeFlags::Modifier from parent scope (#7932)
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
2024-12-16 11:26:12 +00:00
Boshen
dcb27ff6cd
ci: change setup-zig (#7930) 2024-12-16 13:52:15 +08:00
Dunqing
850dd43597 fix(codegen): missing , when generating type parameters with jsx (#7929)
close: #7917
2024-12-16 05:35:06 +00:00
overlookmotel
d94923d3b2
fix(tools): just submodules update transformer test fixtures (#7893)
`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.
2024-12-16 13:20:17 +08:00
Dunqing
b8d2bd2eba refactor(semantic): move determining references flags for export specifier to visit_export_named_declaration (#7924)
``` 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`.
2024-12-16 02:26:53 +00:00
Dunqing
596aead0e9 fix(semantic): reset references flags when resolved (#7923)
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.
2024-12-16 02:26:52 +00:00
Dunqing
523d48ccb2 test(transformer): move named test to exports folder (#7922)
I made a mistake, I should have put it in the `exports`  folder and not `export`
2024-12-16 02:26:51 +00:00
Alexander S.
e2b6233284
refactor(language_server): add capabilities struct (#7906)
vscode test from local, 
intellij test from
https://github.com/oxc-project/oxc/pull/7445#issuecomment-2496950216
2024-12-16 10:25:26 +08:00
Alexander S.
0867b40e00
fix(linter): fix configuration parser for no-restricted-imports (#7921)
follow up from #7916
2024-12-16 10:21:31 +08:00
overlookmotel
10a86b9242 docs(transformer): fix comments (#7925)
Fix comment. It was inaccurate previously.
2024-12-15 22:42:36 +00:00
overlookmotel
02b653c061 feat(transformer/class-properties): do not create temp var for template literal computed key (#7919)
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;
}
```
2024-12-15 16:55:00 +00:00
overlookmotel
b31f123b7f perf(transformer/class-properties): do not re-generate same method key (#7915)
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.
2024-12-15 16:54:59 +00:00
overlookmotel
088dd481df refactor(transformer/class-properties): shorten code (#7913)
Use `SymbolTable::symbol_is_mutated`, rather than repeating the same logic.
2024-12-15 16:54:58 +00:00
overlookmotel
f4cb5d3c95 docs(transformer): clarify comment (#7918) 2024-12-15 15:06:27 +00:00
overlookmotel
1317c00a5d docs(transformer/class-properties): clarify doc comments (#7914)
Use `prop` for property name in comments, to match everywhere else in this transform.
2024-12-15 14:54:47 +00:00
overlookmotel
544ffbf6c7 refactor(transformer/class-properties): split up code into multiple files (#7912)
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`.
2024-12-15 14:17:29 +00:00
overlookmotel
9989b58b1c docs(transformer/class-properties): re-order file list in doc comment (#7911)
Re-order list to reflect order transforms occur.
2024-12-15 14:11:47 +00:00
翠 / green
db9e93b554
feat(mangler): mangle top level variables (#7907)
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>
2024-12-15 21:31:41 +08:00