Commit graph

7297 commits

Author SHA1 Message Date
overlookmotel
e76fbb0721 fix(transformer/class-properties): fix symbol clashes in instance prop initializers (#7872)
Instance property initializers are moved into constructor. If symbols they reference are shadowed within constructor, rename those symbols.

Input:

```js
class C {
  prop = foo();
  constructor(foo) {
    console.log(foo);
  }
}
```

Output:

```js
class C {
  constructor(_foo) { // <-- renamed
    this.prop = foo(); // <-- moved into constructor
    console.log(_foo); // <-- renamed
  }
}
```
2024-12-15 01:53:12 +00:00
Alexander S.
f0a8d8aab7
refactor(tasks/lint_rules): detect typescript alias from mod.rs file (#7891)
based on #7890

tried graphite, but I do not have write access to this repo.  
Do not know how to create Branches on a Fork and the PRs on the Forked
Project.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-12-15 00:14:15 +08:00
overlookmotel
0804916b28 test(transformer): make update fixtures script .mjs (#7892)
`.mjs` to match `reporter.mjs` in same directory.
2024-12-14 15:29:21 +00:00
overlookmotel
3858221f45 refactor(global): sort imports (#7883)
Pure refactor. Re-order imports for clarity:

1. `std`
2. External crates
3. `oxc_*` crates
4. Current crate `use crate::...`
5. Super `use super::...`
6. Local modules

This order is from "furthest away" to "closest". This makes it clearer to see what is coming from where.

`cargo +nightly fmt` (#7877) did a lot of the work, but unfortunately `rustfmt` does not have an option to (a) put workspace crates in a separate block from external crates and (b) move `mod` statements to after `use` statements.
2024-12-14 15:07:21 +00:00
overlookmotel
2c942362da refactor(transformer): improve encapsulation of transforms (#7888)
Modules in `oxc_transformer` only export the minimum required, to make the transforms less tightly coupled to each other.
2024-12-14 14:48:28 +00:00
overlookmotel
98d794673b refactor(semantic): import flags and ID types from oxc_syntax (#7887)
`oxc_semantic` had a bit of a mess of modules importing and re-exporting symbols from `oxc_syntax` all over the place. I assume this is a leftover from when our crates were structured differently.

Make this consistent by always importing `oxc_syntax`'s symbols from `oxc_syntax`, and only re-export them from the crate root.
2024-12-14 14:48:28 +00:00
overlookmotel
b9322c68e6 feat(semantic): re-export all flags and ID types (#7886)
`oxc_semantic` already re-exports `ScopeId`, `ScopeFlags`, `SymbolId` and `SymbolFlags` from `oxc_syntax`. It seems inconsistent that it doesn't also re-export `ReferenceId`, `ReferenceFlags`, `NodeId` and `NodeFlags` too. Do that.
2024-12-14 14:48:27 +00:00
dalaoshu
ee26b448cc
feat(linter): enhance get_element_type to resolve more element types (#7885)
I think it should if makes sense.

_Originally posted by @Boshen in
https://github.com/oxc-project/oxc/issues/7881#issuecomment-2543108246_
            

Since `jsx-a11y` supports these names, I have aligned them accordingly.
2024-12-14 22:45:37 +08:00
overlookmotel
7637aac21f style(ast_tools): reformat macro (#7884)
Fix indentation in macro definition.
2024-12-14 13:51:50 +00:00
dalaoshu
32935e6875
fix(linter): false positive in jsx-a11y/label-has-associated-control (#7881)
closes #7849

This is essentially because `get_element_type` does not support
recognizing tag names like `<a.b />`. I'm unsure whether we should
support it.
2024-12-14 21:22:31 +08:00
overlookmotel
fb897f6c3a style(data_structures): add line break (#7882) 2024-12-14 13:16:49 +00:00
Boshen
81eedb10c0 feat(parser): 'readonly' type modifier is only permitted on array and tuple literal types. (#7880) 2024-12-14 12:00:52 +00:00
Boshen
7a087b914e
ci: update .github/workflows/ci_security.yml 2024-12-14 17:45:39 +08:00
overlookmotel
38aafa25a6 perf(transformer/class-properties): reduce size of transform_call_expression_for_super_member_expr (#7859)
Follow-on after #7831. Break up `transform_call_expression_for_super_member_expr` into multiple functions, to make `transform_call_expression_for_super_member_expr` as small as possible, to encourage inlining it.
2024-12-14 08:06:33 +00:00
IWANABETHATGUY
9a309103a4
fix(oxc_transformer): inject_global_variables should considering string imported name (#7768)
Co-authored-by: Boshen <boshenc@gmail.com>
2024-12-14 16:05:56 +08:00
Boshen
9d77ab79f1
Update FUNDING.yml 2024-12-14 15:29:41 +08:00
Boshen
7fb9d47460 style(rust): cargo +nightly fmt (#7877) 2024-12-14 06:03:31 +00:00
oxc-bot
b40c410824
release(oxlint): v0.15.2 (#7876)
## [0.15.2] - 2024-12-14

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-12-14 13:37:03 +08:00
Boshen
36ebb3e784
Revert "chore(renovate): temporary "updateNotScheduled": true"
This reverts commit 1bb097d459.
2024-12-14 13:25:22 +08:00
Boshen
20c29a19f3
ci: downgrade action-gh-release
v2.2.0 is broken https://github.com/softprops/action-gh-release/issues/555
2024-12-14 13:24:31 +08:00
Boshen
e62a69a8dc
Revert "ci: persist-credentials: true in release_oxlint"
This reverts commit 0ad4fe9e15.
2024-12-14 13:21:16 +08:00
Boshen
0ad4fe9e15
ci: persist-credentials: true in release_oxlint 2024-12-14 13:17:36 +08:00
Boshen
816cba6f35
Revert "ci(release_oxlint): split out github release job"
This reverts commit 1eab12a03a.
2024-12-14 13:17:35 +08:00
overlookmotel
588df9f366 test(transformer): transformer conformance runner --override output with spaces not tabs (#7865)
When running `just test-transform --override`, generate override files with indentation as double spaces, instead of tabs. This matches our convention for formatting JS files.
2024-12-14 04:57:00 +00:00
overlookmotel
53e2bc0896 feat(traverse): add TraverseScoping::rename_symbol method (#7871)
Add `TraverseScoping::rename_symbol` method. This renames the symbol, and also the binding for that symbol.
2024-12-14 04:28:54 +00:00
overlookmotel
492407386b fix(semantic): ScopeTree::rename_binding preserve order of bindings (#7870)
`ScopeTree::rename_binding` was previously altering the order of bindings in the `FxIndexMap`. Order of bindings matters in the mangler. Reimplement `rename_binding` to preserve original order.
2024-12-14 04:28:53 +00:00
overlookmotel
1cf8f8f2ca refactor(semantic): SymbolTable::set_name return old name (#7869)
`SymbolTable::set_name` return old symbol name. `set_name` is marked `#[inline]`, so where the caller does not use the old name, getting it should be optimized out by the compiler. So it makes the method more flexible, at no cost.
2024-12-14 04:28:52 +00:00
overlookmotel
c0714945b2 refactor(semantic)!: remove SymbolTable::rename method (#7868)
Remove `SymbolTable::rename` method. We also have `SymbolTable::set_name` method which does the same thing.
2024-12-14 04:28:51 +00:00
overlookmotel
624398083a refactor(transformer/class-properties): instance prop inits visitor use Visit (#7867)
Use `Visit` instead of `VisitMut` as `InstanceInitializerVisitor` does not need to mutate the AST.
2024-12-14 04:28:49 +00:00
Boshen
0f540ecc9f
chore(just): remove update_fixtures from just submodules (#7875)
It is replaced by `update-transformer-fixtures`
2024-12-14 12:28:15 +08:00
overlookmotel
c0576faf80 fix(transformer/class-properties): use UID for args in created class constructor (#7866)
When creating class constructor for a class which has super class, use UID `_args` for temp var (rather than `args`). This avoids shadowing a var called `args` used in an instance property initializer.

This diverges from Babel. Babel uses `args` unless it finds a var called `args` in an instance property initializer. But searching the AST of initializers can be fairly expensive, so it's better to skip it. The overrides for test fixtures included in this PR are just to account for that difference.
2024-12-14 04:18:48 +00:00
Boshen
0b67b37584
ci: fix ci_security.yml 2024-12-14 12:17:26 +08:00
Jan Olaf Martin
3659e6d768
fix(cfg): include export default code in CFG instructions (#7862)
Previously any instructions happening inside of the expression passed to
`export default` were invisible in the CFG.

Example:

```
// Uncommenting this line makes the call to bar() disappear from the
// CFG view of the program:
// export default
bar();
```
2024-12-14 12:09:28 +08:00
overlookmotel
eb47d433ff refactor(transformer/class-properties): re-use existing Vec (#7854)
Follow-on after #7831.

Previously this code was:

1. Create a new empty `Vec` (in `move_vec` call).
2. Consume the old `Vec` and create a new `Vec<ArrayExpressionElement>`.
3. Push to the empty `Vec` created in step 1.

Instead:

1. Drain the old `Vec` and create a new `Vec<ArrayExpressionElement>`.
2. The old `Vec` is now empty, but still holds an allocation if it wasn't empty before.
3. Push to the old `Vec` (re-using the existing allocation).

i.e. We create 1 less `Vec`, and re-use an existing allocation if possible.
2024-12-14 03:27:56 +00:00
overlookmotel
1380b7b7e9 refactor(transformer/class-properties): reduce visibility of method (#7858)
Follow-on after #7831. `transform_super_call_expression_arguments` is only used within this file, so does not need to be `pub(super)`.
2024-12-14 03:21:58 +00:00
overlookmotel
e766051c2d test(transformer): skip test which uses filesystem under miri (#7874)
Miri does not support filesystem operations. Skip this test which loads snapshot from disk when running under Miri.
2024-12-14 03:16:27 +00:00
overlookmotel
f39e65e722 test(transformer): prevent lint error when running miri (#7873) 2024-12-14 03:10:07 +00:00
overlookmotel
3542b4f55f style(wasm): re-order imports (#7864) 2024-12-14 02:30:26 +00:00
overlookmotel
8cf9766be3 refactor(semantic, syntax, wasm): remove #![allow(non_snake_case)] (#7863)
`#![allow(non_snake_case)]` was required in files using `#[derive(Tsify)]`, as a bug in Rust Analyser caused erroneous warnings. This appears to be fixed now, so we can remove these `#![allow]` attributes.
2024-12-14 01:52:32 +00:00
Dunqing
0f5e0787b8 refactor(transformer/class-properties): rename *_owner to owned_* (#7855)
If I understand https://github.com/oxc-project/oxc/pull/7831?notification_referrer_id=NT_kwDOAcKkeLQxMzgzNzE1MTAwNjoyOTUzMzMwNA#pullrequestreview-2502317967 correctly, `owned_*` are better here
2024-12-13 15:28:55 +00:00
Boshen
4b2433539b perf(codegen): improve printing of statement comments (#7857)
closes #7814
2024-12-13 15:20:28 +00:00
Boshen
71a40a222f perf(codegen): guard comment printing comments when there are no comments (#7856) 2024-12-13 15:12:09 +00:00
overlookmotel
34091b2e7a refactor(transformer): use Expression::is_super (#7852)
Shorten code by using `Expression::is_super`, which was introduced in #7831.
2024-12-13 15:05:12 +00:00
overlookmotel
d660d8d12d fix(transformer/optional-chaining): do not create unused reference when noDocumentAll assumption (#7847)
Similar to #7832. Only create an `IdentifierReference` if it's going to be used in AST.
2024-12-13 14:59:13 +00:00
overlookmotel
beb982a69e refactor(ast): use exhaustive match for Argument to ArrayExpressionElement conversion (#7848)
Follow-on after #7830. Refactor.

Use an exhaustive match in implementation of `From<Argument<'a>> for ArrayExpressionElement<'a>`.

At present this change makes no difference. But the reason I feel an exhaustive match is preferable here is that if we add a variant to `Argument` enum later, then this match will be missing an arm to handle that variant, and compiler will refuse to compile until we deal with it.

Whereas before this PR, compiler would not complain, but instead it'd be a runtime panic when `into_expression` discovers that the new `Argument` variant is not an `Expression`.
2024-12-13 14:52:12 +00:00
overlookmotel
e55ab24cc9 refactor(linter): use Expression::is_super (#7850)
Simplify code by using `Expression::is_super` which was introduced in #7831.

Also remove a lifetime bound which is unnecessary and replace use of `bool::then` (which I always find hard to read) with more explicit code.
2024-12-13 14:47:31 +00:00
Boshen
1eab12a03a
ci(release_oxlint): split out github release job 2024-12-13 22:46:15 +08:00
overlookmotel
5d42df8dd6 refactor(semantic): use Expression::is_super (#7851)
Shorten code by using `Expression::is_super`, which was introduced in #7831.
2024-12-13 14:35:13 +00:00
overlookmotel
e49de81544 docs(ast): document Expression::is_* methods (#7853) 2024-12-13 14:12:45 +00:00
Boshen
f8175c545b
ci: wait 3 minutes before smoke test and eslint-plugin-oxlint
closes #7789
2024-12-13 21:54:32 +08:00