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
317 changes: 242 additions & 75 deletions src/ast/lib.rs

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/bun_core/string/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ mod wtf8_text;
pub use wtf8_text::{
Wtf8Codepoints, codepoint_len_utf16, push_codepoint_wtf8_joined, push_wtf8,
push_wtf8_well_formed, utf8_decoded_len_utf16, utf8_lossy_len_utf16, wtf8_codepoint_at,
wtf8_codepoint_count, wtf8_codepoints, wtf8_first_codepoint, wtf8_has_surrogate,
wtf8_len_utf16, wtf8_offset_of_utf16_index, wtf8_slice_by_utf16, wtf8_to_utf16, wtf16_to_wtf8,
wtf8_codepoint_count, wtf8_codepoint_start, wtf8_codepoints, wtf8_first_codepoint,
wtf8_has_surrogate, wtf8_len_utf16, wtf8_offset_of_utf16_index, wtf8_slice_by_utf16,
wtf8_to_utf16, wtf16_to_wtf8,
};

// UTF-16 surrogate primitives. The single implementation lives in the
Expand Down
8 changes: 8 additions & 0 deletions src/bun_core/string/immutable/wtf8_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ pub fn wtf8_codepoint_at(text: &[u8], at: usize) -> (u32, usize) {
(UNICODE_REPLACEMENT, 1)
}

/// Where the code point starts that `at` is in the middle of. `at` itself if it is not.
pub fn wtf8_codepoint_start(text: &[u8], at: usize) -> usize {
(1..=3)
.filter_map(|back| at.checked_sub(back))
.find(|&start| wtf8_codepoint_at(text, start).1 > at - start)
.unwrap_or(at)
}

/// The code points of `text`, each with the offset in bytes where it starts: `[...text]`. See
/// [`wtf8_codepoint_at`].
#[inline]
Expand Down
3 changes: 1 addition & 2 deletions src/bundler/ParseTask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,6 @@ pub mod parse_worker {
Loader::Css => {
// make css ast
let mut import_records = Vec::<ImportRecord>::default();
let source_code = &source.contents;
let mut temp_log = Log::init();
// `temp_log` is flushed into `log` on every exit path via linear
// control flow (scopeguard would alias `log`/`temp_log`).
Expand All @@ -1293,7 +1292,7 @@ pub mod parse_worker {

let (mut css_ast, extra) = match bun_css::BundlerStyleSheet::parse_bundler(
bump,
source_code,
source,
parser_options,
&mut import_records,
bun_ast::Index::source(source.index.0),
Expand Down
3 changes: 2 additions & 1 deletion src/bundler/transpiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3059,9 +3059,10 @@ impl<'a> Transpiler<'a> {
// `'bump`-threading note).
let alloc: &'static Arena = unsafe { bun_ptr::detach_lifetime_ref::<Arena>(self.arena) };

let source = bun_ast::Source::init_path_string(file_path_text, entry.contents());
let (mut sheet, extra) = match bun_css::StyleSheet::<bun_css::DefaultAtRule>::parse(
alloc,
entry.contents(),
&source,
opts,
None,
bun_ast::Index::source(0u32),
Expand Down
Loading
Loading