Commit graph

438 commits

Author SHA1 Message Date
Boshen
efbdced597 fix(parser): only show flow error if it's a flow file (#5069)
Otherwise we get a mixture of confusing error messages.
2024-08-22 12:19:45 +00:00
Boshen
afe728a73a feat(parser): parse regular expression with regex parser (#4998)
Many false positives and incorrect errors. @leaysgur Enjoy 😁

Run `just conformance` to update the snapshot.
2024-08-22 03:09:55 +00:00
overlookmotel
ca70cc7c03 refactor(linter, mangler, parser, semantic, transformer, traverse, wasm): rename various flag vars to flags (#5028)
Part of #4991.
2024-08-21 00:19:58 +00:00
Boshen
b2ff2df5af refactor(parser)!: remove builder pattern from Parser struct (#5000)
part of #4455

use `with_options(ParseOptions { ..ParseOptions::default() })` API instead.
2024-08-20 07:40:25 +00:00
Burlin
f88970bc79
refactor(ast)!: Change order of fields in CallExpression (#4859)
fix: #4821

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2024-08-20 09:47:12 +08:00
Boshen
6800e694e3
feat(oxc): add Compiler and CompilerInterface (#4954)
This PR adds a full compiler pipeline to the `oxc` crate, to stop us
from implementing the same pipeline over and over again.

relates #4455
2024-08-19 10:20:05 +08:00
rzvxa
c164bb8b64 chore(deps): remove static_assertions dependency. (#4883) 2024-08-14 02:18:06 +00:00
Boshen
1bdde2c117 fix(parser): detect @flow in `/** @flow */ comment (#4861)
Discovered in https://github.com/oxc-project/monitor-oxc

There are files with

```
/**
 * @flow
 */
```

https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/__mocks__/JSXAttributeMock.js#L1

So I changed the logic to checking the first comment instead.
2024-08-13 05:43:48 +00:00
Boshen
559baa5602
docs(parser): clean up doc regarding performance; remove conformance
conformance is removed due to needing to keep it updated.
2024-08-12 14:02:09 +08:00
Boshen
a40a217de4 fix(parser): parse assert keyword in TSImportAttributes (#4610)
closes #4601
2024-08-04 01:41:31 +00:00
rzvxa
d25dea7b94 refactor(parser): use ast_builder in more places. (#4612) 2024-08-02 22:38:06 +00:00
overlookmotel
55a8763d6e perf(parser): faster decoding unicode escapes in identifiers (#4579)
Replace `next_char` and `peek_char` with `peek_byte` when decoding unicode escape sequences in identifiers.
2024-07-31 03:33:08 +00:00
overlookmotel
ae1d38f60d perf(parser): fast path for ASCII when checking char after numeric literal (#4577)
Make a fast path for ASCII characters when lexer checks for invalid chars after a numeric literal. Also shorten the check for ASCII chars.
2024-07-31 03:33:05 +00:00
overlookmotel
56ae615b6e perf(parser): make not at EOF the hot path in Source methods (#4576)
Reverse `if` arms in 2 very commonly-called methods in `Source` so that "not at EOF" is the first branch. This will encourage compiler to treat EOF as the cold branch (which it should be, as we're almost never at EOF).
2024-07-31 03:33:02 +00:00
overlookmotel
e68ed628b8 refactor(parser): convert lexer byte handler for | to a single match (#4575)
Same as #4573 and #4574. Convert lexer's byte handler for `|` to a single match rather than multiple `next_ascii_byte_eq` calls.
2024-07-31 03:33:00 +00:00
overlookmotel
bba824bc34 refactor(parser): convert Lexer::read_minus to a single match (#4574)
Same as #4573. Convert `Lexer::read_minus` to a single match rather than multiple `next_ascii_byte_eq` calls.
2024-07-31 03:32:57 +00:00
overlookmotel
ef5418a917 refactor(parser): convert Lexer::read_left_angle to a single match (#4573)
`Lexer::read_left_angle` was a series of disparate `next_ascii_byte_eq` and `peek_byte` calls. Convert it to a single match on `peek_byte`. This I think will remove a couple of bounds checks.
2024-07-31 03:32:54 +00:00
overlookmotel
25679e6277 perf(parser): optimize Lexer::hex_digit (#4572)
Optimize `Lexer::hex_digit`.

Rather than checking for `A-F` and `a-f` separately, can check for them both in one go. `b'A' | 32 == b'a'` (and same for all other alphabetic letters) so matching against `b | 32` allows checking for all matching letters, lower or upper case, in one operation.
2024-07-31 03:32:52 +00:00
overlookmotel
bb33bcce35 perf(parser): speed up lexing non-decimal numbers (#4571)
Inline `Lexer::read_non_decimal` to reduce branching.
2024-07-31 00:29:00 +00:00
overlookmotel
9e5be78af5 refactor(parser): add Lexer::consume_2_chars (#4569)
Add `Lexer::consume_2_chars` to replace `lexer.consume_char(); lexer.consume_char();`. Mostly this is just neater code, but *may* also help compiler to elide bounds checks when it's preceded by `lexer.peek_2_bytes()`.
2024-07-31 00:28:58 +00:00
overlookmotel
649913e6cd refactor(parser): extract u8 not &u8 when iterating over bytes (#4568)
Iterating over `str.as_bytes()` produces `&u8`s. Dereference to `u8` in `for` statement. Should make no difference to generated assembly, purely making this change for neater code style.
2024-07-31 00:28:57 +00:00
overlookmotel
59f00c0a44 refactor(parser): rename function (#4566)
Rename `matches_number_char` function to `matches_number_byte` as it takes a `u8` byte, not a `char`.
2024-07-31 00:28:55 +00:00
overlookmotel
8e3e9104e5 refactor(parser): rename vars (#4565)
Use `b` everywhere in lexer for a `u8` byte, keeping the name `c` for a vars containing a `char`.
2024-07-31 00:28:53 +00:00
overlookmotel
0c0601f9a4 refactor(parser): rename function (#4564)
Rename `Lexer::next_ascii_char_eq` to `next_ascii_byte_eq`, for consistency with other method names which operate on bytes.
2024-07-31 00:28:51 +00:00
overlookmotel
0acc4a726e refactor(parser): fetch 2 bytes in ? byte handler (#4563)
Lexer's `?` byte handler needs to fetch next 2 bytes, so do that in one shot, rather than bounds-checking twice.
2024-07-31 00:28:50 +00:00
overlookmotel
565eccf631 refactor(parser): shorten lexer code (#4562)
Use `lexer.peek_byte()` instead of `lexer.source.peek_byte()`.
2024-07-31 00:28:48 +00:00
overlookmotel
ab8509edaa perf(parser): use - not saturating_sub (#4561)
Follow-on after #4304. Avoid using `saturating_sub` when plain `-` will do. `-` is cheaper - it's a single assembly instruction, whereas `saturating_sub` is usually 3 instructions.

https://godbolt.org/z/fo8Tcx6bK
2024-07-31 00:28:46 +00:00
lucab
c9c38a187c perf(parser): support peeking over bytes (#4304)
Closes https://github.com/oxc-project/oxc/issues/3291
2024-07-30 17:53:13 +00:00
DonIsaac
d5c4b190aa fix(parser): fix enum member parsing (#4543)
Closes #4449
2024-07-30 10:43:09 +00:00
lucab
0870ee1f9f perf(parser): get and check lookahead token (#4534) 2024-07-29 16:45:39 +00:00
overlookmotel
148bdb5585 refactor(parser): adjust function inlining (#4530)
These 2 `#[inline(always)]` were introduced by accident by me just playing around in #4298. One should be kept, but the other one we should leave to compiler to decide.
2024-07-29 15:38:02 +00:00
Boshen
7446e986c3 feat(codegen): align more esbuild implementations (#4510) 2024-07-28 13:35:37 +00:00
Boshen
35654e665c feat(codegen): align operator precedence with esbuild (#4509)
closes #4339
2024-07-28 11:48:51 +00:00
lucab
868fc87885 perf(parser): optimize conditional advance on ASCII values (#4298)
Part of https://github.com/oxc-project/oxc/issues/3291.
2024-07-27 01:17:25 +00:00
overlookmotel
aece1df561 fix(ast): visit Programs hashbang field first (#4368)
Visit `hashbang` before `directives` for `Program`.
2024-07-19 16:27:51 +00:00
Dunqing
f68b659713 refactor(ast)!: reorder fields of ArrowFunctionExpression (#4364)
Found in #4328
Same as #4248
2024-07-19 14:12:05 +00:00
DonIsaac
a2eabe1f4b refactor(parser): use error codes for ts diagnostics (#4335)
Part of #4333
2024-07-18 16:09:25 +00:00
lucab
9a87e41332 fix(parser): avoid crashing on invalid const modifier (#4267)
Followup on https://github.com/oxc-project/oxc/pull/3977, fixing one of the crashes at https://github.com/oxc-project/oxc/pull/3977.
2024-07-15 11:37:31 +00:00
overlookmotel
a8dc4f34b2
perf(parser): speed up parsing numbers with _ separators (#4259)
When parsing a number which contains `_` separators, rather than looping
through the string once to remove separators, and then again to convert
to an `f64`, do it all in a single loop.

Co-authored-by: overlookmotel <557937+overlookmotel@users.noreply.github.com>
2024-07-15 12:27:47 +08:00
overlookmotel
b94540d0fb perf(parser): speed up parsing octal literals (#4258)
Micro-optimization to parsing octal numbers. This removes usage of `char`, so removes a surprising amount of instructions.
2024-07-15 03:42:47 +00:00
overlookmotel
a7b328c4f5 perf(parser): faster parsing decimal numbers (#4257)
Closes #3288.

Speed up parsing decimal literals (e.g. `123`), using same techniques as `parse_octal` etc.
2024-07-15 03:38:09 +00:00
Boshen
a71787572e
chore: remove unsafe_code = "warn" rust lint
Feels too verbose as we already have unsafe comment turned on
2024-07-15 10:39:08 +08:00
overlookmotel
641a78bc2b fix(parser): fix tests for number parsing (#4254)
Fix tests for parsing large numbers.

* Tests for imprecision decimals and octals weren't using numbers larger than `u64::MAX`, so were not testing what they were meant to be - that parser can handle larger numbers.
* Tests for decimals (e.g. `123.5`) were calling `parse_int` which isn't meant to handle that (`parse_float` does that).
* Tests were calling `parse_int` with negative numbers, which it's not meant to handle.

Also, re-order the const assertions in same order as the code above.
2024-07-15 01:26:13 +00:00
Dunqing
ace4f1ff77 refactor(semantic): update the order of visit_function and Visit fields in the builder to be consistent (#4248)
Same as #4195
2024-07-14 11:39:15 +00:00
Dunqing
20cdb1fe0a feat(semantic): align class scope with typescript (#4195)
```ts
class Klass <T>   extends Root       <R>                   {}
//    ^^^^^ ^^^           ^^^^       ^^^                   ^^
//    id type_paramter super_class super_type_parameters  body
```
I reorder fields according to the order above

The class scope is not defined in the spec. But we need to create a scope for `class` to store `TypeParamters`
2024-07-14 03:19:30 +00:00
DonIsaac
4a656c3a18 fix(lexer): incorrect lexing of large hex/octal/binary literals (#4072)
Closes #3347. Implementation follows the approach described by @overlookmotel [here](https://github.com/oxc-project/oxc/issues/3347#issuecomment-2119004288).
2024-07-10 16:39:10 +00:00
Boshen
28eeee0f71 fix(parser): fix asi error diagnostic pointing at invalid text causing crash (#4163) 2024-07-10 14:45:10 +00:00
rzvxa
48947a26d2 fix(ast): put decorators before everything else. (#4143)
Won't fix #4142

It is similar to #3994 but for those types that weren't relying on this order. It seems to be the right order.
technically speaking it is a breaking change but I know as a fact that it won't have a big difference on our downstream. If you want it to be chronically correct feel free to merge as a breaking change.
2024-07-10 02:03:05 +00:00
Luca Bruno
5731e3957f
refactor(ast)!: store span details inside comment struct (#4132)
This tweaks `Comment` definition in order to internally store the start
and end position of its span.

Closes: https://github.com/oxc-project/oxc/issues/4069
2024-07-09 23:23:43 +08:00
rzvxa
b936162093 refactor(ast/ast_builder)!: shorter allocator utility method names. (#4122)
This PR serves two purposes, First off it would lower the amount of characters we have to type in for a simple operation such as wrapping an expression in a vector. Secondly, it would follow the generated names more closely since nowhere else in the builder we do have `new_xxx`, We always say `xxx` since a builder always constructs something.

```
new_vec -> vec
new_vec_single -> vec1*
new_vec_from_iter -> vec_from_iter
new_vec_with_capacity -> vec_with_capacity
new_str -> str
new_atom -> atom
```

`*` This one is the main motivation behind this PR, It saves 10 characters!
2024-07-09 12:16:38 +00:00