Skip to content

Commit

Permalink
fix: compute whether script (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Oct 31, 2024
1 parent cc18ff2 commit 1078084
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ harness = false
anyhow = "1.0.43"
async-trait = "0.1.68"
data-url = "0.3.0"
deno_ast = { version = "0.43.0", features = ["dep_analysis", "emit"] }
deno_ast = { version = "0.43.2", features = ["dep_analysis", "emit"] }
deno_unsync.workspace = true
deno_semver = "0.5.13"
encoding_rs = "0.8.33"
Expand Down
26 changes: 22 additions & 4 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,7 @@ impl<'a> ParserModuleAnalyzer<'a> {
},
};
ModuleInfo {
is_script: match program {
ProgramRef::Module(_) => false,
ProgramRef::Script(_) => true,
},
is_script: program.compute_is_script(),
dependencies: analyze_dependencies(program, text_info, comments),
ts_references: analyze_ts_references(text_info, leading_comments),
self_types_specifier: analyze_ts_self_types(
Expand Down Expand Up @@ -1094,6 +1091,27 @@ const f = new Set();
);
}

#[test]
fn test_import_equals() {
let specifier = ModuleSpecifier::parse("file:///a/test.ts").unwrap();
let source = r#"
export import value = require("./a.js");
import value2 = require("./b.js");
"#;
let parsed_source = DefaultEsParser
.parse_program(ParseOptions {
specifier: &specifier,
source: source.into(),
media_type: MediaType::TypeScript,
scope_analysis: false,
})
.unwrap();
let module_info = ParserModuleAnalyzer::module_info(&parsed_source);
assert!(module_info.is_script);
let dependencies = module_info.dependencies;
assert_eq!(dependencies.len(), 2);
}

#[tokio::test]
async fn test_analyze_ts_references_and_jsx_import_source_with_shebang() {
let specifier = ModuleSpecifier::parse("file:///a/test.tsx").unwrap();
Expand Down

0 comments on commit 1078084

Please sign in to comment.