Open duanemoody opened 5 years ago
The following produces a Syntax Error for me in Firefox:
function x() { "use strict"; "\141" }
Note that the specific escape sequence \0
not followed by another digit is allowed, as is not considered as legacy octal escape sequence.
Correct, the proper encoding is \0o141
not \141
now. There is no explanation for why hex encoding is permitted but octal is not.
current implementations of Chrome and Firefox seem to assume this is an oversight and parse them in string literals
I’m not able to repro this, can you provide an example?
Edit: Since the OP didn’t mentioned strict mode, I’m guessing maybe you’re testing outside of strict mode? If so, browsers do still implement it for backwards compat. It’s currently defined in Annex B though, rather than in the main spec: https://tc39.es/ecma262/#sec-additional-syntax-string-literals.
the proper encoding is \0o141 not \141 now
The sequence "\0o141" in a string is an escaped null character followed by the literal characters "o141". This has always been true afaik. The ‘bare’ \141 syntax that used to exist is what became disallowed in strict mode — though it was actually removed by ES3, in 1999, before strict mode existed. That specific thing is was what Annex B was first introduced for, and the introductory text implies the intention at the time was deprecation (I’m guessing don’t-break-the-web was still being worked out at the time..?).
@duanemoody I think you are confusing the syntax of some escapes in string ("\x61"
, "\u0061"
, legacy "\141"
) with the syntax of number literals (0x61
, 0o141
, legacy 0141
)?
The syntax for numeric escape systems somehow omits octal even in its
\0u123
form; current implementations of Chrome and Firefox seem to assume this is an oversight and parse them in string literals. I only see documentation disallowing the deprecated legacy octal escape sequence\123
esp. in strict mode, but no explicit wholesale prohibition of octal nor a justification for such.Editorial error?