1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-08 15:19:40 -05:00

fix: TSX analysis in module graph loader (#5785)

This commit is contained in:
Bartek Iwańczuk 2020-05-23 19:04:29 +02:00 committed by GitHub
parent 94f1de5f80
commit c3c16f025c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 3 deletions

View file

@ -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>);
@ -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(),

View file

@ -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(

1
cli/tests/Component.tsx Normal file
View file

@ -0,0 +1 @@
import "./046_jsx_test.tsx";

View file

@ -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",

1
cli/tests/tsx_imports.ts Normal file
View file

@ -0,0 +1 @@
import "./Component.tsx";

View file

@ -0,0 +1,2 @@
Compile [WILDCARD]tsx_imports.ts
{ factory: [Function: View], props: null, children: [] }