Commit graph

7329 commits

Author SHA1 Message Date
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
翠 / green
075bd165a8
feat(minifier): fold bitwise operation (#7908)
This PR implements constant evaluation for bitwise operations (`&`, `|`,
`^`).

I wanted to play around with the minifier a bit 🙂
2024-12-15 21:27:05 +08:00
overlookmotel
dcaf674aa8 refactor(transformer/class-properties): rename file (#7910)
Pure refactor. Rename file for clarity that it relates to transform of private fields (`this.#prop`) and not private property declarations (`#x = 123`).
2024-12-15 13:01:16 +00:00
overlookmotel
73900482c3 docs(transformer/class-properties): reformat doc comment (#7909) 2024-12-15 12:22:31 +00:00
overlookmotel
a5f04a72b5 perf(ast): faster Comment::is_jsdoc (#7905)
Small optimization.

Replace string slice + `starts_with` (at least 3 x bounds checks + 2 x UTF8 character boundary checks) with a single byte read (1 x bounds check).
2024-12-15 04:28:27 +00:00
Alexander S.
b99ee37326
refactor(linter): move rule "no-restricted-imports" to nursery (#7897)
many options are not supported:

https://github.com/oxc-project/oxc/issues/7810#issuecomment-2543182046
2024-12-15 12:26:47 +08:00
Cameron
9c9b73dadb
fix(linter): fix incorrect fixer for prefer-regexp-test (#7898)
closes #7793
2024-12-15 12:06:52 +08:00
overlookmotel
8ca8fce4e1 perf(transformer/class-properties): reduce work updating scopes when transforming static prop initializers (#7904)
Static property initializers need to be modified in various ways. One is to change the parent scope of the first level of scopes in the initializer to the new parent scope.

Lots of nodes which have scopes cannot be the first level. e.g. an `IfStatement` cannot because it would have to be inside a function, and that function would be the first-level scope. The `IfStatement` must be a nested scope, so we know we won't need to update its parent.

Skip checking if we need to update parent scope for all these nodes.
2024-12-15 01:53:14 +00:00
overlookmotel
80d0b3e10f perf(transformer/class-properties): fast path for instance prop initializer scope re-parenting (#7901)
Add a fast path for inserting instance property initializers into constructor, when no existing constructor or constructor has no bindings. This should be reasonably common.

The `Scope flags mismatch` errors are due to #7900.
2024-12-15 01:53:13 +00:00
overlookmotel
feac02e65b feat(transformer/class-properties): only rename symbols if necessary (#7896)
#7872 implements renaming symbols in constructor which shadow references in instance property initializers. But we don't need to rename where the reference in initializer references a symbol which is bound within the initializer itself.

Input:

```js
class C {
  double = n => n * 2;
  constructor(n) {
    console.log(n);
  }
}
```

Output:

```js
class C {
  constructor(n) { // <-- not renamed
    this.double = n => n * 2; // <-- moved into constructor
    console.log(n); // <-- not renamed
  }
}
```

This produces better output, and avoids a traversal of constructor's AST renaming symbols.
2024-12-15 01:53:13 +00:00
overlookmotel
e76fbb0721 fix(transformer/class-properties): fix symbol clashes in instance prop initializers (#7872)
Instance property initializers are moved into constructor. If symbols they reference are shadowed within constructor, rename those symbols.

Input:

```js
class C {
  prop = foo();
  constructor(foo) {
    console.log(foo);
  }
}
```

Output:

```js
class C {
  constructor(_foo) { // <-- renamed
    this.prop = foo(); // <-- moved into constructor
    console.log(_foo); // <-- renamed
  }
}
```
2024-12-15 01:53:12 +00:00
Alexander S.
f0a8d8aab7
refactor(tasks/lint_rules): detect typescript alias from mod.rs file (#7891)
based on #7890

tried graphite, but I do not have write access to this repo.  
Do not know how to create Branches on a Fork and the PRs on the Forked
Project.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-12-15 00:14:15 +08:00
overlookmotel
0804916b28 test(transformer): make update fixtures script .mjs (#7892)
`.mjs` to match `reporter.mjs` in same directory.
2024-12-14 15:29:21 +00:00
overlookmotel
3858221f45 refactor(global): sort imports (#7883)
Pure refactor. Re-order imports for clarity:

1. `std`
2. External crates
3. `oxc_*` crates
4. Current crate `use crate::...`
5. Super `use super::...`
6. Local modules

This order is from "furthest away" to "closest". This makes it clearer to see what is coming from where.

`cargo +nightly fmt` (#7877) did a lot of the work, but unfortunately `rustfmt` does not have an option to (a) put workspace crates in a separate block from external crates and (b) move `mod` statements to after `use` statements.
2024-12-14 15:07:21 +00:00
overlookmotel
2c942362da refactor(transformer): improve encapsulation of transforms (#7888)
Modules in `oxc_transformer` only export the minimum required, to make the transforms less tightly coupled to each other.
2024-12-14 14:48:28 +00:00
overlookmotel
98d794673b refactor(semantic): import flags and ID types from oxc_syntax (#7887)
`oxc_semantic` had a bit of a mess of modules importing and re-exporting symbols from `oxc_syntax` all over the place. I assume this is a leftover from when our crates were structured differently.

Make this consistent by always importing `oxc_syntax`'s symbols from `oxc_syntax`, and only re-export them from the crate root.
2024-12-14 14:48:28 +00:00
overlookmotel
b9322c68e6 feat(semantic): re-export all flags and ID types (#7886)
`oxc_semantic` already re-exports `ScopeId`, `ScopeFlags`, `SymbolId` and `SymbolFlags` from `oxc_syntax`. It seems inconsistent that it doesn't also re-export `ReferenceId`, `ReferenceFlags`, `NodeId` and `NodeFlags` too. Do that.
2024-12-14 14:48:27 +00:00
dalaoshu
ee26b448cc
feat(linter): enhance get_element_type to resolve more element types (#7885)
I think it should if makes sense.

_Originally posted by @Boshen in
https://github.com/oxc-project/oxc/issues/7881#issuecomment-2543108246_
            

Since `jsx-a11y` supports these names, I have aligned them accordingly.
2024-12-14 22:45:37 +08:00
overlookmotel
7637aac21f style(ast_tools): reformat macro (#7884)
Fix indentation in macro definition.
2024-12-14 13:51:50 +00:00
dalaoshu
32935e6875
fix(linter): false positive in jsx-a11y/label-has-associated-control (#7881)
closes #7849

This is essentially because `get_element_type` does not support
recognizing tag names like `<a.b />`. I'm unsure whether we should
support it.
2024-12-14 21:22:31 +08:00
overlookmotel
fb897f6c3a style(data_structures): add line break (#7882) 2024-12-14 13:16:49 +00:00
Boshen
81eedb10c0 feat(parser): 'readonly' type modifier is only permitted on array and tuple literal types. (#7880) 2024-12-14 12:00:52 +00:00
Boshen
7a087b914e
ci: update .github/workflows/ci_security.yml 2024-12-14 17:45:39 +08:00
overlookmotel
38aafa25a6 perf(transformer/class-properties): reduce size of transform_call_expression_for_super_member_expr (#7859)
Follow-on after #7831. Break up `transform_call_expression_for_super_member_expr` into multiple functions, to make `transform_call_expression_for_super_member_expr` as small as possible, to encourage inlining it.
2024-12-14 08:06:33 +00:00
IWANABETHATGUY
9a309103a4
fix(oxc_transformer): inject_global_variables should considering string imported name (#7768)
Co-authored-by: Boshen <boshenc@gmail.com>
2024-12-14 16:05:56 +08:00
Boshen
9d77ab79f1
Update FUNDING.yml 2024-12-14 15:29:41 +08:00
Boshen
7fb9d47460 style(rust): cargo +nightly fmt (#7877) 2024-12-14 06:03:31 +00:00
oxc-bot
b40c410824
release(oxlint): v0.15.2 (#7876)
## [0.15.2] - 2024-12-14

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-14 13:37:03 +08:00