Skip to content

The BigInt suffix should be disallowed in NonOctal Decimal Integer Literal #10465

@JLHwung

Description

@JLHwung

Bug Report

Current Behavior
The following code should throw a syntax error if the parser plugin bigInt is enabled.

Input Code

089n

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

  1. 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");

  1. Add a test on https://github.com/babel/babel/tree/master/packages/babel-parser/test/fixtures/experimental/bigint

  2. 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).

  1. Write a comment there to let other possible contributors know that you are working on this bug.
  2. Fork the repo
  3. Run git clone https://github.com/<YOUR_USERNAME>/babel.git && cd babel
  4. Run yarn && make bootstrap
  5. Wait ⏳
  6. Run make watch (or make build whenever you change a file)
  7. Add a test (only input.js; output.js will be automatically generated)
  8. Update the code!
  9. 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
  10. If it is working, run make test to run all the tests
  11. Run git push and open a PR!

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions