Commit graph

5445 commits

Author SHA1 Message Date
overlookmotel
f3850eb53b fix(semantic): correctly resolve binding for return type of functions (#6388)
Fixes #6387.
2024-11-26 15:43:35 +00:00
Boshen
b0e1c03284
feat(ast)!: add StringLiteral::raw field (#7393)
part of #7254
2024-11-26 23:33:56 +08:00
7086cmd
97af341cac feat(minifier): minify alternated one child if block (#7231) 2024-11-26 15:00:16 +00:00
camc314
2ac9f963df feat(linter): typescript/no-inferrable-types (#7438) 2024-11-26 14:49:31 +00:00
Ethan Goh
ac0d25c426
feat(minifier): minify one child if statement expression (#7230) 2024-11-26 22:48:27 +08:00
Boshen
c133693e5c perf(minifier): fuse ast passes (#7493) 2024-11-26 14:30:04 +00:00
Dunqing
58a125ff88 fix(transformer/async-to-generator): correct the SymbolFlags of function id in module (#7470) 2024-11-26 11:59:22 +00:00
Dunqing
37842c166d fix(transformer/object-rest-spread): generate catch variable binding with correct SymbolFlags (#7469) 2024-11-26 11:59:21 +00:00
overlookmotel
199076bd14 fix(transformer/class-properties): transform private property accesses in static prop initializers (#7483)
Transform private property accesses in static prop initializers. e.g.:

Input:

```js
class C {
  static #x = 123;
  static y = this.#x;
}
```

Transformed:

```js
class C {}
var _x = { _: 123 };
babelHelpers.defineProperty(C, "y", babelHelpers.assertClassBrand(C, C, _x)._);
```

`this.#x` has been transformed to `babelHelpers.assertClassBrand(C, C, _x)._`.
2024-11-26 11:36:09 +00:00
overlookmotel
5ca6eea77e perf(transformer/class-properties): inline visitor methods (#7485)
Inline visitor methods in class properties transform.
2024-11-26 11:36:09 +00:00
7086cmd
24189f28ad feat(ecma): implement array join method (#6936) 2024-11-26 11:28:07 +00:00
Dunqing
9c9deaeffe feat(traverse): add generate_uid_in_current_hoist_scope method (#7423)
Add an API to handle variable hoisting.
2024-11-26 11:21:36 +00:00
leaysgur
3a1ef6a230 refactor(prettier): Refactor IR related macros (#7491)
- Remove `format!` macro
- Rename string related macros, `&'static`: `text!` and `'a`: `dynamic_text!`
- Apply `wrap!` macro instead of manually using `enter|leave_node`
- Introduce `/ir` directory and move `Doc`, `impl Display`, `DocBuilder`, etc.

I'm not yet determined how to, how deep to use macro, but this is first stepping stone... 🥌
2024-11-26 09:31:30 +00:00
tbashiyy
8d89fdc886
feat(linter): add eslint/prefer-spread (#7112)
In this PR, 
- move existing `unicorn:prefer-spread` to `eslint:prefer-spread`.
- combine 2 rules from `eslint:prefer-spread` and
`unicorn:prefer-spread`

([This is already talked in
discord](https://discord.com/channels/1079625926024900739/1080712072012238858/1299981398064496652))

---------

Co-authored-by: Cameron Clark <cameron.clark@hey.com>
2024-11-26 17:30:38 +08:00
Boshen
17c0dd8fb2
fix(linter): fix jsx_no_script_url doc failed to build
"Element is missing end tag."
2024-11-26 16:03:14 +08:00
oxc-bot
861ae1581a
release(oxlint): v0.13.2 (#7489) 2024-11-26 15:25:31 +08:00
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
overlookmotel
971c91a2e8 feat(traverse): add methods to BoundIdentifier + MaybeBoundIdentifier to create SimpleAssignmentTargets (#7418)
We had methods to create `AssignmentTarget`s. Add methods to create `SimpleAssignmentTarget`s too.
2024-11-22 12:31:29 +00:00
overlookmotel
eb39a50a2e refactor(transformer/logic-assignment): shorten code (#7419)
Use `create_spanned_read_expression` instead of `create_spanned_expression`, as it's shorter than specifying `ReferenceFlags` manually.
2024-11-22 11:42:03 +00:00
overlookmotel
be5f843a12 docs(traverse): fix docs for BoundIdentifier + MaybeBoundIdentifier (#7417) 2024-11-22 10:58:34 +00:00
Dunqing
27b2268a6c refactor(semantic)!: remove SymbolFlags::Export (#7414)
close: #7338
close: #7344

The `SymbolFlags::Export` is Initially used to solve `ExportSpecifier` that is not `IdentifierReference` that causes we cannot determine whether a Binding is not used everywhere by `Semantic`.

Since #3820 this problem is solved, so we don't need `SymbolFlags::Export` no longer. Also, removing this can help us easier to pass the `Semantic` check in `Transformer`
2024-11-22 09:17:37 +00:00
Dunqing
c90537f1f0 refactor(linter/only-used-in-recursion): improve implementation to remove using SymbolFlags::Export (#7413)
part of #7414
2024-11-22 09:17:36 +00:00
Dunqing
c8adc46a08 refactor(linter/no-unused-vars): improve implementation to remove using SymbolFlags::Export (#7412)
part of #7414
2024-11-22 09:17:35 +00:00
Dunqing
7ff9f13973 fix(transformer): correct all ReferenceFlags (#7410) 2024-11-22 09:10:55 +00:00
Dunqing
6f0fe38bff fix(semantic)!: correct all ReferenceFlags::Write according to the spec (#7388)
close #7323

According to the specification re-design the JavaScript-part ReferenceFlags inferring approach.

* https://tc39.es/ecma262/#sec-assignment-operators-runtime-semantics-evaluation
* https://tc39.es/ecma262/#sec-postfix-increment-operator-runtime-semantics-evaluation
* https://tc39.es/ecma262/#sec-runtime-semantics-restdestructuringassignmentevaluation
* ... See references of https://tc39.es/ecma262/#sec-putvalue

### Changes

1. The left-hand of `AssignmentExpression` is always `ReferenceFlags::Write`
```js
let a = 0;
console.log(a = 0);
            ^ Write only
```

2. The `argument` of `UpdateExpression` is always `ReferenceFlags::Read | Write`
```js
let a = 0;
a++;
^ Read and Write
```

This change might cause some trouble for `Minfier` to remove this code, because ‘a’ is not used elsewhere. I have taken a look at `esbuild` and `Terser`. Only the `Terser` can remove this code.
2024-11-22 06:08:30 +00:00
Dmitry Zakharov
6730e3effe
docs(linter): add more examples for unicorn/prefer-array-some (#7411) 2024-11-22 14:06:46 +08:00
no-yan
4ad26b952f
feat(linter): add no-promise-in-callback (#7307)
related: #4655

This PR implements a rule to detect Promises inside error-first
callbacks, preventing the mixed usage of callbacks and Promises.

Example of problematic code:
```javascript
a(function(err) { doThing().then(a) });
                  ^^^^^^^^^^^^^^
```


[Original
implementation](266ddbb030/rules/no-promise-in-callback.js)
2024-11-22 10:21:26 +08:00
Dmitry Zakharov
9002e97e12
fix(linter): add proper support for findIndex and findLastIndex for unicorn/prefer-array-some (#7405)
closes #7404
2024-11-22 10:12:13 +08:00
oxc-bot
0918e520cf
release(crates): v0.37.0 (#7399) 2024-11-21 22:27:55 +08:00
oxc-bot
4b5a176630
release(oxlint): v0.13.0 (#7398)
## [0.13.0] - 2024-11-21

- 7bf970a linter: [**BREAKING**] Remove tree_shaking plugin (#7372)
(Boshen)
- 7f8747d linter: Implement `react/no-array-index-key` (#6960)
(BitterGourd)

### Features

- be152c0 linter: Add `typescript/no-require-imports` rule (#7315)
(Dmitry Zakharov)
- 849489e linter: Add suggestion for no-console (#4312) (DonIsaac)
- 8cebdc8 linter: Allow appending plugins in override (#7379)
(camchenry)
- 8cfea3c oxc_cfg: Add implicit return instruction (#5568)
(IWANABETHATGUY)
- e6922df parser: Fix incorrect AST for `x?.f<T>()` (#7387) (Boshen)

### Bug Fixes

- e91c287 linter: Fix panic in react/no-array-index-key (#7395) (Boshen)
- a32f5a7 linter/no-array-index-key: Compile error due to it uses a
renamed API (#7391) (Dunqing)
- 666b6c1 parser: Add missing `ChainExpression` in optional
`TSInstantiationExpression` (#7371) (Boshen)

### Documentation

- df143ca linter: Add docs for config settings (#4827) (DonIsaac)
- ad44cfa linter: Import/first options (#7381) (Zak)

### Refactor

- c34d649 linter: Use `scope_id` etc methods (#7394) (overlookmotel)
- 466f395 vscode: Split `ConfigService` and `Config` (#7376) (Alexander
S.)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-11-21 22:21:32 +08:00
Boshen
e91c2878d8 fix(linter): fix panic in react/no-array-index-key (#7395) 2024-11-21 13:35:21 +00:00
overlookmotel
c34d649176 refactor(linter): use scope_id etc methods (#7394)
Utilize the methods added in #7127 in `oxc_linter`.
2024-11-21 12:29:57 +00:00
Boshen
224775c056 feat(transformer): transform object rest spread (#7003)
https://babel.dev/docs/babel-plugin-transform-object-rest-spread
2024-11-21 11:33:26 +00:00
overlookmotel
b3d5802ef1 docs(syntax): more comments for ReferenceFlags (#7392)
Add more docs to `ReferenceFlags`, mainly to include the runtime test in https://github.com/oxc-project/oxc/issues/5165#issuecomment-2488333549.
2024-11-21 11:20:28 +00:00
Dunqing
a32f5a73d3 fix(linter/no-array-index-key): compile error due to it uses a renamed API (#7391)
Fix: https://github.com/oxc-project/oxc/pull/6960#issuecomment-2490754348
2024-11-21 10:46:21 +00:00
BitterGourd
7f8747dd6a
feat(linter): implement react/no-array-index-key (#6960)
Implement not recommended rule `no-array-index-key` (#1022 )
2024-11-21 10:29:40 +00:00
IWANABETHATGUY
8cfea3c5b6
feat(oxc_cfg): add implicit return instruction (#5568)
1. Adding a new InstructionKind `ImplicitReturn`
2. Adding a new `ImplicitReturn` instruction for each function body,
just like biome

![image](https://github.com/user-attachments/assets/1511a64a-96d8-47b6-a394-11cd40e98b85)
2024-11-21 16:18:51 +08:00
Dmitry Zakharov
be152c01c5
feat(linter): add typescript/no-require-imports rule (#7315) 2024-11-21 16:15:49 +08:00
DonIsaac
df143ca7bb docs(linter): add docs for config settings (#4827) 2024-11-21 08:08:30 +00:00
DonIsaac
849489e8b4 feat(linter): add suggestion for no-console (#4312)
Part of #4179
2024-11-21 07:46:29 +00:00
Hiroshi Ogawa
3d66929fa2
fix(sourcemap): improve source map visualizer (#7386)
- Related https://github.com/rolldown/rolldown/issues/2737

Probably this is still an approximation of what
https://github.com/evanw/source-map-visualization does, but I tried to
get some ideas from it.

For comparison, I added an example from their site
https://evanw.github.io/source-map-visualization/ as a snapshot in
`crates/oxc_sourcemap/tests/fixtures/esbuild/visualizer.snap`. I'll
mention a few notable changes in the comments.

Snapshot change in rolldown repo can be found in
- https://github.com/rolldown/rolldown/pull/2829
2024-11-21 14:35:56 +08:00
Boshen
e6922df3bb feat(parser): fix incorrect AST for x?.f<T>() (#7387) 2024-11-21 06:10:48 +00:00
Boshen
885e37f8eb feat(transformer): Optional Chaining (#6990)
close: #6958
2024-11-21 03:12:18 +00:00
camchenry
8cebdc8129 feat(linter): allow appending plugins in override (#7379)
follow up to https://github.com/oxc-project/oxc/issues/6896

for improved compatibility with ESLint, this tries to match the behavior of plugin overrides so that plugins can be enabled for certain paths. this does not allow disabling plugins.
2024-11-21 01:46:28 +00:00
Zak
ad44cfa840
docs(linter): import/first options (#7381)
Fix the docs for
[import-first](https://oxc.rs/docs/guide/usage/linter/rules/import/first.html#import-first)
which mentions the option `"absolute-import"` rather than
`"absolute-first"`
2024-11-21 09:46:12 +08:00
Boshen
f059b0e655 fix(ast)!: add missing ChainExpression from TSNonNullExpression (#7377)
closes #7375

* `foo?.bar!`
* `foo?.[bar]!`

`TSNonNullExpression` was not wrapped inside `ChainExpression`.
2024-11-20 15:54:28 +00:00
Boshen
878189c407 feat(parser,linter)!: add ParserReturn::is_flow_language; linter ignore flow error (#7373)
closes #7123
2024-11-20 12:50:24 +00:00
Boshen
666b6c104c fix(parser): add missing ChainExpression in optional TSInstantiationExpression (#7371) 2024-11-20 11:51:55 +00:00
Boshen
7bf970a4b6 refactor(linter)!: remove tree_shaking plugin (#7372)
This rule has been in `nursery` for a long time and I don't see it
coming out of `nursery` in the foreseeable future.

closes #7031
clsoes #7057
2024-11-20 11:46:29 +00:00
Boshen
6a98ef1a0c feat(transformer): add CompilerAssumptions to TransformContext (#7369) 2024-11-20 09:27:29 +00:00
Boshen
9b9d02078c docs(semantic): document the meaning of ReferenceFlags::Read and Write (#7368)
closes #5165
2024-11-20 09:18:25 +00:00
Boshen
82773cb455 feat(codegen): remove underscore from bigint (#7367)
closes #7285
closes #7286
2024-11-20 09:08:51 +00:00
oxc-bot
b6d5c0f33e
release(oxlint): v0.12.0 (#7366)
## [0.12.0] - 2024-11-20

- 20d9080 linter: [**BREAKING**] Override plugins array when passed in
config file (#7303) (camchenry)

### Features

- 1d9f528 linter: Implement `unicorn/prefer-string-raw` lint rule
(#7335) (Ryan Walker)
- d445e0f linter: Implement `unicorn/consistent-existence-index-check`
(#7262) (Ryan Walker)
- 01ddf37 linter: Add `allowReject` option to
`no-useless-promise-resolve-reject` (#7274) (no-yan)
- 755a31b linter: Support bind function case for compatibility with
`promise/no-return-wrap` (#7232) (no-yan)
- 428770e linter: Add `import/no-namespace` rule (#7229) (Dmitry
Zakharov)
- 9c91151 linter: Implement typescript/no-empty-object-type (#6977)
(Orenbek)
- 2268a0e linter: Support `overrides` config field (#6974) (DonIsaac)
- 3dcac1a linter: React/exhaustive-deps (#7151) (camc314)
- d3a0119 oxlint: Add `cwd` property to `LintRunner` (#7352) (Alexander
S.)

### Bug Fixes

- ba0b2ff editor: Reload workspace configuration after change (#7302)
(Alexander S.)
- bc0e72c linter: Handle user variables correctly for import/no_commonjs
(#7316) (Dmitry Zakharov)
- bf839c1 linter: False positive in `jest/expect-expect` (#7341)
(dalaoshu)
- ff2a1d4 linter: Move `exhaustive-deps` to `react` (#7251) (camc314)
- df5c535 linter: Revert unmatched rule error (#7257) (Cameron A
McHenry)
- c4ed230 linter: Fix false positive in eslint/no-cond-assign (#7241)
(camc314)
- ef847da linter: False positive in `jsx-a11y/iframe-has-title` (#7253)
(dalaoshu)
- 62b6327 linter: React/exhaustive-deps update span for unknown deps
diagnostic (#7249) (camc314)

### Documentation

- 4c124a8 editor/vscode: Update VS Code readme with installation
instructions and available features (#7306) (Nicholas Rayburn)

### Refactor

- c6a4868 linter: Temporarily remove unknown rules checking (#7260)
(camchenry)

### Testing

- 5190b7f editor: Add test setup (#7361) (Alexander S.)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-11-20 15:45:24 +08:00
overlookmotel
234c7b9fef feat(traverse): implement GatherNodeParts for member expression types (#7363)
`GatherNodeParts` was missing support for these types as entry points for collection.
2024-11-20 03:58:48 +00:00
Dunqing
c587dd3cd6 fix(codegen): do not print parenthesis for in expression in ArrowFunctionExpression (#7360)
Please check out [esbuild](https://esbuild.github.io/try/#dAAwLjI0LjAAACgpID0+ICIiIGluIHt9)
2024-11-19 14:29:18 +00:00
Boshen
d60801218e feat(transform_conformance): snapshot our transformed outputs (#7358) 2024-11-19 12:49:44 +00:00
Dunqing
6cfb5df9b9 feat(transformer): support generate proper binding name from ChainExpression (#7326) 2024-11-19 10:31:54 +00:00
Dunqing
58db9ef322 refactor(codegen): do not print unnecessary parentheses if both sides use the same logical operator (#7325)
As shown by the changing tests, we don't need to print parentheses for them.

### Comparison
In [esbuild](https://esbuild.github.io/try/#dAAwLjI0LjAAAGEgPz8gKGIgPz8gKGMgPz8gZCkpOwooYSA/PyAoYiA/PyAoYyA/PyBkKSkpOwooYSB8fCAoYiB8fCBjKSkgfHwgZDsKYSB8fCAoYiB8fCAoYyB8fCBkKSk7CmEgJiYgKChiICYmIGMpICYmIGQp), it will print parentheses as-is, in [SWC](https://play.swc.rs/?version=1.9.2&code=H4sIAAAAAAAAA0tUsLdX0EgCk8kgMkVT05pLIxGLMES8pgYkDiSTNTVBVIo1F5IgUDFIDKQ2UUFNTUEDKAykkjVBZIomAGEbiHtuAAAA&config=H4sIAAAAAAAAA1VQzW7DIAy%2B9ykin6tlyrHXTb3ttCdA1GmpACPbSIuqvPuAJml6w9%2Bv8ePQdXAXC6fuUZ5lSIYFeZsLIlNU81cQ0CmhWHZJ4biyKpVSztiQ%2BUmAGr6iVhPK8DkMsOJsoozEYd%2BQBb9xdBHPxF%2FeiJwd%2BossuVsVo7G68xXIhUSsv5TZYi27qSY59T1K%2BJBbn56W48vAOaoLTWuyUjDqLCz0%2FPYDTyRVNxovyw4QXHTjtF%2FdUiglIu%2FCKjXx6jf%2FYc1v6RDokhu5HL0etq5U0gLFu8BLuTZu6eDkZ7W3s8%2F%2FYy0r4MUBAAA%3D), we have the same output now
2024-11-19 10:31:53 +00:00
overlookmotel
c335f92ada perf(syntax): reorder operator enum variants (#7351)
Re-order enum variants of `AssignmentOperator`, `BinaryOperator` and `UnaryOperator`.

* `Exponential` moved to after `Remainder` (so with the rest of the arithmetic operators).
* `Shift*` operators follow arithmetic operators.
* `AssignmentOperator::Bitwise*` ops moved to before `Logical*` ops (so all ops which correspond to `BinaryOperator`s are together).
* `*Or` always before `*And`.
* Plus/Addition always before Minus/Subtraction.

The purpose is to make the various methods on these types maximally efficient:

1. Group together variants so that `AssignmentOperator::is_*` methods can be executed with the minimum number of operations (essentially `variant - min <= max`).
2. Align the variants of `AssignmentOperator` and `BinaryOperator` so that conversion methods added in #7350 become very cheap too (essentially `if variant - min <= max { Some(variant + offset) } else { None }`).
2024-11-19 01:23:28 +00:00
Dmitry Zakharov
bc0e72c1e2
fix(linter): handle user variables correctly for import/no_commonjs (#7316)
test case found in `typescript/no-require-imports`
2024-11-19 09:23:16 +08:00
Ryan Walker
1d9f528668
feat(linter): implement unicorn/prefer-string-raw lint rule (#7335)
Implements
[unicorn/refer-string-raw](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-raw.md)
for #684
2024-11-19 09:22:40 +08:00
overlookmotel
2534cdecb7 feat(syntax): add AssignmentOperator::to_logical_operator and to_binary_operator methods (#7350)
Add methods to convert `AssignmentOperator` to `LogicalOperator` or `BinaryOperator`. e.g. `+=` -> `+`, `&&=` -> `&&`.
2024-11-19 01:12:11 +00:00
overlookmotel
41a0e60c3e refactor(ast)!: remove impl GetAddress for Function (#7343)
`impl GetAddress for Function` was added as a hack, in the absence of another way to get the `Address` of a `&Function` (https://github.com/oxc-project/backlog/issues/140).

Remove it, and use `Address:from_ptr` instead in JSX Refresh transform, which is only place using it.
2024-11-19 01:05:31 +00:00
overlookmotel
b5a202711c style(syntax): improve formatting (#7349)
Style nit. Adjust formatting.
2024-11-18 22:26:30 +00:00
dalaoshu
bf839c1dfa
fix(linter): false positive in jest/expect-expect (#7341)
closes #7237
2024-11-18 15:17:36 +00:00
leaysgur
167d2d560d chore(docs): Replace TAB with SPACE to render markdown correctly (#7337)
Possibly fixes #7336
2024-11-18 11:54:33 +00:00
overlookmotel
c84e892380 perf(ast): AstBuilder::vec1 use Vec::from_array_in (#7334)
`AstBuilder::vec1` can use `Vec::from_array_in` rather than creating a `Vec` and then pushing to it. This should optimize better.
2024-11-18 02:35:46 +00:00
overlookmotel
510b95d6c4 perf(transformer): use AstBuilder::vec_from_array (#7333)
Use `AstBuilder::vec_from_array` introduced in #7331 in the transformer, in place of creating a `Vec` with `Vec::with_capacity` and then pushing values to it.
2024-11-18 02:35:46 +00:00
overlookmotel
39afb48025 feat(allocator): introduce Vec::from_array_in (#7331)
Because we lack specialization in stable Rust, `Vec::from_iter_in` is unable to take advantage of the fact that `[T; N]` has a statically knowable size.

Introduce `Vec::from_array_in` for this case, which should be able to create the `Vec` with a single static-sized memcpy, or may allow the compiler to see that it can construct the array directly in the arena, rather than construct on stack and then copy to the arena.

Also add a corresponding `AstBuilder::vec_from_array` method, and use it in various places in codebase.
2024-11-18 02:35:46 +00:00
overlookmotel
1938a1d6d9 refactor(isolated_declarations): do not copy Vec unnecessarily (#7332)
This function receives an owned `oxc_allocator::Vec`. No need to copy the contents to a new `Vec` with `AstBuilder::vec_from_iter`, can just use the original.
2024-11-18 02:28:38 +00:00
overlookmotel
44fd962fbb perf(transformer/arrow-functions): move arguments transform checks to aid inlining (#7322)
Move the cheap "does arguments need to be transformed" checks introduced in #7321 into `enter_identifier_reference` and `enter_binding_identifier`, and mark those methods `#[inline]`. These hot paths can then usually execute without a function call.

This wins back the other half of the perf hit of #7234.
2024-11-17 10:49:17 +00:00
overlookmotel
26d3e96aca perf(transformer/arrow-functions): store state of whether arguments needs transform (#7321)
Track whether `arguments` needs to be transformed. If it doesn't, can skip expensive checks for whether `IdentifierReference`s and `BindingIdentifier`s names are `arguments` or not.

This recovers about half the performance hit of #7234.
2024-11-17 10:49:16 +00:00
overlookmotel
871e19bea2 refactor(transformer/arrow-function): comments on possible improvement (#7320) 2024-11-17 10:07:35 +00:00
overlookmotel
ea08c1f495 refactor(transformer/arrow-function): reserve correct capacity for Vec (#7319) 2024-11-17 10:07:35 +00:00
overlookmotel
e09d2df448 perf(transformer/arrow-function): create super method binding names lazily (#7313)
Key `super` getter/setter hash map with original property name `&str`, instead of generated binding name. This allows a couple of improvements:

* Generate binding names for `super` getters/setters lazily, only when they're created, rather than every time you encounter a `super`.
* Don't allocate strings into arena which are never used as part of AST. Use `CompactString` for building those strings instead.
2024-11-17 10:07:34 +00:00
overlookmotel
5d853869eb refactor(transformer/arrow-functions): use IndexMap for super getter/setters (#7317)
Generate getter/setter declarations in same order as Babel by using `IndexMap` instead of `HashMap` to store `super` getter/setter method details.
2024-11-17 10:07:34 +00:00
overlookmotel
0a2470399e perf(transformer/arrow-function): optimize generate_super_binding_name (#7312)
Optimize this function in various ways:

* Return a static `Atom` (rather than allocating into arena) if no `property`.
* Reserve capacity for `ArenaString` at start.
* Make path for unicode identifiers (very rare case) `#[cold]` and `#[inline(never)]`.
* Slightly faster uppercase conversion.
2024-11-17 10:07:34 +00:00
overlookmotel
389b84e4ff fix(transformer/arrow-function): handle unicode when capitalizing property name (#7311)
Previously was assuming property name starts with an ASCII character. If it started with a multi-byte unicode char, `&property[1..]` would panic.
2024-11-17 10:07:34 +00:00
overlookmotel
5cfe0b623e refactor(transformer/arrow-function): generate_super_binding_name take &str and &TraverseCtx (#7310)
Pure refactor. Take `&str` rather than `&Atom` (1 less indirection) and `&TraverseCtx<'a>` (more conventional).
2024-11-17 10:07:33 +00:00
Dunqing
7d75130865 fix(transformer/async-to-generator): arguments isn't correct after transformation (#7234)
Fix due to this plugin transforming the async method and async arrow function, it caused arguments no longer point the original function.

For example:

Before

```js
class Cls {
  async method() {
    () => {
    	console.log(arguments)
    }
  }
}
```

After:

```js
class Cls {
  method() {
    var _arguments = arguments;
    return babelHelpers.asyncToGenerator(function* () {
      () => {
        console.log(_arguments);
      };
    })();
  }
}
```

In this way, the `_arguments` is its original function's arguments

### For performance regression

It seems we need to check the IdentifierReference and BindingIdentifier if it's an `arguments`, that causes a significant regression, we may need a cheap way to do checking
2024-11-17 05:01:44 +00:00
Ryan Walker
d445e0f612
feat(linter): implement unicorn/consistent-existence-index-check (#7262)
[unicorn/consistent-existence-index-check](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/consistent-existence-index-check.md)
for #684

---------

Co-authored-by: Cam McHenry <camchenry@users.noreply.github.com>
2024-11-16 20:07:52 +00:00
Song Gao
cf3415b0e4
chore(doc): replace main/master to tag/commit to make the url always accessible (#7298) 2024-11-16 21:00:30 +08:00
7086cmd
cf99be0a0d fix(minifier): do not compare bigint with object (#7294)
@Boshen, could you please update the snap of runtime and commit to this PR? I want to see the effects after the unit tests are added.
2024-11-16 06:01:06 +00:00
camchenry
20d9080d59 fix(linter)!: override plugins array when passed in config file (#7303)
- fixes https://github.com/oxc-project/oxc/issues/6896

When the `plugins` config property is specified, it will overwrite the default plugins array. This allows the plugins list to be easily customized and allows for disabling default plugins at the same time as enabling non-default ones.

- example: `{ "plugins": [] }` will enable no plugins.
- example: `{ }` will enable default plugins.
- example: `{ "plugins": ["typescript", "import"] }` will enable only the import and typescript plugins.
2024-11-16 05:54:05 +00:00
overlookmotel
d135d3ec48 feat(data_structures): add methods to SparseStack (#7305)
Add methods to `SparseStack` to get the filled entries as a slice, and get their length.
2024-11-16 05:36:36 +00:00
overlookmotel
4acf2db82b refactor(transformer): helper loader methods take Span (#7304)
`TransformCtx::helper_call` and `TransformCtx::helper_call_expr` take a `Span`. Sometimes the helper call replaces some original code, and should have the same span as the original code.
2024-11-16 05:36:35 +00:00
overlookmotel
faf8dde4ff feat(traverse): add methods for creating Expression::Identifiers (#7301)
It's a common pattern in transformer to call `ctx.create_ident_reference()` and then convert to an `Expression` with `Expression::Identifier(ctx.ast.alloc(ident))`.

Add methods to do this in a single method call.
2024-11-16 05:36:35 +00:00
overlookmotel
1cbc624a8b refactor(traverse)!: rename TraverseCtx methods for creating IdentifierReferences (#7300)
`create_reference_id` was a confusing name, as it doesn't return a `ReferenceId`. Rename these methods to more clearly represent what they do.
2024-11-15 16:44:08 +00:00
overlookmotel
a0766e6a7f fix(codegen): fix arithmetic overflow printing unspanned nodes (#7292)
Similar to #7289. Check if `span.end` is 0 before doing `span.end - 1`, to prevent arithmetic overflow.

Also changed all checks to `span.end > 0`, just for consistency.
2024-11-15 16:04:02 +00:00
overlookmotel
33ec4e6182 fix(codegen): fix arithmetic overflow printing unspanned NewExpression (#7289)
`self.span.end - 1` overflows if the `NewExpression` is generated in transformer and has no span, so `self.span.end == 0`.
2024-11-15 02:56:49 +00:00
Song Gao
8da23692fc
build(traverse): generate files in parallel (#7281)
Create type files in parallel. Although it's already pretty fast, always better to be faster.
2024-11-14 23:04:53 +00:00
overlookmotel
f0affa20c6 docs(ast): improve docs examples for PropertyDefinition (#7287) 2024-11-14 22:28:14 +00:00
Boshen
b57d00d6fb fix(tasks/compat_data): fix misplaced features (#7284)
closes #7279
2024-11-14 16:36:16 +00:00
overlookmotel
9f5ae56810 refactor(transformer/nullish-coalescing): split main logic into separate function (#7273)
Small refactor. Move main logic of the transform into a separate function, to allow `enter_expression` to be inlined.
2024-11-14 16:17:23 +00:00
overlookmotel
345fbb9da3 refactor(transformer/nullish-coalescing): avoid repeated symbol lookups (#7272)
`clone_expression` was unnecessarily looking up the `SymbolId` of references multiple times. Use `BoundIdentifier` instead to avoid that.

Notes:

* `create_conditional_expression` has to take all parts as `Expression`s just to support `this ?? something`.
* `TraverseCtx::is_static` also handles `Super`, but can skip that in this case as `super ?? something` is not valid syntax.
2024-11-14 16:17:23 +00:00
overlookmotel
5b5c8a9bdb fix(transformer/nullish-coalescing): correct span (#7269)
Transformed expression inherit same `Span` as the input.
2024-11-14 16:17:22 +00:00
overlookmotel
e219ae8c94 docs(transformer/nullish-coalescing): clarify doc comment (#7268)
Expand doc comment for `create_conditional_expression` to clarify what it does.
2024-11-14 16:17:21 +00:00
no-yan
01ddf37843
feat(linter): add allowReject option to no-useless-promise-resolve-reject (#7274)
followup to #7232.
2024-11-14 14:06:55 +00:00
overlookmotel
84038ee434 refactor(semantic): shorten code (#7277)
Tiny refactor. No need for `matches!` here.
2024-11-14 12:50:06 +00:00
overlookmotel
9e85cc10c9 refactor(semantic): remove duplicated code (#7276)
`if matches!(self.kind, TSModuleDeclarationKind::Global)` at top of function already performed this check, no need to check it again.
2024-11-14 12:50:04 +00:00
no-yan
755a31bda7
feat(linter): support bind function case for compatibility with promise/no-return-wrap (#7232)
part of #4655

### Summary

Logic has been added to handle bind functions, unifying the
implementations of `unicorn/no-useless-promise-resolve-reject` and
`promise/no-return-wrap`.
This enables detection of the following code:

```javascript
foo().then((function() { return Promise.resolve(4) }).bind(this))
```

Merging this PR will allow this rule to pass all test cases of
promise/no-return-wrap without options. Additionally, merging #7274 will
ensure that all test cases are passed.
2024-11-14 19:33:42 +08:00
Dmitry Zakharov
428770edee
feat(linter): add import/no-namespace rule (#7229) 2024-11-14 19:23:56 +08:00
camc314
ff2a1d4937 fix(linter): move exhaustive-deps to react (#7251)
@Boshen lemme know if this is incorrect, but i noticed that `rules-of-hooks` lives inside `react` not `react-hooks`

1f2a6c666f/crates/oxc_linter/src/config/rules.rs (L291-L292)

1f2a6c666f/crates/oxc_linter/src/options/filter.rs (L254)
2024-11-14 08:02:26 +00:00
Alexander S.
216d533b01
fix(language_server): revalidate files when oxlint config is changing (#7259)
![lsp-refresh-files](https://github.com/user-attachments/assets/e6b64f73-966d-490a-9191-b3ec64d3ac1e)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-14 10:45:17 +08:00
overlookmotel
10cdce9b67 style(ast): add line break (#7271) 2024-11-13 15:45:44 +00:00
ottomated
897d3b1567 feat(ast): serialize StringLiterals to ESTree without raw (#7263)
#7211 alternative. Makes the `raw` field on estree literals optional.
2024-11-13 15:37:30 +00:00
overlookmotel
e84ea2c3c6 refactor(traverse)!: remove TraverseCtx::clone_identifier_reference (#7266)
Remove `TraverseCtx::clone_identifier_reference`.

This API encourages unnecessary repeated lookups of the `SymbolId` for a reference. It is preferable to use `MaybeBoundIdentifier` which only looks up the `SymbolId` once.
2024-11-13 15:12:35 +00:00
overlookmotel
8c754b1b43 feat(traverse): introduce MaybeBoundIdentifier (#7265)
`MaybeBoundIdentifier` is similar to `BoundIdentifier`, but can be used where the identifier may or may not have have a `SymbolId` (may or may not be bound).

Typical usage:

```rs
// Create `MaybeBoundIdentifier` from an existing `IdentifierReference`
let binding = MaybeBoundIdentifier::from_identifier_reference(ident, ctx);

// Generate `IdentifierReference`s and insert them into AST
assign_expr.left = binding.create_write_target(ctx);
assign_expr.right = binding.create_read_expression(ctx);
```
2024-11-13 15:12:33 +00:00
overlookmotel
de472ca7c0 refactor(ast): move StringLiteral definition higher up (#7270)
Pure refactor. `StringLiteral` definition was sandwiched in the middle of RegExp-related code. Move it higher up in `literal.rs`.

All the rest of the diff is just re-ordering generated code.
2024-11-13 13:37:37 +00:00
overlookmotel
834c94d9d2 docs(traverse): tidy doc comments for TraverseCtx::is_static (#7267)
Better describe what this method does in its doc comment, and tidy up wording a little.
2024-11-13 11:40:07 +00:00
overlookmotel
7a4872818e refactor(traverse): reorder imports (#7264) 2024-11-13 11:02:37 +00:00
Orenbek
9c91151603
feat(linter): implement typescript/no-empty-object-type (#6977) 2024-11-13 09:31:16 +00:00
DonIsaac
2268a0ef90 feat(linter): support overrides config field (#6974)
Part of #5653
2024-11-13 05:40:59 +00:00
camchenry
c6a48684c3 refactor(linter): temporarily remove unknown rules checking (#7260)
I had intended to leave this in until we could rework some of the rule/plugin name resolution code, however this is causing issues with merging https://github.com/oxc-project/oxc/pull/6974. The mutability of `self` is difficult to resolve in that PR without more drastic changes. Since this isn't currently helping us out, I am simply removing the code for now until we can revisit this.
2024-11-13 03:41:03 +00:00
Cameron A McHenry
df5c535dd0
fix(linter): revert unmatched rule error (#7257)
- related to https://github.com/oxc-project/oxc/issues/6988

This is causing a lot of errors currently such as
https://github.com/oxc-project/oxc/issues/7233. I think we need to
handle rule names more robustly first:

- https://github.com/oxc-project/oxc/issues/7240
- https://github.com/oxc-project/oxc/issues/7082
- https://github.com/oxc-project/oxc/discussions/7242

then, I think we can revisit this and maybe implement it as an actual
lint plugin too? https://github.com/oxc-project/oxc/discussions/7086
2024-11-13 09:06:20 +08:00
camc314
c4ed230f8a fix(linter): fix false positive in eslint/no-cond-assign (#7241)
fixes #7238
2024-11-12 14:45:38 +00:00
overlookmotel
740ba4bcbd docs(ast): correct doc comment for StringLiteral (#7255)
Correct doc comment for `StringLiteral`'s `value` field. The doc comment was wrong.
2024-11-12 13:47:16 +00:00
dalaoshu
ef847dab9c
fix(linter): false positive in jsx-a11y/iframe-has-title (#7253)
closes #7243
2024-11-12 13:14:50 +00:00
overlookmotel
44375a5662 refactor(ast)!: rename TSEnumMemberName enum variants (#7250)
Variants of `TSEnumMemberName` were previously only prefixed with `Static` to avoid naming conflicts with the variants inherited from `Expression` for non-static member names. #7219 removed the variants inherited from `Expression`, so all variants are now static. So we can shorten the names again (back to what they were before `inherit_variants!` was introduced).
2024-11-12 12:22:21 +00:00
overlookmotel
d3d58f8ace refactor(ast): remove inherit_variants! from TSEnumMemberName (#7248)
#7219 removed all variants of `TSEnumMemberName` except `IdentifierName` and `StringLiteral`. It no longer inherits variants from `Expression`, so we can remove the `inherit_variants!` macro wrapper.

The discriminants no longer need to avoid clashes with `Expression`'s, so they can start at 0.
2024-11-12 12:22:20 +00:00
camc314
62b6327879 fix(linter): react/exhaustive-deps update span for unknown deps diagnostic (#7249)
Relates to #7246
2024-11-12 11:55:50 +00:00
camc314
3dcac1ae0b feat(linter): react/exhaustive-deps (#7151)
Firstly, a massive thanks to @alisnic for starting this (incredibly complicated) lint rule in https://github.com/oxc-project/oxc/pull/2637 !

still a draft. current state:

3x false positives (all todo with refs)

3x false negatives (TS will catch these
13x false negatvies todo with refs
1x false negative TODO

closes  #2637
relates to #2174
2024-11-12 11:42:47 +00:00
overlookmotel
c5f4ee7a82 fix(transformer): correct code comments (#7247)
Follow-on after #7199. Just correct typos in a couple of comments.
2024-11-12 11:09:22 +00:00
Boshen
20fe3cd6e7
chore(semantic): fix doc 2024-11-12 12:00:16 +08:00
Boshen
4740642926
chore(semantic): rename examples/simple.rs to examples/semantic.rs 2024-11-12 11:55:58 +08:00
Boshen
1282221e36 fix(codegen): print comments when block is empty (#7236)
part of #7190
2024-11-11 11:20:25 +00:00
7086cmd
0d6a66aa9e test(minifier): fix minimize condition tests (#7222) 2024-11-11 08:36:19 +00:00
Boshen
080a67be16 test(semantic): semantic checker store conformance pass/fail info in a separate file (#7235)
closes #6069
2024-11-11 08:13:13 +00:00
oxc-bot
de107246c8
release(crates): v0.36.0 (#7227)
## [0.36.0] - 2024-11-09

- b11ed2c ast: [**BREAKING**] Remove useless `ObjectProperty::init`
field (#7220) (Boshen)

- 0e4adc1 ast: [**BREAKING**] Remove invalid expressions from
`TSEnumMemberName` (#7219) (Boshen)

- 846711c transformer: [**BREAKING**] Change API to take a
`&TransformOptions` instead of `TransformOptions` (#7213) (Boshen)

- 092de67 types: [**BREAKING**] Append `rest` field into `elements` for
objects and arrays to align with estree (#7212) (ottomated)

- d1d1874 ast: [**BREAKING**] Change `comment.span` to real position
that contain `//` and `/*` (#7154) (Boshen)

- 843bce4 ast: [**BREAKING**] `IdentifierReference::reference_id` return
`ReferenceId` (#7126) (overlookmotel)

### Features

- cc8a191 ast: Methods on AST nodes to get `scope_id` etc (#7127)
(overlookmotel)
- dc0215c ast_tools: Add #[estree(append_to)], remove some custom
serialization code (#7149) (ottomated)
- 9d6cc9d estree: ESTree compatibility for all literals (#7152)
(ottomated)
- b74686c isolated-declarations: Support transform TSExportAssignment
declaration (#7204) (Dunqing)
- ad3a2f5 tasks/compat_data: Generate our own compat table (#7176)
(Boshen)
- b4258ee transformer: Add defaulted `Module::Preserve` option (#7225)
(Boshen)
- 324c3fe transformer: Add `TransformOptions::module` option (#7188)
(Boshen)
- a166a4a transformer: Add esbuild comma separated target API
`--target=es2020,chrome58` (#7210) (Boshen)
- 3a20b90 transformer: Add es target to `engineTargets` (#7193) (Boshen)
- 22898c8 transformer: Warn BigInt when targeting < ES2020 (#7184)
(Boshen)
- a579011 transformer: Add features `ES2018NamedCapturingGroupsRegex`
and `ES2018LookbehindRegex` (#7182) (Boshen)
- 8573f79 transformer: Turn on async_to_generator and
async_generator_functions plugins in enable_all (#7135) (Dunqing)
- df77241 transformer: Enable `ArrowFunctionConverter` in
`async-to-generator` and `async-generator-functions` plugins (#7113)
(Dunqing)
- b6a5750 transformer/arrow-function-converter: Move scope to changed
scope for `this_var` if scope have changed (#7125) (Dunqing)
- 1910227 transformer/async-to-generator: Support inferring the function
name from the ObjectPropertyValue's key (#7201) (Dunqing)
- ffa8604 transformer/async-to-generator: Do not transform await
expression if is not inside async function (#7138) (Dunqing)
- e536d47 transformer/babel: Add support for trying to get the `Module`
from `BabelPlugins` (#7218) (Dunqing)
- 5cfdc05 transformer/typescript: Support transform `export =` and
`import = require(...)` when module is commonjs (#7206) (Dunqing)

### Bug Fixes

- c82b273 transformer/async-generator-functions: Only transform object
method in exit_function (#7200) (Dunqing)
- b2a888d transformer/async-generator-functions: Incorrect
transformation for `for await` if it's not placed in a block (#7148)
(Dunqing)
- 19892ed transformer/async-generator-functions: Transform incorrectly
for `for await` if it's in LabeledStatement (#7147) (Dunqing)
- ede10dc transformer/async-to-generator: Incorrect transform when super
expression is inside async method (#7171) (Dunqing)
- 293d072 transformer/async-to-generator: Only transform object method
in exit_function (#7199) (Dunqing)
- ae692d7 transformer/async_to_generator: Fix checking if function is
class method (#7117) (overlookmotel)
- eea4ab8 transformer/helper-loader: Incorrect `SymbolFlags` for default
import when `SourceType` is script (#7226) (Dunqing)

### Refactor

- d27e14f ast: `AstKind::as_*` methods take `self` (#5546)
(overlookmotel)
- fac5042 ast: Use `scope_id` etc methods (#7130) (overlookmotel)
- a297765 minifier: Use `map` and `and_then` instead of let else (#7178)
(7086cmd)
- fc86703 napi/transform: Change test files to TypeScript (#7221)
(Boshen)
- c5485ae semantic: Add `ancestor_kinds` iterator function (#7217)
(camchenry)
- abf1602 semantic: Rename `iter_parents` to `ancestors` (#7216)
(camchenry)
- 42171eb semantic: Rename `ancestors` to `ancestor_ids` (#7215)
(camchenry)
- de56083 transformer: Add `impl TryFrom<EngineTargets> for EnvOptions`
(#7191) (Boshen)
- 0a43c64 transformer: Move `ESTarget` to its own file (#7189) (Boshen)
- 0e1f12c transformer: Remove unimplemented `EnvOptions::bugfixes`
(#7162) (Boshen)
- a981caf transformer: Add `Engine` enum for `EngineTargets` (#7161)
(Boshen)
- 8340243 transformer: Rename `Query` to `BrowserslistQuery` (#7143)
(Boshen)
- 481f7e6 transformer: Change `Targets` to `EngineTargets` (#7142)
(Boshen)
- 55e6989 transformer: Deserialize engine target strings to specific
keys (#7139) (Boshen)
- fdfd9a4 transformer: Use `scope_id` etc methods (#7128)
(overlookmotel)
- ff8bd50 transformer: Move implementation of ArrowFunction to
common/ArrowFunctionConverter (#7107) (Dunqing)
- 4a515be transformer/arrow-function-coverter: Rename function name and
add some comments to explain confusing parts. (#7203) (Dunqing)
- c307e1b transformer/arrow-functions: Pass `ArenaBox` as function param
(#7169) (overlookmotel)
- 217d433 transformer/arrow-functions: Remove unused `&mut self`
function param (#7165) (overlookmotel)
- 426df71 transformer/arrow-functions: Use `scope_id` method (#7164)
(overlookmotel)
- 11c5e12 transformer/arrow-functions: Correct comments (#7163)
(overlookmotel)
- 1238506 transformer/async-generator-function: Remove inactive
`#[allow(clippy::unused_self)]` attrs (#7167) (overlookmotel)
- 84ee581 transformer/async-generator-functions: Simplify identifying
whether within an async generator function (#7170) (overlookmotel)
- 1b12328 transformer/async-generator-functions: Use `clone` not
`clone_in` on `LabelIdentifier` (#7172) (overlookmotel)
- cd1006f transformer/async-generator-functions: Do not transform yield
expression where inside generator function (#7134) (Dunqing)
- 2c5734d transformer/async-generator-functions: Do not transform await
expression where inside ArrowFunctionExpression (#7132) (Dunqing)
- 5ce83bd transformer/async-generator-functions: Remove dead code for
handle await expression (#7131) (Dunqing)
- e04ee97 transformer/async-generator-functions: Move handling of
`MethodDefinition`'s value to `exit_function` (#7106) (Dunqing)
- b57d5a5 transformer/async-to-generator: Remove unused `&self` function
param (#7166) (overlookmotel)
- f80085c transformer/async-to-generator: Move handling of
`MethodDefinition`'s value to `exit_function` (#7105) (Dunqing)
- e2241e6 transformer/jsx-self: Remove unused `&self` function params
(#7159) (overlookmotel)
- 1dfd241 transformer/optional-catch-binding: Remove inactive
`#[allow(clippy::unused_self)]` attr (#7158) (overlookmotel)
- fd9b44c transformer/typescript: Remove inactive
`#[allow(clippy::unused_self)]` attr (#7160) (overlookmotel)
- cacfb9b traverse: Use `symbol_id` etc methods (#7129) (overlookmotel)

### Styling

- 38a6df6 transformer/arrow-functions: Semicolon after return statements
(#7168) (overlookmotel)
- 64b7e3a transformer/async-generator-functions: Import
`oxc_allocator::Vec` as `ArenaVec` (#7173) (overlookmotel)

### Testing

- be819dd napi/transform: Add test for not default es transform (Boshen)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-11-10 00:31:14 +08:00
Dunqing
eea4ab830a fix(transformer/helper-loader): incorrect SymbolFlags for default import when SourceType is script (#7226) 2024-11-09 14:32:44 +00:00
Boshen
b4258ee58e feat(transformer): add defaulted Module::Preserve option (#7225) 2024-11-09 12:55:13 +00:00
oxc-bot
68dc899887
release(oxlint): v0.11.1 (#7224)
## [0.11.1] - 2024-11-09

### Features

- 4dd9b60 editor/vscode: Replace existing output channel and trace
output channel with a single LogOutputChannel (#7196) (Nicholas Rayburn)
- 1fcd709 linter: Add jsx support for only-used-in-recursion (#7120)
(no-yan)
- 4d577cf linter: Add `import/first` rule (#7180) (Dmitry Zakharov)
- 9b8973f linter: Add `import/unambiguous` rule (#7187) (Dmitry
Zakharov)
- 5ab1ff6 linter: Implement @typescript-eslint/no-unsafe-function-type
(#6989) (Orenbek)

### Bug Fixes

- eea8879 editor/vscode: Update language client id to fix the resolution
of the oxc.trace.server setting (#7181) (Nicholas Rayburn)
- b73cfd9 linter: Fix `is_method_call` with parentheses and chain
expression (#7095) (tbashiyy)

### Refactor

- 8c0a362 linter: Use `ctx.source_range(comment.content_span())` API
(#7155) (Boshen)
- c5485ae semantic: Add `ancestor_kinds` iterator function (#7217)
(camchenry)
- abf1602 semantic: Rename `iter_parents` to `ancestors` (#7216)
(camchenry)
- 42171eb semantic: Rename `ancestors` to `ancestor_ids` (#7215)
(camchenry)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-11-09 19:57:08 +08:00
7086cmd
a2977655c8 refactor(minifier): use map and and_then instead of let else (#7178)
For the test case, Closure Compiler doesn't handle this at all in the REPL! If it's necessary, I will turn it back.

This PR uses builtin `and_then` and `map` method, which is better instead of a lot of `if let Some`.
2024-11-09 11:48:48 +00:00
overlookmotel
d27e14f065 refactor(ast): AstKind::as_* methods take self (#5546)
Make `AstKind::as_*` methods (e.g. `AstKind::as_boolean_literal`) take `self`, not `&self`.

`AstKind` is `Copy`.

See: https://github.com/oxc-project/oxc/issues/5506#issuecomment-2332912976
2024-11-09 09:39:13 +00:00
Dunqing
5cfdc05d06 feat(transformer/typescript): support transform export = and import = require(...) when module is commonjs (#7206)
close: #7141
2024-11-09 09:32:28 +00:00
no-yan
1fcd70932d
feat(linter): add jsx support for only-used-in-recursion (#7120)
close #5530

This PR adds support for handling recursive JSX components, allowing
detect functions like the one below:

```javascript
function ListItem({ depth }) {
    return <ListItem depth={depth} />
}
```

Some logic is duplicated with the non-JSX case. But the refactor will be
complicated and affects over-all, so we can make it in another PR.

cc: @DonIsaac @camc314

---------

Co-authored-by: Cam McHenry <camchenry@users.noreply.github.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-09 17:11:27 +08:00
Dmitry Zakharov
4d577cf69f
feat(linter): add import/first rule (#7180) 2024-11-09 17:10:59 +08:00
Boshen
b11ed2cf7b refactor(ast)!: remove useless ObjectProperty::init field (#7220)
closes https://github.com/oxc-project/backlog/issues/143
2024-11-09 09:00:29 +00:00
Boshen
0e4adc15dd feat(ast)!: remove invalid expressions from TSEnumMemberName (#7219) 2024-11-09 08:48:14 +00:00
Dunqing
e536d47e56 feat(transformer/babel): add support for trying to get the Module from BabelPlugins (#7218)
When configuring a `transform-modules-commonjs` plugin in `options.json`, we should treat it as a `CommonJS` module
2024-11-09 08:38:15 +00:00
Boshen
324c3fe184 feat(transformer): add TransformOptions::module option (#7188) 2024-11-09 08:38:15 +00:00
camchenry
c5485ae7ee refactor(semantic): add ancestor_kinds iterator function (#7217)
for convenience, I've added a new function called `ancestor_kinds` which loops overall `ancestors` and gets their `AstKind`. this is a common pattern in a couple of places. I also did some somewhat related refactoring to remove places where we were manually calling `AstNode::kind` instead of using `ancestor_kinds` or calling `parent_kind`.
2024-11-09 08:04:38 +00:00
camchenry
abf1602f33 refactor(semantic): rename iter_parents to ancestors (#7216)
for consistency with the `ancestor_ids` function, this changes it to use the same terminology but make it clear it actually returns the node, not just the ID.

this is pure refactor, no functional changes here.
2024-11-09 07:07:26 +00:00
camchenry
42171eba94 refactor(semantic): rename ancestors to ancestor_ids (#7215)
pure refactor, renaming this method to make it more clear that it returns only IDs, not nodes. in preparation for the next PR.
2024-11-09 07:00:15 +00:00
Boshen
846711cf41 feat(transformer)!: change API to take a &TransformOptions instead of TransformOptions (#7213)
closes #7185

`TransformOption`s has an initialization cost, it should be initialized once and shared across files.
2024-11-09 06:01:13 +00:00
ottomated
092de67c47 fix(types)!: append rest field into elements for objects and arrays to align with estree (#7212)
Fixes https://github.com/oxc-project/oxc/pull/7149#discussion_r1831677446 and removes the need for some manual typescript.
2024-11-09 05:23:53 +00:00
Boshen
a166a4abd7 feat(transformer): add esbuild comma separated target API --target=es2020,chrome58 (#7210) 2024-11-08 14:09:20 +00:00
Dunqing
b74686c598 feat(isolated-declarations): support transform TSExportAssignment declaration (#7204)
part of #7141
2024-11-08 11:51:41 +00:00
Dunqing
4a515be24e refactor(transformer/arrow-function-coverter): rename function name and add some comments to explain confusing parts. (#7203)
close: #7174
2024-11-08 08:18:46 +00:00
Dunqing
ede10dc030 fix(transformer/async-to-generator): incorrect transform when super expression is inside async method (#7171)
After transformation, super expressions have moved to unexpected places. This PR replaces super expression to call expression, and then inserts the super methods to the top of the method body.

For example:

Before:
```js
class G {
  async method() {
    super.foo()
  }
}
```

After:
```js
class G {
  method() {
    var _superprop_getFoo = () => super.foo,
      _this = this;
    return _asyncToGenerator(function* () {
      _superprop_getFoo().call(_this);
    })();
  }
}```
2024-11-08 08:18:45 +00:00
Dunqing
1910227590 feat(transformer/async-to-generator): support inferring the function name from the ObjectPropertyValue's key (#7201)
Support for inferring function name from ObjectPropertyValue's key

For example:
```js
({ foo: async function() {} })
```

After this, we will able to infer `foo` for the object method
2024-11-08 08:18:44 +00:00