diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-11-10 03:53:31 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 17:23:31 +0530 |
commit | bc33a4b2e06dd5518e0d1bbf7b538d0b00df214d (patch) | |
tree | e139e95178892521ecb5807959e324422ed29045 /ops/deno.rs | |
parent | 92764c0decb370b0f8a78770314ceda7228d315f (diff) |
refactor(ops): Rewrite fast call optimizer and codegen (#16514)
Diffstat (limited to 'ops/deno.rs')
-rw-r--r-- | ops/deno.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/ops/deno.rs b/ops/deno.rs new file mode 100644 index 000000000..67af603e9 --- /dev/null +++ b/ops/deno.rs @@ -0,0 +1,32 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. + +use proc_macro2::{Span, TokenStream}; +use proc_macro_crate::{crate_name, FoundCrate}; +use quote::quote; +use syn::Ident; + +/// Identifier to the `deno_core` crate. +/// +/// If macro called in deno_core, `crate` is used. +/// If macro called outside deno_core, `deno_core` OR the renamed +/// version from Cargo.toml is used. +pub(crate) fn import() -> TokenStream { + let found_crate = + crate_name("deno_core").expect("deno_core not present in `Cargo.toml`"); + + match found_crate { + FoundCrate::Itself => { + // TODO(@littledivy): This won't work for `deno_core` examples + // since `crate` does not refer to `deno_core`. + // examples must re-export deno_core to make this work + // until Span inspection APIs are stabalized. + // + // https://github.com/rust-lang/rust/issues/54725 + quote!(crate) + } + FoundCrate::Name(name) => { + let ident = Ident::new(&name, Span::call_site()); + quote!(#ident) + } + } +} |