rspack_core 0.100.1

rspack core
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::sync::Arc;

use rspack_sources::{ReplaceSource, Source, SourceExt, SourceValue};

pub fn remove_bom(source: Arc<dyn Source>) -> Arc<dyn Source> {
  let has_bom = match source.source() {
    SourceValue::String(content) => content.starts_with('\u{feff}'),
    SourceValue::Buffer(buffer) => buffer.starts_with("\u{feff}".as_bytes()),
  };

  if !has_bom {
    return source;
  }

  let mut replace_source = ReplaceSource::new(source);
  replace_source.replace_static(0, 3, "", None);
  replace_source.boxed()
}