Commit graph

4864 commits

Author SHA1 Message Date
DonIsaac
48821c0110 feat(semantic,syntax): add SymbolFlags::ArrowFunction (#4946)
There are many cases in lint rules where we want to see if a symbol is a
function by checking its SymbolFlags. This is currently not fully possible,
since variables assigned to arrow functions are not distinguished from any other
kind of variable. This PR adds `SymbolFlags::ArrowFunction` for variables that
are initialized to arrow functions. Symbols that are re-assigned to arrow
functions will not have this flag, but this is acceptable for lint rules.
2024-08-18 05:54:23 +00:00
camc314
915cb4d5a3 feat(linter): add dangerous fixer for oxc only used in recursion (#4805) 2024-08-18 01:19:37 +00:00
Don Isaac
4cb8c3771f
refactor(linter): move default_true to utils (#4947) 2024-08-17 14:09:58 -04:00
Boshen
873d502993
refactor(coverage): use the oxc crate 2024-08-17 22:40:08 +08:00
Boshen
bbf9ec0774 fix(codegen): add missing declare to PropertyDefinition (#4937)
I'm seeing a broken test for

```rust
    #[test]
    fn dts_class_decl_prop_test() {
        transform_dts_test(
            "export class Foo { declare a: string }",
            "export declare class Foo {
  a: string;
}",
        );
    }
```

can you double check @Dunqing ?
2024-08-17 14:26:24 +00:00
Boshen
bea76f0f24
fix(coverage): fix babel cases 2024-08-17 11:22:00 +08:00
Boshen
81439403fd chore(coverage): print path relative to snapshot file (#4938)
Ctrl + click in terminal can open the file with this change.

I don't know about vscode, but maybe a plugin can help?

<img width="1399" alt="image" src="https://github.com/user-attachments/assets/9bb4609b-14e9-4df8-b5ee-cb96b72b2f7d">

<img width="1131" alt="image" src="https://github.com/user-attachments/assets/e0293693-f755-4b91-8712-bbd2a0e615cc">
2024-08-17 03:09:25 +00:00
Dunqing
fd34640d65 feat(traverse): support generate_uid_based_on_node method in TraverseCtx (#4940)
close: #4906

Port completely  `gatherNodeParts` from `Babel`. But we don't have test cases to test it, we can find the bugs(if any) after we use this API in transformer plugins
2024-08-17 02:50:23 +00:00
DonIsaac
3f28c77eb6 feat(linter/eslint): improve no-dupe-keys (#4943)
- make labels in diagnostics more user-friendly
- improve examples in documentation
2024-08-17 01:25:26 +00:00
DonIsaac
e1582a5dd3 feat(linter/eslint): improve no-duplicate-case rule (#4942)
- ignore parethesis when comparing case test expressions
- make labels in diagnostics more friendly
- add more examples to documentation
2024-08-17 01:21:49 +00:00
Don Isaac
e99836d7d8
fix(linter/unicorn): allow set spreading in no-useless-spread (#4944)
Closes #4872
2024-08-16 16:33:18 -04:00
Boshen
4c989d0fda
chore(parser): remove multi-thread example
because `ouroboros` has a few heavy dependencies, including an older
version of itertools.
2024-08-16 22:57:10 +08:00
Dunqing
d3bbc620cc
fix(isolated-declarations): declare modifier of PropertyDefinition should not be retained (#4941)
related: #4937

There are no tests/snapshots updates and seems we don't have a way to
test it until #4937 is merged. But I tested it locally and it worked!
2024-08-16 22:11:43 +08:00
michaelm
8e80f593fd
fix(isolated_declarations): Class properties should still be lifted from private constructors (#4934)
Before, this
```ts
export class Bux {
  private constructor(
    public readonly prop: number = 0,
    private readonly prop2: number = 1,
    readonly prop3: number = 1,
  ) {}
}
```
would be emitted as 
```ts
export declare class Bux {
	private constructor();
}
```

Now it will be emitted as
```ts
export declare class Bux {
	readonly prop: number;
	private readonly prop2;
	readonly prop3: number;
	private constructor();
}
```

Co-authored-by: MichaelMitchell-at <=>
2024-08-16 21:43:44 +08:00
Boshen
7ecf0efd40
chore(coverage): remove arrow functions plugin from semantic check 2024-08-16 19:12:17 +08:00
Boshen
f210cf7873 fix(codegen): print TSSatisfiesExpression and TSInstantiationExpression (#4936)
I can't figure out the precedence so printing extra parentheses instead ...
2024-08-16 09:53:17 +00:00
Boshen
61cdfef5c7
chore(coverage): remove quotes around path from snapshot files
to make it easier to triple click and copy the path
2024-08-16 16:03:50 +08:00
Boshen
c220730779 feat(coverage): check symbols and scopes after transformation (#4917)
closes https://github.com/oxc-project/oxc/issues/4790

@overlookmotel enjoy ... take a look at the snapshots and probably nothing else.

The snapshots are minimal right now, but it's already showing symbols from import specifiers are not being removed. We can iterate on the snapshot representation to aid debugging later.

I'll extend this to `transformer_conformance` and `oxc-monitor` in an up coming PR.
2024-08-16 07:05:11 +00:00
Boshen
46cb1c1b7b fix(minifier): handle Object.definedPropert(exports for @babel/types/lib/index.js (#4933)
Discoverd in `monitor-oxc`

```javascript
Object.keys(_index6).forEach(function(key) {
	if (key === "default" || key === "__esModule") return;
	if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
	if (key in exports && exports[key] === _index6[key]) return;
	Object.defineProperty(exports, key, {
		enumerable: true,
		get: function() {
			return _index6[key];
		}
	});
});
```

🙃
2024-08-16 06:48:15 +00:00
Dunqing
248a757b34 fix(transformer/typescript): typescript syntax within SimpleAssignmentTarget with MemberExpressions is not stripped (#4920)
close: #4870

I added the `move_identifier_reference` and `move_member_expression` methods used to take ownership in `ast_builder_impl`.  This way can let us get rid of `ast.copy`.

Another possible approach is to add `get_expression_owner` to `SimpleAssignmentTarget` and a `get_inner_expression_owner` method to `Expression`. And add an `into_xxxxx` method for `inherit_variants` macro

The implementation looks like this
```rs
let Some(expression) = self.get_expression_owner() else { return; }
match expr.get_inner_expression_owner() {
    Expression::Identifier(ident) => {
        *target = self.ctx.ast.simple_assignment_target_from_identifier_reference(ident);
    }
    inner_expr @ match_member_expression!(Expression) => {
        *target = SimpleAssignmentTarget::from(
            inner_expr.into_member_expression()
        );
    }
    _ => (),
}
```
2024-08-16 05:05:10 +00:00
mysteryven
508644a34e fix(linter/tree-shaking): correct the calculation of >>, << and >>> (#4932)
fixes: #4914
2024-08-16 02:33:48 +00:00
DonIsaac
80d0d1f0c4 feat(semantic): check for invalid interface heritage clauses (#4928) 2024-08-16 02:30:09 +00:00
Burlin
9c64b12963
fix(linter): improve no-zero-fractions rule for member expressions and scientific notation (#4793) 2024-08-15 21:24:08 -04:00
rzvxa
a0b1b86161 fix(ci): Return an error code on the failed AST Changes step. (#4930)
Closes #4929
2024-08-16 00:29:06 +00:00
Don Isaac
4081293ce7
fix(linter/no-unused-vars): panic in fixer when removing destructures (#4923)
Closes #4839
2024-08-15 17:30:33 -04:00
Don Isaac
c21d735c3d
test(linter/no-unused-vars): add ignored destructuring test cases (#4922)
Add test cases that cover #4888. I can't reproduce the issue this way,
so I'll try running oxlint as a CLI instead. These test cases will be
useful to have in our repo anyways.
2024-08-15 17:03:08 -04:00
Dunqing
f1fcdde593 feat(transformer): support react fast refresh (#4587)
close: #3943

## Further improvements

There is a double visit here. We need to collect all react hooks calling in `Function` and `ArrowFunctionExpression`. If we want to remove this implementation, we may wait for #4188.

d797e595d2/crates/oxc_transformer/src/react/refresh.rs (L744-L947)

## Tests

All tests copy from https://github.com/facebook/react/blob/main/packages/react-refresh/src/__tests__/ReactFresh-test.js

There are still 4 tests that have not been passed

**1. refresh/can-handle-implicit-arrow-returns/input.jsx**

Related to #4767. transform correct, just output doesn't match the expected output

**2. refresh/registers-identifiers-used-in-jsx-at-definition-site/input.jsx**
**3. refresh/registers-identifiers-used-in-react-create-element-at-definition-site/input.jsx**

Blocked by #4746

**4. refresh/supports-typescript-namespace-syntax/input.tsx**

oxc transforms ts to js first, so probably we can ignore this case. If we really want to pass this test, we also need to turn off `TypeScript` plugin.

## What's next?

### Options:

1. Support transform `refresh_reg` and `refresh_sig` options to `MemberExpression`. Currently `import.meta.xxxx` still is an `Identifier`
2. Support `emit_full_signatures` option

### Other
NAPI, testing in `monitor-oxc`, etc..
2024-08-15 16:41:30 +00:00
michaelm
b3ec9e50bd
fix(isolated_declarations): Always emit module declarations that perform augmentation (#4919)
Fixes https://github.com/oxc-project/oxc/issues/4607

Co-authored-by: MichaelMitchell-at <=>
2024-08-16 00:39:28 +08:00
overlookmotel
1eb59d2b5e refactor(ast, isolated_declarations, transformer): mark AstBuilder::copy as an unsafe function (#4907)
`AstBuilder::copy` is completely unsound (#3483), and we need to remove it. Make it an `unsafe` function to discourage any further usage of it in meantime.
2024-08-15 16:22:43 +01:00
Dunqing
46fb3cbb3e Revert "fix(isolated_declarations): Always emit module declarations (#4911)" (#4916)
This reverts commit 0fb0b71f0d.

test failed  https://github.com/oxc-project/oxc/actions/runs/10405198969/job/28815418191

We should only emit for
```ts
declare module "xx" {}
declare global {}
```

Do not emit for
```ts
module x {}
declare module x {}
```

@MichaelMitchell-at cc
2024-08-15 14:48:28 +00:00
michaelm
0fb0b71f0d
fix(isolated_declarations): Always emit module declarations (#4911)
Fixes https://github.com/oxc-project/oxc/issues/4607

Co-authored-by: MichaelMitchell-at <=>
2024-08-15 22:13:32 +08:00
michaelm
4a16916887
fix(isolated_declarations): Support expando functions (#4910)
I mentioned this issue in a
https://github.com/oxc-project/oxc/issues/4607#issuecomment-2264863618
but I later realized this is actually a separate issue from the one that
I originally reported.

It seems that https://github.com/oxc-project/oxc/pull/3872 added support
for reporting expando function errors, but didn't add support for cases
where expando functions are allowed. This PR adds support for not
reporting errors when there is a namespace declaration that declares the
variable being assigned to.

[TypeScript
playground](https://www.typescriptlang.org/play/?noCheck=true&isolatedDeclarations=true&ts=5.5.4#code/KYDwDg9gTgLgBAMwK4DsDGMCWEWIhACgEoAuOANwkwBM4BvAXwCgF8A6AQzDABsBPOAF44xIQD56zJqEiw4aHAGd4AIw5QhI0hSq1BExkzVQ2aDjx6bR+yUzszo8FBwC2wRWA5pgcAHIBleiY4OAc5BRRlOABzfCttShpxWxDYiDYeYBRomAALTQBGAAYmKTCnV3dPbzwIIJDM1XVNABYAJgBuYNDwRzhGuDUAL0Kioq6pVnTjVs6WdmHR8bsAehW4VHLgaiYIqKG44WIyRL0DZgP0mAh-GChMbPjkxiA)
for reference

---------

Co-authored-by: MichaelMitchell-at <=>
2024-08-15 22:12:16 +08:00
overlookmotel
2476dceee0 fix(transformer): remove an ast.copy from NullishCoalescingOperator transform (#4913)
Remove one unnecessary `ast.copy` call from `NullishCoalescingOperator` transform (towards #3483).
2024-08-15 13:21:48 +00:00
Dunqing
72a37fc02a feat(traverse): support clone_identifier_reference method in TraverseCtx (#4880)
related: #4804

needs from: #4876

The `clone_identifier_reference` method is used to clone an `IdentifierReference` and create a `Reference` and insert it to `SymbolTable`'s `resolved_references`.

The reason we need this is because we need to make sure that `IdentifierReference`'s `reference_id` is unique
2024-08-15 12:02:47 +00:00
rzvxa
47c9552ecf docs(ast, ast_macros, ast_tools): better documentation for Ast helper attributes. (#4856) 2024-08-15 11:32:36 +00:00
overlookmotel
90d0b2ba65 refactor(allocator, ast, span, ast_tools): use allocator as var name for Allocator (#4900)
We mostly use `allocator` as var name for an `Allocator`, but in some places used the shorter name `alloc`. Use `allocator` everywhere for consistency.
2024-08-15 10:49:11 +00:00
Dunqing
0d7912217a feat(transformer): support logical-assignment-operators plugin (#4890)
part of #4754

The implementation copy from the original implementation which removed in https://github.com/oxc-project/oxc/pull/2865.
2024-08-15 10:10:36 +00:00
Dunqing
ab1d08ccfb feat(transformer): support optional-catch-binding plugin (#4885)
part of #4754

The implementation copy from the original implementation which removed in https://github.com/oxc-project/oxc/pull/2865.
2024-08-15 10:10:34 +00:00
Dunqing
69da9fda3a feat(transformer): support nullish-coalescing-operator plugin (#4884)
The implementation copy from the original implementation which removed in https://github.com/oxc-project/oxc/pull/2865.
2024-08-15 10:10:33 +00:00
Dunqing
3a66e5843d feat(transformer): support exponentiation operator plugin (#4876)
The implementation copy from the original implementation which removed in https://github.com/oxc-project/oxc/pull/2865.
2024-08-15 10:10:32 +00:00
oxc-bot
b3e189764f
Release oxlint v0.7.2 (#4909)
## [0.7.2] - 2024-08-15

### Features

- 97e38cd linter: Add fixer for unicorn/prefer-optional-catch-binding
(#4867) (heygsc)
- 93ae1c7 linter: Eslint-plugin-react jsx-props-no-spread-multi (#4866)
(keita hino)
- 0a23610 linter: Add fixer for unicorn/prefer-array-flat-map (#4844)
(heygsc)
- 13c7b1b linter/jsx-a11y: Add fixer for aria-unsupported-elements
(#4854) (DonIsaac)
- a6195a6 linter/jsx-a11y: Add fixer for anchor-has-content (#4852)
(DonIsaac)
- 4d28d03 task/website: Support render `subschemas.all_of` (#4800)
(mysteryven)

### Bug Fixes

- 21f5762 codegen: Minify large numbers (#4889) (Boshen)
- a08d7a7 linter/jsx-a11y: Reduce false negatives for html-has-lang
(#4855) (DonIsaac)
- a81ce3a linter/no-unused-vars: Do not delete function expressions when
fixing (#4848) (DonIsaac)

### Documentation

- 955a4b4 oxlint: Improve cli doc regarding fix and `-D all` (Boshen)

### Refactor

- 56f033c linter: Improve diagnostics for several jsx-a11y rules (#4853)
(DonIsaac)
- c53c210 linter/no-unused-vars: Split fixer logic into multiple files
(#4847) (DonIsaac)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-08-15 14:56:34 +08:00
Boshen
5b14608a95
chore(tasks/website): do not run textlint nor prettier 2024-08-15 14:28:57 +08:00
Boshen
34aa93bda3 feat(coverage): add checker for correctness of semantic data (#4908)
Part of https://github.com/oxc-project/oxc/issues/4790
2024-08-15 04:46:07 +00:00
IWANABETHATGUY
d49fb160e3 feat(oxc_codegen): support generate range leading comments (#4898)
1. Support print range leading comments for specific expr or stmt
2024-08-15 04:20:48 +00:00
overlookmotel
9c700ed509
docs(transformer): add README including style guide (#4899)
Add a README to `oxc_transformer` crate, including a "style guide" for
writing transforms. As discussed in #4881.
2024-08-15 10:52:14 +08:00
overlookmotel
f88cbcd4ab feat(transformer): add BoundIdentifier::new_uid_in_current_scope method (#4903)
Add method `BoundIdentifier::new_uid_in_current_scope` as a shortcut.
2024-08-14 18:55:27 +00:00
overlookmotel
786bf07e45 refactor(index): shorten code and correct comment (#4905)
Style nit + comment correction. Plain `Box` is used everywhere else in this file, no need to fully specify `alloc::boxed::Box`.
2024-08-14 17:55:25 +00:00
overlookmotel
a6967b30f3 refactor(allocator): correct code comment (#4904)
Correct code comment in `Box::unbox`.
2024-08-14 17:44:54 +00:00
overlookmotel
452187a3ca refactor(transformer): rename BoundIdentifier::new_uid_in_root_scope (#4902)
Just renaming the method.
2024-08-14 17:37:25 +00:00
overlookmotel
1e6d0fe7dd
feat(transformer): add methods to BoundIdentifier (#4897)
`BoundIdentifier` helper previously only had methods to create a
read-only `IdentifierReference`. Add methods to also create write-only
or read-write `IdentifierReference`s.
2024-08-15 00:12:20 +08:00