Skip to content

Commit

Permalink
Merge branch 'main' into jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
spenserblack authored Aug 18, 2023
2 parents 3479def + 83e25ad commit ea611f8
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions gengo/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@ impl Generated {
self.globs.iter().any(|g| g.matches_path(filepath.as_ref()))
}

fn is_generated_with_read<P: AsRef<Path>>(&self, _filepath: P, _contents: &[u8]) -> bool {
false
fn is_generated_with_read<P: AsRef<Path>>(&self, _filepath: P, contents: &[u8]) -> bool {
self.likely_minified(contents)
}

fn likely_minified(&self, contents: &[u8]) -> bool {
// NOTE If the first 10 lines are really long, it's probably minified.
contents
.split(|&b| b == b'\n')
.take(10)
.any(|line| line.len() > 250)
}

fn globs() -> Vec<Pattern> {
Expand Down Expand Up @@ -52,4 +60,13 @@ mod tests {
let generated = Generated::new();
assert_eq!(generated.is_generated_no_read(filepath), expected);
}

#[test]
fn test_likely_minified() {
let generated = Generated::new();
let header: Vec<u8> = b"/*!\n * This is my license etc etc\n */".to_vec();
let contents = b"console.log('hello, world!');".repeat(50);
let contents = [header, contents].concat();
assert!(generated.likely_minified(&contents));
}
}

0 comments on commit ea611f8

Please sign in to comment.