Commit graph

2721 commits

Author SHA1 Message Date
Boshen
c4b169e5d6
refactor(prettier): add call_arguments.rs (#2393) 2024-02-11 23:16:07 +08:00
Boshen
7e99e52bbc
refactor(prettier): function parameters (#2392) 2024-02-11 23:01:19 +08:00
Dunqing
73e116e8a1
fix(parser): incorrect parsing of class accessor property name (#2386) 2024-02-11 22:57:13 +08:00
Wenzhe Wang
384d5acd7a
fix(codegen): lower the level of precedence in TaggedTemplateExpression (#2391) 2024-02-11 22:56:32 +08:00
Boshen
747de8cfd4
refactor(prettier): improve Group API (#2390) 2024-02-11 21:53:02 +08:00
keita hino
8d6202f946
feat(linter): eslint-plugin-jest require-to-throw-message (#2384)
partof: #492 

docs:
https://github.com/jest-community/eslint-plugin-jest/blob/main/docs/rules/require-to-throw-message.md
code:
https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/require-to-throw-message.ts
test:
https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/__tests__/require-to-throw-message.test.ts
2024-02-11 20:38:24 +08:00
Boshen
9ff7986610
feat(prettier): handle binaryish expression in return statement (#2388) 2024-02-11 20:01:25 +08:00
Boshen
871a73afdd
fix(prettier): semi colon after class property (#2387) 2024-02-11 19:25:38 +08:00
Dunqing
0df7e296f9
feat(tasks/codegen): check node version >= 20 (#2385)
This syntax only works on node >= 20
`import value from './json-value-array_FIXTURE.json' with { type: 'json'
};`
2024-02-11 19:23:11 +08:00
overlookmotel
383f5b3081
perf(parser): consume multi-line comments faster (#2377)
Consume multi-line comments faster.

* Initially search for `*/`, `\r`, `\n` or `0xE2` (first byte of
irregular line breaks).
* Once a line break is found, switch to faster search which only looks
for `*/`, as it's not relevant whether there are more line breaks or
not.

Using `memchr` for the 2nd simpler search, as it's efficient for a
search with only one "needle".

Initializing `memchr::memmem::Finder` is fairly expensive, and tried
numerous ways to handle it. This is most performant way I could find.
Any ideas how to avoid re-creating it for each Lexer pass? (it can't be
a `static` as `Finder::new` is not a const function, and `lazy_static!`
is too costly)
2024-02-11 12:43:14 +08:00
Boshen
24a9255610
Release napi oxc-parser@v0.4.0 2024-02-11 12:37:44 +08:00
Boshen
5723690fdf
Release napi oxc-parser@v0.4.0-alpha.0 2024-02-11 11:56:46 +08:00
Boshen
15a8857927
refactor(prettier): improve print_statement_sequence (#2383) 2024-02-11 00:16:26 +08:00
Boshen
82a6dc17d3
feat(pretter): implement print_binaryish_expressions (#2382) 2024-02-10 23:18:56 +08:00
Boshen
4e8fcb5110
refactor(prettier): remove BinaryishLeft (#2381) 2024-02-10 23:10:33 +08:00
Yunfei He
7d7a3fcef8
perf(lint/no_var_requires): quicker way to check if the IdentifierReference point to a global variable (#2376)
The old code use this function to do the checking, which is too much for
this simple checking


ef336cb66b/crates/oxc_linter/src/ast_util.rs (L267-L276)
2024-02-10 22:46:02 +08:00
cinchen
92afbb102e
feat(linter): eslint-plugin-jest: prefer-equality-matcher (#2358)
Rule detail:
[link](https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/prefer-equality-matcher.ts)
2024-02-10 19:30:28 +08:00
Boshen
2dfe5210bb
fix(prettier): print strings as raw strings (#2380) 2024-02-10 17:52:17 +08:00
Boshen
642484e2cb
feat(prettier): print newlines between array expression elements (#2379) 2024-02-10 17:31:09 +08:00
Boshen
f194b1fac8
refactor(prettier): clean up implementation of object key (#2378) 2024-02-10 16:49:10 +08:00
Boshen
ef336cb66b
feat(parser): recover from async x [newline] => x (#2375)
```javascript
async x
=> x
```

Babel recovers and displays "No line break is allowed before '=>'
2024-02-10 11:19:08 +08:00
overlookmotel
c4fa738312
perf(parser): consume single-line comments faster (#2374)
Use `byte_search!` macro to consume single-line comments.

Would be a lot simpler if didn't have to deal with irregular line breaks. Damn you Unicode!
2024-02-10 11:02:30 +08:00
overlookmotel
b29719d2df
refactor(parser): add methods to Source + SourcePosition (#2373)
Preparatory step for #2374.
2024-02-10 10:57:33 +08:00
overlookmotel
79ae9a9b2c
refactor(parser): extend byte_search macro (#2372)
Preparatory step for #2374.
2024-02-10 10:52:59 +08:00
overlookmotel
0be8397c77
perf(parser): optimize lexing strings (#2366)
Optimize lexing strings a bit.
2024-02-09 23:52:45 +08:00
Boshen
d6d921ea1f
Publish crates v0.7.0 2024-02-09 23:01:12 +08:00
Boshen
70c983d4bb
feat(prettier): print rest parameters (#2370) 2024-02-09 22:59:28 +08:00
Boshen
9b6c313ebf
fix(prettier): flatten all binary expressions for now (#2367) 2024-02-09 21:48:27 +08:00
Boshen
90a834f87b
chore: update snapshot 2024-02-09 21:08:39 +08:00
overlookmotel
c0d1d6b08a
perf(parser): lex strings as bytes (#2357)
Lex string literals as bytes, using same techniques as for identifiers.

Handling escapes could be optimized a bit more, and maybe I'll return to that, but as escapes are fairly rare, it wouldn't be the biggest gain.
2024-02-09 21:00:27 +08:00
overlookmotel
1baf9c33d2
ci: run benchmarks on branches called bench-* (#2365)
I've recently switched over from hacking on a fork to working directly
on upstream, in order to be able to use Graphite.

One thing I miss now is ability to create branches and run CodSpeed on
them while developing. Compared to running benches locally, CodSpeed has
the advantage of giving you a visual history, showing how each commit
you push moves the dials.

This PR makes the benchmarks run for any branch named `bench-*`, in
order to enable this workflow on upstream, without having to open a
draft PR for every experiment.
2024-02-09 20:57:37 +08:00
Yuji Sugiura
2521b52011
fix(linter/jsx_a11y): Ensure plugin settings are used (#2359)
Currently, some of the rules did not use `settings`, so make sure they
do.

- [x] Align implementation of `getElementType()`
  - (This is the only util that depends on `settings`)

Original rules which use `getElementType()` are:

- [x] 🙅🏻‍♂️ accessible-emoji
- [x]  alt-text
- [x] 🙅🏻‍♂️ anchor-ambiguous-text
- [x]  anchor-has-content
- [x] anchor-is-valid
  - TODO: `from_configuration()` not implemented => #2361 
- [x] 🙆🏻‍♀️ aria-activedescendant-has-tabindex
- [x] 🙆🏻‍♀️ aria-role
- [x] 🙆🏻‍♀️ aria-unsupported-elements
- [x] autocomplete-valid
- TODO: `from_configuration()` not implemented and needed for this =>
#2362
- [x] 🙆🏻‍♀️ click-events-have-key-events
- [x] 🙅🏻‍♂️ control-has-associated-label
- [x] heading-has-content
  - TODO: 1 test should be failed but passes 🤔 => #2360 
- [x] 🙆🏻‍♀️ html-has-lang
- [x]  iframe-has-title
- [x] 🙆🏻‍♀️ img-redundant-alt
- [x] 🙅🏻‍♂️ interactive-supports-focus
- [x] 🙅🏻‍♂️ label-has-associated-control
- [x] 🙅🏻‍♂️ label-has-for
- [x] 🙆🏻‍♀️ lang
- [x] 🙆🏻‍♀️ media-has-caption
- [x]  no-aria-hidden-on-focusable
- [x] 🙆🏻‍♀️ no-autofocus
- [x] 🙆🏻‍♀️ no-distracting-elements
- [x] 🙅🏻‍♂️ no-interactive-element-to-noninteractive-role
- [x] 🙅🏻‍♂️ no-noninteractive-element-interactions
- [x] 🙅🏻‍♂️ no-noninteractive-element-to-interactive-role
- [x] 🙅🏻‍♂️ no-noninteractive-tabindex
- [x] 🙅🏻‍♂️ no-onchange
- [x] 🙆🏻‍♀️ no-redundant-roles
- [x] 🙅🏻‍♂️ no-static-element-interactions
- [x]  prefer-tag-over-role
- [x] 🙆🏻‍♀️ role-has-required-aria-props
- [x] 🙆🏻‍♀️ role-supports-aria-props
- [x] 🙆🏻‍♀️ scope

🙅🏻‍♂️ = Not implemented yet by oxlint /  = Fixed by this PR / 🙆🏻‍♀️ =
Already used
2024-02-09 20:55:50 +08:00
overlookmotel
2f6cf73d51
fix(parser): remove erroneous debug assertion (#2356)
This was a bit of a whoopsie in last batch of PRs. This assertion shouldn't be there, because all reads are now via `source.position().read()`, so this assertion says "you can only read some byte values".

Only reason it didn't blow up conformance tests is that they run in release mode.

Sorry. Please merge soon as you can and cover my shame!
2024-02-09 20:55:12 +08:00
Dunqing
2eb489e996
fix(codegen): format new expession + import expression with the correct parentheses (#2346)
Similar to #2330
2024-02-09 20:51:50 +08:00
Boshen
f49ffb2b63
fix(linter): getter-return false positive with TypeScript syntax (#2363)
closes #2349
2024-02-09 18:22:53 +08:00
Boshen
ca77ccc951
refactor(prettier): add a space!() macro (#2348) 2024-02-09 12:11:42 +08:00
overlookmotel
8376f15b9a
perf(parser): eat whitespace after line break (#2353)
Uses the `byte_search!` macro introduced in #2352 to consume whitespace after a line break.
2024-02-09 12:02:51 +08:00
overlookmotel
d3a59f27f7
perf(parser): lex identifiers as bytes not chars (#2352)
This PR re-implements lexing identifiers with a fast path for the most common case - identifiers which are pure ASCII characters, using the new `Source` / `SourcePosition` APIs.

Lexing identifiers is a hot path, and accounts for the majority of the time the Lexer spends. The performance bump from this change is (if I do say so myself!) quite decent.

I've spent a lot of time tuning the implementation, which gained a further 10-15% on the Lexer benchmarks compared to my first, simpler attempt. Some of the design decisions, if they look odd, are likely motivated by gains in performance.

### Techniques

This implementation uses a few different strategies for performance:

* Search byte-by-byte, not char-by-char.
* Process batches of 32 bytes at a time to reduce bounds checks.
* Mark uncommon paths `#[cold]`.

### Structure

The implementation is built in 3 layers:

1. ASCII characters only.
2. ASCII and Unicode characters.
3. `\` escape sequences (and all the above).

`identifier_name_handler` starts at the top layer, and is optimized for consuming ASCII as fast as possible. Each "layer" is considered more uncommon than the previous, and dropping down a layer is a de-opt.

I'm assuming that 95%+ of JavaScript code does not include either Unicode characters or escapes in identifiers, so the speed of the fast path is prioritised.

That said, once a Unicode character is encountered, the next layer does expect to find further Unicode characters, rather than de-opting over and over again. If an identifier *starts* with a Unicode character, it enters the code straight on the 2nd layer, so is not penalised by going through a `#[cold]` boundary. Lexing Unicode is never going to be as fast as ASCII, but still I felt it was important not to penalise it unnecessarily, so as not to be Anglo-centric.

### ASCII search macro

The main ASCII search is implemented as a macro. I found that, for reasons I don't understand, it's significantly faster to have all the code in a single function, even compared to multiple functions marked `#[inline]` or `#[inline(always)]`. The fastest implementation also requires some code to be repeated twice, which is nicer to do with a macro.

This macro, and the `ByteMatchTable` types that go with it, are designed to be re-usable. Next step will be to apply them for whitespace and strings, which should be fairly simple.

Searching in batches of 32 bytes is also designed to be forward-compatible with SIMD.

### Bye bye `AutoCow`

`AutoCow` is removed. Instead, a string-builder is only created if it's needed, when a `\` escape is first encountered. The string builder is also more efficient than `AutoCow` was, as it copies bytes in chunks, rather than 1-by-1.

This won't make much difference for identifiers, as escapes are so rare anyway, but this same technique can be used for strings, where they're more common.
2024-02-09 12:01:30 +08:00
overlookmotel
6910e4f71b
refactor(parser): macro for ASCII identifier byte handlers (#2351)
Add a macro for ASCII identifier byte handlers.

This is a preparatory step towards #2352.
2024-02-09 11:55:35 +08:00
overlookmotel
6f597b18bc
refactor(parser): all pointer manipulation through SourcePosition (#2350)
A safer and faster interface for reading source text using pointers than `*ptr`.
2024-02-09 10:26:51 +08:00
Boshen
651b0b15d1
refactor(prettier): s/nodes/stack (#2347) 2024-02-08 23:22:44 +08:00
Dunqing
e4754873ee
fix(prettier): printing value instead of key in BindingProperty (#2334)
fix: #2314
2024-02-08 21:49:10 +08:00
Boshen
5d9b0f3312
ci: speed up benchmark build (#2343)
closes #2299

Managed to figure out what `cargo codspeed build` is doing :-)
2024-02-08 19:47:50 +08:00
overlookmotel
185b3dbcc3
refactor(parser): fix outdated comment (#2344)
Just fixes an outdated comment.
2024-02-08 19:47:33 +08:00
Yuji Sugiura
63b4741ff3
refactor(linter/config): Use serde::Deserialize for config parsing (#2325)
Fixes #2258 

### Overview

- Re-implemented the config parser to use `serde::Deserialize`
- In order to benefit from it as much as possible, avoided implementing
custom deserializers and tried to use attributes as much as possible
  - This required some changes to the caller signatures...

 

- Fixed a bug that did not support for abbreviations like `"rule-name":
1`
- Fixed settings that should have been located in `settings.react` but
were not
2024-02-08 16:48:38 +08:00
overlookmotel
f3470163d9
refactor(parser): make Source::set_position safe (#2341)
Make `Source::set_position` a safe function.

This addresses a shortcoming of #2288.

Instead of requiring caller of `Source::set_position` to guarantee that the `SourcePosition` is created from this `Source`, the preceding PRs enforce this guarantee at the type level.

`Source::set_position` is going to be a central API for transitioning the lexer to processing the source as bytes, rather than `char`s (and the anticipated speed-ups that will produce). So making this method safe will remove the need for a *lot* of unsafe code blocks, and boilerplate comments promising "SAFETY: There's only one `Source`", when to the developer, this is blindingly obvious anyway.

So, while splitting the parser into `Parser` and `ParserImpl` (#2339) is an annoying change to have to make, I believe the benefit of this PR justifies it.
2024-02-08 14:56:26 +08:00
overlookmotel
aef593fb50
parser(refactor): promise only one Source on a thread at a time (#2340)
Introduce invariant that only a single `lexer::Source` can exist on a thread at one time.

This is a preparatory step for #2341.

2 notes:

Restriction is only 1 x `ParserImpl` / `Lexer` / `Source` on 1 *thread* at a time, not globally. So this does not prevent parsing multiple files simultaneously on different threads.

Restriction does not apply to public type `Parser`, only `ParserImpl`. `ParserImpl`s are not created in created in `Parser::new`, but instead in `Parser::parse`, where they're created and then immediately consumed. So the end user is also free to create multiple `Parser` instances (if they want to for some reason) on the same thread.
2024-02-08 14:51:17 +08:00
Maurice Nicholson
ebc08d4e1e
fix(linter): add missing typescript-eslint(_) prefix for some errors (#2342)
Running latest on one of my projects these warnings jumped out at me
because they were "anonymous" vs the others.

This PR just adds the usual rule-name prefix to the errors where it was
missing
2024-02-08 14:28:56 +08:00
overlookmotel
0bdecb5043
refactor(parser): wrapper type for parser (#2339)
Split parser into public interface `Parser` and internal implementation `ParserImpl`.

This involves no changes to public API.

This change is a bit annoying, but justification is that it's required for #2341, which I believe to be very worthwhile.

The `ParserOptions` type also makes it a bit clearer what the defaults for `allow_return_outside_function` and `preserve_parens` are. It came as a surprise to me that `preserve_parens` defaults to `true`, and this refactor makes that a bit more obvious when reading the code.

All the real changes are in [oxc_parser/src/lib.rs](https://github.com/oxc-project/oxc/pull/2339/files#diff-8e59dfd35fc50b6ac9a9ccd991e25c8b5d30826e006d565a2e01f3d15dc5f7cb). The rest of the diff is basically replacing `Parser` with `ParserImpl` everywhere else.
2024-02-07 23:22:08 +08:00
Dunqing
3268d7d66e
feat(tasks/prettier): add some information for debug no spec calls (#2333) 2024-02-07 16:55:59 +08:00