Bug Report
Current and Expected Behavior
Currently @babel/parser allows numeric separators (i.e. the _ in 123_456) inside unicode escape sequences, both in the \u{...} and \uXXXX forms. They should be disallowed.
Input Code
- REPL or Repo link if applicable:
"\u{1F_639}";
"\u12_34";
"\x1_2";
repl
Babel Configuration (.babelrc, package.json, cli command)
You may need to enable the numericSeparator parser plugin in order to debug this issue.
Environment
Possible Solution
This is a bug in the Tokenizer, the part of @babel/parser which transforms the input source code into a lazy list of tokens (e.g. strings, numbers, identifiers, punctuators, ...).
The problem is that readInt, when the numericSeparator plugin is enabled, always allows numeric separators.
When readInt is called by readHexChar, if it finds _ it should throw something like Numeric separators are not allowed inside unicode escape sequences.
If anyone wants to work on this issue, please leave a comment below! If you need any help, plase ask me (or to any other Babel team member) on Slack 🙂
If you don't know how to clone Babel, follow these steps: (you need to have make and yarn available on your machine).
- Fork the repo
- Run
git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babel
- Run
yarn && make bootstrap
- Wait ⏳
- Run
make watch (or make build whenever you change a file)
- Add some tests (at least one for
\u{...}, \uXXXX and one for \xXX) in packages/babel-parser/test/fixtures/experimental/numeric-separator. Please don't call it "invalid-*", but use a descriptive name 😛
- If you want an example of a test for an error, you can check one of the
invalid-* tests in that folder.
- Update the code!
yarn jest parser to run the tests
- If it is working, run
make test to run all the tests
- Note: this change will likely also impact the results of running the Test262 suite on Babel.
- Before running those tests you need to run
make bootstrap-test262 to download them
- Use
make test-test262 to run them
- If some tests which were previously failing now pass, you can run
make test-test262-update-whitelist
- Run
git push and open a PR!
Bug Report
Current and Expected Behavior
Currently
@babel/parserallows numeric separators (i.e. the_in123_456) inside unicode escape sequences, both in the\u{...}and\uXXXXforms. They should be disallowed.Input Code
"\u{1F_639}"; "\u12_34"; "\x1_2";repl
Babel Configuration (.babelrc, package.json, cli command)
You may need to enable the
numericSeparatorparser plugin in order to debug this issue.Environment
Possible Solution
This is a bug in the
Tokenizer, the part of@babel/parserwhich transforms the input source code into a lazy list of tokens (e.g. strings, numbers, identifiers, punctuators, ...).The problem is that
readInt, when thenumericSeparatorplugin is enabled, always allows numeric separators.When
readIntis called byreadHexChar, if it finds_it should throw something likeNumeric separators are not allowed inside unicode escape sequences.If anyone wants to work on this issue, please leave a comment below! If you need any help, plase ask me (or to any other Babel team member) on Slack 🙂
If you don't know how to clone Babel, follow these steps: (you need to have
makeandyarnavailable on your machine).git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babelyarn && make bootstrapmake watch(ormake buildwhenever you change a file)\u{...},\uXXXXand one for\xXX) inpackages/babel-parser/test/fixtures/experimental/numeric-separator. Please don't call it "invalid-*", but use a descriptive name 😛invalid-*tests in that folder.yarn jest parserto run the testsmake testto run all the testsmake bootstrap-test262to download themmake test-test262to run themmake test-test262-update-whitelistgit pushand open a PR!