Skip to content

Commit

Permalink
Merge pull request #78 from rusty-ecma/fix/export-then-assign-one-line
Browse files Browse the repository at this point in the history
fix: parsing a variable export decl with two statements on one line
  • Loading branch information
FreeMasen committed May 6, 2023
2 parents 3cadf9a + b81bd88 commit d61d566
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 34 deletions.
6 changes: 4 additions & 2 deletions src/spanned/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,9 +737,11 @@ where
|| self.look_ahead.token.matches_keyword(Keyword::Const(()))
{
let _start = self.look_ahead_position;
let lex = self.parse_lexical_decl(false)?;
let mut lex = self.parse_lexical_decl(false)?;
if let Decl::Var { semi_colon, .. } = &mut lex {
semi = semi_colon.take();
}
let decl = NamedExportDecl::Decl(lex);
semi = self.consume_semicolon()?;
let spec = ModExportSpecifier::Named(decl);
ModExport { keyword, spec }
} else if self.look_ahead.token.matches_keyword(Keyword::Var(())) {
Expand Down
64 changes: 32 additions & 32 deletions tests/snapshots/everything_js__es2015_module.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2340,26 +2340,26 @@ Mod(
},
],
},
semi_colon: Some(
Slice {
source: ";",
loc: SourceLocation {
start: Position {
line: 18,
column: 22,
},
end: Position {
line: 18,
column: 23,
},
},
},
),
semi_colon: None,
},
),
),
},
semi_colon: None,
semi_colon: Some(
Slice {
source: ";",
loc: SourceLocation {
start: Position {
line: 18,
column: 22,
},
end: Position {
line: 18,
column: 23,
},
},
},
),
},
),
Decl(
Expand Down Expand Up @@ -2526,26 +2526,26 @@ Mod(
},
],
},
semi_colon: Some(
Slice {
source: ";",
loc: SourceLocation {
start: Position {
line: 19,
column: 29,
},
end: Position {
line: 19,
column: 30,
},
},
},
),
semi_colon: None,
},
),
),
},
semi_colon: None,
semi_colon: Some(
Slice {
source: ";",
loc: SourceLocation {
start: Position {
line: 19,
column: 29,
},
end: Position {
line: 19,
column: 30,
},
},
},
),
},
),
Decl(
Expand Down
23 changes: 23 additions & 0 deletions tests/snippets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,21 @@ fn class_method_export() {
run_test(js, true).unwrap();
}

#[test]
fn export_then_assign_two_lines() {
run_spanned_test(
"export let a;
a = 0;",
true,
)
.unwrap();
}

#[test]
fn export_then_assign_one_line() {
run_spanned_test("export let a; a = 0;", true).unwrap();
}

#[test]
fn redecl_error_in_nested_arrow() {
let js = r#"(() => {
Expand Down Expand Up @@ -1293,3 +1308,11 @@ fn run_test(js: &str, as_mod: bool) -> Result<(), ressa::Error> {
p.parse()?;
Ok(())
}

fn run_spanned_test<'a>(js: &'a str, as_mod: bool) -> Result<(), ressa::Error> {
use ressa::spanned::Parser;
env_logger::builder().is_test(true).try_init().ok();
let mut p = Parser::builder().js(js).module(as_mod).build()?;
p.parse()?;
Ok(())
}

0 comments on commit d61d566

Please sign in to comment.