Commit graph

7141 commits

Author SHA1 Message Date
Tyler Earls
62f0a22b89
test(linter): port react-jsx-uses-vars rules to no_unused_vars (#7731)
I added the test cases from
[eslint-plugin-react/jsx-uses-vars](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/tests/lib/rules/jsx-uses-vars.js)
to a `react.rs` file in the `no_unused_vars` tests module.

After adding the new tests, they immediately passed without any source
code changes required. It would seem that the linter already supported
this rule, but now there will be tests to support it.

---------

Co-authored-by: Cameron <cameron.clark@hey.com>
2024-12-08 22:18:23 +00:00
overlookmotel
88a0b9c4af test(transformer/class-properties): override test output for _super in class constructor (#7729)
Our output for this test differs from Babel, because we handle `super()` in class constructors differently, but our output is valid.
2024-12-08 17:57:57 +00:00
overlookmotel
3bae741bb4 test(transformer/class-properties): override test output for _super in class constructor (#7726)
Our output for this test differs from Babel, because we handle `super()` in class constructors differently, but our output is valid.
2024-12-08 15:52:27 +00:00
Boshen
48b1e4ad32 refactor(napi/parser): enable serialize feature for oxc_ast only (#7728) 2024-12-08 15:38:57 +00:00
Boshen
c98457db5c feat(napi/transformer): add runtime helper mode (#7727)
part of #7599
2024-12-08 15:29:55 +00:00
Boshen
85eec3c82e feat(napi/transform,napi/parser): return structured error object (#7724)
closes #7261
2024-12-08 14:11:56 +00:00
dalaoshu
02f9903211
test(linter): add regression tests for import/namespace (#7723)
Related to #7696
2024-12-08 15:35:14 +08:00
overlookmotel
37709cec18 test(transformer): transform conformance print code with double-space indent (#7707)
Transform conformance tester (`just test-transform`) print code with double-space indent, instead of tabs. This matches our formatting convention for JS files.
2024-12-08 02:58:18 +00:00
overlookmotel
59132006c9 refactor(transformer/class-properties)!: rename ClassPropertiesOptions::loose (#7716)
`loose` option also covers the `private_fields_as_properties` assumption, not only `set_public_class_fields`.
2024-12-08 01:41:41 +00:00
overlookmotel
a6fd2def34 test(transformer): add just script to update transformer test fixtures (#7713)
Add `just update-transformer-fixtures` to update transformer conformance tests with overrides (see #7688).
2024-12-08 01:41:40 +00:00
overlookmotel
34a8d91454 test(transformer): fix merging options in fixtures update script (#7712)
Fix how options are merged with options from parent folder(s). It's much simpler than I had thought. If folder's options contains `plugins`, that overwrites `plugins` from parent options. They don't get merged.
2024-12-08 01:41:39 +00:00
overlookmotel
7344d21c81 refactor(transformer/class-properties): TODO comments for future optimizations (#7711) 2024-12-08 01:41:38 +00:00
overlookmotel
dd55b84399 refactor(transformer/class-properties): shorten output when _super function (#7710)
Produce more compact output when insert a `_super` function into class constructor.
2024-12-08 01:41:36 +00:00
overlookmotel
97e4185c19 fix(transformer/class-properties): fix SymbolFlags for _super function (#7709)
Fix `SymbolFlags` for generated `_super` function outside class.
2024-12-08 01:41:35 +00:00
overlookmotel
de5b0b63a9 fix(transformer/class-properties): make _super function outside class strict mode (#7708)
When create a `_super` function outside class, ensure it's always strict mode. The code it contains was previously inside the class, so was strict mode.
2024-12-08 01:41:34 +00:00
overlookmotel
5fd136139f test(transformer/class-properties): override fixtures (#7689)
Override some transform conformance test fixtures for class properties transform, where:

* Our output differs from Babel in cosmetic manner only.
* Our transform intentionally works differently from Babel.
* Babel's fixtures enable arrow functions transform, which malfunctions in our implementation. But we're not trying to test arrow functions transform here, so disable it.
2024-12-08 01:41:33 +00:00
overlookmotel
efaaa97986 test(transformer): update fixtures script support overrides (#7688)
Support overriding test fixtures in `update_fixtures.js` script.

Any files in `tasks/transform_conformance/overrides` are copied into Babel test fixtures. If `options.json` is overridden, then script runs Babel with updated options, to generate a new `output` file for the fixture.
2024-12-08 01:41:32 +00:00
overlookmotel
da63e873d9 test(transformer/class-properties): exec test for this in computed key (#7687)
Add an exec test for #7686.
2024-12-08 01:41:31 +00:00
overlookmotel
65a1c311ab test(transformer): fix exec test reporter (#7722)
`JsonReporter` which the custom test reporter introduced in #7715 uses does not provide error message in `message` prop, where cause of failure is failing assertions. So tests failing due to failing assertions were omitted from snapshot. Include them.

Also add count of passing tests at top of the snapshot.
2024-12-08 01:41:30 +00:00
Boshen
ad27b20dc3 fix(linter): only resolve esm files for import plugin (#7720)
closes #7696

cjs files do not work at all.
2024-12-07 17:30:45 +00:00
dalaoshu
5e6053f35a
fix(linter): false positive in eslint/yoda (#7719) 2024-12-07 15:12:30 +00:00
Boshen
b9a2b35e5a refactor(linter): remove aho-corasick (#7718) 2024-12-07 12:34:41 +00:00
Boshen
5891166c80 feat(transform_conformance): custom reporter for exec test (#7715)
closes #7704
2024-12-07 11:25:00 +00:00
Boshen
9257d9d8ea
chore(CODEOWNERS): assign crates/oxc_transformer/src/plugins to me 2024-12-07 19:22:07 +08:00
Boshen
72eab6cd96 feat(parser)!: stage 3 import source and import defer (#7706)
* https://github.com/tc39/proposal-defer-import-eval
* https://github.com/tc39/proposal-source-phase-imports
* https://tc39.es/proposal-source-phase-imports/#sec-ecmascript-language-expressions
* https://tc39.es/proposal-defer-import-eval/#prod-NameSpaceImport
2024-12-06 16:15:52 +00:00
Dunqing
8c3a954336 fix(codegen): missing parens for in in for in loop init (#7705)
Well, this looks like an accidental change before, `Context::empty().and_forbid_in(false)` does nothing at all.
2024-12-06 15:52:05 +00:00
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