Commit graph

4260 commits

Author SHA1 Message Date
Boshen
ca0b4fa08a refactor(tasks): clean up test files and remove libs.txt (#4172) 2024-07-10 17:38:06 +00:00
Boshen
083fe38971
chore(codegen): add a for loop special case 2024-07-11 01:35:05 +08:00
Boshen
254d5e07e3
fix(wasm): codegen is broken due to preserve_parens(false) 2024-07-11 01:33:10 +08: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
bd69571965 fix(linter): fix top level return panic in eslint/array_callback_return (#4167) 2024-07-10 15:28:01 +00:00
rzvxa
67fe75ec6c feat(ast, ast_codegen): pass the scope_id to the enter_scope event. (#4168) 2024-07-10 15:19:23 +00:00
Boshen
c8f5664e0a fix(linter): fix panic with unicode in unicorn/prefer_dom_node_dataset (#4166) 2024-07-10 15:14:45 +00:00
lucab
22031430b1 perf(semantic): store unresolved refs in a stack (#4162)
This tweaks `SemanticBuilder` logic in order to accumulate unresolved
references in a stack, getting rid of the previous index-vector which
is not required under the current access pattern.

Ref: https://github.com/oxc-project/oxc/pull/4107#issuecomment-2214167393
2024-07-10 14:59:16 +00:00
Boshen
f2b32731df fix(linter): fix fixer panic in typescript/consistent_indexed_object_style (#4165) 2024-07-10 14:45:15 +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
cinchen
218814483b
feat(linter): eslint-plugin-jest/prefer-hooks-in-order (#4052)
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-hooks-in-order.ts)
2024-07-10 22:41:19 +08:00
rzvxa
3ba7cfed1f feat(ast_codegen): add #[visit(enter_before)] hint. (#4147)
Closes #4142

I can split it into 2 PRs but it seems pointless. Let me know if you guys disagree with me.
2024-07-10 14:02:29 +00:00
rzvxa
e1279da55c chore(ci): fix the formatting issues on AST Changes. (#4153)
I'm not sure what causes this issue so this PR is going to start as an experimentation
2024-07-10 13:38:05 +00:00
Boshen
725571aad1 feat(napi/transformer): add jsx option to force parsing with jsx (#4133)
To mimic the esbuild `loader=jsx` or babel `babel-plugin-syntax-jsx` behavior.
2024-07-10 11:12:10 +00:00
Boshen
54cd04aead feat(minifier): implement dce with var hoisting (#4160) 2024-07-10 11:03:21 +00:00
Boshen
44a894a2f9 feat(minifier): implement return statement dce (#4155)
This isn't complete, I need to figure out `var` hoisting 🙃
2024-07-10 11:03:14 +00:00
lucab
03ad1e32cc refactor(semantic): tweak comment argument type (#4157)
Minor followup from https://github.com/oxc-project/oxc/pull/4132.
2024-07-10 07:19:24 +00:00
Boshen
b632c0458c
chore: commit uncommited change 2024-07-10 13:44:02 +08:00
DonIsaac
cc586145ab feat(linter): better schemas for allow/warn/deny (#4150) 2024-07-10 02:51: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
Boshen
fca9706ab3
perf(semantic): faster search for leading comments (#4140)
fixes #4114

@leaysgur This is my wild guess, I need a second pairs of eyes to make
sure this is correct.
2024-07-10 09:54:26 +08:00
rzvxa
e6c407d1c3
chore(ci): add Codegen to the CI workflow. (#4144)
It should be marked as `required`.
Closes #4138

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-07-10 09:47:30 +08:00
rzvxa
bdcc2986f7 docs(ast): update the note regarding the ast_codegen markers. (#4149) 2024-07-09 22:52:08 +00:00
rzvxa
daea29c0da
chore: update the branding to use the universal variant. (#4139)
Have the same spirit as this one
https://github.com/oxc-project/.github/pull/2

Makes the `OXC` visible on any background no matter the contrast.
2024-07-09 23:32:52 +08: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
github-actions[bot]
714bf1dd7f
Release crates v0.19.0 (#4137)
## [0.19.0] - 2024-07-09

- b936162 ast/ast_builder: [**BREAKING**] Shorter allocator utility
method names. (#4122) (rzvxa)

### Features

- 485c871 ast: Allow conversion from `Expression` into `Statement` with
`FromIn` trait. (#4124) (rzvxa)

### Refactor

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-07-09 20:32:06 +08:00
rzvxa
485c871e8d feat(ast): allow conversion from Expression into Statement with FromIn trait. (#4124)
Our downstream rolldown is using this, If we want them to adopt our traits we should provide this implementation for them.

2cd2a367ee/crates/rolldown_ecmascript/src/allocator_helpers/into_in.rs (L24)
2024-07-09 12:16:40 +00: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
github-actions[bot]
e29cdbfe40
Release crates v0.18.0 (#4136)
## [0.18.0] - 2024-07-09

- d347aed ast: [**BREAKING**] Generate `ast_builder.rs`. (#3890) (rzvxa)

### Features

- c6c16a5 minifier: Dce all conditional expressions (#4135) (Boshen)
- 365d9ba oxc_codegen: Generate annotation comments before
`CallExpression` and `NewExpression` (#4119) (IWANABETHATGUY)
- 3a0f2aa parser: Check for illegal modifiers in modules and namespaces
(#4126) (DonIsaac)
- 2f53bdf semantic: Check for abstract ClassElements in non-abstract
classes (#4127) (DonIsaac)
- c4ee9f8 semantic: Check for abstract initializations and
implementations (#4125) (Don Isaac)
- 44c7fe3 span: Add various implementations of `FromIn` for `Atom`.
(#4090) (rzvxa)

### Bug Fixes

- cb1af04 isolated-declarations: Remove the `async` and `generator`
keywords from `MethodDefinition` (#4130) (Dunqing)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-07-09 19:56:10 +08:00
Boshen
c6c16a5fc9
feat(minifier): dce all conditional expressions (#4135) 2024-07-09 18:28:33 +08:00
Dunqing
cb1af043b8 fix(isolated-declarations): remove the async and generator keywords from MethodDefinition (#4130)
close: #4120
2024-07-09 03:58:47 +00:00
rzvxa
0b433108be feat(ast_codegen): add cli arguments to use with oxc_ast_codegen executable. (#4117)
```
Usage: oxc_ast_codegen [--dry-run] [--no-fmt] [--schema=ARG]

Available options:
        --dry-run     Runs all generators but won't write anything down.
        --no-fmt      Don't run cargo fmt at the end
        --schema=ARG  Path of output `schema.json`.
    -h, --help        Prints help information
```
2024-07-09 03:42:11 +00:00
rzvxa
6db630fab3 refactor(ast_codegen): cleanup usages of the generated outputs. (#4116) 2024-07-09 03:42:05 +00:00
DonIsaac
2f53bdf72d feat(semantic): check for abstract ClassElements in non-abstract classes (#4127)
feat(semantic): check for abstract ClassElements in non-abstract classes

chore: update coverage snapshots
2024-07-09 03:35:32 +00:00
DonIsaac
c5b4be021e feat(linter): add fixer for prefer-node-protocol (#4129) 2024-07-09 03:13:24 +00:00
DonIsaac
2334515247 fix(linter): panic in get_enclosing_function (#4121)
Fixes one of the panics described in #4111
2024-07-09 02:59:08 +00:00
DonIsaac
3a0f2aa7ef feat(parser): check for illegal modifiers in modules and namespaces (#4126) 2024-07-09 02:54:06 +00:00
rzvxa
d347aedfda feat(ast)!: generate ast_builder.rs. (#3890)
### Every structure has 2 builder methods:

1. `xxx` e.g. `block_statement`
```rust
    #[inline]
    pub fn block_statement(self, span: Span, body: Vec<'a, Statement<'a>>) -> BlockStatement<'a> {
        BlockStatement { span, body, scope_id: Default::default() }
    }
```
2. `alloc_xxx` e.g. `alloc_block_statement`
```rust
    #[inline]
    pub fn alloc_block_statement(
        self,
        span: Span,
        body: Vec<'a, Statement<'a>>,
    ) -> Box<'a, BlockStatement<'a>> {
        self.block_statement(span, body).into_in(self.allocator)
    }
```

### We generate 3 types of methods for enums:

1. `yyy_xxx` e.g. `statement_block`
```rust
    #[inline]
    pub fn statement_block(self, span: Span, body: Vec<'a, Statement<'a>>) -> Statement<'a> {
        Statement::BlockStatement(self.alloc(self.block_statement(span, body)))
    }
```
2. `yyy_from_xxx` e.g. `statement_from_block`
```rust
    #[inline]
    pub fn statement_from_block<T>(self, inner: T) -> Statement<'a>
    where
        T: IntoIn<'a, Box<'a, BlockStatement<'a>>>,
    {
        Statement::BlockStatement(inner.into_in(self.allocator))
    }
```
3. `yyy_xxx` where `xxx` is inherited e.g. `statement_declaration`
```rust
    #[inline]
    pub fn statement_declaration(self, inner: Declaration<'a>) -> Statement<'a> {
        Statement::from(inner)
    }
```

------------

### Generic parameters:

We no longer accept `Box<'a, ADT>`, `Atom` or `&'a str`, Instead we use `IntoIn<'a, Box<'a, ADT>>`, `IntoIn<'a, Atom<'a>>` and `IntoIn<'a, &'a str>` respectively.
It allows us to rewrite things like this:
```rust
let ident = IdentifierReference::new(SPAN, Atom::from("require"));
let number_literal_expr = self.ast.expression_numeric_literal(
    right_expr.span(),
    num,
    raw,
    self.ast.new_str(num.to_string().as_str()),
    NumberBase::Decimal,
);
```
As this:
```rust
let ident = IdentifierReference::new(SPAN, "require");
let number_literal_expr = self.ast.expression_numeric_literal(
    right_expr.span(),
    num,
    raw,
    num.to_string(),
    NumberBase::Decimal,
);
```
2024-07-09 00:57:26 +00:00
rzvxa
91c792a2ce feat(ast_codegen): add ast builder generator. (#4098) 2024-07-09 00:47:23 +00:00
Don Isaac
1b91d40da2
fix(linter): incorrect fixer for no-unused-labels (#4123) 2024-07-08 17:58:59 -04:00
Don Isaac
c4ee9f8ec6
feat(semantic): check for abstract initializations and implementations (#4125) 2024-07-08 17:30:16 -04:00
IWANABETHATGUY
365d9ba252
feat(oxc_codegen): generate annotation comments before CallExpression and NewExpression (#4119)
1. test case copy from `vue/core`, here are all usages of `#__PURE__` in
`vue/core`
https://gist.github.com/IWANABETHATGUY/c7911ecd98467a2969b2a994a34d32bc#file-pure_annotation_in_vue_repo-sh
2. Also took a look in other codebase,
https://github.com/search?q=%23__PURE__&type=code, most of the usage of
`#__PURE__` attached as leading comment before `CallExpression` and
`NewExpression`
2024-07-09 00:22:28 +08:00
rzvxa
44c7fe39ee feat(span): add various implementations of FromIn for Atom. (#4090) 2024-07-08 15:32:57 +00:00
Boshen
6e6ec748c1
chore(README): update branding 2024-07-08 22:44:19 +08:00
github-actions[bot]
c3f08ce8e0
Release crates v0.17.2 (#4115)
## [0.17.2] - 2024-07-08

### Features

- 115ac3b allocator: Introduce `FromIn` and `IntoIn` traits. (#4088)
(rzvxa)
- 720983a napi/transform: Allow setting `sourceType` to `transform`
(#4113) (Boshen)
- e386b62 semantic: Check for invalid type import assignments (#4097)
(DonIsaac)

### Bug Fixes

- 5472b7c codegen: 256 indentations level is not enough for codegen
(Boshen)
- 5c31236 isolated-declarations: Keep literal value for readonly
property (#4106) (Dunqing)
- e67c7d1 isolated-declarations: Do not infer type for private
parameters (#4105) (Dunqing)
- 3fcad5e isolated_declarations: Remove nested AssignmentPatterns from
inside parameters (#4077) (michaelm)
- f8d77e4 isolated_declarations: Infer type of template literal
expressions as string (#4068) (michaelm)
- 0f02608 semantic: Bind `TSImportEqualsDeclaration`s (#4100) (Don
Isaac)
- 4413e2d transformer: Missing initializer for readonly consructor
properties (#4103) (Don Isaac)

### Performance

- 7ed27b7 isolated-declarations: Use `FxHashSet` instead of `Vec` to
speed up the `contain` (#4074) (Dunqing)
- 9114c8e semantic: Keep a single map of unresolved references (#4107)
(Luca Bruno)

Co-authored-by: Boshen <Boshen@users.noreply.github.com>
2024-07-08 19:16:33 +08:00
Boshen
720983a965
feat(napi/transform): allow setting sourceType to transform (#4113)
closes #4071

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
2024-07-08 19:09:45 +08:00
Jelle van der Waa
2687ebc1c5
refactor(react): use find_binding helper for finding React binding (#4108)
Discovered `find_binding()` when hacking on
https://github.com/oxc-project/oxc/pull/4087 seemed like a nice
refactor.
2024-07-08 18:35:48 +08:00
Jelle van der Waa
ed4c54c0de
fix(eslint/radix): detect yield Number.parseInt variant (#4110)
The eslint rule perfer-numeric-literals has a test for the yield variant
which the radix testsuite did not have. See
https://github.com/oxc-project/oxc/pull/4109
2024-07-08 18:33:18 +08:00
Boshen
a873522ee1
chore: refresh Cargo.lock 2024-07-08 18:31:05 +08:00
Luca Bruno
9114c8e01c
perf(semantic): keep a single map of unresolved references (#4107)
This reworks `ScopeTree` in order to keep a single (root) map of
unresolved references. The `SemanticBuilder` keeps track of all
intermediate ones while walking scopes, and it can get rid of all
non-root ones once done.

Ref: https://github.com/oxc-project/backlog/issues/32
2024-07-08 16:56:13 +08:00