Commit graph

2467 commits

Author SHA1 Message Date
overlookmotel
36c718ee82
feat(tasks): benchmarks for lexer (#2101)
This PR adds benchmarks for the lexer. I'm doing some work on optimizing
the lexer and I thought it'd be useful to see the effects of changes in
isolation, separate from the parser.

These benchmarks may not be ideal to keep long-term, but for now it'd be
useful.

In order to do so, it's necessary for `oxc_parser` crate to expose the
lexer, but have done that without adding it to the docs, and using an
alias `__lexer`.
2024-01-21 14:32:50 +00:00
cin
16b32616c4
feat(linter): eslint-plugin-jest: no-restricted-jest-methods (#2091)
Rule Detail:
[link](https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/no-restricted-jest-methods.ts)

---------

Co-authored-by: Wenzhe Wang <mysteryven@gmail.com>
2024-01-21 17:00:48 +08:00
Wenzhe Wang
142f84f654
fix(linter): not use new_inline with flexible str (#2106) 2024-01-21 16:37:27 +08:00
cin
4adce6fb45
feat/linter: (eslint-plugin-jest): no-restricted-matchers (#2090)
Rule Detail:
[link](https://github.com/jest-community/eslint-plugin-jest/blob/main/src/rules/no-restricted-matchers.ts)
2024-01-21 16:06:00 +08:00
Cameron
51183b801c
fix(linter) panic in prefer-native-coercion-function (#2100)
closes #2098
2024-01-21 01:52:00 +08:00
Boshen
2fdfc4cf1a
Release oxlint and vscode extension v0.2.2 2024-01-20 23:04:47 +08:00
Boshen
59e29f286a
chore(parser): explain the reason for omitting "}" and ">" in jsx text lexer (#2097)
closes #2094
2024-01-20 23:03:44 +08:00
Boshen
3f2b48f1a9
refactor(parser): remove useless string builder from jsx text lexer (#2096)
relates #2094
2024-01-20 22:34:57 +08:00
Dunqing
8e43eeffe7
refactor(semantic): improve declare symbol logic in FormalParameters (#2088) 2024-01-20 20:59:11 +08:00
msdlisper
a36813405b
refactor(linter): perfect the scope linter (#2092)
perfect the scope linter for #1141
2024-01-20 10:46:35 +08:00
Boshen
2f5afff9bd
fix(parser): fix crash on TSTemplateLiteralType in function return position (#2089)
```
interface Helpers {
  inspect(): `~~~~\n${string}\n~~~~`;
}
```
2024-01-19 23:14:05 +08:00
Dunqing
721a869b6e
feat(linter): improve no_redeclare rule implementation (#2084) 2024-01-19 20:10:06 +08:00
Boshen
a9e2158362
Update README 2024-01-19 18:39:07 +08:00
Yuji Sugiura
2f1e1e2e46
feat/tasks: expose linter RULES and use it for listing (#2083)
Part of #2020 , follow up of #2081 .
2024-01-19 16:45:00 +08:00
Yuji Sugiura
60ab7121f8
(feat/tasks): refactor lint_rules for subsequent todos (#2081)
Part of #2020 

- Handle args and flags
- Split files
- Prettify CLI outputs
2024-01-19 15:10:49 +08:00
Dunqing
b5b2ef34af
feat(transformer/typescript): improve function parameters name (#2079) 2024-01-19 13:50:10 +08:00
Dunqing
7711f7abaf
feat(transformer/typescript): support only_remove_type_imports option (#2077) 2024-01-18 23:25:31 +08:00
Dunqing
f5bf5dece1
feat(transformer/typescript): support transform exported TSModuleBlock (#2076) 2024-01-18 23:20:26 +08:00
Dunqing
56ca8b6dfe
feat(transformer/typescript): support transform namespace (#2075) 2024-01-18 23:15:28 +08:00
Dunqing
2e78b918d1
refactor(transformer/typescript): move the ExportNamedDeclaration logic to its function (#2074) 2024-01-18 21:28:48 +08:00
Yuji Sugiura
85c98525d7
feat(tasks): introduce tasks/lint_rules (#2068)
Part of #2020
2024-01-18 21:22:29 +08:00
overlookmotel
0e32618664
refactor(parser): combine token kinds for skipped tokens (#2072)
Small optimization to the lexer.

Whitespace, line breaks, and comments are all skipped by
`read_next_token()`.

At present there's a different `Kind` for each, and `read_next_token()`
decides whether to skip with `matches!(kind, Kind::WhiteSpace |
Kind::NewLine | Kind::Comment | Kind::MultiLineComment)`.

These `Kind`s are used for no other purpose, so there seems little
reason to differentiate them.

This PR combines them all into `Kind::Skip`, so then the test of whether
to skip is reduced to `kind == Kind::Skip`.

Only produces ~0.3% performance bump on parser benchmarks. But, why
not?...
2024-01-18 21:14:12 +08:00
Valerii Smirnov
d7ecd21801
fix(linter): eslint-plugin-import no-named-as-default-member rule (#2071)
Fixed false positives and early return @mysteryven 
#1988

64de6e9265 (r1453429430)
2024-01-18 09:32:40 +08:00
Wenzhe Wang
29dc5e69ff
fix(codegen): add parenthesis in binary expression by precedence (#2067)
related ESBuild code:
f5f8ff895c/internal/js_printer/js_printer.go (L3348-L3371)
2024-01-17 23:01:42 +08:00
Wenzhe Wang
32349af691
chore(tasks): remove redundant directory after exec (#2069) 2024-01-17 17:35:15 +08:00
Dunqing
b89e84cc2d
feat(transformer/typescript): keep imports if import specifiers is empty (#2058) 2024-01-17 16:14:31 +08:00
Dunqing
24ac957660
fix(semantic): incorrect reference flag (#2057) 2024-01-17 16:08:31 +08:00
Dunqing
3413bb3884
feat(transformer/typescript): remove type-related exports (#2056) 2024-01-17 16:04:30 +08:00
Dunqing
95d741abd6
feat(transformer/typescript): remove type only imports/exports correctly (#2055) 2024-01-17 15:58:04 +08:00
overlookmotel
8d5f5b8a49
refactor(parser): macro for ASCII byte handlers (#2066)
As discussed on #2046, it wasn't ideal to have `unsafe {
lexer.consume_ascii_char() }` in every byte handler. It also wasn't
great to have a safe function `consume_ascii_char()` which could cause
UB if called incorrectly (so wasn't really safe at all).

This PR achieves the same objective of #2046, but using a macro to
define byte handlers for ASCII chars, which builds in the assertion that
next char is guaranteed to be ASCII.

Before #2046:

```rs
const SPS: ByteHandler = |lexer| {
  lexer.consume_char();
  Kind::WhiteSpace
};
```

After this PR:

```rs
ascii_byte_handler!(SPS(lexer) {
  lexer.consume_char();
  Kind::WhiteSpace
});
```

i.e. The body of the handlers are unchanged from how they were before
https://github.com/oxc-project/oxc/pull/2046.

This expands to:

```rs
const SPS: ByteHandler = |lexer| {
  unsafe {
    let s = lexer.current.chars.as_str();
    assert_unchecked!(!s.is_empty());
    assert_unchecked!(s.as_bytes()[0] < 128);
  }
  lexer.consume_char();
  Kind::WhiteSpace
};
```

But due to the assertions the macro inserts, `consume_char()` is now
optimized for ASCII characters, and reduces to a single instruction. So
the `consume_ascii_char()` function introduced by #2046 is unnecessary,
and can be removed again.

The "boundary of unsafe" is moved to a new function `handle_byte()`
which `read_next_token()` calls. `read_next_token()` is responsible for
upholding the safety invariants, which include ensuring that
`ascii_byte_handler!()` macro is not being misused (that last part is
strictly speaking a bit of a cheat, but...).

I am not a fan of macros, as they're not great for readability. But in
this case I don't think it's *too* bad, because:

1. The macro is well-documented.
2. It's not too clever (only one syntax is accepted).
3. It's used repetitively in a clear pattern, and once you've understood
one, you understand them all.

What do you think? Does this strike a reasonable balance between
readability and safety?
2024-01-17 15:29:15 +08:00
Bradley Farias
18a58d472b
feat(minifier): handle more expressions for side effects (#2062)
Eventually these should return effects rather than a bool since some can
be moved around and ignored. For now, keep it similar to previous code.
2024-01-17 11:22:02 +08:00
Boshen
3faa2aa2a8
fix(linter): s/consistent-type-export/consistent-type-exports (#2065) 2024-01-17 11:03:43 +08:00
Cao Z.H
7a6261403d
feat(website): playground highlight buttons and persistent current view (#2054)
Closes: #2024

![Jan-16-2024
20-39-56](https://github.com/oxc-project/oxc/assets/150761799/aca3e2be-20cf-45c1-8dc1-37a338c769eb)
2024-01-16 23:28:03 +08:00
Boshen
b0d662f266
Release oxlint and vscode extension v0.2.1 2024-01-16 19:41:45 +08:00
Boshen
f514410427
refactor(linter): move LintSettings to its own file (#2052) 2024-01-16 17:23:55 +08:00
Boshen
ae4e714713
refactor(linter): remove the LintSettings parameter from LintContext::new. (#2051) 2024-01-16 17:17:46 +08:00
Boshen
9e06bd7797
feat(linter): remove the --timings feature (#2049)
For a various reasons:

This features bloats the code size.

We have many tools for profiling in Rust (as compared to ESLint where the feature came from),
so a built-in feature is not really needed anymore.

ESLint needed `--timings` because it needs to monitor plugins.
We control all our code so we don't need this.
2024-01-16 14:21:04 +08:00
Boshen
f4132976e9
chore: say good bye to ezno (#2048)
ezno has decided to focus on its own compiler for 2024,
we part away but we still collaborate and share knowledge together.
2024-01-16 13:53:54 +08:00
overlookmotel
408acb90e6
refactor(parser): lexer handle unicode without branch (#2039)
As suggested by @strager in
https://github.com/oxc-project/oxc/pull/2025#pullrequestreview-1820273832,
this PR adds `BYTE_HANDLERS` for first bytes of unicode characters.

This removes a branch from `read_next_token()` and produces a +1%
speed-up on parser benchmarks.
2024-01-16 13:14:22 +08:00
Don Isaac
97b1984d74
build(linter): add new-react-perf rulegen task (#2040)
Adds a new linter rule generation task, `just new-react-perf-rule`, for
incorporating rules from
[eslint-plugin-react-perf](https://github.com/cvazac/eslint-plugin-react-perf)
into oxc.

Since this library has its own testing utilities and only 4 rules, I
didn't bother writing code to port over test cases. If we deem this
requisite I'll add this to the rulegen task.
2024-01-16 12:48:19 +08:00
overlookmotel
66a7a68f9f
perf(parser): lexer byte handlers consume ASCII chars faster (#2046)
In the lexer, most `BYTE_HANDLER`s immediately consume the current char
with `lexer.consume_char()`.

Byte handlers are only called if there's a certain value (or range of
values) for the next char. This is their entire purpose. So in all cases
we know for sure that we're not at EOF, and that the next char is a
single-byte ASCII character.

The compiler, however, doesn't seem to be able to "see through" the
`BYTE_HANDLERS[byte](self)` call and understand these invariants. So it
produces very verbose ASM for `lexer.consume_char()`.

This PR replaces `lexer.consume_char()` in the byte handlers with an
unsafe `lexer.consume_ascii_char()` which skips on to next char with a
single `inc` instruction.

The difference in codegen can be seen here:
https://godbolt.org/z/1ha3cr9W5 (compare the 2 x
`core::ops::function::FnOnce::call_once` handlers).

Downside is that this does introduce a lot of unsafe blocks, but in my
opinion they're all pretty trivial to validate.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-01-16 12:31:45 +08:00
Boshen
09c7570560
ci: use miri to detect memory leak for the parser (#2037)
We'll merge this and then eventually turn it on as a nightly check, it's
a manual run for now.
2024-01-15 15:11:02 +00:00
Boshen
b0f4715df1
ci: disable codegen runtime tests for now
It seems to be unstable across node.js versions
2024-01-15 21:24:07 +08:00
Boshen
a69b76ab77
chore: update snapshots 2024-01-15 21:13:05 +08:00
Valerii Smirnov
c60c31521e
feat(linter): eslint-plugin-import no-named-as-default-member rule (#1988)
- Docs:
https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-named-as-default-member.md
- Code:
https://github.com/import-js/eslint-plugin-import/blob/main/src/rules/no-named-as-default-member.js
- Tests:
https://github.com/import-js/eslint-plugin-import/blob/main/tests/src/rules/no-named-as-default-member.js
2024-01-15 11:03:04 +00:00
dependabot[bot]
21909fa962
chore(deps): bump the dependencies group with 3 updates (#2033) 2024-01-15 15:31:32 +08:00
Boshen
3b40fbdbac
fix(linter): false positive for filename_case where filename doesn't have a proper casing (#2032) 2024-01-15 14:36:48 +08:00
Boshen
68606c4d6d
fix(linter): keep rules disabled if the rule is not enabled in the config (#2031)
relates #1969
2024-01-15 05:32:51 +00:00
Bradley Farias
3490111c56
Commutative undefined minify (#2003)
this should probably be squashed, i'm not familiar with code commit
norms here. we can expand a bunch of the commutative compressions later.

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-01-15 02:51:53 +00:00
Yuto Yoshino
530d1bea56
feat(linter): eslint-plugin-jsx-a11y no-redundant-roles rule (#1981)
Part of: https://github.com/oxc-project/oxc/issues/1141

Based on:
- doc: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/no-redundant-roles.md
- code: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/rules/no-redundant-roles.js
- test: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/__tests__/src/rules/no-redundant-roles-test.js
2024-01-14 21:03:58 +00:00