2020-10-06 14:48:29 +03:00
|
|
|
use swc_common::chain;
|
2019-02-18 08:01:56 +03:00
|
|
|
use swc_ecma_parser::{EsConfig, Syntax};
|
2021-01-05 08:29:52 +03:00
|
|
|
use swc_ecma_transforms_compat::es2020::export_namespace_from;
|
|
|
|
use swc_ecma_transforms_proposal::export_default_from;
|
|
|
|
use swc_ecma_transforms_testing::test;
|
2020-07-23 20:18:22 +03:00
|
|
|
use swc_ecma_visit::Fold;
|
2019-12-24 16:53:48 +03:00
|
|
|
|
2019-02-18 08:01:56 +03:00
|
|
|
fn syntax_default() -> Syntax {
|
|
|
|
Syntax::Es(EsConfig {
|
|
|
|
export_default_from: true,
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
fn syntax_namespace() -> Syntax {
|
2023-03-29 11:48:45 +03:00
|
|
|
Syntax::Es(EsConfig {
|
|
|
|
..Default::default()
|
|
|
|
})
|
2019-02-18 08:01:56 +03:00
|
|
|
}
|
|
|
|
|
2020-07-23 20:18:22 +03:00
|
|
|
fn tr() -> impl Fold {
|
2020-10-06 14:48:29 +03:00
|
|
|
chain!(export_default_from(), export_namespace_from())
|
2019-02-18 08:01:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax_default(),
|
|
|
|
|_| tr(),
|
|
|
|
default_es6,
|
|
|
|
r#"export foo from "bar";"#,
|
|
|
|
r#"
|
2022-07-20 09:57:43 +03:00
|
|
|
export { default as foo } from "bar";
|
2019-02-18 08:01:56 +03:00
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax_default(),
|
|
|
|
|_| tr(),
|
|
|
|
default_compounded_es6,
|
|
|
|
r#"export v, { x, y as w } from "mod";"#,
|
2022-07-20 09:57:43 +03:00
|
|
|
r#"export { default as v, x, y as w } from "mod";"#
|
2019-02-18 08:01:56 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2022-07-13 13:55:55 +03:00
|
|
|
syntax_default(),
|
2019-02-18 08:01:56 +03:00
|
|
|
|_| tr(),
|
|
|
|
namespace_compound_es6,
|
|
|
|
r"export * as foo, { bar } from 'bar';",
|
|
|
|
"import * as _foo from 'bar';
|
|
|
|
export { _foo as foo };
|
|
|
|
export { bar } from 'bar';
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax_namespace(),
|
|
|
|
|_| tr(),
|
|
|
|
namespace_default,
|
|
|
|
"export * as default from 'foo';",
|
|
|
|
"import * as _default from 'foo';
|
|
|
|
export { _default as default };"
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax_namespace(),
|
|
|
|
|_| tr(),
|
|
|
|
namespace_es6,
|
|
|
|
"export * as foo from 'bar';",
|
|
|
|
"import * as _foo from 'bar';
|
|
|
|
export { _foo as foo };"
|
|
|
|
);
|