2019-12-24 16:53:48 +03:00
|
|
|
#![feature(test)]
|
|
|
|
use common::Tester;
|
2020-04-03 04:33:35 +03:00
|
|
|
use std::collections::HashMap;
|
2020-07-23 20:18:22 +03:00
|
|
|
use swc_ecma_transforms::const_modules;
|
|
|
|
use swc_ecma_visit::Fold;
|
2019-12-24 16:53:48 +03:00
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
mod common;
|
|
|
|
|
2020-07-23 20:18:22 +03:00
|
|
|
fn tr(_: &mut Tester<'_>, sources: &[(&str, &[(&str, &str)])]) -> impl Fold {
|
2019-12-24 16:53:48 +03:00
|
|
|
let mut m = HashMap::default();
|
|
|
|
|
|
|
|
for (src, values) in sources {
|
|
|
|
let values = values
|
|
|
|
.iter()
|
|
|
|
.map(|(k, v)| ((*k).into(), v.to_string()))
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
m.insert((*src).into(), values);
|
|
|
|
}
|
|
|
|
|
|
|
|
const_modules(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
test!(
|
|
|
|
::swc_ecma_parser::Syntax::default(),
|
|
|
|
|tester| tr(tester, &[("@ember/env-flags", &[("DEBUG", "true")])]),
|
|
|
|
simple_flags,
|
|
|
|
r#"import { DEBUG } from '@ember/env-flags';
|
|
|
|
if (DEBUG) {
|
|
|
|
console.log('Foo!');
|
|
|
|
}"#,
|
|
|
|
r#"
|
|
|
|
if (true) {
|
|
|
|
console.log('Foo!');
|
|
|
|
}"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
::swc_ecma_parser::Syntax::default(),
|
|
|
|
|tester| tr(
|
|
|
|
tester,
|
|
|
|
&[
|
|
|
|
("@ember/env-flags", &[("DEBUG", "true")]),
|
|
|
|
(
|
|
|
|
"@ember/features",
|
|
|
|
&[("FEATURE_A", "false"), ("FEATURE_B", "true")]
|
|
|
|
)
|
|
|
|
]
|
|
|
|
),
|
|
|
|
complex_multiple,
|
|
|
|
"
|
|
|
|
import { DEBUG } from '@ember/env-flags';
|
|
|
|
import { FEATURE_A, FEATURE_B } from '@ember/features';
|
|
|
|
if (DEBUG) {
|
|
|
|
console.log('Foo!');
|
|
|
|
}
|
|
|
|
|
|
|
|
let woot;
|
|
|
|
if (FEATURE_A) {
|
|
|
|
woot = () => 'woot';
|
|
|
|
} else if (FEATURE_B) {
|
|
|
|
woot = () => 'toow';
|
|
|
|
}
|
|
|
|
",
|
|
|
|
"
|
|
|
|
if (true) {
|
|
|
|
console.log('Foo!');
|
|
|
|
}
|
|
|
|
|
|
|
|
let woot;
|
|
|
|
if (false) {
|
|
|
|
woot = () => 'woot';
|
|
|
|
} else if (true) {
|
|
|
|
woot = () => 'toow';
|
|
|
|
}
|
|
|
|
"
|
|
|
|
);
|