Alexander S.
fe25b651bd
feat(prettier): indent for class definition ( #6059 )
...
trying to match the output for:
5b868377c0/tests/format/typescript/classes/__snapshots__/format.test.js.snap (L3-L92)
<details><summary>main branch output:</summary>
```typescript
class MyContractSelectionWidget extends React.Component<void, MyContractSelectionWidgetPropsType, void> implements SomethingLarge {
method() {}
}
class DisplayObject1 extends utils.EventEmitter implements interaction_InteractiveTarget {}
class DisplayObject2 extends utils.EventEmitter implements interaction_InteractiveTarget {}
class DisplayObject3 extends utils.EventEmitter implements interaction_InteractiveTarget, somethingElse_SomeOtherThing, somethingElseAgain_RunningOutOfNames {}
class DisplayObject4 extends utils.EventEmitter implements interaction_InteractiveTarget {}
class Readable extends events.EventEmitter implements NodeJS_ReadableStream {}
class InMemoryAppender extends log4javascript.Appender implements ICachedLogMessageProvider {}
class Foo extends Immutable.Record({
ipaddress: "",
}) {
ipaddress: string;
}
export class VisTimelineComponent implements AfterViewInit, OnChanges, OnDestroy {}
export class VisTimelineComponent2 implements AfterViewInit, OnChanges, OnDestroy, AndSomethingReallyReallyLong {}
```
</details>
<details><summary>this branch output:</summary>
```typescript
class MyContractSelectionWidget
extends React.Component<void, MyContractSelectionWidgetPropsType, void>
implements SomethingLarge
{
method() {}
}
class DisplayObject1
extends utils.EventEmitter
implements interaction_InteractiveTarget {}
class DisplayObject2
extends utils.EventEmitter
implements interaction_InteractiveTarget {}
class DisplayObject3
extends utils.EventEmitter
implements
interaction_InteractiveTarget,
somethingElse_SomeOtherThing,
somethingElseAgain_RunningOutOfNames {}
class DisplayObject4
extends utils.EventEmitter
implements interaction_InteractiveTarget {}
class Readable
extends events.EventEmitter
implements NodeJS_ReadableStream {}
class InMemoryAppender
extends log4javascript.Appender
implements ICachedLogMessageProvider {}
class Foo extends Immutable.Record({
ipaddress: "",
}) {
ipaddress: string;
}
export class VisTimelineComponent
implements AfterViewInit, OnChanges, OnDestroy {}
export class VisTimelineComponent2
implements
AfterViewInit,
OnChanges,
OnDestroy,
AndSomethingReallyReallyLong {}
```
</details>
Sadly I can't fix the `class Readable` line :/
2024-10-06 22:23:24 +08:00
Boshen
abd3a9fe11
feat(napi/transform): perform dce after define plugin ( #6312 )
2024-10-06 09:49:52 +00:00
overlookmotel
642725cd7d
refactor(linter): rename vars from ast_node_id to node_id ( #6305 )
...
Style nit. We renamed `AstNodeId` to `NodeId`, so rename vars from `ast_node_id` to `node_id` too.
2024-10-06 08:35:51 +00:00
Boshen
020bb80b65
refactor(codegen)!: change to CodegenReturn::code and CodegenReturn::map ( #6310 )
2024-10-06 05:05:47 +00:00
Boshen
a0ccc26c12
feat(napi/transform): add lang option to change source type ( #6309 )
...
part of #6274 and #6156
```
/// Treat the source text as `js`, `jsx`, `ts`, or `tsx`.
#[napi(ts_type = "'js' | 'jsx' | 'ts' | 'tsx'")]
pub lang: Option<String>,
```
2024-10-06 04:53:47 +00:00
Boshen
5b5daec392
refactor(napi): use vitest ( #6307 )
2024-10-06 02:57:48 +00:00
Boshen
58a8615747
refactor(napi/transform): remove context ( #6306 )
2024-10-06 01:57:49 +00:00
overlookmotel
bdd9e925f1
refactor(semantic): rename vars from ast_node_id to node_id ( #6304 )
...
Style nit. We renamed `AstNodeId` to `NodeId`, so rename vars from `ast_node_id` to `node_id` too.
2024-10-06 01:03:48 +00:00
overlookmotel
d11070051b
refactor(semantic): dereference IDs as quickly as possible ( #6303 )
...
It's better to pass around `SymbolId`s (4 bytes) than `&SymbolId`s (8 bytes). In my view, the style of dereferencing immediately is preferable.
2024-10-06 01:03:47 +00:00
overlookmotel
56d50cf92c
fix(transformer): exponentiation transform: do not assume Math is not a local var ( #6302 )
...
`Math` is hopefully a global var (and transform will be incorrect if it isn't), but make sure scope tree is correct either way.
2024-10-06 00:51:29 +00:00
overlookmotel
15cc8afd2e
refactor(transformer): exponentiation transform: break up into functions ( #6301 )
...
Pure refactor.
2024-10-06 00:51:28 +00:00
overlookmotel
bd81c5134c
fix(transformer): exponentiation transform: fix duplicate symbols ( #6300 )
...
Identifier was being cloned unnecessarily, creating an extra symbol.
2024-10-06 00:51:28 +00:00
overlookmotel
7f5a94b902
refactor(transformer): use Option::get_or_insert_with ( #6299 )
...
`Option::get_or_insert_with` is designed for use case where you want to fill an `Option` if it's `None`, and get the contents either way. Use it in transformer where borrow checker allows.
2024-10-06 00:51:27 +00:00
dalaoshu
1a5f293d9b
feat(editors/vscode): update VSCode extention to use project's language server ( #6132 )
...
closes #3426
2024-10-05 20:24:17 -04:00
Boshen
8729755baa
feat(oxc,napi/transform): napi/transform use oxc compiler pipeline ( #6298 )
...
part of #6156
2024-10-05 16:35:09 +00:00
overlookmotel
0cea6e9fa1
refactor(transformer): exponentiation transform: reduce identifier cloning ( #6297 )
...
We already have to look up the reference, so use the `SymbolId` from that reference, rather than looking it up again in `clone_identifier_reference`.
2024-10-05 16:16:29 +00:00
overlookmotel
ac7a3edf31
refactor(transformer): logical assignment transform: reduce identifier cloning ( #6296 )
...
We already have to look up the reference, so use the `SymbolId` from that reference, rather than looking it up again in `clone_identifier_reference`.
2024-10-05 16:00:51 +00:00
overlookmotel
527f7c82ef
refactor(transformer): nullish coalescing transform: no cloning identifier references ( #6295 )
...
`clone_identifier_reference` involves a lookup of `SymbolId`. Use `BoundIdentifier` instead which caches the ID.
2024-10-05 16:00:51 +00:00
overlookmotel
409dffc8ab
refactor(traverse)!: generate_uid return a BoundIdentifier ( #6294 )
...
Closes #5020 .
`TraverseCtx::generate_uid` and associated methods return a `BoundIdentifier`, containing both symbol ID and name. This reduces boilerplate code for the caller and avoids and unnecessary lookup to get the name.
Also add a couple of helper methods to `BoundIdentifier` to reduce boilerplate further.
2024-10-05 16:00:50 +00:00
overlookmotel
7b62966813
refactor(transformer): move BoundIdentifier into oxc_traverse crate ( #6293 )
...
Pure refactor.
2024-10-05 16:00:49 +00:00
no-yan
07196ae0a8
perf(justfile): optimize submodule cloining with shallow fetch ( #6292 )
...
fix #6291 , where `just submodules` takes around 8 minutes to clone
repositories.
This change reduces the clone time from around 8 minutes to 42 seconds
in reported scenario.
<img width="534" alt="image"
src="https://github.com/user-attachments/assets/bf74e412-f1ed-419e-b180-09ed96a8eb67 ">
<details><summary>Command log: time just submodules</summary>
<p>
```
❯ time just submodules
just clone-submodule tasks/coverage/test262 git@github.com:tc39/test262.git d62fa93c8f9ce5e687c0bbaa5d2b59670ab2ff60
cd tasks/coverage/test262 || git init tasks/coverage/test262
bash: 1 行: cd: tasks/coverage/test262: No such file or directory
Initialized empty Git repository in /Users/noyan/ghq/github.com/oxc-project/oxc/tasks/coverage/test262/.git/
cd tasks/coverage/test262 && git remote add origin git@github.com:tc39/test262.git || true
cd tasks/coverage/test262 && git fetch --depth=1 origin d62fa93c8f9ce5e687c0bbaa5d2b59670ab2ff60 && git reset --hard d62fa93c8f9ce5e687c0bbaa5d2b59670ab2ff60
remote: Enumerating objects: 53504, done.
remote: Counting objects: 100% (53504/53504), done.
remote: Compressing objects: 100% (19436/19436), done.
remote: Total 53504 (delta 39436), reused 39428 (delta 33947), pack-reused 0 (from 0)
Receiving objects: 100% (53504/53504), 12.32 MiB | 9.06 MiB/s, done.
Resolving deltas: 100% (39436/39436), done.
From github.com:tc39/test262
* branch d62fa93c8f9ce5e687c0bbaa5d2b59670ab2ff60 -> FETCH_HEAD
Updating files: 100% (51664/51664), done.
HEAD is now at d62fa93c [explicit-resource-management] Complete exception handling
just clone-submodule tasks/coverage/babel git@github.com:babel/babel.git 3bcfee232506a4cebe410f02042fb0f0adeeb0b1
cd tasks/coverage/babel || git init tasks/coverage/babel
bash: 1 行: cd: tasks/coverage/babel: No such file or directory
Initialized empty Git repository in /Users/noyan/ghq/github.com/oxc-project/oxc/tasks/coverage/babel/.git/
cd tasks/coverage/babel && git remote add origin git@github.com:babel/babel.git || true
cd tasks/coverage/babel && git fetch --depth=1 origin 3bcfee232506a4cebe410f02042fb0f0adeeb0b1 && git reset --hard 3bcfee232506a4cebe410f02042fb0f0adeeb0b1
remote: Enumerating objects: 36357, done.
remote: Counting objects: 100% (36357/36357), done.
remote: Compressing objects: 100% (21830/21830), done.
remote: Total 36357 (delta 8527), reused 30780 (delta 7455), pack-reused 0 (from 0)
Receiving objects: 100% (36357/36357), 9.34 MiB | 9.24 MiB/s, done.
Resolving deltas: 100% (8527/8527), done.
From github.com:babel/babel
* branch 3bcfee232506a4cebe410f02042fb0f0adeeb0b1 -> FETCH_HEAD
Updating files: 100% (31735/31735), done.
HEAD is now at 3bcfee23 Fix printing of TS `infer` in compact mode (#16788 )
just clone-submodule tasks/coverage/typescript git@github.com:microsoft/TypeScript.git a709f9899c2a544b6de65a0f2623ecbbe1394eab
cd tasks/coverage/typescript || git init tasks/coverage/typescript
bash: 1 行: cd: tasks/coverage/typescript: No such file or directory
Initialized empty Git repository in /Users/noyan/ghq/github.com/oxc-project/oxc/tasks/coverage/typescript/.git/
cd tasks/coverage/typescript && git remote add origin git@github.com:microsoft/TypeScript.git || true
cd tasks/coverage/typescript && git fetch --depth=1 origin a709f9899c2a544b6de65a0f2623ecbbe1394eab && git reset --hard a709f9899c2a544b6de65a0f2623ecbbe1394eab
remote: Enumerating objects: 69880, done.
remote: Counting objects: 100% (69880/69880), done.
remote: Compressing objects: 100% (52067/52067), done.
remote: Total 69880 (delta 17267), reused 39053 (delta 16227), pack-reused 0 (from 0)
Receiving objects: 100% (69880/69880), 32.80 MiB | 8.54 MiB/s, done.
Resolving deltas: 100% (17267/17267), done.
From github.com:microsoft/TypeScript
* branch a709f9899c2a544b6de65a0f2623ecbbe1394eab -> FETCH_HEAD
Updating files: 100% (72575/72575), done.
HEAD is now at a709f9899 Update deps, dprint plugins (#59810 )
just clone-submodule tasks/prettier_conformance/prettier git@github.com:prettier/prettier.git 52829385bcc4d785e58ae2602c0b098a643523c9
cd tasks/prettier_conformance/prettier || git init tasks/prettier_conformance/prettier
bash: 1 行: cd: tasks/prettier_conformance/prettier: No such file or directory
Initialized empty Git repository in /Users/noyan/ghq/github.com/oxc-project/oxc/tasks/prettier_conformance/prettier/.git/
cd tasks/prettier_conformance/prettier && git remote add origin git@github.com:prettier/prettier.git || true
cd tasks/prettier_conformance/prettier && git fetch --depth=1 origin 52829385bcc4d785e58ae2602c0b098a643523c9 && git reset --hard 52829385bcc4d785e58ae2602c0b098a643523c9
remote: Enumerating objects: 10259, done.
remote: Counting objects: 100% (10259/10259), done.
remote: Compressing objects: 100% (6662/6662), done.
remote: Total 10259 (delta 970), reused 8226 (delta 696), pack-reused 0 (from 0)
Receiving objects: 100% (10259/10259), 12.85 MiB | 10.34 MiB/s, done.
Resolving deltas: 100% (970/970), done.
From github.com:prettier/prettier
* branch 52829385bcc4d785e58ae2602c0b098a643523c9 -> FETCH_HEAD
HEAD is now at 5282938 Release 3.3.3
just submodules 1.56s user 12.29s system 32% cpu 42.408 total
```
</p>
</details>
## Solution
To optimize the cloning process:
- Fetch only the specified commit, eliminating the need for a git clone
(which fetches HEAD and subsequently updates with differences).
- Initialize it with git init when the repository doesn't exist locally.
- Use `git fetch --depth=1` to prevent fetching previous commits.
See: https://stackoverflow.com/a/3489576
I initially suggested using `git fetch --depth=1`, but after testing, I
found that removing clone could speed up the process by about 20
seconds. Therefore, I've changed the approach.
2024-10-05 23:58:03 +08:00
overlookmotel
c7fbf686b9
refactor(transformer): logical assignment operator transform: no cloning identifier references ( #6290 )
...
Use `BoundIdentifier` to generate `IdentifierReference`s from, instead of cloning `IdentifierReference`s. This simplifies the code and is a less error-prone pattern.
2024-10-05 14:48:38 +00:00
overlookmotel
06797b6900
fix(transformer): logical assignment operator transform: fix reference IDs ( #6289 )
2024-10-05 14:48:37 +00:00
overlookmotel
e19deaa102
ci(transformer): move post-transform checker to tasks crate ( #6288 )
...
Move post-transform checker into a `tasks` crate. It doesn't feel like it belongs in `oxc_semantic`. It also feels like too heavy a lump of code to put in `tasks/common`.
2024-10-05 14:48:37 +00:00
overlookmotel
d4f2ee99c1
test(transformer): tidy up transform checker ( #6287 )
...
Pure refactor. Use `oxc_semantic`'s public APIs and shorten a few lines.
2024-10-05 14:48:36 +00:00
overlookmotel
0f5afd7ede
test(transformer): transform checker output symbol name for mismatches ( #6286 )
...
Transform checker include symbol names in output for symbol mismatches. This is rather more helpful for locating bugs than just `SymbolId(3)`.
2024-10-05 14:42:06 +00:00
dalaoshu
d953a6be02
fix(minifier): correct the reference link ( #6283 )
...
These are minor changes, and recently I’ve been learning and trying to
implement some features of `oxc_minifier`, which feels a bit complex.
By the way, I’m wondering whether we should gradually add test cases
during the feature implementation process or just copy all the
corresponding tests directly? Perhaps we could implement something like
`rulegen` similar to `linter`?
2024-10-05 08:54:59 +08:00
overlookmotel
f0a74ca7c6
refactor(transformer): prefer create_bound_reference_id to create_reference_id ( #6282 )
...
`TraverseCtx::create_reference_id` is intended for when you don't know if a reference is bound or not. Replace uses of it with the more specific `create_bound_reference_id` and `create_unbound_reference_id`.
2024-10-04 15:25:31 +00:00
dalaoshu
841317538f
refactor(linter): move shared function from utils to rule ( #6127 )
...
I previously extracted the common parts of `prefer_to_be_truthy` and
`prefer_to_be_falsy` into `utils`. However, we should place
rule-specific logic that isn't general-purpose directly within the
respective rules.
Co-authored-by: Don Isaac <donald.isaac@gmail.com>
2024-10-04 23:24:08 +08:00
IWANABETHATGUY
9736aa0112
fix(oxc_transformer): define import.meta and import.meta.* ( #6277 )
...
1. related esbuild test
d34e79e2a9/internal/bundler_tests/bundler_default_test.go (L5077-L5119)
2024-10-04 14:22:56 +00:00
overlookmotel
ba3e85b157
refactor(transformer): fix spelling ( #6279 )
...
`property` not `proeperty`.
2024-10-04 13:44:59 +00:00
camchenry
50a0029a97
perf(linter): do not concat vec in no-useless-length-check ( #6276 )
...
Probably a very small win, but rather than making lots of small vecs and concatenating, we should just use one vec and then push to it as we visit nodes.
2024-10-04 04:41:59 +00:00
camchenry
ba9c372a15
refactor(linter): make jest/vitest rule mapping more clear ( #6273 )
...
- Renamed the `map_jest` method to make it more clear what it does, now called `map_jest_rule_to_vitest`
- Tried to use a `phf_set!` over a list of strings for checking if we should map rules. Probably not faster, but should be simpler a constant amount of work if we expand the list of rules in the future.
- Made it easier to not mess up the arguments to the `map_jest` function by making it accept a `RuleWithSeverity` instead of just strings.
2024-10-03 21:46:57 -04:00
camchenry
7ca70ddab6
docs(linter): add docs for ContextHost and LintContext ( #6272 )
...
- towards https://github.com/oxc-project/oxc/issues/5870
Adds some very basic docs for methods and properties related to `LintContext` and `ContextHost`.
2024-10-03 21:46:57 -04:00
Boshen
2f888ed871
feat(oxc): add napi transform options ( #6268 )
2024-10-03 13:36:38 +00:00
7086cmd
37cbabbac4
fix(minifier): should not handle the strict operation for bool comparison. ( #6261 )
2024-10-03 12:16:10 +00:00
7086cmd
fcb4651819
test(minifier): enable null comparison with bigint. ( #6252 )
2024-10-03 12:16:09 +00:00
H11
e0a3378864
fix(linter): correct false positive in unicorn/prefer-string-replace-all ( #6263 )
...
closes #6259
2024-10-03 12:58:09 +08:00
Boshen
f51cbadf93
ci: temporary disable windows due to napi failing
...
Running unittests src\lib.rs (target\debug\deps\oxc_coverage-c37180833952f95b.exe)
Load Node-API [napi_get_last_error_info] from host runtime failed: GetProcAddress failed
2024-10-03 12:39:32 +08:00
Boshen
aa0dbb6375
refactor(oxc): add napi feature, change napi parser to use oxc crate ( #6265 )
2024-10-03 04:28:38 +00:00
Yuji Sugiura
7e4fa337d9
chore(just): Fix typo to make just r works ( #6264 )
...
Apparently this is only happening on my end, but a typo is still a typo.
🙄
2024-10-03 11:41:52 +08:00
Boshen
7bb745b085
ci: add trigger monitor oxc in prepare_release_crates
...
closes https://github.com/oxc-project/monitor-oxc/issues/44
2024-10-03 11:19:53 +08:00
7086cmd
e29c0676d6
fix(minifier): handle exceeded shifts. ( #6237 )
...
Related: #6161 , the last situation.
```js
// https://github.com/tc39/test262/blob/main/test/language/expressions/unsigned-right-shift/S9.6_A2.2.js
test((-2147483649 >>> 0) !== 2147483647)
```
2024-10-03 02:52:05 +00:00
leaysgur
5a73a663dc
refactor(regular_expression)!: Simplify public APIs ( #6262 )
...
This PR makes 2 changes to improve the existing API that are not very useful.
- Remove `(Literal)Parser` and `FlagsParser` and their ASTs
- Add `with_flags(flags_text)` helper to `ParserOptions`
Here are the details.
> Remove `(Literal)Parser` and `FlagsParser` and their ASTs
Previously, the `oxc_regular_expression` crate exposed 3 parsers.
- `(Literal)Parser`: assumes `/pattern/flags` format
- `PatternParser`: assumes `pattern` part only
- `FlagsParser`: assumes `flags` part only
However, it turns out that in actual usecases, only the `PatternParser` is actually sufficient, as the pattern and flags are validated and sliced in advance on the `oxc_parser` side.
The current usecase for `(Literal)Parser` is mostly for internal testing.
There were also some misuses of `(Literal)Parser` that restore `format!("/{pattern}/{flags}")` back and use `(Literal)Parser`.
Therefore, only `PatternParser` is now published, and unnecessary ASTs have been removed.
(This also obsoletes #5592 .)
> Added `with_flags(flags_text)` helper to `ParserOptions`
Strictly speaking, there was a subtle difference between the "flag" strings that users were aware of and the "mode" recognised by the parser.
Therefore, it was a common mistake to forget to enable `unicode_mode` when using the `v` flag.
With this helper, crate users no longer need to distinguish between flags and modes.
2024-10-03 02:47:08 +00:00
camchenry
5957214f4c
feat(linter): allow fixing in files with source offsets ( #6197 )
...
- fixes https://github.com/oxc-project/oxc/issues/5913
This PR fixes the calculation of spans when dealing with files that have multiple sources and non-zero source start offsets. This is almost always the case for `.vue`, `.astro`, and `.svelte` files. This enables us to correctly apply fixes for these file types both in the CLI with `oxlint` and also in editors like VS Code.
https://github.com/user-attachments/assets/2836c8bd-09be-4e59-801d-7c95f8c2491f
I'm open to ideas on how to improve testing in this area, as I don't think that we currently have any tests for fixing files end-to-end (beyond what the linter rules check). I did run this locally on the gitlab repository (which is written in Vue) and all of the fixes appeared to be applied correctly.
2024-10-03 00:53:30 +00:00
Boshen
294da86283
fix(napi/transform): fix index.d.ts
2024-10-03 08:52:10 +08:00
Boshen
099ff3a033
refactor(napi/transform): remove "Binding" from types; fix type error ( #6260 )
...
closes #6254
closes #6255
2024-10-03 00:44:07 +00:00
overlookmotel
32d972e2a4
refactor(parser)!: treat unambiguous files containing TS export assignments as modules ( #6253 )
...
An "unambiguous" TS source which contains an `export = <value>;` statement should be interpreted as an ES module.
This is in line with [this Babel test case](94e166782a/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous ) which has [input option of `sourceType: "unambiguous"`](94e166782a/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous/options.json (L2) ), and [outputs an AST with `sourceType: "module"`](94e166782a/packages/babel-parser/test/fixtures/typescript/export/equals-in-unambiguous/output.json (L7) ).
2024-10-03 00:28:00 +00:00
overlookmotel
4f6bc79734
refactor(transformer)!: remove source_type param from Transformer::new ( #6251 )
...
Closes #6248 .
2024-10-03 00:21:01 +00:00
7086cmd
115ccc941e
feat(minifier): bitwise not in exceeded value. ( #6235 )
...
```rs
test("x = ~2147483658.0", "x = 2147483637");
test("x = ~-2147483658", "x = -2147483639");
```
Used `wrapping_neg`, and maybe it is a great solution for #6161 .
2024-10-03 00:16:05 +00:00