Skip to content

Commit 6d031bc

Browse files
committed
feat(quote): implement jsquote! and jsquote_expr!
ref oxc-project/backlog#151 This commit introduces the `jsquote!` and `jsquote_expr!` procedural macros, which utilize the auto-derivation system to build a proto-AST when using them in order to produce in-situ Rust invocations. Inspired heavily by the infamous `quote` crate.
1 parent a278d73 commit 6d031bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+12996
-291
lines changed

.github/generated/ast_changes_watch_list.yml

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ src:
1919
- 'crates/oxc_ast/src/generated/derive_get_span.rs'
2020
- 'crates/oxc_ast/src/generated/derive_get_span_mut.rs'
2121
- 'crates/oxc_ast/src/generated/derive_take_in.rs'
22+
- 'crates/oxc_ast/src/generated/derive_to_rust.rs'
2223
- 'crates/oxc_ast/src/generated/get_id.rs'
2324
- 'crates/oxc_ast/src/serialize.rs'
2425
- 'crates/oxc_ast_macros/src/generated/mod.rs'
@@ -32,16 +33,19 @@ src:
3233
- 'crates/oxc_regular_expression/src/generated/derive_content_eq.rs'
3334
- 'crates/oxc_regular_expression/src/generated/derive_estree.rs'
3435
- 'crates/oxc_regular_expression/src/generated/derive_get_address.rs'
36+
- 'crates/oxc_regular_expression/src/generated/derive_to_rust.rs'
3537
- 'crates/oxc_span/src/generated/assert_layouts.rs'
3638
- 'crates/oxc_span/src/generated/derive_dummy.rs'
3739
- 'crates/oxc_span/src/generated/derive_estree.rs'
40+
- 'crates/oxc_span/src/generated/derive_to_rust.rs'
3841
- 'crates/oxc_span/src/source_type/mod.rs'
3942
- 'crates/oxc_span/src/span.rs'
4043
- 'crates/oxc_syntax/src/generated/assert_layouts.rs'
4144
- 'crates/oxc_syntax/src/generated/derive_clone_in.rs'
4245
- 'crates/oxc_syntax/src/generated/derive_content_eq.rs'
4346
- 'crates/oxc_syntax/src/generated/derive_dummy.rs'
4447
- 'crates/oxc_syntax/src/generated/derive_estree.rs'
48+
- 'crates/oxc_syntax/src/generated/derive_to_rust.rs'
4549
- 'crates/oxc_syntax/src/lib.rs'
4650
- 'crates/oxc_syntax/src/module_record.rs'
4751
- 'crates/oxc_syntax/src/number.rs'

Cargo.lock

+47
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ rust-version = "1.85.0"
2222
absolute_paths_not_starting_with_crate = "warn"
2323
non_ascii_idents = "warn"
2424
unit-bindings = "warn"
25-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage)', 'cfg(coverage_nightly)'] }
25+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage)', 'cfg(coverage_nightly)', 'cfg(oxc_quote_is_nightly)'] }
2626
tail_expr_drop_order = "warn"
2727
unsafe_op_in_unsafe_fn = "warn"
2828
unused_unsafe = "warn"
@@ -120,6 +120,9 @@ oxc_minifier = { version = "0.61.2", path = "crates/oxc_minifier" }
120120
oxc_napi = { version = "0.61.2", path = "crates/oxc_napi" }
121121
oxc_parser = { version = "0.61.2", path = "crates/oxc_parser", features = ["regular_expression"] }
122122
oxc_parser_napi = { version = "0.61.2", path = "napi/parser" }
123+
oxc_quote = { version = "0.61.2", path = "crates/oxc_quote" }
124+
oxc_quote_proc = { version = "0.61.2", path = "crates/oxc_quote_proc" }
125+
oxc_quote_types = { version = "0.61.2", path = "crates/oxc_quote_types" }
123126
oxc_regular_expression = { version = "0.61.2", path = "crates/oxc_regular_expression" }
124127
oxc_semantic = { version = "0.61.2", path = "crates/oxc_semantic" }
125128
oxc_span = { version = "0.61.2", path = "crates/oxc_span" }
@@ -208,6 +211,7 @@ project-root = "0.2.2"
208211
rayon = "1.10.0"
209212
ropey = "1.6.1"
210213
rust-lapper = "1.1.0"
214+
rustc_version = "0.4.1"
211215
ryu-js = "1.0.1"
212216
saphyr = "0.0.3"
213217
schemars = "0.8.21"

crates/oxc_ast/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ oxc_estree = { workspace = true }
2626
oxc_regular_expression = { workspace = true }
2727
oxc_span = { workspace = true }
2828
oxc_syntax = { workspace = true }
29+
oxc_quote_types = { workspace = true }
2930

3031
bitflags = { workspace = true }
3132
cow-utils = { workspace = true }
@@ -38,4 +39,5 @@ serialize = [
3839
"oxc_span/serialize",
3940
"oxc_syntax/serialize",
4041
"oxc_estree/serialize",
42+
"oxc_quote_types/serialize",
4143
]

crates/oxc_ast/src/ast/comment.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
use oxc_allocator::CloneIn;
33
use oxc_ast_macros::ast;
44
use oxc_estree::ESTree;
5+
use oxc_quote_types::ToRust;
56
use oxc_span::{ContentEq, Span};
67

78
/// Indicates a line or block comment.
89
#[ast]
9-
#[generate_derive(CloneIn, ContentEq, ESTree)]
10+
#[generate_derive(CloneIn, ContentEq, ESTree, ToRust)]
1011
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
1112
#[estree(no_rename_variants, no_ts_def)]
1213
pub enum CommentKind {
@@ -19,7 +20,7 @@ pub enum CommentKind {
1920

2021
/// Information about a comment's position relative to a token.
2122
#[ast]
22-
#[generate_derive(CloneIn, ContentEq)]
23+
#[generate_derive(CloneIn, ContentEq, ToRust)]
2324
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
2425
pub enum CommentPosition {
2526
/// Comments prior to a token until another token or trailing comment.
@@ -42,7 +43,7 @@ pub enum CommentPosition {
4243

4344
/// Annotation comment that has special meaning.
4445
#[ast]
45-
#[generate_derive(CloneIn, ContentEq)]
46+
#[generate_derive(CloneIn, ContentEq, ToRust)]
4647
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
4748
pub enum CommentAnnotation {
4849
/// No Annotation
@@ -79,7 +80,7 @@ pub enum CommentAnnotation {
7980

8081
/// A comment in source code.
8182
#[ast]
82-
#[generate_derive(CloneIn, ContentEq, ESTree)]
83+
#[generate_derive(CloneIn, ContentEq, ESTree, ToRust)]
8384
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
8485
#[estree(add_fields(value = CommentValue), field_order(kind, value, span), no_ts_def)]
8586
pub struct Comment {

0 commit comments

Comments
 (0)