Commit graph

6675 commits

Author SHA1 Message Date
Boshen
14ce0eef44 feat(tasks/compat_data): init compat data task (#7156) 2024-11-07 07:39:32 +00:00
Dmitry Zakharov
500effe5bb
chore(linter): correct links to docs in rules (#7183) 2024-11-07 15:20:47 +08:00
Nicholas Rayburn
eea8879642
fix(editor/vscode): Update language client id to fix the resolution of the oxc.trace.server setting (#7181)
Currently `oxc-vscode.trace.server` needs to be used to enable trace
logging for the language server. This fixes it so that
`oxc.trace.server` can be used. I can't find any guidance on what should
be used for the language client id. The VS Code ESLint plugin uses
"ESLint", so I think this change should be fine.

Ref https://github.com/oxc-project/oxc/issues/7136.
2024-11-07 13:29:52 +08:00
ottomated
9d6cc9d3af feat(estree): ESTree compatibility for all literals (#7152)
Adds some new estree macro directives:
- `#[estree(via = foo::Foo)`: Uses From to convert this struct to foo::Foo before serialization
- `#[estree(add_ts = "foo: string")]`: Adds additional fields to the typescript definitions

Used these to make all different literals estree-compatible.
2024-11-06 21:25:41 +00:00
ottomated
dc0215c906 feat(ast_tools): Add #[estree(append_to)], remove some custom serialization code (#7149)
Removed custom logic for ObjectPattern, ArrayPattern, etc. in favor of a custom attribute macro `#[estree(append_to = "foo")]` as part of #6347
2024-11-06 21:09:45 +00:00
overlookmotel
84ee581980 refactor(transformer/async-generator-functions): simplify identifying whether within an async generator function (#7170)
Follow-on after stack up to #7148.

Split `is_inside_async_generator_function` into 2 functions `yield_is_inside_async_generator_function` and `async_is_inside_async_generator_function`.

There are a couple of differences between `yield` and `await`, which we can leverage to make both these functions simpler:

* `yield` cannot appear at top level (there's no such thing as "top level yield").
* `yield` cannot appear in an arrow function (there's no such thing as a "generator arrow function").

In addition:

* Because each function now handles a specific case, no need to check if function containing `async` is an async function. It must be. Ditto for `yield`.
* Remove the `if ctx.current_scope_flags().is_top()` check. Probably this check costs more than it saves because top level `await` is far less common than `await` within async functions. So this check was optimizing for an uncommon case, at a cost to the common case.
* Add more comments to explain the logic.

This is all quite small optimizations, but I was having difficulty understanding the logic, and found that splitting it up made it clearer (at least for me).
2024-11-06 16:06:51 +00:00
overlookmotel
64b7e3a603 style(transformer/async-generator-functions): import oxc_allocator::Vec as ArenaVec (#7173)
Follow-on after stack up to #7148. Style nit. Following our convention (#6996), import `oxc_allocator::Vec` as `ArenaVec`, to prevent ambiguity.
2024-11-06 16:06:49 +00:00
overlookmotel
1b12328f87 refactor(transformer/async-generator-functions): use clone not clone_in on LabelIdentifier (#7172)
Follow-on after stack up to #7148.

Small optimization. `LabelIdentifier` is `Clone` so we can use `Clone::clone` to clone it, instead of `CloneIn::clone_in`.

The difference is that `clone_in` makes a 2nd copy of the `Atom`'s string in the arena, whereas `clone` creates a new `Atom` referencing the same string. This is an unfortunate shortcoming of `CloneIn` (https://github.com/oxc-project/backlog/issues/96), but the more we can avoid `CloneIn`, the better.
2024-11-06 16:06:48 +00:00
overlookmotel
c307e1b7e8 refactor(transformer/arrow-functions): pass ArenaBox as function param (#7169)
Follow-on after stack up to #7148.

Small optimization. `ArrowFunctionExpression` is 56 bytes, whereas `ArenaBox<ArrowFunctionExpression>` is 8 bytes. So it's preferable to pass the `ArenaBox<ArrowFunctionExpression>` to `transform_arrow_function_expression` and call `unbox` on it there instead of unboxing *before* passing to the function.
2024-11-06 14:08:14 +00:00
overlookmotel
38a6df6f66 style(transformer/arrow-functions): semicolon after return statements (#7168)
Follow-on after stack up to #7148. Style nit. End statements with semi-colons. Usually clippy demands this, not sure why it didn't here.
2024-11-06 14:08:12 +00:00
overlookmotel
1238506980 refactor(transformer/async-generator-function): remove inactive #[allow(clippy::unused_self)] attrs (#7167)
Follow-on after stack up to #7148. Remove 2 x `#[allow(clippy::unused_self)]` attrs where that lint isn't triggered because the functions do use their `&self` param.
2024-11-06 14:08:11 +00:00
overlookmotel
b57d5a5277 refactor(transformer/async-to-generator): remove unused &self function param (#7166)
Follow-on after stack up to #7148. Remove unused `&self` function param. This makes calling this function slightly cheaper, as unused data doesn't get passed to the function.
2024-11-06 14:08:09 +00:00
overlookmotel
217d433eb8 refactor(transformer/arrow-functions): remove unused &mut self function param (#7165)
Follow-on after stack up to #7148. Remove unused `&mut self` function params. This makes calling these functions slightly cheaper, as unused data doesn't get passed to the function.
2024-11-06 14:08:08 +00:00
overlookmotel
426df71c13 refactor(transformer/arrow-functions): use scope_id method (#7164)
Follow-on after #7125. Use `scope_id` method introduced in #7127.
2024-11-06 14:08:06 +00:00
overlookmotel
11c5e1209a refactor(transformer/arrow-functions): correct comments (#7163)
Follow-on after #7113. This comment was outdated after the changes in that PR.
2024-11-06 14:08:04 +00:00
overlookmotel
e2241e6376 refactor(transformer/jsx-self): remove unused &self function params (#7159)
Small nit. Removing the unused `&self` param makes these function calls slightly cheaper.
2024-11-06 13:11:31 +00:00
Boshen
0e1f12c303 refactor(transformer): remove unimplemented EnvOptions::bugfixes (#7162) 2024-11-06 12:54:10 +00:00
Boshen
a981cafd1f refactor(transformer): add Engine enum for EngineTargets (#7161) 2024-11-06 12:40:31 +00:00
overlookmotel
fd9b44cf13 refactor(transformer/typescript): remove inactive #[allow(clippy::unused_self)] attr (#7160) 2024-11-06 12:16:08 +00:00
overlookmotel
1dfd241125 refactor(transformer/optional-catch-binding): remove inactive #[allow(clippy::unused_self)] attr (#7158) 2024-11-06 12:02:09 +00:00
Boshen
8c0a362b8b refactor(linter): use ctx.source_range(comment.content_span()) API (#7155) 2024-11-06 06:25:05 +00:00
renovate
3da9443b0e chore(deps): update dependency @types/node to v22.9.0 (#7145)
This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@types/node](https://redirect.github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node) ([source](https://redirect.github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node)) | [`22.8.4` -> `22.9.0`](https://renovatebot.com/diffs/npm/@types%2fnode/22.8.4/22.9.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@types%2fnode/22.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@types%2fnode/22.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@types%2fnode/22.8.4/22.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@types%2fnode/22.8.4/22.9.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Configuration

📅 **Schedule**: Branch creation - "before 10am on monday" in timezone Asia/Shanghai, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/oxc-project/oxc).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xNDIuNyIsInVwZGF0ZWRJblZlciI6IjM4LjE0Mi43IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6W119-->
2024-11-06 06:17:36 +00:00
Dunqing
b2a888df0d fix(transformer/async-generator-functions): incorrect transformation for for await if it's not placed in a block (#7148)
Found in https://github.com/oxc-project/monitor-oxc/actions/runs/11681867380/job/32527898715
2024-11-06 05:51:01 +00:00
Boshen
d1d187417b feat(ast)!: change comment.span to real position that contain // and /* (#7154)
closes #7150
2024-11-06 05:10:33 +00:00
Dunqing
19892ede40 fix(transformer/async-generator-functions): transform incorrectly for for await if it's in LabeledStatement (#7147)
Found in https://github.com/oxc-project/monitor-oxc/actions/runs/11681867380/job/32527898715
2024-11-06 03:27:14 +00:00
Dunqing
8573f79c6d feat(transformer): turn on async_to_generator and async_generator_functions plugins in enable_all (#7135) 2024-11-06 03:27:13 +00:00
Dunqing
ffa8604556 feat(transformer/async-to-generator): do not transform await expression if is not inside async function (#7138) 2024-11-06 03:27:13 +00:00
Dunqing
cd1006fec1 refactor(transformer/async-generator-functions): do not transform yield expression where inside generator function (#7134) 2024-11-06 03:27:13 +00:00
Dunqing
2c5734d49b refactor(transformer/async-generator-functions): do not transform await expression where inside ArrowFunctionExpression (#7132)
The `await expr` should be transformed in AsyncToGenerator rather than AsyncGeneratorFunctions
2024-11-06 03:27:12 +00:00
Dunqing
5ce83bddc6 refactor(transformer/async-generator-functions): remove dead code for handle await expression (#7131)
I thought wrong previously, this should be transformed in the async-to-generator rather than async-generator-functions
2024-11-06 03:27:12 +00:00
Dunqing
b6a575009a feat(transformer/arrow-function-converter): move scope to changed scope for this_var if scope have changed (#7125)
The scope can be moved or deleted, we need to check whether the scope id is the same as the container's scope id, if not, we need to move the `this_var` to the target scope id.
2024-11-06 03:02:36 +00:00
Dunqing
df772411ea feat(transformer): enable ArrowFunctionConverter in async-to-generator and async-generator-functions plugins (#7113)
Part of https://github.com/oxc-project/oxc/pull/7074

In async-to-generator and async-generator-functions plugins, we may need to transform the async arrow function to a regular generator function, now we can reuse the ability of the ArrowFunction plugin by enabling `ArrowFunctionConverter`.

I will fix semantic errors in the follow-up PR
2024-11-06 03:02:36 +00:00
Boshen
0b32951637 chore(deps): update rust crate criterion2 to v2 (#7144) 2024-11-05 14:01:09 +00:00
Boshen
8340243543 refactor(transformer): rename Query to BrowserslistQuery (#7143) 2024-11-05 13:45:12 +00:00
Boshen
481f7e603e refactor(transformer): change Targets to EngineTargets (#7142) 2024-11-05 13:32:11 +00:00
Boshen
55e6989830 refactor(transformer): deserialize engine target strings to specific keys (#7139) 2024-11-05 09:27:01 +00:00
Boshen
9aa34b4896
chore(transformer): remove unused core_js_compat data 2024-11-05 14:25:41 +08:00
Boshen
9386435efb
feat(transform_conformance): use node instead of bun for exec tests (#7121) 2024-11-05 14:20:48 +08:00
overlookmotel
fac5042afa refactor(ast): use scope_id etc methods (#7130)
Utilize the methods added in #7127 in `oxc_ast`.
2024-11-05 02:25:28 +00:00
overlookmotel
cacfb9b326 refactor(traverse): use symbol_id etc methods (#7129)
Utilize the methods added in #7127 in `oxc_traverse`.
2024-11-05 02:25:28 +00:00
overlookmotel
fdfd9a4378 refactor(transformer): use scope_id etc methods (#7128)
Utilize the methods added in #7127 in transformer.
2024-11-05 02:25:27 +00:00
overlookmotel
cc8a1917e5 feat(ast): methods on AST nodes to get scope_id etc (#7127)
Add getter and setter methods to all AST types which have a `ScopeId`, `SymbolId` or `ReferenceId` field to get the contents of that field.

Before:

```rs
let symbol_id = ident.symbol_id.get().unwrap();
```

After:

```rs
let symbol_id = ident.symbol_id();
```

This allows removing boilerplate code from the transformer, and discouraging the anti-pattern of treating these fields as if they may contain either `Some` or `None` (after semantic, they will always be `Some`).
2024-11-05 02:25:27 +00:00
overlookmotel
843bce4d92 refactor(ast)!: IdentifierReference::reference_id return ReferenceId (#7126)
Alter `IdentifierReference::reference_id` to return `ReferenceId`, instead of `Option<ReferenceId>`.

This method is only useful on a post-semantic AST, where it will never return `None`. Returning `ReferenceId` discourages the anti-pattern of treating the result as if it could be either `Some` or `None`, and shortens code.
2024-11-05 02:25:27 +00:00
Dunqing
ff8bd50d38 refactor(transformer): move implementation of ArrowFunction to common/ArrowFunctionConverter (#7107)
Part of #7074

In order can reuse the ability of the `ArrowFunction` plugin, we moved out the implementation to common, then we can use use in other plugins
2024-11-04 16:32:50 +00:00
Dunqing
e04ee97870 refactor(transformer/async-generator-functions): move handling of MethodDefinition's value to exit_function (#7106)
Part of #7074

I have mentioned the reason why I need to move this in https://github.com/oxc-project/oxc/pull/7105
2024-11-04 16:27:21 +00:00
overlookmotel
ae692d70df fix(transformer/async_to_generator): fix checking if function is class method (#7117)
Follow-on after #7105.

Correctly identify when a function is a method definition. `ctx.parent().is_method_definition()` would return `true` for this weird case where the function is the property key of the method, not the method itself:

```js
class C {
    [async function() {}]() {}
}
```

`matches!(ctx.parent(), Ancestor::MethodDefinitionValue(_))` only returns `true` if the function *is* a method definition. Of course, no-one would write such ridiculous code, but we may as well handle whatever is thrown at us.

It's also slightly more performant to check for one specific ancestor type, rather than:

c2802e63fc/crates/oxc_traverse/src/generated/ancestor.rs (L1319-L1326)
2024-11-04 15:46:12 +00:00
renovate[bot]
8e90790a60
chore(deps): update rust crates (#7115) 2024-11-04 23:34:51 +08:00
Boshen
fc6dc52b72
ci(clippy): install ast-grep via npm (#7119) 2024-11-04 23:34:06 +08:00
Boshen
c2802e63fc feat(transform_conformance): add babel runtime to exec tests (#7114) 2024-11-04 14:38:15 +00:00
Dunqing
f80085c683 refactor(transformer/async-to-generator): move handling of MethodDefinition's value to exit_function (#7105)
Part of #7074

We need to handle this before the `arrow_function` plugin inserts `_this = this` because, in the `async-to-generator` plugin, we will move the body to an inner generator function. However, we don't want `_this = this` moved to the inner generator function as well. So as long as we move first, and then insert, we can fix this problem.

The new semantic error is related to another tricky problem, I will fix it in another PR
2024-11-04 14:32:42 +00:00