/// This method parses a javascript / typescript file
This method parses a javascript / typescript file
This method parses a javascript / typescript file
pub fn parse_js(
        &self,
        fm: Arc<SourceFile>,
        handler: &Handler,
        target: EsVersion,
        syntax: Syntax,
        is_module: IsModule,
        comments: Option<&dyn Comments>,
    ) -> Result<Program, Error> {
        self.run(|| {
            let mut error = false;
            let mut errors = vec![];
            let program_result = match is_module {
                IsModule::Bool(true) => {
                    parse_file_as_module(&fm, syntax, target, comments, &mut errors)
                        .map(Program::Module)
                }
                IsModule::Bool(false) => {
                    parse_file_as_script(&fm, syntax, target, comments, &mut errors)
                        .map(Program::Script)
                }
                IsModule::Unknown => {
                    parse_file_as_program(&fm, syntax, target, comments, &mut errors)
                }
            };
            for e in errors {
                e.into_diagnostic(handler).emit();
                error = true;
            }
            let program = program_result.map_err(|e| {
                e.into_diagnostic(handler).emit();
                Error::msg("Syntax Error")
            })?;
            if error {
                return Err(anyhow::anyhow!("Syntax Error").context(
                    "error was recoverable, but proceeding would result in wrong codegen",
                ));
            }
            Ok(program)
        })
    }
pub fn parse_js ( & self , fm : Arc < SourceFile > , handler : & Handler , target : EsVersion , syntax : Syntax , is_module : IsModule , comments : Option < & dyn Comments > , ) -> Result < Program , Error > { self . run ( | | { let mut error = false ; let mut errors = vec ! [ ] ; let program_result = match is_module { IsModule :: Bool ( true ) => { parse_file_as_module ( & fm , syntax , target , comments , & mut errors ) . map ( Program :: Module ) } IsModule :: Bool ( false ) => { parse_file_as_script ( & fm , syntax , target , comments , & mut errors ) . map ( Program :: Script ) } IsModule :: Unknown => { parse_file_as_program ( & fm , syntax , target , comments , & mut errors ) } } ; for e in errors { e . into_diagnostic ( handler ) . emit ( ) ; error = true ; } let program = program_result . map_err ( | e | { e . into_diagnostic ( handler ) . emit ( ) ; Error :: msg ( " " ) } ) ? ; if error { return Err ( anyhow :: anyhow ! ( " " ) . context ( " " , ) ) ; } Ok ( program ) } ) }
This method parses a javascript / typescript file
This method parses a javascript / typescript file
&self
fm
Arc<SourceFile>
handler
&Handler
target
EsVersion
syntax
Syntax
is_module
IsModule
comments
Option<&dyn Comments>