Babel: Possible to represent reserved keywords using unicode escape sequences.

Created on 27 Oct 2016  路  3Comments  路  Source: babel/babel

Input Code

let n = 5;

while(n --> 0) {
  \u0062\u0072\u0065\u0061\u{006B};
}

console.log(n);

In action in babel REPL (Babel 6.18.0)

Expected Behavior

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

Current Behavior

example:

\u0062\u0072\u0065\u0061\u{006B}; => break;

Possible Solution

_TBD_

Context

Your Environment

| software | version |
| --- | --- |
| Babel | 6.18.0 (via REPL) |
| node | n/a |
| npm | n/a |
| Operating System | n/a |


/cc @mathiasbynens (for his expertise 馃槃 )

outdated

All 3 comments

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 alert 42. 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!.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tracker1 picture tracker1  路  3Comments

catamphetamine picture catamphetamine  路  3Comments

jdalton picture jdalton  路  3Comments

kobezzza picture kobezzza  路  3Comments

Tin-Nguyen picture Tin-Nguyen  路  3Comments