-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use new deno_ast emitter API (#429)
- Loading branch information
1 parent
523d1e2
commit 2b1b063
Showing
11 changed files
with
190 additions
and
213 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,15 +7,19 @@ | |
use std::collections::HashSet; | ||
use std::sync::Arc; | ||
|
||
use deno_ast::emit; | ||
use deno_ast::swc::ast::*; | ||
use deno_ast::swc::common::comments::CommentKind; | ||
use deno_ast::swc::common::comments::SingleThreadedComments; | ||
use deno_ast::swc::common::comments::SingleThreadedCommentsMapInner; | ||
use deno_ast::swc::common::Spanned; | ||
use deno_ast::swc::common::DUMMY_SP; | ||
use deno_ast::EmitOptions; | ||
use deno_ast::EmittedSource; | ||
use deno_ast::ModuleSpecifier; | ||
use deno_ast::MultiThreadedComments; | ||
use deno_ast::ParsedSource; | ||
use deno_ast::SourceMap; | ||
use deno_ast::SourceRange; | ||
use deno_ast::SourceRangedForSpanned; | ||
|
||
|
@@ -26,7 +30,6 @@ use crate::WorkspaceMember; | |
|
||
use super::range_finder::ModulePublicRanges; | ||
use super::swc_helpers::any_type_ann; | ||
use super::swc_helpers::emit; | ||
use super::swc_helpers::get_return_stmts_with_arg_from_function_body; | ||
use super::swc_helpers::ident; | ||
use super::swc_helpers::is_void_type; | ||
|
@@ -79,7 +82,8 @@ impl CommentsMut { | |
|
||
#[derive(Debug, Clone)] | ||
pub struct FastCheckDtsModule { | ||
pub text: String, | ||
pub program: Program, | ||
pub comments: SingleThreadedComments, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
dsherret
Member
|
||
pub diagnostics: Vec<FastCheckDtsDiagnostic>, | ||
} | ||
|
||
|
@@ -135,11 +139,20 @@ pub fn transform( | |
}; | ||
|
||
// now emit | ||
let (text, source_map) = emit( | ||
specifier, | ||
let source_map = SourceMap::single( | ||
specifier.clone(), | ||
parsed_source.text_info().text_str().to_owned(), | ||
); | ||
let program = Program::Module(module); | ||
let EmittedSource { text, source_map } = emit( | ||
&program, | ||
&fast_check_comments, | ||
parsed_source.text_info(), | ||
&module, | ||
&source_map, | ||
&EmitOptions { | ||
keep_comments: true, | ||
source_map: deno_ast::SourceMapOption::Separate, | ||
inline_sources: false, | ||
}, | ||
) | ||
.map_err(|e| { | ||
vec![FastCheckDiagnostic::Emit { | ||
|
@@ -152,18 +165,11 @@ pub fn transform( | |
let mut dts_transformer = | ||
FastCheckDtsTransformer::new(parsed_source.text_info(), specifier); | ||
|
||
let module = dts_transformer.transform(module)?; | ||
let (text, _source_map) = | ||
emit(specifier, &dts_comments, parsed_source.text_info(), &module) | ||
.map_err(|e| { | ||
vec![FastCheckDiagnostic::Emit { | ||
specifier: specifier.clone(), | ||
inner: Arc::new(e), | ||
}] | ||
})?; | ||
let module = dts_transformer.transform(program.expect_module())?; | ||
|
||
Some(FastCheckDtsModule { | ||
text, | ||
program: Program::Module(module), | ||
comments: dts_comments, | ||
diagnostics: dts_transformer.diagnostics, | ||
}) | ||
} else { | ||
|
@@ -174,7 +180,7 @@ pub fn transform( | |
module_info: module_info.into(), | ||
text: text.into(), | ||
dts, | ||
source_map: source_map.into(), | ||
source_map: source_map.unwrap().into_bytes().into(), | ||
}) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
We can't store this in the graph because this isn't
Send
. We'll have to come up with some other solution. I'm going to revert part of this unfortunately (sorry, I mised this change in my initial review).