Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module analyzer does not recognize triple-slash directive or @jsxImportSource pragma following hashbang comment #420

Closed
0f-0b opened this issue Mar 21, 2024 · 2 comments · Fixed by #421

Comments

@0f-0b
Copy link
Contributor

0f-0b commented Mar 21, 2024

use deno_graph::{
    DefaultModuleAnalyzer, DefaultModuleParser, MediaType, ModuleAnalyzer as _, ModuleSpecifier,
};

fn main() {
    let specifier = ModuleSpecifier::parse("file:///a.tsx").unwrap();
    let source = &r#"
#!/usr/bin/env -S deno run
/// <reference path="./ref.d.ts" />
/* @jsxImportSource react */
"#[1..];
    let analyzer = DefaultModuleAnalyzer::new(&DefaultModuleParser);
    let module_info = analyzer
        .analyze(&specifier, source.into(), MediaType::Tsx)
        .unwrap();
    assert!(!module_info.ts_references.is_empty());
    assert!(module_info.jsx_import_source.is_some());
}

This program should not panic, but currently (with deno_graph 0.69.9) it panics unless the hashbang comment is removed.

@dsherret
Copy link
Member

dsherret commented Mar 21, 2024

Is this something that doesn't work in Deno or doesn't work in deno_graph? I forget whose responsibility it is to remove/skip the hashbang.

@0f-0b
Copy link
Contributor Author

0f-0b commented Mar 22, 2024

I think Deno just supplies the source code to deno_graph unmodified, and it's up to deno_graph to skip the hashbang. The linked PR implements this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants