Skip to content

Commit

Permalink
fix(parser): fix [+in] context in CallArguments (#265)
Browse files Browse the repository at this point in the history
relates #255
  • Loading branch information
Boshen authored Apr 6, 2023
1 parent 034ca98 commit 6360bda
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
13 changes: 7 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,9 @@ impl<'a> Parser<'a> {

// parse `new ident` without arguments
let arguments = if self.at(Kind::LParen) {
CallArguments::parse(self)?.elements
// ArgumentList[Yield, Await] :
// AssignmentExpression[+In, ?Yield, ?Await]
self.with_context(Context::In, CallArguments::parse)?.elements
} else {
self.ast.new_vec()
};
Expand Down Expand Up @@ -743,10 +745,9 @@ 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);
// ArgumentList[Yield, Await] :
// AssignmentExpression[+In, ?Yield, ?Await]
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 6360bda

Please sign in to comment.