Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ crate-type = ["rlib"]
[features]
default = ["bundler", "nodejs", "sourcemap"]
browserslist = ["browserslist-rs"]
bundler = ["dashmap", "sourcemap", "rayon"]
bundler = ["dashmap", "custom_sourcemap", "rayon"]
cli = ["clap", "serde_json", "browserslist", "jemallocator"]
jsonschema = ["schemars", "serde", "rspack-lightningcss-selectors/jsonschema"]
nodejs = ["dep:serde", "dep:serde-content"]
Expand All @@ -62,7 +62,9 @@ serde = [
"rspack-lightningcss-selectors/serde",
"into_owned",
]
sourcemap = ["parcel_sourcemap"]
# Keep the existing feature name as a compatibility alias.
sourcemap = ["custom_sourcemap"]
custom_sourcemap = ["parcel_sourcemap"]
visitor = []
into_owned = [
"rspack-lightningcss-static-self",
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32661,7 +32661,7 @@ b\0 c');
}

#[test]
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
fn test_url_quoting_source_map() {
let stylesheet = StyleSheet::parse(
r#"
Expand Down Expand Up @@ -32699,7 +32699,7 @@ b\0 c');
}

#[test]
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
fn test_input_source_map() {
let source = r#".imported {
content: "yay, file support!";
Expand Down Expand Up @@ -32734,7 +32734,7 @@ b\0 c');
}

#[test]
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
fn test_source_maps_with_license_comments() {
let source = r#"/*! a single line comment */
/*!
Expand Down
30 changes: 15 additions & 15 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::selector::SelectorList;
use crate::targets::{Targets, TargetsWithSupportsScope};
use crate::vendor_prefix::VendorPrefix;
use cssparser::{serialize_identifier, serialize_name};
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
use parcel_sourcemap::{OriginalLocation, SourceMap};
use std::fmt::Write;

Expand All @@ -17,8 +17,8 @@ pub struct PrinterOptions<'a> {
/// Whether to minify the CSS, i.e. remove white space.
pub minify: bool,
/// An optional reference to a source map to write mappings into.
#[cfg(feature = "sourcemap")]
#[cfg_attr(docsrs, doc(cfg(feature = "sourcemap")))]
#[cfg(feature = "custom_sourcemap")]
#[cfg_attr(docsrs, doc(cfg(feature = "custom_sourcemap")))]
pub source_map: Option<&'a mut SourceMap>,
/// An optional project root path, used to generate relative paths for sources used in CSS module hashes.
pub project_root: Option<&'a str>,
Expand All @@ -41,7 +41,7 @@ impl<'a> Default for PrinterOptions<'a> {
fn default() -> Self {
PrinterOptions {
minify: false,
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
source_map: None,
project_root: None,
targets: Targets::default(),
Expand Down Expand Up @@ -96,17 +96,17 @@ pub struct Printer<'a, 'c, W> {
dest: &'a mut W,
pub(crate) options: PrinterOptions<'a>,
pub(crate) state: PrinterState<'a, 'c>,
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
pub(crate) source_map: Option<&'a mut SourceMap>,
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
pub(crate) source_maps: Vec<Option<SourceMap>>,
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
pub(crate) source_map_source_indices: &'c [Option<u32>],
}

impl<'a, 'c, W: std::fmt::Write + Sized> Printer<'a, 'c, W> {
/// Create a new Printer wrapping the given destination.
#[cfg_attr(not(feature = "sourcemap"), allow(unused_mut))]
#[cfg_attr(not(feature = "custom_sourcemap"), allow(unused_mut))]
pub fn new(dest: &'a mut W, mut options: PrinterOptions<'a>) -> Self {
let dependencies = if options.analyze_dependencies.is_some() {
Some(Vec::new())
Expand All @@ -117,7 +117,7 @@ impl<'a, 'c, W: std::fmt::Write + Sized> Printer<'a, 'c, W> {
Printer {
sources: None,
dest,
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
source_map: options.source_map.take(),
state: PrinterState {
loc: Location {
Expand All @@ -137,9 +137,9 @@ impl<'a, 'c, W: std::fmt::Write + Sized> Printer<'a, 'c, W> {
context: None,
},
options,
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
source_maps: Vec::new(),
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
source_map_source_indices: &[],
}
}
Expand Down Expand Up @@ -307,8 +307,8 @@ impl<'a, 'c, W: std::fmt::Write + Sized> Printer<'a, 'c, W> {
}

/// Adds a mapping to the source map, if any.
#[cfg(feature = "sourcemap")]
#[cfg_attr(docsrs, doc(cfg(feature = "sourcemap")))]
#[cfg(feature = "custom_sourcemap")]
#[cfg_attr(docsrs, doc(cfg(feature = "custom_sourcemap")))]
pub fn add_mapping(&mut self, loc: Location) {
self.state.loc = loc;

Expand Down Expand Up @@ -481,7 +481,7 @@ pub trait PrinterTrait: std::fmt::Write + private::Sealed {
fn whitespace(&mut self) -> Result<(), PrinterError>;
fn delim(&mut self, c: char, ws_before: bool) -> Result<(), PrinterError>;
fn newline(&mut self) -> Result<(), PrinterError>;
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
fn add_mapping(&mut self, loc: Location);
fn indent(&mut self);
fn dedent(&mut self);
Expand Down Expand Up @@ -604,7 +604,7 @@ impl<'a, 'c, W: std::fmt::Write + Sized> PrinterTrait for Printer<'a, 'c, W> {
Printer::newline(self)
}

#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
fn add_mapping(&mut self, loc: Location) {
Printer::add_mapping(self, loc)
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl<'i, T: Clone> ContainerRule<'i, T> {

impl<'a, 'i, T: ToCss> ToCss for ContainerRule<'i, T> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@container ")?;
let has_condition = self.condition.is_some();
Expand Down
2 changes: 1 addition & 1 deletion src/rules/counter_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct CounterStyleRule<'i> {

impl<'i> ToCss for CounterStyleRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@counter-style ")?;
self.name.to_css(dest)?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/custom_media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct CustomMediaRule<'i> {

impl<'i> ToCss for CustomMediaRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@custom-media ")?;
self.name.to_css(dest)?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'i, T: Clone> MozDocumentRule<'i, T> {

impl<'i, T: ToCss> ToCss for MozDocumentRule<'i, T> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@-moz-document url-prefix()")?;
dest.whitespace()?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/font_face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ impl<'i> RuleBodyItemParser<'i, FontFaceProperty<'i>, ParserError<'i>> for FontF

impl<'i> ToCss for FontFaceRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@font-face")?;
dest.whitespace()?;
Expand Down
4 changes: 2 additions & 2 deletions src/rules/font_feature_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl<'a, 'i> RuleBodyItemParser<'i, (), ParserError<'i>> for FontFeatureValuesRu

impl<'i> ToCss for FontFeatureValuesRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@font-feature-values ")?;
self.name.to_css(dest)?;
Expand Down Expand Up @@ -237,7 +237,7 @@ pub struct FontFeatureSubrule<'i> {

impl<'i> ToCss for FontFeatureSubrule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_char('@')?;
self.name.to_css(dest)?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/font_palette_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ impl<'i> FontPaletteValuesRule<'i> {

impl<'i> ToCss for FontPaletteValuesRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@font-palette-values ")?;
self.name.to_css(dest)?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'i> ToCss for ImportRule<'i> {
} else {
None
};
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@import ")?;
if let Some(dep) = dep {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/keyframes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl<'i> KeyframesRule<'i> {

impl<'i> ToCss for KeyframesRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
let mut first_rule = true;
macro_rules! write_prefix {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub struct LayerStatementRule<'i> {

impl<'i> ToCss for LayerStatementRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@layer ")?;
self.names.to_css(dest)?;
Expand Down Expand Up @@ -137,7 +137,7 @@ impl<'i, T: Clone> LayerBlockRule<'i, T> {

impl<'a, 'i, T: ToCss> ToCss for LayerBlockRule<'i, T> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@layer")?;
if let Some(name) = &self.name {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl<'a, 'i, T: ToCss> ToCss for MediaRule<'i, T> {
self.rules.to_css(dest)?;
return Ok(());
}
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@media ")?;
self.query.to_css(dest)?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct NamespaceRule<'i> {

impl<'i> ToCss for NamespaceRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@namespace ")?;
if let Some(prefix) = &self.prefix {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/nesting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'i, T: Clone> NestingRule<'i, T> {

impl<'a, 'i, T: ToCss> ToCss for NestingRule<'i, T> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
if !dest.has_context() {
dest.write_str("@nest ")?;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<'i> NestedDeclarationsRule<'i> {

impl<'i> ToCss for NestedDeclarationsRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);

dest.with_current_context(ContextAccess, |dest, context| {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub struct PageMarginRule<'i> {

impl<'i> ToCss for PageMarginRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_char('@')?;
self.margin_box.to_css(dest)?;
Expand Down Expand Up @@ -206,7 +206,7 @@ impl<'i> PageRule<'i> {

impl<'i> ToCss for PageRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@page")?;
if let Some(first) = self.selectors.first() {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/position_try.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct PositionTryRule<'i> {

impl<'i> ToCss for PositionTryRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@position-try ")?;
self.name.to_css(dest)?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl<'i> PropertyRule<'i> {

impl<'i> ToCss for PropertyRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@property ")?;
self.name.to_css(dest)?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<'i, T: Clone> ScopeRule<'i, T> {

impl<'i, T: ToCss> ToCss for ScopeRule<'i, T> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@scope")?;
dest.whitespace()?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/starting_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'i, T: Clone> StartingStyleRule<'i, T> {

impl<'i, T: ToCss> ToCss for StartingStyleRule<'i, T> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@starting-style")?;
dest.whitespace()?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl<'a, 'i, T: ToCss> StyleRule<'i, T> {
let has_declarations = supports_nesting || len > 0 || self.rules.0.is_empty() || has_preserved_rules;

if has_declarations {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
self.selectors.to_css(dest)?;
dest.whitespace()?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/supports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'i, T: Clone> SupportsRule<'i, T> {

impl<'a, 'i, T: ToCss> ToCss for SupportsRule<'i, T> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@supports ")?;
self.condition.to_css(dest)?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/unknown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct UnknownAtRule<'i> {

impl<'i> ToCss for UnknownAtRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_char('@')?;
dest.write_str(&self.name)?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/view_transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<'i> ViewTransitionRule<'i> {

impl<'i> ToCss for ViewTransitionRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_str("@view-transition")?;
dest.whitespace()?;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/viewport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct ViewportRule<'i> {

impl<'i> ToCss for ViewportRule<'i> {
fn to_css<PrinterT: crate::printer::PrinterTrait>(&self, dest: &mut PrinterT) -> Result<(), PrinterError> {
#[cfg(feature = "sourcemap")]
#[cfg(feature = "custom_sourcemap")]
dest.add_mapping(self.loc);
dest.write_char('@')?;
self.vendor_prefix.to_css(dest)?;
Expand Down
Loading
Loading