Bug Report
Current Behavior
The following code should throw a syntax error if the parser plugin bigInt is enabled.
Input Code
Expected behavior/code
It should throw Invalid BigIntLiteral error.
Background
We use tokenizer to process the source code into a stream of tokens and 08n will be processed in readNumber
|
readNumber(startsWithDot: boolean): void { |
The NonOctal Decimal Integer Literal is defined as
NonOctalDecimalInteger:
0 DecimalDigits
DecimalDigits:
DecimalDigit DecimalDigits_opt
DecimalDigit:
0 1 2 3 4 5 6 7 8 9
The above grammar requires a NonOctal Decimal Integer Literal to be a sequence of decimal digits starting with zero and the length is at least 2.
Possible Solution
- Detect NonOctal Decimal Integer Literal in
readNumber. Throw an error here when it is detected.
|
// disallow floats and legacy octal syntax, new style octal ("0o") is handled in this.readRadixNumber |
|
if (isFloat || octal) this.raise(start, "Invalid BigIntLiteral"); |
-
Add a test on https://github.com/babel/babel/tree/master/packages/babel-parser/test/fixtures/experimental/bigint
-
Run make test-test262-update-whitelist to update the whitelist, the following lines are expected to be removed.
|
language/literals/bigint/non-octal-like-invalid-0008n.js(default) |
|
language/literals/bigint/non-octal-like-invalid-012348n.js(default) |
|
language/literals/bigint/non-octal-like-invalid-08n.js(default) |
|
language/literals/bigint/non-octal-like-invalid-09n.js(default) |
If you don't know how to clone Babel, follow these steps: (you need to have make and yarn available on your machine).
- Write a comment there to let other possible contributors know that you are working on this bug.
- 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 a test (only
input.js; output.js will be automatically generated)
- Update the code!
yarn jest parser to run the tests
- If some test outputs don't match but the new results are correct, you can delete the bad
output.js files and run the tests again
- If it is working, run
make test to run all the tests
- Run
git push and open a PR!
Bug Report
Current Behavior
The following code should throw a syntax error if the parser plugin bigInt is enabled.
Input Code
089nExpected behavior/code
It should throw
Invalid BigIntLiteralerror.Background
We use tokenizer to process the source code into a stream of tokens and
08nwill be processed inreadNumberbabel/packages/babel-parser/src/tokenizer/index.js
Line 981 in 9c1ad0a
The NonOctal Decimal Integer Literal is defined as
The above grammar requires a NonOctal Decimal Integer Literal to be a sequence of decimal digits starting with zero and the length is at least 2.
Possible Solution
readNumber. Throw an error here when it is detected.babel/packages/babel-parser/src/tokenizer/index.js
Lines 1027 to 1028 in 9c1ad0a
Add a test on https://github.com/babel/babel/tree/master/packages/babel-parser/test/fixtures/experimental/bigint
Run
make test-test262-update-whitelistto update the whitelist, the following lines are expected to be removed.babel/scripts/tests/test262/test262_whitelist.txt
Lines 113 to 116 in 9c1ad0a
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)input.js;output.jswill be automatically generated)yarn jest parserto run the testsoutput.jsfiles and run the tests againmake testto run all the testsgit pushand open a PR!