Commit graph

3184 commits

Author SHA1 Message Date
Boshen
60ccbb105c
refactor(transformer): clean up some code (#2949) 2024-04-12 20:23:44 +08:00
Boshen
14754777a4
feat(transformer): implement react-jsx-source (#2948) 2024-04-12 20:21:54 +08:00
Boshen
b05c26374c
ci: fix codecov stack overflow by increasing the stack size
The underlying cause is oxc_prettier recursively printing assignment expressions.
2024-04-12 20:17:53 +08:00
branchseer
f159f60084
Make ast types covariant over the allocator lifetime. (#2943)
## Why

Due to the usage of `&'alloc mut T` in `oxc_allocator::Box`, and
`bumpalo::collections::Vec` in `oxc_allocator::Vec`, ast types are
currently invariant over their allocator lifetime `'a`. This prevents
`ouroboros` from generating `borrow_*` on ast type fields, leading to
the unfriendly `with_*` api:
c250b288ef/crates/oxc_parser/examples/multi-thread.rs (L82-L84)

## How

- For `oxc_allocator::Vec`, switch to `allocator_api2::vec::Vec`, which
has a covariant relationship with the allocator lifetime.
- For `oxc_allocator::Box`, use `std::ptr::NonNull` which is
specifically designed to be covariant. I don't use
`allocator_api2::boxed::Box` because it holds the allocator for
dropping, so the size is bigger.

## Downside

Now that `oxc_allocator::Box` uses the unsafe `NonNull`. It has to be a
private field to be safe. This make it impossible to do `Box(....)`
pattern matching.
2024-04-12 18:12:18 +08:00
Boshen
f903a225a8
feat(transformer): implement react-jsx-self (#2946) 2024-04-12 18:08:36 +08:00
Yuji Sugiura
ba2121f17d
feat(linter): Add --jsdoc-plugin flag (#2935)
Add flag to:

```sh
$ oxlint --jsdoc-plugin
```


![image](https://github.com/oxc-project/oxc/assets/6259812/0e12ceab-966f-47e1-b4b9-5bc2eb6bdb56)
2024-04-12 10:39:12 +08:00
Boshen
0c04bf743f
feat(transformer): transform TypeScript namespace (#2942) 2024-04-12 10:19:13 +08:00
Boshen
c250b288ef
fix(cli): return error if --format receives an unknown value 2024-04-11 21:38:39 +08:00
Boshen
f3a28c61b9
chore(transform_conformance): enable typescript plugin snapshot 2024-04-11 20:06:53 +08:00
Boshen
3419306ac0
feat(transformer): add filename (#2941) 2024-04-11 18:43:51 +08:00
Boshen
df11d10a22
Release oxlint and vscode extension v0.2.17 2024-04-11 16:27:56 +08:00
Boshen
614f73b66c
Release crates v0.12.3 2024-04-11 16:18:17 +08:00
Boshen
ced0721b3b
ci: cache codecov; enable code coverage for oxc_transformer 2024-04-11 16:16:02 +08:00
Boshen
98bf7e6767
fix(cli): fix oxlint --format json yields 0 files to lint (#2940)
closes #2930
2024-04-11 16:03:31 +08:00
Boshen
02adc76760
feat(transformer): implement plugin-transform-react-display-name top-down (#2937)
Missing case:


https://github.com/babel/babel/blob/main/packages/babel-plugin-transform-react-display-name/test/fixtures/display-name/nested/input.js

```js
var foo = qux(createReactClass({}));
var bar = qux(React.createClass({}));
```

This requires recursing down.

Top-down implementation in swc:


67ec5e09b9/crates/swc_ecma_transforms_react/src/display_name/mod.rs (L108-L132)

Or bottom-up in babel:


08b0472069/packages/babel-plugin-transform-react-display-name/src/index.ts (L87-L98)
2024-04-11 15:32:32 +08:00
Boshen
59748199da
refactor(ast): clean up the ts type visit methods 2024-04-11 15:26:24 +08:00
Boshen
88270fe605
chore(benchmark): use a larger file for sourcemap benchmark 2024-04-11 15:11:26 +08:00
Brad Zacher
6c0090882f
feat(oxc_ast): add missing ast visits for types (#2938)
Fixes #2936

*personally* I think it's best if all of the `_ => {}` match cases were
removed from the codebase so that things are provably exhaustive.
This does exactly that specifically for `walk_ts_type` - filling in the
missing cases and all the required code for them.
2024-04-11 07:11:00 +00:00
Boshen
07bd85e25d
chore(transform_conformance): clear the conformance snapshot 2024-04-11 14:09:59 +08:00
cinchen
6757dbab8a
feat(linter): eslint-plugin-jest/prefer-lowercase-title (#2911)
part of https://github.com/oxc-project/oxc/issues/492

Rule Detail:
[link](https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/prefer-lowercase-title.ts)
2024-04-10 21:56:56 +08:00
Todor Andonov
b4b471f4cf
feat(linter): typescript-eslint/consistent-type-definitions (#2885)
Co-authored-by: wenzhe <mysteryven@gmail.com>
2024-04-10 21:09:05 +08:00
Boshen
255c74ccc5
feat(transformer): add transform context to all plugins (#2931) 2024-04-10 14:49:00 +08:00
Yuji Sugiura
0a77d621e2
refactor(semantic/jsdoc): Rework JSDoc struct for better Span handling (#2917)
> The error message emphasizes "empty text" so I would put the span on
the extra text.
> https://github.com/oxc-project/oxc/pull/2893#discussion_r1548843621

To address this, special `Span` handling should be implemented for
comment part.

So, this PR introduces:

- `JSDocCommentPart` struct holds raw `.span` and special
`.span_trimmed_first_line()`
- Add `JSDocKindPart`, `JSDocTypePart` and `JSDocTypeNamePart` in the
same manner
  - `JSDocTag` uses these depending on the purpose
2024-04-10 14:32:51 +08:00
Boshen
79ca6feca9
feat(transformer): add transform callback methods (#2929)
For milestone 1, I think it's safe to just layout all the
transformations manually.


In TypeScript, the transformers are collected dynamically and ran on
each ast node; this achieves a single AST pass.
https://github.com/microsoft/TypeScript/blob/main/src/compiler/transformer.ts#L129-L145

To maximize performance and reduce confusion, I think it's safe to
layout all the transformations manually for milestone 1.

The next PR will add transformation context to all presets so we can
start adding "context".
2024-04-10 11:06:49 +08:00
underfin
8662f4f613
feat(sourcemap): add x_google_ignoreList (#2928) 2024-04-09 20:55:04 +08:00
underfin
5cb3991b67
feat(sourcemap): add sourceRoot (#2926) 2024-04-09 15:42:23 +08:00
Boshen
3e5530805d
Update issue templates 2024-04-09 14:54:46 +08:00
Boshen
0bada0bc93
Update issue templates (#2927) 2024-04-09 14:52:49 +08:00
Kalven Schraut
6eba02f472
fix(cli): if format is json do not print summary information (#2899) (#2925)
this allows the ability to redirect the stdout to so can create a valid
json file

this also matches with eslint's format option

closes #2899
2024-04-09 14:26:10 +08:00
Boshen
d65eab3b8b
feat(transformer): add react preset (#2921) 2024-04-09 12:39:33 +08:00
John Daly
5abbb0cada
fix(linter): import/no-cycle ignore type-only imports (#2924)
A fix for the work done in: https://github.com/oxc-project/oxc/pull/2905

The existing code checks if _all_ import entries in a ModuleRecord are
type-only, when determining if the ModuleRecord should be skipped when
checking for cycles. This is incorrect.

To demonstrate the problem: Running the `no-cycles` rule, with
`ignoreTypes` enabled, on the following example code will cause a cycle
to be reported between Module A and Module B

```typescript
// Module A
import type { Bar } from './b';
import { Baz } from './c'

// Module B
import type { Foo } from './a';

// Module C
export const Baz = 'baz';
```

The reason this is happening is because the import to Module C in Module
A is causing the `was_imported_as_type` variable to evaluate to `false`,
since the Module C import is not type-only.

What we actually want to do is skip visiting Module B entirely, by
checking if its import request from Module A is type-only.

This PR fixes the logic so that only the import entries for the next
ModuleRecord are considered when determining `was_imported_as_type`.
2024-04-09 12:38:15 +08:00
Wang Wenzhe
990eda61d7
feat(linter/tree-shaking): support part BinaryExpression (#2922) 2024-04-09 12:33:51 +08:00
Boshen
659e891615
ci: skip benchmark-napi because it is flaky (#2918)
The flakiness and all the noise produced by it is starting to hurt
maintenance because I can no longer tell if main or PR is failing
properly :-(

codspeed doesn't have the feature "let it run but don't report as error"
or "different thresholds on different benchmarks"
2024-04-08 19:21:57 +08:00
Boshen
79837bd410
Release @oxc-parser/wasm v0.1.0 2024-04-08 15:47:51 +08:00
Boshen
ab26099281
Publish @oxc-parser/wasm with web and node builds (#2916)
Co-authored-by: Saeid Zareie <saeid.za98@gmail.com>
2024-04-08 15:47:02 +08:00
Boshen
d43d404d61
fix: update lock file 2024-04-08 11:17:26 +08:00
Boshen
09452659e2
Release crates v0.12.2 2024-04-08 11:13:13 +08:00
Boshen
7066d55153
Release oxlint and vscode extension v0.2.16 2024-04-08 11:03:41 +08:00
renovate[bot]
cd6f4f1938
chore(deps): lock file maintenance rust crates (#2913) 2024-04-08 02:49:53 +00:00
renovate[bot]
1847329b43
chore(deps): lock file maintenance vscode npm packages (#2914) 2024-04-08 10:27:00 +08:00
Yuji Sugiura
a0fe504869
fix(tasks/lint_rules): Fix plugin-jest rules collector (#2915)
Fixes umbrella issue for
[`plugin-jest`](https://github.com/oxc-project/oxc/issues/492) to render
recommended rules section properly.

- - -

Along with sticking legacy ESLint.
Since `eslint@latest` is now v9 and it removed `Linter#defineRule()` and
`Linter#getRules()` which we use heavily...
2024-04-08 10:22:56 +08:00
underfin
96f02e6e21
feat(sourcemap): optional JSONSourceMap fileds (#2910)
Support optional JSONSourceMap fileds to support js side complex typing.
2024-04-07 23:32:12 +08:00
underfin
d87cf179a6
feat(sourcemap): add methods to mutate SourceMap (#2909) 2024-04-07 23:30:16 +08:00
underfin
74aca1c937
feat(sourcemap): add SourceMapBuilder file (#2908) 2024-04-07 23:29:25 +08:00
John Daly
6de1b77b1b
feat(linter/import): Add ignoreTypes option for the import/no-cycle rule (#2905)
Fixes: https://github.com/oxc-project/oxc/issues/2904

Adds an `ignoreTypes` option for the `import/no-cycle` rule, to ignore
imports that don't have any runtime effect.
2024-04-07 05:07:45 +00:00
Kalven Schraut
79e2c95e2d
fix(linter): handle self closing script tags in astro partial loader (#2017) (#2907)
Added tests to figure out what the problem from the issue was and
realize the self closing tag was not expected. Added code to handle this
case.

I am not that familiar with astro to know how common self closing script
tags are, their docs seem to use an opening and closing one for inline
scripts
https://docs.astro.build/en/guides/client-side-scripts/#load-external-scripts
2024-04-07 13:02:09 +08:00
Kalven Schraut
1cd5e7511b
fix(linter): svelte partial loader handle generics (#2875) (#2906)
While looking into this, I knew vue would have similar problems. Which
then led me to realize the generic case was handled already so I tried
abstract out the function so both the vue and svelte partial loaders
could reuse the code. Finally added some svelte test cases to prove this
resolved the issue.

I am a bit new to rust so if there was a better way to reuse the
find_script_closing_angle function open to suggestions.
2024-04-07 13:00:55 +08:00
Wang Wenzhe
65f38dc0db
fix(tasks/rulegen): read quasi in TaggedTemplateExpression (#2903) 2024-04-07 10:41:14 +08:00
Wang Wenzhe
b053d54b6f
feat(linter/tree-shaking): support try-catch and AwaitExpression (#2902) 2024-04-06 14:02:42 +08:00
Wang Wenzhe
59869d0a96
feat(linter/tree-shaking): check this in different environment (#2901) 2024-04-06 13:58:47 +08:00