let n = 5;
while(n --> 0) {
\u0062\u0072\u0065\u0061\u{006B};
}
console.log(n);
In action in babel REPL (Babel 6.18.0)
It shouldn't be possible to represent reserved keywords using unicode escape sequences (e.g. \uXXXX
or \u{XXXX}
).
See: http://www.ecma-international.org/ecma-262/7.0/#sec-reserved-words
example:
\u0062\u0072\u0065\u0061\u{006B}; => break;
_TBD_
| software | version |
| --- | --- |
| Babel | 6.18.0 (via REPL) |
| node | n/a |
| npm | n/a |
| Operating System | n/a |
/cc @mathiasbynens (for his expertise 馃槃 )
Nice catch! I think this is a bug in Babylon, based on the tree generated in ASTExplorer. The escape sequences are being translated to an Identifier
of break
(which itself is also invalid).
This is something that web browsers used to allow despite it not being mentioned in the spec. As of ES6/ES2015, this behavior is explicitly non-conforming. More background from https://mathiasbynens.be/notes/javascript-identifiers:
[鈥 For example,
var v\u0061r = 42; alert(va\u0072);
would alert42
. This is very confusing, so I wouldn鈥檛 recommend relying on this hack. Luckily, it looks like the ECMAScript 6 spec will explicitly make this behavior non-conforming. Firefox/Spidermonkey, Safari/JavaScriptCore, and IE/Chakra have already dropped this behavior.
@dashed I made a copy of this issue in the Babylon repository, since it is going to need a fix in the parser. Thanks again for the report!.