Skip to main content

transform

Function transform 

Source
pub fn transform(
    source: &[u8],
    language: Language,
    options: TransformOptions,
) -> TransformResult
Expand description

Scan source and produce the bytes a removal would write.

This is scan followed by the edits its report calls for. Nothing is written anywhere: the caller gets the new bytes, the edits that made them, the report they were decided from, and a SourceMap between the two.

A source the scanner reported invalid — an unterminated comment or string — is returned byte for byte with no edits at all, unless ScanOptions::force_invalid is set.

§Examples

use ocomment_core::{Language, TransformOptions, transform};

let result = transform(
    b"let x = 1; // note\n",
    Language::Rust,
    TransformOptions::default(),
);
assert_eq!(result.output, b"let x = 1; \n");
assert_eq!(result.report.comments.len(), 1);
assert_eq!(result.edits.len(), 1);

// An unterminated comment leaves the file alone.
let broken = transform(b"x /* no end", Language::C, TransformOptions::default());
assert!(!broken.report.valid);
assert_eq!(broken.output, b"x /* no end");