@Gordon—Oh! Mea culpa. I thought I had ruled out internal minification, but I had neglected to defer execution in my experiments, which rather invalidates them :-}. Sorry!
Wildly misinterpreting technically valid but extremely unlikely code: / / / // ⇐ Humorously, the bizarre sequence 1 / /a/ does indeed throw an amazing fit, and can produce arbitrarily inappropriate error messages—add a multiline template literal later in the function for total hilarity!
Incorrectly allowing syntactically invalid code in an especially confusing way: /…/ i / /…/i ⇐ The IDE flags /a/ i as a syntax error, but the runtime sees /a/i.
The obscure example do x(); while(…); is already handled correctly, and sequences with - -- and + ++ display incorrectly in error messages but apparently execute correctly—are the increment and decrement operators internally pretokenised, or something?
I can't think of any other examples because alphanumeric tokens already preserve whitespace and JS has few cases where an operator symbol is at the left edge of an expression. Maybe ** and yield*, should they ever be implemented, might surprise people carelessly converting C code?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
@Gordon—Oh! Mea culpa. I thought I had ruled out internal minification, but I had neglected to defer execution in my experiments, which rather invalidates them :-}. Sorry!
Here are the ones I can think of:
Misinterpreting valid and useful code:
- -
/--
+ +
/++
Wildly misinterpreting technically valid but extremely unlikely code:
/ /
///
⇐ Humorously, the bizarre sequence1 / /a/
does indeed throw an amazing fit, and can produce arbitrarily inappropriate error messages—add a multiline template literal later in the function for total hilarity!Incorrectly allowing syntactically invalid code in an especially confusing way:
/…/ i
//…/i
⇐ The IDE flags/a/ i
as a syntax error, but the runtime sees/a/i
.The obscure example
do x(); while(…);
is already handled correctly, and sequences with- --
and+ ++
display incorrectly in error messages but apparently execute correctly—are the increment and decrement operators internally pretokenised, or something?I can't think of any other examples because alphanumeric tokens already preserve whitespace and JS has few cases where an operator symbol is at the left edge of an expression. Maybe
**
andyield*
, should they ever be implemented, might surprise people carelessly converting C code?HTH.