Open Bug 1782849 Opened 2 years ago Updated 2 years ago

Wrong error location with 'switch(value/'

Categories

(Core :: JavaScript Engine, defect, P5)

Firefox 105
defect

Tracking

()

UNCONFIRMED

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.

Component: General → JavaScript Engine

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.

Blocks: sm-frontend
Severity: -- → S4
Priority: -- → P5
You need to log in before you can comment on or make changes to this bug.