Commit graph

6393 commits

Author SHA1 Message Date
overlookmotel
d48e008e47
docs(napi): simplify + reformat README (#6834)
In particular:

* the long comment was scrolling off side of screen on
[npm.com](https://www.npmjs.com/package/oxc-parser).
* the example is ESM, so can simplify it by using top level await.
2024-10-24 08:34:46 +08:00
Alexander S.
dcddbeb689
chore(linter): add line break for consistent (#6837)
This regex expects always a line break before the closing bracet:
https://github.com/oxc-project/eslint-plugin-oxlint/blob/main/scripts/traverse-rules.ts#L110
2024-10-24 07:36:58 +08:00
Boshen
ec5a19b880 fix(minifier): do not remove binary expressions (#6829) 2024-10-23 16:07:29 +00:00
Tapan Prakash
2aa763c803
feat(linter): warn unmatched rule names (#6782)
Fixes https://github.com/oxc-project/oxc/issues/6763
2024-10-24 00:05:01 +08:00
Dunqing
fdd69e4b3f refactor(transformer/typescript): use TraverseCtx::generate_binding to create a symbol (#6806)
Obviously, we reduce much code after using this API
2024-10-23 15:50:11 +00:00
Dunqing
c96e739b96 feat(traverse): add generate_binding and generate_binding_current_scope APIs in context (#6805)
These two APIs are used to create a symbol with the provided symbol name, The difference from `generate_uid` is that we don't need to create a unique name for the symbol.

If you have a better method name for this, Feel free to edit this PR directly
2024-10-23 15:50:09 +00:00
Boshen
22355f73f3 fix(minifier): do not remove undefined for destructuring patterns (#6828) 2024-10-23 15:42:04 +00:00
Dunqing
5928f043b5 feat(semantic): add move_binding API in ScopeTree (#6808)
Part of #6658

This API is useful when we want to move a scope to another scope
2024-10-23 15:36:30 +00:00
Dunqing
e7e60dab68 feat(semantic): add change_parent_id API in ScopeTree (#6807)
Part of #6658

This API is useful when we want to move a scope to another scope
2024-10-23 15:29:28 +00:00
Boshen
088c1b6460 fix(coverage): turn off mangle for runtime test (#6827) 2024-10-23 15:05:36 +00:00
Boshen
7291f71019 fix(coverage): enable only_remove_type_imports for runtime transform test (#6826) 2024-10-23 14:26:48 +00:00
overlookmotel
e5f4b4a333 refactor(transformer/react-refresh): dereference ScopeId as soon as possible (#6820)
Style nit. Dereference `&ScopeId` to `ScopeId` as early as possible. `&ScopeId` is 8 bytes, whereas `ScopeId` is 4 bytes.

In simple cases like this, compiler will optimize it anyway, but still I think it's a better pattern to dererence early. In more complicated cases, it will be better for performance, and in my opinion, it makes things clearer if vars called `scope_id` are always a `ScopeId`, not sometimes a `&ScopeId`.
2024-10-23 13:26:24 +00:00
overlookmotel
57685b28e8 refactor(transformer/react-refresh): unwrap BindingIdentifier::symbol_id (#6817)
Nit. `BindingIdentifier::symbol_id` should always be `Some`. Panic rather than exiting early  if it's not.
2024-10-23 13:26:23 +00:00
overlookmotel
4f6dc22a38 refactor(transformer/react-refresh): avoid re-creating Atoms (#6816)
Store `BoundIdentifier` in `registrations`. This allows removing the call to `ctx.ast.atom()` which re-allocates a new `Atom` into the arena - unnecessary as it's already been allocated when the UID was created.

It's unfortunate that `Semantic` stores symbol names as `CompactStr`s instead of `Atom`s, otherwise we could get the name as an `Atom` without re-allocating it. Hopefully we can make that change in future, and then reduce `BoundIdentifier` to just contain the `SymbolId`. But for now, we are kind of stuck with it.
2024-10-23 13:26:23 +00:00
overlookmotel
8316069e7d refactor(transformer/react-refresh): shorten code by using BoundIdentifier (#6815)
Pure refactor. Use `BoundIdentifier` for shorter code.
2024-10-23 13:26:22 +00:00
overlookmotel
ce1d8cf20b feat(traverse): add BoundIdentifier::from_binding_ident method (#6814) 2024-10-23 13:26:21 +00:00
overlookmotel
b8dfa191be refactor(transformer): shorten code (#6809)
Use `BoundIdentifier::create_binding_pattern`, rather than writing out the code to create a `BindingPattern` manually each time.
2024-10-23 13:18:09 +00:00
overlookmotel
e59b5d919d refactor(minifier): dereference SymbolId as soon as possible (#6823)
Style nit. Dereference `&SymbolId` to `SymbolId` as early as possible. `&SymbolId` is 8 bytes, whereas `SymbolId` is 4 bytes.

In simple cases like these, compiler will optimize it anyway, but still I think it's a better pattern to dererence early. In more complicated cases, it will be better for performance, and in my opinion, it makes things clearer if vars called `symbol_id` are always a `SymbolId`, and not sometimes a `&SymbolId`.
2024-10-23 13:03:04 +00:00
overlookmotel
a148023fad refactor(linter): dereference IDs as soon as possible (#6821)
Style nit. Dereference `&ScopeId` to `ScopeId` (and other IDs) as early as possible. `&ScopeId` is 8 bytes, whereas `ScopeId` is 4 bytes.

In simple cases like these, compiler will optimize it anyway, but still I think it's a better pattern to dererence early. In more complicated cases, it will be better for performance, and in my opinion, it makes things clearer if vars called `scope_id` are always a `ScopeId`, not sometimes a `&ScopeId`.
2024-10-23 12:57:55 +00:00
Boshen
11077708bb fix(coverage): inject babel helpers for transform (#6818) 2024-10-23 12:43:56 +00:00
overlookmotel
871b9f5abc style(transformer/react-refresh): fix whitespace (#6813)
Style nit. Fix whitespace/indentation. Not sure why `rustfmt` didn't do this automatically.
2024-10-23 11:54:53 +00:00
overlookmotel
759710aa66 refactor(transformer): methods only take &TraverseCtx where possible (#6812)
Methods which only need an immutable ref `&TraverseCtx` take that, instead of unnecessary `&mut TraverseCtx`.
2024-10-23 11:37:27 +00:00
overlookmotel
47bc36832c refactor(traverse): BoundIdentifier methods only take &TraverseCtx (#6811)
These methods don't require a `&mut TraverseCtx`, as they only call methods on `AstBuilder`.
2024-10-23 11:32:01 +00:00
overlookmotel
55c07f2d4c docs(traverse): correct doc comment for BoundIdentifier (#6810)
Docs were out of date. APIs have changed.
2024-10-23 10:47:29 +00:00
Boshen
4757376136 fix(coverage): omit explicit-resource-management from runtime test (#6804) 2024-10-23 07:49:01 +00:00
Boshen
05ef03dbab fix(codegen): correct print __proto__ shorthand (#6802) 2024-10-23 07:16:00 +00:00
Boshen
1b7897cf01 fix(codegen): print #field in {} << 0; correctly (#6799) 2024-10-23 05:34:22 +00:00
Boshen
2f6ad42348 fix(codegen): print negative bigint 1n- -1n correctly after constant folding (#6798)
closes #6767
2024-10-23 04:56:50 +00:00
camc314
b4bc300ebf feat(minifier): improve folding block stmts (#6793) 2024-10-23 04:13:58 +00:00
camc314
7c51b2fd9d chore(minifier): remove duplicate minifier test (#6792)
these tests already exist below (and have been enabled)
34fe7c00a3/crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs (L576-L597)

i suspect this was left in as a copy/pasta error
2024-10-23 04:07:50 +00:00
overlookmotel
718ccded34 refactor(ast)!: remove unused new methods (#6789) 2024-10-23 03:36:32 +00:00
overlookmotel
4d2d214ec7 refactor(ast, transformer)!: remove StringLiteral::new method (#6788) 2024-10-23 03:36:32 +00:00
overlookmotel
a1ca964560 refactor(ast, parser)!: remove NumericLiteral::new method (#6787) 2024-10-23 03:36:31 +00:00
overlookmotel
aeaa27a618 refactor(ast, parser, transformer, traverse)!: remove BindingIdentifier::new methods (#6786) 2024-10-23 03:36:31 +00:00
overlookmotel
ecc9151f99 refactor(ast, parser, transformer, traverse)!: remove IdentifierReference::new methods (#6785) 2024-10-23 03:36:30 +00:00
overlookmotel
c91ffbcb01 refactor(ast, transformer)!: remove IdentifierName::new method (#6784) 2024-10-23 03:36:30 +00:00
overlookmotel
2bee4e2735 refactor(ast, transformer)!: remove BlockStatement::new methods (#6783)
First of a series of PRs removing `new` and `new_with_scope_id` etc methods from AST types. Following #6760, all AST node creation can now go via the AST builder.

This lays groundwork for Node IDs (#5689), as we'll need `NodeId`s to be generated in `AstBuilder`, so that all nodes receive an ID.
2024-10-23 03:36:30 +00:00
Boshen
8f179534c2 fix(coverage): remove some broken cases (#6797) 2024-10-23 03:10:49 +00:00
Boshen
9c7ae78c75 fix(coverage): better handling of test262 failling cases (#6794) 2024-10-23 02:02:18 +00:00
mysteryven
0acca58581 feat(linter): support --print-config all to print config file for project (#6579)
Continue work on #4742.

Only `oxlint --print-config all` is supported. It's useful to migrate from command-line interface to config file.

The `--print-config PATH` looks not really useful for us now, I will add it after config file overrides supported.
2024-10-22 17:56:23 +00:00
Boshen
ffa3945465 chore(coverage): ignore v8 failed cases from runtime.snap (#6780) 2024-10-22 16:21:42 +00:00
Dunqing
b711ee1881 fix(transformer): after using StatementInjector, some statements disappeared (#6778) 2024-10-22 14:10:19 +00:00
overlookmotel
d2b8f505f1 refactor(ast_tools): TypeDef::name return a &str (#6776)
It's generally an anti-pattern for functions to return `&String`. `&str` is preferable.
2024-10-22 12:14:41 +00:00
overlookmotel
09d2df1085 refactor(ast_tools): shorter code in AstKindGenerator (#6775)
Tiny refactor. Shorten code a little and avoid converting `Ident`s unnecessarily.
2024-10-22 12:14:40 +00:00
overlookmotel
46898654a2 refactor(ast_tools): simplify code in AstKindGenerator (#6774)
Combine multiple filters into one.

The first 2 filters were doing the same thing, and combining the remaining 2 makes the code easier to read.
2024-10-22 12:14:40 +00:00
overlookmotel
0b6db0e17c refactor(ast_tools): remove support for #[visit(as)] (#6773)
#6740 and #6744 removed visitor type aliases (`#[visit(as(ClassHeritage))]`). Remove support for `#[visit(as(...))]` from `oxc_ast_tools`, since it's now dead code.
2024-10-22 12:14:39 +00:00
Cam McHenry
e221ea3fb5
chore(tasks/lint_rules): sync rules with ESLint v9 (#6777)
The previous version of the `react-perf` ESLint plugin was holding us
back from updating this to ESLint V9. I've manually specified the ESLint
version here, because we want to make sure we are running the latest
major version of ESLint which changes a lot of things.

Also changed it so that rules which are not supported and also
implemented do not get counted twice in the total count. For example,
`eslint/no-with` is marked as not supported but it is still implemented.
This was previously counted for both, which made it look like we had an
additional rule implemented.
2024-10-22 20:14:10 +08:00
overlookmotel
91651e0a3b docs(ast): fix comment for ClassElement::r#static (#6771)
Follow-up after #6731. Make a long comment to remove ambiguity about what this method does for once and for all!
2024-10-22 10:38:15 +00:00
Boshen
e15b7ce09c fix(coverage): tests for --> in the first line should not have raw flag. (#6772) 2024-10-22 10:24:27 +00:00
dalaoshu
3116fd3dc1
fix(oxc_language_server): correct diagnostic link (#6765) 2024-10-22 06:23:54 -04:00