Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed May 24, 2022
1 parent 0f56eed commit 90e43f3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
36 changes: 32 additions & 4 deletions packages/transformers/js/core/src/hoist.rs
Expand Up @@ -2150,7 +2150,7 @@ mod tests {
collect_decls(&module),
Mark::fresh(Mark::root()),
global_mark,
false,
true,
);
module.visit_with(&mut collect);

Expand Down Expand Up @@ -2745,7 +2745,7 @@ mod tests {
"#,
);

assert!(collect.bailouts.is_none());
assert!(collect.bailouts.unwrap().is_empty());

assert_eq!(
code,
Expand All @@ -2766,7 +2766,7 @@ mod tests {
foo.bar();
"#,
);
assert!(collect.bailouts.is_none());
assert!(collect.bailouts.unwrap().is_empty());

assert_eq!(
code,
Expand All @@ -2777,6 +2777,34 @@ mod tests {
"#}
);

let (collect, code, _hoist) = parse(
r#"
import * as foo from 'other';
foo.bar();
let y = "bar";
foo[y]();
"#,
);
assert_eq!(
collect
.bailouts
.unwrap()
.iter()
.map(|b| &b.reason)
.collect::<Vec<_>>(),
vec![&BailoutReason::NonStaticAccess]
);

assert_eq!(
code,
indoc! {r#"
import "abc:other";
$abc$import$70a00e0a8474f72a.bar();
let $abc$var$y = "bar";
$abc$import$70a00e0a8474f72a[$abc$var$y]();
"#}
);

let (collect, code, _hoist) = parse(
r#"
import other from 'other';
Expand All @@ -2785,7 +2813,7 @@ mod tests {
"#,
);

assert!(collect.bailouts.is_none());
assert!(collect.bailouts.unwrap().is_empty());

assert_eq!(
code,
Expand Down
3 changes: 2 additions & 1 deletion packages/transformers/js/core/src/utils.rs
Expand Up @@ -275,6 +275,7 @@ pub enum SourceType {
Module,
}

#[derive(Debug)]
pub struct Bailout {
pub loc: SourceLocation,
pub reason: BailoutReason,
Expand All @@ -297,7 +298,7 @@ impl Bailout {
}
}

#[derive(Eq, PartialEq)]
#[derive(Debug, Eq, PartialEq)]
pub enum BailoutReason {
NonTopLevelRequire,
NonStaticDestructuring,
Expand Down

0 comments on commit 90e43f3

Please sign in to comment.