Skip to content

Commit

Permalink
fix(parser): fix [+in] context in CallArguments
Browse files Browse the repository at this point in the history
relates #255
  • Loading branch information
Boshen committed Apr 6, 2023
1 parent f9347b5 commit c756fe8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
9 changes: 3 additions & 6 deletions crates/oxc_parser/src/js/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
diagnostics,
lexer::{Kind, TokenValue},
list::SeparatedList,
Parser,
Context, Parser,
};

impl<'a> Parser<'a> {
Expand Down Expand Up @@ -635,7 +635,7 @@ impl<'a> Parser<'a> {

// parse `new ident` without arguments
let arguments = if self.at(Kind::LParen) {
CallArguments::parse(self)?.elements
self.with_context(Context::In, CallArguments::parse)?.elements
} else {
self.ast.new_vec()
};
Expand Down Expand Up @@ -743,10 +743,7 @@ impl<'a> Parser<'a> {
optional: bool,
type_parameters: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
) -> Result<Expression<'a>> {
let has_in = self.ctx.has_in();
self.ctx = self.ctx.and_in(true);
let call_arguments = CallArguments::parse(self)?;
self.ctx = self.ctx.and_in(has_in);
let call_arguments = self.with_context(Context::In, CallArguments::parse)?;
Ok(self.ast.call_expression(
self.end_span(lhs_span),
lhs,
Expand Down
7 changes: 1 addition & 6 deletions crates/oxc_parser/src/js/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ use super::{
grammar::CoverGrammar,
list::SwitchCases,
};
use crate::{
diagnostics,
lexer::Kind,
list::NormalList,
Parser, {Context, StatementContext},
};
use crate::{diagnostics, lexer::Kind, list::NormalList, Context, Parser, StatementContext};

impl<'a> Parser<'a> {
/// <https://tc39.es/ecma262/#prod-StatementList>
Expand Down
7 changes: 6 additions & 1 deletion crates/oxc_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,12 @@ mod test {
assert!(!ret.errors.is_empty());
}

let pass = ["async(...null)", "null?async():null", "switch(null){case async():}"];
let pass = [
"async(...null)",
"null?async():null",
"switch(null){case async():}",
"for(new null(null in null);;);",
];

for source in pass {
let ret = Parser::new(&allocator, source, source_type).parse();
Expand Down

0 comments on commit c756fe8

Please sign in to comment.