2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2022-11-25 09:47:21 -05:00
|
|
|
#![cfg(not(test))]
|
2022-11-10 06:53:31 -05:00
|
|
|
|
2023-01-14 23:18:58 -05:00
|
|
|
use proc_macro2::Span;
|
|
|
|
use proc_macro2::TokenStream;
|
|
|
|
use proc_macro_crate::crate_name;
|
|
|
|
use proc_macro_crate::FoundCrate;
|
2022-11-10 06:53:31 -05:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|