RESSA
RESSA copied to clipboard
Parser stops parsing after import statement
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
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!
Excellent, thank you!
A note was added to the README.md as part of #75