Commit graph

75 commits

Author SHA1 Message Date
rzvxa
0ea697b4e9 refactor(ast, ast_codegen): CloneIn implementations now initialize semantic related cells with Default value. (#4819)
closes #4809
2024-08-11 19:10:56 +00:00
rzvxa
74af8e230a refactor(ast_codegen): Simplify InnerMarkers. (#4812) 2024-08-11 18:42:54 +00:00
overlookmotel
92777d0aae refactor(ast_codegen): replace ///@@ with ///@@line_break (#4786)
Follow-on after #4778. `///@@line_break` is more verbose, but it's clearer what it does.
2024-08-09 10:52:22 +00:00
overlookmotel
ec82a79ebe refactor(ast_codegen): trim r# from start of field names (#4785)
Some struct fields are reserved names e.g. `type`. They are written in source as `r#type`. Trim off the `r#` prefix in `FieldDef::name` and add it back when generating output.

Main motivation is to have the unescaped field names in JSON schema.
2024-08-09 10:52:21 +00:00
overlookmotel
31311877f1 refactor(ast_codegen): alter JSON schema format (#4784)
Change the format of schema JSON by altering `serde` attrs.
2024-08-09 10:52:20 +00:00
overlookmotel
c79ca40b77 refactor(ast_codegen): remove excess space from start of doc comments (#4782)
I noticed that in JSON schema the `docs` property contains e.g. `" The name of the identifier being referenced."` (with an excess space on the start). Trim that off.
2024-08-09 10:25:28 +00:00
overlookmotel
d4a3be86ed refactor(ast_codegen): line breaks between types in layout assertions (#4781)
Small style nit. Add line breaks between types in generated layout assertions, to make the file easier to read.
2024-08-09 10:17:21 +00:00
overlookmotel
966fcc925a refactor(ast_codegen): re-order code in fmt module (#4779)
Pure refactor. Just move code which is most used to top of `fmt` module. And rename `pprint` to `pretty_print` to be a little clearer.
2024-08-09 10:01:14 +00:00
overlookmotel
2c1c7050ea refactor(ast_codegen): use doc comments instead of endl! (#4778)
Similar to #4777.

Use `///@@` instead of `endl!();` in AST codegen to create line breaks.

NB: `///@@` needs to be before an item, not after it.
2024-08-09 08:57:18 +00:00
overlookmotel
f418f62e7b refactor(ast_codegen): use doc comments instead of insert! (#4777)
Avoid the `insert!` macro in AST codegen. Use doc comments starting with special symbol `@` instead.

* Before: `insert!("// plain comment");`
* After: `///@ plain comment`
* Or: `//!@ plain comment`

Either `///@` or `//!@` is converted to plain `//` in output.

`//!@` is legal in top-of-file position, which allows us to inline `#![allow(...)]` attributes, which in my opinion makes the generators a bit easier to read.
2024-08-09 08:19:15 +00:00
overlookmotel
c15c931a3f refactor(ast_codegen): move formatting regex definitions (#4775)
Pure refactor. Move the regex definitions used in formatting to next to the `Replacer`s for those regexes.
2024-08-09 07:48:13 +00:00
overlookmotel
dbb5f4c75e refactor(ast_codegen): remove unnecessary imports from generated files (#4774)
#4773 makes types like `Span` importable from `oxc_ast::ast`, so remove the imports from other crates in generated code.

I'm not sure why clippy's `wildcard_imports` rule was not being triggered for `use crate::ast::*;`, but add `#[allow(clippy::wildcard_imports)]` on these statements just to make sure.
2024-08-09 07:48:09 +00:00
rzvxa
fff9da319d fix(ast, ast_codegen): use generate_derive instead of visitable for generating span derives. (#4747)
follow-up to #4735
I was accidentally using the old code to filter the viable target types to derive. It means before this PR we were still using the `#[ast(visit)]` for this purpose.
2024-08-08 17:06:48 +00:00
rzvxa
abe8202ba8 refactor(ast_codegen): declutter the main file. (#4744)
same as #4741
2024-08-08 16:38:13 +00:00
overlookmotel
7345f68d9e refactor(ast_codegen): remove Generator::name and Pass::name methods (#4764)
Remove `Generator::name` and `Pass::name` methods. All impls for these methods return a string identical to the struct name, so can set return value of `Runner::name` in `define_generator!` and `define_pass!` macros instead.
2024-08-08 15:39:10 +00:00
overlookmotel
d32fb6f5c5 refactor(ast_codegen): re-order imports (#4763)
Move imports to top of file in `generators/mod.rs`, just for consistency.
2024-08-08 15:39:09 +00:00
overlookmotel
80046d1144 refactor(ast_codegen): consistent endl! position (#4762)
Pure refactor (style nit). Place `endl!()` macro calls in consistent position throughout codegen.
2024-08-08 15:39:08 +00:00
overlookmotel
2dea0caae0 refactor(ast_codegen): consistent import order (#4761)
Pure refactor. Alter import order in generated code to consistent order - `std`, external crates, `crate`, `super`.
2024-08-08 15:24:45 +00:00
overlookmotel
790c551c5e refactor(ast_codegen): simplify derive_get_span generator (#4757)
Simplify `derive_get_span` generator that was introduced in #4735. No change to functionality, just aiming for greater readability.

In particular:

* Move defining idents/tokens which are specific to `GetSpan` / `GetSpanMut` into those specific generators, rather than branching on `MUT` later on.
* Remove `const MUT` param.
* Remove the confusing pairs of closures and functions both called `derive_enum` / `derive_struct`.
* Inline function which generates the impls - prioritizing readability over DRY code.
2024-08-08 10:47:37 +00:00
overlookmotel
f36500a2bd refactor(ast_codegen): flatten code (#4743)
A bit of code style simplification after #4731. Remove unnecessary nesting and rename some vars for consistency.
2024-08-07 22:32:07 +00:00
rzvxa
aeed29f248 chore(ci): generate .generated_ast_watch_list.yml (#4737)
closes #4699

I also did some reordering to the code so it is easier to follow.
2024-08-07 22:11:34 +00:00
rzvxa
2218340f2b refactor(ast, ast_codegen): use generate_derive for implementing GetSpan and GetSpanMut traits. (#4735) 2024-08-07 22:07:33 +00:00
rzvxa
579b797cc5 refactor(ast): use type identifier instead of CloneIn::Cloned GAT. (#4738)
After https://github.com/oxc-project/oxc/pull/4731#discussion_r1707526289, I realized that I'm using `Self::Cloned` for enum derives. It was from my earlier attempts to resolve lifetime issues.
2024-08-07 21:23:23 +00:00
rzvxa
ec0b4cbdaa feat(ast_codegen): add derive_clone_in generator. (#4731)
Follow-on after #4276, related to #4284.
2024-08-07 20:29:06 +00:00
rzvxa
2e91ad6c4e feat(ast_codegen): support for generate_derive marker. (#4728)
Follow-on after #4276, related to #4284.
2024-08-07 17:38:13 +00:00
overlookmotel
06efae6e4c refactor(ast_codegen): reorder imports (#4709)
Pure refactor. Reorder imports to clarify what's an external crate and what's a local module.
2024-08-06 20:38:42 +00:00
overlookmotel
654a6e67fa refactor(ast_codegen): list input files explicitly (#4708)
List inputs to the codegen explicitly. This is less DRY, but I think it has the advantage of being more obvious - for #4704.
2024-08-06 19:14:05 +00:00
overlookmotel
07607d3e94 feat(ast_codegen, span): process Span through ast_codegen (#4703)
Add `#[ast]` attr to `Span`.

Due to how AST codegen works, this necessitates putting the type def in a separate file. https://github.com/oxc-project/oxc/pull/4696#issuecomment-2271781995
2024-08-06 18:22:22 +00:00
rzvxa
125c5fd8ed feat(ast_codegen, span): process SourceType through ast_codegen. (#4696) 2024-08-06 17:42:12 +00:00
rzvxa
82e2f6b924 feat(ast_codegen): process AST-related syntax types. (#4694) 2024-08-06 17:14:35 +00:00
rzvxa
b04dc3d026 refactor(ast_codegen): disallow implicit enum discriminants on #[ast] types. (#4690) 2024-08-06 17:14:33 +00:00
rzvxa
1690a57ed3 refactor(ast_codegen): move away from RType in generators. (#4682)
This PR introduces `EarlyCtx` and `LateCtx` in place of the old `CodegenCtx`, Early passes operate at the AST level while generators and other late passes operate on the schema.

It will also replace the confusing `RType` name with something more idiomatic ~~(open for suggestions, I haven't found a good name yet)~~ I've named it `AstType` and dropped the `R` prefix for `REnum` and `RStruct`.

There are some qualities of life improvements too, Things like `to_type_elide` can be used to simplify the code.

Related to #4442 (and can potentially mark it "close as fixed").
2024-08-06 17:14:31 +00:00
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