swc_common/
lib.rs

1//! Utilities for the swc project
2//!
3//!
4//! # Cargo features
5//!
6//! ## `tty-emitter`
7//!
8//! Adds default implementation of Emitter.
9//! Enabling this feature will add tty-related dependencies.
10//!
11//! ## `sourcemap`
12//!
13//! Adds methods to generate web sourcemap.
14//!
15//! ## `plugin-base`
16//!
17//! Base mode for plugins, which can be enabled by `plugin-mode` or `plugin-rt`.
18//!
19//! This mode creates a trait which can be used to override `swc_common` itself.
20//!
21//! ## `plugin-rt`
22//!
23//! Creates an implementation for the plugin trait. This implements simply
24//! invokes thread-locals declared in `swc_common`.
25//!
26//! ## `plugin-mode`
27//!
28//! Allows replacing operations related to thread-local variables with a trait.
29#![deny(clippy::all)]
30#![cfg_attr(docsrs, feature(doc_cfg))]
31#![cfg_attr(not(test), allow(unused))]
32
33use std::fmt::Debug;
34
35pub use ast_node::{ast_node, ast_serde, DeserializeEnum, Spanned};
36pub use from_variant::FromVariant;
37pub use swc_eq_ignore_macros::{EqIgnoreSpan, TypeEq};
38
39pub use self::{
40    eq::{EqIgnoreSpan, TypeEq},
41    errors::{SourceMapper, SourceMapperDyn},
42    pos::{
43        hygiene, BytePos, CharPos, FileName, Globals, Loc, LocWithOpt, Mark, MultiSpan, SourceFile,
44        SourceFileAndBytePos, SourceFileAndLine, Span, SpanLinesError, Spanned, SyntaxContext,
45        DUMMY_SP, GLOBALS, NO_EXPANSION,
46    },
47    source_map::{FileLines, FileLoader, FilePathMapping, SourceMap, SpanSnippetError},
48    syntax_pos::LineCol,
49};
50
51/// A trait for ast nodes.
52pub trait AstNode: Debug + PartialEq + Clone + Spanned {
53    const TYPE: &'static str;
54}
55
56pub mod cache;
57pub mod comments;
58mod eq;
59pub mod errors;
60pub mod input;
61pub mod iter;
62pub mod pass;
63pub mod plugin;
64mod pos;
65#[doc(hidden)]
66pub mod private;
67mod rustc_data_structures;
68pub mod serializer;
69pub mod source_map;
70pub mod sync;
71mod syntax_pos;
72pub mod util;
73
74#[cfg(all(not(debug_assertions), feature = "plugin-rt", feature = "plugin-mode"))]
75compile_error!("You can't enable `plugin-rt` and `plugin-mode` at the same time");
76
77/// Warning: The particular implementation of serialization and deserialization
78/// of the ast nodes may change in the future, and so these types would be
79/// removed. It's safe to say they will be serializable in some form or another,
80/// but not necessarily with these specific types underlying the implementation.
81/// As such, *use these types at your own risk*.
82#[cfg(feature = "rkyv-impl")]
83#[doc(hidden)]
84pub use self::syntax_pos::{
85    ArchivedBytePos, ArchivedCharPos, ArchivedFileName, ArchivedMultiSpan, ArchivedSourceFile,
86    ArchivedSourceFileAndBytePos, ArchivedSpan, ArchivedSpanLinesError, ArchivedSpanSnippetError,
87};