Commit graph

6803 commits

Author SHA1 Message Date
Boshen
65f1e82bd8 refactor(transform_conformance): clean up some code (#7354) 2024-11-19 09:15:14 +00:00
Boshen
4c367b6746
chore(deps): update codecov/codecov-action action to v5 (#7353)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-19 16:01:09 +08:00
overlookmotel
c335f92ada perf(syntax): reorder operator enum variants (#7351)
Re-order enum variants of `AssignmentOperator`, `BinaryOperator` and `UnaryOperator`.

* `Exponential` moved to after `Remainder` (so with the rest of the arithmetic operators).
* `Shift*` operators follow arithmetic operators.
* `AssignmentOperator::Bitwise*` ops moved to before `Logical*` ops (so all ops which correspond to `BinaryOperator`s are together).
* `*Or` always before `*And`.
* Plus/Addition always before Minus/Subtraction.

The purpose is to make the various methods on these types maximally efficient:

1. Group together variants so that `AssignmentOperator::is_*` methods can be executed with the minimum number of operations (essentially `variant - min <= max`).
2. Align the variants of `AssignmentOperator` and `BinaryOperator` so that conversion methods added in #7350 become very cheap too (essentially `if variant - min <= max { Some(variant + offset) } else { None }`).
2024-11-19 01:23:28 +00:00
Dmitry Zakharov
bc0e72c1e2
fix(linter): handle user variables correctly for import/no_commonjs (#7316)
test case found in `typescript/no-require-imports`
2024-11-19 09:23:16 +08:00
Ryan Walker
1d9f528668
feat(linter): implement unicorn/prefer-string-raw lint rule (#7335)
Implements
[unicorn/refer-string-raw](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-raw.md)
for #684
2024-11-19 09:22:40 +08:00
overlookmotel
2534cdecb7 feat(syntax): add AssignmentOperator::to_logical_operator and to_binary_operator methods (#7350)
Add methods to convert `AssignmentOperator` to `LogicalOperator` or `BinaryOperator`. e.g. `+=` -> `+`, `&&=` -> `&&`.
2024-11-19 01:12:11 +00:00
overlookmotel
41a0e60c3e refactor(ast)!: remove impl GetAddress for Function (#7343)
`impl GetAddress for Function` was added as a hack, in the absence of another way to get the `Address` of a `&Function` (https://github.com/oxc-project/backlog/issues/140).

Remove it, and use `Address:from_ptr` instead in JSX Refresh transform, which is only place using it.
2024-11-19 01:05:31 +00:00
Alexander S.
4b8aecc8ed
ci(editor): add lint and compile checks (#7346) 2024-11-19 09:05:19 +08:00
overlookmotel
b5a202711c style(syntax): improve formatting (#7349)
Style nit. Adjust formatting.
2024-11-18 22:26:30 +00:00
dalaoshu
bf839c1dfa
fix(linter): false positive in jest/expect-expect (#7341)
closes #7237
2024-11-18 15:17:36 +00:00
leaysgur
167d2d560d chore(docs): Replace TAB with SPACE to render markdown correctly (#7337)
Possibly fixes #7336
2024-11-18 11:54:33 +00:00
Boshen
7b83a3ddfa
chore(tasks/coverage): update runtime.snap 2024-11-18 18:01:49 +08:00
overlookmotel
c84e892380 perf(ast): AstBuilder::vec1 use Vec::from_array_in (#7334)
`AstBuilder::vec1` can use `Vec::from_array_in` rather than creating a `Vec` and then pushing to it. This should optimize better.
2024-11-18 02:35:46 +00:00
overlookmotel
510b95d6c4 perf(transformer): use AstBuilder::vec_from_array (#7333)
Use `AstBuilder::vec_from_array` introduced in #7331 in the transformer, in place of creating a `Vec` with `Vec::with_capacity` and then pushing values to it.
2024-11-18 02:35:46 +00:00
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