2022-02-26 09:41:14 +03:00
|
|
|
#![deny(warnings)]
|
|
|
|
|
2021-03-31 21:01:44 +03:00
|
|
|
use std::path::PathBuf;
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-26 09:41:14 +03:00
|
|
|
use swc_common::{Mark, SyntaxContext};
|
2021-03-31 21:01:44 +03:00
|
|
|
use swc_ecma_ast::*;
|
2022-02-26 09:41:14 +03:00
|
|
|
use swc_ecma_parser::{parse_file_as_module, Syntax, TsConfig};
|
2022-04-26 10:38:50 +03:00
|
|
|
use swc_ecma_transforms_base::resolver;
|
2021-12-07 08:34:16 +03:00
|
|
|
use swc_ecma_visit::{FoldWith, Visit, VisitWith};
|
2021-03-31 21:01:44 +03:00
|
|
|
use testing::fixture;
|
|
|
|
|
2022-01-28 13:11:30 +03:00
|
|
|
#[fixture("../swc_ecma_parser/tests/**/*.ts")]
|
|
|
|
#[fixture("../swc_ecma_parser/tests/**/*.tsx")]
|
2021-03-31 21:01:44 +03:00
|
|
|
fn no_empty(input: PathBuf) {
|
|
|
|
eprintln!("{}", input.display());
|
|
|
|
|
|
|
|
testing::run_test2(false, |cm, _handler| {
|
|
|
|
let fm = cm.load_file(&input).expect("failed to load file");
|
|
|
|
|
2022-02-26 09:41:14 +03:00
|
|
|
let module = match parse_file_as_module(
|
|
|
|
&fm,
|
2021-03-31 21:01:44 +03:00
|
|
|
Syntax::Typescript(TsConfig {
|
|
|
|
tsx: input.ends_with("tsx"),
|
|
|
|
decorators: true,
|
|
|
|
no_early_errors: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
EsVersion::latest(),
|
|
|
|
None,
|
2022-02-26 09:41:14 +03:00
|
|
|
&mut vec![],
|
|
|
|
) {
|
2021-03-31 21:01:44 +03:00
|
|
|
Ok(v) => v,
|
|
|
|
// We are not testing parser
|
|
|
|
Err(..) => return Ok(()),
|
|
|
|
};
|
|
|
|
|
2022-04-26 10:38:50 +03:00
|
|
|
let module = module.fold_with(&mut resolver(Mark::new(), Mark::new(), true));
|
2021-03-31 21:01:44 +03:00
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
module.visit_with(&mut AssertNoEmptyCtxt);
|
2021-03-31 21:01:44 +03:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct AssertNoEmptyCtxt;
|
|
|
|
|
|
|
|
impl Visit for AssertNoEmptyCtxt {
|
2021-12-07 08:34:16 +03:00
|
|
|
fn visit_expr(&mut self, n: &Expr) {
|
2021-03-31 21:01:44 +03:00
|
|
|
n.visit_children_with(self);
|
|
|
|
|
2022-01-15 09:36:40 +03:00
|
|
|
if let Expr::Ident(i) = n {
|
|
|
|
if i.span.ctxt == SyntaxContext::empty() {
|
|
|
|
unreachable!("ts_resolver has a bug")
|
2021-03-31 21:01:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
fn visit_pat(&mut self, n: &Pat) {
|
2021-03-31 21:01:44 +03:00
|
|
|
n.visit_children_with(self);
|
|
|
|
|
2022-01-15 09:36:40 +03:00
|
|
|
if let Pat::Ident(i) = n {
|
|
|
|
if i.id.span.ctxt == SyntaxContext::empty() {
|
|
|
|
unreachable!("ts_resolver has a bug")
|
2021-03-31 21:01:44 +03:00
|
|
|
}
|
2022-01-15 09:36:40 +03:00
|
|
|
}
|
|
|
|
}
|
2021-03-31 21:01:44 +03:00
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
fn visit_ts_getter_signature(&mut self, n: &TsGetterSignature) {
|
2021-03-31 21:01:44 +03:00
|
|
|
if n.computed {
|
2021-12-07 08:34:16 +03:00
|
|
|
n.key.visit_with(self);
|
2021-03-31 21:01:44 +03:00
|
|
|
}
|
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
n.type_ann.visit_with(self);
|
2021-03-31 21:01:44 +03:00
|
|
|
}
|
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
fn visit_ts_method_signature(&mut self, n: &TsMethodSignature) {
|
2021-03-31 21:01:44 +03:00
|
|
|
if n.computed {
|
2021-12-07 08:34:16 +03:00
|
|
|
n.key.visit_with(self);
|
2021-03-31 21:01:44 +03:00
|
|
|
}
|
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
n.params.visit_with(self);
|
|
|
|
n.type_ann.visit_with(self);
|
|
|
|
n.type_params.visit_with(self);
|
2021-03-31 21:01:44 +03:00
|
|
|
}
|
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
fn visit_ts_property_signature(&mut self, n: &TsPropertySignature) {
|
2021-03-31 21:01:44 +03:00
|
|
|
if n.computed {
|
2021-12-07 08:34:16 +03:00
|
|
|
n.key.visit_with(self);
|
2021-03-31 21:01:44 +03:00
|
|
|
}
|
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
n.init.visit_with(self);
|
|
|
|
n.params.visit_with(self);
|
|
|
|
n.type_ann.visit_with(self);
|
|
|
|
n.type_params.visit_with(self);
|
2021-03-31 21:01:44 +03:00
|
|
|
}
|
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
fn visit_ts_setter_signature(&mut self, n: &TsSetterSignature) {
|
2021-03-31 21:01:44 +03:00
|
|
|
if n.computed {
|
2021-12-07 08:34:16 +03:00
|
|
|
n.key.visit_with(self);
|
2021-03-31 21:01:44 +03:00
|
|
|
}
|
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
n.param.visit_with(self);
|
2021-03-31 21:01:44 +03:00
|
|
|
}
|
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
fn visit_ts_tuple_element(&mut self, n: &TsTupleElement) {
|
|
|
|
n.ty.visit_with(self);
|
2021-03-31 21:01:44 +03:00
|
|
|
}
|
|
|
|
}
|