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.
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.
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.
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.
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.
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.
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.
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
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.
- 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.
`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.
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.
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>
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.
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.
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>
`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.
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>
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.
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.
`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);
```