Skip to content

Commit

Permalink
fix: TSX analysis in module graph loader (denoland#5785)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju committed May 23, 2020
1 parent 94f1de5 commit c3c16f0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
11 changes: 8 additions & 3 deletions cli/module_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ where
}
}

const SUPPORTED_MEDIA_TYPES: [MediaType; 4] = [
MediaType::JavaScript,
MediaType::TypeScript,
MediaType::JSX,
MediaType::TSX,
];

#[derive(Debug, Serialize)]
pub struct ModuleGraph(HashMap<String, ModuleGraphFile>);

Expand Down Expand Up @@ -384,9 +391,7 @@ impl ModuleGraphLoader {
let module_specifier = ModuleSpecifier::from(source_file.url.clone());
let source_code = String::from_utf8(source_file.source_code)?;

if source_file.media_type == MediaType::JavaScript
|| source_file.media_type == MediaType::TypeScript
{
if SUPPORTED_MEDIA_TYPES.contains(&source_file.media_type) {
if let Some(types_specifier) = source_file.types_header {
let type_header = ReferenceDescriptor {
specifier: types_specifier.to_string(),
Expand Down
1 change: 1 addition & 0 deletions cli/swc_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl AstParser {
let mut ts_config = TsConfig::default();
ts_config.dynamic_import = true;
ts_config.decorators = true;
ts_config.tsx = true;
let syntax = Syntax::Typescript(ts_config);

let lexer = Lexer::new(
Expand Down
1 change: 1 addition & 0 deletions cli/tests/Component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./046_jsx_test.tsx";
5 changes: 5 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,11 @@ itest!(disallow_http_from_https_ts {
exit_code: 1,
});

itest!(tsx_imports {
args: "run --reload tsx_imports.ts",
output: "tsx_imports.ts.out",
});

itest!(fix_js_import_js {
args: "run --quiet --reload fix_js_import_js.ts",
output: "fix_js_import_js.ts.out",
Expand Down
1 change: 1 addition & 0 deletions cli/tests/tsx_imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import "./Component.tsx";
2 changes: 2 additions & 0 deletions cli/tests/tsx_imports.ts.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Compile [WILDCARD]tsx_imports.ts
{ factory: [Function: View], props: null, children: [] }

0 comments on commit c3c16f0

Please sign in to comment.