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
4 changes: 2 additions & 2 deletions src/bundler/linker_context/prepareCssAstsForChunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ fn prepare_css_asts_for_chunk_impl(c: &LinkerContext, chunk: &mut Chunk, bump: &
let print_result = match ast_import.to_css(
bump,
&printer_options,
Some(ImportInfo {
ImportInfo {
import_records: &entry.condition_import_records,
ast_urls_for_css: parse_graph.ast.items_url_for_css(),
ast_unique_key_for_additional_file: parse_graph
.input_files
.items_unique_key_for_additional_file(),
}),
},
// `LocalsResultsMap` is the same `ArrayHashMap<Ref, Box<[u8]>>`
// alias as `bun_js_printer::MangledProps`; no cast needed.
Some(&c.mangled_props),
Expand Down
6 changes: 2 additions & 4 deletions src/bundler/transpiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3060,7 +3060,7 @@ impl<'a> Transpiler<'a> {
alloc,
entry.contents(),
opts,
Some(&mut import_records),
&mut import_records,
bun_ast::Index::source(0u32),
) {
Ok(v) => v,
Expand Down Expand Up @@ -3089,9 +3089,7 @@ impl<'a> Transpiler<'a> {
minify: self.options.minify_whitespace,
..bun_css::PrinterOptions::default()
},
Some(bun_css::ImportInfo::init_outside_of_bundler(
&import_records,
)),
bun_css::ImportInfo::init_outside_of_bundler(&import_records),
None,
&symbols,
) {
Expand Down
27 changes: 17 additions & 10 deletions src/css/css_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2574,23 +2574,30 @@ mod stylesheet_impl {
&'a self,
arena: &'a Bump,
options: &PrinterOptions<'a>,
import_info: Option<ImportInfo<'a>>,
import_info: ImportInfo<'a>,
local_names: Option<&'a LocalsResultsMap>,
symbols: &'a bun_ast::symbol::Map,
) -> PrintResult<ToCssResult> {
// TODO: this is not necessary
// Make sure we always have capacity > 0: https://github.com/napi-rs/napi-rs/issues/1124.
// PERF: this always heap-allocates — profile if hot.
let mut dest: Vec<u8> = Vec::with_capacity(1);
self.to_css_with_writer(arena, &mut dest, options, import_info, local_names, symbols)?;
self.to_css_with_writer(
arena,
&mut dest,
options,
Some(import_info),
local_names,
symbols,
)?;
return Ok(ToCssResult { code: dest });
}

pub fn parse(
arena: &'static Bump,
code: &[u8],
options: ParserOptions<'_>,
import_records: Option<&mut Vec<ImportRecord<'static>>>,
import_records: &mut Vec<ImportRecord<'static>>,
source_index: SrcIndex,
) -> Maybe<(StyleSheet<DefaultAtRule>, StylesheetExtra), Err<ParserError>> {
// Returns the concrete `StyleSheet<DefaultAtRule>`. Callers that
Expand All @@ -2609,7 +2616,7 @@ mod stylesheet_impl {
code,
options,
&mut at_rule_parser,
import_records.map(core::ptr::NonNull::from),
core::ptr::NonNull::from(import_records),
source_index,
)
}
Expand All @@ -2620,7 +2627,7 @@ mod stylesheet_impl {
code: &[u8],
options: ParserOptions<'_>,
at_rule_parser: &mut P,
import_records: Option<core::ptr::NonNull<Vec<ImportRecord<'static>>>>,
import_records: core::ptr::NonNull<Vec<ImportRecord<'static>>>,
source_index: SrcIndex,
) -> Maybe<(Self, StylesheetExtra), Err<ParserError>> {
// TODO: 'bump lifetime threading — every arena-backed slice the
Expand All @@ -2642,7 +2649,7 @@ mod stylesheet_impl {
let mut input = ParserInput::new(code, arena);
let mut parser = Parser::new(
&mut input,
import_records,
Some(import_records),
if options.css_modules.is_some() {
ParserOpts::CSS_MODULES
} else {
Expand Down Expand Up @@ -2769,7 +2776,7 @@ mod stylesheet_impl {
&'a self,
arena: &'a Bump,
options: &PrinterOptions<'a>,
import_info: Option<ImportInfo<'a>>,
import_info: ImportInfo<'a>,
) -> Result<ToCssResult, PrintErr> {
// #[cfg(feature = "sourcemap")]
// assert!(
Expand All @@ -2784,7 +2791,7 @@ mod stylesheet_impl {
bun_alloc::ArenaVec::new_in(arena),
&mut dest,
options,
import_info,
Some(import_info),
None,
&symbols,
);
Expand Down Expand Up @@ -2827,7 +2834,7 @@ mod stylesheet_impl {
code,
options,
&mut at_rule_parser,
Some(import_records_ptr),
import_records_ptr,
source_index,
)
}
Expand Down Expand Up @@ -3209,7 +3216,7 @@ impl<'a> Parser<'a> {
///
/// Pass in `import_records` to track imports (`@import` rules, `url()`
/// tokens). If this is `None`, calling `Parser::add_import_record` will
/// error.
/// error, so pass `None` only for a grammar with no `url()` (An+B, a color).
pub fn new(
input: &'a mut ParserInput<'a>,
import_records: Option<core::ptr::NonNull<Vec<ImportRecord<'static>>>>,
Expand Down
10 changes: 3 additions & 7 deletions src/css_jsc/css_internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn testing_impl<'a>(
alloc,
source,
parser_options,
Some(&mut import_records),
&mut import_records,
bun_ast::Index::INVALID,
) {
Ok(ret) => {
Expand Down Expand Up @@ -165,9 +165,7 @@ fn testing_impl<'a>(
},
..Default::default()
},
Some(ImportRecordHandler::init_outside_of_bundler(
&import_records,
)),
ImportRecordHandler::init_outside_of_bundler(&import_records),
Some(&local_names),
&symbols,
) {
Expand Down Expand Up @@ -275,9 +273,7 @@ pub(crate) fn attr_test<'a>(
targets,
..Default::default()
},
Some(ImportRecordHandler::init_outside_of_bundler(
&import_records,
)),
ImportRecordHandler::init_outside_of_bundler(&import_records),
) {
Ok(r) => r,
Err(_e) => {
Expand Down
6 changes: 2 additions & 4 deletions src/runtime/cli/pm_diff_normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ fn normalize_css(path: &[u8], bytes: &[u8]) -> Option<Normalized> {
alloc,
bytes,
opts,
Some(&mut import_records),
&mut import_records,
bun_ast::Index::INVALID,
)
.ok()?;
Expand All @@ -928,9 +928,7 @@ fn normalize_css(path: &[u8], bytes: &[u8]) -> Option<Normalized> {
minify: false,
..bun_css::PrinterOptions::default()
},
Some(bun_css::ImportInfo::init_outside_of_bundler(
&import_records,
)),
bun_css::ImportInfo::init_outside_of_bundler(&import_records),
None,
&symbols,
)
Expand Down
Loading