diff --git a/common/Cargo.toml b/common/Cargo.toml index 4bea40da7be3..153a150f1e3c 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" license = "Apache-2.0/MIT" name = "swc_common" repository = "https://github.com/swc-project/swc.git" -version = "0.10.5" +version = "0.10.6" [features] concurrent = ["parking_lot"] diff --git a/common/src/errors.rs b/common/src/errors.rs index fb17cb09d2c8..7cfe387d1629 100644 --- a/common/src/errors.rs +++ b/common/src/errors.rs @@ -7,13 +7,12 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#[cfg(feature = "tty-emitter")] -pub use self::emitter::EmitterWriter; + use self::Level::*; pub use self::{ diagnostic::{Diagnostic, DiagnosticId, DiagnosticStyledString, SubDiagnostic}, diagnostic_builder::DiagnosticBuilder, - emitter::{ColorConfig, Emitter}, + emitter::{ColorConfig, Emitter, EmitterWriter}, }; #[cfg(feature = "tty-emitter")] use crate::sync::Lrc; diff --git a/common/src/errors/emitter.rs b/common/src/errors/emitter.rs index 8e82fe565b90..28a757148308 100644 --- a/common/src/errors/emitter.rs +++ b/common/src/errors/emitter.rs @@ -8,40 +8,29 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[cfg(feature = "tty-emitter")] use self::Destination::*; -#[cfg(feature = "tty-emitter")] -use super::snippet::{Annotation, Line}; -use super::DiagnosticBuilder; -#[cfg(feature = "tty-emitter")] use super::{ - snippet::{AnnotationType, MultilineAnnotation, Style, StyledString}, + snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, Style, StyledString}, styled_buffer::StyledBuffer, - CodeSuggestion, DiagnosticId, Level, SourceMapperDyn, SubDiagnostic, + CodeSuggestion, DiagnosticBuilder, DiagnosticId, Level, SourceMapperDyn, SubDiagnostic, +}; +use crate::{ + sync::Lrc, + syntax_pos::{MultiSpan, SourceFile, Span}, }; -#[cfg(feature = "tty-emitter")] -use crate::sync::Lrc; -#[cfg(feature = "tty-emitter")] -use crate::syntax_pos::SourceFile; -#[cfg(feature = "tty-emitter")] -use crate::syntax_pos::{MultiSpan, Span}; #[cfg(feature = "tty-emitter")] use atty; -#[cfg(feature = "tty-emitter")] -use std::borrow::Cow; -#[cfg(feature = "tty-emitter")] -use std::cmp::{min, Reverse}; -#[cfg(feature = "tty-emitter")] -use std::collections::HashMap; -use std::io::{self, prelude::*}; -#[cfg(feature = "tty-emitter")] -use std::ops::Range; +use std::{ + borrow::Cow, + cmp::{min, Reverse}, + collections::HashMap, + io::{self, prelude::*}, + ops::Range, +}; #[cfg(feature = "tty-emitter")] use termcolor::{Buffer, BufferWriter, Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; -#[cfg(feature = "tty-emitter")] use unicode_width; -#[cfg(feature = "tty-emitter")] const ANONYMIZED_LINE_NUM: &str = "LL"; /// Emitter trait for emitting errors. @@ -55,7 +44,6 @@ pub trait Emitter: crate::sync::Send { } } -#[cfg(feature = "tty-emitter")] impl Emitter for EmitterWriter { fn emit(&mut self, db: &DiagnosticBuilder<'_>) { let mut primary_span = db.span.clone(); @@ -144,7 +132,6 @@ impl ColorConfig { } } -#[cfg(feature = "tty-emitter")] pub struct EmitterWriter { dst: Destination, sm: Option>, @@ -153,7 +140,6 @@ pub struct EmitterWriter { ui_testing: bool, } -#[cfg(feature = "tty-emitter")] struct FileWithAnnotatedLines { file: Lrc, lines: Vec, @@ -177,7 +163,9 @@ impl EmitterWriter { ui_testing: false, } } +} +impl EmitterWriter { pub fn new( dst: Box, source_map: Option>, @@ -1395,17 +1383,14 @@ impl EmitterWriter { } } -#[cfg(feature = "tty-emitter")] fn draw_col_separator(buffer: &mut StyledBuffer, line: usize, col: usize) { buffer.puts(line, col, "| ", Style::LineNumber); } -#[cfg(feature = "tty-emitter")] fn draw_col_separator_no_space(buffer: &mut StyledBuffer, line: usize, col: usize) { draw_col_separator_no_space_with_style(buffer, line, col, Style::LineNumber); } -#[cfg(feature = "tty-emitter")] fn draw_col_separator_no_space_with_style( buffer: &mut StyledBuffer, line: usize, @@ -1415,7 +1400,6 @@ fn draw_col_separator_no_space_with_style( buffer.putc(line, col, '|', style); } -#[cfg(feature = "tty-emitter")] fn draw_range( buffer: &mut StyledBuffer, symbol: char, @@ -1429,12 +1413,10 @@ fn draw_range( } } -#[cfg(feature = "tty-emitter")] fn draw_note_separator(buffer: &mut StyledBuffer, line: usize, col: usize) { buffer.puts(line, col, "= ", Style::LineNumber); } -#[cfg(feature = "tty-emitter")] fn draw_multiline_line( buffer: &mut StyledBuffer, line: usize, @@ -1445,7 +1427,6 @@ fn draw_multiline_line( buffer.putc(line, offset + depth - 1, '|', style); } -#[cfg(feature = "tty-emitter")] fn num_overlap( a_start: usize, a_end: usize, @@ -1459,7 +1440,7 @@ fn num_overlap( } contains(b_start..b_end + extra, a_start) || contains(a_start..a_end + extra, b_start) } -#[cfg(feature = "tty-emitter")] + fn overlaps(a1: &Annotation, a2: &Annotation, padding: usize) -> bool { num_overlap( a1.start_col, @@ -1470,7 +1451,6 @@ fn overlaps(a1: &Annotation, a2: &Annotation, padding: usize) -> bool { ) } -#[cfg(feature = "tty-emitter")] fn emit_to_destination( rendered_buffer: &[Vec], lvl: Level, @@ -1498,6 +1478,7 @@ fn emit_to_destination( let _buffer_lock = lock::acquire_global_lock("rustc_errors"); for (pos, line) in rendered_buffer.iter().enumerate() { for part in line { + #[cfg(feature = "tty-emitter")] dst.apply_style(lvl, part.style)?; write!(dst, "{}", part.text)?; dst.reset()?; @@ -1543,7 +1524,6 @@ impl Destination { } } - #[cfg(feature = "tty-emitter")] fn writable(&mut self) -> WritableDst<'_> { match *self { #[cfg(feature = "tty-emitter")] @@ -1607,16 +1587,19 @@ impl<'a> WritableDst<'a> { #[cfg(feature = "tty-emitter")] fn set_color(&mut self, color: &ColorSpec) -> io::Result<()> { match *self { + #[cfg(feature = "tty-emitter")] WritableDst::Terminal(ref mut t) => t.set_color(color), + #[cfg(feature = "tty-emitter")] WritableDst::Buffered(_, ref mut t) => t.set_color(color), WritableDst::Raw(_) => Ok(()), } } - #[cfg(feature = "tty-emitter")] fn reset(&mut self) -> io::Result<()> { match *self { + #[cfg(feature = "tty-emitter")] WritableDst::Terminal(ref mut t) => t.reset(), + #[cfg(feature = "tty-emitter")] WritableDst::Buffered(_, ref mut t) => t.reset(), WritableDst::Raw(_) => Ok(()), } diff --git a/common/src/errors/lock.rs b/common/src/errors/lock.rs index 617778ad9589..07d76b47fcaf 100644 --- a/common/src/errors/lock.rs +++ b/common/src/errors/lock.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg(feature = "tty-emitter")] - //! Bindings to acquire a global named lock. //! //! This is intended to be used to synchronize multiple compiler processes to diff --git a/common/src/errors/snippet.rs b/common/src/errors/snippet.rs index 98b8f139c0bf..dd1668fa6067 100644 --- a/common/src/errors/snippet.rs +++ b/common/src/errors/snippet.rs @@ -12,14 +12,12 @@ use super::Level; -#[cfg(feature = "tty-emitter")] #[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct Line { pub line_index: usize, pub annotations: Vec, } -#[cfg(feature = "tty-emitter")] #[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct MultilineAnnotation { pub depth: usize, @@ -31,7 +29,6 @@ pub struct MultilineAnnotation { pub label: Option, } -#[cfg(feature = "tty-emitter")] impl MultilineAnnotation { pub fn increase_depth(&mut self) { self.depth += 1; @@ -68,7 +65,6 @@ impl MultilineAnnotation { } } -#[cfg(feature = "tty-emitter")] #[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)] pub enum AnnotationType { /// Annotation under a single line of code @@ -98,7 +94,6 @@ pub enum AnnotationType { MultilineLine(usize), } -#[cfg(feature = "tty-emitter")] #[derive(Clone, Debug, PartialOrd, Ord, PartialEq, Eq)] pub struct Annotation { /// Start column, 0-based indexing -- counting *characters*, not @@ -121,7 +116,6 @@ pub struct Annotation { pub annotation_type: AnnotationType, } -#[cfg(feature = "tty-emitter")] impl Annotation { /// Whether this annotation is a vertical line placeholder. pub fn is_line(&self) -> bool { diff --git a/common/src/errors/styled_buffer.rs b/common/src/errors/styled_buffer.rs index bdb4b0f2108e..2df9be2e59c3 100644 --- a/common/src/errors/styled_buffer.rs +++ b/common/src/errors/styled_buffer.rs @@ -10,8 +10,6 @@ // Code for creating styled buffers -#![cfg(feature = "tty-emitter")] - use super::snippet::{Style, StyledString}; #[derive(Debug)]