Commit graph

43 commits

Author SHA1 Message Date
rzvxa
49d5196e57 test(ast): fix assert_layouts.rs offset tests on 32bit platforms. (#4620) 2024-08-03 14:37:30 +00:00
rzvxa
0c52c0db02 feat(ast_codegen): add alignment and size data to the schema. (#4615)
This PR generates the layouts in the schema but doesn't use it to reorder.
2024-08-03 12:43:10 +00:00
rzvxa
bcfa2978e7 fix(ast_codegen): detect "complex" type wrappers (#4617)
Detect types such as `Cell<Option<ScopeId>>` and mark them as such! We didn't used to use this method for these options but now we have to check all types to calculate their layouts which means we need to process them correctly(instead of falling to their inner value).
2024-08-03 12:11:34 +00:00
overlookmotel
54047e021c feat(ast): GetSpanMut trait (#4609)
Closes #4606.

Introduce `GetSpanMut` trait and implement it on all AST node types.

This has to be a separate trait, rather than adding `span_mut` method to `GetSpan` because `AstKind` implements `GetSpan`, and it only has an immutable `&` ref to AST node it contains.
2024-08-02 11:50:24 +00:00
rzvxa
f39e759a53 refactor(ast_codegen): abstract passes and generators behind Runner trait. (#4556) 2024-08-02 00:08:05 +00:00
rzvxa
abc88363d7 fix(ast_codegen): create output path if doesn't exist. (#4555) 2024-08-02 00:08:02 +00:00
rzvxa
65c411eea1 feat(ast_codegen): add normalize_with to create errors from options. (#4554) 2024-08-02 00:07:59 +00:00
rzvxa
e736a5478c refactor(ast_codegen): cleanup schema generated by ast_codegen. (#4403) 2024-08-02 00:07:56 +00:00
rzvxa
26c6e80354 refactor(ast_codegen): cleanup ast_codegen. (#4392) 2024-08-02 00:07:53 +00:00
rzvxa
8685932c0b refactor(ast_codegen): use stringify for generators names. (#4388)
The generator name is always the same as its identifier so this PR changes all `"<generator_ident>"` to `stringify!(<generator_ident>)`
2024-08-02 00:07:50 +00:00
DonIsaac
c6a11bed1d docs(ast): auto-generate doc comments for AstBuilder methods (#4471)
# What This PR Does

Modifies `ast_codegen` to auto-generate rustdoc comments for generated `AstBuilder` methods. As we add more doc comments to AST node fields, the generated documentation will get better.

![image](https://github.com/user-attachments/assets/d27f0d53-38dd-4ba8-93e0-ffaf5c8e6809)
2024-07-29 15:50:28 +00:00
Dunqing
2477330440 feat(ast): add AstKind::TSExportAssignment (#4501)
part of #4488
2024-07-27 04:55:02 +00:00
Dunqing
aaee07e170 feat(ast): add AstKind::AssignmentTargetPattern, AstKind::ArrayAssignmentTarget and AstKind::ObjectAssignmentTarget (#4456)
close: #4435
2024-07-25 09:32:33 +00:00
overlookmotel
9c5d2f9d6a refactor(ast/builder): use Box::new_in over .into_in (#4428)
In `AstBuilder`'s `alloc_*` methods, use `Box::new_in` instead of `.into_in`. This is more explicit, so I feel easier to understand. It may also make life easier for compiler by not requiring it to perform type coercion.
2024-07-24 16:34:32 +00:00
rzvxa
7a3e92591f refactor(ast_codegen): better visit marker parsing. (#4371)
closes #4281
2024-07-20 17:07:24 +00:00
rzvxa
d345b84a72 feat(ast): add #[ast] attribute to non-visited AST types. (#4309)
Mark everything mentioned in https://github.com/oxc-project/oxc/pull/3815#issuecomment-2186736258 as AST.

We now error on the occurrence of non-ast items in the source of truth. It doesn't make sure that all fields and variants are `#[ast]` and therefore `repr_stable` but there are only a handful of non-AST types used here(mainly Atom and Span). Since we don't have access to the external types we can't make sure of it unless we find a way to const assert it.

The best we can do until then is to check all field/variant types to be either `#[ast]` or in a white list. I can add this check to the codegen in an upcoming PR.
2024-07-20 12:22:26 +00:00
rzvxa
5f1c7ecad7 refactor(ast): rename the visited_node marker to ast. (#4289)
closes #4282
I went with `#[ast(visit)]` but we can change it to 2 separate markers as suggested by @overlookmotel in the issue.
2024-07-20 12:02:25 +00:00
overlookmotel
1458d81268 refactor(visit): add #[inline] to empty functions (#4330)
Add `#[inline]` to empty default implementations of `enter_node` etc. Hopefully compiler will inline them automatically within Oxc even cross-crate because we compile with LTO, but maybe not for external consumers who don't use LTO.
2024-07-17 17:10:36 +00:00
Dunqing
1108f2a700 fix(semantic): resolve references to the incorrect symbol (#4280)
close: #3799
related: #3863
2024-07-17 02:50:48 +00:00
Dunqing
af4dc0112e feat(ast): align ts ast scope with typescript (#4253)
close: #3969
close: #2023

We need to add scope according to [this](d8086f14b6/src/compiler/binder.ts (L3883-L3962)). There are still some ASTs that need to be added to the scope.

---

Context from @Boshen:

Before this whole journey of fixing symbols and scopes I asked @Dunqing to debug through binder.ts via a debugger to fully understand how it does resolution.

We then agreed to align the implementation so that when a problem occurs, we can debug through both implementations and find where our problem is.

tsc doesn't have a specification, so we need to align with the reference implementation instead.
2024-07-17 02:50:47 +00:00
overlookmotel
2c7bb9f6c8 refactor(ast): pass final ScopeFlags into visit_function (#4283)
We have a strange workaround for `visit_function` where we pass in `ScopeFlags`, to support creating the scope inside `Function`, but setting different flags for `MethodDefinition`s.

Previously `visit_function` took `Option<ScopeFlags>` and then did `flags.unwrap_or(ScopeFlags::empty()) | ScopeFlags::Function` to it. Personally, I found this confusing. When I was looking at `MethodDefinition`, I was wondering "It's a function, why doesn't it set Function flag too?"

This changes makes it more explicit and clear what `ScopeFlags` everything has.
2024-07-16 07:22:07 +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
Boshen
83bd40db4e
chore: turn off doctest for all [[bin]] 2024-07-14 16:55:19 +08:00
rzvxa
aab7aaaa06 refactor(ast/visit): fire node events as the outermost one. (#4203)
I'm going to be AFK today(till about 9 PM UTC). Meanwhile, I Didn't want to be a blocker so here we go.
It would fix the #4200 merge if you guys find it in the correct order otherwise feel free to close it.
2024-07-12 03:27:59 +00:00
Boshen
8c54a2f1ed fix(tasks/ast_codegen): run cargo fmt synchronously (#4181)
relates #4152

This is my wild guess, because it works in my other script 143685deb1/xtask/src/main.rs (L21)
2024-07-11 02:59:30 +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
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
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
rzvxa
91c792a2ce feat(ast_codegen): add ast builder generator. (#4098) 2024-07-09 00:47:23 +00:00
rzvxa
aa585d31e1
fix(ast_codegen, ast): visit ExpressionArrayElement as Expression. (#4061)
hotfix for #4060

I just added an edge case, We can come back to it later on and make it a
standard in our codegen.

The diff is big because it causes the code to reorder, The edge case
generated code doesn't follow the order in which they are defined in the
source of truth(eg `js.rs`)
2024-07-06 00:29:36 +08:00
rzvxa
1854a52bd7 feat(ast_codegen): introduce the #[span] hint. (#4012)
closes #3904
2024-07-02 10:18:58 +00:00
rzvxa
71e9286fa6 improvement(ast_codegen): use visit_as attribute to create aliased AstKinds. (#4011) 2024-07-02 10:18:56 +00:00
rzvxa
352c0b4103 pref(ast): inline visit walks with small bodies. (#4009)
~~Attempt to improve the performance of visitors, It is mostly for experiments. I'm not sure how much performance is there to gain back.~~

- [x] inline plural visits (eg: visit_statements)
- [x] inline enums when there are 5 or fewer match cases
- [x] inline structs when there are 5 or less fields
- [x] inline `Visit::alloc`
2024-07-02 10:18:55 +00:00
rzvxa
b51f75baf8 refactor(ast_codegen): no longer outputs discard variable for empty visitors. (#4008) 2024-07-02 10:18:53 +00:00
rzvxa
272df6ee90 feat(ast_codegen): support for generating VisitMut. (#4006) 2024-07-02 10:18:49 +00:00
rzvxa
7538af12d8 feat(ast_codegen): add visit generator (#3954)
~~The generated code is only here for the sake of my own comparison (instead of manually keeping a backup of the old generated file). I would clean this up as soon as it is ready, submit some parts of it as the down stack, and stack the actual generated code on top of this. So please don't let the huge diff distract you, It won't have many conflicts since almost all of these are the generated visit code, which is completely contained to its own module(other than some minor renaming refactors).~~

The order of function definitions is a bit different, I've used a depth-first search, We can switch to a breadth-first one to align functions more closely to the original.
2024-07-02 10:18:45 +00:00
Boshen
1852ea4fd2
chore: clean up unused deps 2024-06-30 19:04:44 +08:00
rzvxa
71c07c59d7 improvement(ast_codegen): better output formatting. (#3932)
We use prettyplease for formatting our generated code, Which has a lot of advantages over rustfmt, But sometimes it conflicts with our cargo fmt config,
Since it isn't configurable I just added a `cargo fmt` step after the generation process to prevent conflicts.
We might be able to not rely on prettyplease at all, But We have to test that one after we have most of our generated code, rustfmt usually bails on nested calls and macros so it might not work as our only solution. In contrast to that prettyplease is used in both bindgen and cargo-expand and is created for this exact reason(formatting generated code).
2024-06-29 05:37:15 +00:00
Boshen
4cf3c7645f refactor(parser): improve parsing of TypeScript types (#3903)
- [x] fix everything
2024-06-26 05:58:16 +00:00
rzvxa
2e026e1b7f feat(ast_codegen): generate ast_kind.rs. (#3888)
[List of 68 blacklisted items](https://github.com/oxc-project/oxc/pull/3888/files#diff-59cbea4a1444e752992821d3429a5f27bf1027a530977d075ec89aa55995912aR11)
2024-06-25 15:47:04 +00:00
rzvxa
09f4d3c4d3 feat(ast_codegen): add ImplGetSpanGenerator. (#3852)
This one is ready to replace the handwritten module.
2024-06-25 14:39:39 +00:00
rzvxa
f6c4ec44ca feat(tasks/ast_codegen): prototype for codegen AST related code (#3815)
Part of https://github.com/oxc-project/oxc/issues/3819
2024-06-25 13:54:50 +00:00