Skip to content

Commit

Permalink
Fixes based on self review.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Aug 4, 2021
1 parent 1b36032 commit 5517fc5
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions cli/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl ParsedModule {
let source_map = Rc::new(SourceMap::default());
let file_name = FileName::Custom(self.info.specifier.clone());
source_map.new_source_file(file_name, self.info.text.clone());
let comments = self.comments.as_single_threaded();
let comments = self.comments.as_single_threaded(); // needs to be mutable

let jsx_pass = react::react(
source_map.clone(),
Expand Down Expand Up @@ -374,29 +374,26 @@ impl ParsedModule {
}
}

/// For a given specifier, source text, and media type, parse the text of the
/// For a given specifier, source, and media type, parse the text of the
/// module and return a representation which can be further processed.
///
/// # Arguments
///
/// - `specifier` - The module specifier for the module.
/// - `source_text` - The source code for the module.
/// - `source` - The source code for the module.
/// - `media_type` - The media type for the module.
///
// NOTE(bartlomieju): `specifier` has `&str` type instead of
// `&ModuleSpecifier` because runtime compiler APIs don't
// require valid module specifiers
pub fn parse(
specifier: &str,
source_text: &str,
source: &str,
media_type: &MediaType,
) -> Result<ParsedModule, AnyError> {
let info = SourceFileInfo::new(specifier, source_text);
let input = StringInput::new(
source_text,
BytePos(0),
BytePos(source_text.len() as u32),
);
let info = SourceFileInfo::new(specifier, source);
let input =
StringInput::new(source, BytePos(0), BytePos(source.len() as u32));
let (comments, module) = parse_string_input(&info, input, media_type)?;

Ok(ParsedModule {
Expand Down Expand Up @@ -464,16 +461,16 @@ pub fn lex(source: &str, media_type: &MediaType) -> Vec<LexedItem> {
/// SourceFile.
pub fn transpile_module(
specifier: &str,
source_text: &str,
source: &str,
media_type: &MediaType,
emit_options: &EmitOptions,
globals: &Globals,
cm: Rc<SourceMap>,
) -> Result<(Rc<SourceFile>, Module), AnyError> {
let info = SourceFileInfo::new(specifier, source_text);
let info = SourceFileInfo::new(specifier, source);
let source_file = cm.new_source_file(
FileName::Custom(specifier.to_string()),
source_text.to_string(),
source.to_string(),
);
let input = StringInput::from(&*source_file);
let (comments, module) = parse_string_input(&info, input, media_type)?;
Expand Down

0 comments on commit 5517fc5

Please sign in to comment.