RESSA icon indicating copy to clipboard operation
RESSA copied to clipboard

Parser stops parsing after import statement

Open allsey87 opened this issue 4 years ago • 2 comments

I guess this is just a usability issue, but when I try to modify the RESSA parser example to parse some JS with an import statement, the parser returns an UseOfModuleFeatureOutsideOfModule error and stops processing the remainder of the script. Perhaps it can be documented a bit more clearly why this doesn't work and whether there is a work around?

use ressa::*;

static JS: &str = "
import { Something } from './somewhere';
function Thing(stuff) {
    this.stuff = stuff;
}
function AnotherThing(stuff) {
    this.stuff = stuff;
}
";

fn main() {
    let parser = Parser::new(JS).expect("Failed to create parser");
    for part in parser {
        if let Ok(part) = part {
            println!("{:?}\n", part);
        }
    }
}

This is using RESSA 0.7.0 from crates.io

allsey87 avatar May 14 '20 08:05 allsey87

Hey, thanks for opening the issue!

I will have to take a look at the documentation again but the reason you are seeing this is because you are trying to parse an ES6 module with the default parser options.

I'll leave this issue open for the time being as a reminder to update the docs but in the short term, to solve your problem you would use something like the following.

let parser = Parser::builder().module(true).js(JS).build().expect("Failed to create parser");

Hope that helps, thanks again for the report!

FreeMasen avatar May 14 '20 14:05 FreeMasen

Excellent, thank you!

allsey87 avatar May 14 '20 15:05 allsey87

A note was added to the README.md as part of #75

FreeMasen avatar Nov 24 '22 19:11 FreeMasen