Commit graph

7114 commits

Author SHA1 Message Date
Dunqing
ab51c2ae90 feat(transformer): support DefaultImport in ModuleImports (#6434)
Support import like `import React from 'react';` by `ModuleImports`

The usage is:
```rs
 self.ctx.module_imports.add_import(
     Atom::from("react"),
     ImportKind::new_default(Atom::from("React")),
     symbol_id
)
2024-10-13 08:09:07 +00:00
Dunqing
02bfbfeef5 fix(codegen): preserve parenthesis for ChainExpression (#6430)
close: #6385

The fixing way was referenced from `esbuild`, it is according to these [states](332727499e/internal/js_ast/js_ast.go (L590-L604)
)(determined in the parser) to determine whether to print parenthesis

Due to differences in implementation details, we are unable to record certain information like `esbuild` does in its parser. But fortunately, The `ParenthesisExpression` AST is actually like what `esbuild` stored states.
2024-10-13 08:03:37 +00:00
Boshen
c56343d1f3 feat(linter): promote no_unsafe_optional_chaining to correctness (#6491)
It's in the eslint recommended list https://eslint.org/docs/latest/rules/no-unsafe-optional-chaining
2024-10-13 07:58:01 +00:00
IWANABETHATGUY
1a93033b7b feat(oxc_language_server): add diagnostic code with link (#6487)
1. follow #6479
2. Adding related doc link to lsp diagnostic code.
## Preview
![image](https://github.com/user-attachments/assets/dad5b6a2-787a-43c3-b308-ebe74e38e21c)

**after click**
![image](https://github.com/user-attachments/assets/5b725fcd-cacd-4779-9b2a-15824d7c0cf7)

The UI looks a little wired, due to aba9ea3f1d/crates/oxc_diagnostics/src/lib.rs (L113-L120),

I suggest change the code above to
```rs
format!("{scope}/{number}")
```
2024-10-13 07:07:43 +00:00
camc314
2ade16ece5 fix(codegen): invalid codegen when in inside bin expr in or loop (#6431)
https://github.com/oxc-project/monitor-oxc/actions/runs/11278829870 ??
2024-10-13 06:47:10 +00:00
camc314
6896efc00c fix(codegen): fix in in sequence expr in for loops (#6428)
not sure if this is right, but it doesn't break any existing tests so hopefully?
2024-10-13 06:47:09 +00:00
camc314
096e590483 feat(minifier): implement folding charAt string fns (#6436) 2024-10-13 06:41:05 +00:00
camc314
e5a6f5de6a feat(minifier): implement converting template literals to strings (#6486)
basically:
```
`hello ${"world"}`
```
 now becomes:
```
"hello world"
```
2024-10-13 06:26:32 +00:00
camc314
14d0590b0b feat(minifier): implement folding of simple function calls (Boolean) (#6484)
Basically `Boolean(true)` -> `true` or `Boolean(foo)` -> `!!foo`
2024-10-13 06:26:32 +00:00
camc314
7fbc7b6dae feat(minifier): implement folding of simple function calls (String) (#6483)
basically `String(foo)` -> `foo + ''`
2024-10-13 06:26:31 +00:00
Tapan Prakash
bae5b7da27
chore(editors/vscode): Remove Prettier dependency entirely (#6480)
Previous PR removed the Prettier commands
(https://github.com/oxc-project/oxc/pull/6412), but the prettier
dependency was not fully removed. This PR aims to remove the dependency
from package.json entirely.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-10-13 14:25:49 +08:00
DonIsaac
58467a53a1 feat(parser): better handling of invalid modifiers (#6482)
## What This PR Does

1. Recover on, and provide a better message for, invalid `export` modifier on constructor parameters. Before, an `unexpected token` error would be produced and the parser would panic. Now, the parser recovers and produces a message saying `'export' modifier cannot appear on a parameter.`
  ```ts
class Foo {
    constructor(export x: number) {}
}
  ```

2. Recover on, and provide a better message for, invalid modifiers on index signatures. Same recovery/message characteristics as above.
  ```ts
class Foo {
    public [x: string]: string;
}
```
2024-10-13 03:16:02 +00:00
DonIsaac
8ea6b721b8 feat(parser): better errors for reserved words used as identifier names (#6478)
## What This PR Does
Provide better error messages when a reserved word is used as a `BindingIdentifier`
```ts
var const = 1;
export enum const {}
const if = 1;
```
2024-10-13 03:16:01 +00:00
IWANABETHATGUY
66dccc0584
feat(oxc_language_server): add related code for lsp_types::Diagnostic#source (#6479)
Closed #6477
# Before
# After

![image](https://github.com/user-attachments/assets/20377c2f-ba94-4fb5-a21c-fbd269f40385)

![image](https://github.com/user-attachments/assets/fae901b3-9753-4610-8b36-61974781f770)

Compare to eslint: 

![image](https://github.com/user-attachments/assets/0037b265-0a84-4eae-8bc9-4cbb66197485)

we could polish in the feature and link to
`lsp_types::Diagnostic#source`
2024-10-13 01:53:05 +08:00
dalaoshu
0784e74791
fix(linter): error fixer of switch-case-braces (#6474)
Related to #6466 

This PR does not fundamentally solve the problem, we need to implement
`raw` or `value` for `RegExpLiteral`.


1ba2a247e1/crates/oxc_codegen/src/gen.rs (L1194-L1198)


1ba2a247e1/crates/oxc_ast/src/ast/literal.rs (L94-L101)
2024-10-13 00:15:08 +08:00
Boshen
bbca743689 refactor(minifier): move string methods to oxc_ecmascript (#6472) 2024-10-12 09:40:43 +00:00
Boshen
856cab5000 refactor(ecmascript): move ToInt32 from oxc_syntax to oxc_ecmascript (#6471) 2024-10-12 09:29:46 +00:00
Boshen
1ba2a247e1 refactor(ecmascript): remove HasProto which is not part of the spec (#6470) 2024-10-12 08:48:45 +00:00
Boshen
455dab4900 chore(oxc): rename crate oxc_syntax_operations to oxc_ecmascript (#6469) 2024-10-12 08:34:42 +00:00
7086cmd
702c049ebc refactor(minifier): move compress block to dce (#6468) 2024-10-12 07:59:44 +00:00
Boshen
91c87dd380 refactor(codegen)!: remove Codegen::enableSourceMap API (#6452) 2024-10-12 04:56:43 +00:00
camc314
a4f57a42e8 feat(minifier): implement folding indexOf and lastIndexOf string fns (#6435) 2024-10-12 04:36:13 +00:00
DonIsaac
5ee1ef3d92 feat(allocator): add Vec::into_boxed_slice (#6195)
Note that this PR does not implement the inverse operation (`Box::to_vec` for `[T]`).
2024-10-12 04:29:43 +00:00
Alexander S.
7240ee23fc
refactor(linter): make advertised fix kinds consistent (#6461) 2024-10-11 19:25:32 -04:00
overlookmotel
b48c3683d6 refactor(linter): no_global_assign rule: reduce name lookups (#6460)
2 small optimizations to this lint rule:

1. Get the name for the symbol only once, rather than on each turn of the inner loop (every reference to a symbol has the same name by definition).
2. Avoid creating temporary `CompactStr`s, which causes an allocation if the string is longer than 24 bytes.
2024-10-11 20:53:35 +00:00
Boshen
7645e5c34b refactor(codegen)!: remove CommentOptions API (#6451) 2024-10-11 13:53:28 +00:00
7086cmd
3677ef81e9 feat(minifier): dce ExpressionStatements with no side effect (#6457)
Not sure about the performance. Just have a try.
2024-10-11 13:40:44 +00:00
dalaoshu
e81181261d
fix(linter): error diagnostic message based on parameter length of valid-expect (#6455) 2024-10-11 09:16:17 -04:00
overlookmotel
073b02af14 refactor(ast): type params field before params in TS function declaration types (#6391)
Our convention is that AST type fields are ordered in order they appear in source. Move `type_parameters` fields in TS function declaration types to before `this_param` and formal parameters.
2024-10-11 09:57:28 +00:00
7086cmd
06ea1216af feat(minifier): fold for statement (#6450) 2024-10-11 08:33:23 +00:00
overlookmotel
85d93ed713 fix(transformer): arrow function transform: correctly resolve this in class accessor properties (#6386)
Correctly resolve scope of `this` in class accessor properties.

The omission of this case became clear from examining Babel's `environmentVisitor`:

f343c499b0/packages/babel-traverse/src/visitors.ts (L398-L436)
2024-10-11 07:09:56 +00:00
Boshen
cb8f4210c3 refactor(prettier)!: remove source_text argument from constructor (#6448) 2024-10-11 06:27:33 +00:00
Boshen
520096030a refactor(oxc)!: remove passing Trivias around (#6446)
part of #6426
2024-10-11 06:09:25 +00:00
Boshen
2808973af3 feat(ast)!: add Program::comments (#6445) 2024-10-11 04:47:36 +00:00
Boshen
2b7be08af4 feat(ast)! add source_text to Program (#6444) 2024-10-11 04:13:41 +00:00
Boshen
4d8bc8c8af perf(parser): precompute is_typescript (#6443) 2024-10-11 03:39:38 +00:00
Boshen
b1bf12c336 fix(parser): do not parse as and satisfies expression in javascript (#6442)
closes #6427
2024-10-11 03:31:24 +00:00
Boshen
46a38c63ff refactor(minifier): remove allow clippy::unused_self (#6441) 2024-10-11 02:54:25 +00:00
DonIsaac
2566ce787d refactor(linter): remove OxlintOptions (#6098)
Removed in favor of LinterBuilder
2024-10-11 02:30:26 +00:00
DonIsaac
002078afe3 refactor(linter): make Runtime's members private (#6440)
Protecting `Runtime`'s API in preparation of multli-config support.
2024-10-11 02:11:28 +00:00
DonIsaac
c00f669435 perf(linter): use NonZeroUsize for pending module cache entries (#6439)
Using `NonZeroUsize` lets `rustc` detect a niche value, shrinking the size of `CacheStateEntry` from 16 bytes to 8. It has the added benefit of making `CacheStateEntry::PendingStore`'s purpose clearer.
2024-10-11 02:11:28 +00:00
DonIsaac
6a0a5337e1 refactor(linter): move module cache logic out of Runtime (#6438)
Pure refactor. Makes `Runtime` easier to reason about.
2024-10-11 02:11:27 +00:00
DonIsaac
c18c6e9db1 refactor(linter): split service code into separate modules (#6437)
Refactor in preparation of multi-config/`override` support.
2024-10-11 02:11:27 +00:00
Dunqing
702b574afb refactor(codegen): only print necessary parentheses in TSAsExpression (#6429)
Part of fixing #6385
2024-10-11 02:04:27 +00:00
Don Isaac
7458089e3c
chore: add dev container config (#6433)
This will make it easier to review PRs in github codespaces.

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-10-11 10:04:09 +08:00
DonIsaac
80266d85c9 feat(linter)!: support plugins in oxlint config files (#6088)
> Closes #5046
This PR migrates the linter crate and oxlint app to use the new `LinterBuilder` API. This PR has the following effects:

1. `plugins` in oxlint config files are now supported
2. irons out weirdness when using CLI args and config files together. CLI args are now always applied on top of config file settings, overriding them.

# Breaking Changes
Before, config files would override rules set in CLI arguments. For example, running this command:
```sh
oxlint -A correctness -c oxlintrc.json
```
With this config file
```jsonc
// oxlintrc.json
{
  "rules": {
    "no-const-assign": "error"
  }
}
```
Would result in a single rule, `no-const-assign` being turned on at an error level with all other rules disabled (i.e. set to "allow").

Now, **CLI arguments will override config files**. That same command with the same config file will result with **all rules being disabled**.

## Details

For a more in-depth explanation, assume we are running the below command using the `oxlintrc.json` file above:
```sh
oxlint -A all -W correctness -A all -W suspicious -c oxlintrc.json
```

### Before
> Note: GitHub doesn't seem to like deeply nested lists. Apologies for the formatting.

Here was the config resolution process _before_ this PR:
<details><summary>Before Steps</summary>

1. Start with a default set of filters (["correctness", "warn"]) if no filters were passed to the CLI. Since some were, the filter list starts out empty.
2. Apply each filter taken from the CLI from left to right. When a filter allows a rule or category, it clears the configured set of rules. So applying those filters looks like this
  a. start with an empty list `[]`
  b. `("all", "allow")` -> `[]`
  c. `("correctness", "warn")` -> `[ <correctness rules> ]`
  d. `("all", "allow")` -> `[]`
  e. `("suspicious", "warn")` -> `[ <suspicious rules> ]`. This is the final rule set for this step
3. Apply overrides from `oxlintrc.json`. This is where things get a little funky, as mentioned in point 2 of what this PR does. At this point, all rules in the rules list are only from the CLI.
  a. If a rule is only set in the CLI and is not present in the config file, there's no effect
  b. If a rule is in the config file but not the CLI, it gets inserted into the list.
  c. If a rule is already in the list and in the config file
    i. If the rule is only present once (e.g. `"no-loss-of-precision": "error"`), unconditionally override whatever was in the CLI with what was set in the config file
    ii. If the rule is present twice (e.g. `"no-loss-of-precision": "off", "@typescript-eslint/no-loss-of-precision": "error"`),
      a. if all rules in the config file are set to `allow`, then turn the rule off
      b. If one of them is `warn` or `deny`, then update the currently-set rule's config object, but _leave its severity alone_.

  So, for our example, the final rule set would be `[<all suspicious rules: "warn">, no-const-assign: "error"]`

</details>

### After
Rule filters were completely re-worked in a previous PR. Now, lint filters aren't kept on hand-only the rule list is.

<details><summary>After Steps</summary>

1. Start with the default rule set, which is all correctness rules for all enabled plugins (`[<all correctness rules: "warn">]`)
2. Apply configuration from `oxlintrc.json` _first_.
  a. If the rule is warn/deny exists in the list already, update its severity and config object. If it's not in the list, add it.
  b. If the rule is set to allow, remove it from the list.

  The list is now `[<all correctness rules except no-const-assign: "warn">, no-const-assign: "error"]`.

3. Apply each filter taken from the CLI from left to right. This works the same way as before. So, after they're applied, the list is now `[<suspicous rules: "warn">]`

</details>
2024-10-10 19:21:50 +00:00
Radu Baston
454874a42d
feat(linter): Implement react/iframe-missing-sandbox (#6383)
https://github.com/oxc-project/oxc/issues/1022

---------

Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-10-10 15:17:29 -04:00
camc314
a9544ae3eb feat(minifier): partially implement minification for some known string methods (#6424)
- implements minification for `toLowerCase`, `toUpperCase` and `trim`
2024-10-10 15:23:03 +00:00
Boshen
6a194f9086 docs(span): document validity of ModuleKind::Unambiguous (#6423)
relates #6249
2024-10-10 14:59:41 +00:00
leaysgur
b5b0af98cb feat(regular_expression): Support RegExp Modifiers (#6410)
Fixes #6354
2024-10-10 14:46:17 +00:00