Commit graph

6789 commits

Author SHA1 Message Date
overlookmotel
39afb48025 feat(allocator): introduce Vec::from_array_in (#7331)
Because we lack specialization in stable Rust, `Vec::from_iter_in` is unable to take advantage of the fact that `[T; N]` has a statically knowable size.

Introduce `Vec::from_array_in` for this case, which should be able to create the `Vec` with a single static-sized memcpy, or may allow the compiler to see that it can construct the array directly in the arena, rather than construct on stack and then copy to the arena.

Also add a corresponding `AstBuilder::vec_from_array` method, and use it in various places in codebase.
2024-11-18 02:35:46 +00:00
overlookmotel
1938a1d6d9 refactor(isolated_declarations): do not copy Vec unnecessarily (#7332)
This function receives an owned `oxc_allocator::Vec`. No need to copy the contents to a new `Vec` with `AstBuilder::vec_from_iter`, can just use the original.
2024-11-18 02:28:38 +00:00
overlookmotel
44fd962fbb perf(transformer/arrow-functions): move arguments transform checks to aid inlining (#7322)
Move the cheap "does arguments need to be transformed" checks introduced in #7321 into `enter_identifier_reference` and `enter_binding_identifier`, and mark those methods `#[inline]`. These hot paths can then usually execute without a function call.

This wins back the other half of the perf hit of #7234.
2024-11-17 10:49:17 +00:00
overlookmotel
26d3e96aca perf(transformer/arrow-functions): store state of whether arguments needs transform (#7321)
Track whether `arguments` needs to be transformed. If it doesn't, can skip expensive checks for whether `IdentifierReference`s and `BindingIdentifier`s names are `arguments` or not.

This recovers about half the performance hit of #7234.
2024-11-17 10:49:16 +00:00
overlookmotel
871e19bea2 refactor(transformer/arrow-function): comments on possible improvement (#7320) 2024-11-17 10:07:35 +00:00
overlookmotel
ea08c1f495 refactor(transformer/arrow-function): reserve correct capacity for Vec (#7319) 2024-11-17 10:07:35 +00:00
overlookmotel
e09d2df448 perf(transformer/arrow-function): create super method binding names lazily (#7313)
Key `super` getter/setter hash map with original property name `&str`, instead of generated binding name. This allows a couple of improvements:

* Generate binding names for `super` getters/setters lazily, only when they're created, rather than every time you encounter a `super`.
* Don't allocate strings into arena which are never used as part of AST. Use `CompactString` for building those strings instead.
2024-11-17 10:07:34 +00:00
overlookmotel
5d853869eb refactor(transformer/arrow-functions): use IndexMap for super getter/setters (#7317)
Generate getter/setter declarations in same order as Babel by using `IndexMap` instead of `HashMap` to store `super` getter/setter method details.
2024-11-17 10:07:34 +00:00
overlookmotel
0a2470399e perf(transformer/arrow-function): optimize generate_super_binding_name (#7312)
Optimize this function in various ways:

* Return a static `Atom` (rather than allocating into arena) if no `property`.
* Reserve capacity for `ArenaString` at start.
* Make path for unicode identifiers (very rare case) `#[cold]` and `#[inline(never)]`.
* Slightly faster uppercase conversion.
2024-11-17 10:07:34 +00:00
overlookmotel
389b84e4ff fix(transformer/arrow-function): handle unicode when capitalizing property name (#7311)
Previously was assuming property name starts with an ASCII character. If it started with a multi-byte unicode char, `&property[1..]` would panic.
2024-11-17 10:07:34 +00:00
overlookmotel
5cfe0b623e refactor(transformer/arrow-function): generate_super_binding_name take &str and &TraverseCtx (#7310)
Pure refactor. Take `&str` rather than `&Atom` (1 less indirection) and `&TraverseCtx<'a>` (more conventional).
2024-11-17 10:07:33 +00:00
Nicholas Rayburn
7b7555a0ab
docs(website): Link to specific ref when generating website docs (#7324)
Currently the website links to main which is subject to change without
an update to the website. This updates the website to link to the
specific commit that was used when the website was published.

Feel free to cleanup anything in this PR.
2024-11-17 14:23:00 +08:00
Dunqing
7d75130865 fix(transformer/async-to-generator): arguments isn't correct after transformation (#7234)
Fix due to this plugin transforming the async method and async arrow function, it caused arguments no longer point the original function.

For example:

Before

```js
class Cls {
  async method() {
    () => {
    	console.log(arguments)
    }
  }
}
```

After:

```js
class Cls {
  method() {
    var _arguments = arguments;
    return babelHelpers.asyncToGenerator(function* () {
      () => {
        console.log(_arguments);
      };
    })();
  }
}
```

In this way, the `_arguments` is its original function's arguments

### For performance regression

It seems we need to check the IdentifierReference and BindingIdentifier if it's an `arguments`, that causes a significant regression, we may need a cheap way to do checking
2024-11-17 05:01:44 +00:00
Ryan Walker
d445e0f612
feat(linter): implement unicorn/consistent-existence-index-check (#7262)
[unicorn/consistent-existence-index-check](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/consistent-existence-index-check.md)
for #684

---------

Co-authored-by: Cam McHenry <camchenry@users.noreply.github.com>
2024-11-16 20:07:52 +00:00
dalaoshu
28d37e478d
chore(justfile): add pnpm install to init (#7297)
Recently, due to some issues, I had to re-clone the oxc project multiple
times. After running `just init`, I always had to run `pnpm install`
separately. We could include `pnpm install` to init command to
streamline the process. In addition, I propose to include
`cargo-binstall` in the init command.

I'm not sure if we should include the `submodules` command in the init
command, as it is generally unnecessary for most users unless they are
working on specific projects like the minifier.
2024-11-17 00:30:56 +08:00
Song Gao
cf3415b0e4
chore(doc): replace main/master to tag/commit to make the url always accessible (#7298) 2024-11-16 21:00:30 +08:00
Nicholas Rayburn
4c124a86ea
docs(editor/vscode): Update VS Code readme with installation instructions and available features (#7306) 2024-11-16 14:53:51 +08:00
7086cmd
cf99be0a0d fix(minifier): do not compare bigint with object (#7294)
@Boshen, could you please update the snap of runtime and commit to this PR? I want to see the effects after the unit tests are added.
2024-11-16 06:01:06 +00:00
camchenry
20d9080d59 fix(linter)!: override plugins array when passed in config file (#7303)
- fixes https://github.com/oxc-project/oxc/issues/6896

When the `plugins` config property is specified, it will overwrite the default plugins array. This allows the plugins list to be easily customized and allows for disabling default plugins at the same time as enabling non-default ones.

- example: `{ "plugins": [] }` will enable no plugins.
- example: `{ }` will enable default plugins.
- example: `{ "plugins": ["typescript", "import"] }` will enable only the import and typescript plugins.
2024-11-16 05:54:05 +00:00
overlookmotel
d135d3ec48 feat(data_structures): add methods to SparseStack (#7305)
Add methods to `SparseStack` to get the filled entries as a slice, and get their length.
2024-11-16 05:36:36 +00:00
overlookmotel
4acf2db82b refactor(transformer): helper loader methods take Span (#7304)
`TransformCtx::helper_call` and `TransformCtx::helper_call_expr` take a `Span`. Sometimes the helper call replaces some original code, and should have the same span as the original code.
2024-11-16 05:36:35 +00:00
overlookmotel
faf8dde4ff feat(traverse): add methods for creating Expression::Identifiers (#7301)
It's a common pattern in transformer to call `ctx.create_ident_reference()` and then convert to an `Expression` with `Expression::Identifier(ctx.ast.alloc(ident))`.

Add methods to do this in a single method call.
2024-11-16 05:36:35 +00:00
Alexander S.
ba0b2ff856
fix(editor): reload workspace configuration after change (#7302)
after changing `settings.json`, the changes whould not to updated
internally.

With this PR the updated values get passed to the language-server. 🥳 

probably closes https://github.com/oxc-project/backlog/issues/132
because we also support the oxlint config

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-16 13:34:44 +08:00
overlookmotel
1cbc624a8b refactor(traverse)!: rename TraverseCtx methods for creating IdentifierReferences (#7300)
`create_reference_id` was a confusing name, as it doesn't return a `ReferenceId`. Rename these methods to more clearly represent what they do.
2024-11-15 16:44:08 +00:00
overlookmotel
a0766e6a7f fix(codegen): fix arithmetic overflow printing unspanned nodes (#7292)
Similar to #7289. Check if `span.end` is 0 before doing `span.end - 1`, to prevent arithmetic overflow.

Also changed all checks to `span.end > 0`, just for consistency.
2024-11-15 16:04:02 +00:00
dalaoshu
16cfb96a79
fix(justfile): make submodules work on windows (#7293)
Related to #7290, closes #7296 

By default, `Windows` encounters the following issue unless the user
installs `PowerShell 7` (pwsh).

```bash
error: Recipe `submodules` could not be run because just could not find the shell: program not found
error: Recipe `init` could not be run because just could not find the shell: program not found
```

Furthermore, I have found a better way to solve this problem.
2024-11-16 00:03:23 +08:00
overlookmotel
f4213b8d12
fix(tools): just test-transform run conformance only once (#7295)
`--exec` flag also runs the non-exec tests, so it's not required to run
it twice.
2024-11-16 00:02:54 +08:00
Song Gao
ea9ca8ab10
fix(just): make submodules work on windows (#7290)
Fix #7282 
- Change default shell to powershell 7(pwsh) to supports "&&"
- change url from git protocol to https protocol. This does not need a
public token(I do not know what it is...).
- specify different submodule init command for windows

Co-authored-by: Song Gao <songgao@microsoft.com>
2024-11-15 18:55:03 +08:00
Boshen
8d8f34cfb5
chore(tasks/coverage): update runtime.snap 2024-11-15 12:48:56 +08:00
overlookmotel
33ec4e6182 fix(codegen): fix arithmetic overflow printing unspanned NewExpression (#7289)
`self.span.end - 1` overflows if the `NewExpression` is generated in transformer and has no span, so `self.span.end == 0`.
2024-11-15 02:56:49 +00:00
Song Gao
8da23692fc
build(traverse): generate files in parallel (#7281)
Create type files in parallel. Although it's already pretty fast, always better to be faster.
2024-11-14 23:04:53 +00:00
overlookmotel
f0dee76a4d style(ast_tools): fix wonky formatting (#7288)
Follow-on after #7283. Pure refactor. `rustfmt` was malfunctioning on this code for some reason. Alter the code slightly so it formats it nicely.
2024-11-14 22:58:16 +00:00
overlookmotel
f0affa20c6 docs(ast): improve docs examples for PropertyDefinition (#7287) 2024-11-14 22:28:14 +00:00
Boshen
b57d00d6fb fix(tasks/compat_data): fix misplaced features (#7284)
closes #7279
2024-11-14 16:36:16 +00:00
overlookmotel
9f5ae56810 refactor(transformer/nullish-coalescing): split main logic into separate function (#7273)
Small refactor. Move main logic of the transform into a separate function, to allow `enter_expression` to be inlined.
2024-11-14 16:17:23 +00:00
overlookmotel
345fbb9da3 refactor(transformer/nullish-coalescing): avoid repeated symbol lookups (#7272)
`clone_expression` was unnecessarily looking up the `SymbolId` of references multiple times. Use `BoundIdentifier` instead to avoid that.

Notes:

* `create_conditional_expression` has to take all parts as `Expression`s just to support `this ?? something`.
* `TraverseCtx::is_static` also handles `Super`, but can skip that in this case as `super ?? something` is not valid syntax.
2024-11-14 16:17:23 +00:00
overlookmotel
5b5c8a9bdb fix(transformer/nullish-coalescing): correct span (#7269)
Transformed expression inherit same `Span` as the input.
2024-11-14 16:17:22 +00:00
overlookmotel
e219ae8c94 docs(transformer/nullish-coalescing): clarify doc comment (#7268)
Expand doc comment for `create_conditional_expression` to clarify what it does.
2024-11-14 16:17:21 +00:00
dalaoshu
a48ebd6295
fix(tasks): cargo clippy error on rust 1.82.0 (#7283)
I mentioned this clippy issue in the discord help channel. The problem
seems to be related to using the stable rust toolchain, but when I
switched to version `1.81.0`, the issue was resolved.

However, some of the clippy suggestions might still be worth considering
and could be adopted.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-15 00:08:04 +08:00
no-yan
01ddf37843
feat(linter): add allowReject option to no-useless-promise-resolve-reject (#7274)
followup to #7232.
2024-11-14 14:06:55 +00:00
overlookmotel
84038ee434 refactor(semantic): shorten code (#7277)
Tiny refactor. No need for `matches!` here.
2024-11-14 12:50:06 +00:00
overlookmotel
9e85cc10c9 refactor(semantic): remove duplicated code (#7276)
`if matches!(self.kind, TSModuleDeclarationKind::Global)` at top of function already performed this check, no need to check it again.
2024-11-14 12:50:04 +00:00
no-yan
755a31bda7
feat(linter): support bind function case for compatibility with promise/no-return-wrap (#7232)
part of #4655

### Summary

Logic has been added to handle bind functions, unifying the
implementations of `unicorn/no-useless-promise-resolve-reject` and
`promise/no-return-wrap`.
This enables detection of the following code:

```javascript
foo().then((function() { return Promise.resolve(4) }).bind(this))
```

Merging this PR will allow this rule to pass all test cases of
promise/no-return-wrap without options. Additionally, merging #7274 will
ensure that all test cases are passed.
2024-11-14 19:33:42 +08:00
Dmitry Zakharov
428770edee
feat(linter): add import/no-namespace rule (#7229) 2024-11-14 19:23:56 +08:00
camc314
ff2a1d4937 fix(linter): move exhaustive-deps to react (#7251)
@Boshen lemme know if this is incorrect, but i noticed that `rules-of-hooks` lives inside `react` not `react-hooks`

1f2a6c666f/crates/oxc_linter/src/config/rules.rs (L291-L292)

1f2a6c666f/crates/oxc_linter/src/options/filter.rs (L254)
2024-11-14 08:02:26 +00:00
Alexander S.
216d533b01
fix(language_server): revalidate files when oxlint config is changing (#7259)
![lsp-refresh-files](https://github.com/user-attachments/assets/e6b64f73-966d-490a-9191-b3ec64d3ac1e)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-14 10:45:17 +08:00
overlookmotel
10cdce9b67 style(ast): add line break (#7271) 2024-11-13 15:45:44 +00:00
ottomated
897d3b1567 feat(ast): serialize StringLiterals to ESTree without raw (#7263)
#7211 alternative. Makes the `raw` field on estree literals optional.
2024-11-13 15:37:30 +00:00
overlookmotel
e84ea2c3c6 refactor(traverse)!: remove TraverseCtx::clone_identifier_reference (#7266)
Remove `TraverseCtx::clone_identifier_reference`.

This API encourages unnecessary repeated lookups of the `SymbolId` for a reference. It is preferable to use `MaybeBoundIdentifier` which only looks up the `SymbolId` once.
2024-11-13 15:12:35 +00:00
overlookmotel
8c754b1b43 feat(traverse): introduce MaybeBoundIdentifier (#7265)
`MaybeBoundIdentifier` is similar to `BoundIdentifier`, but can be used where the identifier may or may not have have a `SymbolId` (may or may not be bound).

Typical usage:

```rs
// Create `MaybeBoundIdentifier` from an existing `IdentifierReference`
let binding = MaybeBoundIdentifier::from_identifier_reference(ident, ctx);

// Generate `IdentifierReference`s and insert them into AST
assign_expr.left = binding.create_write_target(ctx);
assign_expr.right = binding.create_read_expression(ctx);
```
2024-11-13 15:12:33 +00:00