mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
d5634164cb
Closes https://github.com/denoland/deno/issues/2699 Closes https://github.com/denoland/deno/issues/2347 Uses unstable rustfmt features. Since dprint invokes `rustfmt` we do not need to switch the cargo toolchain to nightly. Do we care about formatting stability of our codebase across Rust versions? (I don't)
35 lines
1.1 KiB
Rust
35 lines
1.1 KiB
Rust
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
|
#![cfg(not(test))]
|
|
|
|
use proc_macro2::Span;
|
|
use proc_macro2::TokenStream;
|
|
use proc_macro_crate::crate_name;
|
|
use proc_macro_crate::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)
|
|
}
|
|
}
|
|
}
|