Commit graph

5197 commits

Author SHA1 Message Date
Boshen
cbd9a60194
fix(wasm): do not run symbols and scopes for .d.ts files 2024-08-30 19:57:09 +08:00
Dunqing
32f730085c feat(ast)!: add JSXElementName::IdentifierReference and JSXMemberExpressionObject::IdentifierReference (#5223)
close: #3528

part of #4746
2024-08-30 11:11:04 +00:00
Boshen
8ab270b720
feat(wasm): add mangler 2024-08-30 18:45:56 +08:00
Dunqing
783a31beb6 ci(benchmark/transformer): enable all > es6 plugins (#5324)
There is a bug in the react refresh plugin, I will fix it in follow-up PR and enable the plugin in the benchmark
2024-08-30 09:30:17 +00:00
Dunqing
d04857bd35 feat(transformer): support Targets::from_query method (#5336) 2024-08-30 09:30:16 +00:00
Dunqing
3d4a64c811 feat(transformer): make Targets public (#5335) 2024-08-30 09:30:15 +00:00
Dunqing
8334bd4fa2 docs(transformer): add documentation for Targets::get_targets (#5337)
`Targets` will be public in follow-up PRs.
2024-08-30 09:30:14 +00:00
Boshen
3ae94b8801
refactor(semantic): change build_module_record to accept &Path instead of PathBuf 2024-08-30 12:24:49 +08:00
overlookmotel
946c867b27 refactor(ast): box TSThisParameter (#5325)
Box `TSThisParameter` in `Function`, `TSMethodSignature` and `TSFunctionType`. I assume `function(this: Whatever) {}` is a fairly rare syntax in TS code, and obviously never occurs in JS code, so it takes up a lot of space in `Function` for this uncommon case.

This change reduces `Function` from 136 bytes to 104.
2024-08-29 18:00:58 +00:00
Dunqing
0eb7602e18 feat(transformer): support TransformOptions::from_preset_env API (#5323) 2024-08-29 15:20:50 +00:00
camc314
b1037372b7 feat(linter): improve no-accumulating-spread (#5302)
VSCode has a couple violations. examples:

```
  x oxc(no-accumulating-spread): Do not spread accumulators in loops
    ,-[src/vs/workbench/services/textMate/common/TMGrammarFactory.ts:65:5]
 64 |                 let injections: string[] = [];
 65 |                 for (let i = 1; i <= scopeParts.length; i++) {
    :                 ^|^
    :                  `-- For this loop
 66 |                     const subScopeName = scopeParts.slice(0, i).join('.');
 67 |                     injections = [...injections, ...(this._injections[subScopeName] || [])];
    :                                   ^^^^^^|^^^^^^
    :                                         `-- From this spread
 68 |                 }
    `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  x oxc(no-accumulating-spread): Do not spread accumulators in loops
     ,-[src/vs/base/common/actions.ts:205:3]
 204 |         let out: IAction[] = [];
 205 |         for (const list of actionLists) {
     :         ^|^
     :          `-- For this loop
 206 |             if (!list.length) {
 207 |                 // skip
 208 |             } else if (out.length) {
 209 |                 out = [...out, new Separator(), ...list];
     :                        ^^^|^^
     :                           `-- From this spread
 210 |             } else {
     `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  help: It looks like you're spreading an `Array`. Consider using the `Array.push` or `Array.concat` methods to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  x oxc(no-accumulating-spread): Do not spread accumulators in loops
     ,-[src/vs/workbench/contrib/extensions/browser/extensionsActions.ts:302:3]
 301 |         let actions: IAction[] = [];
 302 |         for (const visibleActions of actionsGroups) {
     :         ^|^
     :          `-- For this loop
 303 |             if (visibleActions.length) {
 304 |                 actions = [...actions, ...visibleActions, new Separator()];
     :                            ^^^^^|^^^^
     :                                 `-- From this spread
 305 |             }
     `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  x oxc(no-accumulating-spread): Do not spread accumulators in loops
      ,-[src/vs/workbench/contrib/extensions/browser/extensionsActions.ts:1141:3]
 1140 |         let actions: IAction[] = [];
 1141 |         for (const menuActions of menuActionGroups) {
      :         ^|^
      :          `-- For this loop
 1142 |             actions = [...actions, ...menuActions, new Separator()];
      :                        ^^^^^|^^^^
      :                             `-- From this spread
 1143 |         }
      `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

  x oxc(no-accumulating-spread): Do not spread accumulators in loops
     ,-[src/vs/workbench/contrib/extensions/browser/extensionsViews.ts:334:4]
 333 |             let actions: IAction[] = [];
 334 |             for (const menuActions of groups) {
     :             ^|^
     :              `-- For this loop
 335 |                 actions = [...actions, ...menuActions, new Separator()];
     :                            ^^^^^|^^^^
     :                                 `-- From this spread
 336 |             }
     `----
  help: Consider using `Object.assign()` or `Array.prototype.push()` to mutate the accumulator instead.
        Using spreads within accumulators leads to `O(n^2)` time complexity.

```
2024-08-29 14:17:44 +00:00
overlookmotel
da8aa1873a improve(traverse)!: TraverseCtx::ancestors iterator do not yield Ancestor::None (#5295)
`TraverseCtx::ancestors` iterator would previously yield `Some(Ancestor::None)` before finally yielding `None`. Skip `Ancestor::None` as it's pointless.
2024-08-29 09:22:13 +00:00
overlookmotel
23e84564e7 fix(traverse)!: TraverseCtx::ancestor with level 0 = equivalent to parent (#5294)
Change meaning of `level` passed to `TraverseCtx` from "levels above current" to "levels above parent". `ctx.parent()`'s equivalent was `ctx.ancestor(1)`, now it's `ctx.ancestor(0)`.

This prevents out of bounds read on `ctx.ancestor(0)` (UB), which was made possible by #5286.
2024-08-29 08:52:04 +00:00
overlookmotel
6e969f9fa4 feat(semantic): add ScopeTree::delete_root_unresolved_reference (#5305)
Add an API to `ScopeTree` to delete an unresolved reference.
2024-08-29 08:39:09 +00:00
Dunqing
d2666fe039 refactor(transformer/object-rest-spread): move plugin-relates files to object_rest_spread mod (#5320)
Both `object_spread` and `object_rest` belong to `object_rest_object`, so moving them to the plugin mod makes the file structure clearer
2024-08-29 07:35:09 +00:00
Dunqing
164511549f refactor(transformer/object-reset-spread): make plugin initialization unconditional (#5319)
Align with other plugins
2024-08-29 07:35:08 +00:00
DonIsaac
9c22ce9c99 feat(linter): add hyperlinks to diagnostic messages (#5318)
Adds hyperlinks to diagnostic codes.

Diagnostics without codes will not have links. In practice, this means linter diagnostics have links, while semantic and parser diagnostics do not.

![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/OVwvhVoSj4tgQWTUipoY/11790a3a-7dfa-4c6d-be43-550d8b6370a9.png)

> notice the underline under the error code
2024-08-29 05:50:04 +00:00
DonIsaac
cd63336c7e refactor(diagnostic): change how diagnostic codes are rendered (#5317)
Preparation for upstack PRs. Graphical reporter diagnostics look exactly the same. This does, however, change `to_string()` to only show diagnostic messages, and not error codes + messages.
2024-08-29 05:50:03 +00:00
oxc-bot
53ff3493ef
Release oxlint v0.9.1 (#5316)
## [0.9.1] - 2024-08-29

### Features

- 6633972 linter: Add fixer for `no-empty` (#5276) (camc314)
- a58e448 linter/eslint: Add fixer to `no-var` (#5144) (camc314)
- a6e9769 linter/jsx-a11y: Add `label-has-associated-control` (#5163)
(Billy Levin)
- c8e8532 linter/unicorn: Add fixer to `throw-new-error` (#5275)
(camc314)
- 7ccde4b linter/unicorn: Add fixer to `prefer-date-now` (#5147)
(camc314)

### Bug Fixes

- 76e86f8 linter: Eslint-plugin-unicorn prefer-spread wrong linter
suggestion on variables of type string (#5265) (Arian94)
- b39544e linter/jest: Fixer for `prefer-jest-mocked` creates invalid
LHS expressions (#5243) (camc314)
- 9953fa5 linter/no-null: Incorrect fixer for `NullLiteral` within
`ReturnStatement` (#5247) (Dunqing)
- 318479e linter/no-unused-vars: Mark the class/function in the new
expression as used (#5306) (magic-akari)

### Refactor

- fa1d460 linter: Clean up Fixer and Message (#5308) (DonIsaac)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-08-29 13:04:52 +08:00
cinchen
fdef8aec72
fix(linter): jest/vitest rule compat (#4797)
This pr is for jest/vitest compat and add another jest rule condition

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
Co-authored-by: Wang Wenzhe <mysteryven@gmail.com>
2024-08-29 11:04:00 +08:00
Boshen
2bc36ccbb6
chore: add scopes_for_breaking_change to oxc_release.toml 2024-08-29 11:02:48 +08:00
camc314
bb995f6361 feat(jsx-a11y/linter) add fixer for scope (#5310) 2024-08-29 00:51:00 +00:00
camc314
e5ead86d43 feat(linter) catch more cases for misrefactored-assign-op (#5309)
changes from using `without_parenthesis` to using `get_inner_expression` to ignore type casts, non null assertions ect.

this helps catch more error cases
2024-08-29 00:47:38 +00:00
Dunqing
3acb3f6461 fix(transformer/react): mismatch output caused by incorrect transformation ordering (#5255)
close: #4767
2024-08-29 00:38:02 +00:00
DonIsaac
fa1d460852 refactor(linter): clean up Fixer and Message (#5308)
- refactor(linter): clean up Fixer and Message
- perf(linter): replace sort_by_key with sort_unstable_by_key in fixer
2024-08-28 23:19:46 +00:00
DonIsaac
270fc53401 chore(bench): include fixers in linter benchmarks (#5307)
Fixing code is an important part of linter logic. We want to make sure fixers for each rule, and the code responsible for applying those fixes, are included in benchmarks.

As it currently stands, fixer closures are applied regardless of whether the user wants fixers to be applied. However, this is an implementation detail and is subject to change. I  also want to bench the performance of `Fixer`.
2024-08-28 23:19:43 +00:00
magic-akari
318479ec4d
fix(linter/no-unused-vars): mark the class/function in the new expression as used (#5306)
Fix: #5274
2024-08-28 13:38:16 -04:00
magic-akari
08dc0adeab feat(transformer): add object-spread plugin (#3133) 2024-08-28 15:57:20 +00:00
Boshen
5c4c00123d fix(codegen): print export @decorator declare abstract class Foo correctly (#5303) 2024-08-28 15:30:39 +00:00
camc314
6633972663 feat(linter): add fixer for no-empty (#5276)
adds a suggestion for `no-empty` eslint lint rule
2024-08-28 15:06:29 +00:00
Boshen
7fa2fa386c
refactor(wasm): clean up code and add transform (#5299)
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-08-28 22:14:35 +08:00
overlookmotel
5380eccca4 ci: enable arithmetic overflow checks in conformance tests (#5296)
Enable checks for arithmetic overflow in conformance tests, to catch more bugs.
2024-08-28 14:07:11 +00:00
Boshen
8d6b05ca01 fix(transformer): class property with typescript value should not be removed (#5298) 2024-08-28 13:53:41 +00:00
Boshen
70091771b6
test(parser): fix incorrect flow error test 2024-08-28 20:53:32 +08:00
Boshen
fb75d2576b
Revert "fix(parser): Revert "check for @flow with recoverable errors as well" (#5297)"
This reverts commit d4c06ef093.
2024-08-28 20:53:13 +08:00
overlookmotel
d4c06ef093 fix(parser): Revert "check for @flow with recoverable errors as well" (#5297)
e1d8b92080 caused CI to fail. Revert it.
2024-08-28 12:48:37 +00:00
Boshen
e1d8b92080
fix(parser): check for @flow with recoverable errors as well 2024-08-28 19:39:07 +08:00
Boshen
5e27798dc3
chore(parser): parse regular expression in example 2024-08-28 19:32:44 +08:00
overlookmotel
b43a3948a1 refactor(traverse): correct code comments (#5293)
#5286 changed `TraverseCtx::ancestor` to always return an `Ancestor`. Update doc comments to reflect that.
2024-08-28 10:10:04 +00:00
Dunqing
292d162b23 feat(codegen): print missing fields for AccessorProperty (#5291)
Found in https://github.com/oxc-project/monitor-oxc/actions/runs/10592050362/job/29350666018
2024-08-28 08:42:39 +00:00
Dunqing
5754c89b5e fix(transformer/typescript): remove accessibility from AccessorProperty (#5292)
Regression by #5290
2024-08-28 08:42:38 +00:00
Dunqing
550574982f feat(ast): add accessibility field to AccessorProperty (#5290) 2024-08-28 08:42:37 +00:00
Arian94
76e86f80df
fix(linter): eslint-plugin-unicorn prefer-spread wrong linter suggestion on variables of type string (#5265)
fixes #5248.

Similar issue found in here:
https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1147
2024-08-28 09:26:44 +01:00
overlookmotel
582ce9ea65 refactor(traverse)!: TraverseCtx::ancestor return Ancestor::None if out of bounds (#5286)
This aligns it better with `TraverseCtx::parent` which always returns an `Ancestor`.
2024-08-28 05:26:16 +00:00
Kevin Deng 三咲智子
234a24c14d
fix(ast)!: merge UsingDeclaration into VariableDeclaration (#5270)
relate #2854
2024-08-28 11:26:05 +08:00
leaysgur
15b87adb05 chore(regular_expression): Extract diagnostics (#5287)
- Extract `Diagnostic::error()`s to separate file
- Align error message prefix
2024-08-28 03:19:29 +00:00
camc314
d6b84ec44e fix(linter) bug in fixer for no-null (#5273)
i tested this in the microsoft/vscode repo and there were no syntax errors after running the fixer 🎉

hopefully this is the last fix.
2024-08-28 02:14:38 +00:00
Boshen
e6fd52e2a6 fix(parser): change unterminated regex error to be non-recoverable (#5285)
closes #5257
2024-08-28 01:57:31 +00:00
leaysgur
cffce11620 fix(regular_expression): Prevent panic on too large number (#5282)
Partially close #5257

Use `checked_(mul|add)` to prevent panic.
2024-08-28 01:31:54 +00:00
overlookmotel
d71f0ed2d0 refactor(traverse): inline all passthrough methods (#5279)
Many methods of `TraverseCtx` just delegate to methods of `TraverseAncestry` or `TraverseScoping`. Mark them all `#[inline]`.
2024-08-28 01:07:11 +00:00