Commit graph

5279 commits

Author SHA1 Message Date
oxc-bot
00a7372eaf
release(crates): v0.38.0 (#7490) 2024-11-26 14:38:47 +08:00
Boshen
45ef3eb2be chore(transformer): disable class properties transform from the target API (#7487) 2024-11-26 06:10:35 +00:00
Boshen
713e210012 chore(transformor): disable class properties transform (#7486)
The plugin is not ready.
2024-11-26 03:47:46 +00:00
Alexander S.
571d7e2419
fix(language_server): calculate correct column when Unicode chars (#7484)
Before:

![grafik](https://github.com/user-attachments/assets/ddae446d-9167-405b-b44e-c7f76850ffd0)

After:

![grafik](https://github.com/user-attachments/assets/e8d7ac5c-8fe9-4c51-897d-bdb55f7f33dc)

Closes #3625
2024-11-26 10:44:13 +08:00
Guillaume Piedigrossi
87c893fb49
feat(linter): add the eslint/no_duplicate_imports rule (#7309) 2024-11-25 20:56:29 +00:00
overlookmotel
e5d49db360 refactor(transformer/class-properties): placeholder method for transforming private field assignment patterns (#7482)
Add a no-op placeholder method for transforming private fields as `AssignmentPattern`s. e.g. `[object.#prop] = []`.

Implementation will be added later.
2024-11-25 20:10:07 +00:00
overlookmotel
97de0b7be1 fix(transformer/class-properties): transform this in static prop initializers (#7481)
Convert `this` in static property initializers to reference to class name.

`class C { static prop = this; }` -> `class C {}; C.prop = C;`
2024-11-25 20:10:05 +00:00
overlookmotel
d2745df3bc fix(transformer/class-properties): stop searching for super() in TSModuleBlocks (#7480)
Fix edge case in class static properties transform. When transforming `super()` in class constructor, stop searching when hit a `TSModuleBlock`. `TSModuleBlock` is essentially a function, so `super()` there is invalid.
2024-11-25 20:10:03 +00:00
overlookmotel
2a5954ae71 docs(transformer/class-properties): document transform options (#7478)
Add docs for the `loose` option / `set_public_class_fields` assumption.
2024-11-25 17:17:28 +00:00
overlookmotel
abb0e0e08e refactor(transformer/class-properties): rename var (#7477)
Pure refactor. Name var more descriptively.
2024-11-25 16:45:21 +00:00
overlookmotel
25823c8529 refactor(transformer/class-properties): safer use of GetAddress (#7474)
Avoid using `Address::from_ptr`, which is error-prone.
2024-11-25 14:25:27 +00:00
overlookmotel
3396b69379 refactor(transformer/exponentiation-operator): correct comment (#7476)
Follow-on after #7410. Update comment to reflect the changed logic.
2024-11-25 14:16:22 +00:00
overlookmotel
10ea830651 style(traverse): fix indentation in codegen (#7475) 2024-11-25 13:19:19 +00:00
overlookmotel
eb70219821 feat(ast): derive GetAddress on all enum types (#7472)
Implement `GetAddress` on all AST enums where all variants are boxed. Part of #7339.
2024-11-25 12:13:44 +00:00
Dunqing
d7d073578d refactor(semantic): remove SymbolFlags::TypeLiteral (#7415) 2024-11-25 11:34:34 +00:00
jordan boyer
79ab8cca0e
feat(lint-unicorn): add rule prefer set has (#7075)
implementing the rule [prefer set
has](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-set-has.md)
from unicorn.

I put the fix as dangerous fix because they was no test for the fix on
the unicorn part. I did add some test for this but i'm not sure that i'm
covering everything.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-11-25 19:33:51 +08:00
Jelle van der Waa
7236d14dc8
feat(eslint/jsx_a11y): implement anchor_ambiguous_text (#5729)
Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-11-25 11:07:36 +00:00
overlookmotel
111d722fe1 style(transformer/optional-chaining): code style nit (#7468) 2024-11-25 10:51:42 +00:00
Dunqing
e26916ceae perf(transformer/optional-chaining): mark enter_expression as inline (#7390) 2024-11-25 18:31:35 +08:00
overlookmotel
9778298fdb feat(transformer): class properties transform (#7011)
Add class properties transform.

Implementation is incomplete. Notable missing parts:

* Scopes are not updated where property initializers move from class body into class constructor / `_super` function.
* Does not handle binding shadowing problems when property initializers move from class body into class constructor.
* `this` and references to class name in static property initializers need to be transformed to point to a temp var.
* Not all usages of private properties are supported (see below).
* Code which is moved to outside of class body is not transformed by other transforms for class declarations (works OK for class expressions). This includes static property initializers, static blocks, and computed property/method keys.
* Only basic checks for whether computed property/method keys may have side effects.
* Numerous other small issues noted in TODO comments through the code.

### Private properties

Currently does not handle the following usages of private properties:

```js
class Class {
  #prop;
  static #static;

  method() {
    object?.#prop;
    object?.#prop();
    [object.#prop] = [1];
    ({x: object.#prop} = {x: 1});
    object.#prop`xyz`;

    object?.#static;
    object?.#static();
    [object.#static] = [1];
    ({x: object.#static} = {x: 1});
    object.#static`xyz`;
  }
}
```
2024-11-25 10:24:20 +00:00
Boshen
3169bc61d1
ci: clean up wasm type check (#7466)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-25 17:56:17 +08:00
Brian Liu
0b9da38a9e
feat(linter): implement unicorn/prefer-negative-index (#6920)
[unicorn/prefer-negative-index](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v56.0.0/docs/rules/prefer-negative-index.md)

---------

Co-authored-by: Brian Liu <brian@redflagsdating.com>
Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-11-25 09:25:15 +00:00
Radu Baston
f0643c4484
feat(linter): implement jsx-no-script-url (#6995)
https://github.com/oxc-project/oxc/issues/1022

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-25 16:49:27 +08:00
Boshen
5d65656517 refactor(oxc_index)!: move to own repo github.com/oxc-project/oxc-index-vec (#7464)
closes #7454
2024-11-25 08:36:44 +00:00
dalaoshu
db6558f33c
fix(linter): false positive in eslint/prefer-object-has-own (#7463)
closes #7450
2024-11-25 16:32:48 +08:00
Alexander S.
a3ecbde369
fix(language_server): do not tell clients about codeActionProvider when they do not support codeActionLiteralSupport (#7445)
VSCode output:

```
                "codeActionLiteralSupport": {
                    "codeActionKind": {
                        "valueSet": [
                            "",
                            "quickfix",
                            "refactor",
                            "refactor.extract",
                            "refactor.inline",
                            "refactor.rewrite",
                            "source",
                            "source.organizeImports"
                        ]
                    }
                },
```

See also eslint implementation
b33437b5ad/server/src/eslintServer.ts (L221-L225)
2024-11-25 14:30:02 +08:00
Alexander S.
25d9ed9b10
fix(language_server): revalidate files when configPath has changed (#7447)
closes #7446 

![revalidate-files-when-config-changes](https://github.com/user-attachments/assets/a5f4a612-9e0d-4f14-932c-f3b9b956a24a)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-25 14:29:26 +08:00
Dunqing
88ddce4fa6 chore(isolated-declarations): remove outdated panic comment (#7462) 2024-11-25 05:28:09 +00:00
Dunqing
0ff94fa620 refactor(isolated-declarations): use CloneIn instead of ast.copy (#7459) 2024-11-25 04:56:17 +00:00
IWANABETHATGUY
e9f9e8242a feat(oxc_transformer): replace_global_define ThisExpression (#7443)
Test from d34e79e2a9/internal/bundler_tests/bundler_default_test.go (L5195-L5260),

esbuild snapshot:

d34e79e2a9/internal/bundler_tests/snapshots/snapshots_default.txt (L1081-L1108)
2024-11-25 04:13:52 +00:00
IWANABETHATGUY
87978499a3
feat(oxc_transformer): replace_global_define destructuring assignment optimization (#7449)
1. Closed #7382

Co-authored-by: Hiroshi Ogawa <hi.ogawa.zz@gmail.com>
2024-11-24 23:24:32 +08:00
Hiroshi Ogawa
d5df615264
fix(oxc_codegen): don't emit empty span mapping (#7448) 2024-11-24 17:04:52 +08:00
Alexander S.
84fcc43cf5
docs(language_server): add readme (#7429)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-24 12:31:23 +08:00
Naoya Yoshizawa
00060ca0f1
feat(linter): Implement eslint/no-object-constructor (#7345)
A test case for `new Object()` has been commented out:

This is due to the test configuration specifying `globals: { Object:
"off" }`.
This approach follows the example set by the no_new_wrappers rule.
[Reference
Code](bf839c1dfa/crates/oxc_linter/src/rules/eslint/no_new_wrappers.rs (L88))

---------

Co-authored-by: no-yan <63000297+no-yan@users.noreply.github.com>
Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-11-23 19:17:51 +00:00
Boshen
59e7e4674f feat(napi/transform): add TransformOptions::target API (#7426) 2024-11-23 15:46:33 +00:00
oxc-bot
88d17b96e3
release(oxlint): v0.13.1 (#7441)
## [0.13.1] - 2024-11-23

### Features

- 4ad26b9 linter: Add `no-promise-in-callback` (#7307) (no-yan)
- 9558087 oxlint: Auto detect config file in CLI (#7348) (Alexander S.)

### Bug Fixes

- 8507464 linter: Hanging when source has syntax/is flow (#7432)
(Cameron)
- e88cf1b linter: Make `overrides` globs relative to config path (#7407)
(camchenry)
- 9002e97 linter: Add proper support for findIndex and findLastIndex for
`unicorn/prefer-array-some` (#7405) (Dmitry Zakharov)

### Documentation

- 6730e3e linter: Add more examples for `unicorn/prefer-array-some`
(#7411) (Dmitry Zakharov)

### Refactor

- 6c0d31b linter: Remove useless `const` declaration (#7430) (Song Gao)
- c8adc46 linter/no-unused-vars: Improve implementation to remove using
SymbolFlags::Export (#7412) (Dunqing)
- c90537f linter/only-used-in-recursion: Improve implementation to
remove using SymbolFlags::Export (#7413) (Dunqing)

### Testing

- 779f479 editor: Check if workspace configuration is updated (#7403)
(Alexander S.)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-11-23 23:46:16 +08:00
IWANABETHATGUY
4bb1dca673 feat(oxc_transformer): ReplaceGlobalDefines for ChainExpr (#7433) 2024-11-23 15:21:30 +00:00
Cameron
8507464d5a
fix(linter): hanging when source has syntax/is flow (#7432)
Closes #7406

See
https://github.com/oxc-project/oxc/issues/7406#issuecomment-2494981152
for why this is happening

not sure whether there's a better solve for this/
2024-11-23 23:20:19 +08:00
Cameron
c6d790b287
fix(language-server): fix panic by building scope tree child ids (#7440)
closes #7434

i couldn't test this. but what's happening is semaitc is being build
without scope child ids. When exhaustive_deps tries to access it its an
empty vec - hence the panic
2024-11-23 23:19:11 +08:00
dalaoshu
d8c093126d
feat(oxc_transformer): use better diagnostic message for ReplaceGlobalDefinesPlugin (#7439)
When I was handling plugin-related diagnostics in `rolldown`, I
encountered this issue.

If there is a define key like `a.6.b`, the error message states that
<code>\`a.6.b\` is not an identifier</code>. However, it should actually
be that <code>\`6\` is not an identifier</code>.
2024-11-23 23:18:36 +08:00
overlookmotel
63f4d6c24a docs(ast_tools): reformat docs for #[ast] proc macro (#7437) 2024-11-23 14:26:53 +00:00
overlookmotel
bc0e8bc721 docs(ast_tools): update and reformat docs for #[ast] proc macro (#7436)
Docs for `#[ast]` macro were out of date.
2024-11-23 14:09:07 +00:00
overlookmotel
cf0b3bcf1c refactor(ast_tools): remove tsify helper attr from Ast derive macro (#7435)
We no longer use this attr.
2024-11-23 14:09:05 +00:00
IWANABETHATGUY
21614f23b6 feat(oxc_transformer): ReplaceGlobalDefinesPlugin for ComputedMemberExpr (#7431)
support replace `test['foo']` like `ComputedMemberExpr`, since they are static either,
e.g.:
https://hyrious.me/esbuild-repl/?version=0.23.0&b=e%00entry.js%00console.log%28a%5B%27b%27%5D.c%29&b=%00file.js%00&b=%00file2.js%00&o=%7B%0A++treeShaking%3A+true%2C%0A%0AglobalName%3A+%22global%22%2C%0A%22bundle%22%3A+false%2C%0Aformat%3A+%22esm%22%2C%0Adefine%3A+%7B%0A++%22a.b.c%22%3A+%22foo%22%0A%7D%0A%7D
2024-11-23 10:26:43 +00:00
overlookmotel
6fd0fcb4ff refactor(transformer/object-rest-spread): avoid multiple symbol lookups (#7420)
`IdentifierReference::is_global_reference` and `MaybeBoundIdentifier::from_identifier_reference` both look up the symbol for the identifier. Do this lookup only once, rather than twice.
2024-11-23 05:00:30 +00:00
Song Gao
6c0d31b165
refactor(linter): remove useless const declaration (#7430)
Remove uesless const declaration, since they need to access flags, so
they should never be evaluated in compiling time.

Or does this keyword have some other functions I missed?
2024-11-23 11:58:44 +08:00
Dunqing
4d6bd07afe fix(transformer/async-generator-functions): correct all binding scope id (#7425)
Fixed a bunch of semantic errors by removing moving binding logic 😢. This plugin constructs a complex `for-await` replacement so that I wrongly move to an incorrect scope.
2024-11-22 16:29:00 +00:00
Boshen
bb2c0c219b refactor(transformer)!: return String as error instead of OxcDiagnostic (#7424) 2024-11-22 16:22:49 +00:00
camchenry
e88cf1bfd6 fix(linter): make overrides globs relative to config path (#7407)
- fixes https://github.com/oxc-project/oxc/issues/7365

currently, we are matching globs on the absolute path to the file, which means that in order to properly match, all globs would need to start with `**/`. this is not consistent with the behavior in ESLint, which is defined here:  https://eslint.org/docs/v8.x/use/configure/configuration-files#how-do-overrides-work

> **The patterns are applied against the file path relative to the directory of the config file.** For example, if your config file has the path `/Users/john/workspace/any-project/.eslintrc.js` and the file you want to lint has the path `/Users/john/workspace/any-project/lib/util.js`, then the pattern provided in `.eslintrc.js` is executed against the relative path `lib/util.js`.

This PR adds the ability to store the path to the configuration file along with the configuration data, so that we can later use it to resolve the relative paths of the files in the overrides section.

I'm not exactly sure if this will still make sense with nested configuration files, but I think it makes sense to store a path to each configuration file, alongside where the overrides are stored.
2024-11-22 14:37:45 +00:00
overlookmotel
52784d2aea refactor(transformer/optional-chaining): avoid multiple symbol lookups (#7421)
`IdentifierReference::is_global_reference` and `MaybeBoundIdentifier::from_identifier_reference` both look up the symbol for the identifier. Do this lookup only once, rather than twice.
2024-11-22 13:36:34 +00:00