-
-
Notifications
You must be signed in to change notification settings - Fork 554
feat(quote): implement jsquote!
and jsquote_expr!
#10116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
Hi! I'm I would like to apply some automated changes to this pull request, but it looks like I don't have the necessary permissions to do so. To get this pull request into a mergeable state, please do one of the following two things:
|
CodSpeed Instrumentation Performance ReportMerging #10116 will not alter performanceComparing Summary
Benchmarks breakdown
|
I'm grappling a bit with substitutions. All of the differentiating types ( Throwing an Further, doing what So for now, I'll just add as many exceptions as I can with the hopes that maybe someday this can be formalized in a bit more of a generic way. |
Another way to go about this is to have a dedicated set of utility types that can be converted into various like-types. For example: let a = oxc_allocator::Allocator::default();
let s = oxc_span::Span::empty(0);
let ident = oxc_quote::Ident(&a, s, "foobar");
let _ = jsquote!(&a, s, {
var #ident = 10;
console.log(#ident);
}); Which would expand to something like... // ...
VariableDeclarator {
// ...
id: BindingPattern {
kind: ident.into(), // Ident -> BindingPatternKind::BindingIdentifier(...)
// ...
},
// ...
}
// ...
{
arguments: [
ident.into() // Ident -> Argument::IdentifierReference(...)
]
} But it might actually be easier to implement a flag in the parser to explicitly parse template variables as AST nodes. I might try that approach too. |
6d031bc
to
d90cf82
Compare
For some reason I'm getting this on CI, but I can't reproduce locally by running the same command. error[E0609]: no field `lossy` on type `&ast::literal::StringLiteral<'_>`
--> crates/oxc_ast/src/generated/derive_to_rust.rs:5726:32
|
57[26](https://github.com/oxc-project/oxc/actions/runs/14159257451/job/39662477714?pr=10116#step:4:27) | ("lossy", self.lossy.to_rust())
| ^^^^^ unknown field
|
= note: available fields are: `span`, `value`, `raw`, `lone_surrogates` Also, grepping for |
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.
Thank you for working on this great staff! We will take a look at this later. |
Hi! This is just a draft. Wanted to see what you might think about this implementation for a
quote!
-like macro for OXC, inspired heavily by the infamousquote
crate. Please just consider it a proposal; if it isn't the best way forward for this, that's alright too.ref oxc-project/backlog#151
This commit introduces the
jsquote!
andjsquote_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.jsquote_expr!
returns anExpression<'_>
and uses.parse_expression()
jsquote!
returns aVec<'_, Statement<'_>>
and uses.parse()
It only has half of the placeholder implementation right now but anything without placeholders should work as you'd expect.They are implemented in the latest commit but have a few caveats (see comments below).I want to say up-front that there are some really unfortunate hacks in the proc macro to make this work on stable. Nothing "unsafe", just fragile. Until some of the long-time unstable features are no longer so, they can be improved.
I've also tried to enable the unstable features automatically depending on which compiler is used (I did it the way I did, instead of using features, since all the CI runs with
--all-features
, but I didn't want to muck with therust-toolchain.toml
and cause a bigger stir than this PR probably already does).