-
-
Notifications
You must be signed in to change notification settings - Fork 407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scripts should not be considered in a block #1339
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,7 @@ mod tests; | |
|
||
use crate::{ | ||
syntax::{ | ||
ast::{ | ||
node::{self}, | ||
Punctuator, | ||
}, | ||
ast::{node, Punctuator}, | ||
lexer::{InputElement, TokenKind}, | ||
parser::{ | ||
expression::Initializer, | ||
|
@@ -25,7 +22,7 @@ use crate::{ | |
}, | ||
BoaProfiler, | ||
}; | ||
use std::io::Read; | ||
use std::{collections::HashSet, io::Read}; | ||
|
||
/// Formal parameters parsing. | ||
/// | ||
|
@@ -66,6 +63,7 @@ where | |
cursor.set_goal(InputElement::RegExp); | ||
|
||
let mut params = Vec::new(); | ||
let mut param_names = HashSet::new(); | ||
|
||
if cursor.peek(0)?.ok_or(ParseError::AbruptEnd)?.kind() | ||
== &TokenKind::Punctuator(Punctuator::CloseParen) | ||
|
@@ -76,14 +74,19 @@ where | |
loop { | ||
let mut rest_param = false; | ||
|
||
let position = cursor.peek(0)?.ok_or(ParseError::AbruptEnd)?.span().start(); | ||
let next_param = match cursor.peek(0)? { | ||
Some(tok) if tok.kind() == &TokenKind::Punctuator(Punctuator::Spread) => { | ||
rest_param = true; | ||
FunctionRestParameter::new(self.allow_yield, self.allow_await).parse(cursor)? | ||
} | ||
_ => FormalParameter::new(self.allow_yield, self.allow_await).parse(cursor)?, | ||
}; | ||
if param_names.contains(next_param.name()) { | ||
return Err(ParseError::general("duplicate parameter name", position)); | ||
} | ||
|
||
param_names.insert(next_param.name().to_string()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is creating a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, at some point we want to intern all these strings, but for now this is not possible. The only optimization that could be done reasonably fast would be to change the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess that still minimizes the space used by the HashSet... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll change this to a |
||
params.push(next_param); | ||
|
||
if cursor.peek(0)?.ok_or(ParseError::AbruptEnd)?.kind() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add the parameter name in the error message? That way it's a bit more explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to, but the
general
function requires a&'static str
, which I cannot make from aformat!
macro. We would need to change theParseError
type to take anInto<Box<str>>
in order for this to work. I'm not sure if that is within the scope of this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's leave it like this for now then :)