Wrong error location with 'switch(value/'
Categories
(Core :: JavaScript Engine, defect, P5)
Tracking
()
People
(Reporter: 845043157, Unassigned)
References
(Blocks 1 open bug)
Details
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0
Steps to reproduce:
run the program:
switch(value/{
case 1:
print(1);
}
Actual results:
SyntaxError:missing : after property id:
case 1:
................^
Expected results:
SyntaxError:missing ) after switch expression:
switch(value/{
..........................^
The error message told me 'case 1' is wrong while the truth is that I mistakenly entered ‘switch(value)’ as ‘switch(value/’.
It makes it difficult for me to correct this error.I think the error location should in 'switch(value/' rather than 'case 1:' and it may be a bug.
Comment 1•2 years ago
|
||
This is tricky, because it gets parsed as the expression value / { case 1:
. That means /
is treated as the division operator and { case
is treated as the start of an object literal. The parser expects :
after case
to finish parsing the object literal, like { case : value }
.
For comparison, Chrome reports: Uncaught SyntaxError: Unexpected number
.
Updated•2 years ago
|
Description
•