Skip to content

Commit

Permalink
fix: a lot of test rule is not work
Browse files Browse the repository at this point in the history
  • Loading branch information
sunrabbit123 committed Aug 17, 2023
1 parent a04f4b1 commit 9653443
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 28 deletions.
34 changes: 6 additions & 28 deletions crates/stc_ts_file_analyzer/tests/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ struct StcError {
code: usize,
}

fn get_env() -> Env {
let mut libs = vec![];
fn get_env_from_path(path: &Path, mut libs: Vec<Lib>) -> Env {
let case = parse_conformance_test(path).unwrap().into_iter().next().unwrap();
libs.extend(&case.libs);
let ls = &[
"es2022.full",
"es2021.full",
Expand All @@ -59,15 +60,7 @@ fn get_env() -> Env {
libs.sort();
libs.dedup();

Env::simple(
Rule {
strict_function_types: true,
..Default::default()
},
EsVersion::latest(),
ModuleConfig::None,
&libs,
)
Env::simple(case.rule, case.target, case.module_config, &libs)
}

fn validate(input: &Path) -> Vec<StcError> {
Expand All @@ -78,7 +71,7 @@ fn validate(input: &Path) -> Vec<StcError> {

let fm = cm.load_file(input).unwrap();

let env = get_env();
let env = get_env_from_path(input, vec![]);

let generator = module_id::ModuleIdGenerator::default();
let path = Arc::new(FileName::Real(input.to_path_buf()));
Expand Down Expand Up @@ -252,22 +245,7 @@ fn run_test(file_name: PathBuf, want_error: bool, disable_logging: bool) -> Opti

let handler = Arc::new(handler);
let fm = cm.load_file(&file_name).unwrap();
let mut libs = vec![];
let ls = &[
"es2020.full",
"es2019.full",
"es2018.full",
"es2017.full",
"es2016.full",
"es2015.full",
];
for s in ls {
libs.extend(Lib::load(s))
}
libs.sort();
libs.dedup();

let env = Env::simple(case.rule, case.target, case.module_config, &libs);
let env = get_env_from_path(&file_name, vec![]);
let stable_env = env.shared().clone();
let generator = module_id::ModuleIdGenerator::default();
let path = Arc::new(FileName::Real(file_name.clone()));
Expand Down
5 changes: 5 additions & 0 deletions crates/stc_ts_file_analyzer/tests/tsc/rule/strictNullCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @strictNullChecks: true
// @declaration: true

declare let a : string;
a = "a" as string | undefined;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"file": "tests/tsc/rule/strictNullCheck.ts",
"line": 5,
"col": 1,
"code": 2322
}
]
1 change: 1 addition & 0 deletions crates/stc_ts_type_checker/tests/tsc-stats.rust-debug
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Stats {
required_error: 3502,
matched_error: 6533,
extra_error: 764,
panic: 73,
}

0 comments on commit 9653443

Please sign in to comment.