Commit graph

7115 commits

Author SHA1 Message Date
Dunqing
4afbe5599e fix(codegen): missing parens for in in for loop init when it includes two binary expression (#7703)
close: #7690

I don't know the logic much, it works without `left_ctx` and no tests failed
2024-12-06 15:52:04 +00:00
IWANABETHATGUY
f7d41dd6fb fix(oxc_transform): overlap replacement (#7621)
closed  https://github.com/oxc-project/oxc/issues/7594

### Reference
https://github.com/oxc-project/oxc/pull/7343/files
2024-12-06 15:26:54 +00:00
overlookmotel
ac910eea5e refactor(transformer/class-properties): move code out of transform_assignment_target (#7701)
Follow-on after #7697.

`transform_assignment_target` is inlined into `enter_assignment_target` visitor, so we want it to be as small as possible. Move assigning to `target` into `transform_assignment_target_impl`, which is the cold path.

The principle is that in the transformer the most important thing for performance is to optimize for the path which is "nothing to do here, exit".

Here we are only transforming `object.#prop`, but very few `AssignmentTarget`s are `object.#prop`, so 99% of the time there is nothing to do. So we want to keep that "do nothing and exit" path as fast and small as possible.

In practice, the `*target =` assignment is only a single assembly operation, so this PR is a micro-optimization. But why not? Every little helps.
2024-12-06 15:15:28 +00:00
overlookmotel
e67e981743 refactor(transformer/class-properties): shorten code (#7700)
Follow-on after #7697. No need to cast twice. You can go from `MemberExpression` direct to `AssignmentTarget`.
2024-12-06 15:15:27 +00:00
overlookmotel
ab3e1c3df4 refactor(transformer/class-properties): add TODO comments (#7702)
Add "TODO" comments for future optimizations we could make.
2024-12-06 15:05:00 +00:00
Dunqing
86d4c90e4d feat(transformer/class-properties): support for transforming AssignmentTarget (#7697)
Instance prop:
 * `[object.#prop] = arr` -> `[_toSetter(_classPrivateFieldSet, [_prop, object])._] = arr`
 * `({x: object.#prop} = obj)` -> `({ x: _toSetter(_classPrivateFieldSet, [_prop, object])._ } = obj)`

 Static prop:
 * `[object.#prop] = arr` -> `[_assertClassBrand(Class, object, _prop)._] = arr`
 * `({x: object.#prop} = obj)` -> `({ x: _assertClassBrand(Class, object, _prop)._ } = obj)`
2024-12-06 12:18:54 +00:00
Boshen
66a680a119
deps(coverage): bump test262 (#7695) 2024-12-06 14:34:01 +08:00
Boshen
c3a538c47c
deps: node v22.12.0 (#7693) 2024-12-06 13:59:37 +08:00
oxc-bot
5f4f6d140b
release(oxlint): v0.14.1 (#7692) 2024-12-06 13:06:54 +08:00
Boshen
fd0935cfcd feat(linter): change react/rules-of-hooks category to pedantic (#7691)
Although this rule is recommended by the React team,
it does not report incorrect or wrong code for the `correctness` category.

When turned on by default, I find false positive warnings confusing,
I cannot tell whether my code is wrong or the rule implementation is
wrong - see examples in the affine repo.

```
  x eslint-plugin-react-hooks(rules-of-hooks): React Hook "use" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function.
    ,-[packages/backend/server/src/config/affine.self.ts:80:1]
 79 |     /* Captcha Plugin Default Config */
 80 | ,-> AFFiNE.use('captcha', {
 81 | |     turnstile: {},
 82 | |     challenge: {
 83 | |       bits: 20,
 84 | |     },
 85 | `-> });
 86 |
    `----
```
2024-12-06 03:49:32 +00:00
camc314
7cee065249 fix(linter): panic in yoda (#7679)
fixes #7674
2024-12-06 03:33:38 +00:00
overlookmotel
72b5d58560 fix(transformer/class-properties): create temp var for this in computed key (#7686)
`this` in computed key needs a temp var, otherwise once moved into constructor it refers to the wrong `this`.
2024-12-06 02:20:57 +00:00
overlookmotel
28ce187189 refactor(transformer/class-properties): duplicate_object_twice method (#7685)
Follow-up after #7664.

Generalize `duplicate_object` to produce however many duplicates are required. Use it in `transform_expression_to_wrap_nullish_check`.

This should be slightly more efficient, and will make it fool-proof if we expand `duplicate_object` later to handle other `Expression` types.
2024-12-05 23:20:44 +00:00
Dunqing
888396845c refactor(transformer/class-properties): use duplicate_object in transform_expression_to_wrap_nullish_check (#7664)
The `duplicate_object` is great, it has handled unbound identifiers and `this` expressions, so we can remove a lot of code. But it is still a little bit annoying because we need two `object` here,  although we can use `clone_in` it needs a special logic for `Expression::Identifier`.
2024-12-05 17:46:22 +00:00
camc314
f029090d65 docs(linter): update rule documentation (#7684) 2024-12-05 16:17:46 +00:00
camc314
be9863a415 test(linter): add more tests fo rules-of-hooks (#7683)
closes #6651
2024-12-05 15:18:14 +00:00
overlookmotel
1925ddc59b refactor(transformer): rename VarDeclarationsStore methods (#7682)
Follow-on after #7668. Rename `create_var*` methods to `create_uid_var*`.

Previous method name `create_var` might suggest that it creates a binding with the provided name. But actually it creates a UID with name *based on* the name provided.
2024-12-05 15:09:24 +00:00
Dunqing
583b36b6bf docs(transformer/class-properties): remove oudated todo (#7669) 2024-12-05 14:46:56 +00:00
Dunqing
3d593ec2eb refactor(var-declarations): remove unnecessary init parameter from insert_var (#7668)
If we want to pass `init`, we should use `insert_var_with_init`
2024-12-05 14:38:40 +00:00
Dunqing
e8518e942c feat(transformer/var-declarations): add insert_var_with_init method (#7667)
part of #7668
2024-12-05 14:38:39 +00:00
Dunqing
0ca10e270a refactor(transformer): use ctx.var_declarations.create_var* methods (#7666)
It turns out these APIs are very useful, we remove many boilerplate code.
2024-12-05 14:31:20 +00:00
camc314
4e489bdf0a docs(linter): update rule documentation (#7681)
part of #6050
2024-12-05 14:09:30 +00:00
Dunqing
8705a291e2 feat(transformer/var-declaration): add a series of create_var* methods (#7665)
part of #7666.

These methods aim to combine generate binding and insert var into one method.
2024-12-05 13:52:58 +00:00
Dunqing
ff73c7ffde feat(traverse): add TraverseCtx::generate_uid_in_current_hoist_scope_based_on_node (#7642)
We have a lot of usage for this API in `class-properties`
2024-12-05 13:41:43 +00:00
overlookmotel
3de4a43761 test(minifier): reformat minsize table (#7678)
Reformat the table which `minsize` task outputs. I always found the column headings confusing previously.
2024-12-05 12:16:29 +00:00
Cameron
56fe5f8bb9
docs(linter): update rule documentation (#7680)
part of #6050
2024-12-05 20:14:42 +08:00
Boshen
00fea9285b feat(napi/parser): expose span positions of import.meta (#7677) 2024-12-05 11:03:52 +00:00
Boshen
e64fd9556d feat(linter): map .js to .ts when resolving with tsconfig.json (#7675)
fixes #6913
closes #6906
2024-12-05 09:07:23 +00:00
Boshen
b8dc333ed4 feat(syntax): add ExportEntry::is_type (#7676) 2024-12-05 09:02:18 +00:00
Kevin Deng 三咲智子
245d7d922c
fix(oxc_transformer): alias es2015 to es6 (#7673)
Supported in
[esbuild](https://esbuild.github.io/try/#dAAwLjI0LjAALS10YXJnZXQ9ZXM2ADEqKjI)
2024-12-05 16:26:05 +08:00
Boshen
d0b78f7361 feat(codegen): minify whitespace for some expressions (#7671)
part of #7638
2024-12-05 06:59:17 +00:00
Boshen
6ae178e0b9 fix(linter): ignore type references in no-undef (#7670)
fixes #7007
fixes #7008
2024-12-05 05:36:54 +00:00
overlookmotel
a0973dcb5a refactor(linter): use BigIntLiteral::raw field (#7660)
No need to slice source text to get raw value of `BigIntLiteral`. It already has a `raw` field.
2024-12-05 04:23:14 +00:00
camc314
3711a8e342 refactor(linter): rename is_same_reference to is_same_expression (#7654) 2024-12-05 04:15:15 +00:00
overlookmotel
2179b93729 fix(estree): make type of BigIntLiteral::raw prop in ESTree AST optional (#7663)
`BigIntLiteral`'s `raw` field is not an `Option` on Rust side, but this is an internal implementation detail - we may parse bigints to a `BigInt` in future (as we did in the past before we hit a memory leak problem), and make `raw` an `Option`.

So at present, the `raw` field is always non-null in JS-side AST. But update the TS type def to reflect that it should be an optional property. This aligns with ESTree.
2024-12-05 04:00:57 +00:00
overlookmotel
cbba26c237 fix(estree): raw: null in ESTree AST for generated NullLiterals (#7662)
In JS-side AST, leave `raw` field as `null` for `NullLiteral`s, if they are generated and have no raw representation in source text.
2024-12-05 04:00:56 +00:00
overlookmotel
1d59fc8353 fix(estree): raw: null in ESTree AST for generated BooleanLiterals (#7661)
In JS-side AST, leave `raw` field as `null` for `BooleanLiteral`s, if they are generated and have no raw representation in source text.
2024-12-05 04:00:55 +00:00
overlookmotel
8993e893a0 refactor(ast): shorten code (#7659)
Pure refactor. Shorten code - `Vec` instead of `std::vec::Vec`.
2024-12-05 01:16:16 +00:00
overlookmotel
746c8aaa4f refactor(ast): rename vars (#7658)
Pure refactor. Rename vars in serialization code. `value.value` is a bit confusing.
2024-12-05 01:16:15 +00:00
overlookmotel
ad76d1d72d fix(transformer/class-properties): transform delete chain expression in static prop initializers (#7656)
Follow-on after #7575. Annoyingly, we have to transform private fields in static prop initializers separately, to make sure the stack of private properties is in sync while visiting them.
2024-12-05 01:07:18 +00:00
overlookmotel
44fe854231 refactor(transformer/class-properties): move logic for handling delete of chain expression into transform_unary_expression (#7655)
Follow-on after #7575. Pure refactor. Move all logic for transforming `delete <chain expression>` into the handler `transform_unary_expression`. Aim is to keep logic in one place and keep the main visitor as simple as possible.
2024-12-05 01:07:17 +00:00
overlookmotel
6c82589daf perf(transformer/class-properties): replace recursion with loop (#7652)
Follow-on after #7575. Small optimization. Replace recursive function calls with a loop.
2024-12-05 01:01:11 +00:00
overlookmotel
0c9cc48806 style(ast): import Atom (#7657)
Code style refactor. Import `Atom` at top of file to shorten code.
2024-12-05 00:53:38 +00:00
Song Gao
ebc80f6749
refactor(ast)!: change 'raw' from &str to Option<Atom> (#7547)
Fix #7254 

Changed all "raw" properties of literal types (if they have this property) to `Option<Atom>`.

---------

Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2024-12-05 00:34:45 +00:00
overlookmotel
e5145b0083 style(transformer/class-properties): reformat doc comments (#7653)
Follow-on after #7575. By convention we use backticks for code snippets in doc comments.
2024-12-04 20:43:02 +00:00
Boshen
c523ccb7ef feat(codegen): better whitespace minification for import / export statements (#7650)
part of #7638
2024-12-04 19:24:03 +00:00
Dunqing
c793d71a78 feat(transformer/class-properties): transform ChainExpression (#7575)
Fully support transforming ChainExpression in class properties. Our implementation has some differences in execution order compared to Babel, but we have passed all execution-related tests.
2024-12-04 16:52:57 +00:00
tbashiyy
bd9d38a9a0
feat(linter): Implement eslint:yoda (#7559)
In this PR, implement
[eslint:yoda](https://eslint.org/docs/latest/rules/yoda)

ref: https://github.com/oxc-project/oxc/issues/479
2024-12-04 15:58:21 +00:00
Boshen
690fc54cdb
ci(deny.yml): check for deny.toml 2024-12-04 23:41:31 +08:00
Boshen
8c0b0ee2bd fix(parser): better diagnostic for invalid for await syntax (#7649) 2024-12-04 15:18:29 +00:00