Skip to content

Commit

Permalink
fix: remove dts handling
Browse files Browse the repository at this point in the history
  • Loading branch information
metreniuk committed Aug 9, 2023
1 parent 9ea7426 commit a7f6f93
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 81 deletions.
21 changes: 0 additions & 21 deletions crates/oxc_linter/src/rules/typescript/no_namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,24 +335,3 @@ fn test() {

Tester::new(NoNamespace::NAME, pass, fail).test_and_snapshot();
}

#[test]
fn test_declarations() {
use crate::tester::Tester;

let pass = vec![
("namespace foo {}", Some(serde_json::json!([{ "allowDefinitionFiles": true }]))),
("module foo {}", Some(serde_json::json!([{ "allowDefinitionFiles": true }]))),
];

let fail = vec![
("namespace foo {}", Some(serde_json::json!([{ "allowDefinitionFiles": false }]))),
("module foo {}", Some(serde_json::json!([{ "allowDefinitionFiles": false }]))),
("declare module foo {}", Some(serde_json::json!([{ "allowDefinitionFiles": false }]))),
("declare namespace foo {}", Some(serde_json::json!([{ "allowDefinitionFiles": false }]))),
];

Tester::new(NoNamespace::NAME, pass, fail)
.with_extension("d.ts".to_string())
.test_and_snapshot();
}
34 changes: 0 additions & 34 deletions crates/oxc_linter/src/snapshots/no_namespace__declarations.snap

This file was deleted.

29 changes: 4 additions & 25 deletions crates/oxc_linter/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub struct Tester {
expect_pass: Vec<(String, Option<Value>)>,
expect_fail: Vec<(String, Option<Value>)>,
snapshot: String,
extension: String,
}

impl Tester {
Expand All @@ -25,13 +24,7 @@ impl Tester {
) -> Self {
let expect_pass = expect_pass.into_iter().map(|(s, r)| (s.into(), r)).collect::<Vec<_>>();
let expect_fail = expect_fail.into_iter().map(|(s, r)| (s.into(), r)).collect::<Vec<_>>();
Self {
rule_name,
expect_pass,
expect_fail,
snapshot: String::new(),
extension: String::from("tsx"),
}
Self { rule_name, expect_pass, expect_fail, snapshot: String::new() }
}

pub fn new_without_config<S: Into<String>>(
Expand All @@ -41,18 +34,7 @@ impl Tester {
) -> Self {
let expect_pass = expect_pass.into_iter().map(|s| (s.into(), None)).collect::<Vec<_>>();
let expect_fail = expect_fail.into_iter().map(|s| (s.into(), None)).collect::<Vec<_>>();
Self {
rule_name,
expect_pass,
expect_fail,
snapshot: String::new(),
extension: String::from("tsx"),
}
}

pub fn with_extension(&mut self, extension: String) -> &mut Self {
self.extension = extension;
self
Self { rule_name, expect_pass, expect_fail, snapshot: String::new() }
}

pub fn test(&mut self) {
Expand Down Expand Up @@ -93,18 +75,15 @@ impl Tester {
}

fn snapshot(&self) {
let mut name = self.rule_name.replace('-', "_");
if &self.extension == "d.ts" {
name.push_str("__declarations");
}
let name = self.rule_name.replace('-', "_");
insta::with_settings!({ prepend_module_to_snapshot => false, }, {
insta::assert_snapshot!(name.clone(), self.snapshot, &name);
});
}

fn run(&mut self, source_text: &str, config: Option<Value>) -> bool {
let name = self.rule_name.replace('-', "_");
let path = PathBuf::from(name).with_extension(self.extension.clone());
let path = PathBuf::from(name).with_extension("tsx");
let allocator = Allocator::default();
let result = self.run_rules(&allocator, &path, source_text, config, false);
if result.is_empty() {
Expand Down
4 changes: 3 additions & 1 deletion crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ impl<'a> SemanticBuilder<'a> {

pub fn build(mut self, program: &'a Program<'a>) -> SemanticBuilderReturn<'a> {
// First AST pass
self.visit_program(program);
if !self.source_type.is_typescript_definition() {
self.visit_program(program);
}

// Second partial AST pass on top level import / export statements
let module_record = if self.with_module_record_builder {
Expand Down

0 comments on commit a7f6f93

Please sign in to comment.